@@ -17,7 +17,7 @@ from flint.types.fmpz_vec cimport fmpz_vec
1717from flint.types.fmpq_vec cimport fmpq_vec
1818
1919from 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
2222from flint.flintlib.functions.fmpq cimport fmpq_set, fmpq_one
2323from flint.flintlib.functions.fmpq_mpoly cimport (
@@ -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,6 +802,36 @@ cdef class fmpq_mpoly(flint_mpoly):
785802 fmpq_mpoly_term_content(res.val, self .val, self .ctx.val)
786803 return res
787804
805+ def zpoly (self ):
806+ """
807+ Return the integer polynomial of ``self``. The product
808+ of this and ``self.zcontent()`` represents the whole
809+ polynomial.
810+
811+ >>> ctx = fmpq_mpoly_ctx.get(("x","y"))
812+ >>> x, y = ctx.gens()
813+ >>> (x*2/3 + y*2/5).zpoly()
814+ 5*x + 3*y
815+ """
816+ cdef fmpz_mpoly_ctx zctx = fmpz_mpoly_ctx.from_context(self .ctx)
817+ cdef fmpz_mpoly res = create_fmpz_mpoly(zctx)
818+ fmpz_mpoly_set(res.val, self .val.zpoly, zctx.val)
819+ return res
820+
821+ def zcontent (self ):
822+ """
823+ Return the content of ``self``. The product of this and
824+ ``self.zpoly()`` represents the whole polynomial.
825+
826+ >>> ctx = fmpq_mpoly_ctx.get(("x","y"))
827+ >>> x, y = ctx.gens()
828+ >>> (x*2/3 + y*2/5).zcontent()
829+ 2/15
830+ """
831+ cdef fmpq res = fmpq.__new__ (fmpq)
832+ fmpq_set(res.val, self .val.content)
833+ return res
834+
788835 def resultant (self , other , var ):
789836 """
790837 Return the resultant of ``self`` and ``other`` with respect to variable ``var``.
0 commit comments