Skip to content

Commit 43dc15d

Browse files
committed
Add fmpq_mpoly.zpoly and fmpq_mpoly.zcontent
1 parent 36c5f92 commit 43dc15d

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

src/flint/types/fmpq_mpoly.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ 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 zpoly(self) -> fmpz_mpoly: ...
106+
def zcontent(self) -> fmpq: ...
107+
105108
def factor(self) -> tuple[fmpq, list[tuple[fmpq_mpoly, int]]]: ...
106109
def factor_squarefree(self) -> tuple[fmpq, list[tuple[fmpq_mpoly, int]]]: ...
107110

src/flint/types/fmpq_mpoly.pyx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ from flint.types.fmpz_vec cimport fmpz_vec
1717
from flint.types.fmpq_vec cimport fmpq_vec
1818

1919
from flint.types.fmpz cimport fmpz, any_as_fmpz
20-
from flint.types.fmpz_mpoly cimport fmpz_mpoly
20+
from flint.types.fmpz_mpoly cimport fmpz_mpoly, fmpz_mpoly_ctx, create_fmpz_mpoly
2121

2222
from flint.flintlib.functions.fmpq cimport fmpq_set, fmpq_one
2323
from flint.flintlib.functions.fmpq_mpoly cimport (
@@ -785,6 +785,36 @@ cdef class fmpq_mpoly(flint_mpoly):
785785
fmpq_mpoly_term_content(res.val, self.val, self.ctx.val)
786786
return res
787787

788+
def zpoly(self):
789+
"""
790+
Return the integer polynomial of ``self``. The product
791+
of this and ``self.zcontent()``, represents the whole
792+
polynomial.
793+
794+
>>> ctx = fmpq_mpoly_ctx.get(("x","y"))
795+
>>> x, y = ctx.gens()
796+
>>> (fmpq(2,3)*x + fmpq(2,5)*y).zpoly()
797+
5*x + 3*y
798+
"""
799+
cdef fmpz_mpoly_ctx zctx = fmpz_mpoly_ctx.from_context(self.ctx)
800+
cdef fmpz_mpoly res = create_fmpz_mpoly(zctx)
801+
fmpz_mpoly_set(res.val, self.val.zpoly, zctx.val)
802+
return res
803+
804+
def zcontent(self):
805+
"""
806+
Return the content of ``self``. The product of this and
807+
``self.zpoly()``, represents the whole polynomial.
808+
809+
>>> ctx = fmpq_mpoly_ctx.get(("x","y"))
810+
>>> x, y = ctx.gens()
811+
>>> (fmpq(2,3)*x + fmpq(2,5)*y).zcontent()
812+
2/15
813+
"""
814+
cdef fmpq res = fmpq.__new__(fmpq)
815+
fmpq_set(res.val, self.val.content)
816+
return res
817+
788818
def resultant(self, other, var):
789819
"""
790820
Return the resultant of ``self`` and ``other`` with respect to variable ``var``.

0 commit comments

Comments
 (0)