agda-stdlib icon indicating copy to clipboard operation
agda-stdlib copied to clipboard

Create a version of [m+kn]%n≡m%n for integers

Open Taneb opened this issue 2 months ago • 2 comments

Working on modular arithmetic, to prove that the setoid of integers modulo m (for nonzero m), I find myself looking for something like [a+kn]%n≡a%n : ∀ a k n .{{_ : NonZero n}} → (a + k * n) % n ≡ a % n in Data.Integer.DivMod. I've found this difficult to prove myself.

Taneb avatar Nov 14 '25 08:11 Taneb

Having looked at something similar, it seems to be a horrid case analysis on k. I wonder if it might be easier to redefine _%ℕ_ and _/ℕ_ on integers to delegate to the naturals via the signed representation instead of the current versions? (Which seem to recapitulate/inline the signAbs view construction?) #2878

jamesmckinna avatar Nov 14 '25 09:11 jamesmckinna

I'm pretty sure Conor and I have code for this somewhere. A direct proof is horrible. There's a proof via symmetric difference and a worker helper that does a rather complex recursion that is not horrid. [Coming up with that worker, that's pure Conor genius.] There are things quite close here. Hmm, it might be we had something even closer in a previous version (we're obsessive refactorers).

JacquesCarette avatar Nov 18 '25 02:11 JacquesCarette