# A Cautionary Tale of Compute Inverse Trigonometric Functions

From $\arcsin(x)$‘s definition: $\{(x, y) | \sin(y) = x, -\frac{\pi}{2} \le y \le \frac{\pi}{2}\},$

we have $\arcsin(0) = 0, \arcsin(\frac{1}{2})= \frac{\pi}{6},\arcsin(\frac{\sqrt{3}}{2}) = \frac{\pi}{3}, \arcsin(1) = \frac{\pi}{2}$

and, $\arcsin(-\frac{1}{2})= -\frac{\pi}{6},\arcsin(-\frac{\sqrt{3}}{2}) = -\frac{\pi}{3}, \arcsin(-1) = -\frac{\pi}{2}.$

To obtain other values of $\arcsin(x)$, we may simply solve $\sin(y) - x = 0$

for $y$ where $-1 \le x \le 1.$

For example (see Fig. 1), solving $\sin(y) = \frac{1}{\sqrt{2}}$ for $y$ gives $y \approx \frac{\pi}{4}.$ It is in agreement with the fact that $\arcsin(\frac{1}{\sqrt{2}})= \frac{\pi}{4}.$

Fig. 1

In Fig. 2, we compute $\arcsin(x)$ from repeatedly solving $\sin(y) = x$ for $y$ where $x=-1+i \cdot\frac{1-(-1)}{n}, i=1,2,...n.$

Fig. 2

Since $\sin(y)$ is a periodic function, $\sin(y) = x$ has infinitely many solutions. It is possible that the solution obtained by Newton’s method lies outside of $[-\frac{\pi}{2}, \frac{\pi}{2}]$, the range of $\arcsin(x)$ by its definition. Such solution cannot be considered the value of $\arcsin(x).$

Fig. 3

Exercise-1 Compute $\arccos(x)$ by solving $\cos(y) = x$ for $y.$

Exercise-2 Explain Fig. 3.

# A Mathematical Allegory

We have defined function $\arcsin$ as a set: $\{(x, y) | \sin(y) =x, \frac{-\pi}{2} \le y \le \frac{\pi}{2}\}.$

By definition, $\arcsin(-1) = \frac{-\pi}{2}, \arcsin(0)=0, \arcsin(1) = \frac{\pi}{2}$

and $\frac{d}{dx} \arcsin(x) = \frac{1}{\sqrt{1-x^2}}.$

It means that $\arcsin(x)$ is the unique solution of $\frac{dy}{dx} = \frac{1}{\sqrt{1-x^2}}\quad\quad\quad(\star)$

where $y(-1)=-\frac{\pi}{2}, y(0)=0$ and $y(1)=\frac{\pi}{2}.$

To compute $\arcsin(x)$, we solve $(\star)$ for $y(x)$ as follows:

Integrate $\frac{dy}{dx} = \frac{1}{\sqrt{1-x^2}}$ from $-1$ to $x$ gives $\displaystyle\int\limits_{-1}^{x}\frac{dy}{dx} \,dx=\displaystyle\int\limits_{-1}^{x}\frac{1}{\sqrt{1-\xi^2}}\; d\xi\overset{\textbf{FTC}}{\implies}y(x) - y(-1) = \displaystyle\int\limits_{-1}^{x} \frac{1}{\sqrt{1-\xi^2}}\, d\xi.$

Therefore, $y(x) = \displaystyle\int\limits_{-1}^{x}\frac{1}{\sqrt(1-\xi^2}\,d\xi + y(-1) \overset{y(-1)=\frac{-\pi}{2}}{=} \displaystyle\int\limits_{-1}^{x}\frac{1}{\sqrt{1-\xi^2}}\,d\xi - \frac{\pi}{2}.$

That is, $\arcsin(x) = \displaystyle\int\limits_{-1}^{x} \frac{1}{\sqrt{1-\xi^2}}\;d\xi - \frac{\pi}{2}.$

To obtain $\arcsin(x), -1 < x < 1$, we numerically evaluate $\int\limits_{-1}^{x}\frac{1}{\sqrt{1-\xi^2}}\,d\xi$, using function ‘quad_qags’.

Fig. 1

The result is visually validated in Fig. 2.

Fig. 2

Note: ‘romberg’, another function that computes the numerical integration by Romberg’s method will not work since it evaluates $\frac{1}{\sqrt{1-x^2}}$ at $x=-1.$

Fig. 3

An alternate approach is to solve $\frac{dy}{dx} = \frac{1}{\sqrt{1-x^2}}, y(0)=0$ as an initial-value problem of ODE using ‘rk’ , the function that implements the classic Runge-Kutta algorithm.

Fig. 4 for $0 < x < 1$

Fig. 5 $-1

Putting the results together, we have

Fig. 6 $-1

However, we cannot solve $\frac{dy}{dx} = \frac{1}{\sqrt{1-x^2}}, y(-1)=\frac{-\pi}{2}$ using ‘rk’:

Fig. 7

Exercise-1 Compute $\arccos(x)$ for $x \in (-1, 1)$.

Exercise-2 Explain why ‘rk’ cannot solve $\frac{dy}{dx} = \frac{1}{\sqrt{1-x^2}}, y(-1)=\frac{-\pi}{2}$.

# Finding Derivative the “Hard” Way

In “Instrumental Flying“, we defined $\cosh^{-1}(x), \sinh^{-1}(x)$ as the inverse of $\cosh(x)$ and $\sinh(x)$ repectively.

To find the derivative of $\cosh^{-1}(x)$, let $y = \cosh^{-1}(x).$

We have $x = \cosh(y).$

Differentiate it, $\frac{d}{dx} x = \frac{d}{dx} \cosh(y) \implies 1=\frac{d}{dy} \cosh(y)\cdot \frac{dy}{dx},$

i.e., $1 = \sinh(y) \frac{dy}{dx}\implies \frac{dy}{dx} = \frac{1}{\sinh(y)}.$

By $\cosh(y)^2-\sinh(y)^2=1$ (see Exercise-1) and $\cosh(y) \ge 1$ (see Exrecise-2), $\sinh(y)^2 = \cosh(y)^2-1 \implies |\sinh(y)| = \sqrt{x^2-1} \overset{ (\star) }{\implies} \sinh(y) = \sqrt{x^2-1}.$

And so, $\frac{dy}{dx} = \frac{1}{\sqrt{x^2-1}} \implies \boxed{\frac{d}{dx}\cosh^{-1}(x) = \frac{1}{\sqrt{x^2-1}}}.$

Similarly, to find $\frac{d}{dx}\sinh^{-1}(x),$ let $y = \sinh^{-1}(x)\implies x=\sinh(y).$

Differentiate it, $\frac{d}{dx} x = \frac{d}{dx}\sinh(y) = \frac{d}{dy}\sinh(y)\frac{dy}{dx}\implies 1 = \cosh(y)\cdot\frac{dy}{dx}.$

By $\cosh(x)^2-\sinh(x)^2=1, \cosh(y) \ge 1$, $\cosh(y) = \textbf{+}\sqrt{\sinh(y)^2+1} = \sqrt{x^2+1}.$

Therefore, $1 = \sqrt{x^2+1}\frac{dy}{dx} \implies \boxed{\frac{d}{dx}\sinh^{-1}(x) = \frac{1}{\sqrt{x^2+1}}}$.

Prove: $\forall x \ge 0, \sinh(x) \ge 0.\quad\quad\quad(\star)$

By definition, $\sinh(x) = \frac{e^x-e^{-x}}{2} = \frac{e^{2x}-1}{2 e^{x}} \ge 0$, since $\forall x>0, e^{x},e^{2x} \ge 1$ (see Exercise-3).

Exercise-1 Show that $\forall x \in R, \cosh(x)^2 - \sinh(x)^2 =1$.

Exercise-2 Show that $\forall x \in R, \cosh(x) \ge 1$.

Exercise-3 Show that $\forall x \ge 0, e^{x} \ge 1.$

Exercise-4 Differentiate $\cosh^{-1}(x), \sinh^{-1}(x)$ directly (hint: see”Deriving Two Inverse Functions“).

# Oasis

An oasis awaits

The above image is created by Omega CAS Explorer:

The governing equations are: $x_{n+1} = \rho + c_2(x_n\cos(t_n)-y_n\sin(t_n),$ $y_{n+1} = c_2(x_n\sin(t_n) + y_n\cos(t_n))$

where $t_n = c_1-\frac{c_3}{1+x_n^2 + y_n^2}.$