Spivak Calculus. Why is the books proof valid? Is my attempt at a proof valid? 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.
 A: All these solutions look overcomplicated. Given $x$, choose a sequence $(x_n)_n$ in $A$ with $x_n\to x$. We have $f(x_n)\geq g(x_n)$ for all $n$. Letting $n\to \infty$ and using continuity of $f,g$, we obtain $f(x)\geq g(x)$.
A: I assume set $A$ is dense in $\mathbb {R} $ and that means that every real number is a limit point of $A$ (ie every interval contains infinitely many points of $A$).
Frankly speaking neither your argument nor the textbook solution appears well written. Specifically what is $a$ in both of them is not clear. 
Here is an alternative approach. We are given that $f(x) \geq 0$ for all $x\in A$. On the contrary assume that there is a some real number $c$ with $f(c) <0$. Then by continuity of $f$ at $c$ there is a neighborhood $I$ of $c$ in which $f$ is negative. But $I$ contains infinitely many points of $A$ and at these points $f$ is non-negative. The contradiction proves the desired result.

After a re-reading of your question I finally figured out the book solution which is same as the proof mentioned above. The proof proceeds by taking $a$ as some arbitrary real number. And $f(a) =l$. If $l=0$ we  have no issue. So let $l\neq 0$. Then one chooses $\epsilon =|l|/2>0$ and gets a $\delta>0$ (via continuity of $f$ at $a$) such that $$|x-a|<\delta\implies |f(x) - l|<|l|/2$$ so that if $l<0$ then $$f(x) <l+(|l|/2)<0$$ for all $x$ with $|x-a|<\delta$. But in this interval $(a-\delta, a+\delta) $ there are many points of $A$ at which $f$ is non-negative and therefore we can't have $l<0$. Thus we must have $l=f(a) >0$.
So this textbook proof explains why $f(c) <0$ implies that $f$ is also negative in some neighborhood of $c$ (used in my proof). 
A: 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.

