unevaluated boolean and conditional expressions, take 2
Subject: unevaluated boolean and conditional expressions, take 2
From: Robert Dodier
Date: Sat, 4 Feb 2006 19:05:10 -0700
Hello all,
I've made some changes to the code for handling unevaluated
boolean and conditional expressions, so that the branches of
unevaluated conditionals are evaluated less aggressively. See:
http://cvs.sf.net/viewcvs.py/maxima/maxima/share/contrib/boolsimp/
Specifically, atoms are evaluated but functions are not called.
This addresses some problematic cases mentioned by Stavros.
pp: if x > 0 then print(1) else print(2); => if x > 0 then print(1)
else print(2)
/* nothing printed here */
''pp, x = 1;
/* now 1 is printed */
''pp, x = -1;
/* now 2 is printed */
f(x) := if x <= 0 then 1 else x*f(x - 1);
fy : f(y); => if y <= 0 then 1 else y f(y - 1)
''fy, y = 8; => 40320
f(8); => 40320
if not equal (x, 0) then 1/x else 0, x=0; => 0
/* no 1/0 error triggered */
The examples I mentioned last time also still work.
The file rtest_boolsimp.mac contains a lot of examples.
Avoiding function evaluations means that unevaluated conditionals
might contain "obvious" unsimplified boolean expressions.
e.g. x : 100; if y > x then if x > 0 then aa else bb else cc;
=> if y > 100 then if 100 > 0 then aa else bb else cc;
Maxima doesn't simplify constant relational expressions e.g. 100 > 0
above, probably because expressions involving = are ambiguous.
The code that I've written doesn't touch that problem at all;
I've left it for the next go-around.
Also, errors which arise from simplification of branch expressions
(e.g. 1/0, 0^0) can still cause problems. I'm not convinced there
should be any errors in simplification, so I'm not inclined to try to
work around it. I see resolution of this as another problem for
the next go-around.
Thanks for any comments you might have.
Robert Dodier