integration of signum & friends



This morning, I committed a new share/contrib/integration folder. In
this folder is code I wrote for integrating functions that involve
abs, signum, max, min, and unit_step.  Also in this folder is a rtest
file and user documentation (texi + html).

I thank Richard Fateman, Robert Dodier, and Richard Hennessy for
assistance with bug fixes and help with matchdeclare and
tellsimpafter.

(1) I think I correctly updated /share/Makefile.am; if not, let me
know.

(2) file_seach_maxima is unable to locate the new folder
share/contrib/integration. If somebody can help me fix this, I'd
appreciate it.

(3) I learned a few things about using tellsimpafter to extend
integrate. My matchdeclare / tellsimpafter code is

       matchdeclare(x, symbolp, q, true, a, numberp, b, numberp);
         block([simp : false], tellsimpafter('integrate(q,x), signum_int
         (q,x)),
                               tellsimpafter('integrate(q,x,a,b),
                               abs_defint(q,x,a,b)));

The functions signum_int and abs_definit return a noun form on
failure. Maybe it's a funmake bug, but the funmake statement needs to
be

  block([noun_int : nounify('integrate)], funmake(noun_int, [....]).

Without the (extra, I think) nounify, you'll get weird bugs when
Maxima uses antidiff to evaluate a definite integral.

One more thing: Some integration code sets opsubst to false. Code that
substitutes a lambda form for a function should set opsubst to true.
Robert Dodier figured this out for me (thank you).

(4) Of course, if somebody would like to move / blend my texi
documentation, that's OK.

(5) If you've writen code that extends integrate, I invite you to
paste your code into /share/contrib/integration.

(6) The signum_int code looks for integrands of the form p(x) *
signum(q(x)), where q(x) is a product of linear factors. A quick demo:

(%i1) load("abs_integrate.mac")$

 (%i1) integrate(abs(x)*x,x);
 (%o1) (x^3*signum(x))/3

The function signum_to_abs partially converts signum expressions to abs:

 (%i2) factor(signum_to_abs(%));
 (%o2) (x^2*abs(x))/3

Let's check the antiderivative

 (%i3) factor(diff(%,x));
 (%o3) x*abs(x)

A max example

 (%i4) integrate(max(x,x^2),x);
 (%o4) signum(x-1)*((x^3*signum(x))/6-1/6)+signum(x-1)*(1/4-(x^2*signum
 (x))/4)+x^3/6+x^2/4

Let's check that the antiderivative is continuous at 0 and 1

 (%i5) [gruntz(%,x,1,'minus) = gruntz(%,x,1,plus), gruntz(%,x,0,'minus) =
 gruntz(%,x,0,'plus)];
 (%o5) [5/12=5/12,-1/12=-1/12]

 (%i6) integrate(exp(-x) * signum(x-42),x);
 (%o6) (%e^(-42)-%e^(-x))*signum(x-42)

The code has a hook to the definite integral code I posted to the
mailing list some time ago

 (%i7) integrate((x-1)/(1 + abs(x)),x,-5,7);
 (%o7) 2-2*log(8)

Barton