Skip to content

Commit 630e20c

Browse files
authoredAug 21, 2024··
Merge pull request #192 from Jake-Moss/mpoly_update
Prefer cdef to def in mpoly operands
2 parents 920a3a2 + c9de856 commit 630e20c

File tree

6 files changed

+459
-254
lines changed

6 files changed

+459
-254
lines changed
 

‎src/flint/flint_base/flint_base.pxd

+31-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,37 @@ cdef class flint_mpoly_context(flint_elem):
1414
cdef const char ** c_names
1515

1616
cdef class flint_mpoly(flint_elem):
17-
pass
17+
cdef _add_scalar_(self, other)
18+
cdef _sub_scalar_(self, other)
19+
cdef _mul_scalar_(self, other)
20+
21+
cdef _add_mpoly_(self, other)
22+
cdef _sub_mpoly_(self, other)
23+
cdef _mul_mpoly_(self, other)
24+
25+
cdef _divmod_mpoly_(self, other)
26+
cdef _floordiv_mpoly_(self, other)
27+
cdef _truediv_mpoly_(self, other)
28+
cdef _mod_mpoly_(self, other)
29+
30+
cdef _rsub_scalar_(self, other)
31+
cdef _rsub_mpoly_(self, other)
32+
33+
cdef _rdivmod_mpoly_(self, other)
34+
cdef _rfloordiv_mpoly_(self, other)
35+
cdef _rtruediv_mpoly_(self, other)
36+
cdef _rmod_mpoly_(self, other)
37+
38+
cdef _pow_(self, other)
39+
40+
cdef _iadd_scalar_(self, other)
41+
cdef _isub_scalar_(self, other)
42+
cdef _imul_scalar_(self, other)
43+
44+
cdef _iadd_mpoly_(self, other)
45+
cdef _isub_mpoly_(self, other)
46+
cdef _imul_mpoly_(self, other)
47+
1848

1949
cdef class flint_mat(flint_elem):
2050
pass

‎src/flint/flint_base/flint_base.pyx

+131-87
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ cdef class flint_scalar(flint_elem):
165165
return self._invert_()
166166

167167

168-
169168
cdef class flint_poly(flint_elem):
170169
"""
171170
Base class for polynomials.
@@ -405,52 +404,73 @@ cdef class flint_mpoly(flint_elem):
405404
if not other:
406405
raise ZeroDivisionError("nmod_mpoly division by zero")
407406

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):
409423
return NotImplemented
410424

411-
def _add_mpoly_(self, other):
425+
cdef _divmod_mpoly_(self, other):
412426
return NotImplemented
413427

414-
def _iadd_scalar_(self, other):
428+
cdef _floordiv_mpoly_(self, other):
415429
return NotImplemented
416430

417-
def _iadd_mpoly_(self, other):
431+
cdef _truediv_mpoly_(self, other):
418432
return NotImplemented
419433

420-
def _sub_scalar_(self, other):
434+
cdef _mod_mpoly_(self, other):
421435
return NotImplemented
422436

423-
def _sub_mpoly_(self, other):
437+
cdef _rsub_scalar_(self, other):
424438
return NotImplemented
425439

426-
def _isub_scalar_(self, other):
440+
cdef _rsub_mpoly_(self, other):
427441
return NotImplemented
428442

429-
def _isub_mpoly_(self, other):
443+
cdef _rdivmod_mpoly_(self, other):
430444
return NotImplemented
431445

432-
def _mul_scalar_(self, other):
446+
cdef _rfloordiv_mpoly_(self, other):
433447
return NotImplemented
434448

435-
def _imul_mpoly_(self, other):
449+
cdef _rtruediv_mpoly_(self, other):
436450
return NotImplemented
437451

438-
def _imul_scalar_(self, other):
452+
cdef _rmod_mpoly_(self, other):
439453
return NotImplemented
440454

441-
def _mul_mpoly_(self, other):
455+
cdef _pow_(self, other):
442456
return NotImplemented
443457

444-
def _pow_(self, other):
458+
cdef _iadd_scalar_(self, other):
445459
return NotImplemented
446460

447-
def _divmod_mpoly_(self, other):
461+
cdef _isub_scalar_(self, other):
448462
return NotImplemented
449463

450-
def _floordiv_mpoly_(self, other):
464+
cdef _imul_scalar_(self, other):
451465
return NotImplemented
452466

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):
454474
return NotImplemented
455475

456476
def __add__(self, other):
@@ -465,32 +485,15 @@ cdef class flint_mpoly(flint_elem):
465485
return self._add_scalar_(other)
466486

467487
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-
"""
484488
if typecheck(other, type(self)):
485489
self.context().compatible_context_check(other.context())
486-
self._iadd_mpoly_(other)
487-
return
490+
return self._add_mpoly_(other)
488491

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
492495

493-
self._iadd_scalar_(other_scalar)
496+
return self._add_scalar_(other)
494497

495498
def __sub__(self, other):
496499
if typecheck(other, type(self)):
@@ -504,32 +507,15 @@ cdef class flint_mpoly(flint_elem):
504507
return self._sub_scalar_(other)
505508

506509
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-
"""
523510
if typecheck(other, type(self)):
524511
self.context().compatible_context_check(other.context())
525-
self._isub_mpoly_(other)
526-
return
512+
return self._rsub_mpoly_(other)
527513

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
531517

532-
self._isub_scalar_(other_scalar)
518+
return self._rsub_scalar_(other)
533519

534520
def __mul__(self, other):
535521
if typecheck(other, type(self)):
@@ -543,32 +529,15 @@ cdef class flint_mpoly(flint_elem):
543529
return self._mul_scalar_(other)
544530

545531
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-
"""
562532
if typecheck(other, type(self)):
563533
self.context().compatible_context_check(other.context())
564-
self._imul_mpoly_(other)
565-
return
534+
return self._mul_mpoly_(other)
566535

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
570539

571-
self._imul_scalar_(other_scalar)
540+
return self._mul_scalar_(other)
572541

573542
def __pow__(self, other, modulus):
574543
if modulus is not None:
@@ -605,7 +574,7 @@ cdef class flint_mpoly(flint_elem):
605574

606575
other = self.context().scalar_as_mpoly(other)
607576
other._division_check(self)
608-
return other._divmod_mpoly_(self)
577+
return self._rdivmod_mpoly_(other)
609578

610579
def __truediv__(self, other):
611580
if typecheck(other, type(self)):
@@ -628,7 +597,7 @@ cdef class flint_mpoly(flint_elem):
628597

629598
other = self.context().scalar_as_mpoly(other)
630599
other._division_check(self)
631-
return other._truediv_mpoly_(self)
600+
return self._rtruediv_mpoly_(other)
632601

633602
def __floordiv__(self, other):
634603
if typecheck(other, type(self)):
@@ -651,7 +620,7 @@ cdef class flint_mpoly(flint_elem):
651620

652621
other = self.context().scalar_as_mpoly(other)
653622
other._division_check(self)
654-
return other._floordiv_mpoly_(self)
623+
return self._rfloordiv_mpoly_(other)
655624

656625
def __mod__(self, other):
657626
if typecheck(other, type(self)):
@@ -674,7 +643,82 @@ cdef class flint_mpoly(flint_elem):
674643

675644
other = self.context().scalar_as_mpoly(other)
676645
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)
678722

679723
def __contains__(self, x):
680724
"""

‎src/flint/types/fmpq_mpoly.pyx

+69-37
Original file line numberDiff line numberDiff line change
@@ -352,78 +352,128 @@ cdef class fmpq_mpoly(flint_mpoly):
352352
fmpq_mpoly_neg(res.val, (<fmpq_mpoly>self).val, res.ctx.val)
353353
return res
354354

355-
356-
def _add_scalar_(self, other: fmpq):
355+
cdef _add_scalar_(self, arg):
357356
cdef fmpq_mpoly res
357+
cdef fmpq other = <fmpq>arg
358358
res = create_fmpq_mpoly(self.ctx)
359359
fmpq_mpoly_add_fmpq(res.val, self.val, other.val, self.ctx.val)
360360
return res
361361

362-
def _add_mpoly_(self, other: fmpq_mpoly):
363-
cdef fmpq_mpoly res
362+
cdef _add_mpoly_(self, arg):
363+
cdef fmpq_mpoly res, other = <fmpq_mpoly>arg
364364
res = create_fmpq_mpoly(self.ctx)
365365
fmpq_mpoly_add(res.val, self.val, other.val, res.ctx.val)
366366
return res
367367

368-
def _sub_scalar_(self, other: fmpq):
368+
cdef _sub_scalar_(self, arg):
369369
cdef fmpq_mpoly res
370+
cdef fmpq other = <fmpq>arg
370371
res = create_fmpq_mpoly(self.ctx)
371372
fmpq_mpoly_sub_fmpq(res.val, self.val, other.val, self.ctx.val)
372373
return res
373374

374-
def _sub_mpoly_(self, other: fmpq_mpoly):
375-
cdef fmpq_mpoly res
375+
cdef _sub_mpoly_(self, arg):
376+
cdef fmpq_mpoly res, other = <fmpq_mpoly>arg
376377
res = create_fmpq_mpoly(self.ctx)
377378
fmpq_mpoly_sub(res.val, self.val, other.val, res.ctx.val)
378379
return res
379380

380-
def _mul_scalar_(self, other: fmpq):
381+
cdef _mul_scalar_(self, arg):
381382
cdef fmpq_mpoly res
383+
cdef fmpq other = <fmpq>arg
382384
res = create_fmpq_mpoly(self.ctx)
383385
fmpq_mpoly_scalar_mul_fmpq(res.val, self.val, other.val, self.ctx.val)
384386
return res
385387

386-
def _mul_mpoly_(self, other: fmpq_mpoly):
387-
cdef fmpq_mpoly res
388+
cdef _mul_mpoly_(self, arg):
389+
cdef fmpq_mpoly res, other = <fmpq_mpoly>arg
388390
res = create_fmpq_mpoly(self.ctx)
389391
fmpq_mpoly_mul(res.val, self.val, other.val, res.ctx.val)
390392
return res
391393

392-
def _pow_(self, other: fmpz):
394+
cdef _pow_(self, arg):
393395
cdef fmpq_mpoly res
396+
cdef fmpz other = <fmpz>arg
394397
res = create_fmpq_mpoly(self.ctx)
395398
if fmpq_mpoly_pow_fmpz(res.val, self.val, other.val, res.ctx.val) == 0:
396399
raise ValueError("unreasonably large polynomial") # pragma: no cover
397400
return res
398401

399-
def _divmod_mpoly_(self, other: fmpq_mpoly):
400-
cdef fmpq_mpoly quotient, remainder
402+
cdef _divmod_mpoly_(self, arg):
403+
cdef fmpq_mpoly quotient, remainder, other = <fmpq_mpoly>arg
401404
quotient = create_fmpq_mpoly(self.ctx)
402405
remainder = create_fmpq_mpoly(self.ctx)
403406
fmpq_mpoly_divrem(quotient.val, remainder.val, self.val, other.val, self.ctx.val)
404407
return (quotient, remainder)
405408

406-
def _floordiv_mpoly_(self, other: fmpq_mpoly):
407-
cdef fmpq_mpoly quotient
409+
cdef _floordiv_mpoly_(self, arg):
410+
cdef fmpq_mpoly quotient, other = <fmpq_mpoly>arg
408411
quotient = create_fmpq_mpoly(self.ctx)
409412
fmpq_mpoly_div(quotient.val, self.val, other.val, self.ctx.val)
410413
return quotient
411414

412-
def _truediv_mpoly_(self, other: fmpq_mpoly):
413-
cdef fmpq_mpoly quotient
415+
cdef _truediv_mpoly_(self, arg):
416+
cdef fmpq_mpoly quotient, other = <fmpq_mpoly>arg
414417
quotient = create_fmpq_mpoly(self.ctx)
415418
if fmpq_mpoly_divides(quotient.val, self.val, other.val, self.ctx.val):
416419
return quotient
417420
else:
418421
raise DomainError("fmpq_mpoly division is not exact")
419422

420-
def _mod_mpoly_(self, other: fmpq_mpoly):
421-
cdef fmpq_mpoly quotient, remainder
423+
cdef _mod_mpoly_(self, arg):
424+
cdef fmpq_mpoly quotient, remainder, other = <fmpq_mpoly>arg
422425
quotient = create_fmpq_mpoly(self.ctx)
423426
remainder = create_fmpq_mpoly(self.ctx)
424427
fmpq_mpoly_divrem(quotient.val, remainder.val, self.val, other.val, self.ctx.val)
425428
return remainder
426429

430+
cdef _rsub_scalar_(self, arg):
431+
cdef fmpq_mpoly res
432+
cdef fmpq other = <fmpq>arg
433+
res = create_fmpq_mpoly(self.ctx)
434+
fmpq_mpoly_sub_fmpq(res.val, self.val, other.val, self.ctx.val)
435+
fmpq_mpoly_neg(res.val, res.val, res.ctx.val)
436+
return res
437+
438+
cdef _rsub_mpoly_(self, arg):
439+
return (<fmpq_mpoly>arg)._sub_mpoly_(self)
440+
441+
cdef _rdivmod_mpoly_(self, arg):
442+
return (<fmpq_mpoly>arg)._divmod_mpoly_(self)
443+
444+
cdef _rfloordiv_mpoly_(self, arg):
445+
return (<fmpq_mpoly>arg)._floordiv_mpoly_(self)
446+
447+
cdef _rtruediv_mpoly_(self, arg):
448+
return (<fmpq_mpoly>arg)._truediv_mpoly_(self)
449+
450+
cdef _rmod_mpoly_(self, arg):
451+
return (<fmpq_mpoly>arg)._mod_mpoly_(self)
452+
453+
cdef _iadd_scalar_(self, arg):
454+
cdef fmpq other = <fmpq>arg
455+
fmpq_mpoly_add_fmpq(self.val, self.val, other.val, self.ctx.val)
456+
457+
cdef _isub_scalar_(self, arg):
458+
cdef fmpq other = <fmpq>arg
459+
fmpq_mpoly_sub_fmpq(self.val, self.val, other.val, self.ctx.val)
460+
461+
cdef _imul_scalar_(self, arg):
462+
cdef fmpq other = <fmpq>arg
463+
fmpq_mpoly_scalar_mul_fmpq(self.val, self.val, other.val, self.ctx.val)
464+
465+
cdef _iadd_mpoly_(self, arg):
466+
cdef fmpq_mpoly other = <fmpq_mpoly>arg
467+
fmpq_mpoly_add(self.val, self.val, other.val, self.ctx.val)
468+
469+
cdef _isub_mpoly_(self, arg):
470+
cdef fmpq_mpoly other = <fmpq_mpoly>arg
471+
fmpq_mpoly_sub(self.val, self.val, other.val, self.ctx.val)
472+
473+
cdef _imul_mpoly_(self, arg):
474+
cdef fmpq_mpoly other = <fmpq_mpoly>arg
475+
fmpq_mpoly_mul(self.val, self.val, other.val, self.ctx.val)
476+
427477
def __call__(self, *args) -> fmpq:
428478
cdef:
429479
fmpq_vec V
@@ -439,24 +489,6 @@ cdef class fmpq_mpoly(flint_mpoly):
439489
raise ValueError("unreasonably large polynomial") # pragma: no cover
440490
return vres
441491

442-
def _iadd_scalar_(self, other: fmpq):
443-
fmpq_mpoly_add_fmpq(self.val, self.val, other.val, self.ctx.val)
444-
445-
def _iadd_mpoly_(self, other: fmpq_mpoly):
446-
fmpq_mpoly_add(self.val, self.val, other.val, self.ctx.val)
447-
448-
def _isub_scalar_(self, other: fmpq):
449-
fmpq_mpoly_sub_fmpq(self.val, self.val, other.val, self.ctx.val)
450-
451-
def _isub_mpoly_(self, other: fmpq_mpoly):
452-
fmpq_mpoly_sub(self.val, self.val, other.val, self.ctx.val)
453-
454-
def _imul_scalar_(self, other: fmpq):
455-
fmpq_mpoly_scalar_mul_fmpq(self.val, self.val, other.val, self.ctx.val)
456-
457-
def _imul_mpoly_(self, other: fmpq_mpoly):
458-
fmpq_mpoly_mul(self.val, self.val, other.val, self.ctx.val)
459-
460492
def monoms(self):
461493
"""
462494
Return the exponent vectors of each term as a tuple of fmpz.

‎src/flint/types/fmpz_mod_mpoly.pyx

+76-43
Original file line numberDiff line numberDiff line change
@@ -430,77 +430,128 @@ cdef class fmpz_mod_mpoly(flint_mpoly):
430430
fmpz_mod_mpoly_neg(res.val, (<fmpz_mod_mpoly>self).val, res.ctx.val)
431431
return res
432432

433-
def _add_scalar_(self, other: fmpz):
433+
cdef _add_scalar_(self, arg):
434434
cdef fmpz_mod_mpoly res
435+
cdef fmpz other = <fmpz>arg
435436
res = create_fmpz_mod_mpoly(self.ctx)
436437
fmpz_mod_mpoly_add_fmpz(res.val, self.val, other.val, self.ctx.val)
437438
return res
438439

439-
def _add_mpoly_(self, other: fmpz_mod_mpoly):
440+
cdef _sub_scalar_(self, arg):
440441
cdef fmpz_mod_mpoly res
442+
cdef fmpz other = <fmpz>arg
441443
res = create_fmpz_mod_mpoly(self.ctx)
442-
fmpz_mod_mpoly_add(res.val, self.val, other.val, res.ctx.val)
444+
fmpz_mod_mpoly_sub_fmpz(res.val, self.val, other.val, self.ctx.val)
443445
return res
444446

445-
def _sub_scalar_(self, other: fmpz):
447+
cdef _mul_scalar_(self, arg):
446448
cdef fmpz_mod_mpoly res
449+
cdef fmpz other = <fmpz>arg
447450
res = create_fmpz_mod_mpoly(self.ctx)
448-
fmpz_mod_mpoly_sub_fmpz(res.val, self.val, other.val, self.ctx.val)
451+
fmpz_mod_mpoly_scalar_mul_fmpz(res.val, self.val, other.val, self.ctx.val)
449452
return res
450453

451-
def _sub_mpoly_(self, other: fmpz_mod_mpoly):
454+
cdef _pow_(self, arg):
452455
cdef fmpz_mod_mpoly res
456+
cdef fmpz other = <fmpz>arg
453457
res = create_fmpz_mod_mpoly(self.ctx)
454-
fmpz_mod_mpoly_sub(res.val, self.val, other.val, res.ctx.val)
458+
if fmpz_mod_mpoly_pow_fmpz(res.val, self.val, other.val, res.ctx.val) == 0:
459+
raise ValueError("unreasonably large polynomial") # pragma: no cover
455460
return res
456461

457-
def _mul_scalar_(self, other: fmpz):
458-
cdef fmpz_mod_mpoly res
462+
cdef _add_mpoly_(self, arg):
463+
cdef fmpz_mod_mpoly res, other = <fmpz_mod_mpoly>arg
459464
res = create_fmpz_mod_mpoly(self.ctx)
460-
fmpz_mod_mpoly_scalar_mul_fmpz(res.val, self.val, other.val, self.ctx.val)
465+
fmpz_mod_mpoly_add(res.val, self.val, other.val, res.ctx.val)
461466
return res
462467

463-
def _mul_mpoly_(self, other: fmpz_mod_mpoly):
464-
cdef fmpz_mod_mpoly res
468+
cdef _sub_mpoly_(self, arg):
469+
cdef fmpz_mod_mpoly res, other = <fmpz_mod_mpoly>arg
465470
res = create_fmpz_mod_mpoly(self.ctx)
466-
fmpz_mod_mpoly_mul(res.val, self.val, other.val, res.ctx.val)
471+
fmpz_mod_mpoly_sub(res.val, self.val, other.val, res.ctx.val)
467472
return res
468473

469-
def _pow_(self, other: fmpz):
470-
cdef fmpz_mod_mpoly res
474+
cdef _mul_mpoly_(self, arg):
475+
cdef fmpz_mod_mpoly res, other = <fmpz_mod_mpoly>arg
471476
res = create_fmpz_mod_mpoly(self.ctx)
472-
if fmpz_mod_mpoly_pow_fmpz(res.val, self.val, other.val, res.ctx.val) == 0:
473-
raise ValueError("unreasonably large polynomial") # pragma: no cover
477+
fmpz_mod_mpoly_mul(res.val, self.val, other.val, res.ctx.val)
474478
return res
475479

476-
def _divmod_mpoly_(self, other: fmpz_mod_mpoly):
477-
cdef fmpz_mod_mpoly quotient, remainder
480+
cdef _divmod_mpoly_(self, arg):
481+
cdef fmpz_mod_mpoly quotient, remainder, other = <fmpz_mod_mpoly>arg
478482
quotient = create_fmpz_mod_mpoly(self.ctx)
479483
remainder = create_fmpz_mod_mpoly(self.ctx)
480484
fmpz_mod_mpoly_divrem(quotient.val, remainder.val, self.val, other.val, self.ctx.val)
481485
return (quotient, remainder)
482486

483-
def _floordiv_mpoly_(self, other: fmpz_mod_mpoly):
484-
cdef fmpz_mod_mpoly quotient
487+
cdef _floordiv_mpoly_(self, arg):
488+
cdef fmpz_mod_mpoly quotient, other = <fmpz_mod_mpoly>arg
485489
quotient = create_fmpz_mod_mpoly(self.ctx)
486490
fmpz_mod_mpoly_div(quotient.val, self.val, other.val, self.ctx.val)
487491
return quotient
488492

489-
def _truediv_mpoly_(self, other: fmpz_mod_mpoly):
490-
cdef fmpz_mod_mpoly quotient
493+
cdef _truediv_mpoly_(self, arg):
494+
cdef fmpz_mod_mpoly quotient, other = <fmpz_mod_mpoly>arg
491495
quotient = create_fmpz_mod_mpoly(self.ctx)
492496
if fmpz_mod_mpoly_divides(quotient.val, self.val, other.val, self.ctx.val):
493497
return quotient
494498
else:
495499
raise DomainError("fmpz_mod_mpoly division is not exact")
496500

497-
def _mod_mpoly_(self, other: fmpz_mod_mpoly):
498-
cdef fmpz_mod_mpoly quotient, remainder
501+
cdef _mod_mpoly_(self, arg):
502+
cdef fmpz_mod_mpoly quotient, remainder, other = <fmpz_mod_mpoly>arg
499503
quotient = create_fmpz_mod_mpoly(self.ctx)
500504
remainder = create_fmpz_mod_mpoly(self.ctx)
501505
fmpz_mod_mpoly_divrem(quotient.val, remainder.val, self.val, other.val, self.ctx.val)
502506
return remainder
503507

508+
cdef _rsub_scalar_(self, arg):
509+
cdef fmpz_mod_mpoly res
510+
cdef fmpz other = <fmpz>arg
511+
res = create_fmpz_mod_mpoly(self.ctx)
512+
fmpz_mod_mpoly_sub_fmpz(res.val, self.val, other.val, self.ctx.val)
513+
fmpz_mod_mpoly_neg(res.val, res.val, res.ctx.val)
514+
return res
515+
516+
cdef _rsub_mpoly_(self, arg):
517+
return (<fmpz_mod_mpoly>arg)._sub_mpoly_(self)
518+
519+
cdef _rdivmod_mpoly_(self, arg):
520+
return (<fmpz_mod_mpoly>arg)._divmod_mpoly_(self)
521+
522+
cdef _rfloordiv_mpoly_(self, arg):
523+
return (<fmpz_mod_mpoly>arg)._floordiv_mpoly_(self)
524+
525+
cdef _rtruediv_mpoly_(self, arg):
526+
return (<fmpz_mod_mpoly>arg)._truediv_mpoly_(self)
527+
528+
cdef _rmod_mpoly_(self, arg):
529+
return (<fmpz_mod_mpoly>arg)._mod_mpoly_(self)
530+
531+
cdef _iadd_scalar_(self, arg):
532+
cdef fmpz other = <fmpz>arg
533+
fmpz_mod_mpoly_add_fmpz(self.val, self.val, other.val, self.ctx.val)
534+
535+
cdef _isub_scalar_(self, arg):
536+
cdef fmpz other = <fmpz>arg
537+
fmpz_mod_mpoly_sub_fmpz(self.val, self.val, other.val, self.ctx.val)
538+
539+
cdef _imul_scalar_(self, arg):
540+
cdef fmpz other = <fmpz>arg
541+
fmpz_mod_mpoly_scalar_mul_fmpz(self.val, self.val, other.val, self.ctx.val)
542+
543+
cdef _iadd_mpoly_(self, arg):
544+
cdef fmpz_mod_mpoly other = <fmpz_mod_mpoly>arg
545+
fmpz_mod_mpoly_add(self.val, self.val, other.val, self.ctx.val)
546+
547+
cdef _isub_mpoly_(self, arg):
548+
cdef fmpz_mod_mpoly other = <fmpz_mod_mpoly>arg
549+
fmpz_mod_mpoly_sub(self.val, self.val, other.val, self.ctx.val)
550+
551+
cdef _imul_mpoly_(self, arg):
552+
cdef fmpz_mod_mpoly other = <fmpz_mod_mpoly>arg
553+
fmpz_mod_mpoly_mul(self.val, self.val, other.val, self.ctx.val)
554+
504555
def __call__(self, *args) -> fmpz:
505556
cdef:
506557
fmpz_vec V
@@ -515,24 +566,6 @@ cdef class fmpz_mod_mpoly(flint_mpoly):
515566
fmpz_mod_mpoly_evaluate_all_fmpz(vres.val, self.val, V.double_indirect, self.ctx.val)
516567
return vres
517568

518-
def _iadd_scalar_(self, other: fmpz):
519-
fmpz_mod_mpoly_add_fmpz(self.val, self.val, other.val, self.ctx.val)
520-
521-
def _iadd_mpoly_(self, other: fmpz_mod_mpoly):
522-
fmpz_mod_mpoly_add(self.val, self.val, other.val, self.ctx.val)
523-
524-
def _isub_scalar_(self, other: fmpz):
525-
fmpz_mod_mpoly_sub_fmpz(self.val, self.val, other.val, self.ctx.val)
526-
527-
def _isub_mpoly_(self, other: fmpz_mod_mpoly):
528-
fmpz_mod_mpoly_sub(self.val, self.val, other.val, self.ctx.val)
529-
530-
def _imul_scalar_(self, other: fmpz):
531-
fmpz_mod_mpoly_scalar_mul_fmpz(self.val, self.val, other.val, self.ctx.val)
532-
533-
def _imul_mpoly_(self, other: fmpz_mod_mpoly):
534-
fmpz_mod_mpoly_mul(self.val, self.val, other.val, self.ctx.val)
535-
536569
def monoms(self):
537570
"""
538571
Return the exponent vectors of each term as a tuple of fmpz.

‎src/flint/types/fmpz_mpoly.pyx

+76-43
Original file line numberDiff line numberDiff line change
@@ -326,77 +326,128 @@ cdef class fmpz_mpoly(flint_mpoly):
326326
fmpz_mpoly_neg(res.val, (<fmpz_mpoly>self).val, res.ctx.val)
327327
return res
328328

329-
def _add_scalar_(self, other: fmpz):
329+
cdef _add_scalar_(self, arg):
330330
cdef fmpz_mpoly res
331+
cdef fmpz other = <fmpz>arg
331332
res = create_fmpz_mpoly(self.ctx)
332333
fmpz_mpoly_add_fmpz(res.val, self.val, other.val, self.ctx.val)
333334
return res
334335

335-
def _add_mpoly_(self, other: fmpz_mpoly):
336+
cdef _sub_scalar_(self, arg):
336337
cdef fmpz_mpoly res
338+
cdef fmpz other = <fmpz>arg
337339
res = create_fmpz_mpoly(self.ctx)
338-
fmpz_mpoly_add(res.val, self.val, other.val, res.ctx.val)
340+
fmpz_mpoly_sub_fmpz(res.val, self.val, other.val, self.ctx.val)
339341
return res
340342

341-
def _sub_scalar_(self, other: fmpz):
343+
cdef _mul_scalar_(self, arg):
342344
cdef fmpz_mpoly res
345+
cdef fmpz other = <fmpz>arg
343346
res = create_fmpz_mpoly(self.ctx)
344-
fmpz_mpoly_sub_fmpz(res.val, self.val, other.val, self.ctx.val)
347+
fmpz_mpoly_scalar_mul_fmpz(res.val, self.val, other.val, self.ctx.val)
345348
return res
346349

347-
def _sub_mpoly_(self, other: fmpz_mpoly):
350+
cdef _pow_(self, arg):
348351
cdef fmpz_mpoly res
352+
cdef fmpz other = <fmpz>arg
349353
res = create_fmpz_mpoly(self.ctx)
350-
fmpz_mpoly_sub(res.val, self.val, other.val, res.ctx.val)
354+
if fmpz_mpoly_pow_fmpz(res.val, self.val, other.val, res.ctx.val) == 0:
355+
raise ValueError("unreasonably large polynomial") # pragma: no cover
351356
return res
352357

353-
def _mul_scalar_(self, other: fmpz):
354-
cdef fmpz_mpoly res
358+
cdef _add_mpoly_(self, arg):
359+
cdef fmpz_mpoly res, other = <fmpz_mpoly>arg
355360
res = create_fmpz_mpoly(self.ctx)
356-
fmpz_mpoly_scalar_mul_fmpz(res.val, self.val, other.val, self.ctx.val)
361+
fmpz_mpoly_add(res.val, self.val, other.val, res.ctx.val)
357362
return res
358363

359-
def _mul_mpoly_(self, other: fmpz_mpoly):
360-
cdef fmpz_mpoly res
364+
cdef _sub_mpoly_(self, arg):
365+
cdef fmpz_mpoly res, other = <fmpz_mpoly>arg
361366
res = create_fmpz_mpoly(self.ctx)
362-
fmpz_mpoly_mul(res.val, self.val, other.val, res.ctx.val)
367+
fmpz_mpoly_sub(res.val, self.val, other.val, res.ctx.val)
363368
return res
364369

365-
def _pow_(self, other: fmpz):
366-
cdef fmpz_mpoly res
370+
cdef _mul_mpoly_(self, arg):
371+
cdef fmpz_mpoly res, other = <fmpz_mpoly>arg
367372
res = create_fmpz_mpoly(self.ctx)
368-
if fmpz_mpoly_pow_fmpz(res.val, self.val, other.val, res.ctx.val) == 0:
369-
raise ValueError("unreasonably large polynomial") # pragma: no cover
373+
fmpz_mpoly_mul(res.val, self.val, other.val, res.ctx.val)
370374
return res
371375

372-
def _divmod_mpoly_(self, other: fmpz_mpoly):
373-
cdef fmpz_mpoly quotient, remainder
376+
cdef _divmod_mpoly_(self, arg):
377+
cdef fmpz_mpoly quotient, remainder, other = <fmpz_mpoly>arg
374378
quotient = create_fmpz_mpoly(self.ctx)
375379
remainder = create_fmpz_mpoly(self.ctx)
376380
fmpz_mpoly_divrem(quotient.val, remainder.val, self.val, other.val, self.ctx.val)
377381
return (quotient, remainder)
378382

379-
def _floordiv_mpoly_(self, other: fmpz_mpoly):
380-
cdef fmpz_mpoly quotient
383+
cdef _floordiv_mpoly_(self, arg):
384+
cdef fmpz_mpoly quotient, other = <fmpz_mpoly>arg
381385
quotient = create_fmpz_mpoly(self.ctx)
382386
fmpz_mpoly_div(quotient.val, self.val, other.val, self.ctx.val)
383387
return quotient
384388

385-
def _truediv_mpoly_(self, other: fmpz_mpoly):
386-
cdef fmpz_mpoly quotient
389+
cdef _truediv_mpoly_(self, arg):
390+
cdef fmpz_mpoly quotient, other = <fmpz_mpoly>arg
387391
quotient = create_fmpz_mpoly(self.ctx)
388392
if fmpz_mpoly_divides(quotient.val, self.val, other.val, self.ctx.val):
389393
return quotient
390394
else:
391395
raise DomainError("fmpz_mpoly division is not exact")
392396

393-
def _mod_mpoly_(self, other: fmpz_mpoly):
394-
cdef fmpz_mpoly quotient, remainder
397+
cdef _mod_mpoly_(self, arg):
398+
cdef fmpz_mpoly quotient, remainder, other = <fmpz_mpoly>arg
395399
quotient = create_fmpz_mpoly(self.ctx)
396400
remainder = create_fmpz_mpoly(self.ctx)
397401
fmpz_mpoly_divrem(quotient.val, remainder.val, self.val, other.val, self.ctx.val)
398402
return remainder
399403

404+
cdef _rsub_scalar_(self, arg):
405+
cdef fmpz_mpoly res
406+
cdef fmpz other = <fmpz>arg
407+
res = create_fmpz_mpoly(self.ctx)
408+
fmpz_mpoly_sub_fmpz(res.val, self.val, other.val, self.ctx.val)
409+
fmpz_mpoly_neg(res.val, res.val, res.ctx.val)
410+
return res
411+
412+
cdef _rsub_mpoly_(self, arg):
413+
return (<fmpz_mpoly>arg)._sub_mpoly_(self)
414+
415+
cdef _rdivmod_mpoly_(self, arg):
416+
return (<fmpz_mpoly>arg)._divmod_mpoly_(self)
417+
418+
cdef _rfloordiv_mpoly_(self, arg):
419+
return (<fmpz_mpoly>arg)._floordiv_mpoly_(self)
420+
421+
cdef _rtruediv_mpoly_(self, arg):
422+
return (<fmpz_mpoly>arg)._truediv_mpoly_(self)
423+
424+
cdef _rmod_mpoly_(self, arg):
425+
return (<fmpz_mpoly>arg)._mod_mpoly_(self)
426+
427+
cdef _iadd_scalar_(self, arg):
428+
cdef fmpz other = <fmpz>arg
429+
fmpz_mpoly_add_fmpz(self.val, self.val, other.val, self.ctx.val)
430+
431+
cdef _isub_scalar_(self, arg):
432+
cdef fmpz other = <fmpz>arg
433+
fmpz_mpoly_sub_fmpz(self.val, self.val, other.val, self.ctx.val)
434+
435+
cdef _imul_scalar_(self, arg):
436+
cdef fmpz other = <fmpz>arg
437+
fmpz_mpoly_scalar_mul_fmpz(self.val, self.val, other.val, self.ctx.val)
438+
439+
cdef _iadd_mpoly_(self, arg):
440+
cdef fmpz_mpoly other = <fmpz_mpoly>arg
441+
fmpz_mpoly_add(self.val, self.val, other.val, self.ctx.val)
442+
443+
cdef _isub_mpoly_(self, arg):
444+
cdef fmpz_mpoly other = <fmpz_mpoly>arg
445+
fmpz_mpoly_sub(self.val, self.val, other.val, self.ctx.val)
446+
447+
cdef _imul_mpoly_(self, arg):
448+
cdef fmpz_mpoly other = <fmpz_mpoly>arg
449+
fmpz_mpoly_mul(self.val, self.val, other.val, self.ctx.val)
450+
400451
def __call__(self, *args) -> fmpz:
401452
cdef:
402453
fmpz_vec V
@@ -412,24 +463,6 @@ cdef class fmpz_mpoly(flint_mpoly):
412463
raise ValueError("unreasonably large polynomial") # pragma: no cover
413464
return vres
414465

415-
def _iadd_scalar_(self, other: fmpz):
416-
fmpz_mpoly_add_fmpz(self.val, self.val, other.val, self.ctx.val)
417-
418-
def _iadd_mpoly_(self, other: fmpz_mpoly):
419-
fmpz_mpoly_add(self.val, self.val, other.val, self.ctx.val)
420-
421-
def _isub_scalar_(self, other: fmpz):
422-
fmpz_mpoly_sub_fmpz(self.val, self.val, other.val, self.ctx.val)
423-
424-
def _isub_mpoly_(self, other: fmpz_mpoly):
425-
fmpz_mpoly_sub(self.val, self.val, other.val, self.ctx.val)
426-
427-
def _imul_scalar_(self, other: fmpz):
428-
fmpz_mpoly_scalar_mul_fmpz(self.val, self.val, other.val, self.ctx.val)
429-
430-
def _imul_mpoly_(self, other: fmpz_mpoly):
431-
fmpz_mpoly_mul(self.val, self.val, other.val, self.ctx.val)
432-
433466
def monoms(self):
434467
"""
435468
Return the exponent vectors of each term as a tuple of fmpz.

‎src/flint/types/nmod_mpoly.pyx

+76-43
Original file line numberDiff line numberDiff line change
@@ -406,77 +406,128 @@ cdef class nmod_mpoly(flint_mpoly):
406406
nmod_mpoly_neg(res.val, (<nmod_mpoly>self).val, res.ctx.val)
407407
return res
408408

409-
def _add_scalar_(self, other: ulong):
409+
cdef _add_scalar_(self, arg):
410410
cdef nmod_mpoly res
411+
cdef ulong other = <ulong>arg
411412
res = create_nmod_mpoly(self.ctx)
412413
nmod_mpoly_add_ui(res.val, self.val, other, self.ctx.val)
413414
return res
414415

415-
def _add_mpoly_(self, other: nmod_mpoly):
416+
cdef _sub_scalar_(self, arg):
416417
cdef nmod_mpoly res
418+
cdef ulong other = <ulong>arg
417419
res = create_nmod_mpoly(self.ctx)
418-
nmod_mpoly_add(res.val, self.val, other.val, res.ctx.val)
420+
nmod_mpoly_sub_ui(res.val, self.val, other, self.ctx.val)
419421
return res
420422

421-
def _sub_scalar_(self, other: ulong):
423+
cdef _mul_scalar_(self, arg):
422424
cdef nmod_mpoly res
425+
cdef ulong other = <ulong>arg
423426
res = create_nmod_mpoly(self.ctx)
424-
nmod_mpoly_sub_ui(res.val, self.val, other, self.ctx.val)
427+
nmod_mpoly_scalar_mul_ui(res.val, self.val, other, self.ctx.val)
425428
return res
426429

427-
def _sub_mpoly_(self, other: nmod_mpoly):
430+
cdef _pow_(self, arg):
428431
cdef nmod_mpoly res
432+
cdef fmpz other = <fmpz>arg
429433
res = create_nmod_mpoly(self.ctx)
430-
nmod_mpoly_sub(res.val, self.val, other.val, res.ctx.val)
434+
if nmod_mpoly_pow_fmpz(res.val, self.val, other.val, res.ctx.val) == 0:
435+
raise ValueError("unreasonably large polynomial") # pragma: no cover
431436
return res
432437

433-
def _mul_scalar_(self, other: ulong):
434-
cdef nmod_mpoly res
438+
cdef _add_mpoly_(self, arg):
439+
cdef nmod_mpoly res, other = <nmod_mpoly>arg
435440
res = create_nmod_mpoly(self.ctx)
436-
nmod_mpoly_scalar_mul_ui(res.val, self.val, other, self.ctx.val)
441+
nmod_mpoly_add(res.val, self.val, other.val, res.ctx.val)
437442
return res
438443

439-
def _mul_mpoly_(self, other: nmod_mpoly):
440-
cdef nmod_mpoly res
444+
cdef _sub_mpoly_(self, arg):
445+
cdef nmod_mpoly res, other = <nmod_mpoly>arg
441446
res = create_nmod_mpoly(self.ctx)
442-
nmod_mpoly_mul(res.val, self.val, other.val, res.ctx.val)
447+
nmod_mpoly_sub(res.val, self.val, other.val, res.ctx.val)
443448
return res
444449

445-
def _pow_(self, other: fmpz):
446-
cdef nmod_mpoly res
450+
cdef _mul_mpoly_(self, arg):
451+
cdef nmod_mpoly res, other = <nmod_mpoly>arg
447452
res = create_nmod_mpoly(self.ctx)
448-
if nmod_mpoly_pow_fmpz(res.val, self.val, (<fmpz>other).val, res.ctx.val) == 0:
449-
raise ValueError("unreasonably large polynomial") # pragma: no cover
453+
nmod_mpoly_mul(res.val, self.val, other.val, res.ctx.val)
450454
return res
451455

452-
def _divmod_mpoly_(self, other: nmod_mpoly):
453-
cdef nmod_mpoly quotient, remainder
456+
cdef _divmod_mpoly_(self, arg):
457+
cdef nmod_mpoly quotient, remainder, other = <nmod_mpoly>arg
454458
quotient = create_nmod_mpoly(self.ctx)
455459
remainder = create_nmod_mpoly(self.ctx)
456460
nmod_mpoly_divrem(quotient.val, remainder.val, self.val, other.val, self.ctx.val)
457461
return (quotient, remainder)
458462

459-
def _floordiv_mpoly_(self, other: nmod_mpoly):
460-
cdef nmod_mpoly quotient
463+
cdef _floordiv_mpoly_(self, arg):
464+
cdef nmod_mpoly quotient, other = <nmod_mpoly>arg
461465
quotient = create_nmod_mpoly(self.ctx)
462466
nmod_mpoly_div(quotient.val, self.val, other.val, self.ctx.val)
463467
return quotient
464468

465-
def _truediv_mpoly_(self, other: nmod_mpoly):
466-
cdef nmod_mpoly quotient
469+
cdef _truediv_mpoly_(self, arg):
470+
cdef nmod_mpoly quotient, other = <nmod_mpoly>arg
467471
quotient = create_nmod_mpoly(self.ctx)
468472
if nmod_mpoly_divides(quotient.val, self.val, other.val, self.ctx.val):
469473
return quotient
470474
else:
471475
raise DomainError("nmod_mpoly division is not exact")
472476

473-
def _mod_mpoly_(self, other: nmod_mpoly):
474-
cdef nmod_mpoly quotient, remainder
477+
cdef _mod_mpoly_(self, arg):
478+
cdef nmod_mpoly quotient, remainder, other = <nmod_mpoly>arg
475479
quotient = create_nmod_mpoly(self.ctx)
476480
remainder = create_nmod_mpoly(self.ctx)
477481
nmod_mpoly_divrem(quotient.val, remainder.val, self.val, other.val, self.ctx.val)
478482
return remainder
479483

484+
cdef _rsub_scalar_(self, arg):
485+
cdef nmod_mpoly res
486+
cdef ulong other = <ulong>arg
487+
res = create_nmod_mpoly(self.ctx)
488+
nmod_mpoly_sub_ui(res.val, self.val, other, self.ctx.val)
489+
nmod_mpoly_neg(res.val, res.val, res.ctx.val)
490+
return res
491+
492+
cdef _rsub_mpoly_(self, arg):
493+
return (<nmod_mpoly>arg)._sub_mpoly_(self)
494+
495+
cdef _rdivmod_mpoly_(self, arg):
496+
return (<nmod_mpoly>arg)._divmod_mpoly_(self)
497+
498+
cdef _rfloordiv_mpoly_(self, arg):
499+
return (<nmod_mpoly>arg)._floordiv_mpoly_(self)
500+
501+
cdef _rtruediv_mpoly_(self, arg):
502+
return (<nmod_mpoly>arg)._truediv_mpoly_(self)
503+
504+
cdef _rmod_mpoly_(self, arg):
505+
return (<nmod_mpoly>arg)._mod_mpoly_(self)
506+
507+
cdef _iadd_scalar_(self, arg):
508+
cdef ulong other = <ulong>arg
509+
nmod_mpoly_add_ui(self.val, self.val, other, self.ctx.val)
510+
511+
cdef _isub_scalar_(self, arg):
512+
cdef ulong other = <ulong>arg
513+
nmod_mpoly_sub_ui(self.val, self.val, other, self.ctx.val)
514+
515+
cdef _imul_scalar_(self, arg):
516+
cdef ulong other = <fmpz>arg
517+
nmod_mpoly_scalar_mul_ui(self.val, self.val, other, self.ctx.val)
518+
519+
cdef _iadd_mpoly_(self, arg):
520+
cdef nmod_mpoly other = <nmod_mpoly>arg
521+
nmod_mpoly_add(self.val, self.val, other.val, self.ctx.val)
522+
523+
cdef _isub_mpoly_(self, arg):
524+
cdef nmod_mpoly other = <nmod_mpoly>arg
525+
nmod_mpoly_sub(self.val, self.val, other.val, self.ctx.val)
526+
527+
cdef _imul_mpoly_(self, arg):
528+
cdef nmod_mpoly other = <nmod_mpoly>arg
529+
nmod_mpoly_mul(self.val, self.val, other.val, self.ctx.val)
530+
480531
def __call__(self, *args) -> ulong:
481532
cdef:
482533
slong nvars = self.ctx.nvars(), nargs = len(args)
@@ -502,24 +553,6 @@ cdef class nmod_mpoly(flint_mpoly):
502553

503554
return res
504555

505-
def _iadd_scalar_(self, other: ulong):
506-
nmod_mpoly_add_ui(self.val, self.val, other, self.ctx.val)
507-
508-
def _iadd_mpoly_(self, other: nmod_mpoly):
509-
nmod_mpoly_add(self.val, self.val, other.val, self.ctx.val)
510-
511-
def _isub_scalar_(self, other: ulong):
512-
nmod_mpoly_sub_ui(self.val, self.val, other, self.ctx.val)
513-
514-
def _isub_mpoly_(self, other: nmod_mpoly):
515-
nmod_mpoly_sub(self.val, self.val, other.val, self.ctx.val)
516-
517-
def _imul_scalar_(self, other: ulong):
518-
nmod_mpoly_scalar_mul_ui(self.val, self.val, other, self.ctx.val)
519-
520-
def _imul_mpoly_(self, other: nmod_mpoly):
521-
nmod_mpoly_mul(self.val, self.val, other.val, self.ctx.val)
522-
523556
def monoms(self):
524557
"""
525558
Return the exponent vectors of each term as a tuple of fmpz.

0 commit comments

Comments
 (0)
Please sign in to comment.