Ask Your Question

polynomial evaluation

asked 2013-02-05 03:27:47 -0500

db gravatar image

If I have a polynomial p in variables $x_0,...,x_n$, how do I specialize the algebra appropriately to substitute values for $x_i$'s? For example, how do I compute $p(1,1,...,1)$? Or replace $x_i$ by $q^i$ ($q$ a parameter) so to compute $p(1,q,...,q^n)$? In Mathematica, if the variables were x[[i]], one could do "./x[[i]] -> q^i //Simplify" and it is the equivalent of this replace and simplify that I am looking for.

This is coming from symmetric polynomials/functions theory and I know some of the specializations are built in, but at the end of the day I want to try small examples with different specializations than what is already built in.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-02-05 23:22:52 -0500

Francis Clarke gravatar image

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)
sage: f(x=1, y=2, z=3)
sage: f.subs(x=1, y=2, z=3)
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)

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
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-02-05 03:27:47 -0500

Seen: 1,361 times

Last updated: Feb 05 '13