@@ -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.
@@ -405,52 +404,73 @@ cdef class flint_mpoly(flint_elem):
405
404
if not other:
406
405
raise ZeroDivisionError (" nmod_mpoly division by zero" )
407
406
408
- def _add_scalar_ (self , other ):
407
+ cdef _add_scalar_(self , other):
408
+ return NotImplemented
409
+
410
+ cdef _sub_scalar_(self , other):
411
+ return NotImplemented
412
+
413
+ cdef _mul_scalar_(self , other):
414
+ return NotImplemented
415
+
416
+ cdef _add_mpoly_(self , other):
417
+ return NotImplemented
418
+
419
+ cdef _sub_mpoly_(self , other):
420
+ return NotImplemented
421
+
422
+ cdef _mul_mpoly_(self , other):
409
423
return NotImplemented
410
424
411
- def _add_mpoly_ (self , other ):
425
+ cdef _divmod_mpoly_ (self , other):
412
426
return NotImplemented
413
427
414
- def _iadd_scalar_ (self , other ):
428
+ cdef _floordiv_mpoly_ (self , other):
415
429
return NotImplemented
416
430
417
- def _iadd_mpoly_ (self , other ):
431
+ cdef _truediv_mpoly_ (self , other):
418
432
return NotImplemented
419
433
420
- def _sub_scalar_ (self , other ):
434
+ cdef _mod_mpoly_ (self , other):
421
435
return NotImplemented
422
436
423
- def _sub_mpoly_ (self , other ):
437
+ cdef _rsub_scalar_ (self , other):
424
438
return NotImplemented
425
439
426
- def _isub_scalar_ (self , other ):
440
+ cdef _rsub_mpoly_ (self , other):
427
441
return NotImplemented
428
442
429
- def _isub_mpoly_ (self , other ):
443
+ cdef _rdivmod_mpoly_ (self , other):
430
444
return NotImplemented
431
445
432
- def _mul_scalar_ (self , other ):
446
+ cdef _rfloordiv_mpoly_ (self , other):
433
447
return NotImplemented
434
448
435
- def _imul_mpoly_ (self , other ):
449
+ cdef _rtruediv_mpoly_ (self , other):
436
450
return NotImplemented
437
451
438
- def _imul_scalar_ (self , other ):
452
+ cdef _rmod_mpoly_ (self , other):
439
453
return NotImplemented
440
454
441
- def _mul_mpoly_ (self , other ):
455
+ cdef _pow_ (self , other):
442
456
return NotImplemented
443
457
444
- def _pow_ (self , other ):
458
+ cdef _iadd_scalar_ (self , other):
445
459
return NotImplemented
446
460
447
- def _divmod_mpoly_ (self , other ):
461
+ cdef _isub_scalar_ (self , other):
448
462
return NotImplemented
449
463
450
- def _floordiv_mpoly_ (self , other ):
464
+ cdef _imul_scalar_ (self , other):
451
465
return NotImplemented
452
466
453
- def _truediv_mpoly_ (self , other ):
467
+ cdef _iadd_mpoly_(self , other):
468
+ return NotImplemented
469
+
470
+ cdef _isub_mpoly_(self , other):
471
+ return NotImplemented
472
+
473
+ cdef _imul_mpoly_(self , other):
454
474
return NotImplemented
455
475
456
476
def __add__ (self , other ):
@@ -465,32 +485,15 @@ cdef class flint_mpoly(flint_elem):
465
485
return self ._add_scalar_(other)
466
486
467
487
def __radd__ (self , other ):
468
- return self .__add__ (other)
469
-
470
- def iadd (self , other ):
471
- """
472
- In-place addition, mutates self.
473
-
474
- >>> from flint import Ordering, fmpz_mpoly_ctx
475
- >>> ctx = fmpz_mpoly_ctx.get_context(2, Ordering.lex, 'x')
476
- >>> f = ctx.from_dict({(1, 0): 2, (0, 1): 3, (1, 1): 4})
477
- >>> f
478
- 4*x0*x1 + 2*x0 + 3*x1
479
- >>> f.iadd(5)
480
- >>> f
481
- 4*x0*x1 + 2*x0 + 3*x1 + 5
482
-
483
- """
484
488
if typecheck(other, type (self )):
485
489
self .context().compatible_context_check(other.context())
486
- self ._iadd_mpoly_(other)
487
- return
490
+ return self ._add_mpoly_(other)
488
491
489
- other_scalar = self .context().any_as_scalar(other)
490
- if other_scalar is NotImplemented :
491
- 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
492
495
493
- self ._iadd_scalar_(other_scalar )
496
+ return self ._add_scalar_(other )
494
497
495
498
def __sub__ (self , other ):
496
499
if typecheck(other, type (self )):
@@ -504,32 +507,15 @@ cdef class flint_mpoly(flint_elem):
504
507
return self ._sub_scalar_(other)
505
508
506
509
def __rsub__ (self , other ):
507
- return - self .__sub__ (other)
508
-
509
- def isub (self , other ):
510
- """
511
- In-place subtraction, mutates self.
512
-
513
- >>> from flint import Ordering, fmpz_mpoly_ctx
514
- >>> ctx = fmpz_mpoly_ctx.get_context(2, Ordering.lex, 'x')
515
- >>> f = ctx.from_dict({(1, 0): 2, (0, 1): 3, (1, 1): 4})
516
- >>> f
517
- 4*x0*x1 + 2*x0 + 3*x1
518
- >>> f.isub(5)
519
- >>> f
520
- 4*x0*x1 + 2*x0 + 3*x1 - 5
521
-
522
- """
523
510
if typecheck(other, type (self )):
524
511
self .context().compatible_context_check(other.context())
525
- self ._isub_mpoly_(other)
526
- return
512
+ return self ._rsub_mpoly_(other)
527
513
528
- other_scalar = self .context().any_as_scalar(other)
529
- if other_scalar is NotImplemented :
530
- 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
531
517
532
- self ._isub_scalar_(other_scalar )
518
+ return self ._rsub_scalar_(other )
533
519
534
520
def __mul__ (self , other ):
535
521
if typecheck(other, type (self )):
@@ -543,32 +529,15 @@ cdef class flint_mpoly(flint_elem):
543
529
return self ._mul_scalar_(other)
544
530
545
531
def __rmul__ (self , other ):
546
- return self .__mul__ (other)
547
-
548
- def imul (self , other ):
549
- """
550
- In-place multiplication, mutates self.
551
-
552
- >>> from flint import Ordering, fmpz_mpoly_ctx
553
- >>> ctx = fmpz_mpoly_ctx.get_context(2, Ordering.lex, 'x')
554
- >>> f = ctx.from_dict({(1, 0): 2, (0, 1): 3, (1, 1): 4})
555
- >>> f
556
- 4*x0*x1 + 2*x0 + 3*x1
557
- >>> f.imul(2)
558
- >>> f
559
- 8*x0*x1 + 4*x0 + 6*x1
560
-
561
- """
562
532
if typecheck(other, type (self )):
563
533
self .context().compatible_context_check(other.context())
564
- self ._imul_mpoly_(other)
565
- return
534
+ return self ._mul_mpoly_(other)
566
535
567
- other_scalar = self .context().any_as_scalar(other)
568
- if other_scalar is NotImplemented :
569
- 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
570
539
571
- self ._imul_scalar_(other_scalar )
540
+ return self ._mul_scalar_(other )
572
541
573
542
def __pow__ (self , other , modulus ):
574
543
if modulus is not None :
@@ -605,7 +574,7 @@ cdef class flint_mpoly(flint_elem):
605
574
606
575
other = self .context().scalar_as_mpoly(other)
607
576
other._division_check(self )
608
- return other._divmod_mpoly_( self )
577
+ return self ._rdivmod_mpoly_(other )
609
578
610
579
def __truediv__ (self , other ):
611
580
if typecheck(other, type (self )):
@@ -628,7 +597,7 @@ cdef class flint_mpoly(flint_elem):
628
597
629
598
other = self .context().scalar_as_mpoly(other)
630
599
other._division_check(self )
631
- return other._truediv_mpoly_( self )
600
+ return self ._rtruediv_mpoly_(other )
632
601
633
602
def __floordiv__ (self , other ):
634
603
if typecheck(other, type (self )):
@@ -651,7 +620,7 @@ cdef class flint_mpoly(flint_elem):
651
620
652
621
other = self .context().scalar_as_mpoly(other)
653
622
other._division_check(self )
654
- return other._floordiv_mpoly_( self )
623
+ return self ._rfloordiv_mpoly_(other )
655
624
656
625
def __mod__ (self , other ):
657
626
if typecheck(other, type (self )):
@@ -674,7 +643,82 @@ cdef class flint_mpoly(flint_elem):
674
643
675
644
other = self .context().scalar_as_mpoly(other)
676
645
other._division_check(self )
677
- 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)
678
722
679
723
def __contains__ (self , x ):
680
724
"""
0 commit comments