Skip to content

Commit

Permalink
feat(data/nat/basic): add lemmas about nat.bit_cases_on (#14481)
Browse files Browse the repository at this point in the history
Also drop `nat.bit_cases` (was the same definition with a different
order of arguments).
  • Loading branch information
urkud committed Jun 2, 2022
1 parent ade30c3 commit 1a1895c
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/data/nat/basic.lean
Expand Up @@ -1526,10 +1526,29 @@ by { convert bit1_lt_bit0_iff, refl, }
lemma pos_of_bit0_pos {n : ℕ} (h : 0 < bit0 n) : 0 < n :=
by { cases n, cases h, apply succ_pos, }

/-- Define a function on `ℕ` depending on parity of the argument. -/
@[elab_as_eliminator]
def bit_cases {C : ℕ → Sort u} (H : Π b n, C (bit b n)) (n : ℕ) : C n :=
eq.rec_on n.bit_decomp (H (bodd n) (div2 n))
@[simp] lemma bit_cases_on_bit {C : ℕ → Sort u} (H : Π b n, C (bit b n)) (b : bool) (n : ℕ) :
bit_cases_on (bit b n) H = H b n :=
eq_of_heq $ (eq_rec_heq _ _).trans $ by rw [bodd_bit, div2_bit]

@[simp] lemma bit_cases_on_bit0 {C : ℕ → Sort u} (H : Π b n, C (bit b n)) (n : ℕ) :
bit_cases_on (bit0 n) H = H ff n :=
bit_cases_on_bit H ff n

@[simp] lemma bit_cases_on_bit1 {C : ℕ → Sort u} (H : Π b n, C (bit b n)) (n : ℕ) :
bit_cases_on (bit1 n) H = H tt n :=
bit_cases_on_bit H tt n

lemma bit_cases_on_injective {C : ℕ → Sort u} :
function.injective (λ H : Π b n, C (bit b n), λ n, bit_cases_on n H) :=
begin
intros H₁ H₂ h,
ext b n,
simpa only [bit_cases_on_bit] using congr_fun h (bit b n)
end

@[simp] lemma bit_cases_on_inj {C : ℕ → Sort u} (H₁ H₂ : Π b n, C (bit b n)) :
(λ n, bit_cases_on n H₁) = (λ n, bit_cases_on n H₂) ↔ H₁ = H₂ :=
bit_cases_on_injective.eq_iff

/-! ### decidability of predicates -/

Expand Down

0 comments on commit 1a1895c

Please sign in to comment.