python-flint icon indicating copy to clipboard operation
python-flint copied to clipboard

Query: Regarding documentation of fmpz_mpoly and fmpq_mpoly

Open aasim-maverick opened this issue 8 months ago • 5 comments

I was going through the python-flint docs and while looking into the representation of sparse multivariate polynomials, naturally came across fmpz_mpoly and fmpq_mpoly. However, it kind of confuses me that the docs for both are almost identical.

What confuses me the most is that the docstrings for both the classes say that both the respective types represent sparse multivariate polynomials over the integers. What I expected to see in the case of fmpq_mpoly was that it would represent sparse multivariate polynomials over the rationals. Moreover it's actually naturally possible to construct fmpq_mpoly over the rationals I guess:


In [1]: from flint import *

In [2]: ctx = fmpq_mpoly_ctx.get(('x', 2), 'lex')

In [3]: p = ctx.from_dict({(0, 1): fmpq(1, 2), (1, 1): fmpq(1, 3)})

In [4]: p.coeffs()
Out[4]: [1/3, 1/2]

Makes sense because coeffs() in this case returns a list of fmpq but isn't this what building p over the rationals exactly is ? And doing something similar with fmpz_mpoly will obviously fail since coeffs() in that case will return a list of fmpz and the coercion of 1/2 and 1/3 will henceforth fail. So why do the docs not say for fmpq_mpoly type that it "represents sparse multivariate polynomials over the rationals. "?

I'm sorry if my question here seems foolish, I'm still trying to get my head around things. Would appreciate any insights!

aasim-maverick avatar Mar 12 '25 17:03 aasim-maverick

It is probably just a mistake in the docs. PRs welcome.

oscarbenjamin avatar Mar 12 '25 17:03 oscarbenjamin

The fmpq_mpoly type is for multivariate polynomials over the rational numbers. If the docstring says otherwise then that it is probably because part of the docstring was copied over at some point.

oscarbenjamin avatar Mar 12 '25 22:03 oscarbenjamin

Yeah looks like that.

Even the examples in the docs for fmpz_mpoly and fmpq_mpoly are almost identical in many places. Mathematically, this works since polynomials over the integers are also polynomials over the rationals, but I feel like this approach makes the docs a bit misleading or confusing.

Maybe a better way would be to use non-integer rational values in the examples for fmpq_mpoly, this would more clearly showcase its functionality and make it immediately obvious that it works over the rationals.

aasim-maverick avatar Mar 13 '25 00:03 aasim-maverick

Feel free to open a PR changing the docs.

oscarbenjamin avatar Mar 13 '25 00:03 oscarbenjamin

So why do the docs not say for fmpq_mpoly type that it "represents sparse multivariate polynomials over the rationals. "?

This has been fixed now in gh-320 although it is probably still worth changing the examples to use rational numbers.

oscarbenjamin avatar Sep 04 '25 16:09 oscarbenjamin