Hartshorne Problem II.8.1 b Here is the problem statement: Let $B$ be a local ring containing a perfect field $k$ such that $B$ is the localization of a finitely generated $k$-algebra. Let $k(B)$ be the residue field of $B$. Then show that $B$ is regular if and only if $\Omega_{B/k}$ is free of rank $\text{dim}B+\text{tr.d.}k(B)/k$.
I can shof the if part but not the only if part. Here is hat I've done:
From part (a) we have a s.e.s of $k(B)-$vector spaces
$$0\to m/m^2\to \Omega_{B/k}\otimes_B k(B)\to \Omega_{k(B)/k}\to 0.
$$
We get
$$\text{dim}_{k(B)}(\Omega_{B/k}\otimes_B k(B))=\text{dim}_{k(B)}(m/m^2)+\text{dim}_{k(B)}(\Omega_{k(B)/k}).$$
But by theorem 8.6A the second term on the right is $\text{tr.deg}(k(B)/k)$. So we get $B$ is regular $\iff\dim_{k(B)}(m/m^2)=\dim B\iff   \dim_{k(B)}(\Omega_{B/k}\otimes_B k(B))=\dim B+\text{tr.deg}(k(B)/k)$.
Now assume $\Omega_{B/k}$ is free of rank $\text{dim} B+\text{tr.deg}(k(B)/k)$. Then $\text{dim}_{k(B)}(\Omega_{B/k}\otimes_B k(B))=\text{dim} B+\text{tr.deg}(k(B)/k)$ and $B$ is regular by the equivalence above.
For the converse this is how I started: assume $B$ is regular. Then by the above $\text{dim}_{k(B)}(\Omega_{B/k}\otimes_B k(B))=\text{dim} B+\text{tr.deg}(k(B)/k)$. Also, $B$ is an integral domain and if $K$ is its field of fraction then (by proposition 8.2A)
$$\Omega_{B/k}\otimes_B K\cong \Omega_{K/k}.$$
As $B$ is a localization of a finitely generated $k$-algebra $K$ is a finitely generated extension of $k$. Since $k$ is perfect we get $K$ is separably generated over $k$. Therefore (by theorem 8.6A) $\text{dim}_K(\Omega_{K/k})=\text{tr.d}(K/k)$.
Now my idea here was to show that $\text{tr.d}(K/k)=\text{dim}B+\text{tr.d}(k(B)/k)$ and then use lemma 8.9 from Hartshorne to conclude but I don't know how to prove this.
If anyone could help me finish this approach or show me how to solve it in some other way I would be very grateful!
 A: $\def\d{\delta}
\def\l{\lambda}
\def\W{\Omega}
\def\Hom{\operatorname{Hom}}
\def\Der{\operatorname{Der}}
\def\trdeg{\operatorname{trdeg}}
\def\ol{\overline}
\def\Frac{\operatorname{Frac}}
\def\idealht{\operatorname{ht}}$
If $\W_{B/k}$ is free of rank $\dim B+\trdeg k(B)/k$, then by the exact sequence of vector spaces from part (a) we have that $\dim B+\trdeg k(B)/k = \dim \mathfrak{m}/\mathfrak{m}^2+\dim \W_{k(B)/k}$.
By theorem II.8.6A, $\dim \W_{k(B)/k}=\trdeg k(B)/k$, as $k$ is perfect, so we deduce that $\dim B=\dim \mathfrak{m}/\mathfrak{m}^2$ and therefore $B$ is a regular local ring.
Conversely, suppose $B$ is a regular local ring which is $A_\mathfrak{p}$ for some finitely-generated $k$-algebra $A$ with prime ideal $\mathfrak{p}\subset A$.
Let $K=\Frac B$, which is a separably generated extension of $k$ by theorem I.4.8A.
By proposition II.8.2A, we have $\W_{B/k}\otimes_B K \cong \W_{K/k}$, which is a $k$-vector space of dimension $\trdeg K/k$ by theorem II.8.6A.
Thus $\dim_K \W_{B/k}\otimes_B K = \trdeg K/k = \dim A = \idealht \mathfrak{p} + \dim A/\mathfrak{p}$ where the last two equalities are by theorem I.1.8A.
As $\idealht \mathfrak{p}=\dim B$ and $\dim A/\mathfrak{p} = \trdeg \Frac(A/\mathfrak{p})/k = \trdeg k(B)/k$, we have that $$\dim_K \W_{B/k}\otimes_B K = \dim B+\trdeg k(B)/k.$$
On the other hand, by the exact sequence of (a), we have that $$\dim_{k(B)} \W_{B/k}\otimes_B k(B) = \dim_{k(B)} \mathfrak{m}/\mathfrak{m}^2 + \dim_{k(B)} \W_{k(B)/k} = \dim B+ \trdeg k(B)/k.$$
Therefore $\dim B+\trdeg k(B)/k=\dim_k \W_{B/k}\otimes_B k = \dim_K \W_{B/k}\otimes_B K$ and by lemma II.8.9, $\W_{B/k}$ is free of rank $\dim B+\trdeg k(B)/k$.
