How do we show that any function whose domain is R can be written as the sum of an odd and an even function I do understand how to prove it like this.
g(x)=(f(x)+f(-x))/2
h(x)=(f(x)-f(-x))/2
f(x)=g(x)+h(x)
But I didn't think of that at first.It looks like magic.I see the answer is understandable but I don't know how g(x) and h(x) were constructed in the first place.
How can I elevate my thinking to make me think about this practice in the first place
 A: You can find the solution by a reasoning by analysis and synthesis (not sure about the name, I know the method as "analyse-synthèse" in French, but its Wikipedia page has no English equivalent).
The method has two parts:

*

*In the analysis part, you assume that a solution to the problem exists and you try to deduce some properties of the solution, or the shape of the solution.

*In the synthesis part, you check that the properties you found during the analysis are sufficient to solve the problem.

In logical terms, it is the same as proving an equivalence.

Let's apply the method to the problem of the OP:

Show that every function $f:\mathbb R\to \mathbb R$ can be written as the sum of an even function and an odd function.

Analysis: assume that $f=g+h$ where $g$ is even and $h$ is odd. Then $f(x)=g(x)+h(x)$ and
$$
f(-x)=g(-x)+h(-x) = g(x)-h(x)
$$
Adding the two identities, we get $2g(x)=f(x)+f(-x)$ so $g(x)=\frac{f(x)+f(-x)}{2}$. Similarly, by subtracting the identities, we get $h(x)=\frac{f(x)-f(-x)}{2}$.
Synthesis: Let $f:\mathbb R\to \mathbb R$. We define $g(x)=\frac{f(x)+f(-x)}{2}$ and $h(x)=\frac{f(x)-f(-x)}{2}$ for every real number $x$.
Clearly, $g(x)+h(x)=f(x)$. Also, $g(-x)=\frac{f(-x)+f(x)}{2}=g(x)$ so $g$ is even. Similarly, $h$ is odd. So $f$ is indeed the sum of an even function and an odd function.
Note that we proved more than what was asked, since we proved that not only every function can be decomposed as a sum of an even and an odd function, but that this decomposition is unique.
