Ask Your Question
2

Infinite polynomial ring with several index

asked 2019-05-10 20:54:43 +0100

ianncunha gravatar image

I know it's easy to create a infinite polynomial ring:

R.<y>=InfinitePolynomialRing(ZZ)

But how can I make a infinite polynomial ring with variables indexed by pairs, like x_(a,b)?

edit retag flag offensive close merge delete

Comments

How much of the InfinitePolynomialRing do you need? I have modified the code of Sage that implements this function and related ones, but I don't have complete functionality. For now, I only have polynomial algebra implemented. Also, it is not possible to use "x_(a,b)", since there is a Sage function that validates variable names, and that is not a valid one. What I used is "x[a,b]" which creates a "x_a_b".

I could send you the modified code, so you can complete the implementation as needed by you.

dsejas gravatar imagedsejas ( 2019-05-12 07:12:21 +0100 )edit

Nice! If you can send it to me it would be great!

ianncunha gravatar imageianncunha ( 2019-05-13 19:41:31 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2019-05-11 22:53:10 +0100

slelievre gravatar image

One workaround would be to use an infinite polynomial ring in $x$ and $y$, with $x_i y_j$ standing for $x_{i, j}$.

sage: R.<x, y> = InfinitePolynomialRing(ZZ)
sage: x
x_*
sage: y
y_*
sage: x[3]*y[4]
x_3*y_4
sage: y[6]*x[1]
x_1*y_6
edit flag offensive delete link more

Comments

Yeah, I thought of that. But I would like to know if there is any way to put a function (or something) that returns in the form x_a_b, for a infinite set.

By the way, is easy (but not so good-looking) to define like

def z(a,b):
    z=var('z_%d_%d' %(i,j))
    return z
ianncunha gravatar imageianncunha ( 2019-05-13 19:52:54 +0100 )edit
0

answered 2019-05-14 06:05:58 +0100

dsejas gravatar image

updated 2019-05-16 05:05:33 +0100

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.

edit flag offensive delete link more

Comments

Hello, @ianncunha. Apparently, I made a mistake when uploading the modified code. I have updated the links in my answer. Please, let me know if you can access it.

dsejas gravatar imagedsejas ( 2019-05-16 01:01:18 +0100 )edit

Hello, @ianncunha. I have updated my answer. You can find pointers to a minimal implementation. Please, let me know if this solves your problem. If you require something extra about this, maybe I can help, but you should give me a little time to work. Best regards!

dsejas gravatar imagedsejas ( 2019-05-16 04:54:59 +0100 )edit

Hello, @ianncunha. Since it has been a long time since I posted my answer, I was wondering if it was useful for you. If that is the case, I would appreciate you to tick the answer as correct, so other people can find the answer if they need it.

dsejas gravatar imagedsejas ( 2019-10-15 17:38:28 +0100 )edit

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-05-10 20:54:43 +0100

Seen: 505 times

Last updated: May 16 '19