HP Forums

Full Version: Update: 13 digit precision on HP-15c (from Palmer Hanson)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.


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

If the squares and the product are rounded to ten significant digits as is done on the HP-41 and many other HP calculators the small values beyond ten digits are discarded and the values 1.000014000, 1.000008000 and 1.000011000 remain. The rounding process discards the values of 4.9E-11, 1.6E-11 and 2.8E-11. Perform the following sequence from the keyboard of an HP-41:
     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.9000000 -11 in the display
press RCL 14 and see 1.6000000 -11 in the display
press RCL 15 and see 2.8000000 -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 do; 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 such that the values in R12, R14 and R15 should be zeroes:
SUM- subtracts x^2 from R12, y^2 from R14, and xy from R15

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 eight cases. It also presents a program which uses the "tricky properties" in a double precision routine which carries twenty digits during the calculation of the discriminant. That program obtains correct results for all eight cases. It uses eleven data registers and is quite slow. An equivalent program on my HP-41C runs for as much as ten seconds to obtain a solution. In 1991 I wrote a single precision program for the TI-59 which uses 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 single precision 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 11 or 12 significant digits. One could, of course, devise a case in which the difference between two numbers of 14 significant digits was required and my TI-59 program would fail, but the double precision HP program would succeed. 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 digits 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 stages. First, the 3 least significant digits of the ac term are accumulated in R15 using the "tricky properties". Then the 3 least significant digits of the b^2 term are accumulated in R14 using the "tricky properties". The 3 least significant digits of ac in R15 are preserved by setting y = 0 during the b^2 accumulation. Finally, the 10 most significant digits of b^2 and ac are calculated in the normal manner and combined before the smaller corrections for the least significant parts are applied. The program uses only the six data registers associated with the statistics functions. The user solves by entering the constants of the quadratic with the sequence c ENTER b ENTER a, 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. Experienced RPN programmers will surely find ways to optimize the program; after all, this is the first RPN program I have written.

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 the seventh 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


i very much like the trick of using the 13 digit precision rather than the "grannies china" version because its a lot smaller and quicker.

root finding and proximal double roots are good examples of why calculators need more precision. theres no reason why new models couldnt work internally to excess of 20 digits. it would help.

unfortunately, hps new range does do this but theyve crippled it. one of the problems of working in binary is that you have to suppress garbage. the 9g supresses at 10^-14 so b^2-4ac still gets 0. if they suppressed at less (eg 2^-80) it would solve the quadratic problem superbly.