why $|x|$ in $\frac{d}{dx}\sec^{-1}x=\frac{1}{|x|\sqrt{x^2-1}}$ I derived $$\frac{d}{dx}\sec^{-1}x$$ as follows:
Let $$z=\sec^{-1}x$$ Then $$x=\sec z$$ differentiating both sides w.r.t $x$ we get
$$1=\sec z \tan z \frac{dz}{dx}$$ so we get
$$1=x\sqrt{x^2-1}\frac{dz}{dx}$$ so
$$\frac{dz}{dx}=\frac{1}{x\sqrt{x^2-1}}$$
But why we need to introduce modulus to $x$, is it because slope of the tangent should be unique?
 A: Your mistake is in calculating $\tan(\sec^{-1}(x))$, note that $$\tan(\sec^{-1}(x)) = x\sqrt{1-\frac{1}{x^2}}$$ With this we get that 
$$\frac{d}{dx} \sec^{-1}(x) = \frac{1}{x^2\sqrt{1-\frac{1}{x^2}}}$$
A: $\DeclareMathOperator{\Asec}{Arcsec}$Briefly, the formula
$$
\tan(\sec^{-1}x) = \sqrt{x^{2} - 1}
$$
cannot be true for all real $x$ with $|x| \geq 1$, because the left-hand side is sometimes negative, while the right-hand side is everywhere non-negative. Careful bookkeeping accounts for the "missing" sign.

In more detail, the graph below shows the graph $y = \Asec x$ (the principal branch of the inverse secant) in blue, along with two non-principal branches.

To take the derivative, write $x = \sec y$ and differentiate each side with respect to $x$, just as you've done:
$$
1 = \sec y \tan y\, \frac{dy}{dx},
$$
or
$$
\frac{dy}{dx}
  = \frac{1}{\sec y \tan y}
  = \frac{1}{x \tan(\Asec x)}.
\tag{1}
$$
If $x \geq 1$, then $0 \leq \Asec x < \frac{\pi}{2}$, and "the standard right triangle picture (with acute angle $y$)" shows $\tan y = \tan(\Asec x) = \sqrt{x^{2} - 1}$. Substituting in (1) gives
$$
\frac{dy}{dx}
  = \frac{1}{x \sqrt{x^{2} - 1}},\quad x \geq 1.
\tag{2a}
$$
So far, so good.
If $x \leq -1$, however, then $\frac{\pi}{2} < \Asec x \leq \pi$, so $\tan y < 0$, and
$$
\tan y = \tan(\Asec x) = -\sqrt{x^{2} - 1}.
$$
Substituting in (1) gives
$$
\frac{dy}{dx}
  = \frac{1}{-x \sqrt{x^{2} - 1}},\quad x \leq -1.
\tag{2b}
$$
Together, of course, equations (2a) and (2b) are expressed by
$$
\frac{dy}{dx}
  = \frac{1}{|x| \sqrt{x^{2} - 1}},\quad |x| \geq 1.
$$
Note, incidentally, that if $\sec^{-1}$ denotes a non-principal branch, the preceding derivative formula may be off by a sign, depending whether or not the branch is increasing (correct sign) or decreasing (incorrect sign).
A: In the graph for same $x$ there are two $y$s symmetrically about x-axis. The slopes have opposite signs. So we can write $\pm $ before radical sign or mention the result in this way meaning we are talking about positive upper branch.
