HP Forums
min(a,b) and max(a,b) equation for HP-33S/HP-35S - Printable Version

+- HP Forums (https://archived.hpcalc.org/museumforum)
+-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html)
+--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html)
+--- Thread: min(a,b) and max(a,b) equation for HP-33S/HP-35S (/thread-177995.html)



min(a,b) and max(a,b) equation for HP-33S/HP-35S - x34 - 01-30-2011

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 - Dieter - 01-30-2011

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 - x34 - 01-30-2011

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!