Algorithm of LOG or LN

Algorithm of LOG or LN

Postby mike-stgt » Thu Apr 09, 2020 8:10 am

The VASM listings for the maths routines show no comments. I am not in the position to find out the logic just by reading along the MCode. (And, BWT, I wonder if from label LN10 on only 178 lines of code could be enough.)

Question: do we have somewhere a description of the algorithms behind the keys? If not for the HP41 maybe for other models (assuming HP did not re-invent the wheel for each model)?
mike-stgt
.......
.......
 
Posts: 42
Joined: Tue Dec 24, 2019 12:12 pm

Re: Algorithm of LOG or LN

Postby jeffcalc » Sat Apr 11, 2020 11:49 am

The HP-71B IDS documents the Math code, which I believe uses the same algorithms than the HP41 but with the 71-specific features: 12-digits (15 internally) vs 10 digits (13 internally), management of the Inf and NaN quantities, signed zero, exceptions
Since the general Saturn CPU architecture is similar to the Coconut (64-bit instead of 56-bit registers with fields S, M, X, ...) it should not be too difficult for a 41-guy to read the code.
If you skip the code that manages the special HP71 cases, you will find the core code *commented* - that is, not the description of the algorithm itself but the HP71 implementation.

It would be great to reconstruct the HP41 algorithms and document the 41 VASM Math code.

J-F
User avatar
jeffcalc
....
....
 
Posts: 12
Joined: Fri Aug 28, 2009 8:57 pm

Re: Algorithm of LOG or LN

Postby mike-stgt » Sun Apr 12, 2020 12:10 am

Bonjour JF !

jeffcalc wrote:The HP-71B IDS documents the Math code, [...]


Thank you for this hint to the IDS of the 71B. Forgot it as the 71B is not my machine. But I'll have a look even I doubt that I am the one who will find the Rosetta Stone. Likewise I could read along the human DNA to understand mankind.

[...]it should not be too difficult for a 41-guy to read the code.


A 41-guy... are there still some around?
Well, some time ago I hoped NSA's Ghidra (a software reverse engineering (SRE) framework) could be of some help in this respect. Alas it even failed analysing my own PC routines (my 4-banger for example). For this I did not even try to use it for "not so much PC" software. As I know no other free SRE it is quite some drudgery. Once I used my NutEm (NUT firmware interpreter) to produce a trace of one of the HP-12C's TVM functions in the hope to get some insight. I gave up instantaneous.

If you skip the code that manages the special HP71 cases, you will find the core code *commented* - that is, not the description of the algorithm itself but the HP71 implementation.


Christoph told me, discussions accompanying the progress of the WP-34S project covered some aspects of algorithms. Maybe there are some who do know about the inner workings of the HP41.

It would be great to reconstruct the HP41 algorithms and document the 41 VASM Math code.


Yes, sure ;)

The reason why I ask is the t-shirt of David Brailsford in this video showing on his chest LB 10 = 3.322 -- What's it all about? As the subject of the video is EDSAC PC this could be a reference to Feynman, just a guess. Or is it a hint to need 4 bits for BCD? And the result, 3.322, take nearest HP41 (an emulated one at most) and with six keys hit (seven with the ON key) you have an answer with even more decimals. How does it do this? The hunger for knowledge is told to be one of the major zest in life (not for all it seems: "...still don't know what that means, but I know what it does"), so I'll try to wade through MCode from label LN10 on -- in my spare time ;)

BTW, there are still other unfathomed depth in the HP41 system, how to simulate Blinky (red eye) for example.

M.
mike-stgt
.......
.......
 
Posts: 42
Joined: Tue Dec 24, 2019 12:12 pm

Re: Algorithm of LOG or LN

Postby mike-stgt » Mon Apr 13, 2020 11:05 pm

First I had a look at the IDS of HP-71B (file 71idsv3.pdf, p. 1446ff). Alas, I am not in the position to grasp the maths behind the algorithm, even with the commentaries.

Next I produced several firmware trace logs of LN with different input in X-register, alpha, -5, 0, 1, 9, and 10 on an HP-41 (simulated under NutEm), also, but for input 10 only, on an HP-11C and -12C. Input alpha, -5, and 0 is just to easily see where the process branches to the error messages. Input 1 will not result an error but may use a short track to the answer. Comparing the files revealed following:

The procedures used in the Voyagers and in HP-41 are almost the same. Mostly XQ and GO point to a differen address as the routines do not reside at the same spot in ROM. One minor difference is the replacement of sequence C<>M, C=M used in HP-41 (@1B5D, @+1) by M=C in HP-11C (@1305). The comparison of the trace for input 9 and 10 shows the use of constants, like @8577 or @8627. In contrast, [s]I can't see similar in the firmware of the HP-71B.[/s] ((I hoped [s] would trigger strike through as in other forums.)) The constants are the same in the HP71 firmware, they are inserted as subroutine call what I overlooked at first glance.

Result: so many trees and no forest -- I am still not able to see the maths used in the a. m. models to compute LN.

Edit: Found at last the constants in HP-71B too :mrgreen:
Last edited by mike-stgt on Sat Apr 18, 2020 8:32 am, edited 1 time in total.
mike-stgt
.......
.......
 
Posts: 42
Joined: Tue Dec 24, 2019 12:12 pm

Re: Algorithm of LOG or LN

Postby jeffcalc » Thu Apr 16, 2020 8:45 pm

Hi Mike,

You can refer to this article "Personal Calculator Algorithms IV: Logarithm Functions" in HP Journal, April 1978, p.29

J-F
User avatar
jeffcalc
....
....
 
Posts: 12
Joined: Fri Aug 28, 2009 8:57 pm

Re: Algorithm of LOG or LN

Postby dlachieze » Fri Apr 17, 2020 4:50 am

And also to this article: Henry Briggs and the HP35 for an historical background.
dlachieze
....
....
 
Posts: 14
Joined: Wed Mar 11, 2009 9:39 am

Re: Algorithm of LOG or LN

Postby mike-stgt » Sat Apr 18, 2020 1:34 am

Bonjour JF!
Hello Didier!

Thank you both for the two links. That will give me plenty to do for some time.
To know about the basics and have access to the papers in question is the first step, understanding it many more ;)

Addendum: took the second step and found some time for the article JF mentioned. Thank you for this hint, perfect for me, it steps forward in chunks small enough to swallow. This article helps me to grasp the comments in the 71's IDS. What helped too was the trace I was able to take with an emulator of the 71B. Now I found the constants I missed in the IDS.

Best,
M.
mike-stgt
.......
.......
 
Posts: 42
Joined: Tue Dec 24, 2019 12:12 pm

HP41C more precise than HP71B?

Postby mike-stgt » Mon Apr 20, 2020 8:46 am

Something similar like the HP35 2.02 bug in the HP-71B? Also in HP-42S?

Beforehand: no, no bug, all is fine.

But first I was wondering. With full precision display do
Code: Select all
10
LN
ENTER^
+
e^X
on an HP41 and it returns 100 exaclty as expected. Alas on an HP-42S the result is 99,9999999992 what is not what I expected. In contrast
Code: Select all
100
LN
e^X
returns 100 -- no decimals at all. Similar with the HP-71B. I was puzzled.

What looked to me at first glance like a flaw or imperfection turns out as roundoff error. On the HP-71B the 15 digits mantissa of LOG 10 is 230258509299406 what rounded to 12 digits results correctly 2,30258509299. Doubling this also doubles the rounding error, it returns 4,60517018598 what would be 4,60517018599 if computed with 'internal precision'.

Lesson learned? To show all digits is not full precision ;)

M.
mike-stgt
.......
.......
 
Posts: 42
Joined: Tue Dec 24, 2019 12:12 pm

Re: HP41C more precise than HP71B? (no)

Postby jeffcalc » Wed Apr 22, 2020 7:01 pm

It's just a matter of chance...

If you try to compute the same starting with 20 as EXP(2*LN(20)), you will get:
400.0000004 on the 41C, and
399.999999997 on the 71B/42S .

The 71B/42S are 100x more accurate than the 41C , no doubt :D

J-F
User avatar
jeffcalc
....
....
 
Posts: 12
Joined: Fri Aug 28, 2009 8:57 pm

Re: HP41C more precise than HP71B? (no)

Postby mike-stgt » Thu Apr 23, 2020 12:04 pm

jeffcalc wrote:The 71B/42S are 100x more accurate than the 41C , no doubt :D


Yes... and a bit of No! If you do
Code: Select all
3
1/X
3
*
1
-
-- a simple computation with rational figures only -- the HP42S returns a 100 times smaller result than the HP41. So YES, it seems you are right.

Changing the point of view allows a NO at sime time. The results of LN are transcendental for all but one algebraic argument. So for sure there are infinite decimal places, only countably infinite, alas this is still infinite. The two more digits of 71B/42S, even the many more of an arbitrary precision calculator is totally nothing compared to endless. Therefore the supremacy of "100x more accurate" melts away to meaninglessness :mrgreen:

Your "no doubt" results from you point of view regarding only the approximations that are possible on almost all pocket calculators. Comparing this with maths as I do above is a bit unfair. I know ;)

M.
mike-stgt
.......
.......
 
Posts: 42
Joined: Tue Dec 24, 2019 12:12 pm

Next

Return to HP-41 Documentation

Who is online

Users browsing this forum: No registered users and 1 guest

cron