Page 1 of 1

### Q function of HP-32E unveiled

Posted: Fri May 29, 2020 1:40 pm
By looking at some trace logs I found the procedures how Q is computed by HP-32E. This machine uses the same math routines as the HP-41 and uses internally 13 mantissa digits and (in case of Q) constants with 12 digits. So it is not possible to redo the approximation with an HP41 user language program (some call it FOCAL). Only a remake using MCode would do (I will not do it). An HP-42S or -71B offer more digits to the user, so on such models a user program results are the same as the HP-32E in most cases.

Used formulas:
Exact formula and approximation part 1
Q formula and p1.png (10.16 KiB) Viewed 4673 times

Approximation part 2
Q formula part2.png (8.42 KiB) Viewed 4648 times

Plots showing the approximations error.
Part 1 (used for input from -1.28 to 1.28)
Approximation 1 - (1+erf(x/sqrt(2)))/2

Just to show what this wriggling really means, the same but the limits shifted a wee bit outside the area of validity (-1.5 .. 1.5)

((this forum apparently does not allow more than three attachments, find the rest in an append))

### Re: Q function of HP-32E unveiled

Posted: Fri May 29, 2020 1:48 pm
continued...

Just to show what this wriggling really means, the same but the limits shifted a wee bit outside the area of validity (-1.5 .. 1.5)
Same from another "point of view"
Qp1err.png (10.29 KiB) Viewed 4670 times

Error of second part:
Approximation 2 - (1+erf(x/sqrt(2)))/2

On an HP-32E with "only" ten mantissa digits for the user this approximations can not be differenced from exact values.

/M.

Addendum: In case Abramowitz and Stegun are used as reference (see section 26.2), HP mixed up either the formula letter of the integration limits. In cotrast the HP-21S does comply with Abramowitz-Stegun.

### Re: Q function of HP-32E unveiled

Posted: Sat May 30, 2020 8:06 am
Thanks Mike,

It's always interesting to document internal algorithms.
I believe the Q-1(x) function is made by solving x=Q(y) for y, so there is a kind of solver in the 32E.

Is there any 41 module (HP or custom) than implements the Q Q-1functions? (I don't think so)

Anyway, it may be a good candidate for my own HP71 Math ROM 2 project

mike-stgt wrote:On an HP-32E with "only" ten mantissa digits for the user this approximations can not be differenced from exact values.

This is exactly the goal of a good approximation !

J-F

### Re: Q function of HP-32E unveiled

Posted: Sat May 30, 2020 1:00 pm
Bonjour JF !
jeffcalc wrote:It's always interesting to document internal algorithms.

It was interesting to make out from several trace logs for what purpose is this and that code section. Until few hours before the goal I was still prepared not to get there. The "documentation" or let's say description was my time to enjoy my victory.
A major portion of this victory is based on the free emulators for classic HP calculators, MultiCalc+ from Tony Nixon and the one of Bernhard Emese well hidden in his Low Power Connectivity Kit. There are few minor differences (not worth to mention), that made me use only Tony's program. May be I was only accustomed to it for some days longer.
Another big thank you to whom it may concern -- who picked the ROM content off the HP-32 (Eric Smith done it?). Without ROM copy no virtual remake would run.
I believe the Q-1(x) function is made by solving x=Q(y) for y, so there is a kind of solver in the 32E.

This is highly likely. But I do not analyse it, I leave it as an exercise for others I am done.
Is there any 41 module (HP or custom) than implements the Q Q-1functions? (I don't think so)

Well, may be one of the 1015 modules or backward incompatible updates from Ángel Martin, who knows. Frankly, I am not interested. This "translation" of the Q process to a formula was my last big effort with pocket calculators. << J'ai fait tant des projets qui sont restés en l'air... >> -- tu le connaît peut-être. https://youtu.be/bHokx2L1wi4
Anyway, it may be a good candidate for my own HP71 Math ROM 2 project

I programmed Q as HP32 in user language on a HP-42S (under Emu42), attached. It offers few digits more to the user than HP-41, Voyagers, HP-67 or similar, on those machines you have no chance to enter the constants completely, in addition each intermediate step is rounded to 10 mantissa digits, so you will not be happy with the results compared to an HP-32E. On an HP42 the results are more accurate but still differ every now and then. May be rounding the result to 10 digits could ensure the same result as on the ancient Spice model.

Mille kilos de m... pour ton HP71 Math ROM 2 project! I keep my fingers crossed.

Bien cordialement
M.

Edit: removed attachment, find a correction in another thread.

### Re: Q function of HP-32E unveiled

Posted: Sat May 30, 2020 11:03 pm
@Mike - Thanks for sharing this Mike, just this week I read how the 32E is the only machine with this built-in (though the 21S does seem to have several Q() functions, and IIRC, the 50g does as well, maybe even the 49g, etc.).

A few questions:

1. "...looking at some Trace Logs..." Trace Logs from where?

2. What is special about 1.28? Is this from data fit related to the constants used, or something else?

3. In Part-2, it cannot be both for X <= 1.28 and for x >= 1.28, I assume it should be X < 1.28 as in Part-1

@J-F - Yes, a perfect candidate for the Math ROM Ver 2. Exactly the kind of thing that should go in there.

### Re: Q function of HP-32E unveiled

Posted: Sun May 31, 2020 12:57 am
rprosperi wrote:1. "...looking at some Trace Logs..." Trace Logs from where?

From one of the emulators mentioned here.
2. What is special about 1.28? Is this from data fit related to the constants used, or something else?

There is nothing special. It is what I found -- and anybody else may find -- in the ROM of the HP-32E as published with the a. m. emulators.
3. In Part-2, it cannot be both for X <= 1.28 and for x >= 1.28, I assume it should be X < 1.28 as in Part-1

Wrong. Corrected.

### Re: Q function of HP-32E unveiled

Posted: Sun May 31, 2020 1:10 pm
Thanks Mike.

### Re: Q function of HP-32E unveiled

Posted: Mon Jun 01, 2020 12:55 pm
jeffcalc wrote:Anyway, it may be a good candidate for my own HP71 Math ROM 2 project

I suppose as basis for the HP71 the HP-21S procedures would fit better than the approximations of HP32 -- those are ideal on a Spice- or Nut-CPU I assume.

Remains the task to get the HP21 method. With almost no insight to the 'Bert' hardware I found (only by staring at the trace log) for input x=3 and 6 some iterative approach by adding and subtracting corrections from 1/(x*sqrt(2Pi*e^(x^2))) as start point. Other input seems to take another path.

Now -- who of the experts wants to be part of the solution for this problem? Who is first to find the still stashed secrets of the HP-21S? Take on your miner's helmet and shet some light to spots no-one was before

### Re: Q function of HP-32E unveiled

Posted: Wed Jun 17, 2020 2:48 am
Q and a corrected version of Q-1 for HP-42S under Emu42 or similar.
Note: the inverse Q-1 runs the solver with Q. Q-1 is not a migration of the HP-32E method.

### Re: Q-1 function of HP-32E unveiled

Posted: Sun Apr 17, 2022 1:49 pm
jeffcalc wrote:I believe the Q-1(x) function is made by solving x=Q(y) for y, so there is a kind of solver in the 32E.

I may confirm: yes, there are even two of them, one is Newton's method perfectly schoolbook-like, the other... works, alas I don't know why. But I found an error in the setup of the iteration, which is ironed out by one, maybe two more loops.
Find algorithms and formulas in attached PDF.