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]));