Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hello, @ianncunha. Here is the modified code. You can use a program like diff or meld to make comparisons with the original code. (By the way, this is a modification of the file <sage>/rings/polynomial/infinite_polynomial_ring.py. I have removed most of the comments to able to reverse-engineer the code. However, I have kept the copyright note and added my name as "modified by". I hope this is enough to respect the authorship and legal notices. If somebody finds I made something wrong regarding license/authorship, please DO let me know so I can make the corrections.)

On the other hand, I can recommend you an alternative less complicated that I just discovered. You can manually add members to an infinite polynomial ring as follows. First, you need to import the PolynomialRing constructor:

from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing

Then, you can create a Polynomial ring over $\mathbb{Z}$ by calling

P = PolynomialRing(ZZ,('x_0_0'))

In this case, the only generator in P is x_0_0. You can make algebra with this element like this:

5*P('x_0_0')+7*P('x_0_0')

This will return 12*x_0_0, which is beautiful. You can also check the structure with

print(P)

which will return

Univariate Polynomial Ring in x_0_0 over Integer Ring

Of course, this is far from what you wanted, but fear not. You can add a new generator as required. For example, suppose you need a x_0_1. You just have to write the following:

R = PolynomialRing(P.base_ring(), P.gens()+('x_0_1',))

The last comma is so that Sage recognizes the tuple; otherwise, it assumes it's a string inside parentheses. Anyway, now you can make algebra with this new element. For example,

4*R('x_0_1')+5*R('x_0_0')+3*R('x_0_0')

will return

8*x_0_0 + 4*x_0_1

You will also notice that

print(P)

now says

Multivariate Polynomial Ring in x_0_0, x_0_1 over Integer Ring

so Sage automatically recognizes when you have univariate and multivariate rings. You keep adding variables as needed, without the need for them to be defined sequentially. For example, next you can create x_3_27.

In the depths of the Sage code that deals with Polynomial Rings, this is roughly equivalent to a "sparse" construction, which is an efficient way. You can wrap all of this code into a new Python class, so that dealing with it is easier.

I hope this helps!

Hello, @ianncunha. Here is the modified code. You can use a program like diff or meld to make comparisons with the original code. (By the way, this is a modification of the file <sage>/rings/polynomial/infinite_polynomial_ring.py. I have removed most of the comments to able to reverse-engineer the code. However, I have kept the copyright note and added my name as "modified by". I hope this is enough to respect the authorship and legal notices. If somebody finds I made something wrong regarding license/authorship, please DO let me know so I can make the corrections.)corrections.) You just have to save the code in a file, let's say "poly.py" and make from poly import *; this rest is like using regular Sage commands for infinite polynomial rings.

On the other hand, I can recommend share with you an alternative less complicated that I just discovered. discovered a few hours ago. You can manually add members to an infinite polynomial ring as follows. First, you need to import the PolynomialRing constructor:

from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing

Then, you can create a Polynomial ring over $\mathbb{Z}$ by calling

P = PolynomialRing(ZZ,('x_0_0'))
PolynomialRing(ZZ, ('x_0_0'))

In this case, the only generator in of P is x_0_0. You can make algebra with this element like this:

5*P('x_0_0')+7*P('x_0_0')

This will return 12*x_0_0, which is beautiful. You can also check the structure with

print(P)

which will return

Univariate Polynomial Ring in x_0_0 over Integer Ring

Of course, this is far from what you wanted, but fear not. You can add a new generator as required. For example, suppose you need a x_0_1. You just have to write the following:

R P = PolynomialRing(P.base_ring(), P.gens()+('x_0_1',))

The last comma is so that Sage recognizes the tuple; otherwise, it assumes it's a string inside parentheses. Anyway, now you can make algebra with this new element. element too. For example,

4*R('x_0_1')+5*R('x_0_0')+3*R('x_0_0')

will return

8*x_0_0 + 4*x_0_1

You will also notice that

print(P)

now says

Multivariate Polynomial Ring in x_0_0, x_0_1 over Integer Ring

so Sage automatically recognizes when you have univariate and multivariate rings. You keep adding variables as needed, without the need for them to be defined sequentially. For example, next you can create x_3_27.

In the depths of the Sage code that deals with Polynomial Rings, this is roughly ROUGHLY equivalent to a "sparse" construction, which is an efficient way. You can wrap all of this code into a new Python class, so that dealing with it is easier.

I hope this helps!

Hello, @ianncunha. Here is the modified code. You can use a program like diff or meld to make comparisons with the original code. (By the way, this is a modification of the file <sage>/rings/polynomial/infinite_polynomial_ring.py. I have removed most of the comments to able to reverse-engineer the code. However, I have kept the copyright note and added my name as "modified by". I hope this is enough to respect the authorship and legal notices. If somebody finds I made something wrong regarding license/authorship, please DO let me know so I can make the corrections.) You just have to save the code in a file, let's say "poly.py" "poly.py", and make from poly import *; this rest is like using regular Sage commands for infinite polynomial rings.

On the other hand, I can share with you an alternative less complicated that I just discovered a few hours ago. You can manually add members to an infinite polynomial ring as follows. First, you need to import the PolynomialRing constructor:

from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing

Then, you can create a Polynomial ring over $\mathbb{Z}$ by calling

P = PolynomialRing(ZZ, ('x_0_0'))

In this case, the only generator of P is x_0_0. You can make algebra with this element like this:

5*P('x_0_0')+7*P('x_0_0')

This will return 12*x_0_0, which is beautiful. You can also check the structure with

print(P)

which will return

Univariate Polynomial Ring in x_0_0 over Integer Ring

Of course, this is far from what you wanted, but fear not. You can add a new generator as required. For example, suppose you need a x_0_1. You just have to write the following:

P = PolynomialRing(P.base_ring(), P.gens()+('x_0_1',))

The last comma is so that Sage recognizes the tuple; otherwise, it assumes it's a string inside parentheses. Anyway, now you can make algebra with this new element too. For example,

4*R('x_0_1')+5*R('x_0_0')+3*R('x_0_0')

will return

8*x_0_0 + 4*x_0_1

You will also notice that

print(P)

now says

Multivariate Polynomial Ring in x_0_0, x_0_1 over Integer Ring

so Sage automatically recognizes when you have univariate and multivariate rings. You keep adding variables as needed, without the need for them to be defined sequentially. For example, next you can create x_3_27.

In the depths of the Sage code that deals with Polynomial Rings, this is ROUGHLY equivalent to a "sparse" construction, which is an efficient way. You can wrap all of this code into a new Python class, so that dealing with it is easier.

I hope this helps!

Hello, @ianncunha. Here is the modified code. You can use a program like diff or meld to make comparisons with the original code. (By the way, this is a modification of the file <sage>/rings/polynomial/infinite_polynomial_ring.py. I have removed most of the comments to able to reverse-engineer the code. However, I have kept the copyright note and added my name as "modified by". I hope this is enough to respect the authorship and legal notices. If somebody finds I made something wrong regarding license/authorship, please DO let me know so I can make the corrections.) You just have to save the code in a file, let's say "poly.py", and make from poly import *; this rest is like using regular Sage commands for infinite polynomial rings.

On the other hand, I can share with you an alternative less complicated that I just discovered a few hours ago. You can manually add members to an infinite polynomial ring as follows. First, you need to import the PolynomialRing constructor:

from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing

Then, you can create a Polynomial ring over $\mathbb{Z}$ by calling

P = PolynomialRing(ZZ, ('x_0_0'))

In this case, the only generator of P is x_0_0. You can make algebra with this element like this:

5*P('x_0_0')+7*P('x_0_0')

This will return 12*x_0_0, which is beautiful. You can also check the structure with

print(P)

which will return

Univariate Polynomial Ring in x_0_0 over Integer Ring

Of course, this is far from what you wanted, but fear not. You can add a new generator as required. For example, suppose you need a x_0_1. You just have to write the following:

P = PolynomialRing(P.base_ring(), P.gens()+('x_0_1',))

The last comma is so that Sage recognizes the tuple; otherwise, it assumes it's a string inside parentheses. Anyway, now you can make algebra with this new element too. For example,

4*R('x_0_1')+5*R('x_0_0')+3*R('x_0_0')

will return

8*x_0_0 + 4*x_0_1

You will also notice that

print(P)

now says

Multivariate Polynomial Ring in x_0_0, x_0_1 over Integer Ring

so Sage automatically recognizes when you have univariate and multivariate rings. You keep adding variables as needed, without the need for them to be defined sequentially. For example, next you can create x_3_27.

In the depths of the Sage code that deals with Polynomial Rings, this is ROUGHLY equivalent to a "sparse" construction, which is an efficient way. You can wrap all of this code into a new Python class, so that dealing with it is easier.

I hope this helps!

Hello, @ianncunha. Here is the modified code. You can use a program like diff or meld to make comparisons with the original code. (By the way, this is a modification of the file <sage>/rings/polynomial/infinite_polynomial_ring.py. I have removed most of the comments to able to reverse-engineer the code. However, I have kept the copyright note and added my name as "modified by". I hope this is enough to respect the authorship and legal notices. If somebody finds I made something wrong regarding license/authorship, please DO let me know so I can make the corrections.) You just have to save the code in a file, let's say "poly.py", and make from poly import *; this rest is like using regular Sage commands for infinite polynomial rings.

On the other hand, I can share with you an alternative less complicated that I just discovered a few hours ago. You can manually add members to an infinite polynomial ring as follows. First, you need to import the PolynomialRing constructor:

from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing

Then, you can create a Polynomial ring over $\mathbb{Z}$ by calling

P = PolynomialRing(ZZ, ('x_0_0'))

In this case, the only generator of P is x_0_0. You can make algebra with this element like this:

5*P('x_0_0')+7*P('x_0_0')

This will return 12*x_0_0, which is beautiful. You can also check the structure with

print(P)

which will return

Univariate Polynomial Ring in x_0_0 over Integer Ring

Of course, this is far from what you wanted, but fear not. You can add a new generator as required. For example, suppose you need a x_0_1. You just have to write the following:

P = PolynomialRing(P.base_ring(), P.gens()+('x_0_1',))

The last comma is so that Sage recognizes the tuple; otherwise, it assumes it's a string inside parentheses. Anyway, now you can make algebra with this new element too. For example,

4*R('x_0_1')+5*R('x_0_0')+3*R('x_0_0')

will return

8*x_0_0 + 4*x_0_1

You will also notice that

print(P)

now says

Multivariate Polynomial Ring in x_0_0, x_0_1 over Integer Ring

so Sage automatically recognizes when you have univariate and multivariate rings. You keep adding variables as needed, without the need for them to be defined sequentially. For example, next you can create x_3_27.

In the depths of the Sage code that deals with Polynomial Rings, this is ROUGHLY equivalent to a "sparse" construction, which is an efficient way. You can wrap all of this code into a new Python class, so that dealing with it is easier.

I A minimal working implementation can be found here. You can save the code inside a file, e.g. "poly_rings.py" (in the same folder where you call Sage), and, in SageMath, you just have to "from poly_rings.py import *". You can then define an infinite polynomial ring with bi-indexed variables using

P.<x> = PolyRing(ZZ)

That's it!

This needs to be completed as required. For example, you can't call P.one(), unless you define it first. However, it is a functional implementation. Besides that, the actual Polynomial Ring is stored inside P._P, so you could also call P._P.one(). Finally, I have created a minimal test file here that will show you the usage (copy-and-paste it on the REPL).

I really hope this helps!

helps! Please, let me know if this solves your problem.

Hello, @ianncunha. Here is the modified code. You can use a program like diff or meld to make comparisons with the original code. (By the way, this is a modification of the file <sage>/rings/polynomial/infinite_polynomial_ring.py. I have removed most of the comments to able to reverse-engineer the code. However, I have kept the copyright note and added my name as "modified by". I hope this is enough to respect the authorship and legal notices. If somebody finds I made something wrong regarding license/authorship, please DO let me know so I can make the corrections.) You just have to save the code in a file, let's say "poly.py", and make from poly import *; this rest is like using regular Sage commands for infinite polynomial rings.

On the other hand, I can share with you an alternative less complicated that I just discovered a few hours ago. You can manually add members to an infinite polynomial ring as follows. First, you need to import the PolynomialRing constructor:

from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing

Then, you can create a Polynomial ring over $\mathbb{Z}$ by calling

P = PolynomialRing(ZZ, ('x_0_0'))

In this case, the only generator of P is x_0_0. You can make algebra with this element like this:

5*P('x_0_0')+7*P('x_0_0')

This will return 12*x_0_0, which is beautiful. You can also check the structure with

print(P)

which will return

Univariate Polynomial Ring in x_0_0 over Integer Ring

Of course, this is far from what you wanted, but fear not. You can add a new generator as required. For example, suppose you need a x_0_1. You just have to write the following:

P = PolynomialRing(P.base_ring(), P.gens()+('x_0_1',))

The last comma is so that Sage recognizes the tuple; otherwise, it assumes it's a string inside parentheses. Anyway, now you can make algebra with this new element too. For example,

4*R('x_0_1')+5*R('x_0_0')+3*R('x_0_0')

will return

8*x_0_0 + 4*x_0_1

You will also notice that

print(P)

now says

Multivariate Polynomial Ring in x_0_0, x_0_1 over Integer Ring

so Sage automatically recognizes when you have univariate and multivariate rings. You keep adding variables as needed, without the need for them to be defined sequentially. For example, next you can create x_3_27.

In the depths of the Sage code that deals with Polynomial Rings, this is ROUGHLY equivalent to a "sparse" construction, which is an efficient way. You can wrap all of this code into a new Python class, so that dealing with it is easier.

A minimal working implementation can be found here. You can save the code inside a file, e.g. "poly_rings.py" (in the same folder where you call Sage), and, in SageMath, you just have to "from poly_rings.py import *". You can then define an infinite polynomial ring with bi-indexed variables using

P.<x> = PolyRing(ZZ)

That's it!

This needs to be completed as required. For example, you can't call P.one(), unless you define it first. However, it is a functional implementation. Besides that, the actual Polynomial Ring is stored inside P._P, so you could also call P._P.one(). Finally, I have created a minimal test file here that will show you the usage (copy-and-paste it on the REPL).

I really hope this helps! Please, let me know if this solves your problem.