On Mon, Sep 28, 2009 at 1:42 AM, ?iga Lenar?i? <ziga.lenarcic at gmail.com>wrote:
> On Sep 28, 2009, at 4:26 AM, Robert Dodier wrote:
> > On 9/24/09, ?iga Lenar?i? <ziga.lenarcic at gmail.com> wrote:
>
> I think 'if' is used mainly for two very different things in Maxima:
>
> 1) programming concept
> 2) for defining piecewise functions ad hoc - f(x) := if x < 0 then x
> else x^2;.
>
Yes, that is correct. I tend to agree with you that the programming if and
the mathematical if are two different things, and should probably be
represented in two different ways, but I lost that argument -- this was
discussed ad infinitum over the past few years. In the end, I was surprised
that combining them (i.e. making prederror false by default) didn't cause
more problems than it has.
> 1) in Mathematica one can write diff( if x< 0 then x else x^2 , x)
> and get the 'correct' result when 'if' is used for defining piecewise
> functions
>
What *is* the correct result? Something like
if x<0 then 1 elseif x>0 then 2*x else <undefined>
? The interesting cases are x=0 and x=<complex number> where '<' is not
defined....
> 2) in Mathematica various commands return an 'if' statement if the
> result is dependent on various parameters - so instead of asksign one
> gets an 'if' expression (which is pretty neat and correct).
>
Yes, we've been trying to get Maxima to do this for years....
> Also taking apart an 'if' statement with 'part' gives weird results -
> so it's not a well behaved expression in that aspect also.
>
Here I disagree with you. It is perfectly well-behaved, but you are perhaps
surprised by its abstract syntax (which may not be documented). The
'surprise' perhaps is that the abstract syntax of 'else x' is actually
'elseif TRUE then x':
args('(if a then b else c)) => [a, b, true, c]
Perhaps 'if' could be strengthened in these areas to make it really a
> first class mathematical expression?
>
We would certainly appreciate your contributions in this area.
-s