Course information, class updates, notes, references, projects ...


Saturday 15 September 2012

Brahmagupta's Sine Interpolation





In a previous post we saw a very accurate approximation to the Sine function provided by the scientist Bhaskara who lived in the 7th century AD. In this post, we present an alternative formula given by his contemporary Brahmagupta. This is based on starting with a table of Sine values. The standard tables presented by Aryabhata and others preceding Brahmagupta used intervals of 3o45'. Intermediate values were then found by linear interpolation. Let's express this in our language:

We assume intervals of fixed width $\delta$. We are thus looking at the angles 0, $\delta$, $2\delta$, ..., $i\delta$ ,... Suppose a table is available for the Sines of these angles: $\sin(0)$, $\sin(\delta)$, $\sin(2\delta)$, ..., $\sin(i\delta)$, ... Our task is to estimate the value of $\sin(x)$ when $x$ is not a tabulated angle. Suppose $x$ is between $x_{i-1}=(i-1)\delta$ and $x_i=i\delta$. The total change of the Sine function over this interval is $\sin(x_i)-\sin(x_{i-1})$ and we denote this by $\triangle\sin_i$. If this change were happening linearly then every unit change in the angle would produce a change of
$$\frac{\triangle\sin_i}{\delta}$$ in the Sine function. In moving from  $x_{i-1}$ to $x$ we would therefore create a change of
$$\frac{\triangle\sin_i}{\delta}(x-x_{i-1})$$ This gives the following approximation, which is called linear interpolation:
$$\sin(x)-\sin(x_{i-1}) \approx \frac{\triangle\sin_i}{\delta}(x-x_{i-1}) \quad\mbox{or}\quad \sin(x) \approx \sin(x_{i-1}) + \frac{\triangle\sin_i}{\delta}(x-x_{i-1})$$
In linear interpolation we match the function which a straight line which meets it at 2 points: $x_{i-1}$ and $x_i$. Brahmagupta's approach amounts to improving this by matching the function with a quadratic which meets it at 3 points: $x_{i-2}$, $x_{i-1}$ and $x_i$. To derive this formula (and we don't know the steps Brahmagupta took) we start with a form similar to the linear interpolation formula: $$\sin(x)\approx \sin(x_{i-1}) + (x-x_{i-1})p(x)$$ where $p(x)$ is a linear function $Ax+B$. This already does the right thing at $x_{i-1}$. We have to choose $p(x)$ so that it also does the right thing at $x_{i-2}$ and $x_i$. In other words, we need $p(x)$ to satisfy the following: $$\sin(x_{i-2})=\sin(x_{i-1}) + (x_{i-2}-x_{i-1})p(x_{i-2})$$ $$\sin(x_{i})=\sin(x_{i-1}) + (x_{i}-x_{i-1})p(x_{i})$$ These can be rearranged into $$p(x_{i-2}) = \frac{\triangle\sin_{i-1}}{\delta}$$ $$p(x_{i}) = \frac{\triangle\sin_{i}}{\delta}$$
This is again a linear interpolation problem and we have already seen how to solve it: \begin{eqnarray*}
p(x) &=&p(x_{i-2}) + \frac{x-x_{i-2}}{x_i-x_{i-2}}(p(x_i)-p(x_{i-2}))= \frac{\triangle\sin_{i-1}}{\delta}+\frac{x-x_{i-2}}{2\delta}\left(\frac{\triangle\sin_{i}-\triangle\sin_{i-1}}{\delta}\right)\\
&=& \frac{\triangle\sin_{i-1}}{\delta}+\frac{x-x_{i-1}+\delta}{2\delta}\left(\frac{\triangle\sin_{i}-\triangle\sin_{i-1}}{\delta}\right) = \frac{\triangle\sin_i+\triangle\sin_{i-1}}{2\delta}+\frac{x-x_{i-1}}{\delta^2}\left(\frac{\triangle\sin_{i}-\triangle\sin_{i-1}}{2}\right)
\end{eqnarray*}
We bring things to a close by putting this expression for $p(x)$ back into our initial quadratic approximation. We get:
$$\sin(x) \approx \sin(x_{i-1}) + \frac{x-x_{i-1}}{\delta}\left(\frac{\triangle\sin_i+\triangle\sin_{i-1}}{2}+\frac{x-x_{i-1}}{\delta}\left(\frac{\triangle\sin_{i}-\triangle\sin_{i-1}}{2}\right)\right)$$ Brahmagupta used $\delta=15^o =900'$. So his base trigonometric table needed only five values (ignoring the trivial cases of 0 and 90 degrees). And here are graphs showing the accuracy of his formula between 60 and 75 degrees:
Linear Interpolation
Brahmagupta's Quadratic Interpolation

Wednesday 5 September 2012

A 1400 Year Old Formula for Sine

Bhaskara was an Indian mathematician who lived in the 7th century AD. One of his claims to fame was his commentary Aryabhatiyabhasya, which is our main source for understanding Aryabhata's cryptic verses. Another was a formula describing the Sine function through a rational approximation. In our terminology, measuring angles in radians, his formula becomes:
$$\sin(x) \approx \frac{16x(\pi-x)}{5\pi^2-4x(\pi-x)},\qquad (0\le x\le \frac{\pi}{2})$$

In this post, we will take a graphical approach to "discovering" this formula. Of course, we are not claiming Bhaskara thought like this. Perhaps he did not need to, as his skill and judgement in direct computation would have been far beyond ours.

Let's start by looking at the Sine function from 0 to $\pi$ (Again, Bhaskara would have only gone up to $\pi/2$ or 90 degrees.) The graph looks like part of an inverted parabola:
 
A parabola that is 0 at origin and $\pi$ must have the form $y=Cx(\pi-x)$, for some constant $C$. Now we want the central value of $y$, at $x=\pi/2$, to be 1. The actual value is $C\pi^2/4$ and so we set $C\pi^2/4=1$ and solve to obtain $C=4/\pi^2$. In Bhaskara's time, a popular estimate for $\pi$ was $\sqrt{10}\approx 3.16$. If we substitute that, we get $C=0.4$. We have obtained an estimate
$$\sin(x) \approx 0.4\, x(\pi-x)$$
How good is this? Let's compare the graphs:
 
Not bad! We could easily be satisfied with this. But Bhaskara was not, so let's take a closer look.  There are two ways of testing the closeness of quantities: their difference could be close to zero, or their ratio could be close to 1. Correspondingly, there are two ways of adjusting a quantity so that it becomes closer to another - by shifting or scaling. Let's first look at the difference between $\sin(x)$ and the quadratic approximation:
 
This kind of shape can be generated by a 4th degree polynomial. But adjusting the coefficients of that polynomial so that it has zeroes and peaks at the right locations calls for quite a bit of fiddling. So let's look at the ratio:
This looks much simpler - a quadratic again! To match this, we need a quadratic that is 1.25 at the ends and 1 in the middle. The following one does the trick:
 $$1.25-0.1\,x(\pi-x)$$
keeping in mind that $\pi^2\approx 10$. So we have
$$\frac{0.4\,x(\pi-x)}{\sin(x)} \approx 1.25-0.1\,x(\pi-x)$$
or
 $$\sin(x)\approx \frac{0.4\,x(\pi-x)}{1.25-0.1x(\pi-x)} = \frac{16\,x(\pi-x)}{50-4\,x(\pi-x)} \approx \frac{16\,x(\pi-x)}{5\pi^2-4\,x(\pi-x)}$$
Let us ask, one last time, how good is our approximation? And answer again with a graph:
 
The red and blue curves representing the two functions overlap too perfectly for the eye to distinguish them.