simplification of if



On Mon, Sep 3, 2012 at 6:35 PM, Robert Dodier <robert.dodier at gmail.com>wrote:

> On 2012-09-01, Stavros Macrakis <macrakis at alum.mit.edu> wrote:
>
> > 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,
>
> Um, the stuff I wrote simplification of "if" and Boolean expressions is
> in share (share/contrib/boolsimp).
>
> I did make some changes to the evaluation of Boolean expressions,
> specifically that Boolean expressions evaluate to Boolean expressions
> when prederror = false and the result is neither true nor false.
>

That's exactly the case I was talking about.

(Previously in that case a Boolean expression evaluated to 'unknown.)
> As a side effect, that made partial evaluation of "if" expressions much
> more interesting and useful.


I agree it made it "more interesting and useful", but it sounded risky to
me.


> > 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.
>
> I agree that such constructs are uncommon, but be that as it may, as
> long as the user can easily predict the behavior of "if", whatever
> result they get is their own problem.
>

Well, if users could predict the behavior of their programs, they wouldn't
have bugs in them :-).  Part of the art of programming language design is
balancing usefulness and risk: How soon will the user discover the
unexpected behavior?  How easy is it to write robust programs which don't
fail in mysterious ways when used in unexpected ways?  Consider a function
with argument A which includes code like (if A>0 then Q:Q/2); it will
silently give an incorrect answer if A>0 is unknown with the if-noun
behavior.  But I do concede that we haven't heard of such problems.

          -s