The Museum of HP Calculators

HP Forum Archive 21

[ Return to Index | Top of Index ]

A very long HP-17BII equation
Message #1 Posted by Gerson W. Barbosa on 16 Apr 2013, 12:39 a.m.

For this equation to be any practical, the HP-17BII ought to have twice as much memory and to be at least ten times as fast. The equation takes about 50 seconds to verify (this is done only once for each "trig session", however. The individual trig equations take longer to evaluate as they get deeper in the if structure (SIN and COS take less than 2 seconds, TAN takes 3 seconds, but ATAN takes about 10 seconds). Before starting a new "trig session", the variables have to be deleted, otherwise the calculator will run out of memory during the verification process. Here is the listing, even though I doubt anyone will ever key that in :-) A better idea would be using the same structure and shorter equations with limited range [-pi..pi], with arguments and outputs in radians (instead of degrees and full range).

      
Re: A very long HP-17BII equation
Message #2 Posted by Didier Lachieze on 16 Apr 2013, 1:59 a.m.,
in response to message #1 by Gerson W. Barbosa

Impressive !!

      
Re: A very long HP-17BII equation
Message #3 Posted by Mike (Stgt) on 16 Apr 2013, 4:05 a.m.,
in response to message #1 by Gerson W. Barbosa

I'd like to verify your timing in an emulated 17b2 and for that I tried to OCR this printer strip (as Christoph's Emu42 may use it). Alas the output is not of much help.

IF (S (SIN ): (1-2XIP ( 
:36~ )~lS9  ) x (2X! (K:l~ 21 
:<f: (L(Fl:MO() ( X: lSld ) XPI-:-18
to show just the first 3 lines. So I do not migrate it.

Ciao.....Mike

            
Re: A very long HP-17BII equation
Message #4 Posted by Gerson W. Barbosa on 16 Apr 2013, 9:08 a.m.,
in response to message #3 by Mike (Stgt)

Here is the forensic test sequence, as an example of usage:

Keystrokes              Display                 corresponding 
                                                HP-42S results
9 X                     X=9
SIN                     SIN=1.56434465037E-1    0.15643446504
STO X COS               COS=0.99999627274       9.99996272743E-1
STO X TAN               TAN=1.74549998542E-2    1.74549998555E-2
STO X MORE ATAN         ATAN=9.99996272875E-1   9.99996272744E-1
MORE STO X MORE ACOS    ACOS=1.56431692694E-1   1.56434441642E-1
MORE STO X MORE ASIN    ASIN=8.99983917628      8.99999864267
More examples:
3.14                    X=3.14
R~D                     R~D=179.908747671
STO X TAN               TAN=-1.59265491996E-3   tan(3.14 rad)
123456789 COS           COS=-0.98768834058
777777777717 +/- X SIN  SIN=5.2335956241E-2   
Last and most importantly, the listing in text format:
IF(S(SIN):(1-2*IP((MOD(X:360)/180)))*(2*SIGMA(K:1:21:4:(L(A:
MOD(X:180)*PI/180))^K/FACT(K))-(EXP(G(A))-EXP(-G(A)))/2)-SIN
:IF(S(COS):COS-((1-2*IP((MOD(X+90:360)/180)))*(2*SIGMA(K:1:
21:4:(L(A:MOD(X+90:180)*PI/180))^K/FACT(K))-(EXP(G(A))-EXP(-
G(A)))/2)):IF(S(TAN):TAN-((2*SIGMA(K:1:21:4:(L(A:MOD(X:180)*
PI/180))^K/FACT(K))-(EXP(G(A))-EXP(-G(A)))/2)/(2*SIGMA(
K:4:20:4:G(A)^K/FACT(K))+2-(EXP(G(A))+EXP(-G(A)))/2)):IF(S(
R~D):X*180/PI-R~D:IF(S(ASIN):ASIN-(0*(L(B:SGN(X))+L(X:ABS(X))
+0*L(F:IP(X)+1)+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(F)*G(B)*90/PI):IF(S(
ACOS):ACOS-(0*(L(X:IF(X<>-1:L(F:1)*SQRT((1-X)/(1+X)):0*L(F:-
2)+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)))*G(F)*G(B)*180/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)-LN((1+X)/(1-X))+G(V)))*G(
B)*90/PI)))))))

Cheers,

Gerson.

                  
Re: A very long HP-17BII equation
Message #5 Posted by Christoph Giesselink on 16 Apr 2013, 12:23 p.m.,
in response to message #4 by Gerson W. Barbosa

A Emu42 State file for a 17BII English ROM rev. B with the equation is available here: http://www.hpmuseum.org/guest/cgiesse/17b2trig.zip

PS. The state file has been replaced by a later version used in this thread.

Edited: 19 Apr 2013, 12:51 p.m. after one or more responses were posted

                        
Re: A very long HP-17BII equation
Message #6 Posted by Gerson W. Barbosa on 16 Apr 2013, 1:35 p.m.,
in response to message #5 by Christoph Giesselink

Thank you! Until this morning this long equation resided only in the memory of my physical HP-17B II, although I had most individual equations either on my HP-200LX or in the CPACK200 SOLVE.EQN file. I installed Emu42 this morning, but decided to use CPACK200 to edit the equation. Transferring it to the Emu42 was going to be the next step, so it was a pleasant surprise when I woke up and saw you had already done that. Thanks again!
Interestingly, on Emu42 I don't have to delete the equation variables after leaving the solver. I extracted the ROM image from an HP-17BII I don't have anymore. The serial number of my current HP-17B is 3518S07942. Like the one I sold, this is a non-international model. The available memory, when using the solver, is 2559 bytes (37%) and 2603 bytes (38%) on the emulator. When I leave the solver these change to 5287 (78%) and 5331(78%), respectively. It is a very small difference, yet I continue to get a "INSUFFICIENT MEMORY" message when I press CALC again on the calculator, unless I delete the equation variables. I've tried clearing DATA and the registers. No problem on the emulator, even under "Authentic Calculator Speed". Different ROMs, perhaps?
I feel tempted to try a longer and more accurate TAN equation, but I think this is good enough for practical purposes :-)

Edited: 16 Apr 2013, 1:40 p.m.

                              
ROM rev. check
Message #7 Posted by Christoph Giesselink on 16 Apr 2013, 2:13 p.m.,
in response to message #6 by Gerson W. Barbosa

To check the ROM revision:

  • Select "File/Settings..." and check the "Authentic Calculator Speed" option
  • Press <ON>+<SK4> together to enter the test mode
  • Press < <- > to enter the memory scanner
  • Press <.> to evaluate the displayed address

You see the ROM revision in the left corner for about 3s, im my case the two letters "BA". The first letter is standing for the main ROM rev., the 2nd for the international expanded ROM rev.

To leave the scanner press <ON>+<SK3> together.

                                    
Re: ROM rev. check
Message #8 Posted by Gerson W. Barbosa on 16 Apr 2013, 2:43 p.m.,
in response to message #7 by Christoph Giesselink

Thanks! Mine is B0 and my ROM image is B3. I was thinking of going for another B3 version (and the hassle of keying all that in again), but after MACHINE RESET after the fourth step (which doesn't delete the solver equations) I noticed the calculator is behaving like the emulator. I still have the same slightly different memory amounts reported earlier, but I don't have to delete the variables prior to entering SOLVE anymore. Apparently the machine reset has removed whatever was causing the problem.

                                          
Re: ROM rev. check
Message #9 Posted by Eric Smith on 16 Apr 2013, 2:57 p.m.,
in response to message #8 by Gerson W. Barbosa

Isn't the digit the reset log, rather than being part of the revision?

                                                
Re: ROM rev. check
Message #10 Posted by Gerson W. Barbosa on 16 Apr 2013, 3:08 p.m.,
in response to message #9 by Eric Smith

So they are both the same version B. The digits were in the rightmost side of the screen. Sorry for the confusion!

Edited: 16 Apr 2013, 3:09 p.m.

                        
(NT) Thanks again!
Message #11 Posted by Gerson W. Barbosa on 19 Apr 2013, 3:32 p.m.,
in response to message #5 by Christoph Giesselink

                  
NT: Thank you
Message #12 Posted by Mike (Stgt) on 17 Apr 2013, 6:47 a.m.,
in response to message #4 by Gerson W. Barbosa

.

      
Re: A very long HP-17BII equation
Message #13 Posted by JimP on 16 Apr 2013, 6:12 p.m.,
in response to message #1 by Gerson W. Barbosa

Monster!

Please forgive my ignorance (particularly when it comes to the L and G functions -- I'm not a skilled programmer type, and I read somewhere that these are a bit different between the variations of the 17B machines) -- has this equation been tested on the 17bII+ machines?

If not then I guess I will have to try it and see!

            
Re: A very long HP-17BII equation
Message #14 Posted by Gerson W. Barbosa on 16 Apr 2013, 7:00 p.m.,
in response to message #13 by JimP

Quote:
Monster!

It does look cryptic, the way it is written. It would look less scary if properly formatted. For instance, take a look at the following parallel between equivalent BASIC and the HP-17B Solver language codes. This is from a similar ATAN implementation.

---------------------------------------------------------

CLS DEFDBL A-M, O-Z DEFINT N, S PI = 4 * ATN(1) INPUT X S1 = SGN(X): X = ABS(X) IF X < 1 THEN X = X S2 = 1: K1 = 0 ELSE X = 1 / X S2 = -1: K1 = PI / 2 END IF IF X > (2 - SQR(3)) THEN X = (X * SQR(3) - 1) / (X + SQR(3)) K2 = PI / 6 ELSE X = X K2 = 0 END IF SUM# = 0 FOR N = 0 TO 12 SUM# = SUM# + (-1) ^ N * X ^ (2 * N + 1) / (2 * N + 1) NEXT N ATAN = (K1 + S2 * (K2 + SUM#)) * S1 * 180 / PI PRINT ATAN

-----------------------------------------------------------

ATAN=

0*(L(S1:SGN(X))+L(X:ABS(X))+

L(X:IF(X<1: L(S2:1)*X+L(K1:0) : 0*(L(K1:PI/2)+L(S2:-1))+1/X))+

L(X:IF(X>2-SQRT(3): 0*L(K2:PI/6)+(X*SQRT(3)-1)/(X+SQRT(3)) : X+L(K2:0))))+

(G(K1)+G(S2)*(SIGMA(N:0:9:1:(-1)^N*X^(2*N+1)/(2*N+1))+G(K2)))*G(S1)*180/PI

-----------------------------------------------------------

As you can see from the example, L stands for "LET" (that is, it is the attribute instruction). Likewise G stands for GET, which is used when the "gotten" variable shouldn't appear in the equations variable list.

There is an issue related to the L() and G() instructions on the HP-17BII+ which stops it from working correctly for certain equations, but I don't know exactly what it is. I only remember having read about this problem in the forum. Also, it appears there is a precedence problem with the exponentiation operator, judging from the last message in the following old thread:

http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/archv013.cgi?read=41253

By what I can remember, there are workarounds for the L() and G() problem, but I can't find them right now. It would be nice if someone ported the equation to the plus model, given its speed and larger memory. Perhaps you could test it on a small equation first.

Regards,

Gerson.

      
Re: A very long HP-17BII equation
Message #15 Posted by Eddie W. Shore on 17 Apr 2013, 8:04 a.m.,
in response to message #1 by Gerson W. Barbosa

That is a long equation. Extraordinary!

            
Re: A very long HP-17BII equation
Message #16 Posted by Gerson W. Barbosa on 17 Apr 2013, 10:02 a.m.,
in response to message #15 by Eddie W. Shore

It shouldn't be difficult to key it in, however (see below). It wouldn't require more than a couple of hours at Starbucks on a Sunday morning :-)

                  
Re: A very long HP-17BII equation
Message #17 Posted by Christoph Giesselink on 17 Apr 2013, 2:13 p.m.,
in response to message #16 by Gerson W. Barbosa

People who know me, know also that I haven't typed in the equation manually into the emulated 17BII. Therefore I'm too much an engineer.

So how I done it. First copied Gerson's text version into an ASCII file named EQU.TXT.

The mk17mac.zip package contain two programs I used AGFILTER.exe and Asc17mac.exe.

With AGFILTER < EQU.TXT > EQU.ASC I replaced the asterisk and slash characters by the correct cross and division symbol. Then I replaced the 'SIGMA' text with a small 's' with a ASCII text editor. The small 's' is a replacement for the sigma character in ASCII files when using Asc17mac. Then with Asc17mac < EQU.ASC > EQU.MAC I generated a keyboard macro file for Emu42.

Finally I started a new 17BII session created a new empty equation and then starting with "Tools/Macro/Play..." and the file EQU.MAC the "type in" process. And then I would go to Starbucks, but there's no one in the Black Forrest, and will let the computer do the rest... ;-)

Ops, I forgot to press the <Input> key and the end.

      
Re: A very long HP-17BII equation
Message #18 Posted by Dave Britten on 17 Apr 2013, 8:47 a.m.,
in response to message #1 by Gerson W. Barbosa

So what you're saying is that the time it takes to actually use this equation is longer than would be required to just dig up a scientific model elsewhere in the house? I commonly ran into the same problem when tinkering with lengthy 17BII equations.

            
Re: A very long HP-17BII equation
Message #19 Posted by Gerson W. Barbosa on 17 Apr 2013, 10:14 a.m.,
in response to message #18 by Dave Britten

Not when the equation has already been entered :-)
Actually this should be useful only to people who have only one calculator, the HP-17BII, and would need to do some trigs occasionally. Very few people, I recognize :-)

      
Re: A very long HP-17BII equation
Message #20 Posted by Gerson W. Barbosa on 17 Apr 2013, 10:00 a.m.,
in response to message #1 by Gerson W. Barbosa

Entering this long equation into the calculator at a time is very prone to errors. Even worst, spotting these
errors would be very time consuming, if not impossible at all.So, I would suggest the strategy I have used:

  • Enter this small equation with placeholders for the other missing partial equations:
    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):ATAN-(X)))))))
    
  • If there are no errors, replace the first X with the other side of the sine equation:
       1-2*IP((MOD(X:360)/180)))*(2*SIGMA(K:1:21:4:(L(A:MOD
       (X:180)*PI/180))^K/FACT(K))-(EXP(G(A))-EXP(-G(A)))/2
    
    The equation now becomes:
       IF(S(SIN):(1-2*IP((MOD(X:360)/180)))*(2*SIGMA(K:1:21:4:(L(A
       :MOD(X:180)*PI/180))^K/FACT(K))-(EXP(G(A))-EXP(-G(A)))/2)-
       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):ATAN-(X)))))))
    
  • When occasional mistakes are corrected, proceed likewise with the other functions, one at a time:

    cosine:

       (1-2*IP((MOD(X+90:360)/180)))*(2*SIGMA(K:1:21:4:(L(A:MOD
       (X+90:180)*PI/180))^K/FACT(K))-(EXP(G(A))-EXP(-G(A)))/2)
    
    tangent:
       (2*SIGMA(K:1:21:4:(L(A:MOD(X:180)*PI/180))^K/FACT
       (K))-(EXP(G(A))-EXP(-G(A)))/2)/(2*SIGMA(K:4:20:
       4:G(A)^K/FACT(K))+2-(EXP(G(A))+EXP(-G(A)))/2)
    
    arcsine:
       0*(L(B:SGN(X))+L(X:ABS(X))+0*L(F:IP(X)+1)+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(F)*G(B)*90/PI
    
    arccosine:
       0*(L(X:IF(X<>-1:L(F:1)*SQRT((1-X)/(1+X)):0*L(F:-2)+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)))*G(F)*G(B)*180/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
    
  • If this is your only solver equation, you shouldn't get a "INSUFFICIENT MEMORY" message when the equation is verified. If this happens, do a MACHINE RESET: press the ON key and the third softkey together. The already entered equation won't be lost.
  • When you're done, test each function for a few arguments distributed along its basic range. If you get a wrong result, check the respective partial equation for mistakes like wrong operators (+ instead of * or > instead of <, for instance).

  •             
    Re: A very long HP-17BII equation
    Message #21 Posted by Ken Shaw on 17 Apr 2013, 11:37 a.m.,
    in response to message #20 by Gerson W. Barbosa

    Excellent suggestion! I've often avoided entering long solver equations because of how easy it is to make a mistake, thinking the only choice was to enter the entire thing at the same time.

    Entering it in stages makes perfect sense. Thanks.

                      
    Re: A very long HP-17BII equation
    Message #22 Posted by Gerson W. Barbosa on 21 Apr 2013, 6:57 p.m.,
    in response to message #21 by Ken Shaw

    You're welcome, Ken!

    Once again I had a chance to test this method and can confirm it works. I said this equation turned the HP-17BII into a somewhat convenient basic scientific calculator. Well, I think I will reconsider this: yesterday I got an unexpected "MEMORY LOST" message without any apparent reason (except perhaps the cheap brand-less batteries I am using :-)

    I took the time to optimize the equations even further. About 200 bytes have been saved when compared to the first version:

       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
       (D~R):X*PI/180-D~R:IF(S(ASIN):ASIN-(X):IF(S(ACOS):ACOS-(X):ATAN-(X))))))))   
    
    sine:
       (-1)^INT(X/180+0*L(X:MOD(X:180)*PI/180))*(2*
       SIGMA(K:1:21:4:X^K/FACT(K))-(EXP(X)-EXP(-X))/2)
    
    cosine:
       (-1)^INT(X/180+0*L(X:MOD(X:180)*PI/180))*(2*SIGMA
       (K:4:20:4:X^K/FACT(K))+2-(EXP(X)+EXP(-X))/2)
    
    tangent
       (0*L(X:MOD(X:180)*PI/180)+4*SIGMA(K:1:21:4:X^K/FACT(K))-EXP(
       X)+EXP(-X))/(4*SIGMA(K:4:20:4:X^K/FACT(K))+4-EXP(X)-EXP(-X))
    
    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
    
    Complete equation:
    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))-(EXP(X)-EXP(-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))+2-(EXP(X)+EXP(-X))/2):IF(S(TAN):TAN-(0*L(X:MOD(X:180
    )*PI/180)+4*SIGMA(K:1:21:4:X^K/FACT(K))-EXP(X)+EXP(-X))/(4*
    SIGMA(K:4:20:4:X^K/FACT(K))+4-EXP(X)-EXP(-X)):IF(S(R~D):X*180
    /PI-R~D:IF(S(D~R):X*PI/180-D~R: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):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))))))))
    

    Running times:

     SIN:  1.8 s
     COS:  1.6 s
     TAN:  2.6 s
     R~D:  2.0 s
     D~R:  2.7 s
    ASIN:  5.2 s
    ACOS:  8.1 s
    ATAN: 10.9 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)

    Hopefully no more changes :-)

                
    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.


    [ Return to Index | Top of Index ]

    Go back to the main exhibit hall