Post Reply 
[HP 35s] Hosoda's trig program affected by bug 20?
07-24-2015, 11:10 AM (This post was last modified: 07-24-2015 11:19 AM by Marcio.)
Post: #1
[HP 35s] Hosoda's trig program affected by bug 20?
Hello all,

While playing with program based functions on the 35s, I noticed that the solver will never finish if Hosoda's program for trig functions is called from inside functions. Hosoda does make use of DSE at the beginning to save the stack registers, so I suspect 20 bug is to blame here.

For example, if you use Hosoda, try solving \(sin(x)=1\) for \(x\).

This is how I did it:

F001 LBL F
F002 RCL X
F003 XEQ H001;
F004 1
F005 -
F006 RTN

FN = F

80 \(\rightarrow\)RAD STO X

Solve for X.

For those unfamiliar with Hosoda's program, it is a nice addition to the 35s to compensate for the loss of accuracy when trig functions are used, especially in cases where the angle is very small (~1E-7) or near 90 degrees.

Our dear friend Gerald added a few enhancements to it and published the final code here.

Very much appreciated.

Marcio
Find all posts by this user
Quote this message in a reply
07-24-2015, 11:19 AM
Post: #2
RE: [HP 35s] Hosoda's trig program affected by bug 20?
If you substitute 0.5 for 1 in your programme the solver evaluation does finish.

"Enhancements" is the wrong word - I merely completed the two missing lines.
Find all posts by this user
Quote this message in a reply
07-24-2015, 11:34 AM
Post: #3
RE: [HP 35s] Hosoda's trig program affected by bug 20?
(07-24-2015 11:19 AM)Gerald H Wrote:  If you substitute 0.5 for 1 in your programme the solver evaluation does finish.

How long did it take to finish?

The 35s I have here has not yet finished since you posted this.
Find all posts by this user
Quote this message in a reply
07-24-2015, 11:49 AM
Post: #4
RE: [HP 35s] Hosoda's trig program affected by bug 20?
Sorry, my error.

Given initial value P= 0.8 after 3 minutes of evaluation the value of P was the same, so I guess the solver bug applies OR the programme messes with the solver in some way.
Find all posts by this user
Quote this message in a reply
07-29-2015, 01:42 PM (This post was last modified: 07-29-2015 04:08 PM by Marcio.)
Post: #5
RE: [HP 35s] Hosoda's trig program affected by bug 20?
Update:

The same will happen if you try to integrate a program.
Find all posts by this user
Quote this message in a reply
07-29-2015, 06:56 PM
Post: #6
RE: [HP 35s] Hosoda's trig program affected by bug 20?
(07-24-2015 11:10 AM)Marcio Wrote:  Hosoda does make use of DSE at the beginning to save the stack registers, so I suspect 20 bug is to blame here.

If that's the only reason that the solver fails then you could use a loop-unrolling:
Code:
J004 X<> 00
J005 ABS
J006 RCL 03
J007 RCL 02
J008 RCL 01
J009 RCL 00
J010 RTN

Code:
J015 RPN
J016 STO 00
J017 R↓
J018 STO 01
J019 R↓
J020 STO 02
J021 R↓
J022 STO 03
J023 R↓

I must admit that I don't understand the following lines:
Code:
J018 4
J019 STO I
J020 STO(I)
J021 DSE I

Why do we need the value 4 in register 04?

But I've noticed this line:
Code:
J066 ISG J

This might still lead to a problem when using the solver.

Kind regards
Thomas
Find all posts by this user
Quote this message in a reply
07-29-2015, 07:21 PM (This post was last modified: 07-29-2015 07:32 PM by Dieter.)
Post: #7
RE: [HP 35s] Hosoda's trig program affected by bug 20?
(07-29-2015 06:56 PM)Thomas Klemm Wrote:  If that's the only reason that the solver fails then you could use a loop-unrolling:
Code:
J004 X<> 00
J005 ABS
J006 RCL 03
J007 RCL 02
J008 RCL 01
J009 RCL 00
J010 RTN

Code:
J015 RPN
J016 STO 00
J017 R↓
J018 STO 01
J019 R↓
J020 STO 02
J021 R↓
J022 STO 03
J023 R↓

The 35s does not use direct numeric registers like the classic calculators. It uses 26 lettered variables A...Z instead. These can be accessed indirectly by negative (!) addresses, i.e. A is –1, B is –2 etc. Of course your idea can be implemented by replacing R00...R03 with A...D – or X, Y, Z and T, if you like.

The Hosoda program uses positive addresses instead. These refer to the 800+ indirect registers of the 35s. So a STO (I) with I=3 stores a value in register (003). I assume this was the preferred solution because this way the program does not interfere with the regular variables A...Z that can be accessed directly by the user.

(07-29-2015 06:56 PM)Thomas Klemm Wrote:  I must admit that I don't understand the following lines:
Code:
J018 4
J019 STO I
J020 STO(I)
J021 DSE I

Why do we need the value 4 in register 04?

I think the author wanted to make sure that at least four indirect registers are allocated. On the 35s this is done by storing a non-zero value in the highest register (here (004). Since the values on the stack may be zero, explicitly storing a non-zero number (here: 4) there (resp. the first one beyond it) makes sure that registers up to (004) are allocated. Finally (000)...(003) hold the original stack, and (004) contains a 4, which merely tells the 35s to allocate sufficient memory.

Dieter
Find all posts by this user
Quote this message in a reply
07-29-2015, 07:52 PM
Post: #8
RE: [HP 35s] Hosoda's trig program affected by bug 20?
Thanks for your answers. I forgot so many things about this calculator. Which proves that I don't use it often.

Cheers
Thomas
Find all posts by this user
Quote this message in a reply
Post Reply 




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