|
| 1 | +(* Borrowed from Stdlib.Logic.EqdepFacts *) |
| 2 | + |
| 3 | +Section Dependent_Equality. |
| 4 | + |
| 5 | +Variables (U : Type) (P : U -> Type). |
| 6 | + |
| 7 | +(** Dependent equality *) |
| 8 | + |
| 9 | +Inductive eq_dep (p : U) (x : P p) : forall q : U, P q -> Prop := |
| 10 | + eq_dep_intro : eq_dep p x p x. |
| 11 | +#[local] Hint Constructors eq_dep: core. |
| 12 | + |
| 13 | +Lemma eq_dep_sym (p q : U) (x : P p) (y : P q) : |
| 14 | + eq_dep p x q y -> eq_dep q y p x. |
| 15 | +Proof. destruct 1; auto. Qed. |
| 16 | + |
| 17 | +Scheme eq_indd := Induction for eq Sort Prop. |
| 18 | + |
| 19 | +Inductive eq_dep1 (p : U) (x : P p) (q : U) (y : P q) : Prop := |
| 20 | + eq_dep1_intro : forall h : q = p, x = eq_rect _ _ y _ h -> eq_dep1 p x q y. |
| 21 | + |
| 22 | +Lemma eq_dep_dep1 (p q : U) (x : P p) (y : P q) : |
| 23 | + eq_dep p x q y -> eq_dep1 p x q y. |
| 24 | +Proof. |
| 25 | +revert q x y; destruct 1. |
| 26 | +apply eq_dep1_intro with (eq_refl p). |
| 27 | +simpl; trivial. |
| 28 | +Qed. |
| 29 | + |
| 30 | +End Dependent_Equality. |
| 31 | + |
| 32 | +Arguments eq_dep [U P] p x q _. |
| 33 | +Arguments eq_dep1 [U P] p x q y. |
| 34 | + |
| 35 | +Section Equivalences. |
| 36 | + |
| 37 | +Variable U : Type. |
| 38 | + |
| 39 | +Definition Eq_rect_eq_on (p : U) (Q : U -> Type) (x : Q p) := |
| 40 | + forall (h : p = p), x = eq_rect p Q x p h. |
| 41 | +Definition Eq_rect_eq := forall p Q x, Eq_rect_eq_on p Q x. |
| 42 | + |
| 43 | +Definition Eq_dep_eq_on (P : U -> Type) (p : U) (x : P p) := |
| 44 | + forall (y : P p), eq_dep p x p y -> x = y. |
| 45 | +Definition Eq_dep_eq := forall P p x, Eq_dep_eq_on P p x. |
| 46 | + |
| 47 | +Definition UIP_on_ (x y : U) (p1 : x = y) := forall (p2 : x = y), p1 = p2. |
| 48 | +Definition UIP_ := forall x y p1, UIP_on_ x y p1. |
| 49 | + |
| 50 | +Definition Streicher_K_on_ (x : U) (P : x = x -> Prop) := |
| 51 | + P (eq_refl x) -> forall p : x = x, P p. |
| 52 | +Definition Streicher_K_ := forall x P, Streicher_K_on_ x P. |
| 53 | + |
| 54 | +Lemma eq_rect_eq_on__eq_dep1_eq_on (p : U) (P : U -> Type) (y : P p) : |
| 55 | + Eq_rect_eq_on p P y -> forall (x : P p), eq_dep1 p x p y -> x = y. |
| 56 | +Proof. |
| 57 | +intro eq_rect_eq. |
| 58 | +simple destruct 1; intro. |
| 59 | +rewrite <- eq_rect_eq; auto. |
| 60 | +Qed. |
| 61 | +Lemma eq_rect_eq__eq_dep1_eq : |
| 62 | + Eq_rect_eq -> forall (P:U->Type) (p:U) (x y:P p), eq_dep1 p x p y -> x = y. |
| 63 | +Proof. |
| 64 | +exact (fun eq_rect_eq P p y x => |
| 65 | + @eq_rect_eq_on__eq_dep1_eq_on p P x (eq_rect_eq p P x) y). |
| 66 | +Qed. |
| 67 | + |
| 68 | +Lemma eq_rect_eq_on__eq_dep_eq_on (p : U) (P : U -> Type) (x : P p) : |
| 69 | + Eq_rect_eq_on p P x -> Eq_dep_eq_on P p x. |
| 70 | +Proof. |
| 71 | +intros eq_rect_eq; red; intros y H. |
| 72 | +symmetry; apply (eq_rect_eq_on__eq_dep1_eq_on _ _ _ eq_rect_eq). |
| 73 | +apply eq_dep_sym in H; apply eq_dep_dep1; trivial. |
| 74 | +Qed. |
| 75 | +Lemma eq_rect_eq__eq_dep_eq : Eq_rect_eq -> Eq_dep_eq. |
| 76 | +Proof. |
| 77 | +exact (fun eq_rect_eq P p x y => |
| 78 | + @eq_rect_eq_on__eq_dep_eq_on p P x (eq_rect_eq p P x) y). |
| 79 | +Qed. |
| 80 | +Lemma eq_dep_eq_on__UIP_on (x y : U) (p1 : x = y) : |
| 81 | + Eq_dep_eq_on (fun y => x = y) x eq_refl -> UIP_on_ x y p1. |
| 82 | +Proof. |
| 83 | +intro eq_dep_eq; red. |
| 84 | +elim p1 using eq_indd. |
| 85 | +intros p2; apply eq_dep_eq. |
| 86 | +elim p2 using eq_indd. |
| 87 | +apply eq_dep_intro. |
| 88 | +Qed. |
| 89 | +Lemma eq_dep_eq__UIP : Eq_dep_eq -> UIP_. |
| 90 | +Proof. |
| 91 | +exact (fun eq_dep_eq x y p1 => |
| 92 | + @eq_dep_eq_on__UIP_on x y p1 (eq_dep_eq _ _ _)). |
| 93 | +Qed. |
| 94 | + |
| 95 | +Lemma Streicher_K_on__eq_rect_eq_on (p : U) (P : U -> Type) (x : P p) : |
| 96 | + Streicher_K_on_ p (fun h => x = eq_rect _ P x _ h) -> Eq_rect_eq_on p P x. |
| 97 | +Proof. |
| 98 | +intro Streicher_K; red; intros. |
| 99 | +apply Streicher_K. |
| 100 | +reflexivity. |
| 101 | +Qed. |
| 102 | +Lemma Streicher_K__eq_rect_eq : Streicher_K_ -> Eq_rect_eq. |
| 103 | +Proof. |
| 104 | +exact (fun Streicher_K p P x => |
| 105 | + @Streicher_K_on__eq_rect_eq_on p P x (Streicher_K p _)). |
| 106 | +Qed. |
| 107 | +End Equivalences. |
| 108 | + |
| 109 | +Arguments eq_dep U P p x q _ : clear implicits. |
| 110 | + |
| 111 | +Set Implicit Arguments. |
| 112 | + |
| 113 | +Section EqdepDec. |
| 114 | + |
| 115 | +Variable A : Type. |
| 116 | + |
| 117 | +Let comp (x y y' : A) (eq1 : x = y) (eq2 : x = y') : y = y' := |
| 118 | + eq_ind _ (fun a => a = y') eq2 _ eq1. |
| 119 | + |
| 120 | +Remark trans_sym_eq (x y : A) (u : x = y) : comp u u = eq_refl y. |
| 121 | +Proof. now case u. Qed. |
| 122 | + |
| 123 | +Variables (x : A) (eq_dec : forall y : A, x = y \/ x <> y). |
| 124 | + |
| 125 | +Let nu (y : A) (u : x = y) : x = y := |
| 126 | + match eq_dec y with |
| 127 | + | or_introl eqxy => eqxy |
| 128 | + | or_intror neqxy => False_ind _ (neqxy u) |
| 129 | + end. |
| 130 | + |
| 131 | +#[local] Lemma nu_constant (y:A) (u v:x = y) : nu u = nu v. |
| 132 | +Proof. |
| 133 | +unfold nu; destruct (eq_dec y) as [Heq|Hneq]; [reflexivity|]. |
| 134 | +now case Hneq. |
| 135 | +Qed. |
| 136 | + |
| 137 | +Let nu_inv (y : A) (v : x = y) : x = y := comp (nu (eq_refl x)) v. |
| 138 | + |
| 139 | +Remark nu_left_inv_on (y : A) (u : x = y) : nu_inv (nu u) = u. |
| 140 | +Proof. case u; unfold nu_inv; apply trans_sym_eq. Qed. |
| 141 | + |
| 142 | +Theorem eq_proofs_unicity_on (y : A) (p1 p2 : x = y) : p1 = p2. |
| 143 | +Proof. |
| 144 | +elim (nu_left_inv_on p1). |
| 145 | +elim (nu_left_inv_on p2). |
| 146 | +now elim nu_constant with y p1 p2. |
| 147 | +Qed. |
| 148 | + |
| 149 | +Theorem K_dec_on (P : x = x -> Prop) (H : P (eq_refl x)) (p : x = x) : P p. |
| 150 | +Proof. now elim eq_proofs_unicity_on with x (eq_refl x) p. Qed. |
| 151 | + |
| 152 | +End EqdepDec. |
| 153 | + |
| 154 | +Theorem K_dec A (eq_dec : forall x y : A, x = y \/ x <> y) (x : A) : |
| 155 | + forall P : x = x -> Prop, P (eq_refl x) -> forall p : x = x, P p. |
| 156 | +Proof. exact (@K_dec_on A x (eq_dec x)). Qed. |
| 157 | + |
| 158 | +Section Eq_dec. |
| 159 | + |
| 160 | +Variables (A : Type) (eq_dec : forall x y : A, {x = y} + {x <> y}). |
| 161 | + |
| 162 | +Theorem K_dec_type (x : A) (P : x = x -> Prop) (H : P (eq_refl x)) (p : x = x) : |
| 163 | + P p. |
| 164 | +Proof. |
| 165 | +elim p using K_dec; [|now trivial]. |
| 166 | +now intros x0 y; case (eq_dec x0 y); [left|right]. |
| 167 | +Qed. |
| 168 | + |
| 169 | +Theorem eq_rect_eq_dec : forall (p : A) (Q : A -> Type) (x : Q p) (h : p = p), |
| 170 | + x = eq_rect p Q x p h. |
| 171 | +Proof. exact (Streicher_K__eq_rect_eq A K_dec_type). Qed. |
| 172 | + |
| 173 | +Theorem eq_dep_eq_dec : forall (P : A->Type) (p : A) (x y : P p), |
| 174 | + eq_dep A P p x p y -> x = y. |
| 175 | +Proof. exact (eq_rect_eq__eq_dep_eq A eq_rect_eq_dec). Qed. |
| 176 | + |
| 177 | +End Eq_dec. |
0 commit comments