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

Mod(14,20) == Mod(39,55) evaluates to True #39372

Open
2 tasks done
maxale opened this issue Jan 23, 2025 · 7 comments
Open
2 tasks done

Mod(14,20) == Mod(39,55) evaluates to True #39372

maxale opened this issue Jan 23, 2025 · 7 comments
Labels

Comments

@maxale
Copy link
Contributor

maxale commented Jan 23, 2025

Steps To Reproduce

sage: Mod(14,20) == Mod(39,55)
True

Expected Behavior

Mod(14,20) and Mod(39,55) are different residue classes, and furthermore neither one is a subset of another. PARI/GP also claims that they are not the same:

? Mod(14,20) == Mod(39,55)
%1 = 0

Actual Behavior

The claimed equality does not make sense.

Additional Information

No response

Environment

  • OS: Ubuntu 24.04.1 LTS
  • Sage Version: 10.6.beta1

Checklist

  • I have searched the existing issues for a bug report that matches the one I want to file, without success.
  • I have read the documentation and troubleshoot guide
@maxale maxale added the t: bug label Jan 23, 2025
@AdityaK1729
Copy link

AdityaK1729 commented Jan 24, 2025

I tried playing around with this, and I have concluded that while comparing the 2 residual classes with totally separate groups, it takes the gcd, and if both the number are same modulo the gcd it returns true (except when gcd is 1), for example

sage: # gcd=140, and 209mod140=69=69mod140
sage: mod(69,420)==mod(209,350)
True
sage: # gcd=1, so it goes false
sage: mod(3,26)==mod(3,27)
False
sage: # any other similar expression not satisfying above constraints is automatically false
sage: mod(29,26)==mod(101,65)
False

@user202729
Copy link
Contributor

user202729 commented Jan 24, 2025

This… "technically" is a consequence of our coercion framework.

  • There's a natural coercion from ℤ to ℤ/mℤ for all m ∈ ℤ⁺.
  • There's a natural coercion from ℤ/(mn)ℤ to ℤ/nℤ for all m, n ∈ ℤ⁺.
  • Common parent is looked for while comparing elements.

It looks like this is needed to handle cases like ℚ[x] → 𝔸[x] and 𝔸 → 𝔸[x], allowing ℚ[x](1) == 𝔸(1).

We also have things like

sage: ZZ(3)==Mod(0, 1)==ZZ(5)
True

I don't see a good way out of this. If you want you can explicitly check parent(a)==parent(b) and a==b.

@AdityaK1729
Copy link

If so, This seems not too hard to fix, can I try fixing it

@user202729
Copy link
Contributor

If so, This seems not too hard to fix, can I try fixing it

Can you justify why this special case is special enough to require fixing despite it violates general behavior of the coercion framework as I pointed out above?

@AdityaK1729
Copy link

No, I meant to say I can apply the last line solution you mentioned, sorry for being not clear

@user202729
Copy link
Contributor

I mean the user can explicitly check for same-parent when they check for equality if they want.

But making SageMath's == checking for same-parent would break everything.

@maxale
Copy link
Contributor Author

maxale commented Jan 24, 2025

After checking with PARI/GP developers on how they treat Mod(14,20) == Mod(39,55), Karim Belabas said that it was a bug evaluating it to 0, which has been fixed in the current development version. So, now in PARI/GP we have:

? Mod(14,20) == Mod(39,55)
%1 = 1

which is consistent with the current Sage's behavior. I'm still not sure it's best route to take though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants