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/substitution/ldrop.ma".
16 include "basic_2/unfold/frsups.ma".
17 include "basic_2/static/sd.ma".
19 (* STRATIFIED STATIC TYPE ASSIGNMENT ON TERMS *******************************)
21 inductive ssta (h:sh) (g:sd h): nat → lenv → relation term ≝
22 | ssta_sort: ∀L,k,l. deg h g k l → ssta h g l L (⋆k) (⋆(next h k))
23 | ssta_ldef: ∀L,K,V,W,U,i,l. ⇩[0, i] L ≡ K. ⓓV → ssta h g l K V W →
24 ⇧[0, i + 1] W ≡ U → ssta h g l L (#i) U
25 | ssta_ldec: ∀L,K,W,V,U,i,l. ⇩[0, i] L ≡ K. ⓛW → ssta h g l K W V →
26 ⇧[0, i + 1] W ≡ U → ssta h g (l+1) L (#i) U
27 | ssta_bind: ∀a,I,L,V,T,U,l. ssta h g l (L. ⓑ{I} V) T U →
28 ssta h g l L (ⓑ{a,I}V.T) (ⓑ{a,I}V.U)
29 | ssta_appl: ∀L,V,T,U,l. ssta h g l L T U →
30 ssta h g l L (ⓐV.T) (ⓐV.U)
31 | ssta_cast: ∀L,W,T,U,l. ssta h g l L T U → ssta h g l L (ⓝW. T) U
34 interpretation "stratified static type assignment (term)"
35 'StaticType h g l L T U = (ssta h g l L T U).
37 (* Basic inversion lemmas ************************************************)
39 fact ssta_inv_sort1_aux: ∀h,g,L,T,U,l. ⦃h, L⦄ ⊢ T •[g, l] U → ∀k0. T = ⋆k0 →
40 deg h g k0 l ∧ U = ⋆(next h k0).
41 #h #g #L #T #U #l * -L -T -U -l
42 [ #L #k #l #Hkl #k0 #H destruct /2 width=1/
43 | #L #K #V #W #U #i #l #_ #_ #_ #k0 #H destruct
44 | #L #K #W #V #U #i #l #_ #_ #_ #k0 #H destruct
45 | #a #I #L #V #T #U #l #_ #k0 #H destruct
46 | #L #V #T #U #l #_ #k0 #H destruct
47 | #L #W #T #U #l #_ #k0 #H destruct
50 (* Basic_1: was just: sty0_gen_sort *)
51 lemma ssta_inv_sort1: ∀h,g,L,U,k,l. ⦃h, L⦄ ⊢ ⋆k •[g, l] U →
52 deg h g k l ∧ U = ⋆(next h k).
55 fact ssta_inv_lref1_aux: ∀h,g,L,T,U,l. ⦃h, L⦄ ⊢ T •[g, l] U → ∀j. T = #j →
56 (∃∃K,V,W. ⇩[0, j] L ≡ K. ⓓV & ⦃h, K⦄ ⊢ V •[g, l] W &
59 (∃∃K,W,V,l0. ⇩[0, j] L ≡ K. ⓛW & ⦃h, K⦄ ⊢ W •[g, l0] V &
60 ⇧[0, j + 1] W ≡ U & l = l0 + 1
62 #h #g #L #T #U #l * -L -T -U -l
63 [ #L #k #l #_ #j #H destruct
64 | #L #K #V #W #U #i #l #HLK #HVW #HWU #j #H destruct /3 width=6/
65 | #L #K #W #V #U #i #l #HLK #HWV #HWU #j #H destruct /3 width=8/
66 | #a #I #L #V #T #U #l #_ #j #H destruct
67 | #L #V #T #U #l #_ #j #H destruct
68 | #L #W #T #U #l #_ #j #H destruct
72 (* Basic_1: was just: sty0_gen_lref *)
73 lemma ssta_inv_lref1: ∀h,g,L,U,i,l. ⦃h, L⦄ ⊢ #i •[g, l] U →
74 (∃∃K,V,W. ⇩[0, i] L ≡ K. ⓓV & ⦃h, K⦄ ⊢ V •[g, l] W &
77 (∃∃K,W,V,l0. ⇩[0, i] L ≡ K. ⓛW & ⦃h, K⦄ ⊢ W •[g, l0] V &
78 ⇧[0, i + 1] W ≡ U & l = l0 + 1
82 fact ssta_inv_bind1_aux: ∀h,g,L,T,U,l. ⦃h, L⦄ ⊢ T •[g, l] U →
83 ∀a,I,X,Y. T = ⓑ{a,I}Y.X →
84 ∃∃Z. ⦃h, L.ⓑ{I}Y⦄ ⊢ X •[g, l] Z & U = ⓑ{a,I}Y.Z.
85 #h #g #L #T #U #l * -L -T -U -l
86 [ #L #k #l #_ #a #I #X #Y #H destruct
87 | #L #K #V #W #U #i #l #_ #_ #_ #a #I #X #Y #H destruct
88 | #L #K #W #V #U #i #l #_ #_ #_ #a #I #X #Y #H destruct
89 | #b #J #L #V #T #U #l #HTU #a #I #X #Y #H destruct /2 width=3/
90 | #L #V #T #U #l #_ #a #I #X #Y #H destruct
91 | #L #W #T #U #l #_ #a #I #X #Y #H destruct
95 (* Basic_1: was just: sty0_gen_bind *)
96 lemma ssta_inv_bind1: ∀h,g,a,I,L,Y,X,U,l. ⦃h, L⦄ ⊢ ⓑ{a,I}Y.X •[g, l] U →
97 ∃∃Z. ⦃h, L.ⓑ{I}Y⦄ ⊢ X •[g, l] Z & U = ⓑ{a,I}Y.Z.
100 fact ssta_inv_appl1_aux: ∀h,g,L,T,U,l. ⦃h, L⦄ ⊢ T •[g, l] U → ∀X,Y. T = ⓐY.X →
101 ∃∃Z. ⦃h, L⦄ ⊢ X •[g, l] Z & U = ⓐY.Z.
102 #h #g #L #T #U #l * -L -T -U -l
103 [ #L #k #l #_ #X #Y #H destruct
104 | #L #K #V #W #U #i #l #_ #_ #_ #X #Y #H destruct
105 | #L #K #W #V #U #i #l #_ #_ #_ #X #Y #H destruct
106 | #a #I #L #V #T #U #l #_ #X #Y #H destruct
107 | #L #V #T #U #l #HTU #X #Y #H destruct /2 width=3/
108 | #L #W #T #U #l #_ #X #Y #H destruct
112 (* Basic_1: was just: sty0_gen_appl *)
113 lemma ssta_inv_appl1: ∀h,g,L,Y,X,U,l. ⦃h, L⦄ ⊢ ⓐY.X •[g, l] U →
114 ∃∃Z. ⦃h, L⦄ ⊢ X •[g, l] Z & U = ⓐY.Z.
117 fact ssta_inv_cast1_aux: ∀h,g,L,T,U,l. ⦃h, L⦄ ⊢ T •[g, l] U →
118 ∀X,Y. T = ⓝY.X → ⦃h, L⦄ ⊢ X •[g, l] U.
119 #h #g #L #T #U #l * -L -T -U -l
120 [ #L #k #l #_ #X #Y #H destruct
121 | #L #K #V #W #U #l #i #_ #_ #_ #X #Y #H destruct
122 | #L #K #W #V #U #l #i #_ #_ #_ #X #Y #H destruct
123 | #a #I #L #V #T #U #l #_ #X #Y #H destruct
124 | #L #V #T #U #l #_ #X #Y #H destruct
125 | #L #W #T #U #l #HTU #X #Y #H destruct //
129 (* Basic_1: was just: sty0_gen_cast *)
130 lemma ssta_inv_cast1: ∀h,g,L,X,Y,U,l. ⦃h, L⦄ ⊢ ⓝY.X •[g, l] U →
131 ⦃h, L⦄ ⊢ X •[g, l] U.
134 (* Advanced inversion lemmas ************************************************)
136 lemma ssta_inv_frsupp: ∀h,g,L,T,U,l. ⦃h, L⦄ ⊢ T •[g, l] U → ⦃L, U⦄ ⧁+ ⦃L, T⦄ → ⊥.
137 #h #g #L #T #U #l #H elim H -L -T -U -l
139 elim (frsupp_inv_atom1_frsups … H)
140 | #L #K #V #W #U #i #l #_ #_ #HWU #_ #H
141 elim (lift_frsupp_trans … (⋆) … H … HWU) -U #X #H
142 elim (lift_inv_lref2_be … H ? ?) -H //
143 | #L #K #W #V #U #i #l #_ #_ #HWU #_ #H
144 elim (lift_frsupp_trans … (⋆) … H … HWU) -U #X #H
145 elim (lift_inv_lref2_be … H ? ?) -H //
146 | #a #I #L #V #T #U #l #_ #IHTU #H
147 elim (frsupp_inv_bind1_frsups … H) -H #H [2: /4 width=4/ ] -IHTU
148 lapply (frsups_fwd_fw … H) -H normalize
149 <associative_plus <associative_plus #H
150 elim (le_plus_xySz_x_false … H)
151 | #L #V #T #U #l #_ #IHTU #H
152 elim (frsupp_inv_flat1_frsups … H) -H #H [2: /4 width=4/ ] -IHTU
153 lapply (frsups_fwd_fw … H) -H normalize
154 <associative_plus <associative_plus #H
155 elim (le_plus_xySz_x_false … H)
160 fact ssta_inv_refl_aux: ∀h,g,L,T,U,l. ⦃h, L⦄ ⊢ T •[g, l] U → T = U → ⊥.
161 #h #g #L #T #U #l #H elim H -L -T -U -l
163 lapply (next_lt h k) destruct -H -e0 (**) (* destruct: these premises are not erased *)
164 <e1 -e1 #H elim (lt_refl_false … H)
165 | #L #K #V #W #U #i #l #_ #_ #HWU #_ #H destruct
166 elim (lift_inv_lref2_be … HWU ? ?) -HWU //
167 | #L #K #W #V #U #i #l #_ #_ #HWU #_ #H destruct
168 elim (lift_inv_lref2_be … HWU ? ?) -HWU //
169 | #a #I #L #V #T #U #l #_ #IHTU #H destruct /2 width=1/
170 | #L #V #T #U #l #_ #IHTU #H destruct /2 width=1/
171 | #L #W #T #U #l #HTU #_ #H destruct
172 elim (ssta_inv_frsupp … HTU ?) -HTU /2 width=1/
176 lemma ssta_inv_refl: ∀h,g,T,L,l. ⦃h, L⦄ ⊢ T •[g, l] T → ⊥.
177 /2 width=8 by ssta_inv_refl_aux/ qed-.
179 lemma ssta_inv_frsups: ∀h,g,L,T,U,l. ⦃h, L⦄ ⊢ T •[g, l] U → ⦃L, U⦄ ⧁* ⦃L, T⦄ → ⊥.
180 #h #g #L #T #U #L #HTU #H elim (frsups_inv_all … H) -H
181 [ * #_ #H destruct /2 width=6 by ssta_inv_refl/
182 | /2 width=8 by ssta_inv_frsupp/