how to define operators acting on functions



Hi ugur,

> # I'm trying to define forward difference operator in maxima. Forward
> difference op is defined such that: delta y(x) = y(x+h) - y(x)
> # I wrote:
> delta(y):=y(x+h)-y(x);
> # This works fine for the first order. But when I tried to apply delta^2 to
> any function, it gives an error:

so let's take your problem apart:

Your delta function expects a function name as argument but returns
an expression. So what will happen, when evaluating

> (%i5) delta(delta(sin));

First the inner function is evualated and you get
delta(sin(x + h) - sin(x))

Now maxima doesn't know how to apply delta to this, so it gives
you an error

> y evaluates to sin(x + h) - sin(x)
> Improper name or value in functional position.
> #0: delta(y=sin(x+h)-sin(x))
>  -- an error.  To debug this try debugmode(true);

I think you have two options to fix this:
a) Make delta return a function (i.e. a lambda expression)
b) Make delta operate on expressions instread of function names
   (you might use subst() to construct you result)

HTH,
Harald