Re: A very long HP-17BII equation Message #23 Posted by Gerson W. Barbosa on 19 Apr 2013, 12:37 a.m., in response to message #20 by Gerson W. Barbosa
In order to make room for D~R (Degrees to Radians Conversion), some optimizations have been made. The same instructions in the previous post apply to the new equations, that is, every underlined X in the first equation should be replaced by the proper equation, one at time:
IF(S(SIN):X-SIN:IF(S(COS):COS-X:IF(S(TAN):TAN-X:IF(S(R~D):X*180/PI-R~D:IF(S
(ASIN):ASIN-(X):IF(S(ACOS):ACOS-(X):IF(S(ATAN):ATAN-(X):X*PI/180-D~R)))))))
sine:
(0.5-IDIV(MOD(X:360):180))*(4*SIGMA(K:1:21:4:(L(A:
MOD(X:180)*PI/180))^K/FACT(K))-EXP(G(A))+EXP(-G(A)))
cosine:
(0.5-IDIV(MOD(X+90:360):180))*(4*SIGMA(K:1:21:4:(L(A:
MOD(X+90:180)*PI/180))^K/FACT(K))-EXP(G(A))+EXP(-G(A)))
tangent
(SIGMA(K:1:21:4:(L(A:MOD(X:180)*PI/180))^K/FACT(K))-(EXP(G(A))-EXP(
-G(A)))/4)/(SIGMA(K:4:20:4:G(A)^K/FACT(K))+1-(EXP(G(A))+EXP(-G(A)))/4)
arcsine:
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)-LN((1+X)/(1-X))+G(V)))*G(B)*90/PI
arccosine:
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)-LN((1+X)/(1-X))+G(V)))*(3-G(B))*90/PI
arctangent:
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)-LN((1+X)/(1-X))+G(V)))*G(B)*90/PI
Here is the complete equation:
IF(S(SIN):(INV(2)-IDIV(MOD(X:360):180))*(4*SIGMA(K:1:21:4:(L(A:
MOD(X:180)*PI/180))^K/FACT(K))-EXP(G(A))+EXP(-G(A)))-SIN:IF(S
(COS):COS-(INV(2)-IDIV(MOD(X+90:360):180))*(4*SIGMA(K:1:21:4:(L(
A:MOD(X+90:180)*PI/180))^K/FACT(K))-EXP(G(A))+EXP(-G(A))):IF(
S(TAN):TAN-(SIGMA(K:1:21:4:(L(A:MOD(X:180)*PI/180))^K/FACT(K)
)-(EXP(G(A))-EXP(-G(A)))/4)/(SIGMA(K:4:20:4:G(A)^K/FACT(K))+1
-(EXP(G(A))+EXP(-G(A)))/4):IF(S(R~D):X*180/PI-R~D: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)-LN((1+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)-LN((1+X)
/(1-X))+G(V)))*(3-G(B))*90/PI):IF(S(ATAN):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)-LN((1+X)/(1-X))+G(V)))
*G(B)*90/PI):X*PI/180-D~R)))))))
That's exactly the text I've used to create a macro for Emu42. Just follow Christoph Giesselink's instructions elsewhere in this thread.
Approximate running times on the real HP-17BII:
SIN: 1.8 s
COS: 1.8 s
TAN: 2.9 s
R~D: 2.1 s
ASIN: 4.5 s
ACOS: 7.0 s
ATAN: 9.5 s
D~R: 10.5 s
D~R is there just for the lazy ones like me. PI shift MTH PI * 180 / EXIT is much faster than X STO MORE R~D :-) If D~R is used quite often, perhaps it should be better to place it just after R~D, in the beginning of the second menu line (but this might delay the inverse functions a bit more). The equation verification time is about 50 seconds (only a few tenths of seconds on the emulator), but this has to be done only in the beginning of a solver session. Notice you can leave the solver (without pressing the EXIT key), go to the MTH menu and back to the solver (by pressing EXIT) as many time as needed, which makes the HP-17BII with this equation a somewhat convenient basic scientific calculator.
----------- P.S.: I've changed the constants 0.5 in the complete equation above to INV(2) in order to avoid an "INVALID EQUATION" error when the radix mark is comma. Otherwise it would be necessary to edit the equation manually to change both instances of the constant to 0,5. It appears INV(2) takes up a few bytes less than 0.5, but I still have to check this out.
Edited: 19 Apr 2013, 2:37 a.m.
|