| 1 |
(* This is a proof of false which used to be accepted by Coq (Jan 12, 2014) due |
| 2 |
to a DeBruijn index error in the check for allowed elimination sorts. |
| 3 |
|
| 4 |
Proof by Maxime Dénès, using a proof of Hurkens' paradox by Hugo Herbelin to derive |
| 5 |
inconsistency. *) |
| 6 |
|
| 7 |
(* We start by adapting the proof of Hurkens' paradox by Hugo in |
| 8 |
theories/Logic/Hurkens.v, so that instead of requiring a retract |
| 9 |
from Type into Prop up to equality, we require it only up to |
| 10 |
equivalence. |
| 11 |
*) |
| 12 |
|
| 13 |
Section Hurkens. |
| 14 |
|
| 15 |
Definition Type2 := Type. |
| 16 |
Definition Type1 := Type : Type2. |
| 17 |
|
| 18 |
(** Assumption of a retract from Type into Prop *) |
| 19 |
|
| 20 |
Variable down : Type1 -> Prop. |
| 21 |
Variable up : Prop -> Type1. |
| 22 |
|
| 23 |
Hypothesis back : forall A, up (down A) -> A. |
| 24 |
|
| 25 |
Hypothesis forth : forall A, A -> up (down A). |
| 26 |
|
| 27 |
Hypothesis backforth : forall (A:Type) (P:A->Type) (a:A), |
| 28 |
P (back A (forth A a)) -> P a. |
| 29 |
|
| 30 |
Hypothesis backforth_r : forall (A:Type) (P:A->Type) (a:A), |
| 31 |
P a -> P (back A (forth A a)). |
| 32 |
|
| 33 |
(** Proof *) |
| 34 |
|
| 35 |
Definition V : Type1 := forall A:Prop, ((up A -> Prop) -> up A -> Prop) -> up A -> Prop. |
| 36 |
Definition U : Type1 := V -> Prop. |
| 37 |
|
| 38 |
Definition sb (z:V) : V := fun A r a => r (z A r) a. |
| 39 |
Definition le (i:U -> Prop) (x:U) : Prop := x (fun A r a => i (fun v => sb v A r a)). |
| 40 |
Definition le' (i:up (down U) -> Prop) (x:up (down U)) : Prop := le (fun a:U => i (forth _ a)) (back _ x). |
| 41 |
Definition induct (i:U -> Prop) : Type1 := forall x:U, up (le i x) -> up (i x). |
| 42 |
Definition WF : U := fun z => down (induct (fun a => z (down U) le' (forth _ a))). |
| 43 |
Definition I (x:U) : Prop := |
| 44 |
(forall i:U -> Prop, up (le i x) -> up (i (fun v => sb v (down U) le' (forth _ x)))) -> False. |
| 45 |
|
| 46 |
Lemma Omega : forall i:U -> Prop, induct i -> up (i WF). |
| 47 |
Proof. |
| 48 |
intros i y. |
| 49 |
apply y. |
| 50 |
unfold le, WF, induct. |
| 51 |
apply forth. |
| 52 |
intros x H0. |
| 53 |
apply y. |
| 54 |
unfold sb, le', le. |
| 55 |
compute. |
| 56 |
apply backforth_r. |
| 57 |
exact H0. |
| 58 |
Qed. |
| 59 |
|
| 60 |
Lemma lemma1 : induct (fun u => down (I u)). |
| 61 |
Proof. |
| 62 |
unfold induct. |
| 63 |
intros x p. |
| 64 |
apply forth. |
| 65 |
intro q. |
| 66 |
generalize (q (fun u => down (I u)) p). |
| 67 |
intro r. |
| 68 |
apply back in r. |
| 69 |
apply r. |
| 70 |
intros i j. |
| 71 |
unfold le, sb, le', le in j |-. |
| 72 |
apply backforth in j. |
| 73 |
specialize q with (i := fun y => i (fun v:V => sb v (down U) le' (forth _ y))). |
| 74 |
apply q. |
| 75 |
exact j. |
| 76 |
Qed. |
| 77 |
|
| 78 |
Lemma lemma2 : (forall i:U -> Prop, induct i -> up (i WF)) -> False. |
| 79 |
Proof. |
| 80 |
intro x. |
| 81 |
generalize (x (fun u => down (I u)) lemma1). |
| 82 |
intro r; apply back in r. |
| 83 |
apply r. |
| 84 |
intros i H0. |
| 85 |
apply (x (fun y => i (fun v => sb v (down U) le' (forth _ y)))). |
| 86 |
unfold le, WF in H0. |
| 87 |
apply back in H0. |
| 88 |
exact H0. |
| 89 |
Qed. |
| 90 |
|
| 91 |
Theorem paradox : False. |
| 92 |
Proof. |
| 93 |
exact (lemma2 Omega). |
| 94 |
Qed. |
| 95 |
|
| 96 |
End Hurkens. |
| 97 |
|
| 98 |
(* Alright, now we use a DeBruijn index off-by-1 error to build a type |
| 99 |
satisfying the hypotheses of the paradox. What is tricky is that the pretyper is |
| 100 |
not affected by the bug (only the kernel is). Even worse, since our goal is to |
| 101 |
bypass the elimination restriction for types in Prop, we have to devise a way to |
| 102 |
feed the kernel with an illegal pattern matching without going through the |
| 103 |
pattern matching compiler (which calls the pretyper). The trick is to use the |
| 104 |
record machinery, which defines projections, checking if the kernel accepts |
| 105 |
it. *) |
| 106 |
|
| 107 |
Definition informative (x : bool) := |
| 108 |
match x with |
| 109 |
| true => Type |
| 110 |
| false => Prop |
| 111 |
end. |
| 112 |
|
| 113 |
Definition depsort (T : Type) (x : bool) : informative x := |
| 114 |
match x with |
| 115 |
| true => T |
| 116 |
| false => True |
| 117 |
end. |
| 118 |
|
| 119 |
(* The let-bound parameters in the record below trigger the error *) |
| 120 |
|
| 121 |
Record Box (ff := false) (tt := true) (T : Type) : Prop := |
| 122 |
wrap {prop : depsort T tt}. |
| 123 |
|
| 124 |
Definition down (x : Type) : Prop := Box x. |
| 125 |
Definition up (x : Prop) : Type := x. |
| 126 |
|
| 127 |
Fail Definition back A : up (down A) -> A := prop A. |
| 128 |
|
| 129 |
(* If the projection has been defined, the following script derives a proof of |
| 130 |
false. |
| 131 |
|
| 132 |
Definition forth A : A -> up (down A) := wrap A. |
| 133 |
|
| 134 |
Definition backforth (A:Type) (P:A->Type) (a:A) : |
| 135 |
P (back A (forth A a)) -> P a := fun H => H. |
| 136 |
|
| 137 |
Definition backforth_r (A:Type) (P:A->Type) (a:A) : |
| 138 |
P a -> P (back A (forth A a)) := fun H => H. |
| 139 |
|
| 140 |
(* Everything set up, we just check that we built the right context for the |
| 141 |
paradox to apply. *) |
| 142 |
|
| 143 |
Theorem pandora : False. |
| 144 |
apply (paradox down up back forth backforth backforth_r). |
| 145 |
Qed. |
| 146 |
|
| 147 |
Print Assumptions pandora. |
| 148 |
|
| 149 |
*) |