[Maxima] Integrating function with abs or max

sen1 at math.msu.edu sen1 at math.msu.edu
Sun Jan 28 22:03:03 CST 2007

```I don't know how maxima treats these things, but here are some
thoughts.

Is one interested in symbolic or numerical integrals?

I will only consider numerical integrals here.

1. There is very little difference between using max, min, and abs of
functions.

Recall that the abs(f(x)) and f(x) are determined from the positive
and negative parts of a function; i.e.,  f_plus, f_minus

Here f_plus(x) = max(f(x),0) and
f_minus(x) = -min(f(x),0)

Then,      f(x) = f_plus - f_minus
abs(f(x)) = f_plus + f_minus

f_plus(x) = (abs(f(x)) + f(x))/2

f_minus(x) = (abs(f(x)) - f(x))/2

So, if one can integrate max(f(x),0) and min(f(x),0), then one can
integrate  both f(x) and abs(f(x)) and the converse is also true.

I think similar tricks can be used for  h(x) = max(f(x),g(x)) using max(f(x) - g(x),0)

2. Let us work with f_plus(x) = max(f(x),0).

It seems natural to find the places where f(x) = 0 and break the
domain of integration into intervals between these points.

So, for transcendental functions this may not be easy.

I did not look at the source code, but it seems that maxima knows
where the bad point of x -> abs(x) is.

Notice:

(%i24) integrate(abs(x),x,0,1);
1
(%o24)                                 -
2
(%i25) integrate(abs(x),x,-.1,1);
1
/
[
(%o25)                         I      abs(x) dx
]
/
- 0.1
(%i26) integrate(abs(x),x,-2,-.1);
399
(%o26)                                ---
200
(%i27) integrate(abs(x),x,-2,.1);
0.1
/
[
(%o27)                          I    abs(x) dx
]
/
- 2

So, maxima seems to fail to find the integral when the domain of
integration contains the non-differentiable point. (call this a "bad" point)

Perhaps one could use this fact to actually find where the bad
points are and then break up the untegral into good subintervals and

So, the routines would find where the current algorithm fails and try
to break up the domain of integration accordingly.

As a second example, consider f(x) = max(x^3-x,0).

(%i28) f(x):= max(x^3 -x,0);
3
(%o28)                      f(x) := max(x  - x, 0)
(%i29) integrate(f(x),x,1,2);
9
(%o29)                                 -
4
(%i30) integrate(f(x),x,0,1);
(%o30)                                 0
(%i31) integrate(f(x),x,-1,0);
1
(%o31)                                 -
4
(%i32) integrate(f(x),x,-2,-1);
(%o32)                                 0
(%i33) integrate(f(x),x,-1,-.1);
9801
(%o33)                               -----
40000
(%i34) integrate(f(x),x,-1,.1);
0.1
/
[         3
(%o34)                      I    max(x  - x, 0) dx
]
/
- 1

(%i35) integrate(f(x),x,-1,.00001);
1.0000000000000001E-5
/
[                           3
(%o35)             I                      max(x  - x, 0) dx
]
/
- 1

So, here maxima seems to find the bad point also.

-sen

---------------------------------------------------------------------------
| Sheldon E. Newhouse            |    e-mail: sen1 at math.msu.edu           |
| Mathematics Department         |       				   |
| Michigan State University      | telephone: 517-355-9684                |
| E. Lansing, MI 48824-1027 USA  |       FAX: 517-432-1562                |
---------------------------------------------------------------------------

On Sun, 28 Jan 2007, Robert Dodier wrote:

> On 1/22/07, Ray Tice <trayracing at yahoo.com> wrote:
>
>> How do I reformulate functions that use abs or max so that maxima can
>> integrate them?
>
> Ray, thanks for the inspiration, but for better or worse I didn't really
> get very far on this yet. If anyone has comments on this stuff I
> would be interested to hear about it.
>
> There are some related problems here -- moving conditionals from
> integrands into limits of integration; allowing arithmetic and other
> operations on conditionals; and simplifying Boolean expressions
> when some clauses imply or rule out others.
>
> I made some sketchy progress on the stuff about operations on
> conditionals (although not the other two items). For your consideration,
> here's an example:
>
> mymax(a,b) := if a>b then a else b;
> myabs(x) := if x<0 then -x else x;
> F(x) := mymax(1 - myabs(x), 0);
> F(x);
>  => -(if 1-(if x < 0 then -x else x) > 0
>            then 1-(if x < 0 then -x else x) else 0
>
> Then simplifying it with some rules about how to flatten it --
>
>  => if (x < 0 and x+1 > 0 or x >= 0 and 1-x > 0) and x < 0
>          then x+1
>          elseif (x < 0 and x+1 > 0 or x >= 0 and 1-x > 0)
>           and x >= 0 then 1-x else 0
>
> The relational expressions can obviously be simplified, I just
> haven't worked on that part yet.
>
> F(x)*F(1 - x) yields a rather long expression --
>
> if (1-x < 0 and 2-x > 0 or 1-x >= 0 and x > 0)
>            and 1-x < 0
>            and (x < 0 and x+1 > 0 or x >= 0 and 1-x > 0)
>            and x < 0 then (2-x)*(x+1)
>           elseif (1-x < 0 and 2-x > 0 or 1-x >= 0 and x > 0)
>            and 1-x < 0
>            and (x < 0 and x+1 > 0 or x >= 0 and 1-x > 0)
>            and x >= 0 then (1-x)*(2-x) ....
>
> but this mess does have the advantage that all of the predicates
> are at the top level (instead of being nested) so I think it should
> be straightforward to extract them for the purpose of modifying
> limits of integration and so on.
>
> There's a lot of work to be done here, but it would be worth
> it because functions defined by if--then--else are very common
> in applications. Hope these meager results can help us get
> the wheels turning.
>
> best,
> Robert Dodier
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
```