Debian Codegraph @

test-suite/failure/subtyping2.v

raw
1 (* Check that no constraints on inductive types disappear at subtyping *)
2
3 Module Type S.
4
5 Record A0 : Type := (* Type_i' *)
6 i0 {X0 : Type; R0 : X0 -> X0 -> Prop}. (* X0: Type_j' *)
7
8 Parameter i0' : forall X0 : Type, (X0 -> X0 -> Prop) -> A0.
9
10 End S.
11
12 Module M.
13
14 Record A0 : Type := (* Type_i' *)
15 i0 {X0 : Type; R0 : X0 -> X0 -> Prop}. (* X0: Type_j' *)
16
17 Definition i0' := i0 : forall X0 : Type, (X0 -> X0 -> Prop) -> A0.
18
19 End M.
20
21 (* The rest of this file formalizes Burali-Forti paradox *)
22 (* (if the constraint between i0' and A0 is lost, the proof goes through) *)
23
24 Inductive ACC (A : Type) (R : A -> A -> Prop) : A -> Prop :=
25 ACC_intro :
26 forall x : A, (forall y : A, R y x -> ACC A R y) -> ACC A R x.
27
28 Lemma ACC_nonreflexive :
29 forall (A : Type) (R : A -> A -> Prop) (x : A),
30 ACC A R x -> R x x -> False.
31 simple induction 1; intros.
32 exact (H1 x0 H2 H2).
33 Qed.
34
35 Definition WF (A : Type) (R : A -> A -> Prop) := forall x : A, ACC A R x.
36
37
38 Section Inverse_Image.
39
40 Variables (A B : Type) (R : B -> B -> Prop) (f : A -> B).
41
42 Definition Rof (x y : A) : Prop := R (f x) (f y).
43
44 Remark ACC_lemma :
45 forall y : B, ACC B R y -> forall x : A, y = f x -> ACC A Rof x.
46 simple induction 1; intros.
47 constructor; intros.
48 apply (H1 (f y0)); trivial.
49 elim H2 using eq_ind_r; trivial.
50 Qed.
51
52 Lemma ACC_inverse_image : forall x : A, ACC B R (f x) -> ACC A Rof x.
53 intros; apply (ACC_lemma (f x)); trivial.
54 Qed.
55
56 Lemma WF_inverse_image : WF B R -> WF A Rof.
57 red; intros; apply ACC_inverse_image; auto.
58 Qed.
59
60 End Inverse_Image.
61
62 Section Burali_Forti_Paradox.
63
64 Definition morphism (A : Type) (R : A -> A -> Prop)
65 (B : Type) (S : B -> B -> Prop) (f : A -> B) :=
66 forall x y : A, R x y -> S (f x) (f y).
67
68 (* The hypothesis of the paradox:
69 assumes there exists an universal system of notations, i.e:
70 - A type A0
71 - An injection i0 from relations on any type into A0
72 - The proof that i0 is injective modulo morphism
73 *)
74 Variable A0 : Type. (* Type_i *)
75 Variable i0 : forall X : Type, (X -> X -> Prop) -> A0. (* X: Type_j *)
76 Hypothesis
77 inj :
78 forall (X1 : Type) (R1 : X1 -> X1 -> Prop) (X2 : Type)
79 (R2 : X2 -> X2 -> Prop),
80 i0 X1 R1 = i0 X2 R2 -> exists f : X1 -> X2, morphism X1 R1 X2 R2 f.
81
82 (* Embedding of x in y: x and y are images of 2 well founded relations
83 R1 and R2, the ordinal of R2 being strictly greater than that of R1.
84 *)
85 Record emb (x y : A0) : Prop :=
86 {X1 : Type;
87 R1 : X1 -> X1 -> Prop;
88 eqx : x = i0 X1 R1;
89 X2 : Type;
90 R2 : X2 -> X2 -> Prop;
91 eqy : y = i0 X2 R2;
92 W2 : WF X2 R2;
93 f : X1 -> X2;
94 fmorph : morphism X1 R1 X2 R2 f;
95 maj : X2;
96 majf : forall z : X1, R2 (f z) maj}.
97
98
99 Lemma emb_trans : forall x y z : A0, emb x y -> emb y z -> emb x z.
100 intros.
101 case H; intros.
102 case H0; intros.
103 generalize eqx0; clear eqx0.
104 elim eqy using eq_ind_r; intro.
105 case (inj _ _ _ _ eqx0); intros.
106 exists X1 R1 X3 R3 (fun x : X1 => f0 (x0 (f x))) maj0; trivial.
107 red; auto.
108 Defined.
109
110
111 Lemma ACC_emb :
112 forall (X : Type) (R : X -> X -> Prop) (x : X),
113 ACC X R x ->
114 forall (Y : Type) (S : Y -> Y -> Prop) (f : Y -> X),
115 morphism Y S X R f -> (forall y : Y, R (f y) x) -> ACC A0 emb (i0 Y S).
116 simple induction 1; intros.
117 constructor; intros.
118 case H4; intros.
119 elim eqx using eq_ind_r.
120 case (inj X2 R2 Y S).
121 apply sym_eq; assumption.
122
123 intros.
124 apply H1 with (y := f (x1 maj)) (f := fun x : X1 => f (x1 (f0 x)));
125 try red; auto.
126 Defined.
127
128 (* The embedding relation is well founded *)
129 Lemma WF_emb : WF A0 emb.
130 constructor; intros.
131 case H; intros.
132 elim eqx using eq_ind_r.
133 apply ACC_emb with (X := X2) (R := R2) (x := maj) (f := f); trivial.
134 Defined.
135
136
137 (* The following definition enforces Type_j >= Type_i *)
138 Definition Omega : A0 := i0 A0 emb.
139
140
141 Section Subsets.
142
143 Variable a : A0.
144
145 (* We define the type of elements of A0 smaller than a w.r.t embedding.
146 The Record is in Type, but it is possible to avoid such structure. *)
147 Record sub : Type := {witness : A0; emb_wit : emb witness a}.
148
149 (* F is its image through i0 *)
150 Definition F : A0 := i0 sub (Rof _ _ emb witness).
151
152 (* F is embedded in Omega:
153 - the witness projection is a morphism
154 - a is an upper bound because emb_wit proves that witness is
155 smaller than a.
156 *)
157 Lemma F_emb_Omega : emb F Omega.
158 exists sub (Rof _ _ emb witness) A0 emb witness a; trivial.
159 exact WF_emb.
160
161 red; trivial.
162
163 exact emb_wit.
164 Defined.
165
166 End Subsets.
167
168
169 Definition fsub (a b : A0) (H : emb a b) (x : sub a) :
170 sub b := Build_sub _ (witness _ x) (emb_trans _ _ _ (emb_wit _ x) H).
171
172 (* F is a morphism: a < b => F(a) < F(b)
173 - the morphism from F(a) to F(b) is fsub above
174 - the upper bound is a, which is in F(b) since a < b
175 *)
176 Lemma F_morphism : morphism A0 emb A0 emb F.
177 red; intros.
178 exists
179 (sub x)
180 (Rof _ _ emb (witness x))
181 (sub y)
182 (Rof _ _ emb (witness y))
183 (fsub x y H)
184 (Build_sub _ x H); trivial.
185 apply WF_inverse_image.
186 exact WF_emb.
187
188 unfold morphism, Rof, fsub; simpl; intros.
189 trivial.
190
191 unfold Rof, fsub; simpl; intros.
192 apply emb_wit.
193 Defined.
194
195
196 (* Omega is embedded in itself:
197 - F is a morphism
198 - Omega is an upper bound of the image of F
199 *)
200 Lemma Omega_refl : emb Omega Omega.
201 exists A0 emb A0 emb F Omega; trivial.
202 exact WF_emb.
203
204 exact F_morphism.
205
206 exact F_emb_Omega.
207 Defined.
208
209 (* The paradox is that Omega cannot be embedded in itself, since
210 the embedding relation is well founded.
211 *)
212 Theorem Burali_Forti : False.
213 apply ACC_nonreflexive with A0 emb Omega.
214 apply WF_emb.
215
216 exact Omega_refl.
217
218 Defined.
219
220 End Burali_Forti_Paradox.
221
222 Import M.
223
224 (* Note: this proof uses a large elimination of A0. *)
225 Lemma inj :
226 forall (X1 : Type) (R1 : X1 -> X1 -> Prop) (X2 : Type)
227 (R2 : X2 -> X2 -> Prop),
228 i0' X1 R1 = i0' X2 R2 -> exists f : X1 -> X2, morphism X1 R1 X2 R2 f.
229 intros.
230 change
231 match i0' X1 R1, i0' X2 R2 with
232 | i0 x1 r1, i0 x2 r2 => exists f : _, morphism x1 r1 x2 r2 f
233 end.
234 case H; simpl.
235 exists (fun x : X1 => x).
236 red; trivial.
237 Defined.
238
239 (* The following command raises 'Error: Universe Inconsistency'.
240 To allow large elimination of A0, i0 must not be a large constructor.
241 Hence, the constraint Type_j' < Type_i' is added, which is incompatible
242 with the constraint j >= i in the paradox.
243 *)
244
245 Fail Definition Paradox : False := Burali_Forti A0 i0' inj.