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/grammar/cl_weight.ma".
16 include "basic_2/substitution/ldrop.ma".
18 (* PARALLEL SUBSTITUTION ON TERMS *******************************************)
20 inductive tps: nat → nat → lenv → relation term ≝
21 | tps_atom : ∀L,I,d,e. tps d e L (⓪{I}) (⓪{I})
22 | tps_subst: ∀L,K,V,W,i,d,e. d ≤ i → i < d + e →
23 ⇩[0, i] L ≡ K. ⓓV → ⇧[0, i + 1] V ≡ W → tps d e L (#i) W
24 | tps_bind : ∀L,I,V1,V2,T1,T2,d,e.
25 tps d e L V1 V2 → tps (d + 1) e (L. ⓑ{I} V2) T1 T2 →
26 tps d e L (ⓑ{I} V1. T1) (ⓑ{I} V2. T2)
27 | tps_flat : ∀L,I,V1,V2,T1,T2,d,e.
28 tps d e L V1 V2 → tps d e L T1 T2 →
29 tps d e L (ⓕ{I} V1. T1) (ⓕ{I} V2. T2)
32 interpretation "parallel substritution (term)"
33 'PSubst L T1 d e T2 = (tps d e L T1 T2).
35 (* Basic properties *********************************************************)
37 lemma tps_lsubs_conf: ∀L1,T1,T2,d,e. L1 ⊢ T1 [d, e] ▶ T2 →
38 ∀L2. L1 [d, e] ≼ L2 → L2 ⊢ T1 [d, e] ▶ T2.
39 #L1 #T1 #T2 #d #e #H elim H -L1 -T1 -T2 -d -e
41 | #L1 #K1 #V #W #i #d #e #Hdi #Hide #HLK1 #HVW #L2 #HL12
42 elim (ldrop_lsubs_ldrop1_abbr … HL12 … HLK1 ? ?) -HL12 -HLK1 // /2 width=4/
48 lemma tps_refl: ∀T,L,d,e. L ⊢ T [d, e] ▶ T.
50 #I elim I -I /2 width=1/
53 (* Basic_1: was: subst1_ex *)
54 lemma tps_full: ∀K,V,T1,L,d. ⇩[0, d] L ≡ (K. ⓓV) →
55 ∃∃T2,T. L ⊢ T1 [d, 1] ▶ T2 & ⇧[d, 1] T ≡ T2.
57 [ * #i #L #d #HLK /2 width=4/
58 elim (lt_or_eq_or_gt i d) #Hid /3 width=4/
60 elim (lift_total V 0 (i+1)) #W #HVW
61 elim (lift_split … HVW i i ? ? ?) // /3 width=4/
62 | * #I #W1 #U1 #IHW1 #IHU1 #L #d #HLK
63 elim (IHW1 … HLK) -IHW1 #W2 #W #HW12 #HW2
64 [ elim (IHU1 (L. ⓑ{I} W2) (d+1) ?) -IHU1 /2 width=1/ -HLK /3 width=8/
65 | elim (IHU1 … HLK) -IHU1 -HLK /3 width=8/
70 lemma tps_weak: ∀L,T1,T2,d1,e1. L ⊢ T1 [d1, e1] ▶ T2 →
71 ∀d2,e2. d2 ≤ d1 → d1 + e1 ≤ d2 + e2 →
73 #L #T1 #T2 #d1 #e1 #H elim H -L -T1 -T2 -d1 -e1
75 | #L #K #V #W #i #d1 #e1 #Hid1 #Hide1 #HLK #HVW #d2 #e2 #Hd12 #Hde12
76 lapply (transitive_le … Hd12 … Hid1) -Hd12 -Hid1 #Hid2
77 lapply (lt_to_le_to_lt … Hide1 … Hde12) -Hide1 /2 width=4/
83 lemma tps_weak_top: ∀L,T1,T2,d,e.
84 L ⊢ T1 [d, e] ▶ T2 → L ⊢ T1 [d, |L| - d] ▶ T2.
85 #L #T1 #T2 #d #e #H elim H -L -T1 -T2 -d -e
87 | #L #K #V #W #i #d #e #Hdi #_ #HLK #HVW
88 lapply (ldrop_fwd_ldrop2_length … HLK) #Hi
89 lapply (le_to_lt_to_lt … Hdi Hi) /3 width=4/
90 | normalize /2 width=1/
95 lemma tps_weak_all: ∀L,T1,T2,d,e.
96 L ⊢ T1 [d, e] ▶ T2 → L ⊢ T1 [0, |L|] ▶ T2.
97 #L #T1 #T2 #d #e #HT12
98 lapply (tps_weak … HT12 0 (d + e) ? ?) -HT12 // #HT12
99 lapply (tps_weak_top … HT12) //
102 lemma tps_split_up: ∀L,T1,T2,d,e. L ⊢ T1 [d, e] ▶ T2 → ∀i. d ≤ i → i ≤ d + e →
103 ∃∃T. L ⊢ T1 [d, i - d] ▶ T & L ⊢ T [i, d + e - i] ▶ T2.
104 #L #T1 #T2 #d #e #H elim H -L -T1 -T2 -d -e
106 | #L #K #V #W #i #d #e #Hdi #Hide #HLK #HVW #j #Hdj #Hjde
109 >(plus_minus_m_m j d) in ⊢ (% → ?); // -Hdj /3 width=4/
111 generalize in match Hide; -Hide (**) (* rewriting in the premises, rewrites in the goal too *)
112 >(plus_minus_m_m … Hjde) in ⊢ (% → ?); -Hjde /4 width=4/
114 | #L #I #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hdi #Hide
115 elim (IHV12 i ? ?) -IHV12 // #V #HV1 #HV2
116 elim (IHT12 (i + 1) ? ?) -IHT12 /2 width=1/
117 -Hdi -Hide >arith_c1x #T #HT1 #HT2
118 lapply (tps_lsubs_conf … HT1 (L. ⓑ{I} V) ?) -HT1 /3 width=5/
119 | #L #I #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hdi #Hide
120 elim (IHV12 i ? ?) -IHV12 // elim (IHT12 i ? ?) -IHT12 //
121 -Hdi -Hide /3 width=5/
125 (* Basic inversion lemmas ***************************************************)
127 fact tps_inv_atom1_aux: ∀L,T1,T2,d,e. L ⊢ T1 [d, e] ▶ T2 → ∀I. T1 = ⓪{I} →
129 ∃∃K,V,i. d ≤ i & i < d + e &
133 #L #T1 #T2 #d #e * -L -T1 -T2 -d -e
134 [ #L #I #d #e #J #H destruct /2 width=1/
135 | #L #K #V #T2 #i #d #e #Hdi #Hide #HLK #HVT2 #I #H destruct /3 width=8/
136 | #L #I #V1 #V2 #T1 #T2 #d #e #_ #_ #J #H destruct
137 | #L #I #V1 #V2 #T1 #T2 #d #e #_ #_ #J #H destruct
141 lemma tps_inv_atom1: ∀L,T2,I,d,e. L ⊢ ⓪{I} [d, e] ▶ T2 →
143 ∃∃K,V,i. d ≤ i & i < d + e &
150 (* Basic_1: was: subst1_gen_sort *)
151 lemma tps_inv_sort1: ∀L,T2,k,d,e. L ⊢ ⋆k [d, e] ▶ T2 → T2 = ⋆k.
153 elim (tps_inv_atom1 … H) -H //
154 * #K #V #i #_ #_ #_ #_ #H destruct
157 (* Basic_1: was: subst1_gen_lref *)
158 lemma tps_inv_lref1: ∀L,T2,i,d,e. L ⊢ #i [d, e] ▶ T2 →
160 ∃∃K,V. d ≤ i & i < d + e &
164 elim (tps_inv_atom1 … H) -H /2 width=1/
165 * #K #V #j #Hdj #Hjde #HLK #HVT2 #H destruct /3 width=4/
168 lemma tps_inv_gref1: ∀L,T2,p,d,e. L ⊢ §p [d, e] ▶ T2 → T2 = §p.
170 elim (tps_inv_atom1 … H) -H //
171 * #K #V #i #_ #_ #_ #_ #H destruct
174 fact tps_inv_bind1_aux: ∀d,e,L,U1,U2. L ⊢ U1 [d, e] ▶ U2 →
175 ∀I,V1,T1. U1 = ⓑ{I} V1. T1 →
176 ∃∃V2,T2. L ⊢ V1 [d, e] ▶ V2 &
177 L. ⓑ{I} V2 ⊢ T1 [d + 1, e] ▶ T2 &
179 #d #e #L #U1 #U2 * -d -e -L -U1 -U2
180 [ #L #k #d #e #I #V1 #T1 #H destruct
181 | #L #K #V #W #i #d #e #_ #_ #_ #_ #I #V1 #T1 #H destruct
182 | #L #J #V1 #V2 #T1 #T2 #d #e #HV12 #HT12 #I #V #T #H destruct /2 width=5/
183 | #L #J #V1 #V2 #T1 #T2 #d #e #_ #_ #I #V #T #H destruct
187 lemma tps_inv_bind1: ∀d,e,L,I,V1,T1,U2. L ⊢ ⓑ{I} V1. T1 [d, e] ▶ U2 →
188 ∃∃V2,T2. L ⊢ V1 [d, e] ▶ V2 &
189 L. ⓑ{I} V2 ⊢ T1 [d + 1, e] ▶ T2 &
193 fact tps_inv_flat1_aux: ∀d,e,L,U1,U2. L ⊢ U1 [d, e] ▶ U2 →
194 ∀I,V1,T1. U1 = ⓕ{I} V1. T1 →
195 ∃∃V2,T2. L ⊢ V1 [d, e] ▶ V2 & L ⊢ T1 [d, e] ▶ T2 &
197 #d #e #L #U1 #U2 * -d -e -L -U1 -U2
198 [ #L #k #d #e #I #V1 #T1 #H destruct
199 | #L #K #V #W #i #d #e #_ #_ #_ #_ #I #V1 #T1 #H destruct
200 | #L #J #V1 #V2 #T1 #T2 #d #e #_ #_ #I #V #T #H destruct
201 | #L #J #V1 #V2 #T1 #T2 #d #e #HV12 #HT12 #I #V #T #H destruct /2 width=5/
205 lemma tps_inv_flat1: ∀d,e,L,I,V1,T1,U2. L ⊢ ⓕ{I} V1. T1 [d, e] ▶ U2 →
206 ∃∃V2,T2. L ⊢ V1 [d, e] ▶ V2 & L ⊢ T1 [d, e] ▶ T2 &
210 fact tps_inv_refl_O2_aux: ∀L,T1,T2,d,e. L ⊢ T1 [d, e] ▶ T2 → e = 0 → T1 = T2.
211 #L #T1 #T2 #d #e #H elim H -L -T1 -T2 -d -e
213 | #L #K #V #W #i #d #e #Hdi #Hide #_ #_ #H destruct
214 lapply (le_to_lt_to_lt … Hdi … Hide) -Hdi -Hide <plus_n_O #Hdd
215 elim (lt_refl_false … Hdd)
221 lemma tps_inv_refl_O2: ∀L,T1,T2,d. L ⊢ T1 [d, 0] ▶ T2 → T1 = T2.
224 (* Basic forward lemmas *****************************************************)
226 lemma tps_fwd_tw: ∀L,T1,T2,d,e. L ⊢ T1 [d, e] ▶ T2 → #[T1] ≤ #[T2].
227 #L #T1 #T2 #d #e #H elim H -L -T1 -T2 -d -e normalize
228 /3 by monotonic_le_plus_l, le_plus/ (**) (* just /3 width=1/ is too slow *)
231 (* Basic_1: removed theorems 25:
232 subst0_gen_sort subst0_gen_lref subst0_gen_head subst0_gen_lift_lt
233 subst0_gen_lift_false subst0_gen_lift_ge subst0_refl subst0_trans
234 subst0_lift_lt subst0_lift_ge subst0_lift_ge_S subst0_lift_ge_s
235 subst0_subst0 subst0_subst0_back subst0_weight_le subst0_weight_lt
236 subst0_confluence_neq subst0_confluence_eq subst0_tlt_head
237 subst0_confluence_lift subst0_tlt
238 subst1_head subst1_gen_head subst1_lift_S subst1_confluence_lift