Solving $(f'(x)) ^{2}=(f(x))^{2}$ when $f(0)=f'(0)=0$ While looking at this answer https://math.stackexchange.com/a/2111753/72031 could not help wondering about the following implication : $$(f'(x)) ^{2}=(f(x))^{2}\Rightarrow f'(x) =f(x) \text{ or } f'(x) =-f(x) $$ Note that the equation $f'^{2}=f^{2}$ is possible if for some values of $x$ we have $f'(x) =f(x) $ and for other values of $x$ we have $f'(x) =-f(x) $.  The linked answer assumes that this will never be the case. It appears that it is not obvious that only one of the alternatives will be true for all values of $x$. I could neither establish this nor find an easy counter-example. So I pose the following problem:

Let $f:\mathbb{R} \to\mathbb{R} $ be such that $f''(x) =f(x)$ for all $x\in\mathbb{R} $ and let $f'(0)=f(0)=0$. Then it is easy to prove that that $(f'(x)) ^{2}=(f(x))^{2}$ for all real $x$. Show that either "$f'(x) =f(x) $ for all real $x$" or "$f'(x) =-f(x) $ for all real $x$" . 

Please avoid solutions based on techniques of solving differential equations. Simpler approaches using theorems from elementary calculus are expected. 
 A: If $f$ is identically zero we're done.  We have $f(0)=0$.  Suppose $f$ is nonzero somewhere on $(0,\infty)$.  Let $a=\max\{x:f([0,x])=\{0\}\}$.  Let $b\in(a,a+1)$ be such that $|f(b)|=\max\{|f(x)|:x\in[a,b]\}$.  Then $|f(b)|=\left|\int_a^b f'(x)\,dx\right|\leq\int_a^b|f'(x)|\,dx=\int_a^b|f(x)|\,dx\leq(b-a)|f(b)|<|f(b)|,$ a contradiction.  Hence $f$ is identically $0$ on $[0,\infty)$.  With similar reasoning to the left we can conclude that $f$ is identically zero.
This fills the logical gap you point to, showing that $f$ must be identically $0$ without assuming $f'=f$ or $f'=-f$ identically.  Now that we can conclude $f=0$ identically, we know both $f'=f$ and $f'=-f$ identically.

An alternative approach, maybe more in the spirit of patching the linked answers, builds on nullUser's observation that $f$ is analytic. 
See nullUser's answer for reasons why $f$ is analytic.  Thus $f'-f$ and $f'+f$ are analytic. We have $(f'-f)(f'+f)=0$.  Because the factors are analytic on a connected domain, this implies one of the factors is identically $0$.
Suppose $f$ and $g$ are analytic on $\mathbb R$ with $fg\equiv0$. Then one of the sets of zeroes of $f$ and $g$ must have an accumulation point, say $g$ wlog. Let $a$ be an accumulation point of the zero set of $g$.  If $g$ were not identically $0$, we could write $g(x)=(x-a)^nh(x)$ with $n$ a positive integer and $h$ an analytic function such that $h(a)\neq0$. By continuity of $h$, this form shows that $a$ is actually an isolated zero of $g$, a contradiction.  Thus $g\equiv 0$.
See the Identity Theorem for analytic functions for more details.
A: Note that the assumption of $f''(x)$ existing and $f''(x)=f(x)$ implies that any such $f$ is infinitely differentiable. Moreover, by Taylor's theorem the remainder term $R_k(x) = \frac{f^{(k+1)}(\xi)}{(k+1)!}x^{k+1}$ clearly goes to $0$ as $k$ increases since $f^{k+1}$ just cycles through $f,f',f,f',...$
Thus $f$ is analytic. The assumptions $f'(0)=f(0)=0$ then imply its Taylor series is zero, so $f=0$. Clearly $f'=f$ is satisfied.
A: The other two answers both proved a stronger result ($f\equiv 0$). I'd like to fill the logic gap assuming only $$(f'(x)) ^{2}=(f(x))^{2}$$ to prove that either $$\forall x,f'(x) =f(x)$$or$$\forall x,f'(x) =-f(x).$$
We have two sets $A$ and $B$ where $$A=\{x|f'(x)=f(x) \}$$$$B=\{x|f'(x)=-f(x)\}$$
Obviously both $A$ and $B$ are closed sets.
Suppose $f(x_0)>0$ at some point $x=x_0\in A$. Then on the right side of $x_0$, $f'(x)$ is always greater than $0$ and $f(x)$ will only grow bigger and bigger. So $f'(x)$ will never equal to $-f(x)$ when $x$ moves from $x_0$ to $+\infty.$

Now we consider what happens on the left side of $x_0.$ When $x$ moves from $x_0$ to the left, $f(x)$ decreases. If we can prove that $f(x)$ is always greater than $0$ for all $x$ in $(-\infty, x_0)$, then we're done. $f'(x)$ cannot equal to $-f(x)$ if $f(x)$ is always above the $x$ axis. 
Now we consider the sulotions of $f'(x)=f(x)$. The general solutions are $$f(x)=c_1e^{x-c_2}$$ We have assumed $f(x)>0$, so $c_1>0$.
Further more, we know that for $\forall x$ in $(-\infty, +\infty)$, $$f(x)=c_1e^{x-c_2}>0$$ Essentially, we have proved $B=\emptyset$. 
We can apply the similar reasonings if $x_0\in B$ or if $f(x_0)<0$ for $x=x_0$ in $A$ or $B$.
Answer to the OP's question:
Well, I have shown that if $f(x)>0$ for some $x=x_0\in A$, then all the $x$ on the right side of $x_0$, $f'(x)=f(x)$. Suppose for some solution $g(x)$, $g(x_1)=0$ for some $x_1$. We may need to assume that $x_1$ is the nearest zero of $g(x)$ to $x_0$. Then there exists $\{a_n\}$, $a_1>a_2>...>a_n$ and $a_n\rightarrow x_1.$ For all $a_n$, all the points on right side of $a_n$ lie on $$f(x)=c_ne^{x}.$$ We can further conclude that $c_1=c_2=...=c_n=...$ because there could only be at most one exponential curve passing all these points. However, $f(x_1)=\lim{f(a_n)}=g(x_1)=0$, a contradiciton. Is it rigorous enough now?
