]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambda_delta/basic_2/unfold/tpss.ma
93916208b649a6d301c53ab4ef1e56f9d6417871
[helm.git] / matita / matita / contribs / lambda_delta / basic_2 / unfold / tpss.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 "basic_2/substitution/tps.ma".
16
17 (* PARTIAL UNFOLD ON TERMS **************************************************)
18
19 definition tpss: nat → nat → lenv → relation term ≝
20                  λd,e,L. TC … (tps d e L).
21
22 interpretation "partial unfold (term)"
23    'PSubstStar L T1 d e T2 = (tpss d e L T1 T2).
24
25 (* Basic eliminators ********************************************************)
26
27 lemma tpss_ind: ∀d,e,L,T1. ∀R:predicate term. R T1 →
28                 (∀T,T2. L ⊢ T1 ▶* [d, e] T → L ⊢ T ▶ [d, e] T2 → R T → R T2) →
29                 ∀T2. L ⊢ T1 ▶* [d, e] T2 → R T2.
30 #d #e #L #T1 #R #HT1 #IHT1 #T2 #HT12
31 @(TC_star_ind … HT1 IHT1 … HT12) //
32 qed-.
33
34 lemma tpss_ind_dx: ∀d,e,L,T2. ∀R:predicate term. R T2 →
35                    (∀T1,T. L ⊢ T1 ▶ [d, e] T → L ⊢ T ▶* [d, e] T2 → R T → R T1) →
36                    ∀T1. L ⊢ T1 ▶* [d, e] T2 → R T1.
37 #d #e #L #T2 #R #HT2 #IHT2 #T1 #HT12
38 @(TC_star_ind_dx … HT2 IHT2 … HT12) //
39 qed-.
40
41 (* Basic properties *********************************************************)
42
43 lemma tpss_strap1: ∀L,T1,T,T2,d,e.
44                    L ⊢ T1 ▶* [d, e] T → L ⊢ T ▶ [d, e] T2 → L ⊢ T1 ▶* [d, e] T2. 
45 /2 width=3/ qed.
46
47 lemma tpss_strap2: ∀L,T1,T,T2,d,e.
48                    L ⊢ T1 ▶ [d, e] T → L ⊢ T ▶* [d, e] T2 → L ⊢ T1 ▶* [d, e] T2. 
49 /2 width=3/ qed.
50
51 lemma tpss_lsubs_trans: ∀L1,T1,T2,d,e. L1 ⊢ T1 ▶* [d, e] T2 →
52                         ∀L2. L2 ≼ [d, e] L1 → L2 ⊢ T1 ▶* [d, e] T2.
53 /3 width=3/ qed.
54
55 lemma tpss_refl: ∀d,e,L,T. L ⊢ T ▶* [d, e] T.
56 /2 width=1/ qed.
57
58 lemma tpss_bind: ∀L,V1,V2,d,e. L ⊢ V1 ▶* [d, e] V2 →
59                  ∀a,I,T1,T2. L. ⓑ{I} V2 ⊢ T1 ▶* [d + 1, e] T2 →
60                  L ⊢ ⓑ{a,I} V1. T1 ▶* [d, e] ⓑ{a,I} V2. T2.
61 #L #V1 #V2 #d #e #HV12 elim HV12 -V2
62 [ #V2 #HV12 #a #I #T1 #T2 #HT12 elim HT12 -T2
63   [ /3 width=5/
64   | #T #T2 #_ #HT2 #IHT @step /2 width=5/ (**) (* /3 width=5/ is too slow *)
65   ]
66 | #V #V2 #_ #HV12 #IHV #a #I #T1 #T2 #HT12
67   lapply (tpss_lsubs_trans … HT12 (L. ⓑ{I} V) ?) -HT12 /2 width=1/ #HT12
68   lapply (IHV a … HT12) -IHV -HT12 #HT12 @step /2 width=5/ (**) (* /3 width=5/ is too slow *)
69 ]
70 qed.
71
72 lemma tpss_flat: ∀L,I,V1,V2,T1,T2,d,e.
73                  L ⊢ V1 ▶* [d, e] V2 → L ⊢ T1 ▶* [d, e] T2 →
74                  L ⊢ ⓕ{I} V1. T1 ▶* [d, e] ⓕ{I} V2. T2.
75 #L #I #V1 #V2 #T1 #T2 #d #e #HV12 elim HV12 -V2
76 [ #V2 #HV12 #HT12 elim HT12 -T2
77   [ /3 width=1/
78   | #T #T2 #_ #HT2 #IHT @step /2 width=5/ (**) (* /3 width=5/ is too slow *)
79   ]
80 | #V #V2 #_ #HV12 #IHV #HT12
81   lapply (IHV … HT12) -IHV -HT12 #HT12 @step /2 width=5/ (**) (* /3 width=5/ is too slow *)
82 ]
83 qed.
84
85 lemma tpss_weak: ∀L,T1,T2,d1,e1. L ⊢ T1 ▶* [d1, e1] T2 →
86                  ∀d2,e2. d2 ≤ d1 → d1 + e1 ≤ d2 + e2 →
87                  L ⊢ T1 ▶* [d2, e2] T2.
88 #L #T1 #T2 #d1 #e1 #H #d1 #d2 #Hd21 #Hde12 @(tpss_ind … H) -T2
89 [ //
90 | #T #T2 #_ #HT12 #IHT
91   lapply (tps_weak … HT12 … Hd21 Hde12) -HT12 -Hd21 -Hde12 /2 width=3/
92 ]
93 qed.
94
95 lemma tpss_weak_top: ∀L,T1,T2,d,e.
96                      L ⊢ T1 ▶* [d, e] T2 → L ⊢ T1 ▶* [d, |L| - d] T2.
97 #L #T1 #T2 #d #e #H @(tpss_ind … H) -T2
98 [ //
99 | #T #T2 #_ #HT12 #IHT
100   lapply (tps_weak_top … HT12) -HT12 /2 width=3/
101 ]
102 qed.
103
104 lemma tpss_weak_all: ∀L,T1,T2,d,e.
105                      L ⊢ T1 ▶* [d, e] T2 → L ⊢ T1 ▶* [0, |L|] T2.
106 #L #T1 #T2 #d #e #HT12
107 lapply (tpss_weak … HT12 0 (d + e) ? ?) -HT12 // #HT12
108 lapply (tpss_weak_top … HT12) //
109 qed.
110
111 lemma tpss_append: ∀K,T1,T2,d,e. K ⊢ T1 ▶* [d, e] T2 →
112                    ∀L. L @@ K ⊢ T1 ▶* [d, e] T2.
113 #K #T1 #T2 #d #e #H @(tpss_ind … H) -T2 // /3 width=3/
114 qed.
115
116 (* Basic inversion lemmas ***************************************************)
117
118 (* Note: this can be derived from tpss_inv_atom1 *)
119 lemma tpss_inv_sort1: ∀L,T2,k,d,e. L ⊢ ⋆k ▶* [d, e] T2 → T2 = ⋆k.
120 #L #T2 #k #d #e #H @(tpss_ind … H) -T2
121 [ //
122 | #T #T2 #_ #HT2 #IHT destruct
123   >(tps_inv_sort1 … HT2) -HT2 //
124 ]
125 qed-.
126
127 (* Note: this can be derived from tpss_inv_atom1 *)
128 lemma tpss_inv_gref1: ∀L,T2,p,d,e. L ⊢ §p ▶* [d, e] T2 → T2 = §p.
129 #L #T2 #p #d #e #H @(tpss_ind … H) -T2
130 [ //
131 | #T #T2 #_ #HT2 #IHT destruct
132   >(tps_inv_gref1 … HT2) -HT2 //
133 ]
134 qed-.
135
136 lemma tpss_inv_bind1: ∀d,e,L,a,I,V1,T1,U2. L ⊢ ⓑ{a,I} V1. T1 ▶* [d, e] U2 →
137                       ∃∃V2,T2. L ⊢ V1 ▶* [d, e] V2 & 
138                                L. ⓑ{I} V2 ⊢ T1 ▶* [d + 1, e] T2 &
139                                U2 = ⓑ{a,I} V2. T2.
140 #d #e #L #a #I #V1 #T1 #U2 #H @(tpss_ind … H) -U2
141 [ /2 width=5/
142 | #U #U2 #_ #HU2 * #V #T #HV1 #HT1 #H destruct
143   elim (tps_inv_bind1 … HU2) -HU2 #V2 #T2 #HV2 #HT2 #H
144   lapply (tpss_lsubs_trans … HT1 (L. ⓑ{I} V2) ?) -HT1 /2 width=1/ /3 width=5/
145 ]
146 qed-.
147
148 lemma tpss_inv_flat1: ∀d,e,L,I,V1,T1,U2. L ⊢ ⓕ{I} V1. T1 ▶* [d, e] U2 →
149                       ∃∃V2,T2. L ⊢ V1 ▶* [d, e] V2 & L ⊢ T1 ▶* [d, e] T2 &
150                                U2 =  ⓕ{I} V2. T2.
151 #d #e #L #I #V1 #T1 #U2 #H @(tpss_ind … H) -U2
152 [ /2 width=5/
153 | #U #U2 #_ #HU2 * #V #T #HV1 #HT1 #H destruct
154   elim (tps_inv_flat1 … HU2) -HU2 /3 width=5/
155 ]
156 qed-.
157
158 lemma tpss_inv_refl_O2: ∀L,T1,T2,d. L ⊢ T1 ▶* [d, 0] T2 → T1 = T2.
159 #L #T1 #T2 #d #H @(tpss_ind … H) -T2
160 [ //
161 | #T #T2 #_ #HT2 #IHT <(tps_inv_refl_O2 … HT2) -HT2 //
162 ]
163 qed-.
164
165 (* Basic forward lemmas *****************************************************)
166
167 lemma tpss_fwd_tw: ∀L,T1,T2,d,e. L ⊢ T1 ▶* [d, e] T2 → #{T1} ≤ #{T2}.
168 #L #T1 #T2 #d #e #H @(tpss_ind … H) -T2 //
169 #T #T2 #_ #HT2 #IHT1
170 lapply (tps_fwd_tw … HT2) -HT2 #HT2
171 @(transitive_le … IHT1) //
172 qed-.
173
174 lemma tpss_fwd_shift1: ∀L,L1,T1,T,d,e. L ⊢ L1 @@ T1 ▶*[d, e] T →
175                        ∃∃L2,T2. |L1| = |L2| & T = L2 @@ T2.
176 #L #L1 #T1 #T #d #e #H @(tpss_ind … H) -T
177 [ /2 width=4/
178 | #T #X #_ #H0 * #L0 #T0 #HL10 #H destruct
179   elim (tps_fwd_shift1 … H0) -H0 #L2 #T2 #HL02 #H destruct /2 width=4/
180 ]
181 qed-.
182