So I had this school assignment with this question
$\int (\cos x - \sin x)^2 \ dx$
And through computations I came up with this:
$\int (\cos x + \sin x )\ dx - \int 2 \cos x \sin x$
And this is where I got stuck, that when I integrate $2 \cos x \sin x$ right away, I would actually get $\color{blue}{x - \sin^2 x + C}$, which is different if I applied the double angle trigonometric identities in $2 \cos x \sin x$ , rewrite it to $\sin 2x$ , and it will give me a different answer, $\color{red}{x + \cos(2x)/2 + C}$
I went to Symbolab, and it really shows the difference, whether I integrate it right away or apply the trigonometric identity first before integrating
I tried to plot the points in Desmos, two answers seems close enough that it's just one constant away (particularly $0.5$), but still mathematically not equal.
So, does this mean that this trigonometric identity changed the actual answer that I should avoid using it as much as possible. Or this is just an exception? Which one is right? Is it both of the two answers?
I already passed my answer to the teacher, but what I actually did before passing it is integrating right away. But this problem haunts me in sleep that I actually opened my pc to ask this question here. Still learning integration techniques that I got introduced to this kind of problem, that overall it's pretty fun and stressing.



Depending on when and what you do the u-substitution, there are at least three ways to calculate $\int 2\sin(x)\cos(x)dx$:
$$ \int 2\sin x\cos x\ dx=\int \sin(2x)\ dx=-\frac12 \cos(2x)+C\tag{1} $$
$$ \int 2\sin x\cos x\ dx = (\sin x)^2+C\tag{2} $$
$$ \int 2\sin x\cos x\ dx = -(\cos x)^2+C\tag{3} $$
These answers are all correct.
In general, if you get (correctly via different methods) $$ \int f(x)\ dx=F(x)+C,\quad \int f(x)\ dx=G(x)+C $$
then there is some constant $K$ such that $G(x)=F(x)+K$.
Recall that $\int f(x)\,dx=F(x)+C$ really means $F'(x)=f(x)$ (on some interval $I$). The solution $F$ is not unique.
To see another example, both the following are correct: $$ \int \cos(x)\,dx=\sin x+C,\quad \int \cos(x)\,dx=\sin x+1+C $$