Spivak Calculus. Why is the books proof valid? Is my attempt at a proof valid?

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)$.


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).


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.