Ask Your Question
0

How to dynamically pass multivariables while constructing a IntegerModRing?

asked 3 years ago

Senthil gravatar image

updated 3 years ago

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

Preview: (hide)

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 ( 3 years ago )

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

Senthil gravatar imageSenthil ( 3 years ago )

1 Answer

Sort by » oldest newest most voted
1

answered 3 years ago

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.

Preview: (hide)
link

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 ( 3 years ago )
1

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

Senthil gravatar imageSenthil ( 3 years ago )

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: 3 years ago

Seen: 221 times

Last updated: Jun 15 '21