Skip to content

Modular arithmetic in terms of ideals #2729

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

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

Taneb
Copy link
Member

@Taneb Taneb commented Jun 7, 2025

Opening this PR to share my WIP. I've got a messy proof of the Chinese remainder theorem for arbitrary rings, but in porting it from my standalone library to this I've somehow made some parameters not infer properly

@Taneb Taneb force-pushed the modular-arithmetic branch from 8617e07 to 94cefa6 Compare June 8, 2025 11:04
Copy link
Contributor

@JacquesCarette JacquesCarette left a comment

Choose a reason for hiding this comment

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

The new Kernel file looks nice.

@JacquesCarette
Copy link
Contributor

Would you want some help to get this further along?

@Taneb
Copy link
Member Author

Taneb commented Jul 30, 2025

Yes, actually. I've been working on a module for the special case of ideals of the ring of integers, and I've been struggling to prove that (for a non-zero modulus) it's finite, which I think it important for the "yes this is modular arithmetic as you know it" feel. I'll post a WIP commit shortly

@JacquesCarette
Copy link
Contributor

Ok, once my students make further progress on the ones they are currently working on, I'll get them to look at this.

@jamesmckinna
Copy link
Contributor

And, ... having murdered my darlings #2257 #2292 I should turn my attention to helping with this!

Comment on lines +89 to +93
_≋?_ : Decidable _≋_
-- need to check whether m is 0
_≋?_ with ℕ.nonZero? ∣ m ∣
... | yes p = _≋?′_ {{p}}
... | no ¬p = {!!}
Copy link
Contributor

Choose a reason for hiding this comment

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

My first thought on reading this code is that .{{_ : NonZero m}} should in fact also be part of the module parametrisation, and thus

  • the anonymous module _ .{{_ : NonZero m}} where can be removed
  • _≋?_ just is _≋?′_

Copy link
Contributor

@jamesmckinna jamesmckinna Aug 3, 2025

Choose a reason for hiding this comment

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

My second thought is that, for general Rings:

  • arithmetic mod 0 does make sense; quotienting by the zero ideal R/(0) is isomorphic to R?
  • arithmetic mod 1 also makes sense; R/(1) is the trivial Ring

In either case, for sure the equality on the quotient would be decidable, but perhaps requires that we analyse these three cases separately:

  • m = 0
  • m = 1
  • NonTrivial m (and that might involve defining that notion for on the model of NonZero?).

So the question is really: do you/we want to consider these special cases for ℤ/mℤ, or would it be 'better' to qualify the module with .{{_ : NonTrivial m}} and infer {{NonZero m}} where needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure why we need to treat the m = 1 case specially. It's not a particularly interesting case, but it should work the same as any other nonzero modulus

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough, but the path to

_≋?_ with ℕ.nonZero? ∣ m ∣
... | yes p = _≋?′_ {{p}}
... | no ¬p = {!!}

is then via _≟_ : DecidableEquality ℤ having first shown R/(0) iso to R for any R : Ring _ _?
(And that ¬p implies m ≡ 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.

Yes, that was my plan

@jamesmckinna
Copy link
Contributor

jamesmckinna commented Aug 3, 2025

Some errors thrown up by checking with agda-v2.8.0 (beyond the failing tests above):

  • Data.Fin.Properties on this branch still has the now-erroneous --warn=noUserWarning which should be fixed after a rebase/merge with the current master?
  • Data.Integer.Properties now triggers a warning about a null rewrite step on L1417 (which I hadn't seen caught anywhere else? but the offending line doesn't appear any more on master, so...)

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