Skip to content

Commit 7edef2a

Browse files
committed
Rename zprimitive to zpoly
1 parent efd85a7 commit 7edef2a

4 files changed

Lines changed: 28 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ Contributors (0.10.0):
175175
Changes (0.10.0):
176176

177177
- [gh-421](https://github.com/flintlib/python-flint/pull/421),
178-
Add `zprimitive` and `zcontent` methods to `fmpq_mpoly`, to get
178+
Add `zpoly` and `zcontent` methods to `fmpq_mpoly`, to get
179179
the primitive integer polynomial and the `fmpq` content, which
180180
form the internal representation of the `fmpq_mpoly`. Also add
181181
support for building with Cython 3.3. (VM, OB)

src/flint/test/test_all.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3934,25 +3934,25 @@ def quick_poly():
39343934
assert False # New _mpoly types?
39353935

39363936

3937-
def test_fmpq_mpoly_zcontent_zprimitive():
3937+
def test_fmpq_mpoly_zcontent_zpoly():
39383938
ctx = flint.fmpq_mpoly_ctx.get(("x", "y"))
39393939
x, y = ctx.gens()
39403940
zctx = flint.fmpz_mpoly_ctx.from_context(ctx)
39413941
zx, zy = zctx.gens()
39423942

39433943
f = -2*x/3 - 2*y/5
39443944
assert f.zcontent() == flint.fmpq(-2, 15)
3945-
assert f.zprimitive() == 5*zx + 3*zy
3945+
assert f.zpoly() == 5*zx + 3*zy
39463946
assert isinstance(f.zcontent(), flint.fmpq)
3947-
assert isinstance(f.zprimitive(), flint.fmpz_mpoly)
3947+
assert isinstance(f.zpoly(), flint.fmpz_mpoly)
39483948
# Can't mix fmpq_mpoly with fmpz_mpoly...
3949-
p = flint.fmpq_mpoly(f.zprimitive(), ctx=ctx)
3949+
p = flint.fmpq_mpoly(f.zpoly(), ctx=ctx)
39503950
c = f.zcontent()
39513951
assert p * c == f
39523952

39533953
f = 0*x
39543954
assert f.zcontent() == 0
3955-
assert f.zprimitive() == 0
3955+
assert f.zpoly() == 0
39563956

39573957

39583958
def _all_mpoly_vecs():

src/flint/types/fmpq_mpoly.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class fmpq_mpoly(flint_mpoly[fmpq_mpoly_ctx, fmpq, ifmpq]):
102102
def xgcd(self, other: fmpq_mpoly, /) -> fmpq: ...
103103
def term_content(self) -> fmpq_mpoly: ...
104104

105-
def zprimitive(self) -> fmpz_mpoly: ...
105+
def zpoly(self) -> fmpz_mpoly: ...
106106
def zcontent(self) -> fmpq: ...
107107

108108
def factor(self) -> tuple[fmpq, list[tuple[fmpq_mpoly, int]]]: ...

src/flint/types/fmpq_mpoly.pyx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,23 @@ cdef class fmpq_mpoly(flint_mpoly):
215215
"""
216216
The *fmpq_mpoly* type represents sparse multivariate polynomials over
217217
the rationals.
218+
219+
Internally, an ``fmpq_mpoly`` is represented as the product of a signed
220+
rational content and a primitive integer multivariate polynomial with
221+
positive leading coefficient. The :meth:`zcontent` and :meth:`zpoly`
222+
methods return copies of these two components, respectively.
223+
224+
The original polynomial can be reconstructed from these components by
225+
converting the integer polynomial back to an ``fmpq_mpoly`` in the
226+
original context and multiplying by the content:
227+
228+
>>> ctx = fmpq_mpoly_ctx.get(("x", "y"))
229+
>>> x, y = ctx.gens()
230+
>>> f = -2*x/3 - 2*y/5
231+
>>> zpoly = f.zpoly()
232+
>>> content = f.zcontent()
233+
>>> fmpq_mpoly(zpoly, ctx=f.context()) * content == f
234+
True
218235
"""
219236

220237
def __cinit__(self):
@@ -785,15 +802,15 @@ cdef class fmpq_mpoly(flint_mpoly):
785802
fmpq_mpoly_term_content(res.val, self.val, self.ctx.val)
786803
return res
787804

788-
def zprimitive(self):
805+
def zpoly(self):
789806
"""
790807
Return the integer polynomial of ``self``. The product
791-
of this and ``self.zcontent()``, represents the whole
808+
of this and ``self.zcontent()`` represents the whole
792809
polynomial.
793810
794811
>>> ctx = fmpq_mpoly_ctx.get(("x","y"))
795812
>>> x, y = ctx.gens()
796-
>>> (x*2/3 + y*2/5).zprimitive()
813+
>>> (x*2/3 + y*2/5).zpoly()
797814
5*x + 3*y
798815
"""
799816
cdef fmpz_mpoly_ctx zctx = fmpz_mpoly_ctx.from_context(self.ctx)
@@ -804,7 +821,7 @@ cdef class fmpq_mpoly(flint_mpoly):
804821
def zcontent(self):
805822
"""
806823
Return the content of ``self``. The product of this and
807-
``self.zprimitive()``, represents the whole polynomial.
824+
``self.zpoly()`` represents the whole polynomial.
808825
809826
>>> ctx = fmpq_mpoly_ctx.get(("x","y"))
810827
>>> x, y = ctx.gens()

0 commit comments

Comments
 (0)