The Museum of HP Calculators

HP Forum Archive 20

[ Return to Index | Top of Index ]

min(a,b) and max(a,b) equation for HP-33S/HP-35S
Message #1 Posted by x34 on 30 Jan 2011, 10:48 a.m.

HP-33s and HP-35s lack min and max functions. Yes, they could be easily programmed, but.. a) Label would be consumed on HP-33S (not a problem for HP-35S, thou) b) You can't use conditionals in the Equation Writer

So, here is simple (but awkward) brute force implementation of MIN & MAX using Signum function, present on these calculators.

MIN(a,b)=((b-a)*SGN(a-b)+b+a)/2

MAX(a,b)=((a-b)*SGN(a-b)+b+a)/2

If used in program, they could be simplified by isolating (a-b).

      
Re: min(a,b) and max(a,b) equation for HP-33S/HP-35S
Message #2 Posted by Dieter on 30 Jan 2011, 12:10 p.m.,
in response to message #1 by x34

If I need a min() or max() function in a program I simply do it this way - without any labels and with minimal memory usage:

MIN-function:         MAX-function:
   X>Y?                 X<Y?
   x<>y                 x<>y

Okay, this doesn't work for the solver. :-)

Looking at your equations for a while I found a somewhat simplified version. Since (a-b)*sign(a-b) is simply abs(a-b) the two equations may be written even shorter this way:

MIN(a,b) = (a+b-ABS(a-b))/2
MAX(a,b) = (a+b+ABS(a-b))/2
By the way thanks for your suggestion - it's always nice to re-think some basics and find solutions one would otherwise not have thought of. :-)

Dieter

Edited: 30 Jan 2011, 12:47 p.m.

            
Re: min(a,b) and max(a,b) equation for HP-33S/HP-35S
Message #3 Posted by x34 on 30 Jan 2011, 5:26 p.m.,
in response to message #2 by Dieter

Dieter, thanks for your simplification! I was just solving another problem involving signum function, and suddenly realized that it could be used to emulate MAX/MIN in solver. I wrote the same ABS solution 15 minutes before reading your post :) Your solution is better!


[ Return to Index | Top of Index ]

Go back to the main exhibit hall