Solution (source code)

= Solution

Factor the numerator as $(e^x-1)^2=x^2+O(x^3)$. The <Taylor series> of the <cosine> gives $\cos3x-2\cos2x+\cos x=(-9/2+4-1/2)x^2+O(x^4)=-x^2+O(x^4)$. Hence
$$
\boxed{\frac{e^{2x}-2e^x+1}{\cos3x-2\cos2x+\cos x}=-1+O(x).}
$$
The first nonzero term is the constant $-1$.