Skip to content

Commit

Permalink
move theorems to Nat/Bitwise
Browse files Browse the repository at this point in the history
  • Loading branch information
pitmonticone committed Oct 20, 2024
1 parent ad80154 commit 94e9c33
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
16 changes: 0 additions & 16 deletions Mathlib/Algebra/Group/Nat.lean
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,6 @@ lemma not_even_iff : ¬ Even n ↔ n % 2 = 1 := by rw [even_iff, mod_two_ne_zero

@[parity_simps] lemma even_add_one : Even (n + 1) ↔ ¬Even n := by simp [even_add]

@[simp]
theorem xor_mod_two_eq : (m ^^^ n) % 2 = (m + n) % 2 := by
by_cases h : (m + n) % 2 = 0
· simp only [h, mod_two_eq_zero_iff_testBit_zero, testBit_zero, xor_mod_two_eq_one, decide_not,
Bool.decide_iff_dist, Bool.not_eq_false', beq_iff_eq, decide_eq_decide]
omega
· simp only [mod_two_ne_zero] at h
simp [h]
omega

@[simp]
theorem even_xor : Even (m ^^^ n) ↔ (Even m ↔ Even n) := by
simp only [even_iff, xor_mod_two_eq]
simp only [← even_iff]
exact even_add

lemma succ_mod_two_eq_zero_iff {m : ℕ} : (m + 1) % 2 = 0 ↔ m % 2 = 1 := by
simp [← Nat.even_iff, ← Nat.not_even_iff, parity_simps]

Expand Down
17 changes: 16 additions & 1 deletion Mathlib/Data/Nat/Bitwise.lean
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ should be connected.
bitwise, and, or, xor
-/


open Function

namespace Nat
Expand Down Expand Up @@ -354,6 +353,22 @@ theorem lt_xor_cases {a b c : ℕ} (h : a < b ^^^ c) : a ^^^ c < b ∨ a ^^^ b <
obtain ha | hb | hc := xor_trichotomy <| Nat.xor_assoc _ _ _ ▸ xor_ne_zero.2 h.ne
exacts [(h.asymm ha).elim, Or.inl <| Nat.xor_comm _ _ ▸ hb, Or.inr hc]

@[simp]
theorem xor_mod_two_eq {m n : ℕ} : (m ^^^ n) % 2 = (m + n) % 2 := by
by_cases h : (m + n) % 2 = 0
· simp only [h, mod_two_eq_zero_iff_testBit_zero, testBit_zero, xor_mod_two_eq_one, decide_not,
Bool.decide_iff_dist, Bool.not_eq_false', beq_iff_eq, decide_eq_decide]
omega
· simp only [mod_two_ne_zero] at h
simp only [h, xor_mod_two_eq_one]
omega

@[simp]
theorem even_xor {m n : ℕ} : Even (m ^^^ n) ↔ (Even m ↔ Even n) := by
simp only [even_iff, xor_mod_two_eq]
simp only [← even_iff]
exact even_add

@[simp] theorem bit_lt_two_pow_succ_iff {b x n} : bit b x < 2 ^ (n + 1) ↔ x < 2 ^ n := by
cases b <;> simp <;> omega

Expand Down

0 comments on commit 94e9c33

Please sign in to comment.