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 "ground_2/relocation/rtmap_sle.ma".
16 include "basic_2/notation/relations/relationstar_5.ma".
17 include "basic_2/syntax/lenv.ma".
19 (* GENERIC ENTRYWISE EXTENSION OF CONTEXT-SENSITIVE REALTIONS FOR TERMS *****)
21 (* Basic_2A1: includes: lpx_sn_atom lpx_sn_pair *)
22 inductive lexs (RN,RP:relation3 lenv term term): rtmap → relation lenv ≝
23 | lexs_atom: ∀f. lexs RN RP f (⋆) (⋆)
24 | lexs_next: ∀f,I,L1,L2,V1,V2.
25 lexs RN RP f L1 L2 → RN L1 V1 V2 →
26 lexs RN RP (⫯f) (L1.ⓑ{I}V1) (L2.ⓑ{I}V2)
27 | lexs_push: ∀f,I,L1,L2,V1,V2.
28 lexs RN RP f L1 L2 → RP L1 V1 V2 →
29 lexs RN RP (↑f) (L1.ⓑ{I}V1) (L2.ⓑ{I}V2)
32 interpretation "generic entrywise extension (local environment)"
33 'RelationStar RN RP f L1 L2 = (lexs RN RP f L1 L2).
35 definition R_pw_confluent2_lexs: relation3 lenv term term → relation3 lenv term term →
36 relation3 lenv term term → relation3 lenv term term →
37 relation3 lenv term term → relation3 lenv term term →
38 relation3 rtmap lenv term ≝
39 λR1,R2,RN1,RP1,RN2,RP2,f,L0,T0.
40 ∀T1. R1 L0 T0 T1 → ∀T2. R2 L0 T0 T2 →
41 ∀L1. L0 ⦻*[RN1, RP1, f] L1 → ∀L2. L0 ⦻*[RN2, RP2, f] L2 →
42 ∃∃T. R2 L1 T1 T & R1 L2 T2 T.
44 definition lexs_transitive: relation5 (relation3 lenv term term)
45 (relation3 lenv term term) … ≝
47 ∀f,L1,T1,T. R1 L1 T1 T → ∀L2. L1 ⦻*[RN, RP, f] L2 →
48 ∀T2. R2 L2 T T2 → R3 L1 T1 T2.
50 (* Basic inversion lemmas ***************************************************)
52 fact lexs_inv_atom1_aux: ∀RN,RP,f,X,Y. X ⦻*[RN, RP, f] Y → X = ⋆ → Y = ⋆.
53 #RN #RP #f #X #Y * -f -X -Y //
54 #f #I #L1 #L2 #V1 #V2 #_ #_ #H destruct
57 (* Basic_2A1: includes lpx_sn_inv_atom1 *)
58 lemma lexs_inv_atom1: ∀RN,RP,f,Y. ⋆ ⦻*[RN, RP, f] Y → Y = ⋆.
59 /2 width=6 by lexs_inv_atom1_aux/ qed-.
61 fact lexs_inv_next1_aux: ∀RN,RP,f,X,Y. X ⦻*[RN, RP, f] Y → ∀g,J,K1,W1. X = K1.ⓑ{J}W1 → f = ⫯g →
62 ∃∃K2,W2. K1 ⦻*[RN, RP, g] K2 & RN K1 W1 W2 & Y = K2.ⓑ{J}W2.
63 #RN #RP #f #X #Y * -f -X -Y
64 [ #f #g #J #K1 #W1 #H destruct
65 | #f #I #L1 #L2 #V1 #V2 #HL #HV #g #J #K1 #W1 #H1 #H2 <(injective_next … H2) -g destruct
66 /2 width=5 by ex3_2_intro/
67 | #f #I #L1 #L2 #V1 #V2 #_ #_ #g #J #K1 #W1 #_ #H elim (discr_push_next … H)
71 (* Basic_2A1: includes lpx_sn_inv_pair1 *)
72 lemma lexs_inv_next1: ∀RN,RP,g,J,K1,Y,W1. K1.ⓑ{J}W1 ⦻*[RN, RP, ⫯g] Y →
73 ∃∃K2,W2. K1 ⦻*[RN, RP, g] K2 & RN K1 W1 W2 & Y = K2.ⓑ{J}W2.
74 /2 width=7 by lexs_inv_next1_aux/ qed-.
77 fact lexs_inv_push1_aux: ∀RN,RP,f,X,Y. X ⦻*[RN, RP, f] Y → ∀g,J,K1,W1. X = K1.ⓑ{J}W1 → f = ↑g →
78 ∃∃K2,W2. K1 ⦻*[RN, RP, g] K2 & RP K1 W1 W2 & Y = K2.ⓑ{J}W2.
79 #RN #RP #f #X #Y * -f -X -Y
80 [ #f #g #J #K1 #W1 #H destruct
81 | #f #I #L1 #L2 #V1 #V2 #_ #_ #g #J #K1 #W1 #_ #H elim (discr_next_push … H)
82 | #f #I #L1 #L2 #V1 #V2 #HL #HV #g #J #K1 #W1 #H1 #H2 <(injective_push … H2) -g destruct
83 /2 width=5 by ex3_2_intro/
87 lemma lexs_inv_push1: ∀RN,RP,g,J,K1,Y,W1. K1.ⓑ{J}W1 ⦻*[RN, RP, ↑g] Y →
88 ∃∃K2,W2. K1 ⦻*[RN, RP, g] K2 & RP K1 W1 W2 & Y = K2.ⓑ{J}W2.
89 /2 width=7 by lexs_inv_push1_aux/ qed-.
91 fact lexs_inv_atom2_aux: ∀RN,RP,f,X,Y. X ⦻*[RN, RP, f] Y → Y = ⋆ → X = ⋆.
92 #RN #RP #f #X #Y * -f -X -Y //
93 #f #I #L1 #L2 #V1 #V2 #_ #_ #H destruct
96 (* Basic_2A1: includes lpx_sn_inv_atom2 *)
97 lemma lexs_inv_atom2: ∀RN,RP,f,X. X ⦻*[RN, RP, f] ⋆ → X = ⋆.
98 /2 width=6 by lexs_inv_atom2_aux/ qed-.
100 fact lexs_inv_next2_aux: ∀RN,RP,f,X,Y. X ⦻*[RN, RP, f] Y → ∀g,J,K2,W2. Y = K2.ⓑ{J}W2 → f = ⫯g →
101 ∃∃K1,W1. K1 ⦻*[RN, RP, g] K2 & RN K1 W1 W2 & X = K1.ⓑ{J}W1.
102 #RN #RP #f #X #Y * -f -X -Y
103 [ #f #g #J #K2 #W2 #H destruct
104 | #f #I #L1 #L2 #V1 #V2 #HL #HV #g #J #K2 #W2 #H1 #H2 <(injective_next … H2) -g destruct
105 /2 width=5 by ex3_2_intro/
106 | #f #I #L1 #L2 #V1 #V2 #_ #_ #g #J #K2 #W2 #_ #H elim (discr_push_next … H)
110 (* Basic_2A1: includes lpx_sn_inv_pair2 *)
111 lemma lexs_inv_next2: ∀RN,RP,g,J,X,K2,W2. X ⦻*[RN, RP, ⫯g] K2.ⓑ{J}W2 →
112 ∃∃K1,W1. K1 ⦻*[RN, RP, g] K2 & RN K1 W1 W2 & X = K1.ⓑ{J}W1.
113 /2 width=7 by lexs_inv_next2_aux/ qed-.
115 fact lexs_inv_push2_aux: ∀RN,RP,f,X,Y. X ⦻*[RN, RP, f] Y → ∀g,J,K2,W2. Y = K2.ⓑ{J}W2 → f = ↑g →
116 ∃∃K1,W1. K1 ⦻*[RN, RP, g] K2 & RP K1 W1 W2 & X = K1.ⓑ{J}W1.
117 #RN #RP #f #X #Y * -f -X -Y
118 [ #f #J #K2 #W2 #g #H destruct
119 | #f #I #L1 #L2 #V1 #V2 #_ #_ #g #J #K2 #W2 #_ #H elim (discr_next_push … H)
120 | #f #I #L1 #L2 #V1 #V2 #HL #HV #g #J #K2 #W2 #H1 #H2 <(injective_push … H2) -g destruct
121 /2 width=5 by ex3_2_intro/
125 lemma lexs_inv_push2: ∀RN,RP,g,J,X,K2,W2. X ⦻*[RN, RP, ↑g] K2.ⓑ{J}W2 →
126 ∃∃K1,W1. K1 ⦻*[RN, RP, g] K2 & RP K1 W1 W2 & X = K1.ⓑ{J}W1.
127 /2 width=7 by lexs_inv_push2_aux/ qed-.
129 (* Basic_2A1: includes lpx_sn_inv_pair *)
130 lemma lexs_inv_next: ∀RN,RP,f,I1,I2,L1,L2,V1,V2.
131 L1.ⓑ{I1}V1 ⦻*[RN, RP, ⫯f] (L2.ⓑ{I2}V2) →
132 ∧∧ L1 ⦻*[RN, RP, f] L2 & RN L1 V1 V2 & I1 = I2.
133 #RN #RP #f #I1 #I2 #L1 #L2 #V1 #V2 #H elim (lexs_inv_next1 … H) -H
134 #L0 #V0 #HL10 #HV10 #H destruct /2 width=1 by and3_intro/
137 lemma lexs_inv_push: ∀RN,RP,f,I1,I2,L1,L2,V1,V2.
138 L1.ⓑ{I1}V1 ⦻*[RN, RP, ↑f] (L2.ⓑ{I2}V2) →
139 ∧∧ L1 ⦻*[RN, RP, f] L2 & RP L1 V1 V2 & I1 = I2.
140 #RN #RP #f #I1 #I2 #L1 #L2 #V1 #V2 #H elim (lexs_inv_push1 … H) -H
141 #L0 #V0 #HL10 #HV10 #H destruct /2 width=1 by and3_intro/
144 lemma lexs_inv_tl: ∀RN,RP,f,I,L1,L2,V1,V2. L1 ⦻*[RN, RP, ⫱f] L2 →
145 RN L1 V1 V2 → RP L1 V1 V2 →
146 L1.ⓑ{I}V1 ⦻*[RN, RP, f] L2.ⓑ{I}V2.
147 #RN #RP #f #I #L2 #L2 #V1 #V2 elim (pn_split f) *
148 /2 width=1 by lexs_next, lexs_push/
151 (* Basic forward lemmas *****************************************************)
153 lemma lexs_fwd_pair: ∀RN,RP,f,I1,I2,L1,L2,V1,V2.
154 L1.ⓑ{I1}V1 ⦻*[RN, RP, f] L2.ⓑ{I2}V2 →
155 L1 ⦻*[RN, RP, ⫱f] L2 ∧ I1 = I2.
156 #RN #RP #f #I1 #I2 #L2 #L2 #V1 #V2 #Hf
157 elim (pn_split f) * #g #H destruct
158 [ elim (lexs_inv_push … Hf) | elim (lexs_inv_next … Hf) ] -Hf
162 (* Basic properties *********************************************************)
164 lemma lexs_eq_repl_back: ∀RN,RP,L1,L2. eq_repl_back … (λf. L1 ⦻*[RN, RP, f] L2).
165 #RN #RP #L1 #L2 #f1 #H elim H -f1 -L1 -L2 //
166 #f1 #I #L1 #L2 #V1 #v2 #_ #HV #IH #f2 #H
167 [ elim (eq_inv_nx … H) -H /3 width=3 by lexs_next/
168 | elim (eq_inv_px … H) -H /3 width=3 by lexs_push/
172 lemma lexs_eq_repl_fwd: ∀RN,RP,L1,L2. eq_repl_fwd … (λf. L1 ⦻*[RN, RP, f] L2).
173 #RN #RP #L1 #L2 @eq_repl_sym /2 width=3 by lexs_eq_repl_back/ (**) (* full auto fails *)
176 (* Basic_2A1: includes: lpx_sn_refl *)
177 lemma lexs_refl: ∀RN,RP.
178 (∀L. reflexive … (RN L)) →
179 (∀L. reflexive … (RP L)) →
180 ∀f.reflexive … (lexs RN RP f).
181 #RN #RP #HRN #HRP #f #L generalize in match f; -f elim L -L //
182 #L #I #V #IH * * /2 width=1 by lexs_next, lexs_push/
185 lemma lexs_sym: ∀RN,RP.
186 (∀L1,L2,T1,T2. RN L1 T1 T2 → RN L2 T2 T1) →
187 (∀L1,L2,T1,T2. RP L1 T1 T2 → RP L2 T2 T1) →
188 ∀f. symmetric … (lexs RN RP f).
189 #RN #RP #HRN #HRP #f #L1 #L2 #H elim H -L1 -L2 -f
190 /3 width=2 by lexs_next, lexs_push/
193 lemma lexs_pair_repl: ∀RN,RP,f,I,L1,L2,V1,V2.
194 L1.ⓑ{I}V1 ⦻*[RN, RP, f] L2.ⓑ{I}V2 →
195 ∀W1,W2. RN L1 W1 W2 → RP L1 W1 W2 →
196 L1.ⓑ{I}W1 ⦻*[RN, RP, f] L2.ⓑ{I}W2.
197 #RN #RP #f #I #L1 #L2 #V1 #V2 #HL12 #W1 #W2 #HN #HP
198 elim (lexs_fwd_pair … HL12) -HL12 /2 width=1 by lexs_inv_tl/
201 lemma lexs_co: ∀RN1,RP1,RN2,RP2.
202 (∀L1,T1,T2. RN1 L1 T1 T2 → RN2 L1 T1 T2) →
203 (∀L1,T1,T2. RP1 L1 T1 T2 → RP2 L1 T1 T2) →
204 ∀f,L1,L2. L1 ⦻*[RN1, RP1, f] L2 → L1 ⦻*[RN2, RP2, f] L2.
205 #RN1 #RP1 #RN2 #RP2 #HRN #HRP #f #L1 #L2 #H elim H -f -L1 -L2
206 /3 width=1 by lexs_atom, lexs_next, lexs_push/
209 lemma lexs_co_isid: ∀RN1,RP1,RN2,RP2.
210 (∀L1,T1,T2. RP1 L1 T1 T2 → RP2 L1 T1 T2) →
211 ∀f,L1,L2. L1 ⦻*[RN1, RP1, f] L2 → 𝐈⦃f⦄ →
212 L1 ⦻*[RN2, RP2, f] L2.
213 #RN1 #RP1 #RN2 #RP2 #HR #f #L1 #L2 #H elim H -f -L1 -L2 //
214 #f #I #K1 #K2 #V1 #V2 #_ #HV12 #IH #H
215 [ elim (isid_inv_next … H) -H //
216 | /4 width=3 by lexs_push, isid_inv_push/
220 lemma sle_lexs_trans: ∀RN,RP. (∀L,T1,T2. RN L T1 T2 → RP L T1 T2) →
221 ∀f2,L1,L2. L1 ⦻*[RN, RP, f2] L2 →
222 ∀f1. f1 ⊆ f2 → L1 ⦻*[RN, RP, f1] L2.
223 #RN #RP #HR #f2 #L1 #L2 #H elim H -f2 -L1 -L2 //
224 #f2 #I #L1 #L2 #V1 #V2 #_ #HV12 #IH
225 [ * * [2: #n1 ] ] #f1 #H
226 [ /4 width=5 by lexs_next, sle_inv_nn/
227 | /4 width=5 by lexs_push, sle_inv_pn/
228 | elim (sle_inv_xp … H) -H [2,3: // ]
229 #g1 #H #H1 destruct /3 width=5 by lexs_push/
233 lemma sle_lexs_conf: ∀RN,RP. (∀L,T1,T2. RP L T1 T2 → RN L T1 T2) →
234 ∀f1,L1,L2. L1 ⦻*[RN, RP, f1] L2 →
235 ∀f2. f1 ⊆ f2 → L1 ⦻*[RN, RP, f2] L2.
236 #RN #RP #HR #f1 #L1 #L2 #H elim H -f1 -L1 -L2 //
237 #f1 #I #L1 #L2 #V1 #V2 #_ #HV12 #IH
238 [2: * * [2: #n2 ] ] #f2 #H
239 [ /4 width=5 by lexs_next, sle_inv_pn/
240 | /4 width=5 by lexs_push, sle_inv_pp/
241 | elim (sle_inv_nx … H) -H [2,3: // ]
242 #g2 #H #H2 destruct /3 width=5 by lexs_next/
246 lemma lexs_sle_split: ∀R1,R2,RP. (∀L. reflexive … (R1 L)) → (∀L. reflexive … (R2 L)) →
247 ∀f,L1,L2. L1 ⦻*[R1, RP, f] L2 → ∀g. f ⊆ g →
248 ∃∃L. L1 ⦻*[R1, RP, g] L & L ⦻*[R2, cfull, f] L2.
249 #R1 #R2 #RP #HR1 #HR2 #f #L1 #L2 #H elim H -f -L1 -L2
250 [ /2 width=3 by lexs_atom, ex2_intro/ ]
251 #f #I #L1 #L2 #V1 #V2 #_ #HV12 #IH #y #H
252 [ elim (sle_inv_nx … H ??) -H [ |*: // ] #g #Hfg #H destruct
253 elim (IH … Hfg) -IH -Hfg /3 width=5 by lexs_next, ex2_intro/
254 | elim (sle_inv_px … H ??) -H [1,3: * |*: // ] #g #Hfg #H destruct
255 elim (IH … Hfg) -IH -Hfg /3 width=5 by lexs_next, lexs_push, ex2_intro/
259 lemma lexs_dec: ∀RN,RP.
260 (∀L,T1,T2. Decidable (RN L T1 T2)) →
261 (∀L,T1,T2. Decidable (RP L T1 T2)) →
262 ∀L1,L2,f. Decidable (L1 ⦻*[RN, RP, f] L2).
263 #RN #RP #HRN #HRP #L1 elim L1 -L1 [ * | #L1 #I1 #V1 #IH * ]
264 [ /2 width=1 by lexs_atom, or_introl/
265 | #L2 #I2 #V2 #f @or_intror #H
266 lapply (lexs_inv_atom1 … H) -H #H destruct
268 lapply (lexs_inv_atom2 … H) -H #H destruct
269 | #L2 #I2 #V2 #f elim (eq_bind2_dec I1 I2) #H destruct
270 [2: @or_intror #H elim (lexs_fwd_pair … H) -H /2 width=1 by/ ]
271 elim (IH L2 (⫱f)) -IH #HL12
272 [2: @or_intror #H elim (lexs_fwd_pair … H) -H /2 width=1 by/ ]
273 elim (pn_split f) * #g #H destruct
274 [ elim (HRP L1 V1 V2) | elim (HRN L1 V1 V2) ] -HRP -HRN #HV12
275 [1,3: /3 width=1 by lexs_push, lexs_next, or_introl/ ]
277 [ elim (lexs_inv_push … H) | elim (lexs_inv_next … H) ] -H