Skip to content

Conversation

remyoudompheng
Copy link
Contributor

This PR adds a few methods to nmod_poly to make its interface closer to fmpz_mod_poly. Currently there is no workaround to shift a nmod_poly with acceptable performance.

@oscarbenjamin
Copy link
Collaborator

It looks like there are FLINT functions for these methods for all poly types. Do you think you could add these for fmpz_poly, fmpq_poly, arb_poly and acb_poly as well?

The usual way to test this would be to add tests in test_all.py like:

# (This covers fmpz_poly, fmpq_poly, nmod_poly, fmpz_mod_poly, fq_default_poly)
@all_polys
def test_all_polys_shift_truncate(args: _PolyTestCase[typ.epoly_p[Tc], Tc]) -> None:
    P, _, _, _ = args
    assert P([1, 2, 3]).left_shift(3) == P([0, 0, 0, 1, 2, 3])
    assert P([1, 2, 3]).right_shift(1) == P([2, 3])
    assert P([1, 2, 3]).truncate(4) == P([1, 2, 3])
    assert P([1, 2, 3]).truncate(2) == P([1, 2])


def test_arb_acb_polys_shift() -> None:
    for P in flint.acb_poly, flint.arb_poly:
        assert P([1, 2, 3]).left_shift(3) == P([0, 0, 0, 1, 2, 3])
        assert P([1, 2, 3]).right_shift(1) == P([2, 3])
        assert P([1, 2, 3]).truncate(4) == P([1, 2, 3])
        assert P([1, 2, 3]).truncate(2) == P([1, 2])

@remyoudompheng
Copy link
Contributor Author

Sure, they are now added
However I observe that arb_poly and acb_poly have no comparison methods (which may be intentional since they do not represent exact values). They are currently not covered at all in test_all.py so I chose to keep it that way and simply include the doctest part.

@oscarbenjamin
Copy link
Collaborator

they are now added

Thanks

They are currently not covered at all in test_all.py so I chose to keep it that way

Fair enough. Yes, they do need to be tested but I think as you say the awkwardness of the comparisons is probably why they are not.

@oscarbenjamin
Copy link
Collaborator

The linter cython-lint is complaining:

$ cython-lint src/
/home/runner/work/python-flint/python-flint/src/flint/types/arb_poly.pyx:351:5: E303 too many blank lines (2)
/home/runner/work/python-flint/python-flint/src/flint/types/acb_poly.pyx:353:5: E303 too many blank lines (2)

@oscarbenjamin
Copy link
Collaborator

Could you add this to release notes in the README here:

python-flint/README.md

Lines 162 to 180 in 81784a9

Next release (0.8.0)...
-----------------------
Contributors
- Oscar Benjamin (OB)
- Robert Dougherty-Bliss (RDB)
Changes
- [gh-300](https://github.com/flintlib/python-flint/pull/300), Fix `arb.repr`
which now returns a Python representation that round trips. (OB)
- [gh-289](https://github.com/flintlib/python-flint/pull/289),
Add `.prec` attribute to series types `fmpz_series`, `fmpq_series`,
`arb_series` and `acb_series`. (OB)
- [gh-274](https://github.com/flintlib/python-flint/pull/274),
Add resultant methods to `fmpz_poly`, `fmpq_poly` and
`nmod_poly`. Now all univariate and polynomial types have the
resultant method except for `fq_default_poly`. (RDB)

@remyoudompheng
Copy link
Contributor Author

It should be all good now.

@oscarbenjamin
Copy link
Collaborator

Looks good. Thanks!

@oscarbenjamin oscarbenjamin merged commit c8713a9 into flintlib:main Aug 27, 2025
80 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants