## Indian_math_Bhaskara_sine_formula_and_extensions_ into_TCL numerical analysis trignometry history

### Preface

Subject: Indian math Bhaskara sine formula and extensions into TCL

gold Here are calculations for Bhaskara sine formula and extensions from Indian math into TCL. The Bhaskara sine formula is of historical interest, but has not been used since the era of the great Indian astronomers. Various spreadsheet, curve fitting, and polynomial solvers on the Bhaskara functions were used to find good fits for implementation into the TCL language. There is more background on math than usually furnished, but the original goal was more historical interest and trig functions in degree measures. The Bhaskara sine formula is of considerable historical interest, as the Blaskara sine formulas and extensions cover about 13 centuries of Indian mathematics and astronomy.

gold 2Dec2018. Important Note, this study on Bhaskara sine functions is mostly for education and historical purposes, see better routines and current methods for angle reduction, sin, cos, etc in the TCL core distribution and TCLLIB. As of Jul2018, the TCLLIB has developed code for trig angles in degrees, trig inverse, and hyper functions in degrees, and angle reduction in radians and degrees. This supplemental trig.tcl, trigtest.tcl, and trig.man code is posted on the TCLLIB website. This math::trig.tcl seems really exciting work, which will keep TCL in pace with some of the other brand name languages (math oriented). .

### Introduction

The Bhaskara sine function or formula was the basis of sine tables edited by the Indian mathematician Bhaskara 1 in the seventh century. The Bhaskara sine function was possibly derived from the parabolic curve, from article in Mathematics Magazine by Dr . Shailesh A. Shirali. The Bhaskara sine formula and extended formulas are mostly for positive x < pi/2. Bhaskara used integers in the formula from the seventh century. Given the normal trig relations, the Bhaskara sine function can be extended to sind, cosd, tand in equivalence to the accuracy of 2nd order taylor series. As Dr . Shailesh A. Shirali demonstrated, the similarity of Bhaskara sine function to the Taylor and Pade formulas is worth some study. Often wondered whether the parabolic curve could be fudged into a sine or cosine curve.

### Bhaskara function and extensions into TCL Code

Details for loading TCL procedures. The Bhaskara sine function was extended into a set of TCL expressions into a catch-all TCL proc using degree measures. The original Bhaskara sine function used angle measurement in jotas, transformed into radians, and then transformed into cordics, according to the Shirali article. Here the formulas used the degree measures, although formula adaptations to radian measure are available. The Bhaskara sind was expr { (4.*\$x*(180.-\$x))/( 40500.-\$x*(180.-\$x)) }, for positive pi and 0>\$x<pi. Dr. Shirali used the the identity cos(a)deg = sin(90-x) deg for the derived Bhaskara cosd of expr { (4.*(90.-\$x))*(90.+\$x)/( 32400.+\$x*\$x) }, -pi/2<\$x>pi/2.

The Bhaskara step quadratic formulas and set up can be used to develop a crude tangent formula. These axioms were developed in the papers by Dr. Shirali , Stroethoff ,and Gupta. Some conditions are found in other Indian sutras: the sine tables were developed on a standard circle of 21600 minutes with a radius of 3438 minutes (for astronomy). The sind is sind(x) = x*(180-x)/8100. In polynomial P, the sind(P) = (4*P)/(5-P). The cosd is cosd(x) (90-x)+(180-(90-x)/8100. The tand is sind/cosd which expands to tand = (x*(180-x)/8100)/((90-x)+(180-(90-x)/8100). Reduction, tand = (x*(180-x)) /((90-x)*(90+x)). So far, these step equations have about an 8 percent error. Substituting P= x*(180-x)/8100 into sind = (4*P)/(5-P) gives the Bhaskara sine formula with 0.37 percent error. Boiling down pages of algebra, the Bhaskara sine formula is a quadratic equation of sind(x) = x*(180-x)/8100 that is evaluated in (4*P)/(5-P) at sind(30) = 1/2. A quadratic equation with solutions at 0, 90, and 180 is transformed into an equation with solutions at 0, 90, 180, and 30 degrees. < The trial step equations in polynomial P are sin = (4*P)/(5-P);side ~ (5-P) - (4*P*4*P) / 4, cos ~ ((5-P) -(4*P*4*P)/4)/(5-P); tan ~ ((5-P) - (4*P*4*P) / 4)/((4*P)/(5-P)) >

### Variant Sine Formula in Grahalaghava manuscript

In the Grahalaghava manuscript of 1520 CE, the Indian mathematician Ganesa Daivajna published the Bhaskara formula with a different constant of 40320 versus the original Bhaskara constant of 40500. The error curve derived from the true sine minus formula(cc=40320) is largely negative, meaning the values of formula(cc=40320) are mostly above the true sine curve. As an inequality, true sine. <= formula(cc=40320) . Now compare the error curve derived from true sine minus formula(cc=40500), which does pass several times through the zero level representing the true sine. But the formula(cc=40500) is mostly positive and below true sine over the interval from 45 degrees (pi/4) to 135 degrees (3*pi/4). Thus in the region of greatest interest, the true sine lies between formula(cc=40500) and formula(cc=40350 )!! With conditions, the inequality exists that formula(cc=40500) <= true sine <= formula(cc=40350), over interval of (pi/4) to (3*pi/4).

There are several ways to estimate an optimal constant in the Blaskara sine formula. Roughly the optimal constant is in a band between 40400 and 40500, based on trial and error at setting input angle aa at 45 degrees or pi/4. The error curve of cc = 40500 has maximum of +.0013 and minimum of -0.0016, average ABS extremes would be (0.0013+0.0016)/2 or 0.00145. Setting extremes to average 0.00145, cc = 40500 * (0.70710678-0.00145)/0.70710678,40416.95. The formula(cc=40417) had relative error of 0.068 percent versus the relative error of 0.173 percent on the original formula(cc=40500). The formula(cc=40417) gave roughly about 0.173/0.068 or 2.5 times improvement in relative error. But will continue to study the error bounds.

### Least Squares Fits and Online Curve Fitter

A least squares method was fit to the sine curve with some known initial points from the small sine table. The 5 points were (0,0),(30,.5),(90,1),(150,.5), and(180,0). The quadratic curve fit to the sine was quad_sine = -0.00012094*x^2 +0.02176871*x -0.01360544, condition that 0<+A1<180 degrees. Another least squares fit was tried with points (0,0)(30,.5)(45,0.7071067811865476) and (90,1). The quadratic curve fit to the sine was = -9.84020089e-05*x^2 +2.00021484e-02*x -2.09138902e-03, condition that 0<+x<90 degrees. The quadratic formula for +x<90 was loaded into a TCL procedure and returned an error of 2 percent from the sine. Lets develop and model an error curve by spreadsheet sine minus quadratic formula. The error curve was modeled by another quadratic as error = 1.39361485e-05*x^2 -6.99389504e-04*x -1.15936030e-02. The sum of the quadratic fit and error fit curves was slightly better in tracking the spreadsheet sine, up to the limit or turning point of 90 degrees.

Taking a clue from Bhaskara, other fits to the sine curve can be tried from an online curve fitter, using the least squares method. The cubic equation was sind = 1.077526*e^(-(x - 90)^2/(2*44.85532^2)), condition 0<x<180 degrees. A fifth degree polynomial from least squares was sind = 0.00003431266 + 0.01720044*x + 0.00001589327*x^2 - 0.000001238347*x^3 + 3.439853e-9*x^4 + 1.479442e-24*x^5 degrees, from 6 points and 0<x<180. A Gaussian bell curve was sind = 1.077526*e^(-(x - 90)^2/(2*44.85532^2)), where 0<x<180 and not a good fit to the eyeball. Somewhat closer fits to sine are found by limiting the interval from 0 to 90 degrees and not turning the corner. The linear fit or stick fit was sind = 0.01578989*x + 0.01203364 degrees, condition that 0<x<90. The linear slope can be defined from simple points such as .5/30 = 0.0166...666 or ((sqrt 2)/2)/45 = 0.0157... An exponential growth fit is sind = -0.04863185 - (-0.02464133/0.01849654)*(1 - e^(-0.01849654*x)).

Candidate models of fit include 1)quadratic and 2)exponential which appear winners of field with more than 200 entries for sine fitting functions. The fitted points on the sine curve were 0<x<90 degrees and available to double precision, E-14. Some calculations appear defaulted to single precision, E-7. The tabled chi results were from 208 equations of 2 parameters (2P) or 2 terms (t2), from the non-linear curve fit algorithm (NLCF). Undoubtedly, this would be hundreds of man-hours in paper calculations, but done automatically on the computer in three seconds or less. As might be expected, the sine, cosine, and tangent functions appear with high on the computed CHI scores, but analysis is looking for functions comparable to Taylor series and independent of trig functions, not snake eating tail. Trig functions are trivial results in this search, but leaving available in table, in case trig results jog memory.

For inclusion in the horse race of sine fitting formulas, the classic sigmoidal functions were estimated like the Richards growth curve, Weibull growth curve, Gaussian growth curve, and Gompertz growth curve, but sigmoidal chi scores were not stressing the pack. In these growth functions, the Levenberg-Marquardt (L-M) algorithm was used with double precision C's. These sigmoidal formulas were loaded into TCL procs.

Normalized trig equations. The simplest quadratic match was sind = A*X+B*X**2, solving above for 0<+X<180. However, the autosolve can also solve (A*X+B*X**2) for the angle normalized to one, as condition for 0<+X<1.0. As graphed below, the normalized solution was sin_n = 1.763*X-0.7218*X**2. The normalized sine curve has the break points of (0,0),(.5,1),and (1,0) which generate three equations, <C=0,0.25*x^2+0.5*x+1=1,x^2+x+1=0 # norm. sin> which can solved as 4*x-4*x**2 , 4*(x-x**2), or 4*x*(1-x). The normalized cosine curve has the break points of (-.5,0),(0,1),and (.5,0) which generate three equations, < 0.25*x^2-0.5*x+1=0,,+1C=0,0.25*x^2+0.5*x+1=0 #norm. cos > which can solved as 1-4*x**2. The normalized tangent curve has the break points of (-.5,-1),(0,0),and (.5,1) which generate three equations <0.25*x^2-0.5*x+1=0,+1=0,0.25*x^2+0.5*x+1=1 #norm. tan> which can solved as +2*x. The curve y= (1-A*(x-1)**2) is reasonable fit to the normalized sine. The average error on residuals to the normalized sine was -9.58E-03 or roughly ABS(.01). The curve y= (1-x**2) is reasonable fit to the normalized cosine. The average error on residuals to the normalized cosine was -6.68E-03 or roughly ABS(.01).

### Denominator in the Bhaskara Sine Formula

The analysis and others have justified the numerator in the Bhaskara sine formula, but trying to justify the denominator. The equivalent normalized denominator in the Bhaskara sine function is 4+(x+1)^2 or x^2+2*x+5. The critical point in Bhaskara's sine derivation (read genius here!) was (30 degrees,0.5 sine), which is ((1/3)*(1/2),0.5) on the normalized sine curve. The additional and fourth equation was .0277777*x^2+.16666666*x+1 =.5 or ((1/6)**2)*x^2+ (1/6)*x+1 =.5 from point (1/6,.5).Loading the equivalent fourth equation with the previous solution, the Wolfram alpha solver reported solution as (19/5)*(x-x**2). The points (0,0),(1/6,.5),(1,0) generate the equations (1/6)(1/6)*x^2+(1/6)*x+1=.5 and x^2+x+1=0, which have the solution y= -3.6*x^2+3.6*x. The points (0,0),(.5,1),(1,0) generate the equations .25*x^2+.5*x+1=.5 and x^2+x+1=0, which have the solution y= -4*x^2+4*x. For the interval (1/6)<x<.5, the normalized sine lies between the two quadratic solutions. Over the interval, the combined average function was about 0.7 percent error, expr {(.7125-(sqrt(2))/2.)/((sqrt(2))/2.)}. Tentative, but the numerator appears to be 1+f'((1/3)*x^3 + x^2+4*x).

### Console program for Bhaskara sine function

The console program below contains an angle wrap reduction procedure in degree measures for the Blaskara sine. Several dusty C++ posts have mentioned a large angle wrap error in C++ versions of angle reduction schemes, for angles of 1.E22 radians. Another post cited angle wrap reduction for trig functions as a non-trivial and unsung problem (probably in round-off error on floating points). This style error can be duplicated in the TCL proc with an input large angle and an input angle error, counting an initial error as 1E-13 and loading large angles as proc(1.0000000000001E5 degrees) returning 280.00000000999, proc(1.0...1E10 degrees) returning 280.000999, and 1.0...1E12 returning 280.0999 . The wish85 window delays returning console after loading greater magnitude angles, but the error growth will sink useful answers after inputs over 1E15 degrees.

The trial error for the console program below for pi/4 or 45 degrees was expr (0.707106-.705882)/.705882 = 0.001734 or 0.17 percent. For angles greater than -+360 degrees, an angle reduction procedure was added to evaluate only angles less than 360 degrees magnitude. The validity for the original Blaskara sine formula was positive angle in the interval from zero to 180 degrees. Blaskara was very careful in selecting his interval of validity; the published Blaskara sine table was from zero to 90 degrees. One good feature of the Bhaskara sine is that the Blaskara sine by itself is roughly accurate short of the interval end at 180 degrees or pi limit, unlike the Taylor and Pade sines which fail much beyond pi/4. For example in testcase 4, the Bhaskara sine evals 179 degrees with relative accuracy of 0.017 or 1.7 percent. Some of the other B_trig functions begin to fail after pi/4, so the valid region for each B_trig function has to be carefully checked. Extending the Bhaskara sine into other N*180 regions is possible with fold and multiply -1. statements. Additional significant figures are used to check the TCL console program, not to infer the accuracy of inputs and product reports.

### References:

• Wikipedia search engine < algorithm >

### Pseudocode & Equations Section

```        more than one formula for 1) tables and 2) console
```

## Appendix Code

### Trial

```        TCL source code follows
# pretty print from autoindent and ased editor
# Indian math Bhaskara sine formula, History of math
# written on Windows XP on TCL
# working under TCL version 8.6
# gold on  TCL Club, 3Dec2018
package require Tk
package require math::constants
namespace path {::tcl::mathop ::tcl::mathfunc math::constants}
proc degree_reduction {aa} {
if { \$aa > 360. } {
while {\$aa > 360.} {
set aa [- \$aa 360.] }
return \$aa }
if { \$aa < -360. } {
while {\$aa < -360.} {
set aa [+ \$aa 360.] }
return \$aa }
return \$aa }
# set x 45.
set x 2.
set angle_keeper \$x
set reduced_angle [ degree_reduction \$x ]
set x [ degree_reduction \$x ]
#set x [* \$x \$math::constants::degtorad ];
# sind was -pi< x >pi,
# but other trig funcs were mostly positive x < pi/2
set pi \$math::constants::pi
set bhaskara_sindx [ expr { (4.*\$x*(180.-\$x))/( 40500.-\$x*(180.-\$x)) } ]
set bhaskara_cosdx [ expr { ((4.*(90.-\$x))*(90.+\$x))/( 32400.+\$x*\$x) } ]
set bhaskara_secdx [ expr { ( 32400.+\$x*\$x)/((4.*(90.-\$x))*(90.+\$x)) } ]
set bhaskara_cscdx [ expr { ( 40500.-\$x*(180.-\$x))/(4.*\$x*(180.-\$x)) } ]
puts "&| \$bhaskara_tandx  :|tand function| |&"
puts "&| \$bhaskara_cotandx  :|cotd function | |&"
puts "&| \$bhaskara_secdx  :|secd function |  |&"
puts "&| \$bhaskara_cscdx  :|cscd function |  |&"
puts "&| \$bhaskara_cosdx  :|cosd function |  |&"
puts "&| \$bhaskara_sindx  :|sind function |  |&"
console eval {.console config -bg palegreen}
console eval {.console config -font {fixed 20 bold}}
console eval {wm geometry . 40x20}
console eval {wm title . " Indian math Bhaskara sine formula   , screen grab and paste from console 2 to texteditor"}
console eval {. configure -background orange -highlightcolor brown -relief raised -border 30}
console show
# Bhaskara sine formulas and extensions can have substantial error,
# especially beyond small angles.
# Small angles are defined here as 2 degrees or less .
# compared to  Modern TCL functions from the C math library.
# These Bhaskara  formulas were prepared for historical interest.
# This posting, screenshots, and TCL source code is
# Editorial rights and disclaimers
# retained under the TCL/TK license terms
# and will be defended as necessary in court.
# end of file```