Ask Your Question

Revision history [back]

To complement @max-alekseyev answer, in case you would like the number of indeterminates to change (since they play a symmetric role), you can make the construction depend on the number of indeterminates, as a parameter.

For this, you can first define the polynomial ring, by providing the base ring, the structure of the structure of the names of the indeterminates, and the number of indeterminates:

sage: n = 4
sage: K = PolynomialRing(QQ, 'x_', n)

We have:

sage: K
Multivariate Polynomial Ring in x_0, x_1, x_2, x_3 over Rational Field

But, we did not let the python names x_i point to the polynomial indeterminates x_i:

sage: x_2
NameError: name 'x_2' is not defined

For this, we can do:

sage: K.inject_variables()
Defining x_0, x_1, x_2, x_3

We now have:

sage: x_2
x_2

To easily make loops, instead of manipulating the strings x_i by hand, we can use the tuple of all the indeterminates:

sage: x = K.gens()
sage: x
(x_0, x_1, x_2, x_3)

sage: x[2]
x_2

Now, the first part of your polynomial is a product $(x_i-x_j)$ for $j<i$, which="" can="" be="" written="" as="" a="" double="" loop="" :<="" p="">

sage: prod(x[i]-x[j] for i in range(n) for j in range(i))

Similarly, you can define the whole polynomial using loops:

sage: p = prod(x[i]-x[j] for i in range(n) for j in range(i)) * sum(x[i] for i in range(n))^18 * sum(x[i]^2 for i in range(n))^2

Then, you can extract coefficients you want:

sage: p.monomial_coefficient(x_0^11*x_1^8*x_2^5*x_3^2)
0

Note that it is easier to start with index zero here, since everything in Python starts at zero, so that loops are easier to write. You could of course play with i+1 and i-1 everywhere, but learning to work with indices starting at 0 might be a better long-term investment (you will need it if you manipulate matrices for example).

To complement @max-alekseyev answer, in case you would like the number of indeterminates to change (since they play a symmetric role), you can make the construction depend on the number of indeterminates, as a parameter.

For this, you can first define the polynomial ring, by providing the base ring, the structure of the structure of the names of the indeterminates, and the number of indeterminates:

sage: n = 4
sage: K = PolynomialRing(QQ, 'x_', n)

We have:

sage: K
Multivariate Polynomial Ring in x_0, x_1, x_2, x_3 over Rational Field

But, we did not let the python names x_i point to the polynomial indeterminates x_i:

sage: x_2
NameError: name 'x_2' is not defined

For this, we can do:

sage: K.inject_variables()
Defining x_0, x_1, x_2, x_3

We now have:

sage: x_2
x_2

To easily make loops, instead of manipulating the strings x_i by hand, we can use the tuple of all the indeterminates:

sage: x = K.gens()
sage: x
(x_0, x_1, x_2, x_3)

sage: x[2]
x_2

Now, the first part of your polynomial is a product $(x_i-x_j)$ for $j<i$, $j<i$ which="" can="" be="" written="" as="" a="" double="" loop="" :<="" p="">

sage: prod(x[i]-x[j] for i in range(n) for j in range(i))

Similarly, you can define the whole polynomial using loops:

sage: p = prod(x[i]-x[j] for i in range(n) for j in range(i)) * sum(x[i] for i in range(n))^18 * sum(x[i]^2 for i in range(n))^2

Then, you can extract coefficients you want:

sage: p.monomial_coefficient(x_0^11*x_1^8*x_2^5*x_3^2)
0

Note that it is easier to start with index zero here, since everything in Python starts at zero, so that loops are easier to write. You could of course play with i+1 and i-1 everywhere, but learning to work with indices starting at 0 might be a better long-term investment (you will need it if you manipulate matrices for example).

To complement @max-alekseyev answer, in case you would like the number of indeterminates to change (since they play a symmetric role), you can make the construction depend on the number of indeterminates, as a parameter.

For this, you can first define the polynomial ring, by providing the base ring, the structure of the structure of the names of the indeterminates, and the number of indeterminates:

sage: n = 4
sage: K = PolynomialRing(QQ, 'x_', n)

We have:

sage: K
Multivariate Polynomial Ring in x_0, x_1, x_2, x_3 over Rational Field

But, we did not let the python names x_i point to the polynomial indeterminates x_i:

sage: x_2
NameError: name 'x_2' is not defined

For this, we can do:

sage: K.inject_variables()
Defining x_0, x_1, x_2, x_3

We now have:

sage: x_2
x_2

To easily make loops, instead of manipulating the strings x_i by hand, we can use the tuple of all the indeterminates:

sage: x = K.gens()
sage: x
(x_0, x_1, x_2, x_3)

sage: x[2]
x_2

Now, the first part of your polynomial is a product $(x_i-x_j)$ for $j<i$ which="" can="" be="" written="" as="" a="" double="" loop="" :<="" p="">

$ (x_i-x_j) $ for $ j 

sage: prod(x[i]-x[j] for i in range(n) for j in range(i))

Similarly, you can define the whole polynomial using loops:

sage: p = prod(x[i]-x[j] for i in range(n) for j in range(i)) * sum(x[i] for i in range(n))^18 * sum(x[i]^2 for i in range(n))^2

Then, you can extract coefficients you want:

sage: p.monomial_coefficient(x_0^11*x_1^8*x_2^5*x_3^2)
0

Note that it is easier to start with index zero here, since everything in Python starts at zero, so that loops are easier to write. You could of course play with i+1 and i-1 everywhere, but learning to work with indices starting at 0 might be a better long-term investment (you will need it if you manipulate matrices for example).

To complement @max-alekseyev answer, in case you would like the number of indeterminates to change (since they play a symmetric role), you can make the construction depend on the number of indeterminates, as a parameter.

For this, you can first define the polynomial ring, by providing the base ring, the structure of the structure of the names of the indeterminates, and the number of indeterminates:

sage: n = 4
sage: K = PolynomialRing(QQ, 'x_', n)

We have:

sage: K
Multivariate Polynomial Ring in x_0, x_1, x_2, x_3 over Rational Field

But, we did not let the python names x_i point to the polynomial indeterminates x_i:

sage: x_2
NameError: name 'x_2' is not defined

For this, we can do:

sage: K.inject_variables()
Defining x_0, x_1, x_2, x_3

We now have:

sage: x_2
x_2

To easily make loops, instead of manipulating the strings x_i by hand, we can use the tuple of all the indeterminates:

sage: x = K.gens()
sage: x
(x_0, x_1, x_2, x_3)

sage: x[2]
x_2

Now, the first part of your polynomial is a product $ (x_i-x_j) $ for $ j

sage: prod(x[i]-x[j] for i in range(n) for j in range(i))

Similarly, you can define the whole polynomial using loops:

sage: p = prod(x[i]-x[j] for i in range(n) for j in range(i)) * sum(x[i] for i in range(n))^18 * sum(x[i]^2 for i in range(n))^2

Then, you can extract coefficients you want:

sage: p.monomial_coefficient(x_0^11*x_1^8*x_2^5*x_3^2)
0

Note that it is easier to start with index zero here, since everything in Python starts at zero, so that loops are easier to write. You could of course play with i+1 and i-1 everywhere, but learning to work with indices starting at 0 might be a better long-term investment (you will need it if you manipulate matrices for example).

To complement @max-alekseyev answer, in case you would like the number of indeterminates to change (since they play a symmetric role), you can make the construction depend on the number of indeterminates, as a parameter.

For this, you can first define the polynomial ring, by providing the base ring, the structure of the structure of the names of the indeterminates, and the number of indeterminates:

sage: n = 4
sage: K = PolynomialRing(QQ, 'x_', n)

We have:

sage: K
Multivariate Polynomial Ring in x_0, x_1, x_2, x_3 over Rational Field

But, we did not let the python names x_i point to the polynomial indeterminates x_i:

sage: x_2
NameError: name 'x_2' is not defined

For this, we can do:

sage: K.inject_variables()
Defining x_0, x_1, x_2, x_3

We now have:

sage: x_2
x_2

To easily make loops, instead of manipulating the strings x_i by hand, we can use the tuple of all the indeterminates:

sage: x = K.gens()
sage: x
(x_0, x_1, x_2, x_3)

sage: x[2]
x_2

Now, the first part of your polynomial is a product $ (x_i-x_j) $ for j

of (x_i-x_j) for j<i which can be written as a double loop :

sage: prod(x[i]-x[j] for i in range(n) for j in range(i))

Similarly, you can define the whole polynomial using loops:

sage: p = prod(x[i]-x[j] for i in range(n) for j in range(i)) * sum(x[i] for i in range(n))^18 * sum(x[i]^2 for i in range(n))^2

Then, you can extract coefficients you want:

sage: p.monomial_coefficient(x_0^11*x_1^8*x_2^5*x_3^2)
0

Note that it is easier to start with index zero here, since everything in Python starts at zero, so that loops are easier to write. You could of course play with i+1 and i-1 everywhere, but learning to work with indices starting at 0 might be a better long-term investment (you will need it if you manipulate matrices for example).

To complement @max-alekseyev answer, in case you one would like the number of indeterminates to change (since they play a symmetric role), you can make the construction depend on the number of indeterminates, as a parameter.

For this, you we can first define the polynomial ring, by providing the base ring, the structure of the structure of the names of the indeterminates, and the number of indeterminates:

sage: n = 4
sage: K = PolynomialRing(QQ, 'x_', n)

We have:

sage: K
Multivariate Polynomial Ring in x_0, x_1, x_2, x_3 over Rational Field

But, we did not let the python Python names x_i point to the polynomial indeterminates x_i:

sage: x_2
NameError: name 'x_2' is not defined

For this, we can do:

sage: K.inject_variables()
Defining x_0, x_1, x_2, x_3

We now have:

sage: x_2
x_2

To easily make loops, instead of manipulating the strings x_i by hand, we can use the tuple of all the indeterminates:

sage: x = K.gens()
sage: x
(x_0, x_1, x_2, x_3)

sage: x[2]
x_2

Now, the first part of your polynomial is a product of (x_i-x_j) for j<i which can be written as a double loop :

sage: prod(x[i]-x[j] for i in range(n) for j in range(i))

Similarly, you can define the whole polynomial using loops:

sage: p = prod(x[i]-x[j] for i in range(n) for j in range(i)) * sum(x[i] for i in range(n))^18 * sum(x[i]^2 for i in range(n))^2

Then, you can extract coefficients you want:

sage: p.monomial_coefficient(x_0^11*x_1^8*x_2^5*x_3^2)
0

Note that it is easier to start with index zero here, since everything in Python starts start at zero, so that loops are easier to write. You We could of course play with i+1 and i-1 everywhere, but learning to work with indices starting at 0 might be a better long-term investment (you (we will need it if you manipulate in manipulating matrices for example).

To complement @max-alekseyev answer, in case one would like the number of indeterminates to change (since they play a symmetric role), you can make the construction depend on the number of indeterminates, as a parameter.

For this, we can first define the polynomial ring, by providing the base ring, the structure of the names of the indeterminates, and the number of indeterminates:

sage: n = 4
sage: K = PolynomialRing(QQ, 'x_', n)

We have:

sage: K
Multivariate Polynomial Ring in x_0, x_1, x_2, x_3 over Rational Field

But, we did not let the Python names x_i point to the polynomial indeterminates x_i:

sage: x_2
NameError: name 'x_2' is not defined

For this, we can do:

sage: K.inject_variables()
Defining x_0, x_1, x_2, x_3

We now have:

sage: x_2
x_2

To easily make loops, instead of manipulating the strings x_i by hand, we can use the tuple of all the indeterminates:

sage: x = K.gens()
sage: x
(x_0, x_1, x_2, x_3)

sage: x[2]
x_2

Now, the first part of your polynomial is a product of (x_i-x_j) for j<i which can be written as a double loop :

sage: prod(x[i]-x[j] for i in range(n) for j in range(i))

Similarly, you we can define the whole polynomial using loops:

sage: p = prod(x[i]-x[j] for i in range(n) for j in range(i)) * sum(x[i] for i in range(n))^18 * sum(x[i]^2 for i in range(n))^2

Then, you we can extract coefficients you want:

sage: p.monomial_coefficient(x_0^11*x_1^8*x_2^5*x_3^2)
0

Note that it is easier to start with index zero here, since everything in Python start at zero, so that loops are easier to write. We could of course play with i+1 and i-1 everywhere, but learning to work with indices starting at 0 might be a better long-term investment (we will need it in manipulating matrices for example).