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 include "basic_2/rt_equivalence/cpcs_cpcs.ma".
16 include "basic_2/dynamic/cnv_cpcs.ma".
17 include "basic_2/dynamic/nta.ma".
19 (* NATIVE TYPE ASSIGNMENT FOR TERMS *****************************************)
21 (* Properties based on preservation *****************************************)
23 lemma cnv_cpms_nta (a) (h) (G) (L):
24 ∀T. ⦃G,L⦄ ⊢ T ![a,h] → ∀U.⦃G,L⦄ ⊢ T ➡*[1,h] U → ⦃G,L⦄ ⊢ T :[a,h] U.
25 /3 width=4 by cnv_cast, cnv_cpms_trans/ qed.
27 lemma cnv_nta_sn (a) (h) (G) (L):
28 ∀T. ⦃G,L⦄ ⊢ T ![a,h] → ∃U. ⦃G,L⦄ ⊢ T :[a,h] U.
30 elim (cnv_fwd_cpm_SO … HT) #U #HTU
31 /4 width=2 by cnv_cpms_nta, cpm_cpms, ex_intro/
34 (* Basic_1: was: ty3_typecheck *)
35 lemma nta_typecheck (a) (h) (G) (L):
36 ∀T,U. ⦃G,L⦄ ⊢ T :[a,h] U → ∃T0. ⦃G,L⦄ ⊢ ⓝU.T :[a,h] T0.
37 /3 width=1 by cnv_cast, cnv_nta_sn/ qed-.
39 (* Basic_1: was: ty3_correct *)
40 (* Basic_2A1: was: ntaa_fwd_correct *)
41 lemma nta_fwd_correct (a) (h) (G) (L):
42 ∀T,U. ⦃G,L⦄ ⊢ T :[a,h] U → ∃T0. ⦃G,L⦄ ⊢ U :[a,h] T0.
43 /3 width=2 by nta_fwd_cnv_dx, cnv_nta_sn/ qed-.
45 lemma nta_pure_cnv (h) (G) (L):
46 ∀T,U. ⦃G,L⦄ ⊢ T :*[h] U →
47 ∀V. ⦃G,L⦄ ⊢ ⓐV.U !*[h] → ⦃G,L⦄ ⊢ ⓐV.T :*[h] ⓐV.U.
48 #h #G #L #T #U #H1 #V #H2
49 elim (cnv_inv_cast … H1) -H1 #X0 #HU #HT #HUX0 #HTX0
50 elim (cnv_inv_appl … H2) #n #p #X1 #X2 #_ #HV #_ #HVX1 #HUX2
51 elim (cnv_cpms_conf … HU … HUX0 … HUX2) -HU -HUX2
52 <minus_O_n <minus_n_O #X #HX0 #H
53 elim (cpms_inv_abst_sn … H) -H #X3 #X4 #HX13 #HX24 #H destruct
54 @(cnv_cast … (ⓐV.X0)) [2:|*: /2 width=1 by cpms_appl_dx/ ]
55 @(cnv_appl … X3) [4: |*: /2 width=7 by cpms_trans, cpms_cprs_trans/ ]
59 (* Basic_1: uses: ty3_sred_wcpr0_pr0 *)
60 lemma nta_cpr_conf_lpr (a) (h) (G):
61 ∀L1,T1,U. ⦃G,L1⦄ ⊢ T1 :[a,h] U → ∀T2. ⦃G,L1⦄ ⊢ T1 ➡[h] T2 →
62 ∀L2. ⦃G,L1⦄ ⊢ ➡[h] L2 → ⦃G,L2⦄ ⊢ T2 :[a,h] U.
63 #a #h #G #L1 #T1 #U #H #T2 #HT12 #L2 #HL12
64 /3 width=6 by cnv_cpm_trans_lpr, cpm_cast/
67 (* Basic_1: uses: ty3_sred_pr2 ty3_sred_pr0 *)
68 lemma nta_cpr_conf (a) (h) (G) (L):
69 ∀T1,U. ⦃G,L⦄ ⊢ T1 :[a,h] U →
70 ∀T2. ⦃G,L⦄ ⊢ T1 ➡[h] T2 → ⦃G,L⦄ ⊢ T2 :[a,h] U.
71 #a #h #G #L #T1 #U #H #T2 #HT12
72 /3 width=6 by cnv_cpm_trans, cpm_cast/
75 (* Note: this is the preservation property *)
76 (* Basic_1: uses: ty3_sred_pr3 ty3_sred_pr1 *)
77 lemma nta_cprs_conf (a) (h) (G) (L):
78 ∀T1,U. ⦃G,L⦄ ⊢ T1 :[a,h] U →
79 ∀T2. ⦃G,L⦄ ⊢ T1 ➡*[h] T2 → ⦃G,L⦄ ⊢ T2 :[a,h] U.
80 #a #h #G #L #T1 #U #H #T2 #HT12
81 /3 width=6 by cnv_cpms_trans, cpms_cast/
84 (* Basic_1: uses: ty3_cred_pr2 *)
85 lemma nta_lpr_conf (a) (h) (G):
86 ∀L1,T,U. ⦃G,L1⦄ ⊢ T :[a,h] U →
87 ∀L2. ⦃G,L1⦄ ⊢ ➡[h] L2 → ⦃G,L2⦄ ⊢ T :[a,h] U.
88 #a #h #G #L1 #T #U #HTU #L2 #HL12
89 /2 width=3 by cnv_lpr_trans/
92 (* Basic_1: uses: ty3_cred_pr3 *)
93 lemma nta_lprs_conf (a) (h) (G):
94 ∀L1,T,U. ⦃G,L1⦄ ⊢ T :[a,h] U →
95 ∀L2. ⦃G,L1⦄ ⊢ ➡*[h] L2 → ⦃G,L2⦄ ⊢ T :[a,h] U.
96 #a #h #G #L1 #T #U #HTU #L2 #HL12
97 /2 width=3 by cnv_lprs_trans/
100 (* Inversion lemmas based on preservation ***********************************)
102 lemma nta_inv_ldef_sn (a) (h) (G) (K) (V):
103 ∀X2. ⦃G,K.ⓓV⦄ ⊢ #0 :[a,h] X2 →
104 ∃∃W,U. ⦃G,K⦄ ⊢ V :[a,h] W & ⬆*[1] W ≘ U & ⦃G,K.ⓓV⦄ ⊢ U ⬌*[h] X2 & ⦃G,K.ⓓV⦄ ⊢ X2 ![a,h].
105 #a #h #G #Y #X #X2 #H
106 elim (cnv_inv_cast … H) -H #X1 #HX2 #H1 #HX21 #H2
107 elim (cnv_inv_zero … H1) -H1 #Z #K #V #HV #H destruct
108 elim (cpms_inv_delta_sn … H2) -H2 *
111 /3 width=5 by cnv_cpms_nta, cpcs_cprs_sn, ex4_2_intro/
115 lemma nta_inv_lref_sn (a) (h) (G) (L):
116 ∀X2,i. ⦃G,L⦄ ⊢ #↑i :[a,h] X2 →
117 ∃∃I,K,T2,U2. ⦃G,K⦄ ⊢ #i :[a,h] T2 & ⬆*[1] T2 ≘ U2 & ⦃G,K.ⓘ{I}⦄ ⊢ U2 ⬌*[h] X2 & ⦃G,K.ⓘ{I}⦄ ⊢ X2 ![a,h] & L = K.ⓘ{I}.
118 #a #h #G #L #X2 #i #H
119 elim (cnv_inv_cast … H) -H #X1 #HX2 #H1 #HX21 #H2
120 elim (cnv_inv_lref … H1) -H1 #I #K #Hi #H destruct
121 elim (cpms_inv_lref_sn … H2) -H2 *
124 /3 width=9 by cnv_cpms_nta, cpcs_cprs_sn, ex5_4_intro/
128 lemma nta_inv_lref_sn_drops_cnv (a) (h) (G) (L):
129 ∀X2, i. ⦃G,L⦄ ⊢ #i :[a,h] X2 →
130 ∨∨ ∃∃K,V,W,U. ⬇*[i] L ≘ K.ⓓV & ⦃G,K⦄ ⊢ V :[a,h] W & ⬆*[↑i] W ≘ U & ⦃G,L⦄ ⊢ U ⬌*[h] X2 & ⦃G,L⦄ ⊢ X2 ![a,h]
131 | ∃∃K,W,U. ⬇*[i] L ≘ K. ⓛW & ⦃G,K⦄ ⊢ W ![a,h] & ⬆*[↑i] W ≘ U & ⦃G,L⦄ ⊢ U ⬌*[h] X2 & ⦃G,L⦄ ⊢ X2 ![a,h].
132 #a #h #G #L #X2 #i #H
133 elim (cnv_inv_cast … H) -H #X1 #HX2 #H1 #HX21 #H2
134 elim (cnv_inv_lref_drops … H1) -H1 #I #K #V #HLK #HV
135 elim (cpms_inv_lref1_drops … H2) -H2 *
137 | #Y #X #W #H #HVW #HUX1
138 lapply (drops_mono … H … HLK) -H #H destruct
139 /4 width=8 by cnv_cpms_nta, cpcs_cprs_sn, ex5_4_intro, or_introl/
140 | #n #Y #X #U #H #HVU #HUX1 #H0 destruct
141 lapply (drops_mono … H … HLK) -H #H destruct
142 elim (lifts_total V (𝐔❴↑i❵)) #W #HVW
143 lapply (cpms_lifts_bi … HVU (Ⓣ) … L … HVW … HUX1) -U
144 [ /2 width=2 by drops_isuni_fwd_drop2/ ] #HWX1
145 /4 width=9 by cprs_div, ex5_3_intro, or_intror/
149 lemma nta_inv_bind_sn_cnv (a) (h) (p) (I) (G) (K) (X2):
150 ∀V,T. ⦃G,K⦄ ⊢ ⓑ{p,I}V.T :[a,h] X2 →
151 ∃∃U. ⦃G,K⦄ ⊢ V ![a,h] & ⦃G,K.ⓑ{I}V⦄ ⊢ T :[a,h] U & ⦃G,K⦄ ⊢ ⓑ{p,I}V.U ⬌*[h] X2 & ⦃G,K⦄ ⊢ X2 ![a,h].
152 #a #h #p * #G #K #X2 #V #T #H
153 elim (cnv_inv_cast … H) -H #X1 #HX2 #H1 #HX21 #H2
154 elim (cnv_inv_bind … H1) -H1 #HV #HT
155 [ elim (cpms_inv_abbr_sn_dx … H2) -H2 *
156 [ #V0 #U #HV0 #HTU #H destruct
157 /4 width=5 by cnv_cpms_nta, cprs_div, cpms_bind, ex4_intro/
158 | #U #HTU #HX1U #H destruct
159 /4 width=5 by cnv_cpms_nta, cprs_div, cpms_zeta, ex4_intro/
161 | elim (cpms_inv_abst_sn … H2) -H2 #V0 #U #HV0 #HTU #H destruct
162 /4 width=5 by cnv_cpms_nta, cprs_div, cpms_bind, ex4_intro/
166 (* Basic_1: uses: ty3_gen_appl *)
167 lemma nta_inv_appl_sn (h) (G) (L) (X2):
168 ∀V,T. ⦃G,L⦄ ⊢ ⓐV.T :[h] X2 →
169 ∃∃p,W,U. ⦃G,L⦄ ⊢ V :[h] W & ⦃G,L⦄ ⊢ T :[h] ⓛ{p}W.U & ⦃G,L⦄ ⊢ ⓐV.ⓛ{p}W.U ⬌*[h] X2 & ⦃G,L⦄ ⊢ X2 ![h].
170 #h #G #L #X2 #V #T #H
171 elim (cnv_inv_cast … H) -H #X #HX2 #H1 #HX2 #H2
172 elim (cnv_inv_appl … H1) * [ | #n ] #p #W #U #Hn #HV #HT #HVW #HTU
173 [ lapply (cnv_cpms_trans … HT … HTU) #H
174 elim (cnv_inv_bind … H) -H #_ #HU
175 elim (cnv_fwd_cpm_SO … HU) #U0 #HU0 -HU
176 lapply (cpms_step_dx … HTU 1 (ⓛ{p}W.U0) ?) -HTU [ /2 width=1 by cpm_bind/ ] #HTU
177 | lapply (le_n_O_to_eq n ?) [ /3 width=1 by le_S_S_to_le/ ] -Hn #H destruct
179 /5 width=11 by cnv_cpms_nta, cnv_cpms_conf_eq, cpcs_cprs_div, cpms_appl_dx, ex4_3_intro/
182 (* Basic_2A1: uses: nta_fwd_pure1 *)
183 lemma nta_inv_pure_sn_cnv (h) (G) (L) (X2):
184 ∀V,T. ⦃G,L⦄ ⊢ ⓐV.T :*[h] X2 →
185 ∨∨ ∃∃p,W,U. ⦃G,L⦄ ⊢ V :*[h] W & ⦃G,L⦄ ⊢ T :*[h] ⓛ{p}W.U & ⦃G,L⦄ ⊢ ⓐV.ⓛ{p}W.U ⬌*[h] X2 & ⦃G,L⦄ ⊢ X2 !*[h]
186 | ∃∃U. ⦃G,L⦄ ⊢ T :*[h] U & ⦃G,L⦄ ⊢ ⓐV.U !*[h] & ⦃G,L⦄ ⊢ ⓐV.U ⬌*[h] X2 & ⦃G,L⦄ ⊢ X2 !*[h].
187 #h #G #L #X2 #V #T #H
188 elim (cnv_inv_cast … H) -H #X1 #HX2 #H1 #HX21 #H
189 elim (cnv_inv_appl … H1) * [| #n ] #p #W0 #T0 #Hn #HV #HT #HW0 #HT0
190 [ lapply (cnv_cpms_trans … HT … HT0) #H0
191 elim (cnv_inv_bind … H0) -H0 #_ #HU
192 elim (cnv_fwd_cpm_SO … HU) #U0 #HU0 -HU
193 lapply (cpms_step_dx … HT0 1 (ⓛ{p}W0.U0) ?) -HT0 [ /2 width=1 by cpm_bind/ ] #HT0
194 lapply (cpms_appl_dx … V V … HT0) [ // ] #HTU0
195 lapply (cnv_cpms_conf_eq … H1 … HTU0 … H) -H1 -H -HTU0 #HU0X1
196 /4 width=8 by cnv_cpms_nta, cpcs_cprs_div, ex4_3_intro, or_introl/
197 | elim (cnv_cpms_fwd_appl_sn_decompose … H1 … H) -H1 -H #X0 #_ #H #HX01
198 elim (cpms_inv_plus … 1 n … HT0) #U #HTU #HUT0
199 lapply (cnv_cpms_trans … HT … HTU) #HU
200 lapply (cnv_cpms_conf_eq … HT … HTU … H) -H #HUX0
201 @or_intror @(ex4_intro … U … HX2) -HX2
202 [ /2 width=1 by cnv_cpms_nta/
203 | /4 width=7 by cnv_appl, lt_to_le/
204 | /4 width=3 by cpcs_trans, cpcs_cprs_div, cpcs_flat/
209 (* Basic_2A1: uses: nta_inv_cast1 *)
210 lemma nta_inv_cast_sn (a) (h) (G) (L) (X2):
211 ∀U,T. ⦃G,L⦄ ⊢ ⓝU.T :[a,h] X2 →
212 ∧∧ ⦃G,L⦄ ⊢ T :[a,h] U & ⦃G,L⦄ ⊢ U ⬌*[h] X2 & ⦃G,L⦄ ⊢ X2 ![a,h].
213 #a #h #G #L #X2 #U #T #H
214 elim (cnv_inv_cast … H) -H #X0 #HX2 #H1 #HX20 #H2
215 elim (cnv_inv_cast … H1) #X #HU #HT #HUX #HTX
216 elim (cpms_inv_cast1 … H2) -H2 [ * || * ]
217 [ #U0 #T0 #HU0 #HT0 #H destruct -HU -HU0
218 lapply (cnv_cpms_conf_eq … HT … HTX … HT0) -HT -HT0 -HTX #HXT0
219 lapply (cprs_step_dx … HX20 T0 ?) -HX20 [ /2 width=1 by cpm_eps/ ] #HX20
221 lapply (cnv_cpms_conf_eq … HT … HTX … HTX0) -HT -HTX -HTX0 #HX0
222 | #m #HUX0 #H destruct -HT -HTX
223 lapply (cnv_cpms_conf_eq … HU … HUX … HUX0) -HU -HUX0 #HX0
225 /4 width=3 by cpcs_cprs_div, cpcs_cprs_step_sn, and3_intro/
228 (* Basic_1: uses: ty3_gen_cast *)
229 lemma nta_inv_cast_sn_old (a) (h) (G) (L) (X2):
230 ∀T0,T1. ⦃G,L⦄ ⊢ ⓝT1.T0 :[a,h] X2 →
231 ∃∃T2. ⦃G,L⦄ ⊢ T0 :[a,h] T1 & ⦃G,L⦄ ⊢ T1 :[a,h] T2 & ⦃G,L⦄ ⊢ ⓝT2.T1 ⬌*[h] X2 & ⦃G,L⦄ ⊢ X2 ![a,h].
232 #a #h #G #L #X2 #T0 #T1 #H
233 elim (cnv_inv_cast … H) -H #X0 #HX2 #H1 #HX20 #H2
234 elim (cnv_inv_cast … H1) #X #HT1 #HT0 #HT1X #HT0X
235 elim (cpms_inv_cast1 … H2) -H2 [ * || * ]
236 [ #U1 #U0 #HTU1 #HTU0 #H destruct
237 lapply (cnv_cpms_conf_eq … HT0 … HT0X … HTU0) -HT0 -HT0X -HTU0 #HXU0
238 /5 width=5 by cnv_cpms_nta, cpcs_cprs_div, cpcs_cprs_step_sn, cpcs_flat, ex4_intro/
240 elim (cnv_nta_sn … HT1) -HT1 #U1 #HTU1
241 lapply (cnv_cpms_conf_eq … HT0 … HT0X … HTX0) -HT0 -HT0X -HTX0 #HX0
242 lapply (cprs_step_sn … (ⓝU1.T1) … HT1X) -HT1X [ /2 width=1 by cpm_eps/ ] #HT1X
243 /4 width=5 by cpcs_cprs_div, cpcs_cprs_step_sn, ex4_intro/
244 | #n #HT1X0 #H destruct -X -HT0
245 elim (cnv_nta_sn … HT1) -HT1 #U1 #HTU1
246 /4 width=5 by cprs_div, cpms_eps, ex4_intro/
250 (* Basic_1: uses: ty3_gen_lift *)
251 (* Note: "⦃G,L⦄ ⊢ U2 ⬌*[h] X2" can be "⦃G,L⦄ ⊢ X2 ➡*[h] U2" *)
252 lemma nta_inv_lifts_sn (a) (h) (G):
253 ∀L,T2,X2. ⦃G,L⦄ ⊢ T2 :[a,h] X2 →
254 ∀b,f,K. ⬇*[b,f] L ≘ K → ∀T1. ⬆*[f] T1 ≘ T2 →
255 ∃∃U1,U2. ⦃G,K⦄ ⊢ T1 :[a,h] U1 & ⬆*[f] U1 ≘ U2 & ⦃G,L⦄ ⊢ U2 ⬌*[h] X2 & ⦃G,L⦄ ⊢ X2 ![a,h].
256 #a #h #G #L #T2 #X2 #H #b #f #K #HLK #T1 #HT12
257 elim (cnv_inv_cast … H) -H #U2 #HX2 #HT2 #HXU2 #HTU2
258 lapply (cnv_inv_lifts … HT2 … HLK … HT12) -HT2 #HT1
259 elim (cpms_inv_lifts_sn … HTU2 … HLK … HT12) -T2 -HLK #U1 #HU12 #HTU1
260 /3 width=5 by cnv_cpms_nta, cpcs_cprs_sn, ex4_2_intro/
263 (* Forward lemmas based on preservation *************************************)
265 (* Basic_1: was: ty3_unique *)
266 theorem nta_mono (a) (h) (G) (L) (T):
267 ∀U1. ⦃G,L⦄ ⊢ T :[a,h] U1 → ∀U2. ⦃G,L⦄ ⊢ T :[a,h] U2 → ⦃G,L⦄ ⊢ U1 ⬌*[h] U2.
268 #a #h #G #L #T #U1 #H1 #U2 #H2
269 elim (cnv_inv_cast … H1) -H1 #X1 #_ #_ #HUX1 #HTX1
270 elim (cnv_inv_cast … H2) -H2 #X2 #_ #HT #HUX2 #HTX2
271 lapply (cnv_cpms_conf_eq … HT … HTX1 … HTX2) -T #HX12
272 /3 width=3 by cpcs_cprs_div, cpcs_cprs_step_sn/
275 (* Advanced properties ******************************************************)
277 (* Basic_1: uses: ty3_sconv_pc3 *)
278 lemma nta_cpcs_bi (a) (h) (G) (L):
279 ∀T1,U1. ⦃G,L⦄ ⊢ T1 :[a,h] U1 → ∀T2,U2. ⦃G,L⦄ ⊢ T2 :[a,h] U2 →
280 ⦃G,L⦄ ⊢ T1 ⬌*[h] T2 → ⦃G,L⦄ ⊢ U1 ⬌*[h] U2.
281 #a #h #G #L #T1 #U1 #HTU1 #T2 #U2 #HTU2 #HT12
282 elim (cpcs_inv_cprs … HT12) -HT12 #T0 #HT10 #HT02
283 /3 width=6 by nta_mono, nta_cprs_conf/