Substitute elementary symmetric functions in a polynomial

Suppose I do the following:

sage: SF=SymmetricFunctions(QQ)
sage: poly=SF.e()(SF.from_polynomial(x^2+y^2))
sage: poly
e[1, 1] - 2*e

Now I would like to substitute e[1, 1] in that expression. However:

sage: poly.subs({SF.e()[1, 1]: 1})
e[1, 1] - 2*e

Does not do what I want (in fact it does not do anything). Is there a way to substitute a specific elementary polynomial?

edit retag close merge delete

Sort by » oldest newest most voted

Looking at the source code, the problem seems to be that the subs method requires to be able to count the number of generators of the parent of poly (i.e. Symmetric Functions over Rational Field in the elementary basis), which is infinite.

Since this parent does not provide any ngens method (that is supposed to count the number of generators), the subs method just returns poly unmodified.

So, you have to write your own. I am not completely sure, but i can suggest the following approach: you can have a look at the map_item method of poly. Since you basically want to replace e[1,1] by e (=1), you can do:

sage: def substitution(item, coeff):
....:    if item == Partition([1, 1]):
....:        return (Partition(), coeff)
....:    else:
....:        return (item, coeff)

sage: poly.map_item(substitution)
e[] - 2*e
more