Skip to content

Commit ce216b8

Browse files
committed
feat: add Int.emod_sub_emod and Int.sub_emod_emod
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
1 parent 2c87905 commit ce216b8

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/Init/Data/Int/DivModLemmas.lean

+7
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,13 @@ theorem mul_emod (a b n : Int) : (a * b) % n = (a % n) * (b % n) % n := by
534534
@[simp] theorem emod_emod (a b : Int) : (a % b) % b = a % b := by
535535
conv => rhs; rw [← emod_add_ediv a b, add_mul_emod_self_left]
536536

537+
@[simp] theorem emod_sub_emod (m n k : Int) : (m % n - k) % n = (m - k) % n :=
538+
Int.emod_add_emod m n (-k)
539+
540+
@[simp] theorem sub_emod_emod (m n k : Int) : (m - n % k) % k = (m - n) % k := by
541+
apply (emod_add_cancel_right (n % k)).mp
542+
rw [Int.sub_add_cancel, Int.add_emod_emod, Int.sub_add_cancel]
543+
537544
theorem sub_emod (a b n : Int) : (a - b) % n = (a % n - b % n) % n := by
538545
apply (emod_add_cancel_right b).mp
539546
rw [Int.sub_add_cancel, ← Int.add_emod_emod, Int.sub_add_cancel, emod_emod]

0 commit comments

Comments
 (0)