Finitely many repeated replacements

You could use ReplaceRepeated with the option MaxIterations->3:

res = ReplaceRepeated[d[a], d[x_]->d[x+b]-d[x-b], MaxIterations->3]

ReplaceRepeated::rrlim: Exiting after d[a] scanned 3 times.

-d[a - 3 b] + d[a - b] - d[a + b] - 2 (-d[a - b] + d[a + b]) + d[a + 3 b]

This agrees with your answer after expanding:

h[a] == Expand[res]

True

The syntax coloring is odd, though, might be a buglet.


Asking for a "better" method you should probably give some metric what is meant by "better. Is it efficiency? Is it easiness of generalization? Anyhow, if you would stick to built-in function in hope that they are more efficient one of the options could be:

n = 3;
DifferenceDelta[d[a - n b], {a, n, 2 b}]

I hope it helps...

Tags:

Replacement