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/notation/relations/statictype_7.ma".
16 include "basic_2/grammar/genv.ma".
17 include "basic_2/relocation/ldrop.ma".
18 include "basic_2/static/sd.ma".
20 (* STRATIFIED STATIC TYPE ASSIGNMENT ON TERMS *******************************)
23 inductive ssta (h:sh) (g:sd h): nat → relation4 genv lenv term term ≝
24 | ssta_sort: ∀G,L,k,l. deg h g k l → ssta h g l G L (⋆k) (⋆(next h k))
25 | ssta_ldef: ∀G,L,K,V,W,U,i,l. ⇩[0, i] L ≡ K. ⓓV → ssta h g l G K V W →
26 ⇧[0, i + 1] W ≡ U → ssta h g l G L (#i) U
27 | ssta_ldec: ∀G,L,K,W,V,U,i,l. ⇩[0, i] L ≡ K. ⓛW → ssta h g l G K W V →
28 ⇧[0, i + 1] W ≡ U → ssta h g (l+1) G L (#i) U
29 | ssta_bind: ∀a,I,G,L,V,T,U,l. ssta h g l G (L. ⓑ{I} V) T U →
30 ssta h g l G L (ⓑ{a,I}V.T) (ⓑ{a,I}V.U)
31 | ssta_appl: ∀G,L,V,T,U,l. ssta h g l G L T U →
32 ssta h g l G L (ⓐV.T) (ⓐV.U)
33 | ssta_cast: ∀G,L,W,T,U,l. ssta h g l G L T U → ssta h g l G L (ⓝW.T) U
36 interpretation "stratified static type assignment (term)"
37 'StaticType h g G L T U l = (ssta h g l G L T U).
39 definition ssta_step: ∀h. sd h → relation4 genv lenv term term ≝
40 λh,g,G,L,T,U. ∃l. ⦃G, L⦄ ⊢ T •[h, g] ⦃l+1, U⦄.
42 (* Basic inversion lemmas ************************************************)
44 fact ssta_inv_sort1_aux: ∀h,g,G,L,T,U,l. ⦃G, L⦄ ⊢ T •[h, g] ⦃l, U⦄ → ∀k0. T = ⋆k0 →
45 deg h g k0 l ∧ U = ⋆(next h k0).
46 #h #g #G #L #T #U #l * -G -L -T -U -l
47 [ #G #L #k #l #Hkl #k0 #H destruct /2 width=1/
48 | #G #L #K #V #W #U #i #l #_ #_ #_ #k0 #H destruct
49 | #G #L #K #W #V #U #i #l #_ #_ #_ #k0 #H destruct
50 | #a #I #G #L #V #T #U #l #_ #k0 #H destruct
51 | #G #L #V #T #U #l #_ #k0 #H destruct
52 | #G #L #W #T #U #l #_ #k0 #H destruct
55 (* Basic_1: was just: sty0_gen_sort *)
56 lemma ssta_inv_sort1: ∀h,g,G,L,U,k,l. ⦃G, L⦄ ⊢ ⋆k •[h, g] ⦃l, U⦄ →
57 deg h g k l ∧ U = ⋆(next h k).
58 /2 width=5 by ssta_inv_sort1_aux/ qed-.
60 fact ssta_inv_lref1_aux: ∀h,g,G,L,T,U,l. ⦃G, L⦄ ⊢ T •[h, g] ⦃l, U⦄ → ∀j. T = #j →
61 (∃∃K,V,W. ⇩[0, j] L ≡ K. ⓓV & ⦃G, K⦄ ⊢ V •[h, g] ⦃l, W⦄ &
64 (∃∃K,W,V,l0. ⇩[0, j] L ≡ K. ⓛW & ⦃G, K⦄ ⊢ W •[h, g] ⦃l0, V⦄ &
65 ⇧[0, j + 1] W ≡ U & l = l0 + 1
67 #h #g #G #L #T #U #l * -G -L -T -U -l
68 [ #G #L #k #l #_ #j #H destruct
69 | #G #L #K #V #W #U #i #l #HLK #HVW #HWU #j #H destruct /3 width=6/
70 | #G #L #K #W #V #U #i #l #HLK #HWV #HWU #j #H destruct /3 width=8/
71 | #a #I #G #L #V #T #U #l #_ #j #H destruct
72 | #G #L #V #T #U #l #_ #j #H destruct
73 | #G #L #W #T #U #l #_ #j #H destruct
77 (* Basic_1: was just: sty0_gen_lref *)
78 lemma ssta_inv_lref1: ∀h,g,G,L,U,i,l. ⦃G, L⦄ ⊢ #i •[h, g] ⦃l, U⦄ →
79 (∃∃K,V,W. ⇩[0, i] L ≡ K. ⓓV & ⦃G, K⦄ ⊢ V •[h, g] ⦃l, W⦄ &
82 (∃∃K,W,V,l0. ⇩[0, i] L ≡ K. ⓛW & ⦃G, K⦄ ⊢ W •[h, g] ⦃l0, V⦄ &
83 ⇧[0, i + 1] W ≡ U & l = l0 + 1
85 /2 width=3 by ssta_inv_lref1_aux/ qed-.
87 fact ssta_inv_gref1_aux: ∀h,g,G,L,T,U,l. ⦃G, L⦄ ⊢ T •[h, g] ⦃l, U⦄ → ∀p0. T = §p0 → ⊥.
88 #h #g #G #L #T #U #l * -G -L -T -U -l
89 [ #G #L #k #l #_ #p0 #H destruct
90 | #G #L #K #V #W #U #i #l #_ #_ #_ #p0 #H destruct
91 | #G #L #K #W #V #U #i #l #_ #_ #_ #p0 #H destruct
92 | #a #I #G #L #V #T #U #l #_ #p0 #H destruct
93 | #G #L #V #T #U #l #_ #p0 #H destruct
94 | #G #L #W #T #U #l #_ #p0 #H destruct
97 lemma ssta_inv_gref1: ∀h,g,G,L,U,p,l. ⦃G, L⦄ ⊢ §p •[h, g] ⦃l, U⦄ → ⊥.
98 /2 width=10 by ssta_inv_gref1_aux/ qed-.
100 fact ssta_inv_bind1_aux: ∀h,g,G,L,T,U,l. ⦃G, L⦄ ⊢ T •[h, g] ⦃l, U⦄ →
101 ∀a,I,X,Y. T = ⓑ{a,I}Y.X →
102 ∃∃Z. ⦃G, L.ⓑ{I}Y⦄ ⊢ X •[h, g] ⦃l, Z⦄ & U = ⓑ{a,I}Y.Z.
103 #h #g #G #L #T #U #l * -G -L -T -U -l
104 [ #G #L #k #l #_ #a #I #X #Y #H destruct
105 | #G #L #K #V #W #U #i #l #_ #_ #_ #a #I #X #Y #H destruct
106 | #G #L #K #W #V #U #i #l #_ #_ #_ #a #I #X #Y #H destruct
107 | #b #J #G #L #V #T #U #l #HTU #a #I #X #Y #H destruct /2 width=3/
108 | #G #L #V #T #U #l #_ #a #I #X #Y #H destruct
109 | #G #L #W #T #U #l #_ #a #I #X #Y #H destruct
113 (* Basic_1: was just: sty0_gen_bind *)
114 lemma ssta_inv_bind1: ∀h,g,a,I,G,L,Y,X,U,l. ⦃G, L⦄ ⊢ ⓑ{a,I}Y.X •[h, g] ⦃l, U⦄ →
115 ∃∃Z. ⦃G, L.ⓑ{I}Y⦄ ⊢ X •[h, g] ⦃l, Z⦄ & U = ⓑ{a,I}Y.Z.
116 /2 width=3 by ssta_inv_bind1_aux/ qed-.
118 fact ssta_inv_appl1_aux: ∀h,g,G,L,T,U,l. ⦃G, L⦄ ⊢ T •[h, g] ⦃l, U⦄ → ∀X,Y. T = ⓐY.X →
119 ∃∃Z. ⦃G, L⦄ ⊢ X •[h, g] ⦃l, Z⦄ & U = ⓐY.Z.
120 #h #g #G #L #T #U #l * -G -L -T -U -l
121 [ #G #L #k #l #_ #X #Y #H destruct
122 | #G #L #K #V #W #U #i #l #_ #_ #_ #X #Y #H destruct
123 | #G #L #K #W #V #U #i #l #_ #_ #_ #X #Y #H destruct
124 | #a #I #G #L #V #T #U #l #_ #X #Y #H destruct
125 | #G #L #V #T #U #l #HTU #X #Y #H destruct /2 width=3/
126 | #G #L #W #T #U #l #_ #X #Y #H destruct
130 (* Basic_1: was just: sty0_gen_appl *)
131 lemma ssta_inv_appl1: ∀h,g,G,L,Y,X,U,l. ⦃G, L⦄ ⊢ ⓐY.X •[h, g] ⦃l, U⦄ →
132 ∃∃Z. ⦃G, L⦄ ⊢ X •[h, g] ⦃l, Z⦄ & U = ⓐY.Z.
133 /2 width=3 by ssta_inv_appl1_aux/ qed-.
135 fact ssta_inv_cast1_aux: ∀h,g,G,L,T,U,l. ⦃G, L⦄ ⊢ T •[h, g] ⦃l, U⦄ →
136 ∀X,Y. T = ⓝY.X → ⦃G, L⦄ ⊢ X •[h, g] ⦃l, U⦄.
137 #h #g #G #L #T #U #l * -G -L -T -U -l
138 [ #G #L #k #l #_ #X #Y #H destruct
139 | #G #L #K #V #W #U #l #i #_ #_ #_ #X #Y #H destruct
140 | #G #L #K #W #V #U #l #i #_ #_ #_ #X #Y #H destruct
141 | #a #I #G #L #V #T #U #l #_ #X #Y #H destruct
142 | #G #L #V #T #U #l #_ #X #Y #H destruct
143 | #G #L #W #T #U #l #HTU #X #Y #H destruct //
147 (* Basic_1: was just: sty0_gen_cast *)
148 lemma ssta_inv_cast1: ∀h,g,G,L,X,Y,U,l. ⦃G, L⦄ ⊢ ⓝY.X •[h, g] ⦃l, U⦄ →
149 ⦃G, L⦄ ⊢ X •[h, g] ⦃l, U⦄.
150 /2 width=4 by ssta_inv_cast1_aux/ qed-.