Post Reply 
A very long HP-17BII equation - Update
12-15-2014, 05:48 PM (This post was last modified: 12-17-2014 01:54 AM by Gerson W. Barbosa.)
Post: #1
A very long HP-17BII equation - Update
After replacing the batteries of my HP-17BII I entered the equation in message #22 of the original thread (not a single error in the first try, just to show this is possible :-). Then I checked the functions for arguments close to 1 and near zero and noticed a significant loss of accuracy for certain arguments. For example:


sin(0.0000010) 1.7455(0850398)E-8
tan(0.0000010) 1.745(50000000)E-8
asin(0.000001) 5.7295(8368089)E-5
acos(0.999999) 8.1028474(8648)E-2
atan(0.000001) 5.7295(8368089)E-5

This update fixes that:

sin(0.0000010) 1.74532925199E-8
tan(0.0000010) 1.74532925199E-8
asin(0.000001) 5.72957795131E-5
acos(0.999999) 8.1028475206(4)E-2
atan(0.000001) 5.72957795131E-5

Also, COS is now slightly more accurate for small arguments and the forensic result is better:

Keystrokes Display corresponding
HP-42S results

9 DSP ALL X X=9
SIN SIN=1.56434465039E-1 0.15643446504
STO X COS COS=9.99996272738E-1 9.99996272743E-1
STO X TAN TAN=1.74549998553E-2 1.74549998555E-2
STO X MORE ATAN ATAN=9.99996272738E-1 9.99996272744E-1
MORE STO X MORE ACOS ACOS=1.56434567554E-1 1.56434441642E-1
MORE STO X MORE ASIN ASIN=9.00000594679 8.99999864267

Fortunately the HP-17BII solver has the LNP1(x)and EXPM(x) functions, which have allowed for this easy fix:

Code:

IF(S(SIN):(-1)^INT(X/180+0*L(X:MOD(X:180)*PI/180))*(2*SIGMA(K
:1:21:4:X^K/FACT(K))-(EXPM1(X)-EXPM1(-X))/2)-SIN:IF(S(COS):
COS-(-1)^INT(X/180+0*L(X:MOD(X:180)*PI/180))*(2*SIGMA(K:4:20:
4:X^K/FACT(K))+1-(EXPM1(X)+EXPM1(-X))/2):IF(S(TAN):TAN-(0*L(X
:MOD(X:180)*PI/180)+4*SIGMA(K:1:21:4:X^K/FACT(K))-EXPM1(X)+
EXPM1(-X))/(4*SIGMA(K:4:20:4:X^K/FACT(K))+2-EXPM1(X)-EXPM1(-X
)):IF(S(DEG):X*180/PI-DEG:IF(S(RAD):X*PI/180-RAD:IF(S(ASIN):
ASIN-(0*(L(B:SGN(X)+IP(X))+L(X:ABS(X))+L(X:IF(X<>1:X/SQRT(1-
SQ(X)):X))+L(X:IF(X<1:L(A:1)*X+L(Q:0):0*(L(Q:PI)+L(A:-1))+INV
(X)))+L(X:IF(X>SQRT(2)-1:0*L(V:PI/2)+(X-1)/(X+1):X+L(V:0))))+
(G(Q)+G(A)*(4*SIGMA(K:1:29:4:X^K/K)-LNP1(2*X/(1-X))+G(V)))*G(
B)*90/PI):IF(S(ACOS):ACOS-(0*(L(X:IF(X<>-1:SQRT((1-X)/(1+X)):
X))+L(B:SGN(X))+L(X:ABS(X))+L(X:IF(X<1:L(A:1)*X+L(Q:0):0*(L(Q
:PI)*L(A:-1))+INV(X)))+L(X:IF(X>SQRT(2)-1:0*L(V:PI/2)+(X-1)/(
X+1):X+L(V:0))))+(G(Q)+G(A)*(4*SIGMA(K:1:29:4:X^K/K)-LNP1(2*X
/(1-X))+G(V)))*(3-G(B))*90/PI):ATAN-(0*(L(B:SGN(X))+L(X:ABS(X
))+L(X:IF(X<1:L(A:1)*X+L(Q:0):0*(L(Q:PI)+L(A:-1))+INV(X)))+L(
X:IF(X>SQRT(2)-1:0*L(V:PI/2)+(X-1)/(X+1):X+L(V:0))))+(G(Q)+G(
A)*(4*SIGMA(K:1:29:4:X^K/K)-LNP1(2*X/(1-X))+G(V)))*G(B)*90/PI
))))))))

This takes almost one minute to verify, but once it has been verified all trigonometric and other mathematical functions can be executed without leaving the solver (if the MATH menu is invoked, EXIT will return to the solver and the already verified equation).

The equation can be more easily entered into the HP-17BII by entering the following small equation first and then replacing each underlined X with its respective equation:

IF(S(SIN):X-SIN:IF(S(COS):COS-X:IF(S(TAN):TAN-X:IF(S(DEG):X*180/PI-DEG:IF(S
(RAD):X*PI/180-RAD:IF(S(ASIN):ASIN-(X):IF(S(ACOS):ACOS-(X):ATAN-(X))))))))


sine:

Code:

   (-1)^INT(X/180+0*L(X:MOD(X:180)*PI/180))*(2*SIGMA
   (K:1:21:4:X^K/FACT(K))-(EXPM1(X)-EXPM1(-X))/2)

cosine:

Code:

   (-1)^INT(X/180+0*L(X:MOD(X:180)*PI/180))*(2*SIGMA
   (K:4:20:4:X^K/FACT(K))+1-(EXPM1(X)+EXPM1(-X))/2)

tangent:

Code:

   (0*L(X:MOD(X:180)*PI/180)+4*SIGMA(K:1:21:4:X^K/FACT(K))-EXPM1(X)
   +EXPM1(-X))/(4*SIGMA(K:4:20:4:X^K/FACT(K))+2-EXPM1(X)-EXPM1(-X))

arcsine:

Code:

   0*(L(B:SGN(X)+IP(X))+L(X:ABS(X))+L(X:IF(X<>1:X/SQRT(1-SQ(X)):X))+L(X:IF(X<1:L(A:1)
   *X+L(Q:0):0*(L(Q:PI)+L(A:-1))+INV(X)))+L(X:IF(X>SQRT(2)-1:0*L(V:PI/2)+(X-1)/(X+1):
   X+L(V:0))))+(G(Q)+G(A)*(4*SIGMA(K:1:29:4:X^K/K)-LNP1(2*X/(1-X))+G(V)))*G(B)*90/PI

arccosine:

Code:

   0*(L(X:IF(X<>-1:SQRT((1-X)/(1+X)):X))+L(B:SGN(X))+L(X:ABS(X))+L(X:IF(X<1:L(A:1)*X+
   L(Q:0):0*(L(Q:PI)*L(A:-1))+INV(X)))+L(X:IF(X>SQRT(2)-1:0*L(V:PI/2)+(X-1)/(X+1):X+L
   (V:0))))+(G(Q)+G(A)*(4*SIGMA(K:1:29:4:X^K/K)-LNP1(2*X/(1-X))+G(V)))*(3-G(B))*90/PI

arctangent:

Code:

   0*(L(B:SGN(X))+L(X:ABS(X))+L(X:IF(X<1:L(A:1)*X+L(Q:0):0*(L(Q:PI)+L(A:
   -1))+INV(X)))+L(X:IF(X>SQRT(2)-1:0*L(V:PI/2)+(X-1)/(X+1):X+L(V:0))))+
   (G(Q)+G(A)*(4*SIGMA(K:1:29:4:X^K/K)-LNP1(2*X/(1-X))+G(V)))*G(B)*90/PI


Running times:

SIN: 2.0 s
COS: 1.8 s
TAN: 2.8 s
DEG: 2.3 s
RAD: 2.8 s
ASIN: 5.3 s
ACOS: 8.2 s
ATAN: 11.0 s

Ranges:
SIN, COS, TAN: -999 999 999 999 to 999 999 999 999 (1)
ASIN & ACOS: -1 to 1
ATAN: 1E-11 < |X| <= 9.99999999999E-499 (2)
(1) For odd multiples of 90 degrees, TAN returns 249999999996, which should be regarded as infinity
(2) Exponents equal or greater than 18 will cause UNDERFLOW, but the results will be correct (either -90 or +90 degrees)

Some usage examples:

3 X X=3
DEG DEG=171.887338539 ; 3 rad = 171.887338539°
STO X TAN TAN=-1.42546543094E-1 ; tan(3 rad) = -1.42546543094E-1
123456789 X COS COS=-9.87688340595E-1 ; cos(123456789) = -9.87688340595E-1
777777777717 +/- X SIN SIN=5.2335956243E-2 ; sin(-777777777717°) = 5.2335956243E-2
0.5 X MORE ACOS 60.0000000002 ; acos(0.5) = 60.0000000002°
MORE STO X MORE RAD 1.0471975512 ; acos(0.5) = 1.0471975512 rad
shift MATH 3 LN 1.09861228867
2 +/- / EXP EXIT 5.77350269189E-1
MORE STO X MORE ATAN ATAN=30.0000000001 ; atan(exp(-ln(3)/2)) = 30.0000000001°

The above equation has been tested on the HP-200LX. On the HP-17BII, replace SIGMA with the Greek letter, as in the picture:

[Image: HP-17BIITrigs_zps0cf0ecaa.png]

You might also want to download a state file for Christoph Gießelink's Emu42 emulator (please change the extension to .e17).

P.S.: I forgot to mention that this equation is no so long as the equation in the original thread. Now it's "only" 1133-character long, 50 characters shorter than the older equation. Unlike then, I haven't experienced any "INSUFFICIENT MEMORY" message.

The following old threads give a clue about the formulas I used:

Mardi Gras Basic Trigs (HP-12C)

Easter Sunday Basic Trigs (HP-12C)

Formatting has been lost in the tables. I have yet to find out how to fix that.


Attached File(s)
.txt  17BIITRIG.txt (Size: 17.39 KB / Downloads: 13)
Find all posts by this user
Quote this message in a reply
12-16-2014, 03:41 PM (This post was last modified: 12-16-2014 03:42 PM by Dave Britten.)
Post: #2
RE: A very long HP-17BII equation - Update
That's as impressive as it is horrifying. I think I'd reach for my Pickett before resorting to keying that in and spending an hour looking for the one character I mistyped. Smile
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)