]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/ground/lib/relations.ma
propagating the arithmetics library, partial commit
[helm.git] / matita / matita / contribs / lambdadelta / ground / lib / relations.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 "basics/relations.ma".
16 include "ground/xoa/and_3.ma".
17 include "ground/xoa/ex_2_2.ma".
18 include "ground/lib/logic.ma".
19
20 (* GENERIC RELATIONS ********************************************************)
21
22 definition replace_2 (A) (B): relation3 (relation2 A B) (relation A) (relation B) ≝
23            λR,Sa,Sb. ∀a1,b1. R a1 b1 → ∀a2. Sa a1 a2 → ∀b2. Sb b1 b2 → R a2 b2.
24
25 (* Inclusion ****************************************************************)
26
27 definition subR2 (S1) (S2): relation (relation2 S1 S2) ≝
28            λR1,R2. (∀a1,a2. R1 a1 a2 → R2 a1 a2).
29
30 interpretation
31   "2-relation inclusion"
32   'subseteq R1 R2 = (subR2 ?? R1 R2).
33
34 definition subR3 (S1) (S2) (S3): relation (relation3 S1 S2 S3) ≝
35            λR1,R2. (∀a1,a2,a3. R1 a1 a2 a3 → R2 a1 a2 a3).
36
37 interpretation
38   "3-relation inclusion"
39   'subseteq R1 R2 = (subR3 ??? R1 R2).
40
41 (* Properties of relations **************************************************)
42
43 definition relation5: Type[0] → Type[0] → Type[0] → Type[0] → Type[0] → Type[0] ≝
44            λA,B,C,D,E.A→B→C→D→E→Prop.
45
46 definition relation6: Type[0] → Type[0] → Type[0] → Type[0] → Type[0] → Type[0] → Type[0] ≝
47            λA,B,C,D,E,F.A→B→C→D→E→F→Prop.
48
49 (**) (* we don't use "∀a. reflexive … (R a)" since auto seems to dislike repeatd δ-expansion *)
50 definition c_reflexive (A) (B): predicate (relation3 A B B) ≝
51            λR. ∀a,b. R a b b.
52
53 definition Decidable: Prop → Prop ≝ λR. R ∨ (R → ⊥).
54
55 definition Transitive (A) (R:relation A): Prop ≝
56            ∀a1,a0. R a1 a0 → ∀a2. R a0 a2 → R a1 a2.
57
58 definition left_cancellable (A) (R:relation A): Prop ≝
59            ∀a0,a1. R a0 a1 → ∀a2. R a0 a2 → R a1 a2.
60
61 definition right_cancellable (A) (R:relation A): Prop ≝
62            ∀a1,a0. R a1 a0 → ∀a2. R a2 a0 → R a1 a2.
63
64 definition pw_confluent2 (A) (R1,R2:relation A): predicate A ≝
65            λa0.
66            ∀a1. R1 a0 a1 → ∀a2. R2 a0 a2 →
67            ∃∃a. R2 a1 a & R1 a2 a.
68
69 definition confluent2 (A): relation (relation A) ≝
70            λR1,R2.
71            ∀a0. pw_confluent2 A R1 R2 a0.
72
73 definition transitive2 (A) (R1,R2:relation A): Prop ≝
74            ∀a1,a0. R1 a1 a0 → ∀a2. R2 a0 a2 →
75            ∃∃a. R2 a1 a & R1 a a2.
76
77 definition confluent1 (A) (B): relation2 (relation2 A B) (relation A) ≝
78            λR1,R2. ∀a1,b. R1 a1 b → ∀a2. R2 a1 a2 → R1 a2 b.
79
80 definition bi_confluent (A) (B) (R: bi_relation A B): Prop ≝
81            ∀a0,a1,b0,b1. R a0 b0 a1 b1 → ∀a2,b2. R a0 b0 a2 b2 →
82            ∃∃a,b. R a1 b1 a b & R a2 b2 a b.
83
84 definition lsub_trans (A) (B): relation2 (A→relation B) (relation A) ≝
85            λR1,R2.
86            ∀L2,T1,T2. R1 L2 T1 T2 → ∀L1. R2 L1 L2 → R1 L1 T1 T2.
87
88 definition s_r_confluent1 (A) (B): relation2 (A→relation B) (B→relation A) ≝
89            λR1,R2.
90            ∀L1,T1,T2. R1 L1 T1 T2 → ∀L2. R2 T1 L1 L2 → R2 T2 L1 L2.
91
92 definition is_mono (B:Type[0]): predicate (predicate B) ≝
93            λR. ∀b1. R b1 → ∀b2. R b2 → b1 = b2.
94
95 definition is_inj2 (A,B:Type[0]): predicate (relation2 A B) ≝
96            λR. ∀a1,b. R a1 b → ∀a2. R a2 b → a1 = a2.
97
98 (* Main properties of equality **********************************************)
99
100 theorem canc_sn_eq (A): left_cancellable A (eq …).
101 // qed-.
102
103 theorem canc_dx_eq (A): right_cancellable A (eq …).
104 // qed-.
105
106 (* Normal form and strong normalization *************************************)
107
108 definition NF (A): relation A → relation A → predicate A ≝
109            λR,S,a1. ∀a2. R a1 a2 → S a1 a2.
110
111 definition NF_dec (A): relation A → relation A → Prop ≝
112            λR,S. ∀a1. NF … R S a1 ∨
113            ∃∃a2. R … a1 a2 & (S a1 a2 → ⊥).
114
115 inductive SN (A) (R,S:relation A): predicate A ≝
116 | SN_intro: ∀a1. (∀a2. R a1 a2 → (S a1 a2 → ⊥) → SN … R S a2) → SN … R S a1
117 .
118
119 lemma NF_to_SN (A) (R) (S): ∀a. NF A R S a → SN A R S a.
120 #A #R #S #a1 #Ha1
121 @SN_intro #a2 #HRa12 #HSa12
122 elim HSa12 -HSa12 /2 width=1 by/
123 qed.
124
125 definition NF_sn (A): relation A → relation A → predicate A ≝
126            λR,S,a2. ∀a1. R a1 a2 → S a1 a2.
127
128 inductive SN_sn (A) (R,S:relation A): predicate A ≝
129 | SN_sn_intro: ∀a2. (∀a1. R a1 a2 → (S a1 a2 → ⊥) → SN_sn … R S a1) → SN_sn … R S a2
130 .
131
132 lemma NF_to_SN_sn (A) (R) (S): ∀a. NF_sn A R S a → SN_sn A R S a.
133 #A #R #S #a2 #Ha2
134 @SN_sn_intro #a1 #HRa12 #HSa12
135 elim HSa12 -HSa12 /2 width=1 by/
136 qed.
137
138 (* Normal form and strong normalization with unboxed triples ****************)
139
140 inductive SN3 (A) (B) (C) (R,S:relation6 A B C A B C): relation3 A B C ≝
141 | SN3_intro: ∀a1,b1,c1. (∀a2,b2,c2. R a1 b1 c1 a2 b2 c2 → (S a1 b1 c1 a2 b2 c2 → ⊥) → SN3 … R S a2 b2 c2) → SN3 … R S a1 b1 c1
142 .
143
144 (* Relations with unboxed triples *******************************************)
145
146 definition tri_RC (A,B,C): tri_relation A B C → tri_relation A B C ≝
147            λR,a1,b1,c1,a2,b2,c2.
148            ∨∨ R … a1 b1 c1 a2 b2 c2
149             | ∧∧ a1 = a2 & b1 = b2 & c1 = c2.
150
151 lemma tri_RC_reflexive (A) (B) (C): ∀R. tri_reflexive A B C (tri_RC … R).
152 /3 width=1 by and3_intro, or_intror/ qed.