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?

AN EXTENDED QUADRATIC SOLUTION FOR THE HP-41 USING THIRTEEN DIGIT CALCULATION OF THE DETERMINANT

We start with an arithmetic exercise using the statistical functions of the HP-41:

Consider the numbers x = 1.000007where 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:

y = 1.000004

x^2 = 1.000014000049

y^2 = 1.000008000016

xy = 1.000011000028

CLSUM clears the statistical registerswhere 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.

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

Another arithmetic exercise using the statistical functions:

Consider the numbers x = 111,111where to see the actual ten digit mantissas you multiply the displayed values by 1E-10, 1E-18 and 1E-14 respectively.

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 we expect the rounded values to appear in those registers, and for example for y^2, by performing the following sequence

Perform the following sequence from the keyboard:

CLSUM clears the statistical registers

1,111,111,111

ENTER

111,111

SUM+ adds x^2 to R12, y^2 to R14, and xy to R15

RCL 14 1.2345679 18 in the displayNow, 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,

1

EEX

18

CHS 1 - 18 in the display

X 1.234567901 in the display

RCL 12 yields -1The 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,

RCL 14 yields 13,000,000

RCL 15 yields 45,700

/[pre]

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,

[pre]

1.234565432E10 is 12,345,654,320

- 12,345,654,321

= -1

for R14 1.234567901E18 is 1,234,567,901,000,000,000I 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.

- 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

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.

01 LBLtQUADThis 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

02 CF 00

03 RCL Z

04 CL SUM

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

32 SQRT

33 X<>Y

34 SIGN

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 /

49 STOP

50 LBL A

51 SF 00

52 CHS

53 SQRT

54 RCL 11

55 /

56 LASTX

57 RCL 13

58 X<>Y

59 /

60 STOP

61 END

c = 4,877,163,849, b = 4,877,262,613 and a = 4,877,361,379. Thenso 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.

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

01 LBLtHPQUAD

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

12 CL SUM

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

36 ENTER^

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

60 SQRT

61 RCL 06

62 SIGN

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

72 STOP

73 LBL C

74 RCL 07

75 X<>Y

76 /

77 STOP

78 LBL D

79 SF 00

80 CHS

81 SQRT

82 RCL 04

83 /

84 X<>Y

85 R^

86 /

87 STOP

88 END

Palmer