feat: add LawfulBEq class

This commit is contained in:
Leonardo de Moura 2022-02-25 13:35:08 -08:00
parent 3b130ee42f
commit b8bed6fb5c
3 changed files with 40 additions and 0 deletions

View file

@ -176,6 +176,24 @@ theorem optParam_eq (α : Sort u) (default : α) : optParam α default = α := r
infix:50 " != " => bne
class LawfulBEq (α : Type u) [BEq α] : Prop where
eq_of_beq : (a b : α) → (a == b) = true → a = b
theorem eq_of_beq [BEq α] [LawfulBEq α] {a b : α} (h : (a == b) = true) : a = b :=
LawfulBEq.eq_of_beq a b h
instance : LawfulBEq Bool where
eq_of_beq a b h := by cases a <;> cases b <;> first | rfl | contradiction
instance : LawfulBEq Nat where
eq_of_beq _ _ h := of_decide_eq_true h
instance : LawfulBEq Char where
eq_of_beq _ _ h := of_decide_eq_true h
instance : LawfulBEq String where
eq_of_beq _ _ h := of_decide_eq_true h
/- Logical connectives an equality -/
def implies (a b : Prop) := a → b

View file

@ -472,4 +472,16 @@ def minimum? [LE α] [DecidableRel (@LE.le α _)] : List α → Option α
| [] => none
| a::as => some <| as.foldl min a
instance [BEq α] [LawfulBEq α] : LawfulBEq (List α) where
eq_of_beq as bs := by
induction as generalizing bs with
| nil => intro h; cases bs <;> first | rfl | contradiction
| cons a as ih =>
cases bs with
| nil => intro h; contradiction
| cons b bs =>
simp [BEq.beq, List.beq]
intro ⟨h₁, h₂⟩
exact ⟨eq_of_beq h₁, ih _ h₂⟩
end List

10
src/Init/Data/Prod.lean Normal file
View file

@ -0,0 +1,10 @@
/-
Copyright (c) 2022 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
prelude
import Init.SimpLemmas
instance [BEq α] [BEq β] [LawfulBEq α] [LawfulBEq β] : LawfulBEq (α × β) where
eq_of_beq a b h := by cases a; cases b; simp [BEq.beq] at h; have ⟨h₁, h₂⟩ := h; rw [eq_of_beq h₁, eq_of_beq h₂]