Exercise 23 (i) of Chapter 3 in Atiyah-Mcdonald's commutative algebra book I'm trying to solve this item of the question 23:

23. Let $A$ be a ring, let $X = \operatorname{Spec}(A)$ and let $U$ be a basic open set in $X$ (i.e., $U = X_f$ for some $f \in A$: Chapter 1, Exercise 17).
  i) If $U = X_f$, show that the ring $A(U) = A_f$ depends only on $U$ and not on $f$.

In another words, we have to prove the sheaf $A$ is well defined. Well, if $U=X_f=X_g$ we should prove that $A_f\cong A_g$. I'm using the obvious mapping $F:A_f\to A_g$, $F(a/f^n)=a/g^n$, but I couldn't prove this mapping is well-defined and an homomorphism with respect to addition neither (the multiplicative part is trivial).
I need help. 
Thanks a lot.
 A: $X_f = X_g$ is equivalent to $r((f)) = r((g))$ (ch.1, exc.17iv, which is where $X_f$ is defined in Atiyah-Macdonald). Therefore $f^n = h g$ and $g^m = k f$ for some $n, m \in {\mathbb N}$ and some $h, k \in A$.
Now, for simplicity, assume for the moment that $f$ and $g$ are not zerodivisors. In that case, $A_f$ and $A_g$ can be considered subrings of the total ring of fractions.
Now $A_f$ contains $1/g = h f^{-n}$ and $A_g$ contains $1/f = k g^{-m}$, so $A_f = A_g$. (Note: they're equal if you consider them as subrings of the total ring of fractions, not just isomorphic).
In general, the reasoning is the same, you just need a more careful formulation.
Write $i \colon A \to A_f$ and $j \colon A \to A_g$ for the localisation maps. Because $j(f)$ is invertible (with inverse $j(k) j(g)^{-m}$), by the universal property of localisation, there is a (unique) homomorphism $\phi \colon A_f \to A_g$ such that $j = \phi \circ i$. Similarly, there is a (unique) homomorphism $\psi \colon A_g \to A_f$ with $i = \phi \circ j$.

Now both $1_{A_f}$ and $\psi \circ \phi$ make the outer diagram above commute (i.e., $i = (\psi \circ \phi) \circ i$ and $i = 1_{A_f} \circ i$). By the universal property of localisation, there is a unique such map; therefore $\psi \circ \phi = 1_{A_f}$. Likewise $\phi \circ \psi = 1_{A_g}$. 
So $\phi$ and $\psi$ are each others inverse, showing that $A_f \cong A_g$. 
