# the permutation of subscripts of a multivariate polynomial

I want to define a function, the input are a permutation sigma belonging to Sn, and a multivariate polynomial f=f(x1,x2,...,xn) over Q, and the output is a multivariate polynomial f=f(x(sigma(1)),x(sigma(2)),...,x(sigma(n))), for example, if sigma=(3,1,2),f=x1+x2x3, then the output should be f=x3+x1x2. It is worth mentioning that this should work for any n not just when n=3. How should I do that?

edit retag close merge delete

Sort by » oldest newest most voted

You can apply a permutation to a tuple, in particular to the tuple of generators of the polynomial ring. You can then apply the function to the permuted variables.

Here is an example, from which you could build a function permute_variables(sigma,f) (left as an exercise).

sage: version() # just for reference
'Sage Version 6.3.beta5, Release Date: 2014-07-01'
sage: R = PolynomialRing(ZZ,n,'x')
sage: R
Multivariate Polynomial Ring in x0, x1, x2, x3, x4 over Integer Ring
sage: Sn = SymmetricGroup(range(n))
sage: f = R.random_element()
sage: f
x1*x2 - x3^2 + x2*x4 + 3*x1 - 1
sage: sigma = Sn.random_element()
sage: sigma
(0,2,4)
sage: R.gens()
(x0, x1, x2, x3, x4)
sage: sigma(R.gens())
(x2, x1, x4, x3, x0)
sage: f(*sigma(R.gens()))
-x3^2 + x0*x4 + x1*x4 + 3*x1 - 1


Rather than a random permutation, you probably prefer to input it yourself. For this, you need to define x0 etc. and make them point to the variables of polynomials in R. This is done with R.inject(variables). And to input permutations as products of cycles, use something like Sn('(0,1)(2,3)'). An example where you input the polynomial and the permutation yourself:

sage: n = 5
sage: R = PolynomialRing(ZZ,n,'x')
sage: R.inject_variables()
Defining x0, x1, x2, x3, x4
sage: Sn = SymmetricGroup(range(n))
sage: f = x1 + x2
sage: sigma = Sn((1,2,3))
sage: sigma
(1,2,3)
sage: f(*sigma(R.gens()))
x2 + x3
sage: sigma = Sn('(0,1)(2,3)')
sage: f(*sigma(R.gens()))
x0 + x3


Be careful: If you define the permutation group as SymmetricGroup(5), they are indexed from 1 to n, so it's tricky to follow what goes on when you let them act on the generators of $R$, which are indexed from 0 to n-1 (you have to offset your indices by one, then apply the permutation, then undo the offset). In particular the permutation $(1,2,3)$ of $S_5$, would then act on $(x_0, x_1, x_2, x_3, x_4)$, acts as the cyclic permutation $(x_0, x_1, x_2)$.

more

Thanks for your answer very much! However, there is still a small problem, when I type in a polynomial f=x1+x2, and n=5, sigma=(1,2,3),it shows an error says that the number of arguments must be less than or equal to 2. How can I make the arguments of f be x1,x2,x3 instead of just x1 and x2?

Don't forget the line R.inject_variables(). Or, if you prefer, define the x_i's by "x0, x1, x2, x3, x4 = R.gens()". *Do not* define x1, x2, x3 as symbolic variables (with var('x1') etc). Does it work now?