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_ldrop.ma".
16 include "basic_2/substitution/tps.ma".
18 (* PARTIAL SUBSTITUTION ON TERMS ********************************************)
20 (* Advanced inversion lemmas ************************************************)
22 fact tps_inv_S2_aux: ∀L,T1,T2,d,e1. L ⊢ T1 ▶ [d, e1] T2 → ∀e2. e1 = e2 + 1 →
23 ∀K,V. ⇩[0, d] L ≡ K. ⓛV → L ⊢ T1 ▶ [d + 1, e2] T2.
24 #L #T1 #T2 #d #e1 #H elim H -L -T1 -T2 -d -e1
26 | #L #K0 #V0 #W #i #d #e1 #Hdi #Hide1 #HLK0 #HV0 #e2 #He12 #K #V #HLK destruct
27 elim (lt_or_ge i (d+1)) #HiSd
29 lapply (le_to_le_to_eq … Hdi ?) /2 width=1/ #H destruct
30 lapply (ldrop_mono … HLK0 … HLK) #H destruct
38 lemma tps_inv_S2: ∀L,T1,T2,d,e. L ⊢ T1 ▶ [d, e + 1] T2 →
39 ∀K,V. ⇩[0, d] L ≡ K. ⓛV → L ⊢ T1 ▶ [d + 1, e] T2.
42 lemma tps_inv_refl_SO2: ∀L,T1,T2,d. L ⊢ T1 ▶ [d, 1] T2 →
43 ∀K,V. ⇩[0, d] L ≡ K. ⓛV → T1 = T2.
44 #L #T1 #T2 #d #HT12 #K #V #HLK
45 lapply (tps_inv_S2 … T1 T2 … 0 … HLK) -K // -HT12 #HT12
46 lapply (tps_inv_refl_O2 … HT12) -HT12 //
49 (* Relocation properties ****************************************************)
51 (* Basic_1: was: subst1_lift_lt *)
52 lemma tps_lift_le: ∀K,T1,T2,dt,et. K ⊢ T1 ▶ [dt, et] T2 →
53 ∀L,U1,U2,d,e. ⇩[d, e] L ≡ K →
54 ⇧[d, e] T1 ≡ U1 → ⇧[d, e] T2 ≡ U2 →
57 #K #T1 #T2 #dt #et #H elim H -K -T1 -T2 -dt -et
58 [ #K #I #dt #et #L #U1 #U2 #d #e #_ #H1 #H2 #_
59 >(lift_mono … H1 … H2) -H1 -H2 //
60 | #K #KV #V #W #i #dt #et #Hdti #Hidet #HKV #HVW #L #U1 #U2 #d #e #HLK #H #HWU2 #Hdetd
61 lapply (lt_to_le_to_lt … Hidet … Hdetd) -Hdetd #Hid
62 lapply (lift_inv_lref1_lt … H … Hid) -H #H destruct
63 elim (lift_trans_ge … HVW … HWU2 ?) -W // <minus_plus #W #HVW #HWU2
64 elim (ldrop_trans_le … HLK … HKV ?) -K /2 width=2/ #X #HLK #H
65 elim (ldrop_inv_skip2 … H ?) -H /2 width=1/ -Hid #K #Y #_ #HVY
66 >(lift_mono … HVY … HVW) -Y -HVW #H destruct /2 width=4/
67 | #K #a #I #V1 #V2 #T1 #T2 #dt #et #_ #_ #IHV12 #IHT12 #L #U1 #U2 #d #e #HLK #H1 #H2 #Hdetd
68 elim (lift_inv_bind1 … H1) -H1 #VV1 #TT1 #HVV1 #HTT1 #H1
69 elim (lift_inv_bind1 … H2) -H2 #VV2 #TT2 #HVV2 #HTT2 #H2 destruct
70 @tps_bind [ /2 width=6/ | @IHT12 /2 width=6/ ] (**) (* /3 width=6/ is too slow, arith3 needed to avoid crash *)
71 | #K #I #V1 #V2 #T1 #T2 #dt #et #_ #_ #IHV12 #IHT12 #L #U1 #U2 #d #e #HLK #H1 #H2 #Hdetd
72 elim (lift_inv_flat1 … H1) -H1 #VV1 #TT1 #HVV1 #HTT1 #H1
73 elim (lift_inv_flat1 … H2) -H2 #VV2 #TT2 #HVV2 #HTT2 #H2 destruct /3 width=6/
77 lemma tps_lift_be: ∀K,T1,T2,dt,et. K ⊢ T1 ▶ [dt, et] T2 →
78 ∀L,U1,U2,d,e. ⇩[d, e] L ≡ K →
79 ⇧[d, e] T1 ≡ U1 → ⇧[d, e] T2 ≡ U2 →
80 dt ≤ d → d ≤ dt + et →
81 L ⊢ U1 ▶ [dt, et + e] U2.
82 #K #T1 #T2 #dt #et #H elim H -K -T1 -T2 -dt -et
83 [ #K #I #dt #et #L #U1 #U2 #d #e #_ #H1 #H2 #_ #_
84 >(lift_mono … H1 … H2) -H1 -H2 //
85 | #K #KV #V #W #i #dt #et #Hdti #Hidet #HKV #HVW #L #U1 #U2 #d #e #HLK #H #HWU2 #Hdtd #_
86 elim (lift_inv_lref1 … H) -H * #Hid #H destruct
88 lapply (lt_to_le_to_lt … (dt+et+e) Hidet ?) // -Hidet #Hidete
89 elim (lift_trans_ge … HVW … HWU2 ?) -W // <minus_plus #W #HVW #HWU2
90 elim (ldrop_trans_le … HLK … HKV ?) -K /2 width=2/ #X #HLK #H
91 elim (ldrop_inv_skip2 … H ?) -H /2 width=1/ -Hid #K #Y #_ #HVY
92 >(lift_mono … HVY … HVW) -V #H destruct /2 width=4/
94 lapply (transitive_le … Hdtd Hid) -Hdtd #Hdti
95 lapply (lift_trans_be … HVW … HWU2 ? ?) -W // /2 width=1/ >plus_plus_comm_23 #HVU2
96 lapply (ldrop_trans_ge_comm … HLK … HKV ?) -K // -Hid /3 width=4/
98 | #K #a #I #V1 #V2 #T1 #T2 #dt #et #_ #_ #IHV12 #IHT12 #L #U1 #U2 #d #e #HLK #H1 #H2 #Hdtd #Hddet
99 elim (lift_inv_bind1 … H1) -H1 #VV1 #TT1 #HVV1 #HTT1 #H1
100 elim (lift_inv_bind1 … H2) -H2 #VV2 #TT2 #HVV2 #HTT2 #H2 destruct
101 @tps_bind [ /2 width=6/ | @IHT12 [3,4: // | skip |5,6: /2 width=1/ | /2 width=1/ ]
102 ] (**) (* /3 width=6/ is too slow, simplification like tps_lift_le is too slow *)
103 | #K #I #V1 #V2 #T1 #T2 #dt #et #_ #_ #IHV12 #IHT12 #L #U1 #U2 #d #e #HLK #H1 #H2 #Hdetd
104 elim (lift_inv_flat1 … H1) -H1 #VV1 #TT1 #HVV1 #HTT1 #H1
105 elim (lift_inv_flat1 … H2) -H2 #VV2 #TT2 #HVV2 #HTT2 #H2 destruct /3 width=6/
109 (* Basic_1: was: subst1_lift_ge *)
110 lemma tps_lift_ge: ∀K,T1,T2,dt,et. K ⊢ T1 ▶ [dt, et] T2 →
111 ∀L,U1,U2,d,e. ⇩[d, e] L ≡ K →
112 ⇧[d, e] T1 ≡ U1 → ⇧[d, e] T2 ≡ U2 →
114 L ⊢ U1 ▶ [dt + e, et] U2.
115 #K #T1 #T2 #dt #et #H elim H -K -T1 -T2 -dt -et
116 [ #K #I #dt #et #L #U1 #U2 #d #e #_ #H1 #H2 #_
117 >(lift_mono … H1 … H2) -H1 -H2 //
118 | #K #KV #V #W #i #dt #et #Hdti #Hidet #HKV #HVW #L #U1 #U2 #d #e #HLK #H #HWU2 #Hddt
119 lapply (transitive_le … Hddt … Hdti) -Hddt #Hid
120 lapply (lift_inv_lref1_ge … H … Hid) -H #H destruct
121 lapply (lift_trans_be … HVW … HWU2 ? ?) -W // /2 width=1/ >plus_plus_comm_23 #HVU2
122 lapply (ldrop_trans_ge_comm … HLK … HKV ?) -K // -Hid /3 width=4/
123 | #K #a #I #V1 #V2 #T1 #T2 #dt #et #_ #_ #IHV12 #IHT12 #L #U1 #U2 #d #e #HLK #H1 #H2 #Hddt
124 elim (lift_inv_bind1 … H1) -H1 #VV1 #TT1 #HVV1 #HTT1 #H1
125 elim (lift_inv_bind1 … H2) -H2 #VV2 #TT2 #HVV2 #HTT2 #H2 destruct
126 @tps_bind [ /2 width=5/ | /3 width=5/ ] (**) (* explicit constructor *)
127 | #K #I #V1 #V2 #T1 #T2 #dt #et #_ #_ #IHV12 #IHT12 #L #U1 #U2 #d #e #HLK #H1 #H2 #Hddt
128 elim (lift_inv_flat1 … H1) -H1 #VV1 #TT1 #HVV1 #HTT1 #H1
129 elim (lift_inv_flat1 … H2) -H2 #VV2 #TT2 #HVV2 #HTT2 #H2 destruct /3 width=5/
133 (* Basic_1: was: subst1_gen_lift_lt *)
134 lemma tps_inv_lift1_le: ∀L,U1,U2,dt,et. L ⊢ U1 ▶ [dt, et] U2 →
135 ∀K,d,e. ⇩[d, e] L ≡ K → ∀T1. ⇧[d, e] T1 ≡ U1 →
137 ∃∃T2. K ⊢ T1 ▶ [dt, et] T2 & ⇧[d, e] T2 ≡ U2.
138 #L #U1 #U2 #dt #et #H elim H -L -U1 -U2 -dt -et
139 [ #L * #i #dt #et #K #d #e #_ #T1 #H #_
140 [ lapply (lift_inv_sort2 … H) -H #H destruct /2 width=3/
141 | elim (lift_inv_lref2 … H) -H * #Hid #H destruct /3 width=3/
142 | lapply (lift_inv_gref2 … H) -H #H destruct /2 width=3/
144 | #L #KV #V #W #i #dt #et #Hdti #Hidet #HLKV #HVW #K #d #e #HLK #T1 #H #Hdetd
145 lapply (lt_to_le_to_lt … Hidet … Hdetd) -Hdetd #Hid
146 lapply (lift_inv_lref2_lt … H … Hid) -H #H destruct
147 elim (ldrop_conf_lt … HLK … HLKV ?) -L // #L #U #HKL #_ #HUV
148 elim (lift_trans_le … HUV … HVW ?) -V // >minus_plus <plus_minus_m_m // -Hid /3 width=4/
149 | #L #a #I #V1 #V2 #U1 #U2 #dt #et #_ #_ #IHV12 #IHU12 #K #d #e #HLK #X #H #Hdetd
150 elim (lift_inv_bind2 … H) -H #W1 #T1 #HWV1 #HTU1 #H destruct
151 elim (IHV12 … HLK … HWV1 ?) -V1 // #W2 #HW12 #HWV2
152 elim (IHU12 … HTU1 ?) -IHU12 -HTU1 [3: /2 width=1/ |4: @ldrop_skip // |2: skip ] -HLK -Hdetd (**) (* /3 width=5/ is too slow *)
154 | #L #I #V1 #V2 #U1 #U2 #dt #et #_ #_ #IHV12 #IHU12 #K #d #e #HLK #X #H #Hdetd
155 elim (lift_inv_flat2 … H) -H #W1 #T1 #HWV1 #HTU1 #H destruct
156 elim (IHV12 … HLK … HWV1 ?) -V1 //
157 elim (IHU12 … HLK … HTU1 ?) -U1 -HLK // /3 width=5/
161 lemma tps_inv_lift1_be: ∀L,U1,U2,dt,et. L ⊢ U1 ▶ [dt, et] U2 →
162 ∀K,d,e. ⇩[d, e] L ≡ K → ∀T1. ⇧[d, e] T1 ≡ U1 →
163 dt ≤ d → d + e ≤ dt + et →
164 ∃∃T2. K ⊢ T1 ▶ [dt, et - e] T2 & ⇧[d, e] T2 ≡ U2.
165 #L #U1 #U2 #dt #et #H elim H -L -U1 -U2 -dt -et
166 [ #L * #i #dt #et #K #d #e #_ #T1 #H #_
167 [ lapply (lift_inv_sort2 … H) -H #H destruct /2 width=3/
168 | elim (lift_inv_lref2 … H) -H * #Hid #H destruct /3 width=3/
169 | lapply (lift_inv_gref2 … H) -H #H destruct /2 width=3/
171 | #L #KV #V #W #i #dt #et #Hdti #Hidet #HLKV #HVW #K #d #e #HLK #T1 #H #Hdtd #Hdedet
172 lapply (le_fwd_plus_plus_ge … Hdtd … Hdedet) #Heet
173 elim (lift_inv_lref2 … H) -H * #Hid #H destruct
175 lapply (lt_to_le_to_lt … (dt + (et - e)) Hid ?) [ <le_plus_minus /2 width=1/ ] -Hdedet #Hidete
176 elim (ldrop_conf_lt … HLK … HLKV ?) -L // #L #U #HKL #_ #HUV
177 elim (lift_trans_le … HUV … HVW ?) -V // >minus_plus <plus_minus_m_m // -Hid /3 width=4/
179 lapply (transitive_le … (i - e) Hdtd ?) /2 width=1/ -Hdtd #Hdtie
180 elim (le_inv_plus_l … Hid) #Hdie #Hei
181 lapply (ldrop_conf_ge … HLK … HLKV ?) -L // #HKV
182 elim (lift_split … HVW d (i - e + 1) ? ? ?) -HVW [4: // |3: /2 width=1/ |2: /3 width=1/ ] -Hid -Hdie
183 #V1 #HV1 >plus_minus // <minus_minus // /2 width=1/ <minus_n_n <plus_n_O #H
184 @ex2_intro [3: @H | skip | @tps_subst [3,5,6: // |1,2: skip | >commutative_plus >plus_minus // /2 width=1/ ] ] (**) (* explicit constructor, uses monotonic_lt_minus_l *)
186 | #L #a #I #V1 #V2 #U1 #U2 #dt #et #_ #_ #IHV12 #IHU12 #K #d #e #HLK #X #H #Hdtd #Hdedet
187 elim (lift_inv_bind2 … H) -H #W1 #T1 #HWV1 #HTU1 #H destruct
188 elim (IHV12 … HLK … HWV1 ? ?) -V1 // #W2 #HW12 #HWV2
189 elim (IHU12 … HTU1 ? ?) -U1 [5: @ldrop_skip // |2: skip |3: >plus_plus_comm_23 >(plus_plus_comm_23 dt) /2 width=1/ |4: /2 width=1/ ] (**) (* 29s without the rewrites *)
191 | #L #I #V1 #V2 #U1 #U2 #dt #et #_ #_ #IHV12 #IHU12 #K #d #e #HLK #X #H #Hdtd #Hdedet
192 elim (lift_inv_flat2 … H) -H #W1 #T1 #HWV1 #HTU1 #H destruct
193 elim (IHV12 … HLK … HWV1 ? ?) -V1 //
194 elim (IHU12 … HLK … HTU1 ? ?) -U1 -HLK // /3 width=5/
198 (* Basic_1: was: subst1_gen_lift_ge *)
199 lemma tps_inv_lift1_ge: ∀L,U1,U2,dt,et. L ⊢ U1 ▶ [dt, et] U2 →
200 ∀K,d,e. ⇩[d, e] L ≡ K → ∀T1. ⇧[d, e] T1 ≡ U1 →
202 ∃∃T2. K ⊢ T1 ▶ [dt - e, et] T2 & ⇧[d, e] T2 ≡ U2.
203 #L #U1 #U2 #dt #et #H elim H -L -U1 -U2 -dt -et
204 [ #L * #i #dt #et #K #d #e #_ #T1 #H #_
205 [ lapply (lift_inv_sort2 … H) -H #H destruct /2 width=3/
206 | elim (lift_inv_lref2 … H) -H * #Hid #H destruct /3 width=3/
207 | lapply (lift_inv_gref2 … H) -H #H destruct /2 width=3/
209 | #L #KV #V #W #i #dt #et #Hdti #Hidet #HLKV #HVW #K #d #e #HLK #T1 #H #Hdedt
210 lapply (transitive_le … Hdedt … Hdti) #Hdei
211 elim (le_inv_plus_l … Hdedt) -Hdedt #_ #Hedt
212 elim (le_inv_plus_l … Hdei) #Hdie #Hei
213 lapply (lift_inv_lref2_ge … H … Hdei) -H #H destruct
214 lapply (ldrop_conf_ge … HLK … HLKV ?) -L // #HKV
215 elim (lift_split … HVW d (i - e + 1) ? ? ?) -HVW [4: // |3: /2 width=1/ |2: /3 width=1/ ] -Hdei -Hdie
216 #V0 #HV10 >plus_minus // <minus_minus // /2 width=1/ <minus_n_n <plus_n_O #H
217 @ex2_intro [3: @H | skip | @tps_subst [5,6: // |1,2: skip | /2 width=1/ | >plus_minus // /2 width=1/ ] ] (**) (* explicit constructor, uses monotonic_lt_minus_l *)
218 | #L #a #I #V1 #V2 #U1 #U2 #dt #et #_ #_ #IHV12 #IHU12 #K #d #e #HLK #X #H #Hdetd
219 elim (lift_inv_bind2 … H) -H #W1 #T1 #HWV1 #HTU1 #H destruct
220 elim (le_inv_plus_l … Hdetd) #_ #Hedt
221 elim (IHV12 … HLK … HWV1 ?) -V1 // #W2 #HW12 #HWV2
222 elim (IHU12 … HTU1 ?) -U1 [4: @ldrop_skip // |2: skip |3: /2 width=1/ ]
223 <plus_minus // /3 width=5/
224 | #L #I #V1 #V2 #U1 #U2 #dt #et #_ #_ #IHV12 #IHU12 #K #d #e #HLK #X #H #Hdetd
225 elim (lift_inv_flat2 … H) -H #W1 #T1 #HWV1 #HTU1 #H destruct
226 elim (IHV12 … HLK … HWV1 ?) -V1 //
227 elim (IHU12 … HLK … HTU1 ?) -U1 -HLK // /3 width=5/
231 (* Basic_1: was: subst1_gen_lift_eq *)
232 lemma tps_inv_lift1_eq: ∀L,U1,U2,d,e.
233 L ⊢ U1 ▶ [d, e] U2 → ∀T1. ⇧[d, e] T1 ≡ U1 → U1 = U2.
234 #L #U1 #U2 #d #e #H elim H -L -U1 -U2 -d -e
236 | #L #K #V #W #i #d #e #Hdi #Hide #_ #_ #T1 #H
237 elim (lift_inv_lref2 … H) -H * #H
238 [ lapply (le_to_lt_to_lt … Hdi … H) -Hdi -H #H
239 elim (lt_refl_false … H)
240 | lapply (lt_to_le_to_lt … Hide … H) -Hide -H #H
241 elim (lt_refl_false … H)
243 | #L #a #I #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #X #HX
244 elim (lift_inv_bind2 … HX) -HX #V #T #HV1 #HT1 #H destruct
246 | #L #I #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #X #HX
247 elim (lift_inv_flat2 … HX) -HX #V #T #HV1 #HT1 #H destruct
252 Theorem subst0_gen_lift_rev_ge: (t1,v,u2,i,h,d:?)
253 (subst0 i v t1 (lift h d u2)) ->
255 (EX u1 | (subst0 (minus i h) v u1 u2) &
260 Theorem subst0_gen_lift_rev_lelt: (t1,v,u2,i,h,d:?)
261 (subst0 i v t1 (lift h d u2)) ->
262 (le d i) -> (lt i (plus d h)) ->
263 (EX u1 | t1 = (lift (minus (plus d h) (S i)) (S i) u1)).
265 lemma tps_inv_lift1_ge_up: ∀L,U1,U2,dt,et. L ⊢ U1 ▶ [dt, et] U2 →
266 ∀K,d,e. ⇩[d, e] L ≡ K → ∀T1. ⇧[d, e] T1 ≡ U1 →
267 d ≤ dt → dt ≤ d + e → d + e ≤ dt + et →
268 ∃∃T2. K ⊢ T1 ▶ [d, dt + et - (d + e)] T2 & ⇧[d, e] T2 ≡ U2.
269 #L #U1 #U2 #dt #et #HU12 #K #d #e #HLK #T1 #HTU1 #Hddt #Hdtde #Hdedet
270 elim (tps_split_up … HU12 (d + e) ? ?) -HU12 // -Hdedet #U #HU1 #HU2
271 lapply (tps_weak … HU1 d e ? ?) -HU1 // [ >commutative_plus /2 width=1/ ] -Hddt -Hdtde #HU1
272 lapply (tps_inv_lift1_eq … HU1 … HTU1) -HU1 #HU1 destruct
273 elim (tps_inv_lift1_ge … HU2 … HLK … HTU1 ?) -U -L // <minus_plus_m_m /2 width=3/
276 lemma tps_inv_lift1_be_up: ∀L,U1,U2,dt,et. L ⊢ U1 ▶ [dt, et] U2 →
277 ∀K,d,e. ⇩[d, e] L ≡ K → ∀T1. ⇧[d, e] T1 ≡ U1 →
278 dt ≤ d → dt + et ≤ d + e →
279 ∃∃T2. K ⊢ T1 ▶ [dt, d - dt] T2 & ⇧[d, e] T2 ≡ U2.
280 #L #U1 #U2 #dt #et #HU12 #K #d #e #HLK #T1 #HTU1 #Hdtd #Hdetde
281 lapply (tps_weak … HU12 dt (d + e - dt) ? ?) -HU12 // /2 width=3/ -Hdetde #HU12
282 elim (tps_inv_lift1_be … HU12 … HLK … HTU1 ? ?) -U1 -L // /2 width=3/
285 lemma tps_inv_lift1_le_up: ∀L,U1,U2,dt,et. L ⊢ U1 ▶ [dt, et] U2 →
286 ∀K,d,e. ⇩[d, e] L ≡ K → ∀T1. ⇧[d, e] T1 ≡ U1 →
287 dt ≤ d → d ≤ dt + et → dt + et ≤ d + e →
288 ∃∃T2. K ⊢ T1 ▶ [dt, d - dt] T2 & ⇧[d, e] T2 ≡ U2.
289 #L #U1 #U2 #dt #et #HU12 #K #d #e #HLK #T1 #HTU1 #Hdtd #Hddet #Hdetde
290 elim (tps_split_up … HU12 d ? ?) -HU12 // #U #HU1 #HU2
291 elim (tps_inv_lift1_le … HU1 … HLK … HTU1 ?) -U1 [2: >commutative_plus /2 width=1/ ] -Hdtd #T #HT1 #HTU
292 lapply (tps_weak … HU2 d e ? ?) -HU2 // [ >commutative_plus <plus_minus_m_m // ] -Hddet -Hdetde #HU2
293 lapply (tps_inv_lift1_eq … HU2 … HTU) -L #H destruct /2 width=3/