Thursday, October 04, 2007

puzzle

The absolute value of a real number is defined as its numerical value without regard for sign. So, for example, abs(2) = abs(-2) = 2. The maximum of two real numbers is defined as the numerically bigger of the two. For example, max(2, -3) = max(2, 2) = 2. Express: (a) abs in terms of max; and (b) max in terms of abs.

I could think of a). Simple.
abs(x) = max(x,-x)

What about b) ?
Can we do without a "flower bracket if{}" ?

3 comments:

sarvagnaani said...

I dont think its possible to define max using abs without an if..because, by definition, max requires a 'decision' of picking the bigger of the two..
but then again..this was just an obvious statement..puzzles are..by definition (:D)..supposed to have tricky answers that are not obvious

Milan said...

Wow! It was a tough one...took a bit of work, but how about...

max(x,y) = 1/2(x + y) + 1/2[abs(x - y)]

Basically you divide the difference into two halves and put a (-)ve sign in one of the halves to ensure that (-)ve numbers are catered to as well...

sarvagnaani said...

brilliant!!!
if x >y then what u r doing is (2x+y-y)/2 which gives x, the other case of x < y, is taken care of by abs..fundoo