How do calculators evaluate inverse trig functions?

$\begingroup$

I know for simple inputs, you can just memorize the answer, but what if I wanted to find $\arcsin{0.554}$. My calculator instantly tells me that the answer is $0.5752 \ \text{radians}$. How can I do that by hand, procedurally, to always arrive at the right answer without having to memorize a bunch of stuff.

Thanks.

$\endgroup$ 6

6 Answers

$\begingroup$

This is a good question! Trig functions and inverse trig functions are tricky. In fact, IEEE has published standards for how they should be computed. (EDIT: Clause 9 of IEEE 754-2008, the floating point standard, recommends but does not require the implementation of trigonometric functions.)

In the following paper, a method is described for computing $\arcsin x$ when $0 < x < 1$: Paper.

In essence, they use the trig identity

$$\arcsin N = \arctan \frac{N}{\sqrt{1-N^2}}.$$

Of course, this just raises the question: how do you compute $\arctan x$?

Old algorithms used something called CORDIC.

Modern computers have sufficient memory and speed that they can construct lookup tables and interpolate. However, CORDIC is still finding use in things like FPGAs. I don't know offhand what the standard algorithm is, currently, but I'm willing to bet your calculator either uses CORDIC or interpolated lookups.

$\endgroup$ 2 $\begingroup$

The calculators normally use a version of the CORDIC-algorithms which is a set of algorithms for evaluating different trigonometric functions, or some kind of power series (e.g. Taylor series) of the function. These algorithms normally are not very well suited for doing calculations 'by hand' since they make use of a lot of repetition where computers are good at but we humans are pretty slow. As the hardware became cheaper we now often also have lookup tables which enables us to do a interpolation which is accurate enough for the expected applications.

$\endgroup$ $\begingroup$

To answer the question in the body, which is quite different from the title, you won't get a very accurate value for arcsin by hand without a lot of work. The easiest reasonably accurate way is to use the closest value you know and a Taylor's series. If you want $\arcsin 0.554$, you probably know $\arcsin 0.5=\frac \pi 6$. Then $\arcsin 0.554 \approx \frac \pi 6 + 0.054 \left.\frac d{dx}\arcsin x\right|_{0.5}=\frac \pi 6 + 0.054 \frac 1{\sqrt {1-0.5^2}}\approx 0.58595$, which is within $0.0012$ of the correct $0.58716.$

$\endgroup$ 3 $\begingroup$

It isn't actually instantaneous, but it's quite fast. There are a few ways to estimate functions. One way is to use a Taylor series expansion.

As for doing this by hand, even if you had the taylor series expansion, it would be difficult to do since you're talking about a lot of calculations. Sure, it could be done, but it would be far easier to just use a calculator.

$\endgroup$ $\begingroup$

I am afraid you won't find an easy by-hand solution. The required numerical methods will involve either sufficiently many tabulated numbers, or substantial arithmetic computation.

The Taylor series does not require any table.

If you can content yourself with a crude approximation, then you can use $$\sin x\approx\frac{4x(\pi-x)}{\pi^2},$$ for $x$ in range $[0,\pi]$. The formula is exact for $0$, $\pi/2$ and $\pi$.

Inverting the latter,

$$\arcsin x\approx\frac{\pi}2(1-\sqrt{1-x}).$$

Unfortunately, this uses a square root.

A more accurate result is given by the first two terms of Taylor $$\arcsin x\approx x+\frac{x^3}6.$$ Use it for $0<x<\sqrt2/2$, and for $x>\sqrt 2/2$, transform as $$\arcsin x=\frac\pi2-\arcsin\sqrt{1-x^2}.$$

I guess it is hard to avoid a square root, as the derivative becomes infinite at $x=1$.

$\endgroup$ 8 $\begingroup$

Your question title asks how calculators compute inverse trig functions, but the body of your question makes it clear that you actually want to know how to compute arcsin by hand. As mentioned in the previous answers & comments, calculators and computers use a variety of algorithms for trig, etc, but mostly they are not very practical for pure manual calculation. They aren't too bad if you have a simple 4 function calculator though, especially if your calculator has a memory. And if it can do square roots, even better.

We can approximate arcsin using polynomials, or ratios of polynomials (Padé approximants), although the latter aren't much fun for pure hand calculation, unless you love long division. ;)

Before the modern era, most people who needed trig values did not compute them from scratch. They looked them up in tables, and perhaps used simple interpolation to estimate values between table entries. Producing these tables and checking them for errors was a lot of work! The actual arithmetic wasn't difficult, once the various relevant identities & interpolation techniques had been discovered, but it takes a lot of effort to make high quality seven figure log and trig tables, and sometimes even higher precision tables were developed. Wikipedia has various articles on the history of this topic.

In this answer, I'll give an algorithm that can be used to calculate arcsin by hand to 5 or so significant digits, without too much tedious arithmetic. But first I need to say a few words about argument reduction.

It's generally not possible to find a polynomial that gives a good approximation to a non-polynomial function over its entire domain. However, it is often possible to find good approximations to the function in small regions of the domain. And in some cases, we can use properties of the function to "reduce" the domain to a smaller region. For example, if we have an algorithm for computing sine or arcsin of a positive argument we can use $\sin(-\theta)=-\sin(\theta)$ to handle negative arguments. And we can use identities like $\cos2\theta=\cos^2\theta-\sin^2\theta$ to reduce large angles to smaller angles. These techniques go by the name of argument reduction, older books may use the term "range reduction".

The graph of $y=\sin^{-1}x$ looks fairly tame near the origin, where $\sin^{-1}x\approx x$, but near $x=1$, it approaches the vertical.Graph of arcsin(x)

Polynomial curves simply can't go vertical like that. But we can reduce the argument. One possibility is to use the complementary angle. We can use $\sin^2\theta + \cos^2\theta = 1$ and $\sin^{-1}x + \cos^{-1}x=\pi/2$. If our sine is too big (the angle is $>\pi/4=45°$, so its sine is $>\sqrt2/2$), we convert it to the sine of the complementary angle (i.e, the cosine), plug that into our arcsin algorithm, and then get the complement of the result. So our core arcsin algorithm only needs to handle sines of angles from $0$ to $\pi/4$ ($0°$ to $45°$). The downside for manual calculation is that we have to compute a square root, which is a bit tedious.

However, there's an even better reduction (which also needs a square root for large arguments). Using the double angle identity mentioned earlier, it can be shown that$$\pi/2-\theta=2\sin^{-1}\left(\sqrt{\frac{1-\sin\theta}2}\right)$$We can use that identity to reduce an arcsin $>1/2$ to one $<1/2$. So now our core algorithm only needs to handle angles in the range of $0$ to $\pi/6$ ($0°$ to $30°$).

We still need at least 4 or 5 polynomial terms to get the desired precision. But we can improve things even further by splitting our interval. We use one polynomial for the low values, and another polynomial for the high values. We choose the splitting point such that the error in each polynomial is roughly equal.

We could use the Taylor series for our polys, but we get better results from Chebyshev polynomials. Even better are optimum polynomials, also known as minimax polynomials because they minimize the maximum error, and which can be found using the Remez algorithm.

Here are a pair of 3rd degree minimax polys for arcsine which cover the domain $(0, 1/2)$. Their maximum error is $\approx 4×10^{-6}$, although the error is approximately doubled when calculating arcsines of arguments $>1/2$. The splitting point is $k=0.29879570554023276$, that is, the 1st poly covers $(0, k)$, the 2nd poly covers $(k, 1/2)$. I give the coefficients as rational numbers to make them easier to use in manual calculation.

Poly 1:$$\frac{205}{1093}x^3 - \frac{5}{927}x^2 + \frac{2645}{2644}x - \frac1{249571}$$Poly 2:$$\frac{410}{1187}x^3 - \frac{82}{541}x^2 + \frac{1102}{1053}x - \frac5{1009}$$


Here's a short Python program that tests those polynomials & the argument reduction algorithm described above. The plot shows the error of the minimax polys compared to the value from the arcsin function in the Python standard library.

Code

""" arcsin, using two 3rd degree minimax polys
err -4.0068676433180e-6
LO
205/1093*x^3 - 5/927*x^2 + 2645/2644*x - 1/249571
HI
410/1187*x^3 - 82/541*x^2 + 1102/1053*x - 5/1009
Written by PM 2Ring 2022.05.10
"""
from math import asin
hpi = 3.1415926535897932 / 2
def asin_mm(x): if x > 0.5: cos_flag = True x = ((1 - x) / 2) ** 0.5 else: cos_flag = False if x < 0.29879570554023276: y = ((205/1093*x - 5/927)*x + 2645/2644)*x - 1/249571 else: y = ((410/1187*x - 82/541)*x + 1102/1053)*x - 5/1009 return hpi - 2 * y if cos_flag else y
def asin_err(x): return asin_mm(x) - asin(x)
plot(asin_err, (0, 1), frame=True, plot_points=400).show()
for i in range(101): x = i / 100 print(f"{x:.2f} {asin(x):.5f} {asin_mm(x):.5f} {asin_err(x): .2e}")

Output

0.00 0.00000 -0.00000 -4.01e-06
0.01 0.01000 0.01000 -7.43e-07
0.02 0.02000 0.02000 1.57e-06
0.03 0.03000 0.03001 3.05e-06
0.04 0.04001 0.04001 3.82e-06
0.05 0.05002 0.05002 4.01e-06
0.06 0.06004 0.06004 3.72e-06
0.07 0.07006 0.07006 3.08e-06
0.08 0.08009 0.08009 2.18e-06
0.09 0.09012 0.09012 1.13e-06
0.10 0.10017 0.10017 1.32e-08
0.11 0.11022 0.11022 -1.08e-06
0.12 0.12029 0.12029 -2.07e-06
0.13 0.13037 0.13037 -2.91e-06
0.14 0.14046 0.14046 -3.53e-06
0.15 0.15057 0.15056 -3.90e-06
0.16 0.16069 0.16069 -3.99e-06
0.17 0.17083 0.17083 -3.79e-06
0.18 0.18099 0.18098 -3.30e-06
0.19 0.19116 0.19116 -2.55e-06
0.20 0.20136 0.20136 -1.58e-06
0.21 0.21157 0.21157 -4.39e-07
0.22 0.22181 0.22182 7.82e-07
0.23 0.23208 0.23208 1.98e-06
0.24 0.24237 0.24237 3.02e-06
0.25 0.25268 0.25268 3.76e-06
0.26 0.26302 0.26303 4.01e-06
0.27 0.27339 0.27340 3.56e-06
0.28 0.28379 0.28380 2.17e-06
0.29 0.29423 0.29423 -4.44e-07
0.30 0.30469 0.30469 -3.31e-06
0.31 0.31519 0.31519 1.10e-06
0.32 0.32573 0.32573 3.36e-06
0.33 0.33630 0.33631 4.00e-06
0.34 0.34692 0.34692 3.48e-06
0.35 0.35757 0.35757 2.22e-06
0.36 0.36827 0.36827 6.02e-07
0.37 0.37901 0.37901 -1.06e-06
0.38 0.38980 0.38979 -2.50e-06
0.39 0.40063 0.40063 -3.53e-06
0.40 0.41152 0.41151 -4.00e-06
0.41 0.42245 0.42245 -3.85e-06
0.42 0.43345 0.43344 -3.08e-06
0.43 0.44449 0.44449 -1.79e-06
0.44 0.45560 0.45560 -1.33e-07
0.45 0.46677 0.46677 1.63e-06
0.46 0.47800 0.47800 3.14e-06
0.47 0.48929 0.48929 3.95e-06
0.48 0.50065 0.50066 3.50e-06
0.49 0.51209 0.51209 1.10e-06
0.50 0.52360 0.52359 -4.04e-06
0.51 0.53518 0.53519 2.11e-06
0.52 0.54685 0.54685 -2.28e-06
0.53 0.55860 0.55860 -5.29e-06
0.54 0.57044 0.57043 -7.10e-06
0.55 0.58236 0.58236 -7.90e-06
0.56 0.59439 0.59438 -7.84e-06
0.57 0.60651 0.60650 -7.10e-06
0.58 0.61873 0.61872 -5.83e-06
0.59 0.63106 0.63105 -4.18e-06
0.60 0.64350 0.64350 -2.29e-06
0.61 0.65606 0.65606 -2.95e-07
0.62 0.66874 0.66874 1.69e-06
0.63 0.68155 0.68156 3.54e-06
0.64 0.69450 0.69450 5.18e-06
0.65 0.70758 0.70759 6.50e-06
0.66 0.72082 0.72083 7.45e-06
0.67 0.73421 0.73422 7.96e-06
0.68 0.74776 0.74777 8.00e-06
0.69 0.76149 0.76150 7.54e-06
0.70 0.77540 0.77540 6.60e-06
0.71 0.78950 0.78950 5.20e-06
0.72 0.80380 0.80381 3.40e-06
0.73 0.81832 0.81832 1.28e-06
0.74 0.83307 0.83307 -1.02e-06
0.75 0.84806 0.84806 -3.34e-06
0.76 0.86331 0.86331 -5.46e-06
0.77 0.87884 0.87883 -7.12e-06
0.78 0.89467 0.89466 -7.96e-06
0.79 0.91081 0.91080 -7.57e-06
0.80 0.92730 0.92729 -5.45e-06
0.81 0.94415 0.94415 -9.67e-07
0.82 0.96141 0.96142 6.63e-06
0.83 0.97911 0.97911 1.95e-06
0.84 0.99728 0.99728 -3.13e-06
0.85 1.01599 1.01598 -6.30e-06
0.86 1.03527 1.03526 -7.82e-06
0.87 1.05520 1.05519 -7.92e-06
0.88 1.07586 1.07586 -6.88e-06
0.89 1.09735 1.09734 -4.96e-06
0.90 1.11977 1.11977 -2.44e-06
0.91 1.14328 1.14328 3.64e-07
0.92 1.16808 1.16808 3.15e-06
0.93 1.19441 1.19442 5.59e-06
0.94 1.22263 1.22264 7.33e-06
0.95 1.25324 1.25324 7.99e-06
0.96 1.28700 1.28701 7.20e-06
0.97 1.32523 1.32524 4.60e-06
0.98 1.37046 1.37046 -2.64e-08
0.99 1.42926 1.42925 -6.04e-06
1.00 1.57080 1.57080 8.01e-06

Arcsin error plot

Live version of the script, running on the SageMathCell server.

$\endgroup$ 1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like