$$ \cos ^{-1} x-\cos ^{-1} y=\left\{\begin{array}{l} \cos ^{-1}\left(x y+\sqrt{1-x^{2}} \sqrt{1-y^{2}}\right) ; \text { if }-1 \leq x, y \leq 1 \quad \text{and} \quad x \leq y \\ -\cos ^{-1}\left(x y+\sqrt{1-x^{2}} \sqrt{1-y^{2}}\right) ; \text { if }-1 \leq y \leq 0,0<x \leq 1 \quad \text{and} \quad x \geqslant 1 \end{array}\right. $$
I'm having some issues proving for different cases, this is what I tried so far:
Let $\cos ^{-1} x=\alpha, \quad \cos ^{-1} y=\beta \quad \Longrightarrow \quad x=\cos \alpha, y=\cos \beta$
$$ \begin{aligned} \cos (\alpha-\beta) &=\cos \alpha \cos \beta+\sin \alpha \sin \beta \\ &=\cos \alpha \cos \beta+\sqrt{1-\cos ^{2} \alpha} \sqrt{1-\cos ^{2} \beta} \\ &=\left(x y+\sqrt{1-\cos ^{2} \alpha} \sqrt{1-\cos ^{2} \beta}\right) \end{aligned} $$
$$ \begin{aligned} \therefore \alpha-\beta &=\cos ^{-1} x-\cos ^{-1} y \\ &=\cos ^{-1}\left(x y+\sqrt{1-x^{2}} \sqrt{1-y^{2}}\right) \end{aligned} $$