if then and unit_step



It has occurred to me on various occasions, that you can do logic in Maxima 
by using step functions.  The unit_step() function, which is used in pw for 
representing piecewise functions, is bi-valued. So are Boolean expressions. 
You can represent connectors like "and", "or" and "not" as expressions 
involving unit_step().

Consider if x>a and x>b then u else v;

It is equivalent to the following, if you agree with the idea that how an 
expression evaluates is all that matters.

(u - v) * unit_step(x - max(a, b)) + v;

then there is "or" as in the following

if x>a or x>b then u else v;

It is equivalent to the following.

(u - v) * unit_step(x - min(a, b)) + v;

Another possibility is

if (x > a) and (x < b) then u else v

(v - u) * unit_step(x - b) + (u - v) * unit_step(x - a) + v

Rich