On 2/18/08, Alexander Ray <riccio at gmx.at> wrote:
> in fact, that was our first try to use unit_step.
> unfortunately, we have next to integrate the function. and
> integrate(f(x)) does not really work nice if f(x) contains unit_step.
Here is an initial attempt at a pattern-matching rule which tells
integrate how to handle unit_step. I've omitted various details,
which we can fill in if it seems worth pursuing.
matchdeclare (uu, lambda ([ee], not atom(ee) and op(ee) = unit_step),
vv, lambda ([ee], atom(ee) or op(ee) # unit_step));
matchdeclare ([aa, bb], all, xx, mapatom);
simp : false;
'integrate (uu*vv, xx, aa, bb);
defrule (r1, ''%, FOO (uu, vv, xx, aa, bb));
simp : true;
FOO (u, v, x, a, b) := (FOO1 (u, x),
if %% < a then integrate (v, x, a, b) elseif %% < b
then integrate (v, x, %%, b) else 0);
FOO1 (u, x) := (if op(u) = unit_step then args(u)
else apply (append, maplist (args, u)),
map (lambda ([e], solve(e = 0, x)), %%),
apply (append, %%),
map (rhs, %%),
apply (max, %%));
Here is a result which makes use of that rule r1.
integrate (f(x)*g(x)*unit_step(x-5), x, a, b);
apply1 (%, r1);
=> if 5 < a then integrate(f(x)*g(x),x,a,b) elseif 5 < b
then integrate(f(x)*g(x),x,5,b) else 0
''%, a=3, b=12;
=> 'integrate(f(x)*g(x),x,5,12)
Maybe that is enough to get started. I would be interested to hear
more about the problem you are working on.
> we try to to calculate a price of a generic plain-vanilla financial
> option, that is nothing else but integrate(f(x,a,b,c,...),x,minf,inf).
> where f(x) typically is piecewise-continuous/differentiable but may
> depend on parameters a,b,c,... in quite a tricky unpredictable manner
> (you have to solve an implicit equation first in order to define the
> integral).
I see a lot of potential uses for Maxima in mixed symbolic and
numerical problems. I would really like to see Maxima become
the tool of choice for such problems. Towards that end,
strengthening Maxima's treatment of functions defined piecewise
is a good strategy.
best
Robert Dodier