Let $A \to B$ be a map of commutative rings, and $d : B \to I/I^2$ be
defined by $df = f\otimes 1 - 1\otimes f$, where $I$ is the kernel of
$B \otimes\_A B \to B$, as in [Hartshorne II.8].



> 
> If $df=0$, I would like to infer that $f \in A$, i.e. "if the
>  derivative is zero, the function is constant".
> 
> 
> 


This is certainly $\bf false$, 
e.g. $A = {\mathbb F}\_p$, $B = A[x]$, and $f=x^p$.
There $B\otimes\_A B\to B$ is $A[x\_1,x\_2] \mapsto A[x]$, with 
$I = \langle x\_1 -x\_2\rangle \ni x\_1^p - x\_2^p = f\otimes 1 - 1\otimes f$.
(That is, not only is $f\otimes 1 - 1\otimes f$ in $I^2$, it's in $I^p$.)



> 
> What is the right condition, then, on $A\to B\ $? My primary interest is
>  in $A = {\mathbb Z}[1/d]$.
> 
> 
> 



When does the relative differential $df=0$ imply that $f$ comes from the base?
I will rather regard $I/I^2$ as $\Omega\_{B/A}$, the module of differential forms. 


First some necessary conditions. If $D$ is a sub-$A$-algebra of $B$ such that $\Omega\_{D/A}=0$ (e.g. $D$ is a localization of $A$ or étale over $A$), the canonical map $\Omega\_{D/A}\otimes\_D B\to \Omega\_{B/A}$ shows that $df=0$ for all $f\in D$. So if $A$ is a field (of characteristic $0$), you want it to be algebraically closed in $B$. If $A$ is not a field, to avoid $B$ to contain a localization of $A$, you almost want to suppose $\mathrm{Spec} B\to \mathrm{Spec}A$ be surjective. 


These being said, now a sufficient condition. 



> 
> Suppose $A$ is noetherian, integrally closed of characteristic $0$, $B$ is an integral domain, $\mathrm{Spec} B\to \mathrm{Spec}A$ is surjective, and its generic fiber is ~~smooth~~ of finite type and geometrically integral. Then the kernel of $B\to \Omega\_{B/A}$ is equal to $A$. 
> 
> 
> 


Proof. 


(1) Let $C$ be the kernel of $d : B\to \Omega\_{B/A}$. This is a sub-$A$-algebra of $B$. The canonical exact sequence 
$$ \Omega\_{C/A}\otimes\_C B\to \Omega\_{B/A}\to \Omega\_{B/C}\to 0$$
implies that $\Omega\_{B/A}\to \Omega\_{B/C}$ is an isomorphism because the first map is identically zero ($dc\otimes b\mapsto bdc=0$ if $c\in C$). 


(2) Let $K=\mathrm{Frac}(A)$, $L=\mathrm{Frac}(B)$. Let us first show that $E:=\mathrm{ker}(L\to\Omega\_{L/K})$ equals to $K$. Note that $E$ is a field. Applying (1) to the situation $A=K$ and $B=L$, we see that $\Omega\_{L/K}\to \Omega\_{L/E}$ is an isomorphism. This map is $L$-linear, and $\dim\_L\Omega\_{L/K}$ is the transcendental degree of $L$ over $K$ (here we use the characteristic zero hypothesis). Similarly for $L/E$. Hence $E$ is algebraic over $K$. But $B\_K$ is geometrically integral over $K$, this forces $E=K$ (otherwise $L\otimes\_K E$ is not integral). 


(3) Let us show $C\_K:=C\otimes\_A K$ equals to $K$. Tensoring the exact sequence of $A$-modules
$$ 0\to C\to B\to \Omega\_{B/A}$$ 
by $K$, we get the exact sequence
$$ 0\to C\_K \to B\_K \to \Omega\_{B\_K/K}. $$ 
First suppose $B\_K$ is smooth over $K$. As $\Omega\_{L/K}$ is a localization of $\Omega\_{B\_K/K}$ and the latter is a free (hence torsion free) $B\_K$-module, the map $\Omega\_{B\_K/K}\to \Omega\_{L/K}$ is injective. By (2) we then get $C\_K=K$. In the general case, some dense open subset $U$ of $\mathrm{Spec}(B\_K)$ is smooth. If $f\in B\_K$ satisfies $df=0$ in $\Omega\_{B\_K/K}$, then $d(f\_{|U})=0$ in $\Omega\_{U/K}$. So $f{|\_U}\in K$. As $B\_K\to O(U)$ is injective, $f\in K$. 


(4) Let us show $C=A$. We have $C\subseteq B\cap K$ (in fact the equality holds). So we have to show $B\cap K=A$. Let $g\in B\cap K$ viewed as a rational function on $\mathrm{Spec}(A)$. Then $A\subseteq A[g]\subseteq B$. For any prime ideal $Q$ of $B$, $g$ is regular at the point $Q\cap A$. So the image of $\pi : \mathrm{Spec}(B)\to \mathrm{Spec}(A)$ is contained in the complementary of the pole divisor of $g$. So the latter is empty by the surjectivity hypothesis on $\pi$. Therefore $g$ is a regular function (here we use the normality of $A$) and $C=A$. 


**Add** Suppose $A, B$ are integral domains of characteristic $0$, $B\_K$ is finitely generated over $K=\mathrm{Frac}(A)$~~, and $\Omega\_{B\_K/K}$ is torsion free over $B\_K$~~. Then we proved above that the kernel of $d: B\to\Omega\_{B/A}$ is contained in $B\cap K^{alg}$. 


**Add 2** One can remove free or torsion-free condition on $\Omega\_{B\_K/K}$. The proof is a little modified in the step 3. We just notice that any integral variety in characteristic $0$ has a dense open subset which is smooth ! 


