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 "basics/star1.ma".
16 include "ground_2/xoa/xoa_props.ma".
18 (* PROPERTIES OF RELATIONS **************************************************)
20 definition Decidable: Prop → Prop ≝ λR. R ∨ (R → ⊥).
22 definition Transitive: ∀A. ∀R: relation A. Prop ≝ λA,R.
23 ∀a1,a0. R a1 a0 → ∀a2. R a0 a2 → R a1 a2.
25 definition confluent2: ∀A. ∀R1,R2: relation A. Prop ≝ λA,R1,R2.
26 ∀a0,a1. R1 a0 a1 → ∀a2. R2 a0 a2 →
27 ∃∃a. R2 a1 a & R1 a2 a.
29 definition transitive2: ∀A. ∀R1,R2: relation A. Prop ≝ λA,R1,R2.
30 ∀a1,a0. R1 a1 a0 → ∀a2. R2 a0 a2 →
31 ∃∃a. R2 a1 a & R1 a a2.
33 definition bi_confluent: ∀A,B. ∀R: bi_relation A B. Prop ≝ λA,B,R.
34 ∀a0,a1,b0,b1. R a0 b0 a1 b1 → ∀a2,b2. R a0 b0 a2 b2 →
35 ∃∃a,b. R a1 b1 a b & R a2 b2 a b.
37 definition LTC: ∀A:Type[0]. ∀B. (A→relation B) → (A→relation B) ≝
40 definition lsub_trans: ∀A,B. relation2 (A→relation B) (relation A) ≝ λA,B,R1,R2.
41 ∀L2,T1,T2. R1 L2 T1 T2 → ∀L1. R2 L1 L2 → R1 L1 T1 T2.
43 definition s_r_transitive: ∀A,B. relation2 (A→relation B) (B→relation A) ≝ λA,B,R1,R2.
44 ∀L2,T1,T2. R1 L2 T1 T2 → ∀L1. R2 T1 L1 L2 → LTC … R1 L1 T1 T2.
46 definition s_rs_transitive: ∀A,B. relation2 (A→relation B) (B→relation A) ≝ λA,B,R1,R2.
47 ∀L2,T1,T2. LTC … R1 L2 T1 T2 → ∀L1. R2 T1 L1 L2 → LTC … R1 L1 T1 T2.
49 definition s_r_confluent1: ∀A,B. relation2 (A→relation B) (B→relation A) ≝ λA,B,R1,R2.
50 ∀L1,T1,T2. R1 L1 T1 T2 → ∀L2. R2 T1 L1 L2 → R2 T2 L1 L2.
52 lemma TC_strip1: ∀A,R1,R2. confluent2 A R1 R2 →
53 ∀a0,a1. TC … R1 a0 a1 → ∀a2. R2 a0 a2 →
54 ∃∃a. R2 a1 a & TC … R1 a2 a.
55 #A #R1 #R2 #HR12 #a0 #a1 #H elim H -a1
57 elim (HR12 … Ha01 … Ha02) -HR12 -a0 /3 width=3 by inj, ex2_intro/
58 | #a #a1 #_ #Ha1 #IHa0 #a2 #Ha02
59 elim (IHa0 … Ha02) -a0 #a0 #Ha0 #Ha20
60 elim (HR12 … Ha1 … Ha0) -HR12 -a /4 width=5 by step, ex2_intro/
64 lemma TC_strip2: ∀A,R1,R2. confluent2 A R1 R2 →
65 ∀a0,a2. TC … R2 a0 a2 → ∀a1. R1 a0 a1 →
66 ∃∃a. TC … R2 a1 a & R1 a2 a.
67 #A #R1 #R2 #HR12 #a0 #a2 #H elim H -a2
69 elim (HR12 … Ha01 … Ha02) -HR12 -a0 /3 width=3 by inj, ex2_intro/
70 | #a #a2 #_ #Ha2 #IHa0 #a1 #Ha01
71 elim (IHa0 … Ha01) -a0 #a0 #Ha10 #Ha0
72 elim (HR12 … Ha0 … Ha2) -HR12 -a /4 width=3 by step, ex2_intro/
76 lemma TC_confluent2: ∀A,R1,R2.
77 confluent2 A R1 R2 → confluent2 A (TC … R1) (TC … R2).
78 #A #R1 #R2 #HR12 #a0 #a1 #H elim H -a1
80 elim (TC_strip2 … HR12 … Ha02 … Ha01) -HR12 -a0 /3 width=3 by inj, ex2_intro/
81 | #a #a1 #_ #Ha1 #IHa0 #a2 #Ha02
82 elim (IHa0 … Ha02) -a0 #a0 #Ha0 #Ha20
83 elim (TC_strip2 … HR12 … Ha0 … Ha1) -HR12 -a /4 width=5 by step, ex2_intro/
87 lemma TC_strap1: ∀A,R1,R2. transitive2 A R1 R2 →
88 ∀a1,a0. TC … R1 a1 a0 → ∀a2. R2 a0 a2 →
89 ∃∃a. R2 a1 a & TC … R1 a a2.
90 #A #R1 #R2 #HR12 #a1 #a0 #H elim H -a0
92 elim (HR12 … Ha10 … Ha02) -HR12 -a0 /3 width=3 by inj, ex2_intro/
93 | #a #a0 #_ #Ha0 #IHa #a2 #Ha02
94 elim (HR12 … Ha0 … Ha02) -HR12 -a0 #a0 #Ha0 #Ha02
95 elim (IHa … Ha0) -a /4 width=5 by step, ex2_intro/
99 lemma TC_strap2: ∀A,R1,R2. transitive2 A R1 R2 →
100 ∀a0,a2. TC … R2 a0 a2 → ∀a1. R1 a1 a0 →
101 ∃∃a. TC … R2 a1 a & R1 a a2.
102 #A #R1 #R2 #HR12 #a0 #a2 #H elim H -a2
103 [ #a2 #Ha02 #a1 #Ha10
104 elim (HR12 … Ha10 … Ha02) -HR12 -a0 /3 width=3 by inj, ex2_intro/
105 | #a #a2 #_ #Ha02 #IHa #a1 #Ha10
106 elim (IHa … Ha10) -a0 #a0 #Ha10 #Ha0
107 elim (HR12 … Ha0 … Ha02) -HR12 -a /4 width=3 by step, ex2_intro/
111 lemma TC_transitive2: ∀A,R1,R2.
112 transitive2 A R1 R2 → transitive2 A (TC … R1) (TC … R2).
113 #A #R1 #R2 #HR12 #a1 #a0 #H elim H -a0
114 [ #a0 #Ha10 #a2 #Ha02
115 elim (TC_strap2 … HR12 … Ha02 … Ha10) -HR12 -a0 /3 width=3 by inj, ex2_intro/
116 | #a #a0 #_ #Ha0 #IHa #a2 #Ha02
117 elim (TC_strap2 … HR12 … Ha02 … Ha0) -HR12 -a0 #a0 #Ha0 #Ha02
118 elim (IHa … Ha0) -a /4 width=5 by step, ex2_intro/
122 definition NF: ∀A. relation A → relation A → predicate A ≝
123 λA,R,S,a1. ∀a2. R a1 a2 → S a2 a1.
125 definition NF_dec: ∀A. relation A → relation A → Prop ≝
126 λA,R,S. ∀a1. NF A R S a1 ∨
127 ∃∃a2. R … a1 a2 & (S a2 a1 → ⊥).
129 inductive SN (A) (R,S:relation A): predicate A ≝
130 | SN_intro: ∀a1. (∀a2. R a1 a2 → (S a2 a1 → ⊥) → SN A R S a2) → SN A R S a1
133 lemma NF_to_SN: ∀A,R,S,a. NF A R S a → SN A R S a.
135 @SN_intro #a2 #HRa12 #HSa12
136 elim HSa12 -HSa12 /2 width=1 by/
139 lemma SN_to_NF: ∀A,R,S. NF_dec A R S →
141 ∃∃a2. star … R a1 a2 & NF A R S a2.
142 #A #R #S #HRS #a1 #H elim H -a1
143 #a1 #_ #IHa1 elim (HRS a1) -HRS /2 width=3 by srefl, ex2_intro/
144 * #a0 #Ha10 #Ha01 elim (IHa1 … Ha10 Ha01) -IHa1 -Ha01 /3 width=3 by star_compl, ex2_intro/
147 definition NF_sn: ∀A. relation A → relation A → predicate A ≝
148 λA,R,S,a2. ∀a1. R a1 a2 → S a2 a1.
150 inductive SN_sn (A) (R,S:relation A): predicate A ≝
151 | SN_sn_intro: ∀a2. (∀a1. R a1 a2 → (S a2 a1 → ⊥) → SN_sn A R S a1) → SN_sn A R S a2
154 lemma NF_to_SN_sn: ∀A,R,S,a. NF_sn A R S a → SN_sn A R S a.
156 @SN_sn_intro #a1 #HRa12 #HSa12
157 elim HSa12 -HSa12 /2 width=1 by/
160 lemma LTC_lsub_trans: ∀A,B,R,S. lsub_trans A B R S → lsub_trans A B (LTC … R) S.
161 #A #B #R #S #HRS #L2 #T1 #T2 #H elim H -T2 /3 width=3 by inj/
162 #T #T2 #_ #HT2 #IHT1 #L1 #HL12
163 lapply (HRS … HT2 … HL12) -HRS -HT2 /3 width=3 by step/
166 lemma s_r_conf1_LTC1: ∀A,B,S,R. s_r_confluent1 A B S R → s_r_confluent1 A B (LTC … S) R.
167 #A #B #S #R #HSR #L1 #T1 #T2 #H @(TC_ind_dx … T1 H) -T1 /3 width=3 by/
170 lemma s_r_trans_LTC1: ∀A,B,S,R. s_r_confluent1 A B S R →
171 s_r_transitive A B S R → s_rs_transitive A B S R.
172 #A #B #S #R #H1SR #H2SR #L2 #T1 #T2 #H @(TC_ind_dx … T1 H) -T1 /2 width=3 by/
173 #T1 #T #HT1 #_ #IHT2 #L1 #HL12 lapply (H2SR … HT1 … HL12) -H2SR -HT1
174 /4 width=5 by s_r_conf1_LTC1, trans_TC/
177 lemma s_r_trans_LTC2: ∀A,B,S,R. s_rs_transitive A B S R → s_r_transitive A B S (LTC … R).
178 #A #B #S #R #HSR #L2 #T1 #T2 #HT12 #L1 #H @(TC_ind_dx … L1 H) -L1 /3 width=3 by inj/
181 lemma s_r_to_s_rs_trans: ∀A,B,S,R. s_r_transitive A B (LTC … S) R →
182 s_rs_transitive A B S R.
183 #A #B #S #R #HSR #L2 #T1 #T2 #HL2 #L1 #HT1
184 elim (TC_idem … (S L1) … T1 T2)
188 lemma s_rs_to_s_r_trans: ∀A,B,S,R. s_rs_transitive A B S R →
189 s_r_transitive A B (LTC … S) R.
190 #A #B #S #R #HSR #L2 #T1 #T2 #HL2 #L1 #HT1
191 elim (TC_idem … (S L1) … T1 T2)
195 lemma s_rs_trans_TC1: ∀A,B,S,R. s_rs_transitive A B S R →
196 s_rs_transitive A B (LTC … S) R.
197 #A #B #S #R #HSR #L2 #T1 #T2 #HL2 #L1 #HT1
198 elim (TC_idem … (S L1) … T1 T2)
199 elim (TC_idem … (S L2) … T1 T2)
200 #_ #H1 #H2 #_ @H2 @HSR /3 width=3 by/
203 (* relations on unboxed pairs ***********************************************)
205 lemma bi_TC_strip: ∀A,B,R. bi_confluent A B R →
206 ∀a0,a1,b0,b1. R a0 b0 a1 b1 → ∀a2,b2. bi_TC … R a0 b0 a2 b2 →
207 ∃∃a,b. bi_TC … R a1 b1 a b & R a2 b2 a b.
208 #A #B #R #HR #a0 #a1 #b0 #b1 #H01 #a2 #b2 #H elim H -a2 -b2
210 elim (HR … H01 … H02) -HR -a0 -b0 /3 width=4 by ex2_2_intro, bi_inj/
211 | #a2 #b2 #a3 #b3 #_ #H23 * #a #b #H1 #H2
212 elim (HR … H23 … H2) -HR -a0 -b0 -a2 -b2 /3 width=4 by ex2_2_intro, bi_step/
216 lemma bi_TC_confluent: ∀A,B,R. bi_confluent A B R →
217 bi_confluent A B (bi_TC … R).
218 #A #B #R #HR #a0 #a1 #b0 #b1 #H elim H -a1 -b1
219 [ #a1 #b1 #H01 #a2 #b2 #H02
220 elim (bi_TC_strip … HR … H01 … H02) -a0 -b0 /3 width=4 by ex2_2_intro, bi_inj/
221 | #a1 #b1 #a3 #b3 #_ #H13 #IH #a2 #b2 #H02
222 elim (IH … H02) -a0 -b0 #a0 #b0 #H10 #H20
223 elim (bi_TC_strip … HR … H13 … H10) -a1 -b1 /3 width=7 by ex2_2_intro, bi_step/
227 lemma bi_TC_decomp_r: ∀A,B. ∀R:bi_relation A B.
228 ∀a1,a2,b1,b2. bi_TC … R a1 b1 a2 b2 →
230 ∃∃a,b. bi_TC … R a1 b1 a b & R a b a2 b2.
231 #A #B #R #a1 #a2 #b1 #b2 * -a2 -b2 /2 width=1/ /3 width=4 by ex2_2_intro, or_intror/
234 lemma bi_TC_decomp_l: ∀A,B. ∀R:bi_relation A B.
235 ∀a1,a2,b1,b2. bi_TC … R a1 b1 a2 b2 →
237 ∃∃a,b. R a1 b1 a b & bi_TC … R a b a2 b2.
238 #A #B #R #a1 #a2 #b1 #b2 #H @(bi_TC_ind_dx … a1 b1 H) -a1 -b1
239 [ /2 width=1 by or_introl/
240 | #a1 #a #b1 #b #Hab1 #Hab2 #_ /3 width=4 by ex2_2_intro, or_intror/ (**) (* auto fails without #_ *)
244 (* relations on unboxed triples *********************************************)
246 definition tri_RC: ∀A,B,C. tri_relation A B C → tri_relation A B C ≝
247 λA,B,C,R,a1,b1,c1,a2,b2,c2. R … a1 b1 c1 a2 b2 c2 ∨
248 ∧∧ a1 = a2 & b1 = b2 & c1 = c2.
250 lemma tri_RC_reflexive: ∀A,B,C,R. tri_reflexive A B C (tri_RC … R).
251 /3 width=1 by and3_intro, or_intror/ qed.
253 definition tri_star: ∀A,B,C,R. tri_relation A B C ≝
254 λA,B,C,R. tri_RC A B C (tri_TC … R).
256 lemma tri_star_tri_reflexive: ∀A,B,C,R. tri_reflexive A B C (tri_star … R).
259 lemma tri_TC_to_tri_star: ∀A,B,C,R,a1,b1,c1,a2,b2,c2.
260 tri_TC A B C R a1 b1 c1 a2 b2 c2 →
261 tri_star A B C R a1 b1 c1 a2 b2 c2.
262 /2 width=1 by or_introl/ qed.
264 lemma tri_R_to_tri_star: ∀A,B,C,R,a1,b1,c1,a2,b2,c2.
265 R a1 b1 c1 a2 b2 c2 → tri_star A B C R a1 b1 c1 a2 b2 c2.
266 /3 width=1 by tri_TC_to_tri_star, tri_inj/ qed.
268 lemma tri_star_strap1: ∀A,B,C,R,a1,a,a2,b1,b,b2,c1,c,c2.
269 tri_star A B C R a1 b1 c1 a b c →
270 R a b c a2 b2 c2 → tri_star A B C R a1 b1 c1 a2 b2 c2.
271 #A #B #C #R #a1 #a #a2 #b1 #b #b2 #c1 #c #c2 *
272 [ /3 width=5 by tri_TC_to_tri_star, tri_step/
273 | * #H1 #H2 #H3 destruct /2 width=1 by tri_R_to_tri_star/
277 lemma tri_star_strap2: ∀A,B,C,R,a1,a,a2,b1,b,b2,c1,c,c2. R a1 b1 c1 a b c →
278 tri_star A B C R a b c a2 b2 c2 →
279 tri_star A B C R a1 b1 c1 a2 b2 c2.
280 #A #B #C #R #a1 #a #a2 #b1 #b #b2 #c1 #c #c2 #H *
281 [ /3 width=5 by tri_TC_to_tri_star, tri_TC_strap/
282 | * #H1 #H2 #H3 destruct /2 width=1 by tri_R_to_tri_star/
286 lemma tri_star_to_tri_TC_to_tri_TC: ∀A,B,C,R,a1,a,a2,b1,b,b2,c1,c,c2.
287 tri_star A B C R a1 b1 c1 a b c →
288 tri_TC A B C R a b c a2 b2 c2 →
289 tri_TC A B C R a1 b1 c1 a2 b2 c2.
290 #A #B #C #R #a1 #a #a2 #b1 #b #b2 #c1 #c #c2 *
291 [ /2 width=5 by tri_TC_transitive/
292 | * #H1 #H2 #H3 destruct /2 width=1 by/
296 lemma tri_TC_to_tri_star_to_tri_TC: ∀A,B,C,R,a1,a,a2,b1,b,b2,c1,c,c2.
297 tri_TC A B C R a1 b1 c1 a b c →
298 tri_star A B C R a b c a2 b2 c2 →
299 tri_TC A B C R a1 b1 c1 a2 b2 c2.
300 #A #B #C #R #a1 #a #a2 #b1 #b #b2 #c1 #c #c2 #H *
301 [ /2 width=5 by tri_TC_transitive/
302 | * #H1 #H2 #H3 destruct /2 width=1 by/
306 lemma tri_tansitive_tri_star: ∀A,B,C,R. tri_transitive A B C (tri_star … R).
307 #A #B #C #R #a1 #a #b1 #b #c1 #c #H #a2 #b2 #c2 *
308 [ /3 width=5 by tri_star_to_tri_TC_to_tri_TC, tri_TC_to_tri_star/
309 | * #H1 #H2 #H3 destruct /2 width=1 by/
313 lemma tri_star_ind: ∀A,B,C,R,a1,b1,c1. ∀P:relation3 A B C. P a1 b1 c1 →
314 (∀a,a2,b,b2,c,c2. tri_star … R a1 b1 c1 a b c → R a b c a2 b2 c2 → P a b c → P a2 b2 c2) →
315 ∀a2,b2,c2. tri_star … R a1 b1 c1 a2 b2 c2 → P a2 b2 c2.
316 #A #B #C #R #a1 #b1 #c1 #P #H #IH #a2 #b2 #c2 *
317 [ #H12 elim H12 -a2 -b2 -c2 /3 width=6 by tri_TC_to_tri_star/
318 | * #H1 #H2 #H3 destruct //
322 lemma tri_star_ind_dx: ∀A,B,C,R,a2,b2,c2. ∀P:relation3 A B C. P a2 b2 c2 →
323 (∀a1,a,b1,b,c1,c. R a1 b1 c1 a b c → tri_star … R a b c a2 b2 c2 → P a b c → P a1 b1 c1) →
324 ∀a1,b1,c1. tri_star … R a1 b1 c1 a2 b2 c2 → P a1 b1 c1.
325 #A #B #C #R #a2 #b2 #c2 #P #H #IH #a1 #b1 #c1 *
326 [ #H12 @(tri_TC_ind_dx … a1 b1 c1 H12) -a1 -b1 -c1 /3 width=6 by tri_TC_to_tri_star/
327 | * #H1 #H2 #H3 destruct //