Newbie - integrate piecewise function



>  What if you took the product of two piecewise defined functions
>  and then asked to integrate THAT?  Clearly any CAS that claims
>  to integrate piecewise functions would have to handle that too.

I disagree.  There are many areas where Maxima solves problems
partially, and gives up gracefully otherwise using noun forms.

In the particular case of a product of piecewise defined functions,
yes it is messy, but there are certainly many simple, doable cases,
e.g. diff(abs(x)*abs(x-1),x) => abs(x)*(x-1)/abs(x-1) +
x*abs(x-1)/abs(x).  In fact, one can do better:

     abs(x)*abs(x-1) ==
     signum(x)*x*signum(x-1)*(x-1) ==
     signum(x*(x-1)) * x * (x-1)

differentiating using product rule gives

     (2*x-1)*signum(x*(x-1))

Of course, this doesn't handle the non-differentiability at 0 and 1.

Integration is messier because at the discontinuities, you don't just
have to deal with point non-differentiability, but with continuity. 
So integrate(signum(x)*exp(x),x) integrated piecewise gives ff(x)=(if
x<0 then -exp(x) else exp(x)), but ff(-0)=-1 and ff(+0)=1, so the
correct integral is (if x<0 then -exp(x) else exp(x)-2).

It would be nice, too, to handle Dirac deltas and all that, but....

>  Here is a standard example where piecewise functions could
>  be a problem:  (abs(x)-x)*(abs(x)+x).  For real x this is always 0.

Why is that a problem?   In fact, expand simplifies that today.  But
even if it didn't, the piecewise analysis is simple.

>  Another is atan(x)+atan(1/x),  which is a step function, but you
>  might not know it, especially if it is disguised.

Why is that a problem?  As it happens, Maxima gets the correct result
for integrate(atan(x)+atan(1/x),x) today -- probably dumb luck that
the result is continuous at x=0, but there you are.

             -s