# How is that differentiation of $\cos(\theta)$ possible

calculustrigonometry

I pondered upon this transformation in a book and have some confusion about it.
$$y =\cos(\theta) = \sin\left(\frac\pi2-\theta\right)$$$$dy = d\left(\sin\left(\frac\pi2-\theta\right)\right)=\cos\left(\frac\pi2-\theta\right) \times d(-\theta) = \cos\left(\frac\pi2-\theta\right) \times (-d\theta)$$

$$\frac {dy}{d\theta}=-\cos\left(\frac\pi2-\theta\right)=-\sin(\theta)$$

The main part I don't understand is:
$$dy = d\left(\sin\left(\frac\pi2-\theta\right)\right)=\cos\left(\frac\pi2-\theta\right) \times d(-\theta)$$

This is (from what I can tell) an informal way to differentiate $$\cos(\theta)$$.

The chain rule says that if f(y) is a differentiable function of y and y(x) is a differentiable function of x, then $$\frac{df}{dx}= \frac{df}{dy}\frac{dy}{dx}$$.
In this example, $$f(y)= \sin(y)$$ and $$y(x)= \frac{\pi}{2}- x$$. $$\frac{df}{dy}= \cos(y)$$ and $$\frac{dy}{dx}= -1$$.
So with $$f(x)= \cos(x)= \sin(\pi- x)$$ $$\frac{df}{dx}= \frac{df}{dy}\frac{dy}{dx}= \cos(y)(-1)= -\cos\left(\frac\pi2- x\right)= -\sin(x)$$.