For a Noetherian local ring $R$ with maximal ideal $\mathfrak{m}$ and residue class field $K$, consider the invariant $$\operatorname{def}(R) := \operatorname{dim}\_K(\mathfrak{m}/\mathfrak{m}^2) - \operatorname{dim}(R).$$ Here are some questions:


1. If $P \subseteq R$ is prime ideal, is it always true that $\operatorname{def}(R\_P) \le \operatorname{def}(R)$?
2. For which Noetherian rings is the function $\operatorname{Spec(}R) \to \mathbb{N}$, $P \mapsto \operatorname{def}(R\_P)$ upper semicontinuous?
3. Is there a name (and/or notation) that is commonly used for this invariant?


By a variant of the Jacobian criterion one can see that question 2 has an affirmaitve answer if $R$ is a finitely generated algebra over a perfect field. But are there more general results?



Is the embedding dimension minus the dimension upper semicontinuous?
Edit. Finally the proof was not so long, so I include it complete:


Question 3. Embedding codimension (sometimes simply codimension).


Question 1. I don't have access here to "Lech, Inequalities related to certain couples of local rings, Acta math. 112 (1964), 69-89", but maybe that paper will answer it better, I can't remember. However, here is a proof when $A$ is quasi-excellent:


Notation: dim = Krull dimension, edim = embedding dimension, codim = edim - dim = embedding codimension.


Lemma 1. Let $(A,m) \to (B,n)$ be a flat homomorphism of noetherian local rings. Then dim $A$ + dim $B/mB$ = dim $B$.


Lemma 2. Let $(A,m) \to (B,n)$ be a flat homomorphism of noetherian local rings with regular closed fiber $B/mB$. Then edim $A$ + edim $B/mB$ = edim $B$.


Deduction of Lemma 2 from Andre-Quillen homology (references (x.y) are to Result y from Chapter x in Andre, Homologie des algebres commutatives, Springer, 1974): let $f:(A,m,k) \to (B,n,l)$ be a flat homomorphism of noetherian local rings with regular closed fiber. Let $p=n/mB$ be the maximal ideal of $B/mB$. It is sufficient to prove that we have an exact sequence of $l$-vector spaces
$$0 \to m/m^2 \otimes\_k l \to n/n^2 \to p/p^2 \to 0.$$
But this exact sequence is a part of the Jacobi -Zariski exact sequence in Andre-Quillen homology (5.1) associated to $B \to B/mB \to l$:
$$H\_2(B/mB,l,l) \to H\_1(B,B/mB,l) \to H\_1(B,l,l) \to H\_1(B/mB,l,l) \to H\_0(B,B/mB,l).$$


$H\_2(B/mB,l,l)=0$ since $B/mB$ is regular by (6.26).


$H\_1(B,B/mB,l)=H\_1(A,k,l)= m/m^2 \otimes\_k l$ by (4.54) (since $f$ is flat) and (6.1) respectively.


$H\_1(B,l,l)= n/n^2$, and $H\_1(B/mB,l,l)= p/p^2$ by (6.1).


$H\_0(B,B/mB,l)=0$ by (4.60).


Another proof without Andre-Quillen homology can be found in arXiv:1205.2119v3, Lemma 3.1.


Corollary 3. Let $(A,m) \to (B,n)$ be a flat homomorphism of noetherian local rings with regular closed fiber. Then codim $A$ + codim $B/mB$ = codim $B$. In particular, codim $A \leq $ codim $B$. Another (trivial) particular case is codim $A$ = codim $\hat{A}$.


Definition. We say that a noetherian local ring is a G-ring if the completion homomorphism $A \to \hat{A}$ is regular. By Matsumura, Commutative Algebra, (33.C) Theorem 75 page 251 this is equivalent to the usual definition of G-ring, and by Theorems, 73, 76 and 77 this is also equivalent to be quasi-excellent (since it is local).


Corollary 4. Let $A$ be a local G-ring. Then for any prime ideal $p$ of $A$ we have codim $A\_p \leq $ codim $A$.


Proof. The result is valid for a complete ring $A$ (choose a regular local ring $S$ with the same embedding dimension of $A$ such that $A=S/I$ and localize), so codim $\hat{A}\_q \leq $ codim $\hat{A}$ = codim $A$. Since $A \to \hat{A}$ is faithfully flat, there exists a prime ideal $q$ of $\hat{A}$ contracting to $p$. The local homomorphism $A\_p \to \hat{A}\_q$ is regular and so by Corollary 3 codim $A\_p \leq $ codim $\hat{A}\_q$.


Question 2.


For excellent rings. An indirect proof, but short enough to be written here, is as follows. Embedding dimension is the diference between the invariant $\delta\_2$ in ["Ragusa, On Opennes ..."](http://www.ams.org/journals/proc/1980-080-02/S0002-9939-1980-0577744-1/S0002-9939-1980-0577744-1.pdf) which is upper semicontinuous by Proposition 3.6 in that paper, and the complete intersection defect which is upper semicontinuous by the main theorem in ["Alonso-Rodicio, On the upper ..."](http://www.mscand.dk/article/view/12275/10291). So for each $n$ the set of primes $p$ such that codim $A\_p > n$ is constructibe. By Corollary 4 it is also stable under specialization. So by Matsumura, Commutative Algebra, (6.G) Lemma, page 46, it is closed. 


