Finding general formula for $\cos^{-1}({\cos{x})}$ My teacher teacher told me that for a general angle $x$, $\cos^{-1}({\cos{x})}$ does't represent $x$ but different straight lines depending upon the intervals in which it lies. For ex: 
$$\cos^{-1}{\cos{x}}=$$
$$x,0\leq x \leq \pi \\ 2\pi-x,\pi\leq x \leq 2\pi\\…$$
making the graph look like :-
From wolfram alpha
He told us that if we have to find the value of $\cos^{-1}({\cos{x})}$ for a particular $x$ we will have to first find the range in which $x$ lies and then judge with the help of graph but I wondered if there is a direct formula for that. I tried with $\tan^-1({\tan{x}})$ and got it as :-
from wolfram alpha
I even verified this with wolfram alpha and got it right but the problem with $\cos$ is that when I try to solve it similarly like I did with the $\tan$ one, and get the interval in which $n$ lies, the extremities of the interval differ by $0.5$ because of which for some values their floor and ceiling match but for some values there isn't an integer value lying in that interval like this :- from wolfram alpha
so what to do in that case and what does no value of $n$ lying in the interval signify?
Thanks for help :)
 A: By definition we have that for $x\in[0,2\pi]$


*

*for $0\le x\le \pi\quad $ $\cos^{-1}{\cos{x}}=x$

*for $\pi<x\le 2\pi\quad$ $\cos^{-1}{\cos{x}}=2\pi-x$


and this is periodic with period $T=2\pi$.
Thus it is a kind of triangle function and we always need to divide into two parts dependind upon the range in which x lies.
A: I'm writing $\arccos$ instead of $\cos^{-1}$. By definition,
$$\arccos(\cos y)=y\qquad(0\leq y\leq\pi)\ .$$
For arbitrary $x\in{\mathbb R}$ define
$$d(x):=\min\bigl\{|x-2k\pi|\,\bigm|\,k\in{\mathbb Z}\bigr\}$$
to be the distance of $x$ from the nearest integer multiple of $2\pi$. Then
$$0\leq d(x)\leq\pi,\quad \cos x=\cos\bigl(d(x)\bigr)\qquad\forall x\in{\mathbb R}\ .$$
It follows that
$$\arccos(\cos x)=\arccos\bigl(\cos\bigr(d(x)\bigr)\bigr)=d(x)\qquad(x\in{\mathbb R})\ ,$$
which reveals $\arccos\circ\cos$ to be a sawtooth function.
A: Claim. Let $x\in\left[k\pi,\left(k+1\right)\pi\right]$, where $k\in\mathbb{Z}$. Then:
\begin{alignat*}{1}
\cos^{-1}\left(\cos x\right) & =\begin{cases}
x-k\pi & \textit{if }k\textit{ is even},\\
\left(k+1\right)\pi-x & \textit{if }k\textit{ is odd}.
\end{cases}
\end{alignat*}

Proof. First, note that $x-k\pi$ and $\left(k+1\right)\pi-x$ are both in  $\left[0,\pi\right]$.
Moreover, if $y\in\left[0,\pi\right]$, then $\cos^{-1}\left(\cos y\right)\overset{1}{=}y$.
Now, suppose $k$ is even. Then $\cos\left(x-k\pi\right) \overset{2}{=}\cos x$ and so:
$$\cos^{-1}\left(\cos x\right)=\cos^{-1}\left[\cos\left(x-k\pi\right)\right]\overset{1}{=}x-k\pi.$$
Next, suppose $k$ is odd. Then $\cos\left[\left(k+1\right)\pi-x\right]\overset{3}{=}\cos x$ and so:
$$\cos^{-1}\left(\cos x\right)=\cos^{-1}\left[\cos\left(\left(k+1\right)\pi-x\right)\right]\overset{1}{=}\left(k+1\right)\pi-x. \tag*{∎}$$  

(The reader can verify $\overset{2}{=}$ and $\overset{3}{=}$ using the Subtraction Formulae for Cosine.)
