H P - 2 8 C N O T E S For a change I'll avoid SYSEVAL and other high-flown ideas. After all, there are some people who use the HP-28C as a calculator. One is Charlie Williams who sent me an electronic mail message over JANET with a sorting program for the 28C, see later. Other club journals are publishing 28C programs regularly now, if people are interested I could try to keep a complete index of such programs for a while, for now I shall just mention ones I find particularly interesting. One journal with a lot of interesting HP-28C programs is NUTS. You may not have heard of this journal - it is a fairly new one published in Holland since 1986, so the Dutch do have something to read following the demise of the earlier Dutch magazine HP User Nieuws. As for the title, well officially it stands for the name of the HP-41 which has been referred to by HP as the Coconut or just the Nut, but in fact as Frans de Vries told me - it's what we must be to be publishing it! In fact there is a second Dutch journal, PROMPT, but HPCC do not have a journal exchange agreement with them, so I have not seen it yet. I got the first four issues of NUTS from Frans during the Copenhagen Conference, and the fifth issue recently reached HPCC. Issue 4 had programs for parametric plotting, including a Bode plot, and clock programs as in other journals. Issue 5 of NUTS includes a prompting routine, a series summation routine, routines which automate EXPAN and COLCT, a routine to simplify differentiation by collecting terms, plus GRAD, DIV and Laplacian fuctions. Guess what, LAP is the program << GRAD DIV >>. A neat Greatest Common Divisor (usually called the Highest Common Factor in English) program from Michiel Niemeijer is: << DO SWAP OVER MOD UNTIL DUP NOT END DROP >> 'HCF STO For example 217 ENTER 637 HCF should show that 7 is the HCF of 217 and 637. This leads him to a very simple formula for the Lowest Common Denominator. << DUP2 HCF / * >> 'LCD STO 217 ENTER 637 LCD should give 19747. Erik van der Veen then points out that WHILE REPEAT is more efficient than DO UNTIL in the calculation of the HCF: << WHILE DUP REPEAT SWAP OVER MOD END DROP >> 'HCF STO The inversion of the test means that DUP now lets you test for a zero directly instead of demanding an inversion with NOT. If you do not understand this, remember that any test such as IF or UNTIL or WHILE simply checks for a number in level 1 - if that number is zero then the test result is false, otherwise the test result is true. Thus both versions of HCF repeatedly calculate MOD of the two numbers in levels 1 and 2, until the MOD becomes zero, so the HCF has been reached. (I am not sure if it is a good idea to omit any checks on the contents of levels 1 and 2 - if these contain real but non-integer numbers, or very large numbers, then the calculation can take a while without giving a meaningful result.) The last version of HCF given by Erik uses recursion: << -> x y << IF y 0 > THEN y x y MOD HCF ELSE x END >> >> Instead of storing its results on the stack and repeating its calculation, this HCF uses recursion; it stores the present values in local variables, simplifies once and calls itself to make another simplification step. This uses up some memory to store each successive call to HCF. Because of the small memory of the 28C, recursion is rarely a good way to do calculations, but this recursive version of HCF leads to a whole article by Frank Sauer on recursive programming, illustrated by the recursive programmer's old favourite - Fibonacci Numbers. Issue 5 of NUTS also has a report and photographs from the Copenhagen conference, and a copy of my PEEK program - oops, sorry I promised not to mention such topics. The second issue of HPX Exchange, the new US journal which has replaced the CHHU Chronicle has a report on the conference and some HP-28C material too; Fred Lipschultz points out that the FOR...STEP program structure lets you change the step size from one step to the next. He gives the example: << 1 100000 FOR x x 1 DISP 1 WAIT x 9 * STEP >> which displays a sequence of powers of 10 without using exponentiation. Now for Charlie Williams' sorting program. He sent the following: !! Quicksort procedures to sort a list of objects !! Input : 1< list > Output: 1< list > !! Lambda (local) variables : j i f l d Temporary Variables : a SORT << DUP 'a' STO SIZE 1 SORT2 a 'a' PURGE >> SORT2 << DUP2 DUP -> j i l f d << DO a i j + 2 / GET 'd' STO DO 'a' a i DUP2 WHILE GET d < REPEAT 1 + DUP2 END 'i' STO j DUP2 WHILE GET d > REPEAT 1 - DUP2 END 'j' STO IF i j <= THEN DUP2 i GET j SWAP PUT j GET i SWAP PUT i 1 + 'i' STO j 1 - 'j' STO ELSE DROP2 END UNTIL i j > END IF f j < THEN j f SORT2 END i 'f' STO l 'j' STO UNTIL f l >= END >> >> Supply a list of objects that can be compared with each other and execute SORT. Space is tight so SORT2 should be keyed in before SORT into a nearly empty machine and there is only enough space to edit SORT2 if SORT is deleted (yawn). (Disable LAST and UNDO if very short of space.) It's not very fast but I think it's quite neat, bearing in mind it was the first program I wrote in RPL. CW Note that Charlie's program uses recursion too, for the lower list. Charlie says he likes the ability of the HP-28C to do recursion, but this is seriously limited by the shortage of memory, so recursive algorithms have to be rewritten to be iterative, and he continues "Now... there is a recursive list processing algorithm to do this automatically for most sorts of functions but..." More next month, when I hope to report on the HP-28C activities of Kim Holm, Graeme Cawsey, Rabin Ezra, and on my HP-28 book which should be ready by then. Wlodek Mier-Jedrzejowicz.