ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 17 Feb 2016 19:40:20 +0100Substitute elementary symmetric functions in a polynomialhttps://ask.sagemath.org/question/32586/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[2]
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[2]
Does not do what I want (in fact it does not do anything). Is there a way to substitute a specific elementary polynomial?Wed, 17 Feb 2016 18:36:12 +0100https://ask.sagemath.org/question/32586/substitute-elementary-symmetric-functions-in-a-polynomial/Answer by tmonteil for <p>Suppose I do the following:</p>
<pre><code>sage: SF=SymmetricFunctions(QQ)
sage: poly=SF.e()(SF.from_polynomial(x^2+y^2))
sage: poly
e[1, 1] - 2*e[2]
</code></pre>
<p>Now I would like to substitute <code>e[1, 1]</code> in that expression. However:</p>
<pre><code>sage: poly.subs({SF.e()[1, 1]: 1})
e[1, 1] - 2*e[2]
</code></pre>
<p>Does not do what I want (in fact it does not do anything). Is there a way to substitute a specific elementary polynomial?</p>
https://ask.sagemath.org/question/32586/substitute-elementary-symmetric-functions-in-a-polynomial/?answer=32592#post-id-32592Looking 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[0]` (=1), you can do:
sage: def substitution(item, coeff):
....: if item == Partition([1, 1]):
....: return (Partition([0]), coeff)
....: else:
....: return (item, coeff)
sage: poly.map_item(substitution)
e[] - 2*e[2]
Wed, 17 Feb 2016 19:40:20 +0100https://ask.sagemath.org/question/32586/substitute-elementary-symmetric-functions-in-a-polynomial/?answer=32592#post-id-32592