Ask Your Question
0

How to dynamically pass multivariables while constructing a IntegerModRing?

asked 2021-06-15 17:53:20 +0200

Senthil gravatar image

updated 2021-06-15 18:23:43 +0200

I want to construct variables from an array of strings and then pass to IntegerModRing

Currently I am hardcoding the variables like below

R.<f1c1,f1c2,f2c1> = IntegerModRing(3^3)[]

R.<f1c1,f1c2,f1c3,f2c1,f3c1> = IntegerModRing(3^4)[]

R.<f1c1,f1c2,f1c3,f1c4,f2c1,f2c2,f3c1,f4c1>
= IntegerModRing(3^5)[]

so on.... 3^6 , 3^7...

I tried like below , but not working for me

xs = ['f1c1','f1c2','f1c3','f1c4','f1c5','f1c6','f2c1','f2c2','f2c3','f3c1','f3c2','f4c1','f5c1','f6c1']

R = IntegerModRing(3^7,names=xs)[]

I want to construct variables from an array of strings and then pass to IntegerModRing

edit retag flag offensive close merge delete

Comments

Are we supposed to guess the relationship you with to establish between the ring an the number and nams of the variables ?

You must be kidding...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2021-06-15 18:04:29 +0200 )edit

I want to construct variables from an array of strings and then pass to IntegerModRing

Senthil gravatar imageSenthil ( 2021-06-15 18:07:23 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-06-15 18:57:34 +0200

tmonteil gravatar image

Your last construction is incorrect since IntegerModRing does not have a name parameter. If i understand correctly, you want to construct a polynomial ring in various indeterminates whose base ring is an integer mod ring. Here is how:

sage: xs = ['f1c1','f1c2','f1c3','f1c4','f1c5','f1c6','f2c1','f2c2','f2c3','f3c1','f3c2','f4c1','f5c1','f6c1']

Define the polynomial ring:

sage: R = PolynomialRing(IntegerModRing(3^7),names=xs)
sage: R
Multivariate Polynomial Ring in f1c1, f1c2, f1c3, f1c4, f1c5, f1c6, f2c1, f2c2, f2c3, f3c1, f3c2, f4c1, f5c1, f6c1 over Ring of integers modulo 2187

To let the Python names f1c1, f1c2, ... point to the corresponding indeterminates:

sage: R.inject_variables()
Defining f1c1, f1c2, f1c3, f1c4, f1c5, f1c6, f2c1, f2c2, f2c3, f3c1, f3c2, f4c1, f5c1, f6c1

Then, you can play :

sage: f1c3 * f1c6^2 + 3^4 * f2c3 + 3^3 * f3c1
f1c3*f1c6^2 + 81*f2c3 + 27*f3c1
sage: P = f1c3 * f1c6^2 + 3^4 * f2c3 + 3^3 * f3c1
sage: P
f1c3*f1c6^2 + 81*f2c3 + 27*f3c1
sage: P^2
f1c3^2*f1c6^4 + 162*f1c3*f1c6^2*f2c3 + 54*f1c3*f1c6^2*f3c1 + 729*f3c1^2

As you can see, the monomials (3^4 * f2c3)^2 and 3^4 * f2c3 * 3^3 * f3c1 have been cancelled.

edit flag offensive delete link more

Comments

Thanks a lot. It worked.

One more question , How to enumerate those variables after injection?

Update: Found Answer for the above question , mentioned in the below comment

Senthil gravatar imageSenthil ( 2021-06-15 19:25:56 +0200 )edit
1

using R.gens() . Able to enumerate..

Senthil gravatar imageSenthil ( 2021-06-15 19:46:51 +0200 )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

Stats

Asked: 2021-06-15 17:53:20 +0200

Seen: 127 times

Last updated: Jun 15 '21