Just stumbled upon this blag (Direct Digital Synthesis (DDS) on the GA144) with a reference to
Quote:
Computer Approximations by John F Hart, Wiley 1968; function 3300
Never heard of that before but seems to be kind of a Taylor approximation of the sine function:
Quote:
This approximation is
which is good to 17 bits between 0 and 90o.
- x(a + bx2 + cx4 + dx6)
Here's a program for the HP-42S:
00 { 31-Byte Prgm }Make sure to have the following values in the registers:
01 LBL "HART"
02 90
03 /
04 ENTER
05 X^2
06 ENTER
07 ENTER
08 RCL* 03
09 RCL+ 02
10 *
11 RCL+ 01
12 *
13 RCL+ 00
14 *
15 END
00 1.57079This table compares the values of this function with the exact result:
01 -0.64589
02 0.07943
03 -0.00433
0 0.00000 0.00000 0.000e+00The last column gives the relative error.
5 0.08716 0.08716 -3.889e-06
10 0.17365 0.17365 -3.488e-06
15 0.25882 0.25882 -2.874e-06
20 0.34202 0.34202 -2.122e-06
25 0.42262 0.42262 -1.326e-06
30 0.50000 0.50000 -5.853e-07
35 0.57358 0.57358 3.816e-09
40 0.64279 0.64279 3.667e-07
45 0.70711 0.70711 4.641e-07
50 0.76604 0.76604 3.054e-07
55 0.81915 0.81915 -4.213e-08
60 0.86603 0.86603 -4.531e-07
65 0.90631 0.90631 -7.571e-07
70 0.93969 0.93969 -7.760e-07
75 0.96593 0.96593 -3.963e-07
80 0.98481 0.98481 3.037e-07
85 0.99620 0.99619 8.426e-07
90 1.00000 1.00000 0.000e+00
Then I wondered how would that compare to a true Taylor-appoximation (with the same order 7):
0 0.00000 0.00000 0.000e+00It didn't surprise me to notice that it's more accurate for small values but looses at 90.
5 0.08716 0.08716 -9.235e-15
10 0.17365 0.17365 -2.384e-12
15 0.25882 0.25882 -6.147e-11
20 0.34202 0.34202 -6.193e-10
25 0.42262 0.42262 -3.732e-09
30 0.50000 0.50000 -1.626e-08
35 0.57358 0.57358 -5.671e-08
40 0.64279 0.64279 -1.681e-07
45 0.70711 0.70711 -4.407e-07
50 0.76604 0.76604 -1.049e-06
55 0.81915 0.81915 -2.309e-06
60 0.86602 0.86603 -4.771e-06
65 0.90630 0.90631 -9.354e-06
70 0.93968 0.93969 -1.754e-05
75 0.96590 0.96593 -3.170e-05
80 0.98475 0.98481 -5.545e-05
85 0.99610 0.99619 -9.439e-05
90 0.99984 1.00000 -1.569e-04
Kind regards
Thomas
BTW: It apears to me that sin and cos got mixed up in the referenced article.
For those interested in the Python program I used to create the tables:
#!/usr/bin/pythonfrom math import sin, radians
def hart(x):
x /= 90.
z = x*x
s = [1.57079, -.64589, 0.07943, -.00433]
return x*(s[0] + z*(s[1] + z*(s[2] + z*s[3])))def taylor(x):
z = x*x
s = [1., -1./6, 1./120, -1./5040]
return x*(s[0] + z*(s[1] + z*(s[2] + z*s[3])))for x in range(0, 91, 5):
y, z = hart(x), sin(radians(x))
# y, z = taylor(radians(x)), sin(radians(x))
t = (y - z)/z if z != 0 else y
print "%2d %8.5f %8.5f %12.3e" % (x, y, z, t)