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

Add optimized is_trivial methods for zzModRing and ZZModRing #1949

Merged
merged 1 commit into from
Nov 26, 2024

Conversation

fingolfin
Copy link
Member

These checks compile down to just a few machine code instructions and zero allocations. Nice.

@@ -56,13 +56,15 @@ is_unit(a::zzModRingElem) = a.parent.n == 1 ? a.data == 0 : gcd(a.data, a.parent

modulus(R::zzModRing) = R.n

characteristic(R::zzModRing) = ZZRingElem(modulus(R))

is_trivial(a::zzModRing) = is_unit(modulus(a))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you use is_unit here but is_one in the other file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_unit is mathematically correct. here it gets optimized to just checking for one as the modulus is unsigned . for the ZZ case using isone is an optimization to save 1 or 2 machine instructions checking for -1

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok. thanks for the explanation

Copy link

codecov bot commented Nov 26, 2024

Codecov Report

Attention: Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 87.89%. Comparing base (73e3de8) to head (f8469c9).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/flint/fmpz_mod.jl 50.00% 1 Missing ⚠️
src/flint/nmod.jl 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1949      +/-   ##
==========================================
- Coverage   87.93%   87.89%   -0.05%     
==========================================
  Files          99       99              
  Lines       36402    36404       +2     
==========================================
- Hits        32010    31997      -13     
- Misses       4392     4407      +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -56,13 +56,15 @@ is_unit(a::ZZModRingElem) = a.parent.n == 1 ? iszero(a.data) : isone(gcd(a.data,

modulus(R::ZZModRing) = R.n

characteristic(R::ZZModRing) = modulus(R)

is_trivial(a::ZZModRing) = is_one(modulus(a)) # constructor ensures the modulus is > 0
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps this makes it clearer?

Suggested change
is_trivial(a::ZZModRing) = is_one(modulus(a)) # constructor ensures the modulus is > 0
is_trivial(a::ZZModRing) = is_one(modulus(a)) # this is correct because the constructor ensures the modulus is > 0

@thofma

This comment was marked as off-topic.

@thofma

This comment was marked as off-topic.

@fingolfin fingolfin merged commit fd3ff47 into master Nov 26, 2024
21 of 24 checks passed
@fingolfin fingolfin deleted the mh/trivial-residue-rings branch November 26, 2024 15:03
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.

3 participants