Subject: If then else and unevaluated conditionals
From: Stavros Macrakis
Date: Mon, 29 Jan 2007 10:01:59 -0500
On 1/29/07, Michel Van den Bergh <michel.vandenbergh at uhasselt.be> wrote:
> I am sort of wondering there should not be two different if then else's.
> One which is a programming construct and which is handled by meval,
> and one which it a "mathematical concept" and which is handled by the
> simplifier. Unevaluated conditionals should go into the latter and not into
> the former I would say.
I agree entirely -- see my past emails on the subject.
> The mathematical if then else could simpy be if(expr1,expr2,expr3).
That's one way of doing it, though I think an unordered case-like
statement lends itself to easier manipulation -- essentially
Dijkstra's guarded clauses. It lends itself to this sort of
manipulation:
ex: abs(a+1)-abs(a)$
exc: expand_case(ex) =>
[[ a+1 >=0 => a+1, a+1 <=0 => -a-1 ]] - [[a >=0 => a, a<=0 => -a ]]
excc: case_combine(exc) =>
[[ a+1 >= 0 and a >= 0 => 1
a+1 >= 0 and a <= 0 => 2*a+1,
a+1 <= 0 and a >= 0 => -2*a-1,
a+1 <= 0 and a <=0 => -1 ]]
simplifying conditionals...
[[ a >= 0 => 1
a+1 >= 0 and a <= 0 => 2*a+1,
false => -2*a-1,
a+1 <= 0 => -1 ]]
simplifying conditionals...
[[ a >= 0 => 1
a+1 >= 0 and a <= 0 => 2*a+1,
a+1 <= 0 => -1 ]]
(this assumes we have conditional simplification, which we don't currently...)
You could also make this work with if/fhen/else, either by expanding
out into things like
if a+1 >= 0 and a >= 0 then 1
elseif a+1 >= 0 and a <= 0 then 2*a+1,
elseif a+1 <= 0 and a >= 0 then -2*a-1,
elseif a+1 <= 0 and a <=0 then -1
But now note that the full condition on the last clause is
not(a+1 >= 0 and a >= 0) and
not(a+1 >= 0 and a <= 0) and
not(a+1 <= 0 and a >= 0) and
(a+1 <= 0 and a <=0)
which of course can be simplified, but looks messy....
I think you can work either way, but the guarded clause way looks
simpler and more symmetric.
-s