simplification of if



Rich,

I think if you look back at the mail archives, several of us were concerned
about conflating the simplifying and the programming 'if'.  Robert went
through with the change nonetheless, and I concede that it doesn't seem to
have caused problems.

This is perhaps because people aren't writing imperative code in Maxima, or
if they are, they are avoiding the noun case.  That is, they simply aren't
writing things like

            if x<0 then i:1 else i:2
and
            if x<0 then go(label)

where the truth of x<0 is unknown at runtime.  I admit this makes me a bit
nervous, but Maxima has always been pretty pragmatic and permissive about
things like this.

Since we already have the noun-if behavior, we might as well make it
simplify better....

                 -s


On Sat, Sep 1, 2012 at 3:52 PM, Richard Fateman
<fateman at eecs.berkeley.edu>wrote:

>  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 listMaxima at math.utexas.eduhttp://www.math.utexas.edu/mailman/listinfo/maxima
>
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
>