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/equivalence/cpcs_cpcs.ma".
16 include "basic_2/dynamic/nta.ma".
18 (* NATIVE TYPE ASSIGNMENT ON TERMS ******************************************)
20 (* alternative definition of nta *)
21 inductive ntaa (h:sh): lenv → relation term ≝
22 | ntaa_sort: ∀L,k. ntaa h L (⋆k) (⋆(next h k))
23 | ntaa_ldef: ∀L,K,V,W,U,i. ⇩[0, i] L ≡ K. ⓓV → ntaa h K V W →
24 ⇧[0, i + 1] W ≡ U → ntaa h L (#i) U
25 | ntaa_ldec: ∀L,K,W,V,U,i. ⇩[0, i] L ≡ K. ⓛW → ntaa h K W V →
26 ⇧[0, i + 1] W ≡ U → ntaa h L (#i) U
27 | ntaa_bind: ∀I,L,V,W,T,U. ntaa h L V W → ntaa h (L. ⓑ{I} V) T U →
28 ntaa h L (ⓑ{I}V.T) (ⓑ{I}V.U)
29 | ntaa_appl: ∀L,V,W,T,U. ntaa h L V W → ntaa h L (ⓛW.T) (ⓛW.U) →
30 ntaa h L (ⓐV.ⓛW.T) (ⓐV.ⓛW.U)
31 | ntaa_pure: ∀L,V,W,T,U. ntaa h L T U → ntaa h L (ⓐV.U) W →
32 ntaa h L (ⓐV.T) (ⓐV.U)
33 | ntaa_cast: ∀L,T,U,W. ntaa h L T U → ntaa h L U W → ntaa h L (ⓣU. T) U
34 | ntaa_conv: ∀L,T,U1,U2,V2. ntaa h L T U1 → L ⊢ U1 ⬌* U2 → ntaa h L U2 V2 →
38 interpretation "native type assignment (term) alternative"
39 'NativeTypeAlt h L T U = (ntaa h L T U).
41 (* Advanced inversion lemmas ************************************************)
43 fact ntaa_inv_bind1_aux: ∀h,L,T,U. ⦃h, L⦄ ⊢ T :: U → ∀J,X,Y. T = ⓑ{J}Y.X →
44 ∃∃Z1,Z2. ⦃h, L⦄ ⊢ Y :: Z1 & ⦃h, L.ⓑ{J}Y⦄ ⊢ X :: Z2 &
46 #h #L #T #U #H elim H -L -T -U
47 [ #L #k #J #X #Y #H destruct
48 | #L #K #V #W #U #i #_ #_ #_ #_ #J #X #Y #H destruct
49 | #L #K #W #V #U #i #_ #_ #_ #_ #J #X #Y #H destruct
50 | #I #L #V #W #T #U #HVW #HTU #_ #_ #J #X #Y #H destruct /2 width=3/
51 | #L #V #W #T #U #_ #_ #_ #_ #J #X #Y #H destruct
52 | #L #V #W #T #U #_ #_ #_ #_ #J #X #Y #H destruct
53 | #L #T #U #W #_ #_ #_ #_ #J #X #Y #H destruct
54 | #L #T #U1 #U2 #V2 #_ #HU12 #_ #IHTU1 #_ #J #X #Y #H destruct
55 elim (IHTU1 ????) -IHTU1 [5: // |2,3,4: skip ] #Z1 #Z2 #HZ1 #HZ2 #HU1
56 lapply (cpcs_trans … HU1 … HU12) -U1 /2 width=3/
60 lemma ntaa_inv_bind1: ∀h,J,L,Y,X,U. ⦃h, L⦄ ⊢ ⓑ{J}Y.X :: U →
61 ∃∃Z1,Z2. ⦃h, L⦄ ⊢ Y :: Z1 & ⦃h, L.ⓑ{J}Y⦄ ⊢ X :: Z2 &
65 lemma ntaa_nta: ∀h,L,T,U. ⦃h, L⦄ ⊢ T :: U → ⦃h, L⦄ ⊢ T : U.
66 #h #L #T #U #H elim H -L -T -U
67 // /2 width=1/ /2 width=2/ /2 width=3/ /2 width=6/
70 (* Properties on relocation *************************************************)
72 lemma ntaa_lift: ∀h,L1,T1,U1. ⦃h, L1⦄ ⊢ T1 :: U1 → ∀L2,d,e. ⇩[d, e] L2 ≡ L1 →
73 ∀T2. ⇧[d, e] T1 ≡ T2 → ∀U2. ⇧[d, e] U1 ≡ U2 → ⦃h, L2⦄ ⊢ T2 :: U2.
74 #h #L1 #T1 #U1 #H elim H -L1 -T1 -U1
75 [ #L1 #k #L2 #d #e #HL21 #X1 #H1 #X2 #H2
76 >(lift_inv_sort1 … H1) -X1
77 >(lift_inv_sort1 … H2) -X2 //
78 | #L1 #K1 #V1 #W1 #W #i #HLK1 #_ #HW1 #IHVW1 #L2 #d #e #HL21 #X #H #U2 #HWU2
79 elim (lift_inv_lref1 … H) * #Hid #H destruct
80 [ elim (lift_trans_ge … HW1 … HWU2 ?) -W // #W2 #HW12 #HWU2
81 elim (ldrop_trans_le … HL21 … HLK1 ?) -L1 /2 width=2/ #X #HLK2 #H
82 elim (ldrop_inv_skip2 … H ?) -H /2 width=1/ -Hid #K2 #V2 #HK21 #HV12 #H destruct
84 | lapply (lift_trans_be … HW1 … HWU2 ? ?) -W // /2 width=1/ #HW1U2
85 lapply (ldrop_trans_ge … HL21 … HLK1 ?) -L1 // -Hid /3 width=8/
87 | #L1 #K1 #W1 #V1 #W #i #HLK1 #_ #HW1 #IHWV1 #L2 #d #e #HL21 #X #H #U2 #HWU2
88 elim (lift_inv_lref1 … H) * #Hid #H destruct
89 [ elim (lift_trans_ge … HW1 … HWU2 ?) -W // <minus_plus #W #HW1 #HWU2
90 elim (ldrop_trans_le … HL21 … HLK1 ?) -L1 /2 width=2/ #X #HLK2 #H
91 elim (ldrop_inv_skip2 … H ?) -H /2 width=1/ -Hid #K2 #W2 #HK21 #HW12 #H destruct
92 lapply (lift_mono … HW1 … HW12) -HW1 #H destruct
93 elim (lift_total V1 (d-i-1) e) /3 width=8/
94 | lapply (lift_trans_be … HW1 … HWU2 ? ?) -W // /2 width=1/ #HW1U2
95 lapply (ldrop_trans_ge … HL21 … HLK1 ?) -L1 // -Hid /3 width=8/
97 | #I #L1 #V1 #W1 #T1 #U1 #_ #_ #IHVW1 #IHTU1 #L2 #d #e #HL21 #X1 #H1 #X2 #H2
98 elim (lift_inv_bind1 … H1) -H1 #V2 #T2 #HV12 #HT12 #H destruct
99 elim (lift_inv_bind1 … H2) -H2 #X #U2 #H1 #HU12 #H2 destruct
100 lapply (lift_mono … H1 … HV12) -H1 #H destruct
101 elim (lift_total W1 d e) /4 width=6/
102 | #L1 #V1 #W1 #T1 #U1 #_ #_ #IHVW1 #IHTU1 #L2 #d #e #HL21 #X1 #H1 #X2 #H2
103 elim (lift_inv_flat1 … H1) -H1 #V2 #X #HV12 #H1 #H destruct
104 elim (lift_inv_bind1 … H1) -H1 #W2 #T2 #HW12 #HT12 #H destruct
105 elim (lift_inv_flat1 … H2) -H2 #Y2 #X #HY #H2 #H destruct
106 elim (lift_inv_bind1 … H2) -H2 #X2 #U2 #HX #HU12 #H destruct
107 lapply (lift_mono … HY … HV12) -HY #H destruct
108 lapply (lift_mono … HX … HW12) -HX #H destruct /4 width=6/
109 | #L1 #V1 #W1 #T1 #U1 #_ #_ #IHTU1 #IHUW1 #L2 #d #e #HL21 #X1 #H1 #X2 #H2
110 elim (lift_inv_flat1 … H1) -H1 #V2 #T2 #HV12 #HT12 #H destruct
111 elim (lift_inv_flat1 … H2) -H2 #X #U2 #H1 #HU12 #H2 destruct
112 lapply (lift_mono … H1 … HV12) -H1 #H destruct
113 elim (lift_total W1 d e) /4 width=6/
114 | #L1 #T1 #U1 #W1 #_ #_ #IHTU1 #IHUW1 #L2 #d #e #HL21 #X #H #U2 #HU12
115 elim (lift_inv_flat1 … H) -H #X2 #T2 #HUX2 #HT12 #H destruct
116 lapply (lift_mono … HUX2 … HU12) -HUX2 #H destruct
117 elim (lift_total W1 d e) /3 width=6/
118 | #L1 #T1 #U11 #U12 #V12 #_ #HU112 #_ #IHTU11 #IHUV12 #L2 #d #e #HL21 #U1 #HTU1 #U2 #HU12
119 elim (lift_total U11 d e) #U #HU11
120 elim (lift_total V12 d e) #V22 #HV122
121 lapply (cpcs_lift … HL21 … HU11 … HU12 HU112) -HU112 /3 width=6/
125 (* Advanced forvard lemmas **************************************************)
127 lemma ntaa_fwd_correct: ∀h,L,T,U. ⦃h, L⦄ ⊢ T :: U → ∃T0. ⦃h, L⦄ ⊢ U :: T0.
128 #h #L #T #U #H elim H -L -T -U
130 | #L #K #V #W #W0 #i #HLK #_ #HW0 * #V0 #HWV0
131 lapply (ldrop_fwd_ldrop2 … HLK) -HLK #HLK
132 elim (lift_total V0 0 (i+1)) /3 width=10/
133 | #L #K #W #V #V0 #i #HLK #HWV #HWV0 #_
134 lapply (ldrop_fwd_ldrop2 … HLK) -HLK #HLK
135 elim (lift_total V 0 (i+1)) /3 width=10/
136 | #I #L #V #W #T #U #HVW #_ #_ * /3 width=2/
137 | #L #V #W #T #U #HVW #_ #_ * #X #H
138 elim (ntaa_inv_bind1 … H) -H /4 width=2/
139 | #L #V #W #T #U #_ #HUW * #T0 #HUT0 /3 width=2/
145 (* Advanced properties ******************************************************)
147 lemma nta_ntaa: ∀h,L,T,U. ⦃h, L⦄ ⊢ T : U → ⦃h, L⦄ ⊢ T :: U.
148 #h #L #T #U #H elim H -L -T -U
149 // /2 width=1/ /2 width=2/ /2 width=3/ /2 width=6/
151 elim (ntaa_fwd_correct … HTU) /2 width=2/
154 (* Advanced eliminators *****************************************************)
156 lemma nta_ind_alt: ∀h. ∀R:lenv→relation term.
157 (∀L,k. R L ⋆k ⋆(next h k)) →
159 ⇩[O, i] L ≡ K.ⓓV → ⦃h, K⦄ ⊢ V : W → ⇧[O, i + 1] W ≡ U →
163 ⇩[O, i] L ≡ K.ⓛW → ⦃h, K⦄ ⊢ W : V → ⇧[O, i + 1] W ≡ U →
167 ⦃h, L⦄ ⊢ V : W → ⦃h, L.ⓑ{I}V⦄ ⊢ T : U →
168 R L V W → R (L.ⓑ{I}V) T U → R L (ⓑ{I}V.T) (ⓑ{I}V.U)
171 ⦃h, L⦄ ⊢ V : W → ⦃h, L⦄ ⊢ (ⓛW.T):(ⓛW.U) →
172 R L V W →R L (ⓛW.T) (ⓛW.U) →R L (ⓐV.ⓛW.T) (ⓐV.ⓛW.U)
175 ⦃h, L⦄ ⊢ T : U → ⦃h, L⦄ ⊢ (ⓐV.U) : W →
176 R L T U → R L (ⓐV.U) W → R L (ⓐV.T) (ⓐV.U)
179 ⦃h, L⦄ ⊢ T : U → ⦃h, L⦄ ⊢ U : W →
180 R L T U → R L U W → R L (ⓣU.T) U
183 ⦃h, L⦄ ⊢ T : U1 → L ⊢ U1 ⬌* U2 → ⦃h, L⦄ ⊢ U2 : V2 →
184 R L T U1 →R L U2 V2 →R L T U2
186 ∀L,T,U. ⦃h, L⦄ ⊢ T : U → R L T U.
187 #h #R #H1 #H2 #H3 #H4 #H5 #H6 #H7 #H8 #L #T #U #H elim (nta_ntaa … H) -L -T -U
188 // /3 width=1 by ntaa_nta/ /3 width=3 by ntaa_nta/ /3 width=4 by ntaa_nta/
189 /3 width=7 by ntaa_nta/