The 13 digit capability of the 15c (From Palmer Hanson...former TI PPC editor)


Hi all. This is part of an email that palmer hanson sent me. He is famous for being the editor of the TI PPC Notes for many years and to us HP fans as part of the Fast Calendar Printer challenge from around 1980. He had the fastest TI calendar printer program, which Roger Hill amazed us all by beating it with a very fast big 41c program. Anyway, what are your thoughts about the material below?

Valentin, this would seem to be right up your alley. :-) Remember, guys...Palmer hasn't spent years programming HP's, so if his program overlooks something, be NICE. :-) --Gene

I have mentioned earlier that I was trying to understand the 13 digit capability which appeared in a footnote in the HP-15C Advanced Functions Handbook.  I think I understand some of it and I used it to write a quadratic program for the HP-41 which uses 13 digits in the calculation of the determinant.  I have added the draft of my documentation to this e-mail.  When I figure out how to make attachments I will send it by that format.  What intrigues me is the existence of a truncated (not rounded) 13 digit capability in an HP product. Do you remember the old HP vs TI comparisons in which the HP folks insisted that ten rounded digits were superior to thirteen truncated digits? 
We start with an arithmetic exercise using the statistical functions of the HP-41:

Consider the numbers  x   = 1.000007
                          y   = 1.000004
                      x^2 = 1.000014000049
                      y^2 = 1.000008000016
                      xy  = 1.000011000028
where the squares and the product round to 1.000014, 1.000008 and 1.000011 respectively on the HP-41.  Perform the following sequence from the keyboard:
     CLSUM                clears the statistical registers
     1.000014 ST- 12      negative of the rounded value of x^2 to R12 
     1.000008 ST- 14      negative of the rounded value of y^2 to R14
     1.000011 ST- 15      negative of the rounded value of xy to R15
     1.000004 ENTER
     1.000007 SUM+        adds x^2 to R12, y^2 to R14, and xy to R15
     press RCL 12 and see 4.9E-11 in the display
     press RCL 14 and see 1.6E-11 in the display
     press RCL 15 and see 2.8E-11 in the display
where the contents of registers 12, 14 and 15 contain the values which were discarded during rounding of the squares and product.  If you reverse the sequence and do the statistical entry first and then subtract the rounded squares and product from registers 12, 14 and 15 you will find that there are zeroes in those registers.
Another arithmetic exercise using the statistical functions: 
Consider the numbers  x   = 111,111
                      y   = 1,111,111,111
                      x^2 = 12,345,654,321
                      y^2 = 1,234,567,900,987,654,321
                      xy  = 123,456,666,654,321
where in the HP-41 the squares and the product round to
                      x^2 = 1.234565432E10  displayed as 1.2345654 10 
                      y^2 = 1.234567901E18  displayed as 1.2345679 18
                      xy  = 1.234566667E14  displayed as 1.2345666 14
where to see the actual ten digit mantissas you multiply the displayed values by 1E-10, 1E-18 and 1E-14 respectively.
Perform the following sequence from the keyboard:
     CLSUM            clears the statistical registers
     SUM+            adds x^2 to R12, y^2 to R14, and xy to R15
where we expect the rounded values to appear in those registers, and for example for y^2, by performing the following sequence
     RCL 14     1.2345679 18 in the display
     CHS        1       - 18 in the display
     X          1.234567901  in the display 
Now, perform the following sequence which, according to the description of the statistical functions on pages 103-104 of the owner's handbook, should remove the entered values from the statistical registers.  If so, the values recalled from R12, R14 and R15 should be zeroes.  But,
    RCL 12 yields -1
    RCL 14 yields 13,000,000
    RCL 15 yields 45,700
The result in R12 can be obtained by subtracting the exact eleven digit square of 111,111 from the HP-41 square of 111,111 with a ten digit mantissa; that is,
          1.234565432E10 is   12,345,654,320                       
                            - 12,345,654,321
                            =             -1
The results in R14 and R15 can be obtained by subtracting values for y^2 and xy which use truncated (not rounded) thirteen digit mantissas from values which use rounded ten digit mantissas; that is,
for R14   1.234567901E18 is   1,234,567,901,000,000,000   
                            - 1,234,567,900,987,000,000
                            =                13,000,000
for R15   1.234566667E14 is   123,456,666,700,000
                            - 123,456,666,654,300
                            =              45,700
I obtain the same results with my HP-11C.  I believe these results are a part of what was described as "... a tricky property of the Sum+ and Sum- keys whereby certain calculations can be carried out to 13 significant digits before being rounded back to 10" in a footnote on page 208 of the HP-15C Advanced Functions Handbook.  I do not get similar effects with older HP calculators such as the HP-33C, HP-67 and HP-80.
Pages 205-211 of the HP-15C Advanced Functions Handbook proposes eight cases for evaluating the ability of a quadratic program to solve difficult cases.  It presents a single precision program for the HP-15C which can obtain correct results for only three of the cases.  It also presents a program which carries twenty digits during the calculation of the discriminant. That program obtains correct results for all eight cases, but uses eleven data registers.  It is also quite slow.  An equivalent program on my HP-41C runs for as much as ten seconds to obtainn a solution.  In 1991 I wrote a similar program for the TI-59 which computes using truncated thirteen digit mantissas as opposed to the rounded ten digit mantissas used with the HP-11, HP-15 and HP-41.  My TI-59 program obtained correct results for seven of the eight cases.  It failed for the seventh case where the discriminant is the single digit difference between two twenty digit numbers.  That program and similar programs for the TI-74, TI-81 and Casio fx-7000G are described on pages 8-13 of the Volume 14 Number 3 issue of TI PPC Notes.
The four cases which a TI-59 program solves correctly but a single precision HP-41C program solves incorrectly all involve discriminants which are calculated as the difference between two numbers of more than 10 significant digits but less than 14 significant digits.  Using the insight into the "tricky properties" of the Sum+ and Sum- functions derived from the numerical exercises above I decided to write an HP-41 program which carries 13 significant dgits during the calculation of the discriminant.  Such a program should yield correct solutions to seven of the eight cases, use fewer registers and use less run time.
The program follows the convention in the HP-15C Advanced Functions Handbook where the quadratic is defined as c - 2bx + ax^2 = 0 and the discriminant is calculated as d = b^2 - ac .  That definition reduces the size of the two parts of the discriminant by a factor of four. The program calculates the terms of the discriminant in two parts.  The 10 most significant digits of are calculated in the normal manner.  The 3 least significant digits are calculated using the "tricky properties".  The most significant parts are combined before the smaller corrections for the least significant  parts are made.  The program uses only the six data registers associated with the statistics functions.  The 3 least significant digits of the term ac which are accumulated in R15 are preserved by setting y = 0 during the accumulation of the 3 least significant digits of b^2 in R14.  The user solves by entering the constants of the quadratic with the sequence c ENTER b ENTER and running the program.  For real roots the program stops with one root in the display.  The second real root is displayed by pressing x<>y.  If the solution is complex Flag 0 is set. The program stops with the real part in the display.  The imaginary root is displayed by pressing x<>y where + and - signs for the imaginary part are implied.  Thr run time is of the order of one second.  The program listing follows.
02 CF 00
03 RCL Z
05 ST- 15
06 X<>Y
07 ST* 15
08 SUM+
09 CLX
10 STO 13
11 STO 14
12 RCL Z
13 ST- 14
14 ST* 14
15 X<>Y
16 SUM+
17 RDN
18 X^2
19 X<>Y
20 STO 12
21 RCL 11
22 *
23 -
24 RCL 14
25 +
26 RCL 15
27 -
28 X<0?
29 GTO A
30 RCL 11
31 RDN
33 X<>Y
35 *
36 +
37 STO 16
38 X<>Y
39 /
40 RCL 16
41 X =/0?  (X not equal to zero)
42 GTO B
43 CLX
44 GTO C
45 LBL B
46 RCL 12
47 X<>Y
48 /
50 LBL A
51 SF 00
52 CHS
54 RCL 11
55 /
57 RCL 13
58 X<>Y
59 /
61 END
This program will yield the correct answers to seven of the eight cases proposed in the HP-15C Advanced Functions Handbook. The exception is the seventh case from the text on page 211 where
c = 4,877,163,849, b = 4,877,262,613 and a = 4,877,361,379.  Then 
   d = (4,877,262,613)^2 - 4,877,361,379 x 4,877,163,849
     = 23,787,690,596,167,587,769 - 23,787,690,596,167,587,771
     = -2
so that twenty significant digits must be carried to yield the correct answer for d. The following program is a conversion of the double precision program from pages 208-210 of the HP-15C Advanced Functions Handbook which will solve this case.  The program runs for about ten seconds to obtain the solution.  The roots are complex with the Re = 0.999979750 and Im = 2.8995463E-10. The HP-15C program requires 84 steps.  My translation for the HP-41C requires 88 steps where the increase in steps is the lack of the combined commands such as RCL + which are used in the HP-15C program but are not available on the HP-41C.
02 CF 00
03 STO 04
04 RDN
05 STO 06
06 STO 08
07 X<>Y
08 STO 07
09 STO 09
10 SCI 2
11 LBL A
13 RCL 08
14 STO 15
15 RCL 04
16 /
17 RND
18 RCL 04
19 SUM -
20 RCL 09
21 RCL 15
22 X<>Y
23 STO 15
24 RDN
25 X<>Y
26 RCL 08
27 SUM -
28 RDN
29 SUM -
30 RCL 15
31 ABS
32 RCL 09
33 ABS
34 X<=Y?
35 GTO B
37 R^
38 STO 08
39 RCL 15
40 STO 09
41 ABS
42 1 E20
43 *
44 RCL 07
45 ABS
46 X<=Y?
47 GTO A
48 LBL B
49 FIX 9
50 RCL 08
51 X^2
52 STO 15
53 RCL 04
54 RCL 09
55 SUM -
56 RCL 06
57 RCL 15
58 X<0?
59 GTO D
61 RCL 06
63 *
64 +
65 STO 16
66 X<>Y
67 /
68 RCL 16
69 X/=0?  X is not equal to zero
70 GTO C
71 CLX
73 LBL C
74 RCL 07
75 X<>Y
76 /
78 LBL D
79 SF 00
80 CHS
82 RCL 04
83 /
84 X<>Y
85 R^
86 /
88 END


interesting indeed.

this is a good example of something superficially trivial but actually complicated to do properly. of course anyone can bang out the textbook quadratic formula. but there are times like these examples when it just doesnt work.

i too have been through the material int the 15c advanced function handbook. i am wondering what is the most stable implementation of this problem (and more generally, polynomial roots). i dont really like the "trick" of using the stats to access extra precision as a general method, although theres no harm in making use of it on the 15c where its available.

here are some ideas ive tried...

(1) use the textbook formula and let d=b^2-4ac go a bit wrong, but then polish the roots using a single newton iteration with no loop. to fix d~0 multiple root problems, i add a small "hack" factor to the roots (eg multiply resp (1+1e-7) and (1-1e-7)) before the newton iteration and this works well to recover information lost in `d'. if you perform the newton iteration in complex mode and add a complex perturbation instead, you can also recover errors in the sign of d. ie whether you've got complex roots or real ones. what happens is the complex roots become real if d < 0 and shouldnt have been.

BUT, case7 fails in the above. this is because the newton iteration winds up repeating a b^2-4ac style calculation that leads to bits being lost. basically case7 has numbers too large to handle.

(2) compute the roots as eigenvalues of a hessenberg matrix. ive tried this too. ive also wondered if theres a suave way of using the matrix functions of the 15c to make this work with very little programming. anyway, you balance the matrix and this helps bad coefficients a lot. all the cases work except case7 again! where the algorithm doesnt notice the complex part and thinks you have two (slightly different) real roots.

this method is much more complex, but surprisingly stable. the other win is, memory permitting, you have a program for arbitrary roots of real-coefficient polynomials.


Hello, Gene;

I printed it and read, did not try any of the examples neither the programs, but it's not exactly necessary to do it, because the text is quite clear and the subject is very well explained.

Thank you again for sharing with us all.

Best regards.

Luiz (Brazil)


It is a real shame TI quit making higher end programmables when they did. The TI group had a lot to offer and the friendly competition helped both sides learn how to program better.

If only TI had introduced the TI-59 follow-up machine (The TI-88) instead of shelving it.

Possibly Related Threads...
Thread Author Replies Views Last Post
  HP PRIME : strange behavior when trying user key capability Damien 12 1,326 11-03-2013, 11:02 AM
Last Post: Joe Horn
  HP Prime editor errors Alberto Candel 0 324 10-22-2013, 01:34 AM
Last Post: Alberto Candel
  Prime Program Editor Bug Dougggg 8 820 10-09-2013, 10:56 PM
Last Post: Han
  HP Prime 2013 8 13. Rev:5106 bluesun08 2 430 09-28-2013, 11:05 AM
Last Post: debrouxl
  Updated PPC DVD Version 2.10: HP-41 Searchable Program Files and Scannable Barcode Jake Schwartz 3 601 09-27-2013, 09:51 PM
Last Post: Olivier (Wa)
  A HP42S Code Editor Andreas 9 1,031 09-22-2013, 03:17 AM
Last Post: Andreas
  Strings inside matrix editor on 50g Chris Smith 3 483 05-22-2013, 04:04 PM
Last Post: Chris Smith
  PPC ROM Price Fouad M. Kaadou 7 778 05-17-2013, 01:03 PM
Last Post: Dave Shaffer (Arizona)
  PPC Rom Barcodes John Abbott (S. Africa) 7 745 05-11-2013, 09:05 AM
Last Post: John Abbott (S. Africa)
  happy fibonacci day 5/8/13 Allen 8 1,022 05-09-2013, 01:48 AM
Last Post: Gerson W. Barbosa

Forum Jump: