Go backward to 3.2 Tuples Go up to 3 Sets, Relations, and Functions Go forward to 3.4 Functions as Sets |
R is a relation between S0, ..., Sn-1 : <=> R subset S0 x ... x Sn-1.An n-ary relation is a subset of a Cartesian product of n sets:
R is a relation of arity n (an n-ary relation) : <=>Let R be an n-ary relation. We define the (n+1)-ary predicate
exists S_0, ..., S_n-1: R is a relation between S_0, ..., S_n-1;
R is an n-ary relation on S : <=>
R subset S x ... x S (cartesian product of n instances of S).
R is a relation on S : <=> R is a 2-ary ( binary) relation on S.
R(x0, ..., xn-1) : <=> <x0, ..., xn-1> in R.and read this as R holds on (ist gültig für) x0, ..., xn-1. If R is a binary relation, we may write this as x0 R x1.
forall x: exists R: (forall y: R(x,y) => x=y)with the understanding that this is interpreted in the domain of sets as
forall x: exists R: (forall y: <x,y> in R => x=y)where R represents a relation, i.e., a set.
Take S := {<x, x/2>: x in N}. S is a relation between N and Q (the set of all rational numbers) and it is also a relation on Q; however, it is not a relation on N (because 1/2 not in N).
The empty set 0 is a relation on every set S.
Logic Evaluator
We define the predicates Relation
(R)
(R is a relation), isRelation
(R, A, B)
(R is a relation between A and B) as shown below:
Relations can be represented in various forms.
{<0, 1>, <0, 2>, <0, 3>, <0, 4>, <1, 2>, <1, 3>, <1, 4>, <2, 3>, <2, 4>, <3, 4>}.Another representation is a truth matrix where an entry true for <x, y> indicates x R y (all entries not shown are false):
A graphical representation is that by a directed graph where an arrow x -> y indicates x R y:
x\y 0 1 2 3 4 ... 0 false true true true true 1 false false true true true 2 false false false true true 3 false false false false true 4 false false false false false ...
We now introduce a notion by which we can denote those values that are affected by a relation.
domain(R) := {r0: r in R}.The range (Wertebereich) of R is the set of all second components of the tuples in R:
range(R) := {r1: r in R}.
An equivalent characterization is given by the following law:
(forall x: x in domain(R) <=> exists y: <x, y> in R); (forall y: y in range(R) <=> exists x: <x, y> in R).
For the empty relation, we have domain(0) = range(0) = 0.
Logic Evaluator The functions domain
and range
are
defined as shown in the corresponding mathematical definitions:
The order of elements in a binary relation can be inverted.
R-1 := {<b, a>: a in A /\ b in B /\ <a, b> in R}.
Above definition uses the notion R subset A x B to denote that R is a binary relation between A and B (as is common mathematical practice). The clause a in A /\ b in B is only added to make the set quantifier conform to the syntax given here.
Logic Evaluator We can define the function ^-1
(R)
(i.e., R-1) as shown below:
Two relations may be combined via an intermediate set to form another relation.
R o S := {<a, c>: a in domain(R) /\ c in range(S) /\ (exists b: <a, b> in R /\ <b, c> in S)}.
The clause a in A /\ c in C may be omitted in above definition; it is only used to make the set quantifier conform to the syntax given here.
An arrow between an element of A and an element of C exists only if there exist two arrows that are correspondingly connected via some intermediate point in B.
Logic Evaluator We can define o
(R, S) (i.e,
R o S) as follows:
(R-1)-1 = R; R o (S o T) = (R o S) o T; (R o S)-1 = S-1 o R-1.
We argue for the correctness of the first law.
(1) (R-1)-1 = R.Because of the definition of =, we have to show
(2) forall r: r in (R-1)-1 <=> r in R.Take arbitrary r.
(3) r in (R-1)-1and show r in R.
We have R subset A x B, therefore we know by definition of -1 that R-1 subset B x A and (R-1)-1 subset A x B. Thus we can find by (3) some a in A and b in B such that r = <a, b>. By definition of -1, we have <b, a> in R-1. Again, by definition of -1, we know that <a, b> in R, therefore r in R.
Logic Evaluator We may test whether our definitions of inversion and composition of relations conform to these laws: