I'd like to set an upvalue for DiscreteShift that changes the rules for being raised to a power:
Unprotect[DiscreteShift];
DiscreteShift /: Power[DiscreteShift[f_, i_], r_] := DiscreteShift[f, {i, r}];
Protect[DiscreteShift];
Power[DiscreteShift[f[n], n], 2] === DiscreteShift[f[n], {n, 2}]
But I'm getting these error messages:
Rule::rhs: "Pattern i_ appears on the right-hand side of rule i_->1+i_. "
TagSetDelayed::tagnf: "Tag DiscreteShift not found in (1+Pattern[f_,_])^r_."
It doesn't seem to like the pattern for DiscreteShift's arguments, but I can't get anything else to work there, either. What is the correct way to write this?
Edit: I'll try to clarify my goal. Here's what I want to do mathematically:
(N + n) f(n) = N f(n) + n f(n)
= f(n+1) + n f(n)
(N + n)^2 f(n) = (N^2 + Nn + nN + n^2) f(n)
= N^2 f(n) + Nn f(n) + nN f(n) + n^2 f(n)
= f(n+2) + (n+1) f(n+1) + n f(n+1) + n^2 f(n)
= f(n+2) + (2n+1) f(n+1) + n^2 f(n)
So I have this funny N operator that acts as a discrete shift, and we're sort of overloading the meaning of multiplying to have it operate on a function. I had hoped to represent N f(n)
by using DiscreteShift[f[n],n]
, and then fixing the power rule for it.