@@ -297,9 +297,6 @@ cdef class fmpz_mpoly(flint_mpoly):
297297 exp_vec = fmpz_vec(x, double_indirect = True )
298298 fmpz_mpoly_set_coeff_fmpz_fmpz(self .val, (< fmpz> coeff).val, exp_vec.double_indirect, self .ctx.val)
299299
300- def __pos__ (self ):
301- return self
302-
303300 def __neg__ (self ):
304301 cdef fmpz_mpoly res
305302 res = create_fmpz_mpoly(self .ctx)
@@ -569,6 +566,51 @@ cdef class fmpz_mpoly(flint_mpoly):
569566 raise ValueError("Unreasonably large polynomial") # pragma: no cover
570567 return vres
571568
569+ def keys(self ):
570+ """
571+ Return the exponent vectors of each term as a tuple of fmpz.
572+
573+ >>> from flint import Ordering
574+ >>> ctx = fmpz_mpoly_ctx.get_context(2, Ordering.lex, 'x')
575+ >>> f = ctx.from_dict({(0, 0): 1, (1, 0): 2, (0, 1): 3, (1, 1): 4})
576+ >>> f.keys()
577+ [(1, 1), (1, 0), (0, 1), (0, 0)]
578+
579+ """
580+ cdef:
581+ slong i, nvars = self .ctx.nvars()
582+ fmpz_vec vec = fmpz_vec(nvars, double_indirect = True )
583+
584+ res = []
585+ for i in range (len (self )):
586+ fmpz_mpoly_get_term_exp_fmpz(vec.double_indirect, self .val, i, self .ctx.val)
587+ res.append(vec.to_tuple())
588+
589+ return res
590+
591+ def values (self ):
592+ """
593+ Return the coefficients of each term as a fmpz
594+
595+ >>> from flint import Ordering
596+ >>> ctx = fmpz_mpoly_ctx.get_context(2, Ordering.lex, 'x')
597+ >>> f = ctx.from_dict({(0, 0): 1, (1, 0): 2, (0, 1): 3, (1, 1): 4})
598+ >>> f.values()
599+ [4, 2, 3, 1]
600+
601+ """
602+ cdef:
603+ fmpz coeff
604+ slong i
605+
606+ res = []
607+ for i in range (len (self )):
608+ coeff = fmpz.__new__ (fmpz)
609+ fmpz_mpoly_get_term_coeff_fmpz(coeff.val, self .val, i, self .ctx.val)
610+ res.append(coeff)
611+
612+ return res
613+
572614 def subs (self , dict_args ) -> fmpz_mpoly:
573615 """
574616 Partial evaluate this polynomial with select constants. All arguments must be fmpz.
0 commit comments