TITLE: Spivak Calculus. Why is the books proof valid? Is my attempt at a proof valid?
QUESTION [6 upvotes]: Here is the problem. If f and g are continuous and $f(x)\ge g(x)$ for all x in a dense set A, prove that $f(x)\ge g(x)$ for all x. Here is the proof I gave on my own attempt. 
I will prove $f(x)\ge 0$ for all x using $f(x)\ge0$ for all x in A. Now in an earlier problem I already proved that if $f(x)=0$ for all x in A, then $f(x)=0$ for all x. So I only need to prove it for the case $f(x)\gt0$. Since f is continuous, for all $\epsilon\gt0$ there is some $\delta\gt0$ such that for all $x$ if $$\vert x-a \vert \lt \delta$$ then, $$\vert f(x)- f(a) \vert \lt \epsilon.$$ So there is some $a\in A$ in the interval $(x-\delta, x+\delta)$ since A is dense. Choosing $\epsilon=f(a)$ we obtain $$-f(a)\lt f(x)-f(a).$$ So $f(x)\ge0$ for all x. Applying this to the funtion $f(x)-g(x)$ we get the desired solution.
Now here is the books solution. It suffices to show that if $f$ is continuous and $f(x)\ge0$ for all x in A, then $f(x)\ge0$ for all x. Now there is a $\delta\gt0$ such that, for all x, if $$0\lt \vert x-a\vert \lt\delta,$$ then $$\vert f(x)-l \vert \lt \frac{\vert l \vert}{2}.$$ This implies that $$f(x)\lt l+ \frac{\vert l \vert}{2}.$$ Now if $l\lt0$, it would follow that $f(x)\lt0$, which would be false for those x in A which satisfy $0\lt \vert x-a \vert \lt \delta$. 
So this brings me to my questions. Why is his proof correct? Couldn't $\frac{\vert l \vert}{2}=0$? Then it would not be an $\epsilon \gt0$. And also is my proof correct? I am guessing I did something wrong since it seems much cleaner than the one he gave and I would assume he would have used it if it is correct.

REPLY [3 votes]: Other answers have provided good proofs, but I'd like to tackle the other aspect of your question:

Is my attempt at a proof valid?

Unfortunately not, in at least two ways:

Your proof breaks the condition "$f(x)≥0$ for all $x$ in $A$" into two cases, namely "$f(x)=0$ for all $x$ in $A$" (a case that you're previously tackled) and "$f(x)>0$ for all $x$ in $A$" (the case that you tackle here); but in fact, those are not the only possible cases: it's also possible that $f(x)=0$ for all $x$ in some subset of $A$ and $f(x)>0$ for all $x$ in the rest of $A$.
For the case where $f(x)>0$ for all $x$ in $A$, your proof concludes that $f(x)>0$ for all $x$. But that's not true: consider the counterexample of $f(x) = (x - \pi)^2$ and $A = \mathbb{Q}$, which satisfies the condition (since $(x - \pi)^2 > 0$ for any rational $x$) but not the conclusion (since $(x - \pi)^2 = 0$ when $x = \pi$). This counterexample "slips through" your proof because you don't fix the $a$, $\epsilon$, etc., for each $x$; every neighborhood of every $x$ contains some $a$ in $A$, and every $a$ in $A$ has some neighborhood on which $f$ is positive, but these two neighborhoods needn't be the same.