1
$\begingroup$

I have a polynomial in n variables, L[1],...,L[n]. Starting from an index j, I want to shift the variables of the polynomial like: L[i]->L[i+1], from i=j to i = n, simultaneously. So for example L[1]+ L[3]^2 -> L[2]+L[4]^2

This is part of a recursion, so n and j will be positive integers, but I would like to define this operation for arbitrary n and j.

I have tried using "\." and loops but I haven't yet figured out how to avoid shifting variables that I have already shifted. Also, I suspect/hope there is a much better way to do this.

$\endgroup$
2
$\begingroup$
ClearAll[shift]
shift[p_, k_] := p /. L[i_ /; i >= k] :> L[i + 1]

Example:

n = 7;
poly = RandomInteger[9, n]. Array[L, n]^RandomInteger[{1, 9}, n]

5 L[1]^9 + 9 L[2]^8 + 4 L[3]^6 + 4 L[4]^3 + 8 L[5]^6 + 4 L[6]

shift[poly, 4]

5 L[1]^9 + 9 L[2]^8 + 4 L[3]^6 + 4 L[5]^3 + 8 L[6]^6 + 4 L[7]

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.