Re: greatest of two numbers



William Elliot wrote:

On Wed, 16 Jan 2008 aarklon@xxxxxxxxx wrote:

Hi all,

The following are the two methods which i have seen for finding
greatest of two numbers

if a and b are two natural numbers

1) greatest(a,b) = [ (a+b ) + abs(a - b) ] / 2

2) ( (a + b) + sqrt[(a - b) ^ 2] ) / 2

is there any better method/ methods than this .????

max{ a,b } = a, if b <= a
= b, if a <= b

Works not only for reals, rationals and integers,
but also all totally ordered sets. For example
R^2 with lexicographical order:
(a,b) <<= (x,y) when a < x or a = x, b <= y.

<<= is an order different that the greater than <, of reals.


Or if you want to avoid "if" cases in the definition, you can use
Knuth's generalization of the Kronecker delta function:
"[expr]" where expr is a boolean expression
is defined to be 1 if expr is true and 0 if expr is false.

Then max(a,b) = ([a>b] * a) + ([a<=b] * b)

Of course, this just pushes the "if" into the definition of the Knuth
brackets, but you may consider the brackets a "known" operator.

--Mark

.