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/extlrsubeq_4.ma".
16 include "basic_2/grammar/lenv_length.ma".
18 (* LOCAL ENVIRONMENT REFINEMENT FOR EXTENDED SUBSTITUTION *******************)
20 inductive lsuby: relation4 nat nat lenv lenv ≝
21 | lsuby_atom: ∀L,d,e. lsuby d e L (⋆)
22 | lsuby_zero: ∀I1,I2,L1,L2,V1,V2.
23 lsuby 0 0 L1 L2 → lsuby 0 0 (L1.ⓑ{I1}V1) (L2.ⓑ{I2}V2)
24 | lsuby_pair: ∀I1,I2,L1,L2,V,e. lsuby 0 e L1 L2 →
25 lsuby 0 (e + 1) (L1.ⓑ{I1}V) (L2.ⓑ{I2}V)
26 | lsuby_succ: ∀I1,I2,L1,L2,V1,V2,d,e.
27 lsuby d e L1 L2 → lsuby (d + 1) e (L1. ⓑ{I1}V1) (L2. ⓑ{I2} V2)
31 "local environment refinement (extended substitution)"
32 'ExtLRSubEq L1 d e L2 = (lsuby d e L1 L2).
34 definition lsuby_trans: ∀S. predicate (lenv → relation S) ≝ λS,R.
35 ∀L2,s1,s2. R L2 s1 s2 →
36 ∀L1,d,e. L1 ⊑×[d, e] L2 → R L1 s1 s2.
38 (* Basic properties *********************************************************)
40 lemma lsuby_pair_lt: ∀I1,I2,L1,L2,V,e. L1 ⊑×[0, e-1] L2 → 0 < e →
41 L1.ⓑ{I1}V ⊑×[0, e] L2.ⓑ{I2}V.
42 #I1 #I2 #L1 #L2 #V #e #HL12 #He >(plus_minus_m_m e 1) /2 width=1 by lsuby_pair/
45 lemma lsuby_succ_lt: ∀I1,I2,L1,L2,V1,V2,d,e. L1 ⊑×[d-1, e] L2 → 0 < d →
46 L1.ⓑ{I1}V1 ⊑×[d, e] L2. ⓑ{I2}V2.
47 #I1 #I2 #L1 #L2 #V1 #V2 #d #e #HL12 #Hd >(plus_minus_m_m d 1) /2 width=1 by lsuby_succ/
50 lemma lsuby_refl: ∀L,d,e. L ⊑×[d, e] L.
52 #L #I #V #IHL #d @(nat_ind_plus … d) -d /2 width=1 by lsuby_succ/
53 #e @(nat_ind_plus … e) -e /2 width=2 by lsuby_pair, lsuby_zero/
56 lemma lsuby_length: ∀L1,L2. |L2| ≤ |L1| → L1 ⊑×[0, 0] L2.
58 [ #X #H lapply (le_n_O_to_eq … H) -H
59 #H lapply (length_inv_zero_sn … H) #H destruct /2 width=1 by lsuby_atom/
60 | #L1 #I1 #V1 #IHL1 * normalize
61 /4 width=2 by lsuby_zero, le_S_S_to_le/
65 lemma TC_lsuby_trans: ∀S,R. lsuby_trans S R → lsuby_trans S (λL. (TC … (R L))).
66 #S #R #HR #L1 #s1 #s2 #H elim H -s2 /3 width=7 by step, inj/
69 (* Basic inversion lemmas ***************************************************)
71 fact lsuby_inv_atom1_aux: ∀L1,L2,d,e. L1 ⊑×[d, e] L2 → L1 = ⋆ → L2 = ⋆.
72 #L1 #L2 #d #e * -L1 -L2 -d -e //
73 [ #I1 #I2 #L1 #L2 #V1 #V2 #_ #H destruct
74 | #I1 #I2 #L1 #L2 #V #e #_ #H destruct
75 | #I1 #I2 #L1 #L2 #V1 #V2 #d #e #_ #H destruct
79 lemma lsuby_inv_atom1: ∀L2,d,e. ⋆ ⊑×[d, e] L2 → L2 = ⋆.
80 /2 width=5 by lsuby_inv_atom1_aux/ qed-.
82 fact lsuby_inv_zero1_aux: ∀L1,L2,d,e. L1 ⊑×[d, e] L2 →
83 ∀J1,K1,W1. L1 = K1.ⓑ{J1}W1 → d = 0 → e = 0 →
85 ∃∃J2,K2,W2. K1 ⊑×[0, 0] K2 & L2 = K2.ⓑ{J2}W2.
86 #L1 #L2 #d #e * -L1 -L2 -d -e /2 width=1 by or_introl/
87 [ #I1 #I2 #L1 #L2 #V1 #V2 #HL12 #J1 #K1 #W1 #H #_ #_ destruct
88 /3 width=5 by ex2_3_intro, or_intror/
89 | #I1 #I2 #L1 #L2 #V #e #_ #J1 #K1 #W1 #_ #_
90 <plus_n_Sm #H destruct
91 | #I1 #I2 #L1 #L2 #V1 #V2 #d #e #_ #J1 #K1 #W1 #_
92 <plus_n_Sm #H destruct
96 lemma lsuby_inv_zero1: ∀I1,K1,L2,V1. K1.ⓑ{I1}V1 ⊑×[0, 0] L2 →
98 ∃∃I2,K2,V2. K1 ⊑×[0, 0] K2 & L2 = K2.ⓑ{I2}V2.
99 /2 width=9 by lsuby_inv_zero1_aux/ qed-.
101 fact lsuby_inv_pair1_aux: ∀L1,L2,d,e. L1 ⊑×[d, e] L2 →
102 ∀J1,K1,W. L1 = K1.ⓑ{J1}W → d = 0 → 0 < e →
104 ∃∃J2,K2. K1 ⊑×[0, e-1] K2 & L2 = K2.ⓑ{J2}W.
105 #L1 #L2 #d #e * -L1 -L2 -d -e /2 width=1 by or_introl/
106 [ #I1 #I2 #L1 #L2 #V1 #V2 #_ #J1 #K1 #W #_ #_ #H
107 elim (lt_zero_false … H)
108 | #I1 #I2 #L1 #L2 #V #e #HL12 #J1 #K1 #W #H #_ #_ destruct
109 /3 width=4 by ex2_2_intro, or_intror/
110 | #I1 #I2 #L1 #L2 #V1 #V2 #d #e #_ #J1 #K1 #W #_
111 <plus_n_Sm #H destruct
115 lemma lsuby_inv_pair1: ∀I1,K1,L2,V,e. K1.ⓑ{I1}V ⊑×[0, e] L2 → 0 < e →
117 ∃∃I2,K2. K1 ⊑×[0, e-1] K2 & L2 = K2.ⓑ{I2}V.
118 /2 width=6 by lsuby_inv_pair1_aux/ qed-.
121 fact lsuby_inv_succ1_aux: ∀L1,L2,d,e. L1 ⊑×[d, e] L2 →
122 ∀J1,K1,W1. L1 = K1.ⓑ{J1}W1 → 0 < d →
124 ∃∃J2,K2,W2. K1 ⊑×[d-1, e] K2 & L2 = K2.ⓑ{J2}W2.
125 #L1 #L2 #d #e * -L1 -L2 -d -e /2 width=1 by or_introl/
126 [ #I1 #I2 #L1 #L2 #V1 #V2 #_ #J1 #K1 #W1 #_ #H
127 elim (lt_zero_false … H)
128 | #I1 #I2 #L1 #L2 #V #e #_ #J1 #K1 #W1 #_ #H
129 elim (lt_zero_false … H)
130 | #I1 #I2 #L1 #L2 #V1 #V2 #d #e #HL12 #J1 #K1 #W1 #H #_ destruct
131 /3 width=5 by ex2_3_intro, or_intror/
135 lemma lsuby_inv_succ1: ∀I1,K1,L2,V1,d,e. K1.ⓑ{I1}V1 ⊑×[d, e] L2 → 0 < d →
137 ∃∃I2,K2,V2. K1 ⊑×[d - 1, e] K2 & L2 = K2.ⓑ{I2}V2.
138 /2 width=5 by lsuby_inv_succ1_aux/ qed-.
140 fact lsuby_inv_zero2_aux: ∀L1,L2,d,e. L1 ⊑×[d, e] L2 →
141 ∀J2,K2,W2. L2 = K2.ⓑ{J2}W2 → d = 0 → e = 0 →
142 ∃∃J1,K1,W1. K1 ⊑×[0, 0] K2 & L1 = K1.ⓑ{J1}W1.
143 #L1 #L2 #d #e * -L1 -L2 -d -e
144 [ #L1 #d #e #J2 #K2 #W1 #H destruct
145 | #I1 #I2 #L1 #L2 #V1 #V2 #HL12 #J2 #K2 #W2 #H #_ #_ destruct
146 /2 width=5 by ex2_3_intro/
147 | #I1 #I2 #L1 #L2 #V #e #_ #J2 #K2 #W2 #_ #_
148 <plus_n_Sm #H destruct
149 | #I1 #I2 #L1 #L2 #V1 #V2 #d #e #_ #J2 #K2 #W2 #_
150 <plus_n_Sm #H destruct
154 lemma lsuby_inv_zero2: ∀I2,K2,L1,V2. L1 ⊑×[0, 0] K2.ⓑ{I2}V2 →
155 ∃∃I1,K1,V1. K1 ⊑×[0, 0] K2 & L1 = K1.ⓑ{I1}V1.
156 /2 width=9 by lsuby_inv_zero2_aux/ qed-.
158 fact lsuby_inv_pair2_aux: ∀L1,L2,d,e. L1 ⊑×[d, e] L2 →
159 ∀J2,K2,W. L2 = K2.ⓑ{J2}W → d = 0 → 0 < e →
160 ∃∃J1,K1. K1 ⊑×[0, e-1] K2 & L1 = K1.ⓑ{J1}W.
161 #L1 #L2 #d #e * -L1 -L2 -d -e
162 [ #L1 #d #e #J2 #K2 #W #H destruct
163 | #I1 #I2 #L1 #L2 #V1 #V2 #_ #J2 #K2 #W #_ #_ #H
164 elim (lt_zero_false … H)
165 | #I1 #I2 #L1 #L2 #V #e #HL12 #J2 #K2 #W #H #_ #_ destruct
166 /2 width=4 by ex2_2_intro/
167 | #I1 #I2 #L1 #L2 #V1 #V2 #d #e #_ #J2 #K2 #W #_
168 <plus_n_Sm #H destruct
172 lemma lsuby_inv_pair2: ∀I2,K2,L1,V,e. L1 ⊑×[0, e] K2.ⓑ{I2}V → 0 < e →
173 ∃∃I1,K1. K1 ⊑×[0, e-1] K2 & L1 = K1.ⓑ{I1}V.
174 /2 width=6 by lsuby_inv_pair2_aux/ qed-.
176 fact lsuby_inv_succ2_aux: ∀L1,L2,d,e. L1 ⊑×[d, e] L2 →
177 ∀J2,K2,W2. L2 = K2.ⓑ{J2}W2 → 0 < d →
178 ∃∃J1,K1,W1. K1 ⊑×[d-1, e] K2 & L1 = K1.ⓑ{J1}W1.
179 #L1 #L2 #d #e * -L1 -L2 -d -e
180 [ #L1 #d #e #J2 #K2 #W2 #H destruct
181 | #I1 #I2 #L1 #L2 #V1 #V2 #_ #J2 #K2 #W2 #_ #H
182 elim (lt_zero_false … H)
183 | #I1 #I2 #L1 #L2 #V #e #_ #J2 #K1 #W2 #_ #H
184 elim (lt_zero_false … H)
185 | #I1 #I2 #L1 #L2 #V1 #V2 #d #e #HL12 #J2 #K2 #W2 #H #_ destruct
186 /2 width=5 by ex2_3_intro/
190 lemma lsuby_inv_succ2: ∀I2,K2,L1,V2,d,e. L1 ⊑×[d, e] K2.ⓑ{I2}V2 → 0 < d →
191 ∃∃I1,K1,V1. K1 ⊑×[d-1, e] K2 & L1 = K1.ⓑ{I1}V1.
192 /2 width=5 by lsuby_inv_succ2_aux/ qed-.
194 (* Basic forward lemmas *****************************************************)
196 lemma lsuby_fwd_length: ∀L1,L2,d,e. L1 ⊑×[d, e] L2 → |L2| ≤ |L1|.
197 #L1 #L2 #d #e #H elim H -L1 -L2 -d -e normalize /2 width=1 by le_S_S/