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.Fri, 09 Jan 2015 14:58:34 +0100Substitute square in polynomialhttps://ask.sagemath.org/question/25452/substitute-square-in-polynomial/Suppose I have a univariate polynomial, say from `QQ['x']`, and for some reason I know that the odd coefficients will all be zero. So in fact this is a polynomial in `x^2`. What's the most elegant syntax to substitute some other value for `x^2`?
The best I could come up with so far is something like this:
sage: x = QQ['x'].0
sage: p = x^6 - 3*x^4 + 5*x^2 - 9
sage: assert not any(p[i] for i in range(1,p.degree()+1,2))
sage: p.parent([p[i] for i in range(0,p.degree()+1,2)])
x^3 - 3*x^2 + 5*x - 9
sage: _(7)
222
Of course, if the value I want to plug in comes from some field where I can compute square roots, I could simply plug one of those in, like `p(sqrt(7))` in the example above, but I'm more interested in substituting a multivariate polynomial or something like this.MvGFri, 09 Jan 2015 14:58:34 +0100https://ask.sagemath.org/question/25452/