piecewise function with integrals



Okay, now I get it.  iif() is a function that only works for simplifying 
functions.  If you want to actually plug in a value for x inside an "if" 
like this one.  You will crash Maxima.

(1/(x-1) *  if equal(x,1) then 1 else (x-1));
%,x=1;
results in an error

You could do

(1/(x-1) *  if equal(x,1) then 1 else (x-1))$
somesimplifyercall(%);
-> if equal(x,1) then error("divide by zero") else 1

I wrote pw.mac so that is tries not to do that, but sometimes user input 
forces this result. I don't think it can be avoided.  Is it really necessary 
to have this feature?  What does it get you to have it?

Sorry for the misunderstanding.

Rich

-----Original Message----- 
From: Richard Hennessy
Sent: Sunday, January 20, 2013 6:29 PM
To: Richard Fateman ; Henry Baker
Cc: maxima at math.utexas.edu
Subject: Re: [Maxima] piecewise function with integrals

"I'm sympathetic with the idea but there is an issue to note ..."


On 1/20/2013 2:44 PM, Henry Baker wrote:
> I'd be happy with a relatively simplistic form of if-then-else 
> expressions, which could do "simplifications"/transformations like this:
>
> a*(if ... then b else c) <=> (if ... then a*b else a*c)
>
> a+(if ... then b else c) <=> (if ... then a+b else a+c)
>
> etc.

This has already been thought through and done in pw.mac.

(%i7) display2d:false;
(out7) false
(%i8) (1/(x-1) *  if equal(x,1) then 1 else (x-1));
(out8) (if equal(x,1) then 1 else x-1)/(x-1)
(%i9) ifthen2iif(%);  /* convert. iif supports context sensitive
simplifications */
(out9) iif(equal(x,1),1,x-1)/(x-1)
(%i10) pulliniif(%); /* combine */
(out10) iif(equal(x,1),1/(x-1),1)
(%i11) iif2ifthen(%); /* convert back, no divide by zero in this case */
(out11) if equal(x,1) then 1/(x-1) else 1

Maybe someone could look at the source code for how it works and how it
fails in various cases.
Rich

_______________________________________________
Maxima mailing list
Maxima at math.utexas.edu
http://www.math.utexas.edu/mailman/listinfo/maxima