@@ -165,7 +165,6 @@ cdef class flint_scalar(flint_elem):
165
165
return self ._invert_()
166
166
167
167
168
-
169
168
cdef class flint_poly(flint_elem):
170
169
"""
171
170
Base class for polynomials.
@@ -414,9 +413,6 @@ cdef class flint_mpoly(flint_elem):
414
413
cdef _mul_scalar_(self , other):
415
414
return NotImplemented
416
415
417
- cdef _pow_(self , other):
418
- return NotImplemented
419
-
420
416
cdef _add_mpoly_(self , other):
421
417
return NotImplemented
422
418
@@ -435,10 +431,28 @@ cdef class flint_mpoly(flint_elem):
435
431
cdef _truediv_mpoly_(self , other):
436
432
return NotImplemented
437
433
434
+ cdef _mod_mpoly_(self , other):
435
+ return NotImplemented
436
+
437
+ cdef _rsub_scalar_(self , other):
438
+ return NotImplemented
439
+
440
+ cdef _rsub_mpoly_(self , other):
441
+ return NotImplemented
442
+
443
+ cdef _rdivmod_mpoly_(self , other):
444
+ return NotImplemented
445
+
446
+ cdef _rfloordiv_mpoly_(self , other):
447
+ return NotImplemented
448
+
438
449
cdef _rtruediv_mpoly_(self , other):
439
450
return NotImplemented
440
451
441
- cdef _mod_mpoly_(self , other):
452
+ cdef _rmod_mpoly_(self , other):
453
+ return NotImplemented
454
+
455
+ cdef _pow_(self , other):
442
456
return NotImplemented
443
457
444
458
cdef _iadd_scalar_(self , other):
@@ -471,32 +485,15 @@ cdef class flint_mpoly(flint_elem):
471
485
return self ._add_scalar_(other)
472
486
473
487
def __radd__ (self , other ):
474
- return self .__add__ (other)
475
-
476
- def iadd (self , other ):
477
- """
478
- In-place addition, mutates self.
479
-
480
- >>> from flint import Ordering, fmpz_mpoly_ctx
481
- >>> ctx = fmpz_mpoly_ctx.get_context(2, Ordering.lex, 'x')
482
- >>> f = ctx.from_dict({(1, 0): 2, (0, 1): 3, (1, 1): 4})
483
- >>> f
484
- 4*x0*x1 + 2*x0 + 3*x1
485
- >>> f.iadd(5)
486
- >>> f
487
- 4*x0*x1 + 2*x0 + 3*x1 + 5
488
-
489
- """
490
488
if typecheck(other, type (self )):
491
489
self .context().compatible_context_check(other.context())
492
- self ._iadd_mpoly_(other)
493
- return
490
+ return self ._add_mpoly_(other)
494
491
495
- other_scalar = self .context().any_as_scalar(other)
496
- if other_scalar is NotImplemented :
497
- raise NotImplementedError (f " cannot add {type(self)} and {type(other)} " )
492
+ other = self .context().any_as_scalar(other)
493
+ if other is NotImplemented :
494
+ return NotImplemented
498
495
499
- self ._iadd_scalar_(other_scalar )
496
+ return self ._add_scalar_(other )
500
497
501
498
def __sub__ (self , other ):
502
499
if typecheck(other, type (self )):
@@ -510,32 +507,15 @@ cdef class flint_mpoly(flint_elem):
510
507
return self ._sub_scalar_(other)
511
508
512
509
def __rsub__ (self , other ):
513
- return - self .__sub__ (other)
514
-
515
- def isub (self , other ):
516
- """
517
- In-place subtraction, mutates self.
518
-
519
- >>> from flint import Ordering, fmpz_mpoly_ctx
520
- >>> ctx = fmpz_mpoly_ctx.get_context(2, Ordering.lex, 'x')
521
- >>> f = ctx.from_dict({(1, 0): 2, (0, 1): 3, (1, 1): 4})
522
- >>> f
523
- 4*x0*x1 + 2*x0 + 3*x1
524
- >>> f.isub(5)
525
- >>> f
526
- 4*x0*x1 + 2*x0 + 3*x1 - 5
527
-
528
- """
529
510
if typecheck(other, type (self )):
530
511
self .context().compatible_context_check(other.context())
531
- self ._isub_mpoly_(other)
532
- return
512
+ return self ._rsub_mpoly_(other)
533
513
534
- other_scalar = self .context().any_as_scalar(other)
535
- if other_scalar is NotImplemented :
536
- raise NotImplementedError (f " cannot subtract {type(self)} and {type(other)} " )
514
+ other = self .context().any_as_scalar(other)
515
+ if other is NotImplemented :
516
+ return NotImplemented
537
517
538
- self ._isub_scalar_(other_scalar )
518
+ return self ._rsub_scalar_(other )
539
519
540
520
def __mul__ (self , other ):
541
521
if typecheck(other, type (self )):
@@ -549,32 +529,15 @@ cdef class flint_mpoly(flint_elem):
549
529
return self ._mul_scalar_(other)
550
530
551
531
def __rmul__ (self , other ):
552
- return self .__mul__ (other)
553
-
554
- def imul (self , other ):
555
- """
556
- In-place multiplication, mutates self.
557
-
558
- >>> from flint import Ordering, fmpz_mpoly_ctx
559
- >>> ctx = fmpz_mpoly_ctx.get_context(2, Ordering.lex, 'x')
560
- >>> f = ctx.from_dict({(1, 0): 2, (0, 1): 3, (1, 1): 4})
561
- >>> f
562
- 4*x0*x1 + 2*x0 + 3*x1
563
- >>> f.imul(2)
564
- >>> f
565
- 8*x0*x1 + 4*x0 + 6*x1
566
-
567
- """
568
532
if typecheck(other, type (self )):
569
533
self .context().compatible_context_check(other.context())
570
- self ._imul_mpoly_(other)
571
- return
534
+ return self ._mul_mpoly_(other)
572
535
573
- other_scalar = self .context().any_as_scalar(other)
574
- if other_scalar is NotImplemented :
575
- raise NotImplementedError (f " cannot multiply {type(self)} and {type(other)} " )
536
+ other = self .context().any_as_scalar(other)
537
+ if other is NotImplemented :
538
+ return NotImplemented
576
539
577
- self ._imul_scalar_(other_scalar )
540
+ return self ._mul_scalar_(other )
578
541
579
542
def __pow__ (self , other , modulus ):
580
543
if modulus is not None :
@@ -611,7 +574,7 @@ cdef class flint_mpoly(flint_elem):
611
574
612
575
other = self .context().scalar_as_mpoly(other)
613
576
other._division_check(self )
614
- return other._divmod_mpoly_( self )
577
+ return self ._rdivmod_mpoly_(other )
615
578
616
579
def __truediv__ (self , other ):
617
580
if typecheck(other, type (self )):
@@ -634,7 +597,6 @@ cdef class flint_mpoly(flint_elem):
634
597
635
598
other = self .context().scalar_as_mpoly(other)
636
599
other._division_check(self )
637
- # return other._truediv_mpoly_(self)
638
600
return self ._rtruediv_mpoly_(other)
639
601
640
602
def __floordiv__ (self , other ):
@@ -658,7 +620,7 @@ cdef class flint_mpoly(flint_elem):
658
620
659
621
other = self .context().scalar_as_mpoly(other)
660
622
other._division_check(self )
661
- return other._floordiv_mpoly_( self )
623
+ return self ._rfloordiv_mpoly_(other )
662
624
663
625
def __mod__ (self , other ):
664
626
if typecheck(other, type (self )):
@@ -681,7 +643,82 @@ cdef class flint_mpoly(flint_elem):
681
643
682
644
other = self .context().scalar_as_mpoly(other)
683
645
other._division_check(self )
684
- return other._mod_mpoly_(self )
646
+ return self ._rmod_mpoly_(other)
647
+
648
+ def iadd (self , other ):
649
+ """
650
+ In-place addition, mutates self.
651
+
652
+ >>> from flint import Ordering, fmpz_mpoly_ctx
653
+ >>> ctx = fmpz_mpoly_ctx.get_context(2, Ordering.lex, 'x')
654
+ >>> f = ctx.from_dict({(1, 0): 2, (0, 1): 3, (1, 1): 4})
655
+ >>> f
656
+ 4*x0*x1 + 2*x0 + 3*x1
657
+ >>> f.iadd(5)
658
+ >>> f
659
+ 4*x0*x1 + 2*x0 + 3*x1 + 5
660
+
661
+ """
662
+ if typecheck(other, type (self )):
663
+ self .context().compatible_context_check(other.context())
664
+ self ._iadd_mpoly_(other)
665
+ return
666
+
667
+ other_scalar = self .context().any_as_scalar(other)
668
+ if other_scalar is NotImplemented :
669
+ raise NotImplementedError (f" cannot add {type(self)} and {type(other)}" )
670
+
671
+ self ._iadd_scalar_(other_scalar)
672
+
673
+ def isub (self , other ):
674
+ """
675
+ In-place subtraction, mutates self.
676
+
677
+ >>> from flint import Ordering, fmpz_mpoly_ctx
678
+ >>> ctx = fmpz_mpoly_ctx.get_context(2, Ordering.lex, 'x')
679
+ >>> f = ctx.from_dict({(1, 0): 2, (0, 1): 3, (1, 1): 4})
680
+ >>> f
681
+ 4*x0*x1 + 2*x0 + 3*x1
682
+ >>> f.isub(5)
683
+ >>> f
684
+ 4*x0*x1 + 2*x0 + 3*x1 - 5
685
+
686
+ """
687
+ if typecheck(other, type (self )):
688
+ self .context().compatible_context_check(other.context())
689
+ self ._isub_mpoly_(other)
690
+ return
691
+
692
+ other_scalar = self .context().any_as_scalar(other)
693
+ if other_scalar is NotImplemented :
694
+ raise NotImplementedError (f" cannot subtract {type(self)} and {type(other)}" )
695
+
696
+ self ._isub_scalar_(other_scalar)
697
+
698
+ def imul (self , other ):
699
+ """
700
+ In-place multiplication, mutates self.
701
+
702
+ >>> from flint import Ordering, fmpz_mpoly_ctx
703
+ >>> ctx = fmpz_mpoly_ctx.get_context(2, Ordering.lex, 'x')
704
+ >>> f = ctx.from_dict({(1, 0): 2, (0, 1): 3, (1, 1): 4})
705
+ >>> f
706
+ 4*x0*x1 + 2*x0 + 3*x1
707
+ >>> f.imul(2)
708
+ >>> f
709
+ 8*x0*x1 + 4*x0 + 6*x1
710
+
711
+ """
712
+ if typecheck(other, type (self )):
713
+ self .context().compatible_context_check(other.context())
714
+ self ._imul_mpoly_(other)
715
+ return
716
+
717
+ other_scalar = self .context().any_as_scalar(other)
718
+ if other_scalar is NotImplemented :
719
+ raise NotImplementedError (f" cannot multiply {type(self)} and {type(other)}" )
720
+
721
+ self ._imul_scalar_(other_scalar)
685
722
686
723
def __contains__ (self , x ):
687
724
"""
0 commit comments