How to dynamically pass multivariables while constructing a IntegerModRing?

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 close merge delete

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...

( 2021-06-15 18:04:29 +0200 )edit

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

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

Sort by ยป oldest newest most voted

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.

more

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

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

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

( 2021-06-15 19:46:51 +0200 )edit