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.ma".
17 (* PARALLEL SUBSTITUTION ON TERMS *******************************************)
19 inductive tps: nat → nat → lenv → relation term ≝
20 | tps_atom : ∀L,I,d,e. tps d e L (⓪{I}) (⓪{I})
21 | tps_subst: ∀L,K,V,W,i,d,e. d ≤ i → i < d + e →
22 ⇩[0, i] L ≡ K. ⓓV → ⇧[0, i + 1] V ≡ W → tps d e L (#i) W
23 | tps_bind : ∀L,a,I,V1,V2,T1,T2,d,e.
24 tps d e L V1 V2 → tps (d + 1) e (L. ⓑ{I} V2) T1 T2 →
25 tps d e L (ⓑ{a,I} V1. T1) (ⓑ{a,I} V2. T2)
26 | tps_flat : ∀L,I,V1,V2,T1,T2,d,e.
27 tps d e L V1 V2 → tps d e L T1 T2 →
28 tps d e L (ⓕ{I} V1. T1) (ⓕ{I} V2. T2)
31 interpretation "parallel substritution (term)"
32 'PSubst L T1 d e T2 = (tps d e L T1 T2).
34 (* Basic properties *********************************************************)
36 lemma tps_lsubs_trans: ∀L1,T1,T2,d,e. L1 ⊢ T1 ▶ [d, e] T2 →
37 ∀L2. L2 ≼ [d, e] L1 → L2 ⊢ T1 ▶ [d, e] T2.
38 #L1 #T1 #T2 #d #e #H elim H -L1 -T1 -T2 -d -e
40 | #L1 #K1 #V #W #i #d #e #Hdi #Hide #HLK1 #HVW #L2 #HL12
41 elim (ldrop_lsubs_ldrop2_abbr … HL12 … HLK1 ? ?) -HL12 -HLK1 // /2 width=4/
47 lemma tps_refl: ∀T,L,d,e. L ⊢ T ▶ [d, e] T.
49 #I elim I -I /2 width=1/
52 (* Basic_1: was: subst1_ex *)
53 lemma tps_full: ∀K,V,T1,L,d. ⇩[0, d] L ≡ (K. ⓓV) →
54 ∃∃T2,T. L ⊢ T1 ▶ [d, 1] T2 & ⇧[d, 1] T ≡ T2.
56 [ * #i #L #d #HLK /2 width=4/
57 elim (lt_or_eq_or_gt i d) #Hid /3 width=4/
59 elim (lift_total V 0 (i+1)) #W #HVW
60 elim (lift_split … HVW i i ? ? ?) // /3 width=4/
61 | * [ #a ] #I #W1 #U1 #IHW1 #IHU1 #L #d #HLK
62 elim (IHW1 … HLK) -IHW1 #W2 #W #HW12 #HW2
63 [ elim (IHU1 (L. ⓑ{I} W2) (d+1) ?) -IHU1 /2 width=1/ -HLK /3 width=9/
64 | elim (IHU1 … HLK) -IHU1 -HLK /3 width=8/
69 lemma tps_weak: ∀L,T1,T2,d1,e1. L ⊢ T1 ▶ [d1, e1] T2 →
70 ∀d2,e2. d2 ≤ d1 → d1 + e1 ≤ d2 + e2 →
72 #L #T1 #T2 #d1 #e1 #H elim H -L -T1 -T2 -d1 -e1
74 | #L #K #V #W #i #d1 #e1 #Hid1 #Hide1 #HLK #HVW #d2 #e2 #Hd12 #Hde12
75 lapply (transitive_le … Hd12 … Hid1) -Hd12 -Hid1 #Hid2
76 lapply (lt_to_le_to_lt … Hide1 … Hde12) -Hide1 /2 width=4/
82 lemma tps_weak_top: ∀L,T1,T2,d,e.
83 L ⊢ T1 ▶ [d, e] T2 → L ⊢ T1 ▶ [d, |L| - d] T2.
84 #L #T1 #T2 #d #e #H elim H -L -T1 -T2 -d -e
86 | #L #K #V #W #i #d #e #Hdi #_ #HLK #HVW
87 lapply (ldrop_fwd_ldrop2_length … HLK) #Hi
88 lapply (le_to_lt_to_lt … Hdi Hi) /3 width=4/
89 | normalize /2 width=1/
94 lemma tps_weak_all: ∀L,T1,T2,d,e.
95 L ⊢ T1 ▶ [d, e] T2 → L ⊢ T1 ▶ [0, |L|] T2.
96 #L #T1 #T2 #d #e #HT12
97 lapply (tps_weak … HT12 0 (d + e) ? ?) -HT12 // #HT12
98 lapply (tps_weak_top … HT12) //
101 lemma tps_split_up: ∀L,T1,T2,d,e. L ⊢ T1 ▶ [d, e] T2 → ∀i. d ≤ i → i ≤ d + e →
102 ∃∃T. L ⊢ T1 ▶ [d, i - d] T & L ⊢ T ▶ [i, d + e - i] T2.
103 #L #T1 #T2 #d #e #H elim H -L -T1 -T2 -d -e
105 | #L #K #V #W #i #d #e #Hdi #Hide #HLK #HVW #j #Hdj #Hjde
108 >(plus_minus_m_m j d) in ⊢ (% → ?); // -Hdj /3 width=4/
110 generalize in match Hide; -Hide (**) (* rewriting in the premises, rewrites in the goal too *)
111 >(plus_minus_m_m … Hjde) in ⊢ (% → ?); -Hjde /4 width=4/
113 | #L #a #I #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hdi #Hide
114 elim (IHV12 i ? ?) -IHV12 // #V #HV1 #HV2
115 elim (IHT12 (i + 1) ? ?) -IHT12 /2 width=1/
116 -Hdi -Hide >arith_c1x #T #HT1 #HT2
117 lapply (tps_lsubs_trans … HT1 (L. ⓑ{I} V) ?) -HT1 /3 width=5/
118 | #L #I #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hdi #Hide
119 elim (IHV12 i ? ?) -IHV12 // elim (IHT12 i ? ?) -IHT12 //
120 -Hdi -Hide /3 width=5/
124 lemma tps_split_down: ∀L,T1,T2,d,e. L ⊢ T1 ▶ [d, e] T2 →
125 ∀i. d ≤ i → i ≤ d + e →
126 ∃∃T. L ⊢ T1 ▶ [i, d + e - i] T &
127 L ⊢ T ▶ [d, i - d] T2.
128 #L #T1 #T2 #d #e #H elim H -L -T1 -T2 -d -e
130 | #L #K #V #W #i #d #e #Hdi #Hide #HLK #HVW #j #Hdj #Hjde
132 [ -Hide -Hjde >(plus_minus_m_m j d) in ⊢ (% → ?); // -Hdj /4 width=4/
134 >(plus_minus_m_m (d+e) j) in Hide; // -Hjde /3 width=4/
136 | #L #a #I #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hdi #Hide
137 elim (IHV12 i ? ?) -IHV12 // #V #HV1 #HV2
138 elim (IHT12 (i + 1) ? ?) -IHT12 /2 width=1/
139 -Hdi -Hide >arith_c1x #T #HT1 #HT2
140 lapply (tps_lsubs_trans … HT1 (L. ⓑ{I} V) ?) -HT1 /3 width=5/
141 | #L #I #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hdi #Hide
142 elim (IHV12 i ? ?) -IHV12 // elim (IHT12 i ? ?) -IHT12 //
143 -Hdi -Hide /3 width=5/
147 (* Basic inversion lemmas ***************************************************)
149 fact tps_inv_atom1_aux: ∀L,T1,T2,d,e. L ⊢ T1 ▶ [d, e] T2 → ∀I. T1 = ⓪{I} →
151 ∃∃K,V,i. d ≤ i & i < d + e &
155 #L #T1 #T2 #d #e * -L -T1 -T2 -d -e
156 [ #L #I #d #e #J #H destruct /2 width=1/
157 | #L #K #V #T2 #i #d #e #Hdi #Hide #HLK #HVT2 #I #H destruct /3 width=8/
158 | #L #a #I #V1 #V2 #T1 #T2 #d #e #_ #_ #J #H destruct
159 | #L #I #V1 #V2 #T1 #T2 #d #e #_ #_ #J #H destruct
163 lemma tps_inv_atom1: ∀L,T2,I,d,e. L ⊢ ⓪{I} ▶ [d, e] T2 →
165 ∃∃K,V,i. d ≤ i & i < d + e &
172 (* Basic_1: was: subst1_gen_sort *)
173 lemma tps_inv_sort1: ∀L,T2,k,d,e. L ⊢ ⋆k ▶ [d, e] T2 → T2 = ⋆k.
175 elim (tps_inv_atom1 … H) -H //
176 * #K #V #i #_ #_ #_ #_ #H destruct
179 (* Basic_1: was: subst1_gen_lref *)
180 lemma tps_inv_lref1: ∀L,T2,i,d,e. L ⊢ #i ▶ [d, e] T2 →
182 ∃∃K,V. d ≤ i & i < d + e &
186 elim (tps_inv_atom1 … H) -H /2 width=1/
187 * #K #V #j #Hdj #Hjde #HLK #HVT2 #H destruct /3 width=4/
190 lemma tps_inv_gref1: ∀L,T2,p,d,e. L ⊢ §p ▶ [d, e] T2 → T2 = §p.
192 elim (tps_inv_atom1 … H) -H //
193 * #K #V #i #_ #_ #_ #_ #H destruct
196 fact tps_inv_bind1_aux: ∀d,e,L,U1,U2. L ⊢ U1 ▶ [d, e] U2 →
197 ∀a,I,V1,T1. U1 = ⓑ{a,I} V1. T1 →
198 ∃∃V2,T2. L ⊢ V1 ▶ [d, e] V2 &
199 L. ⓑ{I} V2 ⊢ T1 ▶ [d + 1, e] T2 &
201 #d #e #L #U1 #U2 * -d -e -L -U1 -U2
202 [ #L #k #d #e #a #I #V1 #T1 #H destruct
203 | #L #K #V #W #i #d #e #_ #_ #_ #_ #a #I #V1 #T1 #H destruct
204 | #L #b #J #V1 #V2 #T1 #T2 #d #e #HV12 #HT12 #a #I #V #T #H destruct /2 width=5/
205 | #L #J #V1 #V2 #T1 #T2 #d #e #_ #_ #a #I #V #T #H destruct
209 lemma tps_inv_bind1: ∀d,e,L,a,I,V1,T1,U2. L ⊢ ⓑ{a,I} V1. T1 ▶ [d, e] U2 →
210 ∃∃V2,T2. L ⊢ V1 ▶ [d, e] V2 &
211 L. ⓑ{I} V2 ⊢ T1 ▶ [d + 1, e] T2 &
215 fact tps_inv_flat1_aux: ∀d,e,L,U1,U2. L ⊢ U1 ▶ [d, e] U2 →
216 ∀I,V1,T1. U1 = ⓕ{I} V1. T1 →
217 ∃∃V2,T2. L ⊢ V1 ▶ [d, e] V2 & L ⊢ T1 ▶ [d, e] T2 &
219 #d #e #L #U1 #U2 * -d -e -L -U1 -U2
220 [ #L #k #d #e #I #V1 #T1 #H destruct
221 | #L #K #V #W #i #d #e #_ #_ #_ #_ #I #V1 #T1 #H destruct
222 | #L #a #J #V1 #V2 #T1 #T2 #d #e #_ #_ #I #V #T #H destruct
223 | #L #J #V1 #V2 #T1 #T2 #d #e #HV12 #HT12 #I #V #T #H destruct /2 width=5/
227 lemma tps_inv_flat1: ∀d,e,L,I,V1,T1,U2. L ⊢ ⓕ{I} V1. T1 ▶ [d, e] U2 →
228 ∃∃V2,T2. L ⊢ V1 ▶ [d, e] V2 & L ⊢ T1 ▶ [d, e] T2 &
232 fact tps_inv_refl_O2_aux: ∀L,T1,T2,d,e. L ⊢ T1 ▶ [d, e] T2 → e = 0 → T1 = T2.
233 #L #T1 #T2 #d #e #H elim H -L -T1 -T2 -d -e
235 | #L #K #V #W #i #d #e #Hdi #Hide #_ #_ #H destruct
236 lapply (le_to_lt_to_lt … Hdi … Hide) -Hdi -Hide <plus_n_O #Hdd
237 elim (lt_refl_false … Hdd)
243 lemma tps_inv_refl_O2: ∀L,T1,T2,d. L ⊢ T1 ▶ [d, 0] T2 → T1 = T2.
246 (* Basic forward lemmas *****************************************************)
248 lemma tps_fwd_tw: ∀L,T1,T2,d,e. L ⊢ T1 ▶ [d, e] T2 → #[T1] ≤ #[T2].
249 #L #T1 #T2 #d #e #H elim H -L -T1 -T2 -d -e normalize
250 /3 by monotonic_le_plus_l, le_plus/ (**) (* just /3 width=1/ is too slow *)
253 (* Basic_1: removed theorems 25:
254 subst0_gen_sort subst0_gen_lref subst0_gen_head subst0_gen_lift_lt
255 subst0_gen_lift_false subst0_gen_lift_ge subst0_refl subst0_trans
256 subst0_lift_lt subst0_lift_ge subst0_lift_ge_S subst0_lift_ge_s
257 subst0_subst0 subst0_subst0_back subst0_weight_le subst0_weight_lt
258 subst0_confluence_neq subst0_confluence_eq subst0_tlt_head
259 subst0_confluence_lift subst0_tlt
260 subst1_head subst1_gen_head subst1_lift_S subst1_confluence_lift