# Proof-check; are there any errors in this proof regarding squares of continuous functions?

I was wondering whether this following is a good proof:

Question:

Suppose that $f$ and $g$ are continuous functions and that for all $x$ we have $f(x)^2 = g(x)^2$. Suppose also that $f(x) \ne 0$ for all $x$. Prove that either $f(x) = g(x)$ or $f(x) = -g(x)$ for all $x$.

Proof:

Suppose that we have $f(x)^2 = g(x)^2$, $f(x) \ne g(x)$ and $f(x) \ne -g(x)$. Then we see that

$$f(x) \ne g(x) \wedge f(x) \ne -g(x)$$ so (remembering that $f(x) \ne 0$ for all $x$) $$f(x)^2 = f(x)f(x) \ne g(x) g(x) = (-g(x))(-g(x)) = g(x)^2$$

This is a contradiction, which proves the assertion.

-
Not really. You seem to be thinking of it pointwise, while you should be thinking function-wise (i.e., you need to prove that either $f(x) = g(x)$ for all $x$, or $f(x) = -g(x)$ for all $x$). Among other things, you haven't used the continuity of $f$ and $g$, which are important. –  Jonathan Christensen Dec 4 '12 at 3:26
@JonathanChristensen But does this not hold for every point $x$? –  providence Dec 4 '12 at 3:30
@providence It does, but it doesn't prove the result you want. It could be that on all the rationals, $g(x) = f(x)$, but on all the irrationals, $g(x) = -f(x)$. –  Jonathan Christensen Dec 4 '12 at 3:33
@Stuart: Your example violates the condition that $f$ be nowhere $0$. –  Brian M. Scott Dec 4 '12 at 3:33
The domain of $f$ and $g$ should be stated. Presumably both are defined and continuous on the entire real line? Connectedness of the domain suffices. –  Jonas Meyer Dec 4 '12 at 3:36

You should be immediately suspicious of your argument, because it doesn’t use the continuity of $f$ and $g$. What if $f(x)=1$ for all $x\in\Bbb R$, and $$g(x)=\begin{cases}-1,&\text{if }x<0\\1,&\text{if }x\ge 0\;?\end{cases}$$
Then $f^2=g^2$, but $f$ is neither $g$ nor $-g$. Of course it’s also true that $g$ is not continuous, but you didn’t use continuity in your argument, so if your argument were correct, this example couldn’t exist.
The real point of the exercise is to show that if $f$ and $g$ are continuous, you can’t have an example like this in which $f(x)=g(x)$ at some points $x$ and $f(x)=-g(x)$ at other points $x$.
HINT: If $f$ is continuous and never $0$, then by the intermediate value theorem either $f$ is strictly positive, or $f$ is strictly negative.