1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 set "baseuri" "cic:/matita/Fsub/defn".
16 include "logic/equality.ma".
18 include "datatypes/bool.ma".
19 include "nat/compare.ma".
20 include "list/list.ma".
21 include "Fsub/util.ma".
23 (*** representation of Fsub types ***)
24 inductive Typ : Set \def
25 | TVar : nat \to Typ (* type var *)
26 | TFree: nat \to Typ (* free type name *)
27 | Top : Typ (* maximum type *)
28 | Arrow : Typ \to Typ \to Typ (* functions *)
29 | Forall : Typ \to Typ \to Typ. (* universal type *)
31 (*** representation of Fsub terms ***)
32 inductive Term : Set \def
33 | Var : nat \to Term (* variable *)
34 | Free : nat \to Term (* free name *)
35 | Abs : Typ \to Term \to Term (* abstraction *)
36 | App : Term \to Term \to Term (* function application *)
37 | TAbs : Typ \to Term \to Term (* type abstraction *)
38 | TApp : Term \to Typ \to Term. (* type application *)
40 (* representation of bounds *)
42 record bound : Set \def {
43 istype : bool; (* is subtyping bound? *)
44 name : nat ; (* name *)
45 btype : Typ (* type to which the name is bound *)
48 (* representation of Fsub typing environments *)
49 definition Env \def (list bound).
50 definition Empty \def (nil bound).
51 definition Cons \def \lambda G,X,T.((mk_bound false X T) :: G).
52 definition TCons \def \lambda G,X,T.((mk_bound true X T) :: G).
54 definition env_append : Env \to Env \to Env \def \lambda G,H.(H @ G).
56 (* notation "hvbox(\Forall S. break T)"
57 non associative with precedence 90
58 for @{ 'forall $S $T}.
76 notation "hvbox(s break \mapsto t)"
77 right associative with precedence 55
78 for @{ 'arrow $s $t }.
80 interpretation "universal type" 'forall S T = (cic:/matita/Fsub/defn/Typ.ind#xpointer(1/1/5) S T).
82 interpretation "bound var" 'var x = (cic:/matita/Fsub/defn/Typ.ind#xpointer(1/1/1) x).
84 interpretation "bound tvar" 'tvar x = (cic:/matita/Fsub/defn/Typ.ind#xpointer(1/1/3) x).
86 interpretation "bound tname" 'tname x = (cic:/matita/Fsub/defn/Typ.ind#xpointer(1/1/2) x).
88 interpretation "arrow type" 'arrow S T = (cic:/matita/Fsub/defn/Typ.ind#xpointer(1/1/4) S T). *)
90 (*** Various kinds of substitution, not all will be used probably ***)
92 (* substitutes i-th dangling index in type T with type U *)
93 let rec subst_type_nat T U i \def
95 [ (TVar n) \Rightarrow match (eqb n i) with
97 | false \Rightarrow T]
98 | (TFree X) \Rightarrow T
100 | (Arrow T1 T2) \Rightarrow (Arrow (subst_type_nat T1 U i) (subst_type_nat T2 U i))
101 | (Forall T1 T2) \Rightarrow (Forall (subst_type_nat T1 U i) (subst_type_nat T2 U (S i))) ].
103 (* substitutes 0-th dangling index in type T with type U *)
104 let rec subst_type_O T U \def subst_type_nat T U O.
106 (* substitutes 0-th dangling index in term t with term u *)
107 let rec subst_term_O t u \def
108 let rec aux t0 i \def
110 [ (Var n) \Rightarrow match (eqb n i) with
112 | false \Rightarrow t0]
113 | (Free X) \Rightarrow t0
114 | (Abs T1 t1) \Rightarrow (Abs T1 (aux t1 (S i)))
115 | (App t1 t2) \Rightarrow (App (aux t1 i) (aux t2 i))
116 | (TAbs T1 t1) \Rightarrow (TAbs T1 (aux t1 (S i)))
117 | (TApp t1 T1) \Rightarrow (TApp (aux t1 i) T1) ]
120 (* substitutes 0-th dangling index in term T, which shall be a TVar,
122 let rec subst_term_tO t T \def
123 let rec aux t0 i \def
125 [ (Var n) \Rightarrow t0
126 | (Free X) \Rightarrow t0
127 | (Abs T1 t1) \Rightarrow (Abs (subst_type_nat T1 T i) (aux t1 (S i)))
128 | (App t1 t2) \Rightarrow (App (aux t1 i) (aux t2 i))
129 | (TAbs T1 t1) \Rightarrow (TAbs (subst_type_nat T1 T i) (aux t1 (S i)))
130 | (TApp t1 T1) \Rightarrow (TApp (aux t1 i) (subst_type_nat T1 T i)) ]
133 (* substitutes (TFree X) in type T with type U *)
134 let rec subst_type_tfree_type T X U on T \def
136 [ (TVar n) \Rightarrow T
137 | (TFree Y) \Rightarrow match (eqb X Y) with
139 | false \Rightarrow T ]
141 | (Arrow T1 T2) \Rightarrow (Arrow (subst_type_tfree_type T1 X U)
142 (subst_type_tfree_type T2 X U))
143 | (Forall T1 T2) \Rightarrow (Forall (subst_type_tfree_type T1 X U)
144 (subst_type_tfree_type T2 X U)) ].
146 (*** height of T's syntactic tree ***)
150 [(TVar n) \Rightarrow (S O)
151 |(TFree X) \Rightarrow (S O)
152 |Top \Rightarrow (S O)
153 |(Arrow T1 T2) \Rightarrow (S (max (t_len T1) (t_len T2)))
154 |(Forall T1 T2) \Rightarrow (S (max (t_len T1) (t_len T2)))].
157 \lambda G:(list bound).match G with
158 [ nil \Rightarrow (mk_bound false O Top)
159 | (cons b H) \Rightarrow b].
161 definition head_nat \def
162 \lambda G:(list nat).match G with
164 | (cons n H) \Rightarrow n].
166 (*** definitions about lists ***)
168 (* var binding is in env judgement *)
169 definition var_bind_in_env : bound \to Env \to Prop \def
170 \lambda b,G.(in_list bound b G).
172 definition fv_env : (list bound) \to (list nat) \def
173 \lambda G.(map ? ? (\lambda b.match b with
174 [(mk_bound B X T) \Rightarrow X]) G).
176 (* variable is in env judgement *)
177 definition var_in_env : nat \to Env \to Prop \def
178 \lambda x,G.(in_list nat x (fv_env G)).
180 definition var_type_in_env : nat \to Env \to Prop \def
181 \lambda x,G.\exists T.(var_bind_in_env (mk_bound true x T) G).
183 let rec fv_type T \def
185 [(TVar n) \Rightarrow []
186 |(TFree x) \Rightarrow [x]
188 |(Arrow U V) \Rightarrow ((fv_type U) @ (fv_type V))
189 |(Forall U V) \Rightarrow ((fv_type U) @ (fv_type V))].
191 (*** Type Well-Formedness judgement ***)
193 inductive WFType : Env \to Typ \to Prop \def
194 | WFT_TFree : \forall X,G.(in_list ? X (fv_env G))
195 \to (WFType G (TFree X))
196 | WFT_Top : \forall G.(WFType G Top)
197 | WFT_Arrow : \forall G,T,U.(WFType G T) \to (WFType G U) \to
198 (WFType G (Arrow T U))
199 | WFT_Forall : \forall G,T,U.(WFType G T) \to
201 (\lnot (in_list ? X (fv_env G))) \to
202 (\lnot (in_list ? X (fv_type U))) \to
203 (WFType ((mk_bound true X T) :: G)
204 (subst_type_O U (TFree X)))) \to
205 (WFType G (Forall T U)).
207 (*** Environment Well-Formedness judgement ***)
209 inductive WFEnv : Env \to Prop \def
210 | WFE_Empty : (WFEnv Empty)
211 | WFE_cons : \forall B,X,T,G.(WFEnv G) \to
212 \lnot (in_list ? X (fv_env G)) \to
213 (WFType G T) \to (WFEnv ((mk_bound B X T) :: G)).
215 (*** Subtyping judgement ***)
216 inductive JSubtype : Env \to Typ \to Typ \to Prop \def
217 | SA_Top : \forall G:Env.\forall T:Typ.(WFEnv G) \to
218 (WFType G T) \to (JSubtype G T Top)
219 | SA_Refl_TVar : \forall G:Env.\forall X:nat.(WFEnv G) \to (var_in_env X G)
220 \to (JSubtype G (TFree X) (TFree X))
221 | SA_Trans_TVar : \forall G:Env.\forall X:nat.\forall T:Typ.
223 (var_bind_in_env (mk_bound true X U) G) \to
224 (JSubtype G U T) \to (JSubtype G (TFree X) T)
225 | SA_Arrow : \forall G:Env.\forall S1,S2,T1,T2:Typ.
226 (JSubtype G T1 S1) \to (JSubtype G S2 T2) \to
227 (JSubtype G (Arrow S1 S2) (Arrow T1 T2))
228 | SA_All : \forall G:Env.\forall S1,S2,T1,T2:Typ.
229 (JSubtype G T1 S1) \to
230 (\forall X:nat.\lnot (var_in_env X G) \to
231 (JSubtype ((mk_bound true X T1) :: G)
232 (subst_type_O S2 (TFree X)) (subst_type_O T2 (TFree X)))) \to
233 (JSubtype G (Forall S1 S2) (Forall T1 T2)).
236 notation < "hvbox(e break ⊢ ta \nbsp 'V' \nbsp tb (= \above \alpha))"
237 non associative with precedence 30 for @{ 'subjudg $e $ta $tb }.
238 notation > "hvbox(e break ⊢ ta 'Fall' break tb)"
239 non associative with precedence 30 for @{ 'subjudg $e $ta $tb }.
240 notation "hvbox(e break ⊢ ta \lessdot break tb)"
241 non associative with precedence 30 for @{ 'subjudg $e $ta $tb }.
242 interpretation "Fsub subtype judgement" 'subjudg e ta tb =
243 (cic:/matita/Fsub/defn/JSubtype.ind#xpointer(1/1) e ta tb).
245 lemma xx : \forall e,ta,tb. e \vdash ta Fall tb.
248 (*** Typing judgement ***)
249 inductive JType : Env \to Term \to Typ \to Prop \def
250 | T_Var : \forall G:Env.\forall x:nat.\forall T:Typ.
251 (WFEnv G) \to (var_bind_in_env (mk_bound false x T) G) \to
253 | T_Abs : \forall G.\forall T1,T2:Typ.\forall t2:Term.
255 (JType ((mk_bound false x T1)::G) (subst_term_O t2 (Free x)) T2) \to
256 (JType G (Abs T1 t2) (Arrow T1 T2))
257 | T_App : \forall G.\forall t1,t2:Term.\forall T2:Typ.
258 \forall T1:Typ.(JType G t1 (Arrow T1 T2)) \to (JType G t2 T1) \to
259 (JType G (App t1 t2) T2)
260 | T_TAbs : \forall G:Env.\forall T1,T2:Typ.\forall t2:Term.
262 (JType ((mk_bound true X T1)::G)
263 (subst_term_tO t2 (TFree X)) (subst_type_O T2 (TFree X)))
264 \to (JType G (TAbs T1 t2) (Forall T1 T2))
265 | T_TApp : \forall G:Env.\forall t1:Term.\forall T2,T12:Typ.
266 \forall X:nat.\forall T11:Typ.
267 (JType G t1 (Forall T11 (subst_type_tfree_type T12 X (TVar O)))) \to
269 \to (JType G (TApp t1 T2) (subst_type_tfree_type T12 X T2))
270 | T_Sub : \forall G:Env.\forall t:Term.\forall T:Typ.
271 \forall S:Typ.(JType G t S) \to (JSubtype G S T) \to (JType G t T).
273 (****** PROOFS ********)
275 lemma subst_O_nat : \forall T,U.((subst_type_O T U) = (subst_type_nat T U O)).
276 intros;elim T;simplify;reflexivity;
279 (*** theorems about lists ***)
281 (* FIXME: these definitions shouldn't be part of the poplmark challenge
282 - use destruct instead, when hopefully it will get fixed... *)
284 lemma inj_head : \forall h1,h2:bound.\forall t1,t2:Env.
285 ((h1::t1) = (h2::t2)) \to (h1 = h2).
287 lapply (eq_f ? ? head ? ? H).simplify in Hletin.assumption.
290 lemma inj_head_nat : \forall h1,h2:nat.\forall t1,t2:(list nat).
291 ((h1::t1) = (h2::t2)) \to (h1 = h2).
293 lapply (eq_f ? ? head_nat ? ? H).simplify in Hletin.assumption.
296 lemma inj_tail : \forall A.\forall h1,h2:A.\forall t1,t2:(list A).
297 ((h1::t1) = (h2::t2)) \to (t1 = t2).
298 intros.lapply (eq_f ? ? (tail ?) ? ? H).simplify in Hletin.assumption.
303 lemma boundinenv_natinfv : \forall x,G.
304 (\exists B,T.(in_list ? (mk_bound B x T) G)) \to
305 (in_list ? x (fv_env G)).
307 [elim H;elim H1;lapply (in_list_nil ? ? H2);elim Hletin
308 |elim H1;elim H2;inversion H3
309 [intros;rewrite < H4;simplify;apply in_Base
310 |intros;elim a3;simplify;apply in_Skip;
311 lapply (inj_tail ? ? ? ? ? H7);rewrite > Hletin in H;apply H;
316 |rewrite > H6;assumption]]]]
319 lemma nat_in_list_case : \forall G,H,n.(in_list nat n (H @ G)) \to
320 (in_list nat n G) \lor (in_list nat n H).
322 [simplify in H1;left;assumption
323 |simplify in H2;inversion H2
324 [intros;lapply (inj_head_nat ? ? ? ? H4);rewrite > Hletin;
326 |intros;lapply (inj_tail ? ? ? ? ? H6);rewrite < Hletin in H3;
327 rewrite > H5 in H1;lapply (H1 H3);elim Hletin1
328 [left;assumption|right;apply in_Skip;assumption]]]
331 lemma natinG_or_inH_to_natinGH : \forall G,H,n.
332 (in_list nat n G) \lor (in_list nat n H) \to
333 (in_list nat n (H @ G)).
337 |simplify;apply in_Skip;assumption]
338 |generalize in match H2;elim H2
339 [simplify;apply in_Base
340 |lapply (H4 H3);simplify;apply in_Skip;assumption]]
343 lemma natinfv_boundinenv : \forall x,G.(in_list ? x (fv_env G)) \to
344 \exists B,T.(in_list ? (mk_bound B x T) G).
346 [simplify;intro;lapply (in_list_nil ? ? H);elim Hletin
347 |intros 3;elim t;simplify in H1;inversion H1
348 [intros;rewrite < H2;simplify;apply ex_intro
352 |lapply (inj_head_nat ? ? ? ? H3);rewrite > H2;rewrite < Hletin;
354 |intros;lapply (inj_tail ? ? ? ? ? H5);rewrite < Hletin in H2;
355 rewrite < H4 in H2;lapply (H H2);elim Hletin1;elim H6;apply ex_intro
359 |apply in_Skip;rewrite < H4;assumption]]]]
362 theorem varinT_varinT_subst : \forall X,Y,T.
363 (in_list ? X (fv_type T)) \to \forall n.
364 (in_list ? X (fv_type (subst_type_nat T (TFree Y) n))).
366 [simplify in H;elim (in_list_nil ? ? H)
367 |simplify in H;simplify;assumption
368 |simplify in H;elim (in_list_nil ? ? H)
369 |simplify in H2;simplify;elim (nat_in_list_case ? ? ? H2);
370 apply natinG_or_inH_to_natinGH;
373 |simplify in H2;simplify;elim (nat_in_list_case ? ? ? H2);
374 apply natinG_or_inH_to_natinGH;
376 |right;apply (H H3)]]
379 lemma incl_bound_fv : \forall l1,l2.(incl ? l1 l2) \to
380 (incl ? (fv_env l1) (fv_env l2)).
381 intros.unfold in H.unfold.intros.apply boundinenv_natinfv.
382 lapply (natinfv_boundinenv ? ? H1).elim Hletin.elim H2.apply ex_intro
389 lemma incl_nat_cons : \forall x,l1,l2.
390 (incl nat l1 l2) \to (incl nat (x :: l1) (x :: l2)).
391 intros.unfold in H.unfold.intros.inversion H1
392 [intros;lapply (inj_head_nat ? ? ? ? H3);rewrite > Hletin;apply in_Base
393 |intros;apply in_Skip;apply H;lapply (inj_tail ? ? ? ? ? H5);rewrite > Hletin;
397 lemma WFT_env_incl : \forall G,T.(WFType G T) \to
398 \forall H.(incl ? (fv_env G) (fv_env H)) \to (WFType H T).
400 [apply WFT_TFree;unfold in H3;apply (H3 ? H1)
402 |apply WFT_Arrow [apply (H2 ? H6)|apply (H4 ? H6)]
406 [unfold;intro;apply H7;apply(H6 ? H9)
408 |simplify;apply (incl_nat_cons ? ? ? H6)]]]
411 lemma fv_env_extends : \forall H,x,B,C,T,U,G.
412 (fv_env (H @ ((mk_bound B x T) :: G))) =
413 (fv_env (H @ ((mk_bound C x U) :: G))).
415 [simplify;reflexivity
416 |elim t;simplify;rewrite > H1;reflexivity]
419 lemma lookup_env_extends : \forall G,H,B,C,D,T,U,V,x,y.
420 (in_list ? (mk_bound D y V) (H @ ((mk_bound C x U) :: G))) \to
422 (in_list ? (mk_bound D y V) (H @ ((mk_bound B x T) :: G))).
424 [simplify in H1;(*FIXME*)generalize in match H1;intro;inversion H1
425 [intros;lapply (inj_head ? ? ? ? H5);rewrite < H4 in Hletin;
426 destruct Hletin;absurd (y = x) [symmetry;assumption|assumption]
427 |intros;simplify;lapply (inj_tail ? ? ? ? ? H7);rewrite > Hletin;
428 apply in_Skip;assumption]
429 |(*FIXME*)generalize in match H2;intro;inversion H2
430 [intros;simplify in H6;lapply (inj_head ? ? ? ? H6);rewrite > Hletin;
431 simplify;apply in_Base
432 |simplify;intros;lapply (inj_tail ? ? ? ? ? H8);rewrite > Hletin in H1;
433 rewrite > H7 in H1;apply in_Skip;apply (H1 H5 H3)]]
436 lemma in_FV_subst : \forall x,T,U,n.(in_list ? x (fv_type T)) \to
437 (in_list ? x (fv_type (subst_type_nat T U n))).
439 [simplify in H;inversion H
440 [intros;lapply (sym_eq ? ? ? H2);absurd (a::l = [])
441 [assumption|apply nil_cons]
442 |intros;lapply (sym_eq ? ? ? H4);absurd (a1::l = [])
443 [assumption|apply nil_cons]]
444 |2,3:simplify;simplify in H;assumption
445 |*:simplify in H2;simplify;apply natinG_or_inH_to_natinGH;
446 lapply (nat_in_list_case ? ? ? H2);elim Hletin
447 [1,3:left;apply (H1 ? H3)
448 |*:right;apply (H ? H3)]]
451 (*** lemma on fresh names ***)
453 lemma fresh_name : \forall l:(list nat).\exists n.\lnot (in_list ? n l).
454 cut (\forall l:(list nat).\exists n.\forall m.
455 (n \leq m) \to \lnot (in_list ? m l))
456 [intros;lapply (Hcut l);elim Hletin;apply ex_intro
458 |apply H;constructor 1]
462 |intros;unfold;intro;inversion H1
463 [intros;lapply (sym_eq ? ? ? H3);absurd (a::l1 = [])
464 [assumption|apply nil_cons]
465 |intros;lapply (sym_eq ? ? ? H5);absurd (a1::l1 = [])
466 [assumption|apply nil_cons]]]
467 |elim H;lapply (decidable_eq_nat a t);elim Hletin
470 |intros;unfold;intro;inversion H4
471 [intros;lapply (inj_head_nat ? ? ? ? H6);rewrite < Hletin1 in H5;
472 rewrite < H2 in H5;rewrite > H5 in H3;
473 apply (not_le_Sn_n ? H3)
474 |intros;lapply (inj_tail ? ? ? ? ? H8);rewrite < Hletin1 in H5;
476 apply (H1 m ? H5);lapply (le_S ? ? H3);
477 apply (le_S_S_to_le ? ? Hletin2)]]
478 |cut ((leb a t) = true \lor (leb a t) = false)
482 |intros;unfold;intro;inversion H5
483 [intros;lapply (inj_head_nat ? ? ? ? H7);rewrite > H6 in H4;
484 rewrite < Hletin1 in H4;apply (not_le_Sn_n ? H4)
485 |intros;lapply (inj_tail ? ? ? ? ? H9);
486 rewrite < Hletin1 in H6;lapply (H1 a1)
488 |lapply (leb_to_Prop a t);rewrite > H3 in Hletin2;
489 simplify in Hletin2;rewrite < H8;
490 apply (trans_le ? ? ? Hletin2);
491 apply (trans_le ? ? ? ? H4);constructor 2;constructor 1]]]
494 |intros;lapply (leb_to_Prop a t);rewrite > H3 in Hletin1;
495 simplify in Hletin1;lapply (not_le_to_lt ? ? Hletin1);
496 unfold in Hletin2;unfold;intro;inversion H5
497 [intros;lapply (inj_head_nat ? ? ? ? H7);
498 rewrite < Hletin3 in H6;rewrite > H6 in H4;
500 |intros;lapply (inj_tail ? ? ? ? ? H9);
501 rewrite < Hletin3 in H6;rewrite < H8 in H6;
502 apply (H1 ? H4 H6)]]]
503 |elim (leb a t);autobatch]]]]
506 (*** lemmata on well-formedness ***)
508 lemma fv_WFT : \forall T,x,G.(WFType G T) \to (in_list ? x (fv_type T)) \to
509 (in_list ? x (fv_env G)).
511 [simplify in H2;inversion H2
512 [intros;lapply (inj_head_nat ? ? ? ? H4);rewrite < Hletin;assumption
513 |intros;lapply (inj_tail ? ? ? ? ? H6);rewrite < Hletin in H3;
515 [intros;lapply (sym_eq ? ? ? H8);absurd (a2 :: l2 = [])
516 [assumption|apply nil_cons]
517 |intros;lapply (sym_eq ? ? ? H10);
518 absurd (a3 :: l2 = []) [assumption|apply nil_cons]]]
519 |simplify in H1;lapply (in_list_nil ? x H1);elim Hletin
520 |simplify in H5;lapply (nat_in_list_case ? ? ? H5);elim Hletin
523 |simplify in H5;lapply (nat_in_list_case ? ? ? H5);elim Hletin
524 [lapply (fresh_name ((fv_type t1) @ (fv_env e)));elim Hletin1;
525 cut ((\lnot (in_list ? a (fv_type t1))) \land
526 (\lnot (in_list ? a (fv_env e))))
527 [elim Hcut;lapply (H4 ? H9 H8)
529 [simplify in Hletin2;
530 (* FIXME trick *);generalize in match Hletin2;intro;
532 [intros;lapply (inj_head_nat ? ? ? ? H12);
533 rewrite < Hletin3 in H11;lapply (Hcut1 H11);elim Hletin4
534 |intros;lapply (inj_tail ? ? ? ? ? H14);rewrite > Hletin3;
536 |unfold;intro;apply H8;rewrite < H10;assumption]
537 |rewrite > subst_O_nat;apply in_FV_subst;assumption]
539 [unfold;intro;apply H7;apply natinG_or_inH_to_natinGH;right;
541 |unfold;intro;apply H7;apply natinG_or_inH_to_natinGH;left;
546 (*** some exotic inductions and related lemmas ***)
548 lemma not_t_len_lt_SO : \forall T.\lnot (t_len T) < (S O).
550 [1,2,3:simplify;unfold;intro;unfold in H;elim (not_le_Sn_n ? H)
551 |*:simplify;unfold;rewrite > max_case;elim (leb (t_len t) (t_len t1))
552 [1,3:simplify in H2;apply H1;apply (trans_lt ? ? ? ? H2);unfold;constructor 1
553 |*:simplify in H2;apply H;apply (trans_lt ? ? ? ? H2);unfold;constructor 1]]
556 lemma Typ_len_ind : \forall P:Typ \to Prop.
557 (\forall U.(\forall V.((t_len V) < (t_len U)) \to (P V))
560 cut (\forall P:Typ \to Prop.
561 (\forall U.(\forall V.((t_len V) < (t_len U)) \to (P V))
563 \to \forall T,n.(n = (t_len T)) \to (P T))
564 [intros;apply (Hcut ? H ? (t_len T));reflexivity
565 |intros 4;generalize in match T;apply (nat_elim1 n);intros;
566 generalize in match H2;elim t
567 [1,2,3:apply H;intros;simplify in H4;elim (not_t_len_lt_SO ? H4)
568 |*:apply H;intros;apply (H1 (t_len V))
569 [1,3:rewrite > H5;assumption
573 lemma t_len_arrow1 : \forall T1,T2.(t_len T1) < (t_len (Arrow T1 T2)).
575 (* FIXME!!! BUG?!?! *)
576 cut ((max (t_len T1) (t_len T2)) = match (leb (t_len T1) (t_len T2)) with
577 [ false \Rightarrow (t_len T2)
578 | true \Rightarrow (t_len T1) ])
579 [rewrite > Hcut;cut ((leb (t_len T1) (t_len T2)) = false \lor
580 (leb (t_len T1) (t_len T2)) = true)
581 [lapply (leb_to_Prop (t_len T1) (t_len T2));elim Hcut1
582 [rewrite > H;rewrite > H in Hletin;simplify;constructor 1
583 |rewrite > H;rewrite > H in Hletin;simplify;simplify in Hletin;
584 unfold;apply le_S_S;assumption]
585 |elim (leb (t_len T1) (t_len T2));autobatch]
586 |elim T1;simplify;reflexivity]
589 lemma t_len_arrow2 : \forall T1,T2.(t_len T2) < (t_len (Arrow T1 T2)).
591 (* FIXME!!! BUG?!?! *)
592 cut ((max (t_len T1) (t_len T2)) = match (leb (t_len T1) (t_len T2)) with
593 [ false \Rightarrow (t_len T2)
594 | true \Rightarrow (t_len T1) ])
595 [rewrite > Hcut;cut ((leb (t_len T1) (t_len T2)) = false \lor
596 (leb (t_len T1) (t_len T2)) = true)
597 [lapply (leb_to_Prop (t_len T1) (t_len T2));elim Hcut1
598 [rewrite > H;rewrite > H in Hletin;simplify;simplify in Hletin;
599 lapply (not_le_to_lt ? ? Hletin);unfold in Hletin1;unfold;
600 constructor 2;assumption
601 |rewrite > H;simplify;unfold;constructor 1]
602 |elim (leb (t_len T1) (t_len T2));autobatch]
603 |elim T1;simplify;reflexivity]
606 lemma t_len_forall1 : \forall T1,T2.(t_len T1) < (t_len (Forall T1 T2)).
608 (* FIXME!!! BUG?!?! *)
609 cut ((max (t_len T1) (t_len T2)) = match (leb (t_len T1) (t_len T2)) with
610 [ false \Rightarrow (t_len T2)
611 | true \Rightarrow (t_len T1) ])
612 [rewrite > Hcut;cut ((leb (t_len T1) (t_len T2)) = false \lor
613 (leb (t_len T1) (t_len T2)) = true)
614 [lapply (leb_to_Prop (t_len T1) (t_len T2));elim Hcut1
615 [rewrite > H;rewrite > H in Hletin;simplify;constructor 1
616 |rewrite > H;rewrite > H in Hletin;simplify;simplify in Hletin;
617 unfold;apply le_S_S;assumption]
618 |elim (leb (t_len T1) (t_len T2));autobatch]
619 |elim T1;simplify;reflexivity]
622 lemma t_len_forall2 : \forall T1,T2.(t_len T2) < (t_len (Forall T1 T2)).
624 (* FIXME!!! BUG?!?! *)
625 cut ((max (t_len T1) (t_len T2)) = match (leb (t_len T1) (t_len T2)) with
626 [ false \Rightarrow (t_len T2)
627 | true \Rightarrow (t_len T1) ])
628 [rewrite > Hcut;cut ((leb (t_len T1) (t_len T2)) = false \lor
629 (leb (t_len T1) (t_len T2)) = true)
630 [lapply (leb_to_Prop (t_len T1) (t_len T2));elim Hcut1
631 [rewrite > H;rewrite > H in Hletin;simplify;simplify in Hletin;
632 lapply (not_le_to_lt ? ? Hletin);unfold in Hletin1;unfold;
633 constructor 2;assumption
634 |rewrite > H;simplify;unfold;constructor 1]
635 |elim (leb (t_len T1) (t_len T2));autobatch]
636 |elim T1;simplify;reflexivity]
639 lemma eq_t_len_TFree_subst : \forall T,n,X.(t_len T) =
640 (t_len (subst_type_nat T (TFree X) n)).
642 [simplify;elim (eqb n n1);simplify;reflexivity
643 |2,3:simplify;reflexivity
644 |simplify;lapply (H n X);lapply (H1 n X);rewrite < Hletin;rewrite < Hletin1;
646 |simplify;lapply (H n X);lapply (H1 (S n) X);rewrite < Hletin;
647 rewrite < Hletin1;reflexivity]
650 (*** lemmata relating subtyping and well-formedness ***)
652 lemma JS_to_WFE : \forall G,T,U.(G \vdash T \lessdot U) \to (WFEnv G).
653 intros;elim H;assumption.
656 lemma JS_to_WFT : \forall G,T,U.(JSubtype G T U) \to ((WFType G T) \land
659 [split [assumption|apply WFT_Top]
660 |split;apply WFT_TFree;assumption
662 [apply WFT_TFree;apply boundinenv_natinfv;apply ex_intro
663 [apply true | apply ex_intro [apply t1 |assumption]]
665 |elim H2;elim H4;split;apply WFT_Arrow;assumption
667 [apply (WFT_Forall ? ? ? H6);intros;elim (H4 X H7);
668 apply (WFT_env_incl ? ? H9);simplify;unfold;intros;assumption
669 |apply (WFT_Forall ? ? ? H5);intros;elim (H4 X H7);
670 apply (WFT_env_incl ? ? H10);simplify;unfold;intros;assumption]]
673 lemma JS_to_WFT1 : \forall G,T,U.(JSubtype G T U) \to (WFType G T).
674 intros;lapply (JS_to_WFT ? ? ? H);elim Hletin;assumption.
677 lemma JS_to_WFT2 : \forall G,T,U.(JSubtype G T U) \to (WFType G U).
678 intros;lapply (JS_to_WFT ? ? ? H);elim Hletin;assumption.
681 lemma WFE_Typ_subst : \forall H,x,B,C,T,U,G.
682 (WFEnv (H @ ((mk_bound B x T) :: G))) \to (WFType G U) \to
683 (WFEnv (H @ ((mk_bound C x U) :: G))).
685 [simplify;intros;(*FIXME*)generalize in match H1;intro;inversion H1
686 [intros;lapply (nil_cons ? G (mk_bound B x T));lapply (Hletin H4);
688 |intros;lapply (inj_tail ? ? ? ? ? H8);lapply (inj_head ? ? ? ? H8);
689 destruct Hletin1;rewrite < Hletin in H6;rewrite < Hletin in H4;
690 rewrite < Hcut1 in H6;apply (WFE_cons ? ? ? ? H4 H6 H2)]
691 |intros;simplify;generalize in match H2;elim t;simplify in H4;
693 [intros;absurd (mk_bound b n t1::l@(mk_bound B x T::G)=Empty)
696 |intros;lapply (inj_tail ? ? ? ? ? H9);lapply (inj_head ? ? ? ? H9);
697 destruct Hletin1;apply WFE_cons
699 [rewrite > Hletin;assumption
701 |rewrite > Hcut1;generalize in match H7;rewrite < Hletin;
702 rewrite > (fv_env_extends ? x B C T U);intro;assumption
703 |rewrite < Hletin in H8;rewrite > Hcut2;
704 apply (WFT_env_incl ? ? H8);rewrite > (fv_env_extends ? x B C T U);
705 unfold;intros;assumption]]]
708 lemma WFE_bound_bound : \forall B,x,T,U,G. (WFEnv G) \to
709 (in_list ? (mk_bound B x T) G) \to
710 (in_list ? (mk_bound B x U) G) \to T = U.
712 [lapply (in_list_nil ? ? H1);elim Hletin
714 [intros;rewrite < H7 in H8;lapply (inj_head ? ? ? ? H8);
715 rewrite > Hletin in H5;inversion H5
716 [intros;rewrite < H9 in H10;lapply (inj_head ? ? ? ? H10);
717 destruct Hletin1;symmetry;assumption
718 |intros;lapply (inj_tail ? ? ? ? ? H12);rewrite < Hletin1 in H9;
719 rewrite < H11 in H9;lapply (boundinenv_natinfv x e)
720 [destruct Hletin;rewrite < Hcut1 in Hletin2;lapply (H3 Hletin2);
723 [apply B|apply ex_intro [apply T|assumption]]]]
724 |intros;lapply (inj_tail ? ? ? ? ? H10);rewrite < H9 in H7;
725 rewrite < Hletin in H7;(*FIXME*)generalize in match H5;intro;inversion H5
726 [intros;rewrite < H12 in H13;lapply (inj_head ? ? ? ? H13);
727 destruct Hletin1;rewrite < Hcut1 in H7;
728 lapply (boundinenv_natinfv n e)
729 [lapply (H3 Hletin2);elim Hletin3
731 [apply B|apply ex_intro [apply U|assumption]]]
732 |intros;apply (H2 ? H7);rewrite > H14;lapply (inj_tail ? ? ? ? ? H15);
733 rewrite > Hletin1;assumption]]]