2014-06-30 18:44:47 +00:00
|
|
|
|
-- Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
|
-- Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
-- Author: Leonardo de Moura
|
2014-06-28 07:29:42 +00:00
|
|
|
|
definition Bool [inline] := Type.{0}
|
2014-06-16 22:50:27 +00:00
|
|
|
|
|
2014-06-28 07:29:42 +00:00
|
|
|
|
inductive false : Bool :=
|
|
|
|
|
-- No constructors
|
|
|
|
|
|
|
|
|
|
theorem false_elim (c : Bool) (H : false)
|
2014-06-28 20:57:36 +00:00
|
|
|
|
:= false_rec c H
|
2014-06-28 07:29:42 +00:00
|
|
|
|
|
|
|
|
|
inductive true : Bool :=
|
|
|
|
|
| trivial : true
|
|
|
|
|
|
|
|
|
|
definition not (a : Bool) := a → false
|
|
|
|
|
precedence `¬`:40
|
|
|
|
|
notation `¬` a := not a
|
|
|
|
|
|
2014-06-30 02:30:38 +00:00
|
|
|
|
notation `assume` binders `,` r:(scoped f, f) := r
|
|
|
|
|
notation `take` binders `,` r:(scoped f, f) := r
|
|
|
|
|
|
2014-06-28 07:29:42 +00:00
|
|
|
|
theorem not_intro {a : Bool} (H : a → false) : ¬ a
|
|
|
|
|
:= H
|
|
|
|
|
|
|
|
|
|
theorem not_elim {a : Bool} (H1 : ¬ a) (H2 : a) : false
|
|
|
|
|
:= H1 H2
|
|
|
|
|
|
|
|
|
|
theorem absurd {a : Bool} (H1 : a) (H2 : ¬ a) : false
|
|
|
|
|
:= H2 H1
|
|
|
|
|
|
|
|
|
|
theorem mt {a b : Bool} (H1 : a → b) (H2 : ¬ b) : ¬ a
|
2014-06-30 02:30:38 +00:00
|
|
|
|
:= assume Ha : a, absurd (H1 Ha) H2
|
2014-06-28 07:29:42 +00:00
|
|
|
|
|
|
|
|
|
theorem contrapos {a b : Bool} (H : a → b) : ¬ b → ¬ a
|
2014-06-30 02:30:38 +00:00
|
|
|
|
:= assume Hnb : ¬ b, mt H Hnb
|
2014-06-28 07:29:42 +00:00
|
|
|
|
|
|
|
|
|
theorem absurd_elim {a : Bool} (b : Bool) (H1 : a) (H2 : ¬ a) : b
|
|
|
|
|
:= false_elim b (absurd H1 H2)
|
|
|
|
|
|
|
|
|
|
inductive and (a b : Bool) : Bool :=
|
|
|
|
|
| and_intro : a → b → and a b
|
|
|
|
|
|
|
|
|
|
infixr `/\` 35 := and
|
|
|
|
|
infixr `∧` 35 := and
|
|
|
|
|
|
|
|
|
|
theorem and_elim_left {a b : Bool} (H : a ∧ b) : a
|
|
|
|
|
:= and_rec (λ a b, a) H
|
|
|
|
|
|
|
|
|
|
theorem and_elim_right {a b : Bool} (H : a ∧ b) : b
|
|
|
|
|
:= and_rec (λ a b, b) H
|
|
|
|
|
|
|
|
|
|
inductive or (a b : Bool) : Bool :=
|
|
|
|
|
| or_intro_left : a → or a b
|
|
|
|
|
| or_intro_right : b → or a b
|
|
|
|
|
|
|
|
|
|
infixr `\/` 30 := or
|
|
|
|
|
infixr `∨` 30 := or
|
|
|
|
|
|
|
|
|
|
theorem or_elim (a b c : Bool) (H1 : a ∨ b) (H2 : a → c) (H3 : b → c) : c
|
|
|
|
|
:= or_rec H2 H3 H1
|
|
|
|
|
|
|
|
|
|
inductive eq {A : Type} (a : A) : A → Bool :=
|
2014-06-28 22:33:56 +00:00
|
|
|
|
| refl : eq a a
|
2014-06-28 07:29:42 +00:00
|
|
|
|
|
|
|
|
|
infix `=` 50 := eq
|
|
|
|
|
|
|
|
|
|
theorem subst {A : Type} {a b : A} {P : A → Bool} (H1 : a = b) (H2 : P a) : P b
|
|
|
|
|
:= eq_rec H2 H1
|
|
|
|
|
|
|
|
|
|
theorem trans {A : Type} {a b c : A} (H1 : a = b) (H2 : b = c) : a = c
|
|
|
|
|
:= subst H2 H1
|
|
|
|
|
|
2014-06-30 21:35:33 +00:00
|
|
|
|
calc_subst subst
|
|
|
|
|
calc_refl refl
|
|
|
|
|
calc_trans trans
|
|
|
|
|
|
2014-06-28 07:29:42 +00:00
|
|
|
|
theorem symm {A : Type} {a b : A} (H : a = b) : b = a
|
|
|
|
|
:= subst H (refl a)
|
|
|
|
|
|
2014-06-30 19:00:47 +00:00
|
|
|
|
theorem congr1 {A : Type} {B : A → Type} {f g : Π x, B x} (H : f = g) (a : A) : f a = g a
|
2014-06-28 18:18:22 +00:00
|
|
|
|
:= subst H (refl (f a))
|
2014-06-28 07:29:42 +00:00
|
|
|
|
|
|
|
|
|
theorem congr2 {A B : Type} {a b : A} (f : A → B) (H : a = b) : f a = f b
|
|
|
|
|
:= subst H (refl (f a))
|
2014-06-30 02:30:38 +00:00
|
|
|
|
|
2014-06-30 19:00:47 +00:00
|
|
|
|
theorem equal_f {A : Type} {B : A → Type} {f g : Π x, B x} (H : f = g) : ∀ x, f x = g x
|
|
|
|
|
:= take x, congr1 H x
|
|
|
|
|
|
2014-06-30 05:56:38 +00:00
|
|
|
|
definition iff (a b : Bool) := (a → b) ∧ (b → a)
|
|
|
|
|
infix `↔` 50 := iff
|
|
|
|
|
|
|
|
|
|
theorem iff_intro {a b : Bool} (H1 : a → b) (H2 : b → a) : a ↔ b
|
|
|
|
|
:= and_intro H1 H2
|
|
|
|
|
|
|
|
|
|
theorem iff_elim {a b c : Bool} (H1 : (a → b) → (b → a) → c) (H2 : a ↔ b) : c
|
|
|
|
|
:= and_rec H1 H2
|
|
|
|
|
|
|
|
|
|
theorem iff_elim_left {a b : Bool} (H : a ↔ b) : a → b
|
|
|
|
|
:= iff_elim (assume H1 H2, H1) H
|
|
|
|
|
|
|
|
|
|
theorem iff_elim_right {a b : Bool} (H : a ↔ b) : b → a
|
|
|
|
|
:= iff_elim (assume H1 H2, H2) H
|
|
|
|
|
|
2014-06-30 07:29:42 +00:00
|
|
|
|
theorem iff_mp_left {a b : Bool} (H1 : a ↔ b) (H2 : a) : b
|
|
|
|
|
:= (iff_elim_left H1) H2
|
|
|
|
|
|
|
|
|
|
theorem iff_mp_right {a b : Bool} (H1 : a ↔ b) (H2 : b) : a
|
|
|
|
|
:= (iff_elim_right H1) H2
|
|
|
|
|
|
2014-06-30 02:30:38 +00:00
|
|
|
|
inductive Exists {A : Type} (P : A → Bool) : Bool :=
|
|
|
|
|
| exists_intro : ∀ (a : A), P a → Exists P
|
|
|
|
|
|
|
|
|
|
notation `∃` binders `,` r:(scoped P, Exists P) := r
|
|
|
|
|
|
|
|
|
|
theorem exists_elim {A : Type} {P : A → Bool} {B : Bool} (H1 : ∃ x : A, P x) (H2 : ∀ (a : A) (H : P a), B) : B
|
|
|
|
|
:= Exists_rec H2 H1
|
|
|
|
|
|
|
|
|
|
definition inhabited (A : Type) := ∃ x : A, true
|
|
|
|
|
|
|
|
|
|
theorem inhabited_intro {A : Type} (a : A) : inhabited A
|
|
|
|
|
:= exists_intro a trivial
|
|
|
|
|
|
|
|
|
|
theorem inhabited_elim {A : Type} {B : Bool} (H1 : inhabited A) (H2 : A → B) : B
|
|
|
|
|
:= exists_elim H1 (λ (a : A) (H : true), H2 a)
|
|
|
|
|
|
|
|
|
|
theorem inhabited_Bool : inhabited Bool
|
|
|
|
|
:= inhabited_intro true
|
|
|
|
|
|
|
|
|
|
theorem inhabited_fun (A : Type) {B : Type} (H : inhabited B) : inhabited (A → B)
|
|
|
|
|
:= inhabited_elim H (take (b : B), inhabited_intro (λ a : A, b))
|
2014-06-30 21:35:33 +00:00
|
|
|
|
|
|
|
|
|
definition cast {A B : Type} (H : A = B) (a : A) : B
|
|
|
|
|
:= eq_rec a H
|
|
|
|
|
|
|
|
|
|
theorem cast_refl {A : Type} (a : A) : cast (refl A) a = a
|
|
|
|
|
:= refl (cast (refl A) a)
|
|
|
|
|
|
|
|
|
|
theorem cast_eq {A : Type} (H : A = A) (a : A) : cast H a = a
|
|
|
|
|
:= calc cast H a = cast (refl A) a : refl (cast H a) -- by proof irrelevance
|
|
|
|
|
... = a : cast_refl a
|
|
|
|
|
|
|
|
|
|
definition heq {A B : Type} (a : A) (b : B) := ∃ H, cast H a = b
|
|
|
|
|
|
|
|
|
|
infixl `==` 50 := heq
|
|
|
|
|
|
|
|
|
|
theorem heq_type_eq {A B : Type} {a : A} {b : B} (H : a == b) : A = B
|
|
|
|
|
:= exists_elim H (λ H Hw, H)
|
|
|
|
|
|
|
|
|
|
theorem eq_to_heq {A : Type} {a b : A} (H : a = b) : a == b
|
|
|
|
|
:= exists_intro (refl A) (trans (cast_refl a) H)
|
|
|
|
|
|
|
|
|
|
theorem heq_to_eq {A : Type} {a b : A} (H : a == b) : a = b
|
|
|
|
|
:= exists_elim H (λ (H : A = A) (Hw : cast H a = b),
|
|
|
|
|
calc a = cast H a : symm (cast_eq H a)
|
|
|
|
|
... = b : Hw)
|
|
|
|
|
|
|
|
|
|
theorem heq_refl {A : Type} (a : A) : a == a
|
|
|
|
|
:= eq_to_heq (refl a)
|