From 045b61f4cf5e18389efd1a4ec487a6ee3965f261 Mon Sep 17 00:00:00 2001 From: Parsnip37 <41875872+Parsnip37@users.noreply.github.com> Date: Sat, 21 Nov 2026 06:12:12 -0500 Subject: [PATCH 1/3] Explain rational multivariate polynomial inputs --- doc/source/fmpq_mpoly.rst | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/doc/source/fmpq_mpoly.rst b/doc/source/fmpq_mpoly.rst index bce01253..f1f0f80e 100644 --- a/doc/source/fmpq_mpoly.rst +++ b/doc/source/fmpq_mpoly.rst @@ -1,6 +1,33 @@ **fmpq_mpoly** -- multivariate polynomials over the rational numbers =============================================================================== +A context fixes the variables and monomial ordering of a polynomial ring +over :math:`\mathbb{Q}`. For nonnegative integers :math:`i` and :math:`j`, +a dictionary entry ``(i, j): c`` represents the term :math:`c x^i y^j` +when the context's variables are ``x`` and ``y``, in that order. + +For example, the polynomial + +.. math:: + + p(x, y) = \frac{1}{3} x y + \frac{1}{2} x + \frac{3}{4} y + +can be constructed with exact rational coefficients: + +.. code-block:: python + + from flint import fmpq, fmpq_mpoly_ctx + + ctx = fmpq_mpoly_ctx.get(("x", "y"), "lex") + p = ctx.from_dict({ + (1, 1): fmpq(1, 3), + (1, 0): fmpq(1, 2), + (0, 1): fmpq(3, 4), + }) + +For integers :math:`a` and :math:`b \ne 0`, ``fmpq(a, b)`` represents +:math:`a/b` exactly. Integer coefficients are also allowed. + .. autoclass :: flint.fmpq_mpoly_ctx :members: :inherited-members: From 24b118e89e9e92429d176406eeed2aa1ff04de63 Mon Sep 17 00:00:00 2001 From: Drew Date: Mon, 23 Nov 2026 09:33:01 -0500 Subject: [PATCH 2/3] Show rational polynomials from generators --- doc/source/fmpq_mpoly.rst | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/doc/source/fmpq_mpoly.rst b/doc/source/fmpq_mpoly.rst index f1f0f80e..63151ca8 100644 --- a/doc/source/fmpq_mpoly.rst +++ b/doc/source/fmpq_mpoly.rst @@ -12,18 +12,23 @@ For example, the polynomial p(x, y) = \frac{1}{3} x y + \frac{1}{2} x + \frac{3}{4} y -can be constructed with exact rational coefficients: - -.. code-block:: python - - from flint import fmpq, fmpq_mpoly_ctx - - ctx = fmpq_mpoly_ctx.get(("x", "y"), "lex") - p = ctx.from_dict({ - (1, 1): fmpq(1, 3), - (1, 0): fmpq(1, 2), - (0, 1): fmpq(3, 4), - }) +can be constructed from the context's generators:: + + >>> from flint import fmpq, fmpq_mpoly_ctx + >>> ctx = fmpq_mpoly_ctx.get(("x", "y"), "lex") + >>> x, y = ctx.gens() + >>> p = x*y/3 + x/2 + 3*y/4 + >>> p + 1/3*x*y + 1/2*x + 3/4*y + +Division by a nonzero integer gives exact rational coefficients. +The same polynomial can also be constructed from a dictionary:: + + >>> p = ctx.from_dict({ + ... (1, 1): fmpq(1, 3), + ... (1, 0): fmpq(1, 2), + ... (0, 1): fmpq(3, 4), + ... }) For integers :math:`a` and :math:`b \ne 0`, ``fmpq(a, b)`` represents :math:`a/b` exactly. Integer coefficients are also allowed. From 34c41fff1a644a5bcc2d274a00e01d6909e22048 Mon Sep 17 00:00:00 2001 From: Drew Date: Mon, 23 Nov 2026 13:45:37 -0500 Subject: [PATCH 3/3] Display the dictionary polynomial --- doc/source/fmpq_mpoly.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/source/fmpq_mpoly.rst b/doc/source/fmpq_mpoly.rst index 63151ca8..71292c1e 100644 --- a/doc/source/fmpq_mpoly.rst +++ b/doc/source/fmpq_mpoly.rst @@ -29,6 +29,8 @@ The same polynomial can also be constructed from a dictionary:: ... (1, 0): fmpq(1, 2), ... (0, 1): fmpq(3, 4), ... }) + >>> p + 1/3*x*y + 1/2*x + 3/4*y For integers :math:`a` and :math:`b \ne 0`, ``fmpq(a, b)`` represents :math:`a/b` exactly. Integer coefficients are also allowed.