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