Let$$f(x)= \lim_{n \to \infty}\dfrac{3^n(\overbrace{\sin(\sin(...\sin(x)))}^{\text{n times}}+(\sqrt 2 \cos x+2)^n+2^n\cos x}{3^n+\sin x(\sqrt 2\cos x+2)^n}.$$ If $l = \lim\limits_{x\to \frac{\pi}{4}^+}f(x)$ and $m = \lim\limits_{x\to \frac{\pi}{4}^-}f(x)$, find the value of $l^2+m^2$.
Attempt:
I do not see any reason why left hand and right limits should differ.
Dividing by $3^n$ we get: $$\lim_{\substack{n \to \infty\\x \to \frac{\pi}{4}}}\dfrac{(\overbrace{\sin(\sin(...\sin(x)))}^{n\text{ times}}+\dfrac{(\sqrt 2 \cos x+2)^n}{3^n}+\dfrac{2^n\cos x}{3^n}}{1+\dfrac{\sin x(\sqrt 2\cos x+2)^n}{3^n}} \equiv \dfrac{0+1+0}{1+\dfrac{1}{\sqrt 2}},$$ so $l=m = \dfrac{\sqrt 2}{\sqrt 2+1}$. But that does not give the right answer of $l^2+m^2$.
The answer is:
$2$
Where have I gone wrong? What is the method to solve it?
Keep in mind that you are first taking the limit with respect to $n$ and only then taking the limit with respect to $x$. So in particular, you care about the behavior of $\dfrac{(\sqrt 2 \cos x+2)^n}{3^n}$ for $x<\pi/4$ for the limit from below and for $x>\pi/4$ for the limit from above.
When $x<\pi/4$, the terms with $\dfrac{(\sqrt 2 \cos x+2)^n}{3^n}$ get large as $n$ gets large and so they dominate both the numerator and denominator in the limit and you get $f(x)=1/\sin x$ for all $x<\pi/4$ and thus $m=\sqrt{2}$. On the other hand, for $x>\pi/4$ the terms with $\dfrac{(\sqrt 2 \cos x+2)^n}{3^n}$ go to $0$ as $n$ gets large and so $f(x)$ is just $0$, which gives $l=0$.