Two ways to define Spec of a ring In defining the sheaf $X$ of a commutative ring $A$, one can either set $\mathcal{O}_X(D(f)) = A_f$ and show that it generates a sheaf, or set $\mathcal{O}_X (U)$ to be the set of partial sections of the map $\amalg_{\mathfrak{p} \in \text{Spec}(A)} A_{\mathfrak{p}} \rightarrow \text{Spec}(A)$ defined on $U$, which are locally of the form $f(\mathfrak{p}) = a/s$. That is, functions $U \rightarrow \amalg_{\mathfrak{p} \in \text{Spec}(A)} A_{\mathfrak{p}}$ such that, for each $\mathfrak{p} \in U$, there is an open neighborhood $D(s)$ of $\mathfrak{p}$ and an element $a \in A$ such that $f(\mathfrak{q}) = a/s$ for each $\mathfrak{q}$ in $D(s)$.
It is easy to show that the second definition is a sheaf, but that is no surprise as it is the sheafification of the first definition. 
However, $\mathcal{O}_X$ is already a sheaf in the first definition. This is equivalent to showing that the two definitions agree on open sets $U = D(s)$. My question is, can anyone show that $\mathcal{O}_X(D(f)) = A_f$ (where I am keeping with the second definition).
 A: There is a standard argument here that appears in most texts on the subject, e.g. Hartshorne II.2.2.  It's not a particularly short argument so I'll just summarize it here.
What we have to show is that the natural map $\psi: A_f \to \mathcal{O}_X(D(f))$ is both injective and surjective.
Injectivity: If $\psi(a/f^n) = \psi(b/f^m)$ then we let $\mathfrak{a}$ be the annihilator of $af^m - bf^n$.  By looking at the localization at primes $\mathfrak{p}\in D(f)$, we can show that $f\in\sqrt{\mathfrak{a}}$, so we have $f^l (af^m - bf^n)$ for some $l$, and therefore $a/f^n = b/f^m$ in $A_f$.
Surjectivity: We start with a section defined by $a_i/g_i$ on some finite covering set of principal opens $\{D(h_i)\}$.  Looking at radicals, we can assume that $g_i=h_i$.  It is argued that we can further assume $h_j a_i = h_i a_j$ for all $i,j$.
Write $f^n = \sum_i h_i b_i$ for some large $n$ and set $a = \sum_i a_i b_i$.  Then $a/f^n = a_i / h_i$ on $D(h_i)$, so $\psi(a/f^n)$ is actually the section we started with.
