]> matita.cs.unibo.it Git - helm.git/blob - matita/contribs/POPLmark/Fsub/part1a_inversion2.ma
tagged 0.5.0-rc1
[helm.git] / matita / contribs / POPLmark / Fsub / part1a_inversion2.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 include "Fsub/defn2.ma".
16
17 (*** Lemma A.1 (Reflexivity) ***)
18 theorem JS_Refl : ∀T,G.WFType G T → WFEnv G → G ⊢ T ⊴  T.
19 intros 3.elim H
20   [apply SA_Refl_TVar [apply H2|assumption]
21   |apply SA_Top [assumption|apply WFT_Top]
22   |apply (SA_Arrow ? ? ? ? ? (H2 H5) (H4 H5))
23   |apply (SA_All ? ? ? ? ? (H2 H5));intros;apply (H4 ? H6)
24      [intro;apply H6;apply (fv_WFT ? ? ? (WFT_Forall ? ? ? H1 H3));
25       simplify;autobatch
26      |autobatch]]
27 qed.
28
29 (*
30  * A slightly more general variant to lemma A.2.2, where weakening isn't
31  * defined as concatenation of any two disjoint environments, but as
32  * set inclusion.
33  *)
34
35 lemma JS_weakening : ∀G,T,U.G ⊢ T ⊴ U → ∀H.WFEnv H → incl ? G H → H ⊢ T ⊴ U.
36 intros 4;elim H
37   [apply (SA_Top ? ? H4);apply (WFT_env_incl ? ? H2 ? (incl_bound_fv ? ? H5))
38   |apply (SA_Refl_TVar ? ? H4);apply (incl_bound_fv ? ? H5 ? H2)
39   |apply (SA_Trans_TVar ? ? ? ? ? (H3 ? H5 H6));apply H6;assumption
40   |apply (SA_Arrow ? ? ? ? ? (H2 ? H6 H7) (H4 ? H6 H7))
41   |apply (SA_All ? ? ? ? ? (H2 ? H6 H7));intros;apply H4
42      [unfold;intro;apply H8;apply (incl_bound_fv ? ? H7 ? H9)
43      |apply (WFE_cons ? ? ? ? H6 H8);autobatch
44      |unfold;intros;inversion H9;intros
45         [destruct H11;apply in_list_head
46         |destruct H13;apply in_list_cons;apply (H7 ? H10)]]]
47 qed.
48
49 theorem narrowing:∀X,G,G1,U,P,M,N.
50   G1 ⊢ P ⊴ U → (∀G2,T.G2@G1 ⊢ U ⊴ T → G2@G1 ⊢ P ⊴ T) → G ⊢ M ⊴ N →
51   ∀l.G=l@(mk_bound true X U::G1) → l@(mk_bound true X P::G1) ⊢ M ⊴ N.
52 intros 10.elim H2
53   [apply SA_Top
54     [rewrite > H5 in H3;
55      apply (WFE_Typ_subst ? ? ? ? ? ? ? H3 (JS_to_WFT1 ? ? ? H))
56     |rewrite > H5 in H4;apply (WFT_env_incl ? ? H4);apply incl_fv_env]
57   |apply SA_Refl_TVar
58     [rewrite > H5 in H3;apply (WFE_Typ_subst ? ? ? ? ? ? ? H3);
59      apply (JS_to_WFT1 ? ? ? H)
60     |rewrite > H5 in H4;rewrite < fv_env_extends;apply H4]
61   |elim (decidable_eq_nat X n)
62     [apply (SA_Trans_TVar ? ? ? P)
63       [rewrite < H7;elim l1;simplify
64         [constructor 1|constructor 2;assumption]
65       |rewrite > append_cons;apply H1;
66        lapply (WFE_bound_bound true n t1 U ? ? H3)
67         [apply (JS_to_WFE ? ? ? H4)
68         |rewrite < Hletin;rewrite < append_cons;apply (H5 ? H6)
69         |rewrite < H7;rewrite > H6;elim l1;simplify
70           [constructor 1|constructor 2;assumption]]]
71     |apply (SA_Trans_TVar ? ? ? t1)
72       [rewrite > H6 in H3;apply (lookup_env_extends ? ? ? ? ? ? ? ? ? ? H3);
73        unfold;intro;apply H7;symmetry;assumption
74       |apply (H5 ? H6)]]
75   |apply (SA_Arrow ? ? ? ? ? (H4 ? H7) (H6 ? H7))
76   |apply (SA_All ? ? ? ? ? (H4 ? H7));intros;
77    apply (H6 ? ? (mk_bound true X1 t2::l1))
78       [rewrite > H7;rewrite > fv_env_extends;apply H8
79       |simplify;rewrite < H7;reflexivity]]
80 qed.
81
82 lemma JSubtype_inv:
83  ∀G:list bound.∀T1,T:Typ.
84   ∀P:list bound → Typ → Prop.
85    (∀t. WFEnv G → WFType G t → T=Top → P G t) →
86    (∀n. T=TFree n → P G (TFree n)) →
87    (∀n,t1.
88     (mk_bound true n t1) ∈ G → G ⊢ t1 ⊴ T → P G t1 → P G (TFree n)) →
89    (∀s1,s2,t1,t2. G ⊢ t1 ⊴ s1 → G ⊢ s2 ⊴ t2 → T=Arrow t1 t2 → P G (Arrow s1 s2)) →
90    (∀s1,s2,t1,t2. G ⊢ t1 ⊴ s1 →
91     (∀X. ¬(X ∈ fv_env G) → (mk_bound true X t1)::G ⊢ subst_type_nat s2 (TFree X) O ⊴ subst_type_nat t2 (TFree X) O)
92       → T=Forall t1 t2 → P G (Forall s1 s2)) →
93     G ⊢ T1 ⊴ T → P G T1.
94  intros;
95  generalize in match (refl_eq ? T);
96  generalize in match (refl_eq ? G);
97  elim H5 in ⊢ (? ? ? % → ? ? ? % → %);
98   [1,2: destruct; autobatch
99   | rewrite < H9 in H6 H7 H8 ⊢ %;
100     rewrite < H10 in H7 H8;
101     autobatch
102   | rewrite < H10 in H6 H8 ⊢ %;
103     autobatch
104   | rewrite < H10 in H6 H8 ⊢ %;
105     apply (H4 t t1 t2 t3); assumption
106   ]
107 qed.
108
109
110 lemma JS_trans_prova: ∀T,G1.WFType G1 T →
111 ∀G,R,U.incl ? (fv_env G1) (fv_env G) → G ⊢ R ⊴ T → G ⊢ T ⊴ U → G ⊢ R ⊴ U.
112 intros 3;elim H;clear H; try autobatch;
113   [ apply (JSubtype_inv ? ? ? ? ? ? ? ? ? H3); intros; destruct; autobatch
114   | inversion H3; intros; destruct; assumption
115   |*: apply (JSubtype_inv ? ? ? ? ? ? ? ? ? H6); intros; destruct;
116     [1,3: autobatch
117     |*: inversion H7; intros; destruct;
118       [1,2: autobatch depth=4 width=4 size=9
119       | apply SA_Top
120          [ assumption
121          | apply WFT_Forall;
122             [ autobatch
123             | intros;lapply (H8 ? H11);
124               autobatch]]
125       | apply SA_All
126          [ autobatch
127          | intros;apply (H4 X);
128             [intro; autobatch;
129             |intro;  apply H13;apply H5; apply (WFT_to_incl ? ? ? H3);
130              assumption
131             |simplify;autobatch
132             |apply (narrowing X (mk_bound true X t::G) ? ? ? ? ? H9 ? ? [])
133                [intros;apply H2
134                   [unfold;intros;lapply (H5 ? H15);rewrite > fv_append;
135                    autobatch
136                   |apply (JS_weakening ? ? ? H9)
137                      [autobatch
138                      |unfold;intros;autobatch]
139                   |assumption]
140                |*:autobatch]
141             |autobatch]]]]]
142 qed.
143
144 theorem JS_trans : ∀G,T,U,V.G ⊢ T ⊴ U → G ⊢ U ⊴ V → G ⊢ T ⊴ V.
145 intros 5;apply (JS_trans_prova ? G);autobatch;
146 qed.
147
148 theorem JS_narrow : ∀G1,G2,X,P,Q,T,U.
149                        (G2 @ (mk_bound true X Q :: G1)) ⊢ T ⊴ U → G1 ⊢ P ⊴ Q →
150                        (G2 @ (mk_bound true X P :: G1)) ⊢ T ⊴ U.
151 intros;apply (narrowing ? ? ? ? ? ? ? H1 ? H) [|autobatch]
152 intros;apply (JS_trans ? ? ? ? ? H2);apply (JS_weakening ? ? ? H1);
153      [autobatch|unfold;intros;autobatch]
154 qed.