flintlib / python-flint

Python bindings for Flint and Arb
MIT License
131 stars 25 forks source link

Make comparisons is_one, and is_zero consistent for polys #168

Closed oscarbenjamin closed 2 months ago

oscarbenjamin commented 2 months ago

nmod_poly previously compared unequal to an integer e.g.

  >>> nmod_poly([1], 3) == 1
  False

This was inconsistent with all other poly types and also with nmod. The change here makes it so that nmod_poly can compare equal with anything that can be coerced by the nmod constructor.

We currently have:

  >>> nmod(1, 3) == fmpz(1)
  False

  >>> nmod(1, 3) == 1
  True

So an exception is made here for int but comparison with fmpz is not allowed. The change here does the same thing for nmod_poly. It will compare unequal to fmpz_poly but will compare equal to an int or an nmod with the same modulus.

Also renamed all __nonzero__ methods to __bool__ (Python 3 vs 2)

Also added is_one and is_zero to almost all *_poly and *_mpoly types because this was inconsistent before.

The two poly types that I didn't add is_one and is_zero to are arb_poly and acb_poly. I was unsure what the expected behaviour there should be...

Currently fmpz_mod has both is_one and is_zero but all other scalar types do not. I'm not sure whether it makes sense to add them just for overall consistency. No matrix types have is_zero or is_one although there are corresponding Flint functions for this.