\(\frac{\left(1+tanx\right)^2-2tan^2x}{1+tan^2x}=\frac{1+2tanx-tan^2x}{1+tan^2x}=\frac{cos^2x\left(1+2tanx-tan^2x\right)}{cos^2x\left(1+tan^2x\right)}\)
\(=\frac{cos^2x+2sinx.cosx-sin^2x}{cos^2x+sin^2x}=\frac{cos^2x-sin^2x+2sinx.cosx}{1}\)
\(=cos2x+sin2x\)