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( L ⊢ break term 46 T1 break ▶ [ term 46 d , break term 46 e ] break term 46 T2 )"
16 non associative with precedence 45
17 for @{ 'PSubst $L $T1 $d $e $T2 }.
19 include "basic_2/substitution/ldrop_append.ma".
21 (* PARALLEL SUBSTITUTION ON TERMS *******************************************)
23 inductive tps: nat → nat → lenv → relation term ≝
24 | tps_atom : ∀L,I,d,e. tps d e L (⓪{I}) (⓪{I})
25 | tps_subst: ∀L,K,V,W,i,d,e. d ≤ i → i < d + e →
26 ⇩[0, i] L ≡ K. ⓓV → ⇧[0, i + 1] V ≡ W → tps d e L (#i) W
27 | tps_bind : ∀L,a,I,V1,V2,T1,T2,d,e.
28 tps d e L V1 V2 → tps (d + 1) e (L. ⓑ{I} V2) T1 T2 →
29 tps d e L (ⓑ{a,I} V1. T1) (ⓑ{a,I} V2. T2)
30 | tps_flat : ∀L,I,V1,V2,T1,T2,d,e.
31 tps d e L V1 V2 → tps d e L T1 T2 →
32 tps d e L (ⓕ{I} V1. T1) (ⓕ{I} V2. T2)
35 interpretation "parallel substritution (term)"
36 'PSubst L T1 d e T2 = (tps d e L T1 T2).
38 (* Basic properties *********************************************************)
40 lemma tps_lsubr_trans: ∀L1,T1,T2,d,e. L1 ⊢ T1 ▶ [d, e] T2 →
41 ∀L2. L2 ⊑ [d, e] L1 → L2 ⊢ T1 ▶ [d, e] T2.
42 #L1 #T1 #T2 #d #e #H elim H -L1 -T1 -T2 -d -e
44 | #L1 #K1 #V #W #i #d #e #Hdi #Hide #HLK1 #HVW #L2 #HL12
45 elim (ldrop_lsubr_ldrop2_abbr … HL12 … HLK1 ? ?) -HL12 -HLK1 // /2 width=4/
51 lemma tps_refl: ∀T,L,d,e. L ⊢ T ▶ [d, e] T.
53 #I elim I -I /2 width=1/
56 (* Basic_1: was: subst1_ex *)
57 lemma tps_full: ∀K,V,T1,L,d. ⇩[0, d] L ≡ (K. ⓓV) →
58 ∃∃T2,T. L ⊢ T1 ▶ [d, 1] T2 & ⇧[d, 1] T ≡ T2.
60 [ * #i #L #d #HLK /2 width=4/
61 elim (lt_or_eq_or_gt i d) #Hid /3 width=4/
63 elim (lift_total V 0 (i+1)) #W #HVW
64 elim (lift_split … HVW i i ? ? ?) // /3 width=4/
65 | * [ #a ] #I #W1 #U1 #IHW1 #IHU1 #L #d #HLK
66 elim (IHW1 … HLK) -IHW1 #W2 #W #HW12 #HW2
67 [ elim (IHU1 (L. ⓑ{I} W2) (d+1) ?) -IHU1 /2 width=1/ -HLK /3 width=9/
68 | elim (IHU1 … HLK) -IHU1 -HLK /3 width=8/
73 lemma tps_weak: ∀L,T1,T2,d1,e1. L ⊢ T1 ▶ [d1, e1] T2 →
74 ∀d2,e2. d2 ≤ d1 → d1 + e1 ≤ d2 + e2 →
76 #L #T1 #T2 #d1 #e1 #H elim H -L -T1 -T2 -d1 -e1
78 | #L #K #V #W #i #d1 #e1 #Hid1 #Hide1 #HLK #HVW #d2 #e2 #Hd12 #Hde12
79 lapply (transitive_le … Hd12 … Hid1) -Hd12 -Hid1 #Hid2
80 lapply (lt_to_le_to_lt … Hide1 … Hde12) -Hide1 /2 width=4/
86 lemma tps_weak_top: ∀L,T1,T2,d,e.
87 L ⊢ T1 ▶ [d, e] T2 → L ⊢ T1 ▶ [d, |L| - d] T2.
88 #L #T1 #T2 #d #e #H elim H -L -T1 -T2 -d -e
90 | #L #K #V #W #i #d #e #Hdi #_ #HLK #HVW
91 lapply (ldrop_fwd_ldrop2_length … HLK) #Hi
92 lapply (le_to_lt_to_lt … Hdi Hi) /3 width=4/
93 | normalize /2 width=1/
98 lemma tps_weak_full: ∀L,T1,T2,d,e.
99 L ⊢ T1 ▶ [d, e] T2 → L ⊢ T1 ▶ [0, |L|] T2.
100 #L #T1 #T2 #d #e #HT12
101 lapply (tps_weak … HT12 0 (d + e) ? ?) -HT12 // #HT12
102 lapply (tps_weak_top … HT12) //
105 lemma tps_split_up: ∀L,T1,T2,d,e. L ⊢ T1 ▶ [d, e] T2 → ∀i. d ≤ i → i ≤ d + e →
106 ∃∃T. L ⊢ T1 ▶ [d, i - d] T & L ⊢ T ▶ [i, d + e - i] T2.
107 #L #T1 #T2 #d #e #H elim H -L -T1 -T2 -d -e
109 | #L #K #V #W #i #d #e #Hdi #Hide #HLK #HVW #j #Hdj #Hjde
112 >(plus_minus_m_m j d) in ⊢ (% → ?); // -Hdj /3 width=4/
114 lapply (plus_minus_m_m … Hjde) -Hjde /3 width=8/
116 | #L #a #I #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hdi #Hide
117 elim (IHV12 i ? ?) -IHV12 // #V #HV1 #HV2
118 elim (IHT12 (i + 1) ? ?) -IHT12 /2 width=1/
119 -Hdi -Hide >arith_c1x #T #HT1 #HT2
120 lapply (tps_lsubr_trans … HT1 (L. ⓑ{I} V) ?) -HT1 /3 width=5/
121 | #L #I #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hdi #Hide
122 elim (IHV12 i ? ?) -IHV12 // elim (IHT12 i ? ?) -IHT12 //
123 -Hdi -Hide /3 width=5/
127 lemma tps_split_down: ∀L,T1,T2,d,e. L ⊢ T1 ▶ [d, e] T2 →
128 ∀i. d ≤ i → i ≤ d + e →
129 ∃∃T. L ⊢ T1 ▶ [i, d + e - i] T &
130 L ⊢ T ▶ [d, i - d] T2.
131 #L #T1 #T2 #d #e #H elim H -L -T1 -T2 -d -e
133 | #L #K #V #W #i #d #e #Hdi #Hide #HLK #HVW #j #Hdj #Hjde
135 [ -Hide -Hjde >(plus_minus_m_m j d) in ⊢ (% → ?); // -Hdj /3 width=8/
137 >(plus_minus_m_m (d+e) j) in Hide; // -Hjde /3 width=4/
139 | #L #a #I #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hdi #Hide
140 elim (IHV12 i ? ?) -IHV12 // #V #HV1 #HV2
141 elim (IHT12 (i + 1) ? ?) -IHT12 /2 width=1/
142 -Hdi -Hide >arith_c1x #T #HT1 #HT2
143 lapply (tps_lsubr_trans … HT1 (L. ⓑ{I} V) ?) -HT1 /3 width=5/
144 | #L #I #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hdi #Hide
145 elim (IHV12 i ? ?) -IHV12 // elim (IHT12 i ? ?) -IHT12 //
146 -Hdi -Hide /3 width=5/
150 lemma tps_append: ∀K,T1,T2,d,e. K ⊢ T1 ▶ [d, e] T2 →
151 ∀L. L @@ K ⊢ T1 ▶ [d, e] T2.
152 #K #T1 #T2 #d #e #H elim H -K -T1 -T2 -d -e // /2 width=1/
153 #K #K0 #V #W #i #d #e #Hdi #Hide #HK0 #HVW #L
154 lapply (ldrop_fwd_ldrop2_length … HK0) #H
155 @(tps_subst … (L@@K0) … HVW) // (**) (* /3/ does not work *)
156 @(ldrop_O1_append_sn_le … HK0) /2 width=2/
159 (* Basic inversion lemmas ***************************************************)
161 fact tps_inv_atom1_aux: ∀L,T1,T2,d,e. L ⊢ T1 ▶ [d, e] T2 → ∀I. T1 = ⓪{I} →
163 ∃∃K,V,i. d ≤ i & i < d + e &
167 #L #T1 #T2 #d #e * -L -T1 -T2 -d -e
168 [ #L #I #d #e #J #H destruct /2 width=1/
169 | #L #K #V #T2 #i #d #e #Hdi #Hide #HLK #HVT2 #I #H destruct /3 width=8/
170 | #L #a #I #V1 #V2 #T1 #T2 #d #e #_ #_ #J #H destruct
171 | #L #I #V1 #V2 #T1 #T2 #d #e #_ #_ #J #H destruct
175 lemma tps_inv_atom1: ∀L,T2,I,d,e. L ⊢ ⓪{I} ▶ [d, e] T2 →
177 ∃∃K,V,i. d ≤ i & i < d + e &
184 (* Basic_1: was: subst1_gen_sort *)
185 lemma tps_inv_sort1: ∀L,T2,k,d,e. L ⊢ ⋆k ▶ [d, e] T2 → T2 = ⋆k.
187 elim (tps_inv_atom1 … H) -H //
188 * #K #V #i #_ #_ #_ #_ #H destruct
191 (* Basic_1: was: subst1_gen_lref *)
192 lemma tps_inv_lref1: ∀L,T2,i,d,e. L ⊢ #i ▶ [d, e] T2 →
194 ∃∃K,V. d ≤ i & i < d + e &
198 elim (tps_inv_atom1 … H) -H /2 width=1/
199 * #K #V #j #Hdj #Hjde #HLK #HVT2 #H destruct /3 width=4/
202 lemma tps_inv_gref1: ∀L,T2,p,d,e. L ⊢ §p ▶ [d, e] T2 → T2 = §p.
204 elim (tps_inv_atom1 … H) -H //
205 * #K #V #i #_ #_ #_ #_ #H destruct
208 fact tps_inv_bind1_aux: ∀d,e,L,U1,U2. L ⊢ U1 ▶ [d, e] U2 →
209 ∀a,I,V1,T1. U1 = ⓑ{a,I} V1. T1 →
210 ∃∃V2,T2. L ⊢ V1 ▶ [d, e] V2 &
211 L. ⓑ{I} V2 ⊢ T1 ▶ [d + 1, e] T2 &
213 #d #e #L #U1 #U2 * -d -e -L -U1 -U2
214 [ #L #k #d #e #a #I #V1 #T1 #H destruct
215 | #L #K #V #W #i #d #e #_ #_ #_ #_ #a #I #V1 #T1 #H destruct
216 | #L #b #J #V1 #V2 #T1 #T2 #d #e #HV12 #HT12 #a #I #V #T #H destruct /2 width=5/
217 | #L #J #V1 #V2 #T1 #T2 #d #e #_ #_ #a #I #V #T #H destruct
221 lemma tps_inv_bind1: ∀d,e,L,a,I,V1,T1,U2. L ⊢ ⓑ{a,I} V1. T1 ▶ [d, e] U2 →
222 ∃∃V2,T2. L ⊢ V1 ▶ [d, e] V2 &
223 L. ⓑ{I} V2 ⊢ T1 ▶ [d + 1, e] T2 &
227 fact tps_inv_flat1_aux: ∀d,e,L,U1,U2. L ⊢ U1 ▶ [d, e] U2 →
228 ∀I,V1,T1. U1 = ⓕ{I} V1. T1 →
229 ∃∃V2,T2. L ⊢ V1 ▶ [d, e] V2 & L ⊢ T1 ▶ [d, e] T2 &
231 #d #e #L #U1 #U2 * -d -e -L -U1 -U2
232 [ #L #k #d #e #I #V1 #T1 #H destruct
233 | #L #K #V #W #i #d #e #_ #_ #_ #_ #I #V1 #T1 #H destruct
234 | #L #a #J #V1 #V2 #T1 #T2 #d #e #_ #_ #I #V #T #H destruct
235 | #L #J #V1 #V2 #T1 #T2 #d #e #HV12 #HT12 #I #V #T #H destruct /2 width=5/
239 lemma tps_inv_flat1: ∀d,e,L,I,V1,T1,U2. L ⊢ ⓕ{I} V1. T1 ▶ [d, e] U2 →
240 ∃∃V2,T2. L ⊢ V1 ▶ [d, e] V2 & L ⊢ T1 ▶ [d, e] T2 &
244 fact tps_inv_refl_O2_aux: ∀L,T1,T2,d,e. L ⊢ T1 ▶ [d, e] T2 → e = 0 → T1 = T2.
245 #L #T1 #T2 #d #e #H elim H -L -T1 -T2 -d -e
247 | #L #K #V #W #i #d #e #Hdi #Hide #_ #_ #H destruct
248 lapply (le_to_lt_to_lt … Hdi … Hide) -Hdi -Hide <plus_n_O #Hdd
249 elim (lt_refl_false … Hdd)
255 lemma tps_inv_refl_O2: ∀L,T1,T2,d. L ⊢ T1 ▶ [d, 0] T2 → T1 = T2.
258 (* Basic forward lemmas *****************************************************)
260 lemma tps_fwd_tw: ∀L,T1,T2,d,e. L ⊢ T1 ▶ [d, e] T2 → ♯{T1} ≤ ♯{T2}.
261 #L #T1 #T2 #d #e #H elim H -L -T1 -T2 -d -e normalize
262 /3 by monotonic_le_plus_l, le_plus/ (**) (* just /3 width=1/ is too slow *)
265 lemma tps_fwd_shift1: ∀L1,L,T1,T,d,e. L ⊢ L1 @@ T1 ▶[d, e] T →
266 ∃∃L2,T2. |L1| = |L2| & T = L2 @@ T2.
267 #L1 @(lenv_ind_dx … L1) -L1 normalize
268 [ #L #T1 #T #d #e #HT1
269 @(ex2_2_intro … (⋆)) // (**) (* explicit constructor *)
270 | #I #L1 #V1 #IH #L #T1 #X #d #e
271 >shift_append_assoc normalize #H
272 elim (tps_inv_bind1 … H) -H
273 #V0 #T0 #_ #HT10 #H destruct
274 elim (IH … HT10) -IH -HT10 #L2 #T2 #HL12 #H destruct
275 >append_length >HL12 -HL12
276 @(ex2_2_intro … (⋆.ⓑ{I}V0@@L2) T2) [ >append_length ] // /2 width=3/ (**) (* explicit constructor *)
280 (* Basic_1: removed theorems 25:
281 subst0_gen_sort subst0_gen_lref subst0_gen_head subst0_gen_lift_lt
282 subst0_gen_lift_false subst0_gen_lift_ge subst0_refl subst0_trans
283 subst0_lift_lt subst0_lift_ge subst0_lift_ge_S subst0_lift_ge_s
284 subst0_subst0 subst0_subst0_back subst0_weight_le subst0_weight_lt
285 subst0_confluence_neq subst0_confluence_eq subst0_tlt_head
286 subst0_confluence_lift subst0_tlt
287 subst1_head subst1_gen_head subst1_lift_S subst1_confluence_lift