1 | initial version |
Regarding your question (1), you can not pass a list of "variables" since they are not defined yet (or there is a chicken-and-egg stuff there). However, you can pass the names of the indeterminates as a list of strings as follows:
sage: B = PolynomialRing(QQ,['a','b','c'])
sage: B
Multivariate Polynomial Ring in a, b, c over Rational Field
Now, if you want the Python name a
point to the polynomial indeterminate a
, and so on, you have to do:
sage: B.inject_variables()
Defining a, b, c
Regarding your question (2), if i understand your question, it seems you are doing things in the reverse order. What you want are polynomial whose indeterminates are x,y,z
, so you will define them over the ring which is made of the polynomials over QQ
with variables a,b,c
:
sage: B.<a,b,c> = QQ[]; B
Multivariate Polynomial Ring in a, b, c over Rational Field
sage: A.<x,y,z>=B[] ; A
Multivariate Polynomial Ring in x, y, z over Multivariate Polynomial Ring in a, b, c over Rational Field
sage: ex = (1-a^2)*x*y^2+(a-b^2+c)*x*y*z+(b^2-c^2-a)*x^2*z
sage: ex
(-a^2 + 1)*x*y^2 + (b^2 - c^2 - a)*x^2*z + (-b^2 + a + c)*x*y*z
sage: ex.coefficients()
[-a^2 + 1, b^2 - c^2 - a, -b^2 + a + c]
sage: ex.monomials()
[x*y^2, x^2*z, x*y*z]
But also:
sage: ex.dict()
{(1, 1, 1): -b^2 + a + c, (1, 2, 0): -a^2 + 1, (2, 0, 1): b^2 - c^2 - a}
sage: dict(ex)
{-b^2 + a + c: x*y*z, b^2 - c^2 - a: x^2*z, -a^2 + 1: x*y^2}
sage: list(ex)
[(-a^2 + 1, x*y^2), (b^2 - c^2 - a, x^2*z), (-b^2 + a + c, x*y*z)]
2 | No.2 Revision |
Regarding your question (1), you can not pass a list of "variables" since they are not defined yet (or there is a chicken-and-egg stuff there). However, you can pass the names of the indeterminates as a list of strings as follows:
sage: B = PolynomialRing(QQ,['a','b','c'])
sage: B
Multivariate Polynomial Ring in a, b, c over Rational Field
Now, if you want the Python name a
point to the polynomial indeterminate a
, and so on, you have to do:
sage: B.inject_variables()
Defining a, b, c
Regarding your question (2), if i understand your question, it seems you are doing things in the reverse order. What you want are polynomial whose indeterminates are x,y,z
, so you will define them over the ring which is made of the polynomials over QQ
with variables a,b,c
:
sage: B.<a,b,c> = QQ[]; B
Multivariate Polynomial Ring in a, b, c over Rational Field
sage: A.<x,y,z>=B[] ; A
Multivariate Polynomial Ring in x, y, z over Multivariate Polynomial Ring in a, b, c over Rational Field
sage: ex = (1-a^2)*x*y^2+(a-b^2+c)*x*y*z+(b^2-c^2-a)*x^2*z
sage: ex
(-a^2 + 1)*x*y^2 + (b^2 - c^2 - a)*x^2*z + (-b^2 + a + c)*x*y*z
sage: ex.coefficients()
[-a^2 + 1, b^2 - c^2 - a, -b^2 + a + c]
sage: ex.monomials()
[x*y^2, x^2*z, x*y*z]
But also:
sage: list(ex)
[(-a^2 + 1, x*y^2), (b^2 - c^2 - a, x^2*z), (-b^2 + a + c, x*y*z)]
sage: dict(ex)
{-b^2 + a + c: x*y*z, b^2 - c^2 - a: x^2*z, -a^2 + 1: x*y^2}
sage: ex.dict()
{(1, 1, 1): -b^2 + a + c, (1, 2, 0): -a^2 + 1, (2, 0, 1): b^2 - c^2 - a}
sage: dict(ex)
{-b^2 + a + c: x*y*z, b^2 - c^2 - a: x^2*z, -a^2 + 1: x*y^2}
sage: list(ex)
[(-a^2 + 1, x*y^2), (b^2 - c^2 - a, x^2*z), (-b^2 + a + c, x*y*z)]