Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

For polynomial substitution there are several possibilities:

sage: R.<x,y,z> = QQ[]
sage: f = x^2*y + y^2*z + z^2*x
sage: f(1, 2, 3)
23
sage: f(x=1, y=2, z=3)
23
sage: f.subs(x=1, y=2, z=3)
23
sage: f(x=1)
y^2*z + z^2 + y

To handle symmetric polynomials it may be best to work in a polynomial ring. For example:

sage: E = SymmetricFunctionAlgebra(QQ, basis='elementary')
sage: g = E([2,1])
sage: h = g.expand(3); h
x0^2*x1 + x0*x1^2 + x0^2*x2 + 3*x0*x1*x2 + x1^2*x2 + x0*x2^2 + x1*x2^2
sage: R = h.parent()
sage: x0, x1, x2 = R.gens()

We can then check symmetry

sage: h == h(x0=x1, x1=x0) and h == h(x0=x1, x1=x2, x2=x0)
True

and do other sorts of substitution

sage: S.<q> = R[]
sage: h(1, q, q^2)
q^5 + 2*q^4 + 3*q^3 + 2*q^2 + q