green's functions, passing functions to a routine



On 8/31/08, John Lapeyre <pdl at johnlapeyre.com> wrote:

>  1) how can one pass functions as arguments to another function?
>    Eg,
>
>   /*WRONG*/
>   ygen(f,x,L) :=  integrate(f(t)*g2(x,t),t,0,x)
>          + integrate(f(t)*g1(x,t),t,x,L);
>
>   this does not do what I am trying to do.

Maxima is inconsistent about whether or not to evaluate the name
of a function. If f is already the name of a function, then f is not
evaluated in the expression f(t); but it is evaluated otherwise.
I'm going to guess that you have a function named f somewhere
in your program. An easy workaround is to name the formal argument
something obscure like f% or whatever.

I think Maxima should consistently evaluate or not evaluate function
and array names. Lately I have been leaning towards evaluating them
but there are also good arguments for not evaluating. This question is
historically designated "Lisp-1 versus Lisp-2".

>  2) I want to integrate g1 and make a function h1 from the
>    result. Is there  a good idiom? This seems to work ok.
>
>    h1(x,t) := ''(ratsimp(integrate(g1(x,t),t)));

Probably better to write

define (h1 (x, t), ratsimp (integrate (g1 (x, t), t)));

which evaluates ratsimp(...) *when the define expression is evaluated*.
The quote-quote operator evaluates ratsimp(...) *when it is parsed*.

When you're working at the interactive prompt, the two might have
the same result. Otherwise they can be quite different.

>  3) Piecewise defined functions.
>    f(x) := if x > 3 then 0 else x;
>    integrate(f(x),[x,0,4]); /* FAILS */
>    fails to give a useful result.

At present integrate, diff, etc know nothing about functions defined
piecewise. I've tinkered with some pattern-matching rules to tell
integrate how to handle such functions. I'll try to dig out the code I
wrote --- I don't think I got very far.

Incidentally the integral should be expressed as: integrate (f (x), x, 0, 4);

HTH

Robert Dodier