@@ -346,19 +346,6 @@ cdef class fmpq_mpoly(flint_mpoly):
346346 return res
347347 return NotImplemented
348348
349- def __iadd__ (self , other ):
350- if typecheck(other, fmpq_mpoly):
351- if (< fmpq_mpoly> self ).ctx is not (< fmpq_mpoly> other).ctx:
352- raise IncompatibleContextError(f" {(<fmpq_mpoly>self).ctx} is not {(<fmpq_mpoly>other).ctx}" )
353- fmpq_mpoly_add((< fmpq_mpoly> self ).val, (< fmpq_mpoly> self ).val, (< fmpq_mpoly> other).val, self .ctx.val)
354- return self
355- else :
356- other = any_as_fmpq(other)
357- if other is not NotImplemented :
358- fmpq_mpoly_add_fmpq((< fmpq_mpoly> self ).val, (< fmpq_mpoly> self ).val, (< fmpq> other).val, self .ctx.val)
359- return self
360- return NotImplemented
361-
362349 def __sub__ (self , other ):
363350 cdef fmpq_mpoly res
364351 if typecheck(other, fmpq_mpoly):
@@ -384,19 +371,6 @@ cdef class fmpq_mpoly(flint_mpoly):
384371 return - res
385372 return NotImplemented
386373
387- def __isub__ (self , other ):
388- if typecheck(other, fmpq_mpoly):
389- if (< fmpq_mpoly> self ).ctx is not (< fmpq_mpoly> other).ctx:
390- raise IncompatibleContextError(f" {(<fmpq_mpoly>self).ctx} is not {(<fmpq_mpoly>other).ctx}" )
391- fmpq_mpoly_sub((< fmpq_mpoly> self ).val, (< fmpq_mpoly> self ).val, (< fmpq_mpoly> other).val, self .ctx.val)
392- return self
393- else :
394- other = any_as_fmpq(other)
395- if other is not NotImplemented :
396- fmpq_mpoly_sub_fmpq((< fmpq_mpoly> self ).val, (< fmpq_mpoly> self ).val, (< fmpq> other).val, self .ctx.val)
397- return self
398- return NotImplemented
399-
400374 def __mul__ (self , other ):
401375 cdef fmpq_mpoly res
402376 if typecheck(other, fmpq_mpoly):
@@ -422,19 +396,6 @@ cdef class fmpq_mpoly(flint_mpoly):
422396 return res
423397 return NotImplemented
424398
425- def __imul__ (self , other ):
426- if typecheck(other, fmpq_mpoly):
427- if (< fmpq_mpoly> self ).ctx is not (< fmpq_mpoly> other).ctx:
428- raise IncompatibleContextError(f" {(<fmpq_mpoly>self).ctx} is not {(<fmpq_mpoly>other).ctx}" )
429- fmpq_mpoly_mul((< fmpq_mpoly> self ).val, (< fmpq_mpoly> self ).val, (< fmpq_mpoly> other).val, self .ctx.val)
430- return self
431- else :
432- other = any_as_fmpq(other)
433- if other is not NotImplemented :
434- fmpq_mpoly_scalar_mul_fmpq(self .val, (< fmpq_mpoly> self ).val, (< fmpq> other).val, self .ctx.val)
435- return self
436- return NotImplemented
437-
438399 def __pow__ (self , other , modulus ):
439400 cdef fmpq_mpoly res
440401 if modulus is not None :
@@ -582,6 +543,84 @@ cdef class fmpq_mpoly(flint_mpoly):
582543 raise ValueError("unreasonably large polynomial") # pragma: no cover
583544 return vres
584545
546+ def iadd(self , other ):
547+ """
548+ In-place addition, mutates self.
549+
550+ >>> from flint import Ordering
551+ >>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
552+ >>> f = ctx.from_dict({(1, 0): 2, (0, 1): 3, (1, 1): 4})
553+ >>> f
554+ 4*x0*x1 + 2*x0 + 3*x1
555+ >>> f.iadd(5)
556+ >>> f
557+ 4*x0*x1 + 2*x0 + 3*x1 + 5
558+
559+ """
560+ if typecheck(other, fmpq_mpoly):
561+ if (< fmpq_mpoly> self ).ctx is not (< fmpq_mpoly> other).ctx:
562+ raise IncompatibleContextError(f" {(<fmpq_mpoly>self).ctx} is not {(<fmpq_mpoly>other).ctx}" )
563+ fmpq_mpoly_add((< fmpq_mpoly> self ).val, (< fmpq_mpoly> self ).val, (< fmpq_mpoly> other).val, self .ctx.val)
564+ return
565+ else :
566+ other = any_as_fmpq(other)
567+ if other is not NotImplemented :
568+ fmpq_mpoly_add_fmpq((< fmpq_mpoly> self ).val, (< fmpq_mpoly> self ).val, (< fmpq> other).val, self .ctx.val)
569+ return
570+ raise NotImplementedError (f" in-place addition not implemented between {type(self)} and {type(other)}" )
571+
572+ def isub (self , other ):
573+ """
574+ In-place subtraction, mutates self.
575+
576+ >>> from flint import Ordering
577+ >>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
578+ >>> f = ctx.from_dict({(1, 0): 2, (0, 1): 3, (1, 1): 4})
579+ >>> f
580+ 4*x0*x1 + 2*x0 + 3*x1
581+ >>> f.isub(5)
582+ >>> f
583+ 4*x0*x1 + 2*x0 + 3*x1 - 5
584+
585+ """
586+ if typecheck(other, fmpq_mpoly):
587+ if (< fmpq_mpoly> self ).ctx is not (< fmpq_mpoly> other).ctx:
588+ raise IncompatibleContextError(f" {(<fmpq_mpoly>self).ctx} is not {(<fmpq_mpoly>other).ctx}" )
589+ fmpq_mpoly_sub((< fmpq_mpoly> self ).val, (< fmpq_mpoly> self ).val, (< fmpq_mpoly> other).val, self .ctx.val)
590+ return
591+ else :
592+ other = any_as_fmpq(other)
593+ if other is not NotImplemented :
594+ fmpq_mpoly_sub_fmpq((< fmpq_mpoly> self ).val, (< fmpq_mpoly> self ).val, (< fmpq> other).val, self .ctx.val)
595+ return
596+ raise NotImplementedError (f" in-place subtraction not implemented between {type(self)} and {type(other)}" )
597+
598+ def imul (self , other ):
599+ """
600+ In-place multiplication, mutates self.
601+
602+ >>> from flint import Ordering
603+ >>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
604+ >>> f = ctx.from_dict({(1, 0): 2, (0, 1): 3, (1, 1): 4})
605+ >>> f
606+ 4*x0*x1 + 2*x0 + 3*x1
607+ >>> f.imul(2)
608+ >>> f
609+ 8*x0*x1 + 4*x0 + 6*x1
610+
611+ """
612+ if typecheck(other, fmpq_mpoly):
613+ if (< fmpq_mpoly> self ).ctx is not (< fmpq_mpoly> other).ctx:
614+ raise IncompatibleContextError(f" {(<fmpq_mpoly>self).ctx} is not {(<fmpq_mpoly>other).ctx}" )
615+ fmpq_mpoly_mul((< fmpq_mpoly> self ).val, (< fmpq_mpoly> self ).val, (< fmpq_mpoly> other).val, self .ctx.val)
616+ return
617+ else :
618+ other = any_as_fmpq(other)
619+ if other is not NotImplemented :
620+ fmpq_mpoly_scalar_mul_fmpq(self .val, (< fmpq_mpoly> self ).val, (< fmpq> other).val, self .ctx.val)
621+ return
622+ raise NotImplementedError (f" in-place multiplication not implemented between {type(self)} and {type(other)}" )
623+
585624 def monoms (self ):
586625 """
587626 Return the exponent vectors of each term as a tuple of fmpz.
0 commit comments