11from flint.flint_base.flint_base cimport (
22 flint_mpoly,
3- flint_mpoly_context ,
3+ flint_mod_mpoly_context ,
44 ordering_py_to_c,
55 ordering_c_to_py,
66)
@@ -76,7 +76,7 @@ cimport libc.stdlib
7676cdef dict _fmpz_mod_mpoly_ctx_cache = {}
7777
7878
79- cdef class fmpz_mod_mpoly_ctx(flint_mpoly_context ):
79+ cdef class fmpz_mod_mpoly_ctx(flint_mod_mpoly_context ):
8080 """
8181 A class for storing the polynomial context
8282
@@ -97,60 +97,20 @@ cdef class fmpz_mod_mpoly_ctx(flint_mpoly_context):
9797 raise TypeError (f" modulus ({modulus}) is not coercible to fmpz" )
9898 else :
9999 m = modulus
100- fmpz_mod_mpoly_ctx_init(self .val, nvars, ordering_py_to_c(ordering), m.val)
101- self .__prime_modulus = None
102- super ().__init__(nvars, names)
103-
104- @classmethod
105- def create_context_key (
106- cls ,
107- slong nvars = 1 ,
108- ordering = Ordering.lex,
109- modulus = None ,
110- names: Optional[str] = "x",
111- nametup: Optional[tuple] = None ,
112- ):
113- """
114- Create a key for the context cache via the number of variables, the ordering, the modulus, and either a
115- variable name string, or a tuple of variable names.
116- """
117- # A type hint of ``ordering: Ordering`` results in the error "TypeError: an integer is required" if a Ordering
118- # object is not provided. This is pretty obtuse so we check its type ourselves
119- if not isinstance (ordering, Ordering):
120- raise TypeError (f" 'ordering' ('{ordering}') is not an instance of flint.Ordering" )
121- elif not typecheck(modulus, fmpz):
122- m = any_as_fmpz(modulus)
123- if m is NotImplemented :
124- raise TypeError (f" 'modulus' ('{modulus}') is not coercible to fmpz" )
125- else :
126- modulus = m
127100
128- if nametup is not None :
129- key = nvars, ordering, nametup, modulus
130- elif nametup is None and names is not None :
131- key = nvars, ordering, cls .create_variable_names(nvars, names), modulus
132- else :
133- raise ValueError (" must provide either 'names' or 'nametup'" )
134- return key
101+ super ().__init__(nvars, names, m.is_prime())
102+ fmpz_mod_mpoly_ctx_init(self .val, nvars, ordering_py_to_c(ordering), m.val)
135103
136104 def _any_as_scalar (self , other ):
137105 if isinstance (other, int ):
138106 return any_as_fmpz(other)
139107 elif typecheck(other, nmod):
140- if (< nmod> other).modulus() != self .modulus():
141- raise DomainError(
142- f" modulus does not match, got {(<nmod>other).modulus()}, expected {self.modulus()}"
143- )
144108 return any_as_fmpz((< nmod> other).val)
145109 elif typecheck(other, fmpz):
146110 res = fmpz.__new__ (fmpz)
147111 fmpz_set((< fmpz> res).val, (< fmpz> other).val)
148112 return res
149113 elif typecheck(other, fmpz_mod):
150- if (< fmpz_mod> other).ctx.modulus() != self .modulus():
151- raise DomainError(
152- f" modulus does not match, got {(<fmpz_mod>other).ctx.modulus()}, expected {self.modulus()}"
153- )
154114 res = fmpz.__new__ (fmpz)
155115 fmpz_set((< fmpz> res).val, (< fmpz_mod> other).val)
156116 return res
@@ -197,22 +157,6 @@ cdef class fmpz_mod_mpoly_ctx(flint_mpoly_context):
197157 fmpz_mod_mpoly_ctx_get_modulus(m.val, self .val)
198158 return m
199159
200- def is_prime (self ):
201- """
202- Return whether the modulus is prime
203-
204- >>> from flint import Ordering
205- >>> ctx = fmpz_mod_mpoly_ctx.get_context(4, Ordering.degrevlex, 2**127, 'z')
206- >>> ctx.is_prime()
207- False
208- >>> ctx = fmpz_mod_mpoly_ctx.get_context(4, Ordering.degrevlex, 2**127 - 1, 'z')
209- >>> ctx.is_prime()
210- True
211- """
212- if self .__prime_modulus is None :
213- self .__prime_modulus = < bint> self .modulus().is_prime()
214- return self .__prime_modulus
215-
216160 def gen (self , slong i ):
217161 """
218162 Return the ``i`` th generator of the polynomial ring
0 commit comments