]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/basic_2/relocation/lsuby.ma
the theory of cpy continues ...
[helm.git] / matita / matita / contribs / lambdadelta / basic_2 / relocation / lsuby.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 include "basic_2/notation/relations/extlrsubeq_4.ma".
16 include "basic_2/relocation/ldrop.ma".
17
18 (* LOCAL ENVIRONMENT REFINEMENT FOR EXTENDED SUBSTITUTION *******************)
19
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)
28 .
29
30 interpretation
31   "local environment refinement (extended substitution)"
32   'ExtLRSubEq L1 d e L2 = (lsuby d e L1 L2).
33
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.
37
38 (* Basic properties *********************************************************)
39
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/
43 qed.
44
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/
48 qed.
49
50 lemma lsuby_refl: ∀L,d,e. L ⊑×[d, e] L.
51 #L elim L -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/
54 qed.
55
56 lemma lsuby_length: ∀L1,L2. |L2| ≤ |L1| → L1 ⊑×[0, 0] L2.
57 #L1 elim L1 -L1
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/
62 ]
63 qed.
64
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/
67 qed.
68
69 (* Basic inversion lemmas ***************************************************)
70
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
76 ]
77 qed-.
78
79 lemma lsuby_inv_atom1: ∀L2,d,e. ⋆ ⊑×[d, e] L2 → L2 = ⋆.
80 /2 width=5 by lsuby_inv_atom1_aux/ qed-.
81
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 →
84                           L2 = ⋆ ∨
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
93 ]
94 qed-.
95
96 lemma lsuby_inv_zero1: ∀I1,K1,L2,V1. K1.ⓑ{I1}V1 ⊑×[0, 0] L2 →
97                        L2 = ⋆ ∨
98                        ∃∃I2,K2,V2. K1 ⊑×[0, 0] K2 & L2 = K2.ⓑ{I2}V2.
99 /2 width=9 by lsuby_inv_zero1_aux/ qed-.
100
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 →
103                           L2 = ⋆ ∨
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
112 ]
113 qed-.
114
115 lemma lsuby_inv_pair1: ∀I1,K1,L2,V,e. K1.ⓑ{I1}V ⊑×[0, e] L2 → 0 < e →
116                        L2 = ⋆ ∨
117                        ∃∃I2,K2. K1 ⊑×[0, e-1] K2 & L2 = K2.ⓑ{I2}V.
118 /2 width=6 by lsuby_inv_pair1_aux/ qed-.
119
120
121 fact lsuby_inv_succ1_aux: ∀L1,L2,d,e. L1 ⊑×[d, e] L2 →
122                           ∀J1,K1,W1. L1 = K1.ⓑ{J1}W1 → 0 < d →
123                           L2 = ⋆ ∨
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/
132 ]
133 qed-.
134
135 lemma lsuby_inv_succ1: ∀I1,K1,L2,V1,d,e. K1.ⓑ{I1}V1 ⊑×[d, e] L2 → 0 < d →
136                        L2 = ⋆ ∨
137                        ∃∃I2,K2,V2. K1 ⊑×[d - 1, e] K2 & L2 = K2.ⓑ{I2}V2.
138 /2 width=5 by lsuby_inv_succ1_aux/ qed-.
139
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
151 ]
152 qed-.
153
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-.
157
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
169 ]
170 qed-.
171
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-.
175
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/
187 ]
188 qed-.
189
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-.
193
194 (* Basic forward lemmas *****************************************************)
195
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/
198 qed-.
199
200 lemma lsuby_fwd_ldrop2_be: ∀L1,L2,d,e. L1 ⊑×[d, e] L2 →
201                            ∀I2,K2,W,i. ⇩[0, i] L2 ≡ K2.ⓑ{I2}W →
202                            d ≤ i → i < d + e →
203                            ∃∃I1,K1. K1 ⊑×[0, d+e-i-1] K2 & ⇩[0, i] L1 ≡ K1.ⓑ{I1}W.
204 #L1 #L2 #d #e #H elim H -L1 -L2 -d -e
205 [ #L1 #d #e #J2 #K2 #W #i #H
206   elim (ldrop_inv_atom1 … H) -H #H destruct
207 | #I1 #I2 #L1 #L2 #V1 #V2 #_ #_ #J2 #K2 #W #i #_ #_ #H
208   elim (lt_zero_false … H)
209 | #I1 #I2 #L1 #L2 #V #e #HL12 #IHL12 #J2 #K2 #W #i #H #_ #Hie
210   elim (ldrop_inv_O1_pair1 … H) -H * #Hi #HLK1
211   [ -IHL12 -Hie destruct normalize -I2
212     <minus_n_O <minus_plus_m_m /2 width=4 by ldrop_pair, ex2_2_intro/
213   | -HL12
214     elim (IHL12 … HLK1) -IHL12 -HLK1 // [2: /2 width=1 by lt_plus_to_minus/ ] -Hie normalize 
215     >minus_minus_comm >arith_b1 /3 width=4 by ldrop_ldrop_lt, ex2_2_intro/
216   ]
217 | #I1 #I2 #L1 #L2 #V1 #V2 #d #e #_ #IHL12 #J2 #K2 #W #i #H #Hdi >plus_plus_comm_23 #Hide
218   elim (le_inv_plus_l … Hdi) #_ #Hi
219   lapply (ldrop_inv_ldrop1_lt … H ?) -H // #HLK1
220   elim (IHL12 … HLK1) -IHL12 -HLK1
221   [2,3: /2 width=1 by lt_plus_to_minus, monotonic_pred/ ] -Hdi -Hide
222   >minus_minus_comm >arith_b1 /3 width=4 by ldrop_ldrop_lt, ex2_2_intro/
223 ]
224 qed-.