@@ -229,7 +229,7 @@ cdef class flint_poly(flint_elem):
229229 integer root and *m* is the multiplicity of the root.
230230
231231 To compute complex roots of a polynomial, instead use
232- the `.complex_roots()` method, which is available on
232+ the `` .complex_roots()` ` method, which is available on
233233 certain polynomial rings.
234234
235235 >>> from flint import fmpz_poly
@@ -322,9 +322,9 @@ cdef class flint_mpoly_context(flint_elem):
322322 @staticmethod
323323 def create_variable_names (slong nvars , names: str ):
324324 """
325- Create a tuple of variable names based on the comma separated `names` string.
325+ Create a tuple of variable names based on the comma separated `` names` ` string.
326326
327- If `names` contains a single value, and `nvars` > 1, then the variables are numbered, e.g.
327+ If `` names`` contains a single value, and `` nvars` ` > 1, then the variables are numbered, e.g.
328328
329329 >>> flint_mpoly_context.create_variable_names(3, "x")
330330 ('x0', 'x1', 'x2')
@@ -344,24 +344,24 @@ cdef class flint_mpoly_context(flint_elem):
344344 Create a key for the context cache via the number of variables, the ordering, and
345345 either a variable name string, or a tuple of variable names.
346346 """
347- # A type hint of `ordering: Ordering` results in the error "TypeError: an integer is required" if a Ordering
347+ # A type hint of `` ordering: Ordering` ` results in the error "TypeError: an integer is required" if a Ordering
348348 # object is not provided. This is pretty obtuse so we check its type ourselves
349349 if not isinstance (ordering, Ordering):
350- raise TypeError (f" ` ordering` ('{ordering}') is not an instance of flint.Ordering" )
350+ raise TypeError (f" ' ordering' ('{ordering}') is not an instance of flint.Ordering" )
351351
352352 if nametup is not None :
353353 key = nvars, ordering, nametup
354354 elif nametup is None and names is not None :
355355 key = nvars, ordering, cls .create_variable_names(nvars, names)
356356 else :
357- raise ValueError (" must provide either ` names` or ` nametup` " )
357+ raise ValueError (" must provide either ' names' or ' nametup' " )
358358 return key
359359
360360 @classmethod
361361 def get_context (cls , *args , **kwargs ):
362362 """
363- Retrieve a context via the number of variables, `nvars`, the ordering, `ordering`, and either a variable
364- name string, `names`, or a tuple of variable names, `nametup`.
363+ Retrieve a context via the number of variables, `` nvars`` , the ordering, `` ordering` `, and either a variable
364+ name string, `` names`` , or a tuple of variable names, `` nametup` `.
365365 """
366366 key = cls .create_context_key(* args, ** kwargs)
367367
@@ -391,6 +391,24 @@ cdef class flint_mpoly_context(flint_elem):
391391 elif other is not self :
392392 raise IncompatibleContextError(f" {other} is not {self}" )
393393
394+ def term (self , coeff = None , exp_vec = None ):
395+ """
396+ Create a monomial from a coefficient and exponent vector. ``coeff`` defaults
397+ to ``1``. ``exp_vec``` defaults to ``(0,) * self.nvars()```.
398+
399+ >>> from flint import fmpz_mpoly_ctx, Ordering
400+ >>> ctx = fmpz_mpoly_ctx.get_context(2, Ordering.lex, 'x')
401+ >>> ctx.term(coeff=5, exp_vec=(2, 3))
402+ 5*x0^2*x1^3
403+ >>> ctx.term()
404+ 1
405+ """
406+ if coeff is None :
407+ coeff = 1
408+ if exp_vec is None :
409+ exp_vec = (0 ,) * self .nvars()
410+ return self .from_dict({tuple (exp_vec): coeff})
411+
394412
395413cdef class flint_mpoly(flint_elem):
396414 """
@@ -405,7 +423,7 @@ cdef class flint_mpoly(flint_elem):
405423
406424 def _division_check (self , other ):
407425 if not other:
408- raise ZeroDivisionError (" nmod_mpoly division by zero" )
426+ raise ZeroDivisionError (f " {self.__class__.__name__} division by zero" )
409427
410428 cdef _add_scalar_(self , other):
411429 return NotImplemented
@@ -431,6 +449,12 @@ cdef class flint_mpoly(flint_elem):
431449 cdef _floordiv_mpoly_(self , other):
432450 return NotImplemented
433451
452+ cdef _truediv_scalar_(self , other):
453+ return NotImplemented
454+
455+ cdef _divexact_scalar_(self , other):
456+ return NotImplemented
457+
434458 cdef _truediv_mpoly_(self , other):
435459 return NotImplemented
436460
@@ -589,8 +613,12 @@ cdef class flint_mpoly(flint_elem):
589613 if other is NotImplemented :
590614 return NotImplemented
591615
592- other = self .context().scalar_as_mpoly(other)
593616 self ._division_check(other)
617+ res = self ._truediv_scalar_(other)
618+ if res is not NotImplemented :
619+ return res
620+
621+ other = self .context().scalar_as_mpoly(other)
594622 return self ._truediv_mpoly_(other)
595623
596624 def __rtruediv__ (self , other ):
@@ -725,7 +753,7 @@ cdef class flint_mpoly(flint_elem):
725753
726754 def __contains__ (self , x ):
727755 """
728- Returns True if `self` contains a term with exponent vector `x ` and a non-zero coefficient.
756+ Returns True if `` self`` contains a term with exponent vector ``x` ` and a non-zero coefficient.
729757
730758 >>> from flint import fmpq_mpoly_ctx, Ordering
731759 >>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
@@ -829,7 +857,7 @@ cdef class flint_mat(flint_elem):
829857
830858cdef ordering_t ordering_py_to_c(ordering): # Cython does not like an "Ordering" type hint here
831859 if not isinstance (ordering, Ordering):
832- raise TypeError (f" ` ordering` ('{ordering}') is not an instance of flint.Ordering" )
860+ raise TypeError (f" ' ordering' ('{ordering}') is not an instance of flint.Ordering" )
833861
834862 if ordering == Ordering.lex:
835863 return ordering_t.ORD_LEX
0 commit comments