Proof of proposition 5.3.1 of Ravi Vakil's notes on algebraic geometry I am reading the proof of proposition 5.3.1 of Ravi Vakil's notes on algebraic geometry, and I have a problem with the last sentence : "If $g' = g''/f^n$ ($g''\in A$) then $\textrm{Spec}((A_f)_{g'}) = \textrm{Spec} (A_{fg''})$, and we're done."
Noting $V = \textrm{Spec} (B)$ and $V' = \textrm{Spec} (B_g)$, and noting $D_Z (h)$ the distinguished affine open subset of an affine scheme $Z$ associated to a section $h\in\Gamma(Z,\mathcal{O}_Z)$, I understand perfectly that if we note $U' = \textrm{Spec} (A_f)$ then the inclusion $U'\subset V$ induces a morphism $f : \Gamma(V',\mathcal{O}_X)\to \Gamma(U',\mathcal{O}_X)$ and that if we note $\varphi$ the associated morphism of affine schemes then $\varphi^{-1}(V') = D_{U'}(g')$ where $g'$ is the image of $g$ by $f$, but as $\varphi$ is the the inclusion $V'\subset U'$, we have $\varphi^{-1}(V') = V'$ because $V'\subset U'$ so finally $V' = D_{U'}(g')$ and $V'$ is distinguished in $U'$. I guess that the last sentence of the proof is supposed to show that this $V'$ is also distinguished in $U$, but I don't understand why.
 A: A first look on math.stackexchange could make think that this question has already various answers, but it is false : the most "complete" answer is this one :
Intersection of open affines can be covered by open sets distinguished in *both*affines
which nevertheless does not show the last bit, simply saying "hence in $U$" instead.
Lemma. (Transitivity of distinction.) Let $X$ be an affine scheme. If $U$ is a distinguished affine open subset of $X$ and if $V$ is a distinguished affine open subset of $V$ then $V$ is a distinguished affine open subset of $X$.
Proof. Note $ U = D_X (f)$ for some $f\in\Gamma(X,\mathscr{O}_X)$ and $V = D_U(g)$ for some $g\in\Gamma(U,\mathscr{O}_X)$. The inclusion $D_X (f)\subseteq X$ induces a morphism $\sigma : \Gamma(X,\mathcal{O}_X)\to\Gamma(D_X (f),\mathcal{O}_X)$ and as $\mathcal{O}_X$ is a sheaf, the image of $f$ by this morphism is invertible, so that the morphism induces a morphism $\varphi:\Gamma(X,\mathcal{O}_X)_{(f)}\to\Gamma(D_X (f),\mathcal{O}_X)$ which is in fact an isomorphism (see EGA I, chapitre I, proof of théeorème (1.3.7).) By the inverse of this isomorphism the element $g\in\Gamma(D_X (f),\mathcal{O}_X)$ corresponds to an element $h\in\Gamma(X,\mathcal{O}_X)_{(f)}$ that can be written $\frac{g''}{f^n}$ for some $g''\in\Gamma(X,\mathcal{O}_X)$ and some $n\in\mathbf{N}$. Note that this is equivalent to the equality $$(\ast) \;\;\sigma(f)^n g = \sigma(g'')$$ taking place in $\Gamma(D_X (f),\mathscr{O}_X)$. Now, we have $D_{U}(g) = D_{X}(g''f)$. Indeed, take $x\in D_{X}(g''f)$ so that $(g''f)(x)\not=0$, that is, $g''(x)f(x)\not=0$, which implies (as after all $x$ corresponds to a prime ideal of $\Gamma(X,\mathcal{O}_X)$) that $f(x)\not=0$ so that $x\in U$, and that $g''(x)\not=0$. Now localizing $(\ast)$ at $x$ gives $\sigma(f)(x)^n g(x) = \sigma(g'')(x)$ which is the same as $f(x)^n g(x) = g''(x)$ which implies that $g(x)\not=0$ which implies that $x\in D_{U}(g)$, and $D_{U}(g''f)\subseteq D_{U}(g)$. Using $(\ast)$ allows also to show the opposite inclusion, and concludes the proof. $\square$
Proposition. Let $X$ be a scheme, and $U,V$ be affine open subsets of $X$. Then $U\cap V$ is union of affine open subsets of $X$ that are distinguished affine open subsets of $U$ and of $V$ simultaneously.
Proof. If $U\cap V=\varnothing$ we have $U\cap V = D_U (1) = D_V(1)$ so we may assume $U\cap V \not=\varnothing$. To conclude it suffices to prove that each point of $U\cap V$ has a neighbourhood in $U\cap V$ which is a distinguished affine open of $U$ and $V$ simultaneously. Take $x\in U\cap V$. As $U\cap V$ is open in $U$ and as distinguished affine open subset of $U$ form a basis of $U$'s topology one can find an $f\in\Gamma(U,\mathscr{O}_X)$ such that $x\in U' := D_U (f) \subseteq U\cap V$. As $U\cap V$ is open in $V$ the set $U'$ is open in $V$ and as distinguished affine open subset of $V$ form a basis of $V$'s topology one can find a $g\in\Gamma(V,\mathscr{O}_X)$ such that $x\in V' := D_V (g) \subseteq U'$. By construction $V'$ is a distinguished affine open subset of $V$, so to conclude it suffices to show that it is a distinguished affine open subset of $U$. The inclusion $V'\subseteq U'$ induces a morphism of rings $\rho : \Gamma(U',\mathscr{O}_X)\to\Gamma(V',\mathscr{O}_X)$. Noting $g'$ the image of $g$ by $\rho$, EGA I, (1.2.2.2) ensures that $({}^a \rho)^{-1}(V') = D_{U'} (g')$ where ${}^a \rho$ is the (affine) schemes morphism associated to $\rho$ , that is, that $V' = U'\cap V' = D_{U'} (g')$, as ${}^a \rho$ is but the inclusion $V'\subseteq U'$, and the lemma concludes the proof. $\square$
Remark. Of course, building up intuition about such arguments allows to understand more easily the proof you are quoting, and allows to write less verbose proofs.
