]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/lib/basics/relations.ma
- lambda: parallel reduction to obtain diamond property
[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 reflexive: ∀A.∀R :relation A.Prop
30 ≝ λA.λR.∀x:A.R x x.
31
32 definition symmetric: ∀A.∀R: relation A.Prop
33 ≝ λA.λR.∀x,y:A.R x y → R y x.
34
35 definition transitive: ∀A.∀R:relation A.Prop
36 ≝ λA.λR.∀x,y,z:A.R x y → R y z → R x z.
37
38 definition irreflexive: ∀A.∀R:relation A.Prop
39 ≝ λA.λR.∀x:A.¬(R x x).
40
41 definition cotransitive: ∀A.∀R:relation A.Prop
42 ≝ λA.λR.∀x,y:A.R x y → ∀z:A. R x z ∨ R z y.
43
44 definition tight_apart: ∀A.∀eq,ap:relation A.Prop
45 ≝ λA.λeq,ap.∀x,y:A. (¬(ap x y) → eq x y) ∧
46 (eq x y → ¬(ap x y)).
47
48 definition antisymmetric: ∀A.∀R:relation A.Prop
49 ≝ λA.λR.∀x,y:A. R x y → ¬(R y x).
50
51 definition singlevalued: ∀A,B. predicate (relation2 A B) ≝ λA,B,R.
52                          ∀a,b1. R a b1 → ∀b2. R a b2 → b1 = b2.
53
54 (* Reflexive closure ************)
55
56 definition RC: ∀A:Type[0]. relation A → relation A ≝
57                λA,R,x,y. R … x y ∨ x = y.
58
59 lemma RC_reflexive: ∀A,R. reflexive A (RC … R).
60 /2 width=1/ qed.
61
62 (********** operations **********)
63 definition Rcomp ≝ λA.λR1,R2:relation A.λa1,a2.
64   ∃am.R1 a1 am ∧ R2 am a2.
65 interpretation "relation composition" 'compose R1 R2 = (Rcomp ? R1 R2).
66
67 definition Runion ≝ λA.λR1,R2:relation A.λa,b. R1 a b ∨ R2 a b.
68 interpretation "union of relations" 'union R1 R2 = (Runion ? R1 R2).
69     
70 definition Rintersection ≝ λA.λR1,R2:relation A.λa,b.R1 a b ∧ R2 a b.
71 interpretation "interesecion of relations" 'intersects R1 R2 = (Rintersection ? R1 R2).
72
73 definition inv ≝ λA.λR:relation A.λa,b.R b a.
74
75 (*********** sub relation ***********)
76 definition subR ≝ λA.λR,S:relation A.(∀a,b. R a b → S a b).
77 interpretation "relation inclusion" 'subseteq R S = (subR ? R S).
78
79 lemma sub_reflexive : 
80   ∀T.∀R:relation T.R ⊆ R.
81 #T #R #x //
82 qed.
83
84 lemma sub_comp_l:  ∀A.∀R,R1,R2:relation A.
85   R1 ⊆ R2 → R1 ∘ R ⊆ R2 ∘ R.
86 #A #R #R1 #R2 #Hsub #a #b * #c * /4/
87 qed.
88
89 lemma sub_comp_r:  ∀A.∀R,R1,R2:relation A.
90   R1 ⊆ R2 → R ∘ R1 ⊆ R ∘ R2.
91 #A #R #R1 #R2 #Hsub #a #b * #c * /4/
92 qed.
93
94 lemma sub_assoc_l: ∀A.∀R1,R2,R3:relation A.
95   R1 ∘ (R2 ∘ R3) ⊆ (R1 ∘ R2) ∘ R3.
96 #A #R1 #R2 #R3 #a #b * #c * #Hac * #d * /5/
97 qed.
98
99 lemma sub_assoc_r: ∀A.∀R1,R2,R3:relation A.
100   (R1 ∘ R2) ∘ R3 ⊆ R1 ∘ (R2 ∘ R3).
101 #A #R1 #R2 #R3 #a #b * #c * * #d * /5 width=5/ 
102 qed.
103
104 (************* functions ************)
105
106 definition compose ≝
107   λA,B,C:Type[0].λf:B→C.λg:A→B.λx:A.f (g x).
108
109 interpretation "function composition" 'compose f g = (compose ? ? ? f g).
110
111 definition injective: ∀A,B:Type[0].∀ f:A→B.Prop
112 ≝ λA,B.λf.∀x,y:A.f x = f y → x=y.
113
114 definition surjective: ∀A,B:Type[0].∀f:A→B.Prop
115 ≝λA,B.λf.∀z:B.∃x:A.z = f x.
116
117 definition commutative: ∀A:Type[0].∀f:A→A→A.Prop 
118 ≝ λA.λf.∀x,y.f x y = f y x.
119
120 definition commutative2: ∀A,B:Type[0].∀f:A→A→B.Prop
121 ≝ λA,B.λf.∀x,y.f x y = f y x.
122
123 definition associative: ∀A:Type[0].∀f:A→A→A.Prop
124 ≝ λA.λf.∀x,y,z.f (f x y) z = f x (f y z).
125
126 (* functions and relations *)
127 definition monotonic : ∀A:Type[0].∀R:A→A→Prop.
128 ∀f:A→A.Prop ≝
129 λA.λR.λf.∀x,y:A.R x y → R (f x) (f y).
130
131 (* functions and functions *)
132 definition distributive: ∀A:Type[0].∀f,g:A→A→A.Prop
133 ≝ λA.λf,g.∀x,y,z:A. f x (g y z) = g (f x y) (f x z).
134
135 definition distributive2: ∀A,B:Type[0].∀f:A→B→B.∀g:B→B→B.Prop
136 ≝ λA,B.λf,g.∀x:A.∀y,z:B. f x (g y z) = g (f x y) (f x z).
137
138 lemma injective_compose : ∀A,B,C,f,g.
139 injective A B f → injective B C g → injective A C (λx.g (f x)).
140 /3/; qed-.
141
142 (* extensional equality *)
143
144 (* moved inside sets.ma
145 definition exteqP: ∀A:Type[0].∀P,Q:A→Prop.Prop ≝
146 λA.λP,Q.∀a.iff (P a) (Q a). *)
147
148 definition exteqR: ∀A,B:Type[0].∀R,S:A→B→Prop.Prop ≝
149 λA,B.λR,S.∀a.∀b.iff (R a b) (S a b).
150
151 definition exteqF: ∀A,B:Type[0].∀f,g:A→B.Prop ≝
152 λA,B.λf,g.∀a.f a = g a.
153
154 (*
155 notation " x \eqP y " non associative with precedence 45 
156 for @{'eqP A $x $y}.
157
158 interpretation "functional extentional equality" 
159 'eqP A x y = (exteqP A x y). *)
160
161 notation "x \eqR y" non associative with precedence 45 
162 for @{'eqR ? ? x y}.
163
164 interpretation "functional extentional equality" 
165 'eqR A B R S = (exteqR A B R S).
166
167 notation " f \eqF g " non associative with precedence 45
168 for @{'eqF ? ? f g}.
169
170 interpretation "functional extentional equality" 
171 'eqF A B f g = (exteqF A B f g).
172
173 (********** relations on unboxed pairs **********)
174
175 definition bi_relation: Type[0] → Type[0] → Type[0]
176 ≝ λA,B.A→B→A→B→Prop.
177
178 definition bi_reflexive: ∀A,B. ∀R:bi_relation A B. Prop
179 ≝ λA,B,R. ∀x,y. R x y x y.
180
181 definition bi_symmetric: ∀A,B. ∀R: bi_relation A B. Prop ≝ λA,B,R.
182                          ∀a1,a2,b1,b2. R a2 b2 a1 b1 → R a1 b1 a2 b2.
183
184 definition bi_transitive: ∀A,B. ∀R: bi_relation A B. Prop ≝ λA,B,R.
185                           ∀a1,a,b1,b. R a1 b1 a b →
186                           ∀a2,b2. R a b a2 b2 → R a1 b1 a2 b2.