Skip to content

Commit

Permalink
feat(Data/Nat/Bitwise): add simp lemmas (#17977)
Browse files Browse the repository at this point in the history
Co-authored-by: @Command-Master 

Upstreamed from the [EquationalTheories](https://github.com/teorth/equational_theories) project.
  • Loading branch information
pitmonticone committed Oct 21, 2024
1 parent a9827c1 commit 4f5e6c1
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 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,21 @@ 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]
omega

@[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 4f5e6c1

Please sign in to comment.