----
> [!definition] Definition. ([[codimension of a closed subspace|codimension of an irreducible closed subspace]])
> Let $X$ be a [[topological space]] and $Z \subset X$ an [[irreducible topological space|irreducible]] [[closed set|closed]] [[subspace topology|subspace]]. The **codimension** of $Z$ in $X$, $\text{codim}(Z,X)$, is the length of the longest ascending chain $Z=Z_{0} \subsetneq \cdots \subsetneq Z_{d}$
of [[irreducible topological space|irreducible]] [[closed]] subsets.
> [!definition] Definition. ([[codimension of a closed subspace]])
>
Similar (and in the affine case identical to) to how we defined the [[height of an ideal]] in terms of [[height of a prime ideal|heights]] of [[prime ideal|prime ideals]], we may define the codimension of *any* [[closed set|closed subset]] $Y \subset X$ as $\text{codim}(Y,X):= \inf_{Z \subset Y} \text{codim}\big(Z, X\big)$
where the infimum is taken over all [[irreducible topological space|irreducible]] [[closed set|closed subsets]] $Z$ of $Y$.
^definition
> [!equivalence]
> If $X$ is a [[scheme]] and $Y \subset X$ a [[closed set|closed subset]], then $\text{codim }Y= \inf\{ \text{dim }\mathcal{O}_{X,y} : y \in Y \}.$
>
>
> > [!proof]- Proof.
> > **Affine case.** First assume $X=\text{Spec }A$ is an [[affine scheme]]. Then a [[closed set|closed subset]] $Y$ has the form $V(I)$ for $I$ an [[ideal]] of $A$. We know (e.g., see the example below) that $\text{codim}(V(I), \text{Spec } A)=\text{ht } I$, [[height of an ideal|where]] $\text{ht }I=\inf\{ \text{ht }\mathfrak{p} : \mathfrak{p} \supset I\}=\inf\{ \text{ht }\mathfrak{p}: \mathfrak{p} \in V(I) \}$. [[Krull dimension|And]] $\text{ht }\mathfrak{p}=\text{dim }A_{\mathfrak{p}}=\text{dim }\mathcal{O}_{\text{Spec } A, \mathfrak{p}}$. So $\text{codim}(V(I), \text{Spec } A)= \inf\{ \text{dim } \mathcal{O}_{\text{Spec } A, \mathfrak{p}}: \mathfrak{p} \in V(I)\},$
> > hence the result holds in the affine case.
> >
> > **General case.** [[dimension of a topological space|Recall]] the following: if $Y$ is a closed subset of $X$ and $U$ is any open subset of $X$, then *$\text{codim}(Y,X)=\text{codim}(Y \cap U, U)$*, assuming $Y \cap U$ is nonempty. Take an open affine [[cover]] $\{ U_{i} \}=\{ \text{Spec } A_{i} \}$ of $X$. Noting $Y \cap U_{i}$ is closed in $U_{i}$ (hence equals some $V(I)$, $I \subset A_{i}$ an [[ideal]]), we have for each $i$: $\text{codim}(Y, X)=\text{codim}(V(I), \text{Spec }A_{i}),$
> > and then applying the affine we obtain: $\text{codim}(Y, X)=\inf \{ \text{dim }\mathcal{O}_{U_{i}, y} : y \in Y \cap U_{i} \} \text{ for all }i.$
> > Since the sets $\{ \text{dim }\mathcal{O}_{U_{i}, y}: y \in Y \cap U_{i} \}$ have the same infimum $\text{codim}(Y,X)$, their union has that infimum too. Of course, their union is precisely $\{ \text{dim }\mathcal{O}_{X, y}: y \in Y \}$, so we are done.
> >
>
>
>
>
So computing codimension (and hence dimension, put $Y=\emptyset$) reduces to computing the dimensions of [[local ring|local rings]].
> [!basicproperties]
> For more properties, see also [[dimension of a topological space|dimension]].
>
^properties
> [!note] Remark.
> Such a notion is intuitive, but subtle, and can be ill-behaved. For example, even for a 'nice' space $X$ like a [[locally Noetherian scheme|Noetherian]] [[affine scheme|affine]] [[scheme]] (basically a [[Noetherian ring]]), generally $\dim Z + \text{codim}(Z, X) \neq \dim X$. It is true that [[codimension is well-behaved for irreducible closed subspaces of varieties over a field]].
^note
> [!basicexample]
> If $B$ is a [[commutative ring|commutative]] [[ring]] and $\mathfrak{p} \in \text{Spec }B$ is a [[prime ideal|prime]] [[Zariski topology on a ring spectrum|ideal]] of $B$, then $\text{codim}\big( V(\mathfrak{p}), \text{Spec } B \big)=\text{ht }\mathfrak{p}$ where $\text{ht }\mathfrak{p}$ denotes the [[height of a prime ideal|height]] of $\mathfrak{p}$.
>
> Indeed, recall $V(\cdot)$ reverses inclusions. So if the chain $\mathfrak{p}=\mathfrak{p}_{d} \supsetneq \mathfrak{p}_{d-1} \supsetneq \cdots \supsetneq \mathfrak{p}_{0}$ in $B$ witnesses that $\text{ht }\mathfrak{p}=d$, then applying $V$ produces a chain $V(\mathfrak{p})=V(\mathfrak{p}_{d}) \subsetneq V(\mathfrak{p}_{d-1}) \subsetneq \cdots \subsetneq V(\mathfrak{p}_{0})$ in $\text{Spec }B$ witnessing that $\text{codim}\big( V(\mathfrak{p}), \text{Spec } B \big)=d$ also. More generally, this reasoning shows $\text{codim}(V(I), \text{Spec } B)=\text{ht } I$ for $I$ a (not necessarily prime) [[ideal]] of $B$.
^basic-example
----
####
----
#### References
> [!backlink]
> ```dataview
> TABLE rows.file.link as "Further Reading"
> FROM [[]]
> FLATTEN file.tags as Tag
> WHERE Tag = "#definition" OR Tag = "#theorem" OR Tag = "#MOC" OR Tag = "#proposition" OR Tag = "#axiom"
> GROUP BY Tag
> ```
> [!frontlink]
> ```dataview
> TABLE rows.file.link as "Further Reading"
> FROM outgoing([[]])
> FLATTEN file.tags as Tag
> WHERE Tag = "#definition" OR Tag = "#theorem" OR Tag = "#MOC" OR Tag = "#proposition" OR Tag = "#axiom"
> GROUP BY Tag
> ```