Is it possible to differentiate $\sin x$ with respect to $\cos x$ from first principles? I was doing a practice problem today for a University admissions test, where it asked me to differentiate $\sin x$ with respect to $\cos x$. The solution I found used the chain rule:
\begin{align}
\frac{d\sin x}{d\cos x}&=\frac{d\sin x}{dx}\cdot\frac{dx}{d\cos x} \\
&=\cos x\cdot\frac{1}{-\sin x} \\
&=-\cot x
\end{align}
However, the more I thought about this problem, the more it made me a feel a little uncomfortable. I don't really understand what it means to differentiate a function with respect to another function, if that is even possible. So I tried to differentiate $\sin x$ with respect to $\cos x$ from first principles, just so I knew what I was working with:
$$
\frac{d\sin x}{d\cos x}=\lim_{h \to 0}\frac{\sin (\cos x+h)-\sin(\cos x)}{h}
$$
The idea behind this was to treat $\cos x$ just as I would any other variable. However, this gave me the incorrect answer of $(\cos \circ \cos)(x)$, and I can't understand why. Is there an intuitive way of thinking about what it means to differentiate a function with respect to another function?
 A: You want to measure a change in $\sin{x}$ with respect to a change in $\cos{x}$. So you want $\sin{x}$ as a function of $\cos{x}$, which is not the same thing as $\sin(\cos{x})$. Therein is your fundamental issue.
What you want: if $x \in [0, \pi]$, then $\sin{x} = \sqrt{1 - \cos^2{x}}$, and so
\begin{align*} \frac{d(\sin{x})}{d(\cos{x})} &= \lim_{h\to 0} \frac{\sqrt{1 - (\cos{x} + h)^2} - \sqrt{1 - \cos^2{x}}}{h} \\
&= \lim_{h\to 0} \frac{[1 - (\cos{x} + h)^2] - (1 - \cos^2{x})}{h(\sqrt{1 - (\cos x + h)^2} + \sqrt{1 - \cos^2{x}})} \\
&= \lim_{h\to 0} \frac{-h(h + 2\cos{x})}{h(\sqrt{1 - (\cos x + h)^2} + \sqrt{1 - \cos^2{x}})} \\
&= \frac{-2\cos{x}}{2\sqrt{1 - \cos^2{x}}} = -\frac{\cos{x}}{\sin{x}} = -\cot{x} \end{align*}
as desired.
Exercise: what happens when $x \in [\pi, 2\pi]$?
A: Set $y=\cos x$, then, for $x\in[0,\pi]$,
$$
\frac{d\sin x}{d\cos x}=\left.\frac{d\sin(\arccos y)}{dy}\right|_{y=\cos x}=-\left.\frac{y}{\sqrt{1-y^2}}\right|_{y=\cos x}=-\frac{\cos x}{\sin x}=-\cot x,
$$
As for the limit, you should write
$$
\lim_{h\to0}\frac{\sin(\arccos(y+h)-\sin(\arccos(y))}{h}=\\
\lim_{h\to0}\frac{\sin(\arccos(\cos x+h)-\sin x}{h}.
$$
