Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make comparisons is_one, and is_zero consistent for polys #168

Merged
merged 1 commit into from
Jul 22, 2024

Conversation

oscarbenjamin
Copy link
Collaborator

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.

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 als with nmod. The
change here makes it so that nmod_poly can compare equal with anything
that can be coerced by the nmod constructor.

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

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

Currently fmpz_mod has both is_one and is_zero but 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.

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.
@oscarbenjamin oscarbenjamin merged commit 2e4b0ab into flintlib:master Jul 22, 2024
30 checks passed
@oscarbenjamin oscarbenjamin deleted the pr_comparisons branch July 22, 2024 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant