]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/lib/basics/relations.ma
24b2c9a9e32b688c05c712cd824a390ba2f65a76
[helm.git] / matita / matita / lib / basics / relations.ma
1 (*
2     ||M||  This file is part of HELM, an Hypertextual, Electronic        
3     ||A||  Library of Mathematics, developed at the Computer Science     
4     ||T||  Department of the University of Bologna, Italy.                     
5     ||I||                                                                 
6     ||T||  
7     ||A||  This file is distributed under the terms of the 
8     \   /  GNU General Public License Version 2        
9      \ /      
10       V_______________________________________________________________ *)
11
12 include "basics/logic.ma".
13 include "basics/core_notation/compose_2.ma".
14
15 (********** predicates *********)
16
17 definition predicate: Type[0] → Type[0]
18 ≝ λA.A→Prop.
19
20 (********** relations **********)
21 definition relation : Type[0] → Type[0]
22 ≝ λA.A→A→Prop. 
23
24 definition relation2 : Type[0] → Type[0] → Type[0]
25 ≝ λA,B.A→B→Prop.
26
27 definition relation3 : Type[0] → Type[0] → Type[0] → Type[0]
28 ≝ λA,B,C.A→B→C→Prop.
29
30 definition relation4 : Type[0] → Type[0] → Type[0] → Type[0] → Type[0]
31 ≝ λA,B,C,D.A→B→C→D→Prop.
32
33 definition reflexive: ∀A.∀R :relation A.Prop
34 ≝ λA.λR.∀x:A.R x x.
35
36 definition symmetric: ∀A.∀R: relation A.Prop
37 ≝ λA.λR.∀x,y:A.R x y → R y x.
38
39 definition transitive: ∀A.∀R:relation A.Prop
40 ≝ λA.λR.∀x,y,z:A.R x y → R y z → R x z.
41
42 definition irreflexive: ∀A.∀R:relation A.Prop
43 ≝ λA.λR.∀x:A.¬(R x x).
44
45 definition cotransitive: ∀A.∀R:relation A.Prop
46 ≝ λA.λR.∀x,y:A.R x y → ∀z:A. R x z ∨ R z y.
47
48 definition tight_apart: ∀A.∀eq,ap:relation A.Prop
49 ≝ λA.λeq,ap.∀x,y:A. (¬(ap x y) → eq x y) ∧
50 (eq x y → ¬(ap x y)).
51
52 definition antisymmetric: ∀A.∀R:relation A.Prop
53 ≝ λA.λR.∀x,y:A. R x y → ¬(R y x).
54
55 definition singlevalued: ∀A,B. predicate (relation2 A B) ≝ λA,B,R.
56                          ∀a,b1. R a b1 → ∀b2. R a b2 → b1 = b2.
57
58 definition confluent1: ∀A. relation A → predicate A ≝ λA,R,a0.
59                        ∀a1. R a0 a1 → ∀a2. R a0 a2 →
60                        ∃∃a. R a1 a & R a2 a. 
61
62 definition confluent: ∀A. predicate (relation A) ≝ λA,R.
63                       ∀a0. confluent1 … R a0.
64
65 (* triangular confluence of two relations *)
66 definition Conf3: ∀A,B. relation2 A B → relation A → Prop ≝ λA,B,S,R.
67                   ∀b,a1. S a1 b → ∀a2. R a1 a2 → S a2 b.
68
69 (* Reflexive closure ************)
70
71 definition RC: ∀A:Type[0]. relation A → relation A ≝
72                λA,R,x,y. R … x y ∨ x = y.
73
74 lemma RC_reflexive: ∀A,R. reflexive A (RC … R).
75 /2 width=1/ qed.
76
77 (********** operations **********)
78 definition Rcomp ≝ λA.λR1,R2:relation A.λa1,a2.
79   ∃am.R1 a1 am ∧ R2 am a2.
80 interpretation "relation composition" 'compose R1 R2 = (Rcomp ? R1 R2).
81
82 definition Runion ≝ λA.λR1,R2:relation A.λa,b. R1 a b ∨ R2 a b.
83 interpretation "union of relations" 'union R1 R2 = (Runion ? R1 R2).
84     
85 definition Rintersection ≝ λA.λR1,R2:relation A.λa,b.R1 a b ∧ R2 a b.
86 interpretation "interesecion of relations" 'intersects R1 R2 = (Rintersection ? R1 R2).
87
88 definition inv ≝ λA.λR:relation A.λa,b.R b a.
89
90 (*********** sub relation ***********)
91 definition subR ≝ λA.λR,S:relation A.(∀a,b. R a b → S a b).
92 interpretation "relation inclusion" 'subseteq R S = (subR ? R S).
93
94 lemma sub_reflexive : 
95   ∀T.∀R:relation T.R ⊆ R.
96 #T #R #x //
97 qed.
98
99 lemma sub_comp_l:  ∀A.∀R,R1,R2:relation A.
100   R1 ⊆ R2 → R1 ∘ R ⊆ R2 ∘ R.
101 #A #R #R1 #R2 #Hsub #a #b * #c * /4/
102 qed.
103
104 lemma sub_comp_r:  ∀A.∀R,R1,R2:relation A.
105   R1 ⊆ R2 → R ∘ R1 ⊆ R ∘ R2.
106 #A #R #R1 #R2 #Hsub #a #b * #c * /4/
107 qed.
108
109 lemma sub_assoc_l: ∀A.∀R1,R2,R3:relation A.
110   R1 ∘ (R2 ∘ R3) ⊆ (R1 ∘ R2) ∘ R3.
111 #A #R1 #R2 #R3 #a #b * #c * #Hac * #d * /5/
112 qed.
113
114 lemma sub_assoc_r: ∀A.∀R1,R2,R3:relation A.
115   (R1 ∘ R2) ∘ R3 ⊆ R1 ∘ (R2 ∘ R3).
116 #A #R1 #R2 #R3 #a #b * #c * * #d * /5 width=5/ 
117 qed.
118
119 (************* functions ************)
120
121 definition compose ≝
122   λA,B,C:Type[0].λf:B→C.λg:A→B.λx:A.f (g x).
123
124 interpretation "function composition" 'compose f g = (compose ? ? ? f g).
125
126 definition injective: ∀A,B:Type[0].∀ f:A→B.Prop
127 ≝ λA,B.λf.∀x,y:A.f x = f y → x=y.
128
129 definition surjective: ∀A,B:Type[0].∀f:A→B.Prop
130 ≝λA,B.λf.∀z:B.∃x:A.z = f x.
131
132 definition commutative: ∀A:Type[0].∀f:A→A→A.Prop 
133 ≝ λA.λf.∀x,y.f x y = f y x.
134
135 definition commutative2: ∀A,B:Type[0].∀f:A→A→B.Prop
136 ≝ λA,B.λf.∀x,y.f x y = f y x.
137
138 definition associative: ∀A:Type[0].∀f:A→A→A.Prop
139 ≝ λA.λf.∀x,y,z.f (f x y) z = f x (f y z).
140
141 (* functions and relations *)
142 definition monotonic : ∀A:Type[0].∀R:A→A→Prop.
143 ∀f:A→A.Prop ≝
144 λA.λR.λf.∀x,y:A.R x y → R (f x) (f y).
145
146 (* functions and functions *)
147 definition distributive: ∀A:Type[0].∀f,g:A→A→A.Prop
148 ≝ λA.λf,g.∀x,y,z:A. f x (g y z) = g (f x y) (f x z).
149
150 definition distributive2: ∀A,B:Type[0].∀f:A→B→B.∀g:B→B→B.Prop
151 ≝ λA,B.λf,g.∀x:A.∀y,z:B. f x (g y z) = g (f x y) (f x z).
152
153 lemma injective_compose : ∀A,B,C,f,g.
154 injective A B f → injective B C g → injective A C (λx.g (f x)).
155 /3/; qed-.
156
157 (* extensional equality *)
158
159 (* moved inside sets.ma
160 definition exteqP: ∀A:Type[0].∀P,Q:A→Prop.Prop ≝
161 λA.λP,Q.∀a.iff (P a) (Q a). *)
162
163 definition exteqR: ∀A,B:Type[0].∀R,S:A→B→Prop.Prop ≝
164 λA,B.λR,S.∀a.∀b.iff (R a b) (S a b).
165
166 definition exteqF: ∀A,B:Type[0].∀f,g:A→B.Prop ≝
167 λA,B.λf,g.∀a.f a = g a.
168
169 (*
170 notation " x \eqP y " non associative with precedence 45 
171 for @{'eqP A $x $y}.
172
173 interpretation "functional extentional equality" 
174 'eqP A x y = (exteqP A x y). *)
175
176 notation "x \eqR y" non associative with precedence 45 
177 for @{'eqR ? ? x y}.
178
179 interpretation "functional extentional equality" 
180 'eqR A B R S = (exteqR A B R S).
181
182 notation " f \eqF g " non associative with precedence 45
183 for @{'eqF ? ? f g}.
184
185 interpretation "functional extentional equality" 
186 'eqF A B f g = (exteqF A B f g).
187
188 (********** relations on unboxed pairs **********)
189
190 definition bi_relation: Type[0] → Type[0] → Type[0]
191 ≝ λA,B.A→B→A→B→Prop.
192
193 definition bi_reflexive: ∀A,B. ∀R:bi_relation A B. Prop
194 ≝ λA,B,R. ∀a,b. R a b a b.
195
196 definition bi_symmetric: ∀A,B. ∀R: bi_relation A B. Prop ≝ λA,B,R.
197                          ∀a1,a2,b1,b2. R a2 b2 a1 b1 → R a1 b1 a2 b2.
198
199 definition bi_transitive: ∀A,B. ∀R: bi_relation A B. Prop ≝ λA,B,R.
200                           ∀a1,a,b1,b. R a1 b1 a b →
201                           ∀a2,b2. R a b a2 b2 → R a1 b1 a2 b2.
202
203 definition bi_RC: ∀A,B:Type[0]. bi_relation A B → bi_relation A B ≝
204                   λA,B,R,a1,b1,a2,b2. R … a1 b1 a2 b2 ∨ (a1 = a2 ∧ b1 = b2).
205
206 lemma bi_RC_reflexive: ∀A,B,R. bi_reflexive A B (bi_RC … R).
207 /3 width=1/ qed.
208
209 (********** relations on unboxed triples **********)
210
211 definition tri_relation: Type[0] → Type[0] → Type[0] → Type[0]
212 ≝ λA,B,C.A→B→C→A→B→C→Prop.
213
214 definition tri_reflexive: ∀A,B,C. ∀R:tri_relation A B C. Prop
215 ≝ λA,B,C,R. ∀a,b,c. R a b c a b c.
216
217 definition tri_symmetric: ∀A,B,C. ∀R: tri_relation A B C. Prop ≝ λA,B,C,R.
218                           ∀a1,a2,b1,b2,c1,c2.
219                           R a2 b2 c2 a1 b1 c1 → R a1 b1 c1 a2 b2 c2.
220
221 definition tri_transitive: ∀A,B,C. ∀R: tri_relation A B C. Prop ≝ λA,B,C,R.
222                            ∀a1,a,b1,b,c1,c. R a1 b1 c1 a b c →
223                            ∀a2,b2,c2. R a b c a2 b2 c2 → R a1 b1 c1 a2 b2 c2.