Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit bb2b58e

Browse files
committed
feat(data/{nat,int}/parity): add division lemmas (#11570)
Add lemmas of the form `even n → n / 2 * 2 = n` and `odd n → n / 2 * 2 + 1 = n`
1 parent 6e016d2 commit bb2b58e

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/data/int/parity.lean

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,22 @@ begin
220220
norm_num },
221221
end
222222

223+
lemma two_mul_div_two_of_even : even n → 2 * (n / 2) = n := int.mul_div_cancel'
224+
225+
lemma div_two_mul_two_of_even : even n → n / 2 * 2 = n := int.div_mul_cancel
226+
227+
lemma two_mul_div_two_add_one_of_odd : odd n → 2 * (n / 2) + 1 = n :=
228+
by { rintro ⟨c, rfl⟩, rw mul_comm, convert int.div_add_mod' _ _, simpa [int.add_mod] }
229+
230+
lemma div_two_mul_two_add_one_of_odd : odd n → n / 2 * 2 + 1 = n :=
231+
by { rintro ⟨c, rfl⟩, convert int.div_add_mod' _ _, simpa [int.add_mod] }
232+
233+
lemma add_one_div_two_mul_two_of_odd : odd n → 1 + n / 2 * 2 = n :=
234+
by { rintro ⟨c, rfl⟩, rw add_comm, convert int.div_add_mod' _ _, simpa [int.add_mod] }
235+
236+
lemma two_mul_div_two_of_odd (h : odd n) : 2 * (n / 2) = n - 1 :=
237+
eq_sub_of_add_eq (two_mul_div_two_add_one_of_odd h)
238+
223239
-- Here are examples of how `parity_simps` can be used with `int`.
224240

225241
example (m n : ℤ) (h : even m) : ¬ even (n + 3) ↔ even (m^2 + m + n) :=

src/data/nat/parity.lean

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,19 @@ by { rintro ⟨c, rfl⟩, simp [pow_mul] }
235235
theorem neg_one_pow_of_odd : odd n → (-1 : R) ^ n = -1 :=
236236
by { rintro ⟨c, rfl⟩, simp [pow_add, pow_mul] }
237237

238+
lemma two_mul_div_two_of_even : even n → 2 * (n / 2) = n := nat.mul_div_cancel_left'
239+
240+
lemma div_two_mul_two_of_even : even n → n / 2 * 2 = n := nat.div_mul_cancel
241+
242+
lemma two_mul_div_two_add_one_of_odd (h : odd n) : 2 * (n / 2) + 1 = n :=
243+
by { rw mul_comm, convert nat.div_add_mod' n 2, rw odd_iff.mp h }
244+
245+
lemma div_two_mul_two_add_one_of_odd (h : odd n) : n / 2 * 2 + 1 = n :=
246+
by { convert nat.div_add_mod' n 2, rw odd_iff.mp h }
247+
248+
lemma one_add_div_two_mul_two_of_odd (h : odd n) : 1 + n / 2 * 2 = n :=
249+
by { rw add_comm, convert nat.div_add_mod' n 2, rw odd_iff.mp h }
250+
238251
-- Here are examples of how `parity_simps` can be used with `nat`.
239252

240253
example (m n : ℕ) (h : even m) : ¬ even (n + 3) ↔ even (m^2 + m + n) :=

0 commit comments

Comments
 (0)