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 notation "hvbox( L1 break ⊑ [ term 46 d , break term 46 e ] break term 46 L2 )"
16 non associative with precedence 45
17 for @{ 'SubEq $L1 $d $e $L2 }.
19 include "basic_2/grammar/lenv_length.ma".
21 (* LOCAL ENVIRONMENT REFINEMENT FOR SUBSTITUTION ****************************)
23 inductive lsubr: nat → nat → relation lenv ≝
24 | lsubr_sort: ∀d,e. lsubr d e (⋆) (⋆)
25 | lsubr_OO: ∀L1,L2. lsubr 0 0 L1 L2
26 | lsubr_abbr: ∀L1,L2,V,e. lsubr 0 e L1 L2 →
27 lsubr 0 (e + 1) (L1. ⓓV) (L2.ⓓV)
28 | lsubr_abst: ∀L1,L2,I,V1,V2,e. lsubr 0 e L1 L2 →
29 lsubr 0 (e + 1) (L1. ⓑ{I}V1) (L2. ⓛV2)
30 | lsubr_skip: ∀L1,L2,I1,I2,V1,V2,d,e.
31 lsubr d e L1 L2 → lsubr (d + 1) e (L1. ⓑ{I1} V1) (L2. ⓑ{I2} V2)
35 "local environment refinement (substitution)"
36 'SubEq L1 d e L2 = (lsubr d e L1 L2).
38 definition lsubr_trans: ∀S. (lenv → relation S) → Prop ≝ λS,R.
39 ∀L2,s1,s2. R L2 s1 s2 →
40 ∀L1,d,e. L1 ⊑ [d, e] L2 → R L1 s1 s2.
42 (* Basic properties *********************************************************)
44 lemma lsubr_bind_eq: ∀L1,L2,e. L1 ⊑ [0, e] L2 → ∀I,V.
45 L1. ⓑ{I} V ⊑ [0, e + 1] L2.ⓑ{I} V.
46 #L1 #L2 #e #HL12 #I #V elim I -I /2 width=1/
49 lemma lsubr_abbr_lt: ∀L1,L2,V,e. L1 ⊑ [0, e - 1] L2 → 0 < e →
50 L1. ⓓV ⊑ [0, e] L2.ⓓV.
51 #L1 #L2 #V #e #HL12 #He >(plus_minus_m_m e 1) // /2 width=1/
54 lemma lsubr_abst_lt: ∀L1,L2,I,V1,V2,e. L1 ⊑ [0, e - 1] L2 → 0 < e →
55 L1. ⓑ{I}V1 ⊑ [0, e] L2. ⓛV2.
56 #L1 #L2 #I #V1 #V2 #e #HL12 #He >(plus_minus_m_m e 1) // /2 width=1/
59 lemma lsubr_skip_lt: ∀L1,L2,d,e. L1 ⊑ [d - 1, e] L2 → 0 < d →
60 ∀I1,I2,V1,V2. L1. ⓑ{I1} V1 ⊑ [d, e] L2. ⓑ{I2} V2.
61 #L1 #L2 #d #e #HL12 #Hd >(plus_minus_m_m d 1) // /2 width=1/
64 lemma lsubr_bind_lt: ∀I,L1,L2,V,e. L1 ⊑ [0, e - 1] L2 → 0 < e →
65 L1. ⓓV ⊑ [0, e] L2. ⓑ{I}V.
68 lemma lsubr_refl: ∀d,e,L. L ⊑ [d, e] L.
70 [ #e elim e -e // #e #IHe #L elim L -L // /2 width=1/
71 | #d #IHd #e #L elim L -L // /2 width=1/
75 lemma TC_lsubr_trans: ∀S,R. lsubr_trans S R → lsubr_trans S (λL. (TC … (R L))).
76 #S #R #HR #L1 #s1 #s2 #H elim H -s2
78 | #s #s2 #_ #Hs2 #IHs1 #L2 #d #e #HL12
79 lapply (HR … Hs2 … HL12) -HR -Hs2 -HL12 /3 width=3/
83 (* Basic inversion lemmas ***************************************************)
85 fact lsubr_inv_atom1_aux: ∀L1,L2,d,e. L1 ⊑ [d, e] L2 → L1 = ⋆ →
86 L2 = ⋆ ∨ (d = 0 ∧ e = 0).
87 #L1 #L2 #d #e * -L1 -L2 -d -e
90 | #L1 #L2 #W #e #_ #H destruct
91 | #L1 #L2 #I #W1 #W2 #e #_ #H destruct
92 | #L1 #L2 #I1 #I2 #W1 #W2 #d #e #_ #H destruct
96 lemma lsubr_inv_atom1: ∀L2,d,e. ⋆ ⊑ [d, e] L2 →
97 L2 = ⋆ ∨ (d = 0 ∧ e = 0).
100 fact lsubr_inv_skip1_aux: ∀L1,L2,d,e. L1 ⊑ [d, e] L2 →
101 ∀I1,K1,V1. L1 = K1.ⓑ{I1}V1 → 0 < d →
102 ∃∃I2,K2,V2. K1 ⊑ [d - 1, e] K2 & L2 = K2.ⓑ{I2}V2.
103 #L1 #L2 #d #e * -L1 -L2 -d -e
104 [ #d #e #I1 #K1 #V1 #H destruct
105 | #L1 #L2 #I1 #K1 #V1 #_ #H
106 elim (lt_zero_false … H)
107 | #L1 #L2 #W #e #_ #I1 #K1 #V1 #_ #H
108 elim (lt_zero_false … H)
109 | #L1 #L2 #I #W1 #W2 #e #_ #I1 #K1 #V1 #_ #H
110 elim (lt_zero_false … H)
111 | #L1 #L2 #J1 #J2 #W1 #W2 #d #e #HL12 #I1 #K1 #V1 #H #_ destruct /2 width=5/
115 lemma lsubr_inv_skip1: ∀I1,K1,L2,V1,d,e. K1.ⓑ{I1}V1 ⊑ [d, e] L2 → 0 < d →
116 ∃∃I2,K2,V2. K1 ⊑ [d - 1, e] K2 & L2 = K2.ⓑ{I2}V2.
119 fact lsubr_inv_atom2_aux: ∀L1,L2,d,e. L1 ⊑ [d, e] L2 → L2 = ⋆ →
120 L1 = ⋆ ∨ (d = 0 ∧ e = 0).
121 #L1 #L2 #d #e * -L1 -L2 -d -e
124 | #L1 #L2 #W #e #_ #H destruct
125 | #L1 #L2 #I #W1 #W2 #e #_ #H destruct
126 | #L1 #L2 #I1 #I2 #W1 #W2 #d #e #_ #H destruct
130 lemma lsubr_inv_atom2: ∀L1,d,e. L1 ⊑ [d, e] ⋆ →
131 L1 = ⋆ ∨ (d = 0 ∧ e = 0).
134 fact lsubr_inv_abbr2_aux: ∀L1,L2,d,e. L1 ⊑ [d, e] L2 →
135 ∀K2,V. L2 = K2.ⓓV → d = 0 → 0 < e →
136 ∃∃K1. K1 ⊑ [0, e - 1] K2 & L1 = K1.ⓓV.
137 #L1 #L2 #d #e * -L1 -L2 -d -e
138 [ #d #e #K1 #V #H destruct
139 | #L1 #L2 #K1 #V #_ #_ #H
140 elim (lt_zero_false … H)
141 | #L1 #L2 #W #e #HL12 #K1 #V #H #_ #_ destruct /2 width=3/
142 | #L1 #L2 #I #W1 #W2 #e #_ #K1 #V #H destruct
143 | #L1 #L2 #I1 #I2 #W1 #W2 #d #e #_ #K1 #V #_ >commutative_plus normalize #H destruct
147 lemma lsubr_inv_abbr2: ∀L1,K2,V,e. L1 ⊑ [0, e] K2.ⓓV → 0 < e →
148 ∃∃K1. K1 ⊑ [0, e - 1] K2 & L1 = K1.ⓓV.
151 fact lsubr_inv_skip2_aux: ∀L1,L2,d,e. L1 ⊑ [d, e] L2 →
152 ∀I2,K2,V2. L2 = K2.ⓑ{I2}V2 → 0 < d →
153 ∃∃I1,K1,V1. K1 ⊑ [d - 1, e] K2 & L1 = K1.ⓑ{I1}V1.
154 #L1 #L2 #d #e * -L1 -L2 -d -e
155 [ #d #e #I1 #K1 #V1 #H destruct
156 | #L1 #L2 #I1 #K1 #V1 #_ #H
157 elim (lt_zero_false … H)
158 | #L1 #L2 #W #e #_ #I1 #K1 #V1 #_ #H
159 elim (lt_zero_false … H)
160 | #L1 #L2 #I #W1 #W2 #e #_ #I1 #K1 #V1 #_ #H
161 elim (lt_zero_false … H)
162 | #L1 #L2 #J1 #J2 #W1 #W2 #d #e #HL12 #I1 #K1 #V1 #H #_ destruct /2 width=5/
166 lemma lsubr_inv_skip2: ∀I2,L1,K2,V2,d,e. L1 ⊑ [d, e] K2.ⓑ{I2}V2 → 0 < d →
167 ∃∃I1,K1,V1. K1 ⊑ [d - 1, e] K2 & L1 = K1.ⓑ{I1}V1.
170 (* Basic forward lemmas *****************************************************)
172 fact lsubr_fwd_length_full1_aux: ∀L1,L2,d,e. L1 ⊑ [d, e] L2 →
173 d = 0 → e = |L1| → |L1| ≤ |L2|.
174 #L1 #L2 #d #e #H elim H -L1 -L2 -d -e normalize
179 | #L1 #L2 #_ #_ #_ #_ #d #e #_ #_ >commutative_plus normalize #H destruct
183 lemma lsubr_fwd_length_full1: ∀L1,L2. L1 ⊑ [0, |L1|] L2 → |L1| ≤ |L2|.
186 fact lsubr_fwd_length_full2_aux: ∀L1,L2,d,e. L1 ⊑ [d, e] L2 →
187 d = 0 → e = |L2| → |L2| ≤ |L1|.
188 #L1 #L2 #d #e #H elim H -L1 -L2 -d -e normalize
193 | #L1 #L2 #_ #_ #_ #_ #d #e #_ #_ >commutative_plus normalize #H destruct
197 lemma lsubr_fwd_length_full2: ∀L1,L2. L1 ⊑ [0, |L2|] L2 → |L2| ≤ |L1|.