Skip to content

Commit

Permalink
feat: add Int.emod_sub_emod and Int.sub_emod_emod
Browse files Browse the repository at this point in the history
This PR adds the subtraction equivalents for `Int.emod_add_emod`
(`(a % n + b) % n = (a + b) % n`) and `Int.add_emod_emod`
(`(a + b % n) % n = (a + b) % n`). These are marked @[simp] like their
addition equivalents.

Discussed on Zulip in
https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/Adding.20some.20sub_emod.20lemmas.20to.20DivModLemmas
  • Loading branch information
vlad902 committed Jan 2, 2025
1 parent 2c87905 commit ce216b8
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Init/Data/Int/DivModLemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,13 @@ theorem mul_emod (a b n : Int) : (a * b) % n = (a % n) * (b % n) % n := by
@[simp] theorem emod_emod (a b : Int) : (a % b) % b = a % b := by
conv => rhs; rw [← emod_add_ediv a b, add_mul_emod_self_left]

@[simp] theorem emod_sub_emod (m n k : Int) : (m % n - k) % n = (m - k) % n :=
Int.emod_add_emod m n (-k)

@[simp] theorem sub_emod_emod (m n k : Int) : (m - n % k) % k = (m - n) % k := by
apply (emod_add_cancel_right (n % k)).mp
rw [Int.sub_add_cancel, Int.add_emod_emod, Int.sub_add_cancel]

theorem sub_emod (a b n : Int) : (a - b) % n = (a % n - b % n) % n := by
apply (emod_add_cancel_right b).mp
rw [Int.sub_add_cancel, ← Int.add_emod_emod, Int.sub_add_cancel, emod_emod]
Expand Down

0 comments on commit ce216b8

Please sign in to comment.