The Museum of HP Calculators

HP Forum Archive 21

 An old trick rediscovered: combining conditional testsMessage #1 Posted by Dieter on 12 Aug 2012, 10:36 a.m. Namir's post re. "question to TI58/59 programmers" reminded me of the olden days when the average calculator nerd had a comprehensive programmer's toolbox at hand, containing numerous clever ways to overcome the restrictions of the devices that were available at that time. One of these tricks is the combination of conditional tests, one followed by another. Such a combination allows the construction of logical operations that are usually not available on programmable calculators, making programs shorter, faster and more elegant. For instance, two consecutive tests A and B set up a logical disjunction, i.e. the combination behaves like an OR operator, leading to a test (NOT A) OR B. Or, the other way round, if you want to test if condition A or condition B is true, simply use the test for (NOT A) directly followed by B. Example 1: The sequence... ```FC? 01 FS? 02 ``` ...tests if Flag 01 or (!) Flag 02 is set. In a similar way, this helped back then to build those tests commands that were not available on contemporary hardware. Even the HP-41 did not feature a X>=Y? test, but this could be accomplished easily: According to the mentioned rule, a test like "X=Y? OR X>Y?" is equivalent to the sequence... ```X!=Y? X>Y? ``` Or, if you prefer, ```X<=Y? X=Y? ``` Such a combination of two tests can also be used to invert a test command. Simply make sure the second command always tests false. According to the stated rule, this is equivalent to (NOT A) OR FALSE, which in turn is logically the same as NOT A. On the HP-41, flag 54 (only set during a PSE command) may be used for the always-negative test. For instance like this: Example 2: The already mentioned X>=Y? test missing on most classic HPs is equivalent to NOT(X

 Old tricks: the flip-flop flagMessage #2 Posted by Luiz C. Vieira (Brazil) on 12 Aug 2012, 3:16 p.m.,in response to message #1 by Dieter Hi. I used this sequence once in a program back in the 80's just to provide a logical flip-flop, i.e., every time this sequence runs, the state of flag xx commutes. I am not sure if this is common knowledge, but here it goes:```FC?C xx SF xx```Flag xx will act as a flip-flop each time these lines are executed. Hope it is of any use. Cheers. Luiz (Brazil) Edited: 12 Aug 2012, 3:17 p.m.

 Re: Old tricks: the flip-flop flagMessage #3 Posted by Dieter on 12 Aug 2012, 3:42 p.m.,in response to message #2 by Luiz C. Vieira (Brazil) Ah, yes, I used this technique more than 30 years ago for my first program implementing Simspon's rule. This way the function values were multiplied with 4, 2, 4, 2, 4, 2... :-) The second version then used k := 6-k instead to provide the two alternating factors. And the final versions stored the odd and even function values separately so that a better estimate with twice the number of nodes needed to evaluate only those that had not been calculated before. Well, later I heard about the Romberg method... :-) Dieter

Go back to the main exhibit hall