I would like to define a translation operator L that from a function q outputs q(x-1) for all x i.e. the same function but shifted by one to the left. I defined it this way:
(%i0) L(q) := q(x-1);
However, if I apply the operator twice
(%i1) L(L(q));
it outputs
(%o1) q(x-1)(x-1)
instead of
(%o1) q(x-2)
What is the proper way to do this?
L
has to return a function for this kind of nesting to work.
Perhaps, a simple substitution is enough for the task:
L(f) := subst(x=x-1,f)$
L(sin(x)); L(L(sin(x)));
sin(x - 1)
sin(x - 2)
A macro with lambda would also work:
L(q) ::= buildq([q], lambda([x], q(x-1)));
So, when, for example, f(x):= x + 1, g(x) := sin(%pi*(x-1)/4)
:
f(1); L(f)(1); L(L(f))(1);
2
1
0
g(1); L(g)(1); L(L(g))(1);
0
-1/sqrt(2)
-1