| 1 |
Set Implicit Arguments. |
| 2 |
Set Universe Polymorphism. |
| 3 |
|
| 4 |
Require Export Notations. |
| 5 |
Require Import Ltac. |
| 6 |
|
| 7 |
Notation "A -> B" := (forall (_ : A), B) : type_scope. |
| 8 |
|
| 9 |
|
| 10 |
Inductive True : Prop := |
| 11 |
I : True. |
| 12 |
|
| 13 |
Register True as core.True.type. |
| 14 |
Register I as core.True.I. |
| 15 |
|
| 16 |
Inductive False : Prop :=. |
| 17 |
|
| 18 |
Register False as core.False.type. |
| 19 |
|
| 20 |
(** [not A], written [~A], is the negation of [A] *) |
| 21 |
Definition not (A:Prop) := A -> False. |
| 22 |
|
| 23 |
Notation "~ x" := (not x) : type_scope. |
| 24 |
|
| 25 |
Register not as core.not.type. |
| 26 |
|
| 27 |
Polymorphic Inductive eq@{s s';u v|} (A:Type@{s;u}) (x:A) : A -> Type@{s';v} := |
| 28 |
eq_refl : x = x :>A |
| 29 |
|
| 30 |
where "x = y :> A" := (@eq A x y) : type_scope. |
| 31 |
|
| 32 |
Arguments eq {A} x _. |
| 33 |
Arguments eq_refl {A x} , [A] x. |
| 34 |
|
| 35 |
Polymorphic Definition eq_elim@{s s' ; u v w |} [A:Type@{s;u}] [x:A] |
| 36 |
(P : forall a : A, x = a :> A -> Type@{s';w}) : |
| 37 |
P x (eq_refl@{s s';u v} x) -> forall [a : A] (e : x = a :> A), P a e := |
| 38 |
fun t _ e => match e with eq_refl => t end. |
| 39 |
|
| 40 |
Polymorphic Definition eq_ind@{s ; u|} [A] [x] P := @eq_elim@{s Prop;u Set Set} A x (fun a _ => P a). |
| 41 |
|
| 42 |
Polymorphic Definition eq_singleton@{s s' ; u v|} [A:Type@{s;u}] [x:A] |
| 43 |
(P : forall a : A, (eq@{s Prop;u Set} x a) -> Type@{s';v}) : |
| 44 |
P x (eq_refl x) -> forall [a : A] (e : x = a :> A), P a e := |
| 45 |
fun t _ e => match e with eq_refl => t end. |
| 46 |
|
| 47 |
Definition eq_rect@{u v|} [A:Type@{u}] [x:A] |
| 48 |
(P : forall a : A, Type@{v}) : |
| 49 |
P x -> forall [a : A] (e : x = a :> A), P a := @eq_singleton A x (fun a _ => P a). |
| 50 |
|
| 51 |
Definition eq_rec@{u|} [A:Type@{u}] [x:A] |
| 52 |
(P : forall a : A, Set) : |
| 53 |
P x -> forall [a : A] (e : x = a :> A), P a := @eq_singleton A x (fun a _ => P a). |
| 54 |
|
| 55 |
Definition eq_sind [A:Set] [x:A] |
| 56 |
(P : forall a : A, SProp) : |
| 57 |
P x -> forall [a : A] (e : x = a :> A), P a := @eq_singleton A x (fun a _ => P a). |
| 58 |
|
| 59 |
Arguments eq_ind [A] x P _ y _ : rename. |
| 60 |
Arguments eq_sind [A] x P _ y _ : rename. |
| 61 |
Arguments eq_rec [A] x P _ y _ : rename. |
| 62 |
Arguments eq_rect [A] x P _ y _ : rename. |
| 63 |
|
| 64 |
Notation "x = y" := (eq@{_ Prop;_ Set} x y) : type_scope. |
| 65 |
Notation "x <> y :> T" := (~ x = y :>T) : type_scope. |
| 66 |
Notation "x <> y" := (~ (x = y)) : type_scope. |
| 67 |
|
| 68 |
#[global] |
| 69 |
Hint Resolve eq_refl: core. |
| 70 |
|
| 71 |
Register eq as core.eq.type. |
| 72 |
Register eq_refl as core.eq.refl. |
| 73 |
Register eq_ind as core.eq.ind. |
| 74 |
Register eq_rect as core.eq.rect. |
| 75 |
Register eq_elim as core.eq.rect. |
| 76 |
|
| 77 |
Register Scheme eq_ind as ind_nodep for eq. |
| 78 |
|
| 79 |
Section equality. |
| 80 |
|
| 81 |
Theorem eq_sym@{s;u|} (A : Type@{s;u}) (x y : A) : x = y -> y = x. |
| 82 |
Proof. |
| 83 |
destruct 1; trivial. |
| 84 |
Defined. |
| 85 |
|
| 86 |
Register eq_sym as core.eq.sym. |
| 87 |
|
| 88 |
Theorem eq_trans@{s;u|} (A : Type@{s;u}) (x y z : A) : x = y -> y = z -> x = z. |
| 89 |
Proof. |
| 90 |
destruct 2; trivial. |
| 91 |
Defined. |
| 92 |
|
| 93 |
Register eq_trans as core.eq.trans. |
| 94 |
|
| 95 |
Theorem f_equal@{s s';u v|} (A : Type@{s;u}) (B : Type@{s';v}) |
| 96 |
(x y : A) (f : A -> B) : x = y -> f x = f y. |
| 97 |
Proof. |
| 98 |
destruct 1; trivial. |
| 99 |
Defined. |
| 100 |
|
| 101 |
Register f_equal as core.eq.congr. |
| 102 |
|
| 103 |
End equality. |
| 104 |
|
| 105 |
Definition eq_Has_Leibniz_elim@{s s'; l l' l''} : Has_Leibniz@{s s' s' ; l l' l''} (@eq@{s s' ; l l'}) := |
| 106 |
fun A x P t y e => match e with eq_refl => t end. |
| 107 |
|
| 108 |
Hint Resolve eq_Has_Leibniz_elim : rewrite_instances. |
| 109 |
|
| 110 |
Inductive comparison : Set := |
| 111 |
| Eq : comparison |
| 112 |
| Lt : comparison |
| 113 |
| Gt : comparison. |
| 114 |
|
| 115 |
Register comparison as core.comparison.type. |
| 116 |
Register Eq as core.comparison.Eq. |
| 117 |
Register Lt as core.comparison.Lt. |
| 118 |
Register Gt as core.comparison.Gt. |
| 119 |
|
| 120 |
Inductive CompareSpecT (Peq Plt Pgt : Prop) : comparison -> Type := |
| 121 |
| CompEqT : Peq -> CompareSpecT Peq Plt Pgt Eq |
| 122 |
| CompLtT : Plt -> CompareSpecT Peq Plt Pgt Lt |
| 123 |
| CompGtT : Pgt -> CompareSpecT Peq Plt Pgt Gt. |
| 124 |
#[global] |
| 125 |
Hint Constructors CompareSpecT : core. |
| 126 |
|
| 127 |
Register CompareSpecT as core.CompareSpecT.type. |
| 128 |
Register CompEqT as core.CompareSpecT.CompEqT. |
| 129 |
Register CompLtT as core.CompareSpecT.CompLtT. |
| 130 |
Register CompGtT as core.CompareSpecT.CompGtT. |
| 131 |
|
| 132 |
Inductive CompareSpec (Peq Plt Pgt : Prop) : comparison -> Prop := |
| 133 |
| CompEq : Peq -> CompareSpec Peq Plt Pgt Eq |
| 134 |
| CompLt : Plt -> CompareSpec Peq Plt Pgt Lt |
| 135 |
| CompGt : Pgt -> CompareSpec Peq Plt Pgt Gt. |
| 136 |
#[global] |
| 137 |
Hint Constructors CompareSpec : core. |
| 138 |
|
| 139 |
Register CompareSpec as core.CompareSpec.type. |
| 140 |
Register CompEq as core.CompareSpec.CompEq. |
| 141 |
Register CompLt as core.CompareSpec.CompLt. |
| 142 |
Register CompGt as core.CompareSpec.CompGt. |
| 143 |
|
| 144 |
Lemma CompareSpec2Type Peq Plt Pgt c : |
| 145 |
CompareSpec Peq Plt Pgt c -> CompareSpecT Peq Plt Pgt c. |
| 146 |
Proof. |
| 147 |
destruct c; intros H; constructor; inversion_clear H; auto. |
| 148 |
Qed. |