Skip to content

Commit d70c2f9

Browse files
committed
Remove keys/values/exponent_tuple functions, rename items -> terms
1 parent 10c19be commit d70c2f9

4 files changed

Lines changed: 55 additions & 63 deletions

File tree

src/flint/flint_base/flint_base.pyx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ cdef class flint_mpoly(flint_elem):
242242
return self.coefficient(0)
243243

244244
def to_dict(self):
245-
return {self.exponent_tuple(i): self.coefficient(i) for i in range(len(self))}
245+
return {self.monomial(i): self.coefficient(i) for i in range(len(self))}
246246

247247
def __contains__(self, x):
248248
"""
@@ -265,24 +265,18 @@ cdef class flint_mpoly(flint_elem):
265265
def __pos__(self):
266266
return self
267267

268-
def keys(self):
269-
return self.monoms()
270-
271-
def values(self):
272-
return self.coeffs()
273-
274-
def items(self):
268+
def terms(self):
275269
"""
276270
Return the exponent vectors and coefficient of each term.
277271
278272
>>> from flint import fmpq_mpoly_ctx, Ordering
279273
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
280274
>>> f = ctx.from_dict({(0, 0): 1, (1, 0): 2, (0, 1): 3, (1, 1): 4})
281-
>>> list(f.items())
275+
>>> list(f.terms())
282276
[((1, 1), 4), ((1, 0), 2), ((0, 1), 3), ((0, 0), 1)]
283277
284278
"""
285-
return zip(self.keys(), self.values())
279+
return zip(self.monoms(), self.coeffs())
286280

287281

288282
cdef class flint_series(flint_elem):

src/flint/test/test_all.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2777,10 +2777,10 @@ def quick_poly():
27772777
assert P(1, ctx=ctx).repr() == f"{ctx.__class__.__name__}(2, '<Ordering.lex: 0>', ('x0', 'x1')).from_dict({{(0, 0): 1}})"
27782778
assert str(quick_poly()) == repr(quick_poly()) == '4*x0^2*x1^2 + 3*x0 + 2*x1 + 1'
27792779

2780-
assert p.exponent_tuple(0) == (2, 2)
2781-
assert p.exponent_tuple(3) == (0, 0)
2782-
assert raises(lambda: p.exponent_tuple(-1), IndexError)
2783-
assert raises(lambda: p.exponent_tuple(4), IndexError)
2780+
assert p.monomial(0) == (2, 2)
2781+
assert p.monomial(3) == (0, 0)
2782+
assert raises(lambda: p.monomial(-1), IndexError)
2783+
assert raises(lambda: p.monomial(4), IndexError)
27842784

27852785
assert p.total_degree() == 4
27862786
assert P(ctx=ctx).total_degree() == -1
@@ -2791,11 +2791,9 @@ def quick_poly():
27912791
assert p(1, 1) == S(10) == 10
27922792

27932793
p = quick_poly()
2794-
assert p.keys() == [(2, 2), (1, 0), (0, 1), (0, 0)]
2795-
assert p.values() == [4, 3, 2, 1]
2796-
assert list(p.items()) == list(zip([(2, 2), (1, 0), (0, 1), (0, 0)], [4, 3, 2, 1]))
2797-
assert sum(ctx.from_dict({exp_vec: coeff}) for exp_vec, coeff in p.items()) == p
2798-
assert sum(p.terms()) == p
2794+
assert p.monoms() == [(2, 2), (1, 0), (0, 1), (0, 0)]
2795+
assert p.coeffs() == [4, 3, 2, 1]
2796+
assert list(p.terms()) == list(zip([(2, 2), (1, 0), (0, 1), (0, 0)], [4, 3, 2, 1]))
27992797

28002798
assert p.subs({"x1": S(0), "x0": S(0)}) == ctx.from_dict({(0, 0): 1})
28012799
assert p.compose(p.subs({"x1": 0}), ctx.from_dict({(0, 1): 1})) == mpoly({

src/flint/types/fmpq_mpoly.pyx

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ cdef class fmpq_mpoly(flint_mpoly):
591591
>>> from flint import Ordering
592592
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
593593
>>> f = ctx.from_dict({(0, 0): 1, (1, 0): 2, (0, 1): 3, (1, 1): 4})
594-
>>> f.keys()
594+
>>> f.monoms()
595595
[(1, 1), (1, 0), (0, 1), (0, 0)]
596596
597597
"""
@@ -613,7 +613,7 @@ cdef class fmpq_mpoly(flint_mpoly):
613613
>>> from flint import Ordering
614614
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
615615
>>> f = ctx.from_dict({(0, 0): 1, (1, 0): 2, (0, 1): 3, (1, 1): 4})
616-
>>> f.values()
616+
>>> f.coeffs()
617617
[4, 2, 3, 1]
618618
619619
"""
@@ -629,28 +629,28 @@ cdef class fmpq_mpoly(flint_mpoly):
629629

630630
return res
631631

632-
def terms(self):
633-
"""
634-
Return the terms of this polynomial as a list of fmpq_mpolys.
632+
# def terms(self):
633+
# """
634+
# Return the terms of this polynomial as a list of fmpq_mpolys.
635635

636-
>>> from flint import Ordering
637-
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
638-
>>> f = ctx.from_dict({(0, 0): 1, (1, 0): 2, (0, 1): 3, (1, 1): 4})
639-
>>> f.terms()
640-
[4*x0*x1, 2*x0, 3*x1, 1]
636+
# >>> from flint import Ordering
637+
# >>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
638+
# >>> f = ctx.from_dict({(0, 0): 1, (1, 0): 2, (0, 1): 3, (1, 1): 4})
639+
# >>> f.terms()
640+
# [4*x0*x1, 2*x0, 3*x1, 1]
641641

642-
"""
643-
cdef:
644-
fmpq_mpoly term
645-
slong i
642+
# """
643+
# cdef:
644+
# fmpq_mpoly term
645+
# slong i
646646

647-
res = []
648-
for i in range(len(self)):
649-
term = create_fmpq_mpoly(self.ctx)
650-
fmpq_mpoly_get_term(term.val, self.val, i, self.ctx.val)
651-
res.append(term)
647+
# res = []
648+
# for i in range(len(self)):
649+
# term = create_fmpq_mpoly(self.ctx)
650+
# fmpq_mpoly_get_term(term.val, self.val, i, self.ctx.val)
651+
# res.append(term)
652652

653-
return res
653+
# return res
654654

655655
def subs(self, dict_args) -> fmpq_mpoly:
656656
"""
@@ -744,14 +744,14 @@ cdef class fmpq_mpoly(flint_mpoly):
744744
fmpq_mpoly_get_term_coeff_fmpq(v.val, self.val, i, self.ctx.val)
745745
return v
746746

747-
def exponent_tuple(self, slong i):
747+
def monomial(self, slong i):
748748
"""
749749
Return the exponent vector at index `i` as a tuple.
750750
751751
>>> from flint import Ordering
752752
>>> ctx = fmpq_mpoly_ctx.get_context(2, Ordering.lex, 'x')
753753
>>> p = ctx.from_dict({(0, 1): 2, (1, 1): 3})
754-
>>> p.exponent_tuple(1)
754+
>>> p.monomial(1)
755755
(0, 1)
756756
"""
757757
cdef:

src/flint/types/fmpz_mpoly.pyx

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ cdef class fmpz_mpoly(flint_mpoly):
573573
>>> from flint import Ordering
574574
>>> ctx = fmpz_mpoly_ctx.get_context(2, Ordering.lex, 'x')
575575
>>> f = ctx.from_dict({(0, 0): 1, (1, 0): 2, (0, 1): 3, (1, 1): 4})
576-
>>> f.keys()
576+
>>> f.monoms()
577577
[(1, 1), (1, 0), (0, 1), (0, 0)]
578578
579579
"""
@@ -595,7 +595,7 @@ cdef class fmpz_mpoly(flint_mpoly):
595595
>>> from flint import Ordering
596596
>>> ctx = fmpz_mpoly_ctx.get_context(2, Ordering.lex, 'x')
597597
>>> f = ctx.from_dict({(0, 0): 1, (1, 0): 2, (0, 1): 3, (1, 1): 4})
598-
>>> f.values()
598+
>>> f.coeffs()
599599
[4, 2, 3, 1]
600600
601601
"""
@@ -611,28 +611,28 @@ cdef class fmpz_mpoly(flint_mpoly):
611611

612612
return res
613613

614-
def terms(self):
615-
"""
616-
Return the terms of this polynomial as a list of fmpz_mpolys.
614+
# def terms(self):
615+
# """
616+
# Return the terms of this polynomial as a list of fmpz_mpolys.
617617

618-
>>> from flint import Ordering
619-
>>> ctx = fmpz_mpoly_ctx.get_context(2, Ordering.lex, 'x')
620-
>>> f = ctx.from_dict({(0, 0): 1, (1, 0): 2, (0, 1): 3, (1, 1): 4})
621-
>>> f.terms()
622-
[4*x0*x1, 2*x0, 3*x1, 1]
618+
# >>> from flint import Ordering
619+
# >>> ctx = fmpz_mpoly_ctx.get_context(2, Ordering.lex, 'x')
620+
# >>> f = ctx.from_dict({(0, 0): 1, (1, 0): 2, (0, 1): 3, (1, 1): 4})
621+
# >>> f.terms()
622+
# [4*x0*x1, 2*x0, 3*x1, 1]
623623

624-
"""
625-
cdef:
626-
fmpz_mpoly term
627-
slong i
624+
# """
625+
# cdef:
626+
# fmpz_mpoly term
627+
# slong i
628628

629-
res = []
630-
for i in range(len(self)):
631-
term = create_fmpz_mpoly(self.ctx)
632-
fmpz_mpoly_get_term(term.val, self.val, i, self.ctx.val)
633-
res.append(term)
629+
# res = []
630+
# for i in range(len(self)):
631+
# term = create_fmpz_mpoly(self.ctx)
632+
# fmpz_mpoly_get_term(term.val, self.val, i, self.ctx.val)
633+
# res.append(term)
634634

635-
return res
635+
# return res
636636

637637
def subs(self, dict_args) -> fmpz_mpoly:
638638
"""
@@ -747,14 +747,14 @@ cdef class fmpz_mpoly(flint_mpoly):
747747
fmpz_mpoly_get_term_coeff_fmpz(v.val, self.val, i, self.ctx.val)
748748
return v
749749

750-
def exponent_tuple(self, slong i):
750+
def monomial(self, slong i):
751751
"""
752752
Return the exponent vector at index `i` as a tuple.
753753
754754
>>> from flint import Ordering
755755
>>> ctx = fmpz_mpoly_ctx.get_context(2, Ordering.lex, 'x')
756756
>>> p = ctx.from_dict({(0, 1): 2, (1, 1): 3})
757-
>>> p.exponent_tuple(1)
757+
>>> p.monomial(1)
758758
(0, 1)
759759
"""
760760
cdef:

0 commit comments

Comments
 (0)