This page is under development. Comments are welcome, but please load any comments in the comments section at the bottom of the page. Please include your wiki MONIKER and date in your comment with the same courtesy that I will give you. Its very hard to reply reasonably without some background of the correspondent on their Wiki bio page. Thanks,[gold] ---- <> *** Subject: Indian math Bhaskara sine formula and extensions into TCL*** ***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>$xpi/2. ---- Continuing in a similar manner, the derived Bhaskara tand was expr { $bhaskara_sindx/$bhaskara_cosdx } and the derived Bhaskara tand was expr {$bhaskara_cosdx/$bhaskara_sindx }. The derived bhaskara_secdx was expr { ( 32400.+$x*$x)/(4.*(90.-$x))*(90.+$x) } and bhaskara_cscdx was expr { ( 40500.-$x*(180.-$x))/(4.*$x*(180.-$x)) } . 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 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) * 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} global bhaskara_sindx bhaskara_cosdx bhaskara_tandx angle_keeper global bhaskara_secdx bhaskara_cscdx bhaskara_cotandx reduced_angle 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 ] # uncomment below to return to radian measure #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_tandx [ expr { $bhaskara_sindx/$bhaskara_cosdx } ] set bhaskara_cotandx [ expr {$bhaskara_cosdx/$bhaskara_sindx } ] 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 # copyrighted under the TCL/TK license terms. # Editorial rights and disclaimers # retained under the TCL/TK license terms # and will be defended as necessary in court. # end of file ====== ---- ---- ---- [gold] This page is copyrighted under the TCL/TK license terms, [http://tcl.tk/software/tcltk/license.html%|%this license]. Disclaimers: This page, screenshots, and TCL source code is copyrighted under the TCL/TK license terms. Editorial rights and disclaimers retained under the TCL/TK license terms and will be defended as necessary in court. **Comments Section** <> Please place any comments here, Thanks. ---- <> Numerical Analysis | Toys | Calculator | Mathematics| Example| Toys and Games | Games | Application | GUI