]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/lib/lambda/terms/relocating_substitution.ma
826c458d70ed7753c83b637d537f0c134a636c1e
[helm.git] / matita / matita / lib / lambda / terms / relocating_substitution.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 "lambda/terms/relocation.ma".
16
17 (* RELOCATING SUBSTITUTION **************************************************)
18
19 (* Policy: depth (level) metavariables: d, e (as for lift) *)
20 let rec dsubst N d M on M ≝ match M with
21 [ VRef i   ⇒ tri … i d (#i) (↑[i] N) (#(i-1))
22 | Abst A   ⇒ 𝛌. (dsubst N (d+1) A)
23 | Appl B A ⇒ @ (dsubst N d B). (dsubst N d A)
24 ].
25
26 interpretation "relocating substitution"
27    'DSubst N d M = (dsubst N d M).
28
29 lemma dsubst_vref_lt: ∀i,d,N. i < d → [d ↙ N] #i = #i.
30 normalize /2 width=1/
31 qed.
32
33 lemma dsubst_vref_eq: ∀i,N. [i ↙ N] #i = ↑[i]N.
34 normalize //
35 qed.
36
37 lemma dsubst_vref_gt: ∀i,d,N. d < i → [d ↙ N] #i = #(i-1).
38 normalize /2 width=1/
39 qed.
40
41 theorem dsubst_lift_le: ∀h,N,M,d1,d2. d2 ≤ d1 →
42                         [d2 ↙ ↑[d1 - d2, h] N] ↑[d1 + 1, h] M = ↑[d1, h] [d2 ↙ N] M.
43 #h #N #M elim M -M
44 [ #i #d1 #d2 #Hd21 elim (lt_or_eq_or_gt i d2) #Hid2
45   [ lapply (lt_to_le_to_lt … Hid2 Hd21) -Hd21 #Hid1
46     >(dsubst_vref_lt … Hid2) >(lift_vref_lt … Hid1) >lift_vref_lt /2 width=1/
47   | destruct >dsubst_vref_eq >lift_vref_lt /2 width=1/
48   | >(dsubst_vref_gt … Hid2) -Hd21 elim (lt_or_ge (i-1) d1) #Hi1d1
49     [ >(lift_vref_lt … Hi1d1) >lift_vref_lt /2 width=1/
50     | lapply (ltn_to_ltO … Hid2) #Hi
51       >(lift_vref_ge … Hi1d1) >lift_vref_ge /2 width=1/ -Hi1d1 >plus_minus // /3 width=1/
52     ]
53   ]
54 | normalize #A #IHA #d1 #d2 #Hd21
55   lapply (IHA (d1+1) (d2+1) ?) -IHA /2 width=1/
56 | normalize #B #A #IHB #IHA #d1 #d2 #Hd21
57   >IHB -IHB // >IHA -IHA //
58 ]
59 qed.
60
61 theorem dsubst_lift_be: ∀h,N,M,d1,d2. d1 ≤ d2 → d2 ≤ d1 + h →
62                         [d2 ↙ N] ↑[d1, h + 1] M = ↑[d1, h] M.
63 #h #N #M elim M -M
64 [ #i #d1 #d2 #Hd12 #Hd21 elim (lt_or_ge i d1) #Hid1
65   [ lapply (lt_to_le_to_lt … Hid1 Hd12) -Hd12 -Hd21 #Hid2
66     >(lift_vref_lt … Hid1) >(lift_vref_lt … Hid1) /2 width=1/
67   | lapply (transitive_le … (i+h) Hd21 ?) -Hd12 -Hd21 /2 width=1/ #Hd2
68     >(lift_vref_ge … Hid1) >(lift_vref_ge … Hid1) -Hid1
69     >dsubst_vref_gt // /2 width=1/
70   ]
71 | normalize #A #IHA #d1 #d2 #Hd12 #Hd21
72   >IHA -IHA // /2 width=1/
73 | normalize #B #A #IHB #IHA #d1 #d2 #Hd12 #Hd21
74   >IHB -IHB // >IHA -IHA //
75 ]
76 qed.
77
78 theorem dsubst_lift_ge: ∀h,N,M,d1,d2. d1 + h ≤ d2 →
79                         [d2 ↙ N] ↑[d1, h] M = ↑[d1, h] [d2 - h ↙ N] M.
80 #h #N #M elim M -M
81 [ #i #d1 #d2 #Hd12 elim (lt_or_eq_or_gt i (d2-h)) #Hid2h
82   [ >(dsubst_vref_lt … Hid2h) elim (lt_or_ge i d1) #Hid1
83     [ lapply (lt_to_le_to_lt … (d1+h) Hid1 ?) -Hid2h // #Hid1h
84       lapply (lt_to_le_to_lt … Hid1h Hd12) -Hid1h -Hd12 #Hid2
85       >(lift_vref_lt … Hid1) -Hid1 /2 width=1/
86     | >(lift_vref_ge … Hid1) -Hid1 -Hd12 /3 width=1/
87     ]
88   | destruct elim (le_inv_plus_l … Hd12) -Hd12 #Hd12 #Hhd2
89     >dsubst_vref_eq >lift_vref_ge // >lift_lift_be // <plus_minus_m_m //
90   | elim (le_inv_plus_l … Hd12) -Hd12 #Hd12 #_
91     lapply (le_to_lt_to_lt … Hd12 Hid2h) -Hd12 #Hid1
92     lapply (ltn_to_ltO … Hid2h) #Hi
93     >(dsubst_vref_gt … Hid2h)
94     >lift_vref_ge /2 width=1/ >lift_vref_ge /2 width=1/ -Hid1
95     >dsubst_vref_gt /2 width=1/ -Hid2h >plus_minus //
96   ]
97 | normalize #A #IHA #d1 #d2 #Hd12
98   elim (le_inv_plus_l … Hd12) #_ #Hhd2
99   >IHA -IHA /2 width=1/ <plus_minus //
100 | normalize #B #A #IHB #IHA #d1 #d2 #Hd12
101   >IHB -IHB // >IHA -IHA //
102 ]
103 qed.
104
105 theorem dsubst_dsubst_ge: ∀N1,N2,M,d1,d2. d1 ≤ d2 →
106                           [d2 ↙ N2] [d1 ↙ N1] M = [d1 ↙ [d2 - d1 ↙ N2] N1] [d2 + 1 ↙ N2] M.
107 #N1 #N2 #M elim M -M
108 [ #i #d1 #d2 #Hd12 elim (lt_or_eq_or_gt i d1) #Hid1
109   [ lapply (lt_to_le_to_lt … Hid1 Hd12) -Hd12 #Hid2
110     >(dsubst_vref_lt … Hid1) >(dsubst_vref_lt … Hid2) >dsubst_vref_lt /2 width=1/
111   | destruct >dsubst_vref_eq >dsubst_vref_lt /2 width=1/
112   | >(dsubst_vref_gt … Hid1) elim (lt_or_eq_or_gt i (d2+1)) #Hid2
113     [ lapply (ltn_to_ltO … Hid1) #Hi
114       >(dsubst_vref_lt … Hid2) >dsubst_vref_lt /2 width=1/
115     | destruct /2 width=1/
116     | lapply (le_to_lt_to_lt (d1+1) … Hid2) -Hid1 /2 width=1/ -Hd12 #Hid1
117       >(dsubst_vref_gt … Hid2) >dsubst_vref_gt /2 width=1/
118       >dsubst_vref_gt // /2 width=1/
119     ]
120   ]
121 | normalize #A #IHA #d1 #d2 #Hd12
122   lapply (IHA (d1+1) (d2+1) ?) -IHA /2 width=1/
123 | normalize #B #A #IHB #IHA #d1 #d2 #Hd12
124   >IHB -IHB // >IHA -IHA //
125 ]
126 qed.
127
128 theorem dsubst_dsubst_lt: ∀N1,N2,M,d1,d2. d2 < d1 →
129                           [d2 ↙ [d1 - d2 -1 ↙ N1] N2] [d1 ↙ N1] M = [d1 - 1 ↙ N1] [d2 ↙ N2] M.
130 #N1 #N2 #M #d1 #d2 #Hd21
131 lapply (ltn_to_ltO … Hd21) #Hd1
132 >dsubst_dsubst_ge in ⊢ (???%); /2 width=1/ <plus_minus_m_m //
133 qed.
134
135 definition dsubstable_dx: predicate (relation term) ≝ λR.
136                           ∀N,M1,M2. R M1 M2 → ∀d. R ([d ↙ N] M1) ([d ↙ N] M2).
137
138 definition dsubstable: predicate (relation term) ≝ λR.
139                        ∀N1,N2. R N1 N2 → ∀M1,M2. R M1 M2 → ∀d. R ([d ↙ N1] M1) ([d ↙ N2] M2).
140
141 lemma star_dsubstable_dx: ∀R. dsubstable_dx R → dsubstable_dx (star … R).
142 #R #HR #N #M1 #M2 #H elim H -M2 // /3 width=3/
143 qed.
144
145 lemma lstar_dsubstable_dx: ∀S,R. (∀a. dsubstable_dx (R a)) →
146                            ∀l. dsubstable_dx (lstar S … R l).
147 #S #R #HR #l #N #M1 #M2 #H
148 @(lstar_ind_l … l M1 H) -l -M1 // /3 width=3/
149 qed.
150
151 lemma star_dsubstable: ∀R. reflexive ? R →
152                        dsubstable R → dsubstable (star … R).
153 #R #H1R #H2 #N1 #N2 #H elim H -N2 /3 width=1/ /3 width=5/
154 qed.