HP Forums

Full Version: min(a,b) and max(a,b) equation for HP-33S/HP-35S
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

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.



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

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. :-)


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

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!