HP Forums

Full Version: Algorithm used to find Q and Q^-1 on HP32E
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

Does anyone have the details of the algorithm used to find Q and Q^-1 on the HP32E calculator - it is obviously iterative.

I suspect that it is performing a numerical integration, probably using a Trapezoid or Simpson approximation but I have not idea which or what limits are used. The manual simply states 'The HP-32E computes Q^-1 using a sophisticated iterative algorithm.' and does not give any further clues as to how the answer is calculated.

Thanks, (in advance).

Mike T.

The algorithms use raitonal polynomials.

The HP29C program library shows a polynomial approximation used to
calculate Q(x). The error term is < 7.5 * 10^-8. The inverted function Q^-1(x) may also be approximated by a polynomial, but the error term is worse (< 4.5 * 10^-4). So it is a good guess the HP32E uses the same (or a similar) poly approximation for Q(x) and for the inverse function Q^-1(x) uses some iterative search (like interval splitting) on the more precise Q(x) approximation to find x.

Algorithm from the manual:

f(x) = exp(-x^2/2) / SQRT(2 * PI);

R(x) = f(x)* (b1*t + b2*t^2 + b3*t^3 + b4*t^4 + b5*t^5) + err(x);

where |err(x)| < 7.5e-8

t = 1 / (1 + r * abs(x));

r = 0.2316419

b1 = 0.319381530

b2 = -0.356563782

b3 = 1.781477937

b4 = -1.821255978

b5 = 1.330274429

Q(x) = [R if (x >= 0)] or [1-R if (x < 0)]

If you want to find out the truth, I'd suggest you try the above math and whether it produces the same results as the 32E does.
No warranties implied - maybe you find a typo (I didn't check it).

According to the manual, the primary source is Abramowitz and Stegun, Handbook of Mathematical Functions, National Bureau of Standards, 1970.

If the above algorithm works like the HP32E, please post a reply..
for a long time (~20years) I wanted to know what makes the HP32E Q^-1 lightshow... which is really cool, for a non-programmable calc.

best regards,
Bernhard

Thank you - I'll try this out some time.

I don't suppose you have an HP29C you can try the published program out on...? A 'quick' check of the results produced on an HP29C against the HP32E would give an indication as to the similarity of the algorithms used. Alternatively I could try implementing this on a HP34C...

Mike T.

Good reason to buy the museum disks and look at the vntage calculator manuals and solution pacs. These guides contain the math equations that show the approximations used to calclate various probability distribution functions and their inverse.

You can also find these equations (for Normal, Student-T, Chi, and F) in my book:

"Mathematical Algorithms in Visual Basic for Scietists and Engineers" by Namir C Shammas This book was published in 1996 by McGraw-Hill.

Namir

for sure, the 32e doesnt use the Abramowitz and Stegun "Hastings" approximation. at least not the standard one, although i understand there are other hasting approxes. the polynomial you mention is the one use by most programmable libraries include those of casio.

however, it is not 10 digit accurate, but the 32e is. also for inversion (ie inv Q). my guess is that it is, in fact, an iteration, as this would be less storage than the bigger polynomials needed for 10 digit accuracy. Q, erf and gamma are all related and normally require two iterative algorithms, one that converges over 0-1 and the other for x>1.

a while back, i ran some tests on this, here,
http://www.voidware.com/index.php?option=com_wrapper&page=http://www.voidware.com/calcs/hp32e.htm

in other news....

the lygea 12c emulator has added N(z) and z. which are exactly Q and inv Q. this is a huge plus for black-scholes on the 12 and why hp couldnt have done this for the 12cp, who knows. AFAIK, the lygea 12c is a true emulator and not a simulator, which means they've suceeded in adding functions to the original code (or bolted them on somehow). so this proves its possible to revise functionality.

it alsp appears to be 10 digit accurate.

http://www.lygea.com/pocket12cdetail.htm

Well, Gentlemen, I did mention in my post it was only a good guess on how the HP32E might do the calculation, did I ?

To really find out the truth, it might be worthwile to try annotate the disassembled microcode listing of the HP32E microcode.

I think this should be done with all HP calc microcode once Eric's Nonpareil is perfected to a point where there are no ambiguities left as how to the ACT chip works (= all calcs simulated perfectly).

Any volunteers ?

Regards,
Bernhard

Some book that must be - the LOWEST price I can find on Amazon is over $1500.00 !! Think I'll have to pass on that..

Hi, Namir:

Is this the book you're referring to ?

Mathematical Algorithms in Visual Basic for Scientists & Engineers

because the price is absolutely outrageous (more than $3 per page ... what was the 'new' price, then ?) and the reviews seem a little on the negative side, don't they ? Any explanation ? Lots of typographical errors at the printer's or something beyond your control ?

Best regards from V.