@@ -11,6 +11,7 @@ from flint.utils.typecheck cimport typecheck
11
11
cimport libc.stdlib
12
12
13
13
from typing import Optional
14
+ from flint.utils.flint_exceptions import IncompatibleContextError
14
15
15
16
16
17
FLINT_BITS = _FLINT_BITS
@@ -369,6 +370,18 @@ cdef class flint_mpoly_context(flint_elem):
369
370
nametup = ctx.names()
370
371
)
371
372
373
+ def any_as_scalar (self , other ):
374
+ raise NotImplementedError (" abstract method" )
375
+
376
+ def scalar_as_mpoly (self , other ):
377
+ raise NotImplementedError (" abstract method" )
378
+
379
+ def compatible_context_check (self , other ):
380
+ if not typecheck(other, type (self )):
381
+ raise TypeError (f" type {type(other)} is not {type(self)}" )
382
+ elif other is not self :
383
+ raise IncompatibleContextError(f" {other} is not {self}" )
384
+
372
385
373
386
cdef class flint_mpoly(flint_elem):
374
387
"""
@@ -381,6 +394,53 @@ cdef class flint_mpoly(flint_elem):
381
394
def to_dict (self ):
382
395
return {self .monomial(i): self .coefficient(i) for i in range (len (self ))}
383
396
397
+ def _division_check (self , other ):
398
+ if not other:
399
+ raise ZeroDivisionError (" nmod_mpoly division by zero" )
400
+
401
+ def _add_scalar_ (self , other ):
402
+ return NotImplemented
403
+
404
+ def _add_mpoly_ (self , other ):
405
+ return NotImplemented
406
+
407
+ def __add__ (self , other ):
408
+ if typecheck(other, type (self )):
409
+ self .context().compatible_context_check(other.context())
410
+ return self ._add_mpoly_(other)
411
+
412
+ other = self .context().any_as_scalar(other)
413
+ if other is NotImplemented :
414
+ return NotImplemented
415
+
416
+ return self ._add_scalar_(other)
417
+
418
+ def __radd__ (self , other ):
419
+ return self .__add__ (other)
420
+
421
+ def __divmod__ (self , other ):
422
+ if typecheck(other, type (self )):
423
+ self ._division_check(other)
424
+ self .context().compatible_context_check(other.context())
425
+ return self ._divmod_mpoly_(other)
426
+
427
+ other = self .context().any_as_scalar(other)
428
+ if other is NotImplemented :
429
+ return NotImplemented
430
+
431
+ self ._division_check(other)
432
+ other = self .context().scalar_as_mpoly(other)
433
+ return self ._divmod_mpoly_(other)
434
+
435
+ def __rdivmod__ (self , other ):
436
+ other = self .context().any_as_scalar(other)
437
+ if other is NotImplemented :
438
+ return NotImplemented
439
+
440
+ self ._division_check(self )
441
+ other = self .context().scalar_as_mpoly(other)
442
+ return other._divmod_mpoly_(self )
443
+
384
444
def __contains__ (self , x ):
385
445
"""
386
446
Returns True if `self` contains a term with exponent vector `x` and a non-zero coefficient.
0 commit comments