So I am doing an introductory course on theory of real functions and am having hard time thinking of examples.
I know various theorems and can tell whether or not a continuous function with specific details exists. However, I would want to know how do experts come up with examples so quickly?
Consider this question:
Does there exist a continuous function $f:\mathbb R\to\mathbb R$ such that $f((0,1))=[0,1]?$
Initially, I was under the impression that pre-image of a closed set must be closed and thus, no such function exists. Later, I realized that it is not at all necessary to have $(0,1)= f^{-1}([0,1])$, rather it's possible that $(0,1)\subset f^{-1}([0,1])$.
For the sake of clarity of notation: $f^{-1}([0,1])=\{x\in\mathbb R \text{ such that } f(x)\in[0,1]\}\tag*{}$
I am kind of sure that such a function (as described in the question) exists, however, I can't think of examples in my mind.
I did the same question a while back with different intervals. Continuous $f:\mathbb R\to\mathbb R$ such that $f((-1,1))=[-1,1]$. I didn't have to think much and I came up with $f(x)=\sin(\pi x)$ which works.
If I translate and scale everything, I think I have $g((-1,1))=[-1,1]$ for: $$\displaystyle g(x)=\frac{\sin(\pi(2x-1))+1}{2}$$
I hope this example is correct. Is there any simpler example (like ones which I can quickly produce in a exam setting...)?
Update:
User localshop suggested that we can partition the interval $(0,1)$ and construct an isolated (half-period of) a triangle wave.
$$h(x)=\begin{cases}0 &\text{if $x\leq 0.25$}\\ 4x-1&\text{if $0.25\leq x\leq 0.5$}\\ -4x+3&\text{if $0.5\leq x\leq 0.75$}\\ 0 &\text{if $x\geq 0.75$}\end{cases}$$
Thanks to Desmos. Here's what the graphs looks like in the region $(0,1)\times [0,1]$: