simplification of if



On 9/1/2012 11:43 AM, Stavros Macrakis wrote:
> In current Maxima:
>
> (%i1) ex: if X then 0 else 1;
> (%o1)                         if X then 0 else 1  <<< OK
> (%i2) subst(true,X,ex);
> (%o2)                        if true then 0 else 1   <<< 
> simplification does not result in 0
> (%i3) block([X:true],ev(ex));
> (%o3)                                  0       <<< re-evaluation does 
> result in 0
>
> Is there any good reason that (if true then A else B) doesn't 
> /simplify /to A?
I think there is an issue of treating an imperative statement as a 
value-returning function at
simplification time.  I haven't thought this through but maybe it 
matters in cases like

if X then go(label1) else return(43)

... when do you (re) simplify X?

what about prederror?

   Separating out the simplification of booleans from the
  programming construct "if" seems like it would clarify things.

but maybe this is all easily done, and I just haven't thought it through.

Have a good weekend.
RJF

>
> Consider for that matter:
>
> (%i1) ex: [abs(x), if x<0 then -x else x];
> (%o1) [abs(x),if x < 0 then -x else x]  <<< OK
> (%i2) assume(x<0);
> (%o2) [x < 0]
> (%i3) expand(ex,0,0);
> (%o3) [-x,if x < 0 then -x else x]   <<< abs(x) does simplify, but the 
> equivalent conditional doesn't
>
> Why does resimplifying abs(x) take advantage of the assumption, but 
> resimplifying IF does not?
>
> I'll be happy to code this up (not very hard!) unless someone sees a 
> problem with it.
>
>                 -s
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima