integration of signum & friends



pw.mac users.

Barton's code is 25 times faster at integrating piecewise functions than pw.mac.  After I check it out some more and since this code 
is in the public domain I am going to place it in pw.mac instead of the tellsimp code which is so slow by comparison.

Rich


----- Original Message ----- 
From: "Richard Hennessy" <rvh2007 at comcast.net>
To: "Barton Willis" <willisb at unk.edu>; "maxima mailing list" <maxima at math.utexas.edu>
Sent: Tuesday, December 09, 2008 5:04 PM
Subject: Re: [Maxima] integration of signum & friends


I was approaching this from a completely different direction.  Anyway I was working on a simplify program that converts integrals
that my pw.mac cannot do to a form it can do.  I was going to call it pwsimp().  I will take on this task.

Rich



----- Original Message ----- 
From: "Barton Willis" <willisb at unk.edu>
To: "maxima mailing list" <maxima at math.utexas.edu>
Sent: Tuesday, December 09, 2008 7:05 AM
Subject: integration of signum & friends



Here is one way to evaluate definite integrals of signum and friends;
nothing fancy, just integrate over the subintervals on which signum
and friends do not vanish. Examples:

 (%i15) mydefint(abs(x),x,-1,1);
 (%o15) 1

 (%i17) mydefint(abs(x^2-1) * cos(x),x,-2,3);
 (%o17) 6*sin(3)+6*cos(3)+sin(2)+4*cos(2)+8*sin(1)-8*cos(1)

 (%i18) mydefint(max(-x,x) + x,x,-9,1);
 (%o18) 1

Return a nounform (argument to abs is nonconstant polynomial)

 (%i19) mydefint(abs(x-a),x,-1,1);
 (%o19) defint(abs(x-a),x,-1,1)

Here, I think the problem is that sign isn't able to simplify the integrand
over each subinterval

 (%i20) mydefint(abs(x^2-3),x,-5,42);
 (%o20) integrate(abs(x^2-3),x,sqrt(3),42)+integrate(abs(x^2-3),x,-sqrt
 (3),sqrt(3))+integrate(abs(x^2-3),x,-5,-sqrt(3))

Maybe somebody would like to fix the bugs in my code, extend it
(indefinite integrals), and make it their own.

Barton

/* This code is lightly tested; I place it in the public domain.

 (1) gather the arguments of signum, abs, and unit_step (convert max and
 min to abs)
 (2) determine where these arguments vanish; call this list of numbers l
 (3) sort the list l from low to high
 (4) integrate over the intervals formed by the list l

Return a nounform when the arguments to signum & friends aren't constant
coefficient
degree 2 or less polynomials.

*/

load("opsubst");
load("topoly");

dint(e,x, l) := block([],
  if emptyp(l) or emptyp(rest(l)) then 0 else
  integrate(e,x,first(l), second(l)) + dint(e,x, rest(l)));

mydefint(e,x,lo,hi) := block([l, knots, acc : 0, realonly : true,
  prederror : false],
  if is(hi < lo)=true then defint(-e,x,hi,lo)
  else if is(lo < hi)=true then (
    e : ?convert\-from\-max\-min\-to\-abs(e),
    l : union(setify(flatten(gatherargs(e, 'signum))), setify(flatten
    (gatherargs(e, 'abs))),
      setify(flatten(gatherargs(e, 'unit_step)))),
    if every(lambda([s], polynomialp(s,[x],'numberp, lambda([s], integerp
    (s) and s < 3))), l) then (
      knots : [lo, hi],
      for lk in l do (
        lk : map('rhs, flatten(algsys([lk],[x]))),
        for lkk in lk do (
          if is(lkk > lo and lkk < hi) then knots : cons(lkk, knots))),
      dint(e,x, sort(knots, lambda([a,b], is(compare(a,b) = "<")))))
    else funmake('defint,[e,x,lo,hi]))
  else funmake('defint,[e,x,lo,hi]));

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

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