Isomorphism between two localizations I am doing exercise 3.23 in Atiyah Macdonald and in the first part of the problem they ask to show that the ring $A_f = S^{-1}A$ where $S = \{1,f,f^2 \ldots \}$ depends only on the choice of the basic open set $X_f$ and not on $f$. For reference,
$$X_f \stackrel{\text{def}}{\equiv} \{P \in \operatorname{Spec}(A) : f \notin P\}.$$
I interpret this as saying that if there is another $g \in A$ such that $X_g = X_f$, then $A_f \cong A_g$. Since $X_f = X_g$ we deduce that $\operatorname{rad}\Big((f)\Big) = \operatorname{rad}\Big((g) \Big).$ From these equalities of radicals, this means that there are equations
\begin{eqnarray*} f^n &=& ag \hspace{5mm} \\
g^m &=& bf \end{eqnarray*}
for some $n,m \in \Bbb{N}$ such that $n,m >0$ and $a,b \in A$. Now we may suppose that $f$ and $g$ are not nilpotent for then $A_f \cong A_g \cong 0$. To show that $A_f \cong A_g$ I am trying to use Corollary 3.3 of Atiyah - Macdonald:


${\color{blue}{\text{Corollary 3.3: If $\tilde{g}: A \rightarrow B$ is a ring homomorphism such that}}}$
${\color{blue}{\text{(i) $s \in S \implies \tilde{g}(s)$ is a unit }}}$
${\color{blue}{\text{(ii) $\tilde{g}(a) = 0\implies as = 0$ for some $s \in S$}}}$
${\color{blue}{\text{(iii) Every element in $B$ is of the form $\tilde{g}(a)\tilde{g}(s)^{-1}$ for some $a\in A$ and $s \in S$ }}}$
${\color{blue}{\text{then there is a unique isomorphism $h:S^{-1}A \rightarrow B$ such that $\tilde{g}$ factorises }}}$ ${\color{blue}{\text{through the localisation $S^{-1}A$.}}}$


In our case we can set $B = P^{-1}A$ where $P = \{1,g,g^2, \ldots\}$.
$\textbf{Difficulty:}$ I have been spending some time now trying to define such a map $\tilde{g} : A \longrightarrow P^{-1}A$. Now it seems to me from those two equations above that there are only choices (up-to multiplication by some constant) orf such a map $\tilde{g}$. The problem is every time I define my $\tilde{g}$, property ${\color{blue}{(iii)}}$ is not satisfied. For example, I have tried to define for $x \in A$
$$ \tilde{g}(x) = \frac{bx}{a} \hspace{4mm} \text{or} \hspace{4mm} \tilde{g}(x) = \frac{x^n}{ab} \hspace{4mm} \text{or} \hspace{4mm} \tilde{g}(x) = \frac{bx}{ag^{m-1}}.$$
Suppose I try to write some $x/g^k$ in $P^{-1}A$ as $g(x')g(s)^{-1}$ for some $a' \in A$ and $s \in S$. Then one candidate we have is $x' =x$ and $s = f$. But then we only get 
$$g(x)g(f)^{-1} = \frac{bx}{g^m}.$$
If I try say $g(xf)g(f)^{-1}$ to remove the $g^m$ in the denominator the problem is that I just end up with $x$. The problems are similar for the second and third $\tilde{g}$ I defined above. How can I get around this? Please do not give it all away as I would like to enjoy some of the fun!
Thanks.
 A: You can use universal properties. 
You know that $f^n = ag$ for some $a$; that means that $g$ is invertible in $A_f$, and therefore there is a unique homomorphism $\varphi\colon A_g\to A_f$ that commutes with the canonical maps $A\to A_g$ and $A\to A_f$; symmetrically, since $g^m=bf$ for some $b$, $f$ is invertible in $A_g$ so there is a unique homomorphism $\psi\colon A_f\to A_g$ that commutes with the canonical maps.
Now consider $\psi\circ\varphi\colon A_f\to A_f$. This is the unique map that commutes with the canonical map $A\to A_f$, hence $\psi\circ\varphi$ is the identity. Likewise, $\varphi\circ\psi\colon A_g\to A_g$ must be the identity, by the uniqueness clause of the universal property of localizations. Therefore, $\varphi=\psi^{-1}$, so $A_f\cong A_g$, as desired. 
A: I think you have to define $\tilde g\colon A \to A_g$ to be the canonical map $\tilde g(x) = x/1$. What is the inverse of $\tilde{g}(f)$? In order to check (iii), you just have to show that $1/g$ is of the desired form. Look at $\tilde{g}(a)\tilde g(f^n)^{-1}$ and use both of your equations. [This seems like a reasonable guess in view of $f^n = ag$, and indeed it does work.]
