| 1 |
(* -*- mode: coq; coq-prog-args: ("-noinit" "-indices-matter" "-w" "-notation-overridden,-deprecated-option") -*- *) |
| 2 |
(* |
| 3 |
The Coq Proof Assistant, version 8.7.1 (January 2018) |
| 4 |
compiled on Jan 21 2018 15:02:24 with OCaml 4.06.0 |
| 5 |
from commit 391bb5e196901a3a9426295125b8d1c700ab6992 |
| 6 |
*) |
| 7 |
|
| 8 |
|
| 9 |
Require Export Corelib.Init.Notations. |
| 10 |
Require Export Corelib.Init.Ltac. |
| 11 |
Notation "'∏' x .. y , P" := (forall x, .. (forall y, P) ..) |
| 12 |
(at level 200, x binder, y binder, right associativity) : type_scope. |
| 13 |
Notation "'λ' x .. y , t" := (fun x => .. (fun y => t) ..) |
| 14 |
(at level 200, x binder, y binder, right associativity). |
| 15 |
Notation "A -> B" := (forall (_ : A), B) : type_scope. |
| 16 |
Reserved Notation "p @ q" (at level 60, right associativity). |
| 17 |
Reserved Notation "! p " (at level 50). |
| 18 |
|
| 19 |
Monomorphic Universe uu. |
| 20 |
Monomorphic Universe uu0. |
| 21 |
Monomorphic Universe uu1. |
| 22 |
Constraint uu0 < uu1. |
| 23 |
|
| 24 |
Global Set Universe Polymorphism. |
| 25 |
Global Set Polymorphic Inductive Cumulativity. |
| 26 |
Global Unset Universe Minimization ToSet. |
| 27 |
|
| 28 |
Notation UU := Type (only parsing). |
| 29 |
Notation UU0 := Type@{uu0} (only parsing). |
| 30 |
|
| 31 |
Global Set Printing Universes. |
| 32 |
|
| 33 |
Inductive unit : UU0 := tt : unit. |
| 34 |
|
| 35 |
Inductive paths@{i} {A:Type@{i}} (a:A) : A -> Type@{i} := idpath : paths a a. |
| 36 |
#[export] Hint Resolve idpath : core . |
| 37 |
Notation "a = b" := (paths a b) (at level 70, no associativity) : type_scope. |
| 38 |
|
| 39 |
Set Primitive Projections. |
| 40 |
Set Nonrecursive Elimination Schemes. |
| 41 |
|
| 42 |
Record total2@{i} { T: Type@{i} } ( P: T -> Type@{i} ) : Type@{i} |
| 43 |
:= tpair { pr1 : T; pr2 : P pr1 }. |
| 44 |
|
| 45 |
Arguments tpair {_} _ _ _. |
| 46 |
Arguments pr1 {_ _} _. |
| 47 |
Arguments pr2 {_ _} _. |
| 48 |
|
| 49 |
Notation "'∑' x .. y , P" := (total2 (λ x, .. (total2 (λ y, P)) ..)) |
| 50 |
(at level 200, x binder, y binder, right associativity) : type_scope. |
| 51 |
|
| 52 |
Definition foo (X:Type) (xy : @total2 X (λ _, X)) : X. |
| 53 |
induction xy as [x y]. |
| 54 |
exact x. |
| 55 |
Defined. |
| 56 |
|
| 57 |
Definition idfun (T : UU) := λ t:T, t. |
| 58 |
|
| 59 |
Definition pathscomp0 {X : UU} {a b c : X} (e1 : a = b) (e2 : b = c) : a = c. |
| 60 |
Proof. |
| 61 |
intros. induction e1. exact e2. |
| 62 |
Defined. |
| 63 |
|
| 64 |
#[export] Hint Resolve @pathscomp0 : pathshints. |
| 65 |
|
| 66 |
Notation "p @ q" := (pathscomp0 p q). |
| 67 |
|
| 68 |
Definition pathsinv0 {X : UU} {a b : X} (e : a = b) : b = a. |
| 69 |
Proof. |
| 70 |
intros. induction e. exact (idpath _). |
| 71 |
Defined. |
| 72 |
|
| 73 |
Notation "! p " := (pathsinv0 p). |
| 74 |
|
| 75 |
Definition maponpaths {T1 T2 : UU} (f : T1 -> T2) {t1 t2 : T1} |
| 76 |
(e: t1 = t2) : f t1 = f t2. |
| 77 |
Proof. |
| 78 |
intros. induction e. exact (idpath _). |
| 79 |
Defined. |
| 80 |
|
| 81 |
Definition map_on_two_paths {X Y Z : UU} (f : X -> Y -> Z) {x x' y y'} (ex : x = x') (ey: y = y') : |
| 82 |
f x y = f x' y'. |
| 83 |
Proof. |
| 84 |
intros. induction ex. induction ey. exact (idpath _). |
| 85 |
Defined. |
| 86 |
|
| 87 |
|
| 88 |
Definition maponpathscomp0 {X Y : UU} {x1 x2 x3 : X} |
| 89 |
(f : X -> Y) (e1 : x1 = x2) (e2 : x2 = x3) : |
| 90 |
maponpaths f (e1 @ e2) = maponpaths f e1 @ maponpaths f e2. |
| 91 |
Proof. |
| 92 |
intros. induction e1. induction e2. exact (idpath _). |
| 93 |
Defined. |
| 94 |
|
| 95 |
Definition maponpathsinv0 {X Y : UU} (f : X -> Y) |
| 96 |
{x1 x2 : X} (e : x1 = x2) : maponpaths f (! e) = ! (maponpaths f e). |
| 97 |
Proof. |
| 98 |
intros. induction e. exact (idpath _). |
| 99 |
Defined. |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
Definition constr1 {X : UU} (P : X -> UU) {x x' : X} (e : x = x') : |
| 104 |
∑ (f : P x -> P x'), |
| 105 |
∑ (ee : ∏ p : P x, tpair _ x p = tpair _ x' (f p)), |
| 106 |
∏ (pp : P x), maponpaths pr1 (ee pp) = e. |
| 107 |
Proof. |
| 108 |
intros. induction e. |
| 109 |
split with (idfun (P x)). |
| 110 |
split with (λ p, idpath _). |
| 111 |
unfold maponpaths. simpl. |
| 112 |
intro. exact (idpath _). |
| 113 |
Defined. |
| 114 |
|
| 115 |
Definition transportf@{i} {X : Type@{i}} (P : X -> Type@{i}) {x x' : X} |
| 116 |
(e : x = x') : P x -> P x' := pr1 (constr1 P e). |
| 117 |
|
| 118 |
Lemma two_arg_paths_f@{i} {A : Type@{i}} {B : A -> Type@{i}} {C:Type@{i}} {f : ∏ a, B a -> C} {a1 b1 a2 b2} |
| 119 |
(p : a1 = a2) (q : transportf B p b1 = b2) : f a1 b1 = f a2 b2. |
| 120 |
Proof. |
| 121 |
intros. induction p. induction q. exact (idpath _). |
| 122 |
Defined. |
| 123 |
|
| 124 |
Definition iscontr@{i} (T:Type@{i}) : Type@{i} := ∑ cntr:T, ∏ t:T, t=cntr. |
| 125 |
|
| 126 |
Lemma proofirrelevancecontr {X : UU} (is : iscontr X) (x x' : X) : x = x'. |
| 127 |
Proof. |
| 128 |
intros. |
| 129 |
induction is as [y fe]. |
| 130 |
exact (fe x @ !(fe x')). |
| 131 |
Defined. |
| 132 |
|
| 133 |
|
| 134 |
Definition hfiber@{i} {X Y : Type@{i}} (f : X -> Y) (y : Y) : Type@{i} := total2 (λ x, f x = y). |
| 135 |
|
| 136 |
Definition hfiberpair {X Y : UU} (f : X -> Y) {y : Y} |
| 137 |
(x : X) (e : f x = y) : hfiber f y := |
| 138 |
tpair _ x e. |
| 139 |
|
| 140 |
Definition coconustot (T : UU) (t : T) := ∑ t' : T, t' = t. |
| 141 |
|
| 142 |
Definition coconustotpair (T : UU) {t t' : T} (e: t' = t) : coconustot T t |
| 143 |
:= tpair _ t' e. |
| 144 |
|
| 145 |
Lemma connectedcoconustot {T : UU} {t : T} (c1 c2 : coconustot T t) : c1 = c2. |
| 146 |
Proof. |
| 147 |
intros. |
| 148 |
induction c1 as [x0 x]. |
| 149 |
induction x. |
| 150 |
induction c2 as [x1 y]. |
| 151 |
induction y. |
| 152 |
exact (idpath _). |
| 153 |
Defined. |
| 154 |
|
| 155 |
Definition isweq@{i} {X Y : Type@{i}} (f : X -> Y) : Type@{i} := |
| 156 |
∏ y : Y, iscontr (hfiber f y). |
| 157 |
|
| 158 |
Lemma isProofIrrelevantUnit : ∏ x x' : unit, x = x'. |
| 159 |
Proof. |
| 160 |
intros. induction x. induction x'. exact (idpath _). |
| 161 |
Defined. |
| 162 |
|
| 163 |
Lemma unitl0 : tt = tt -> coconustot _ tt. |
| 164 |
Proof. |
| 165 |
intros e. exact (coconustotpair unit e). |
| 166 |
Defined. |
| 167 |
|
| 168 |
Lemma unitl1: coconustot _ tt -> tt = tt. |
| 169 |
Proof. |
| 170 |
intro cp. induction cp as [x t]. induction x. exact t. |
| 171 |
Defined. |
| 172 |
|
| 173 |
Lemma unitl2: ∏ e : tt = tt, unitl1 (unitl0 e) = e. |
| 174 |
Proof. |
| 175 |
intros. unfold unitl0. simpl. exact (idpath _). |
| 176 |
Defined. |
| 177 |
|
| 178 |
Lemma unitl3: ∏ e : tt = tt, e = idpath tt. |
| 179 |
Proof. |
| 180 |
intros. |
| 181 |
|
| 182 |
assert (e0 : unitl0 (idpath tt) = unitl0 e). |
| 183 |
{ simple refine (connectedcoconustot _ _). } |
| 184 |
|
| 185 |
set (e1 := maponpaths unitl1 e0). |
| 186 |
|
| 187 |
exact (! (unitl2 e) @ (! e1) @ (unitl2 (idpath _))). |
| 188 |
Defined. |
| 189 |
|
| 190 |
Theorem iscontrpathsinunit (x x' : unit) : iscontr (x = x'). |
| 191 |
Proof. |
| 192 |
intros. |
| 193 |
split with (isProofIrrelevantUnit x x'). |
| 194 |
intros e'. |
| 195 |
induction x. |
| 196 |
induction x'. |
| 197 |
simpl. |
| 198 |
apply unitl3. |
| 199 |
Qed. |
| 200 |
|
| 201 |
Lemma ifcontrthenunitl0 (e1 e2 : tt = tt) : e1 = e2. |
| 202 |
Proof. |
| 203 |
intros. |
| 204 |
simple refine (proofirrelevancecontr _ _ _). |
| 205 |
exact (iscontrpathsinunit tt tt). |
| 206 |
Qed. |
| 207 |
|
| 208 |
Section isweqcontrtounit. |
| 209 |
|
| 210 |
Universe i. |
| 211 |
|
| 212 |
(* To see the bug, run it both with and without this constraint: *) |
| 213 |
|
| 214 |
(* Constraint uu0 < i. *) |
| 215 |
|
| 216 |
(* Without this constraint, we get i = uu0 in the next definition *) |
| 217 |
Lemma isweqcontrtounit@{} {T : Type@{i}} (is : iscontr@{i} T) : isweq@{i} (λ _:T, tt). |
| 218 |
Proof. |
| 219 |
intros. intro y. induction y. |
| 220 |
induction is as [c h]. |
| 221 |
split with (hfiberpair@{i i i} _ c (idpath tt)). |
| 222 |
intros ha. |
| 223 |
induction ha as [x e]. |
| 224 |
simple refine (two_arg_paths_f (h x) _). |
| 225 |
simple refine (ifcontrthenunitl0 _ _). |
| 226 |
Defined. |
| 227 |
|
| 228 |
(* |
| 229 |
Explanation of the bug: |
| 230 |
|
| 231 |
With the constraint uu0 < i above we get: |
| 232 |
|
| 233 |
|= uu0 <= bug.3 |
| 234 |
uu0 <= i |
| 235 |
uu1 <= i |
| 236 |
i <= bug.3 |
| 237 |
|
| 238 |
from this print statement: *) |
| 239 |
|
| 240 |
Print isweqcontrtounit. |
| 241 |
|
| 242 |
(* |
| 243 |
|
| 244 |
Without the constraint uu0 < i above we get: |
| 245 |
|
| 246 |
|= i <= bug.3 |
| 247 |
uu0 = i |
| 248 |
|
| 249 |
Since uu0 = i is not inferred when we impose the constraint uu0 < i, |
| 250 |
it is invalid to infer it when we don't. |
| 251 |
|
| 252 |
*) |
| 253 |
|
| 254 |
Context (X : Type@{uu1}). |
| 255 |
|
| 256 |
Check (@isweqcontrtounit X). (* detect a universe inconsistency *) |
| 257 |
|
| 258 |
End isweqcontrtounit. |