CADiZ

Reference manual / Standard toolkit / section relation_toolkit


More notations for relations

section relation_toolkit parents set_toolkit

First component projection

[X,Y]

first : X \cross Y \fun X
\where \where \where
\forall x : X; y : Y @ first (x,y) = x

For any ordered pair (x,y), first (x,y) is the x component of the pair.

Second component projection

[X,Y]

second : X \cross Y \fun Y
\where \where \where
\forall x : X; y : Y @ second (x,y) = y

For any ordered pair (x,y), second (x,y) is the y component of the pair.

Maplet

function 10 leftassoc (_ \mapsto _)

[X,Y]

_ \mapsto _ : X \cross Y \fun X \cross Y
\where \where \where
\forall x : X ; y : Y @ x \mapsto y = ( x , y )

The maplet forms an ordered pair from two values; x \mapsto y is just another notation for (x, y).

Domain

[X,Y]

dom : (X \rel Y) \fun \power X
\where \where \where
\forall r : X \rel Y @ dom r = {  p : r @ p.1  }

The domain of a relation r is the set of first components of the ordered pairs in r.

Range

[X,Y]

ran : (X \rel Y) \fun \power Y
\where \where \where
\forall r : X \rel Y @ ran r = {  p : r @ p.2  }

The range of a relation r is the set of second components of the ordered pairs in r.

Identity relation

generic (id _)

id X == {  x : X @ x \mapsto x  }

The identity relation on a set X is the relation that relates every member of X to itself.

Relational composition

function 40 leftassoc (_ \comp _)

[X,Y,Z]

_ \comp _ : (X \rel Y) \cross (Y \rel Z) \fun (X \rel Z)
\where \where \where
\forall r : X \rel Y ; s : Y \rel Z @
r \comp s = {  p : r ; q : s | p.2 = q.1 @ p.1 \mapsto q.2  }

The relational composition of a relation r : X \rel Y and s : Y \rel Z is a relation of type X \rel Z formed by taking all the pairs p of r and q of s, where the second component of p is equal to the first component of q, and relating the first component of p with the second component of q.

Functional composition

function 40 leftassoc (_ \circ _)

[X,Y,Z]

_ \circ _ : (Y \rel Z) \cross (X \rel Y) \fun (X \rel Z)
\where \where \where
\forall r : X \rel Y ; s : Y \rel Z @ s \circ r = r \comp s

The functional composition of s and r is the same as the relational composition of r and s.

Domain restriction

function 65 rightassoc (_ \dres _)

[X,Y]

_ \dres _ : \power X \cross ( X \rel Y ) \fun ( X \rel Y )
\where \where \where
\forall a : \power X ; r : X \rel Y @ a \dres r = {  p : r | p.1 \in a  }

The domain restriction of a relation r : X \rel Y by a set a : \power X is the set of pairs in r whose first components are in a.

Range restriction

function 60 leftassoc (_ \rres _)

[X,Y]

_ \rres _ : ( X \rel Y) \cross \power Y \fun ( X \rel Y )
\where \where \where
\forall r : X \rel Y ; b : \power Y @ r \rres b = {  p : r | p.2 \in b  }

The range restriction of a relation r : X \rel Y by a set b : \power Y is the set of pairs in r whose second components are in b.

Domain subtraction

function 65 rightassoc (_ \ndres _)

[X,Y]

_ \ndres _ : \power X \cross ( X \rel Y ) \fun ( X \rel Y )
\where \where \where
\forall a : \power X ; r : X \rel Y @ a \ndres r = {  p : r | p.1 \notin a  }

The domain subtraction of a relation r : X \rel Y by a set a : \power X is the set of pairs in r whose first components are not in a.

Range subtraction

function 60 leftassoc (_ \nrres _)

[X,Y]

_ \nrres _ : ( X \rel Y) \cross \power Y \fun ( X \rel Y )
\where \where \where
\forall r : X \rel Y ; b : \power Y @
r \nrres b = {  p : r | p.2 \notin b  }

The range subtraction of a relation r : X \rel Y by a set b : \power Y is the set of pairs in r whose second components are not in b.

Relational inversion

function (_ ~)

[X,Y]

_ ~ : ( X \rel Y ) \fun ( Y \rel X )
\where \where \where
\forall r : X \rel Y @ r ~ = {  p : r @ p.2 \mapsto p.1  }

The inverse of a relation is the relation obtained by reversing every ordered pair in the relation.

Relational image

function (_ \limg _ \rimg)

[X,Y]

_ \limg _ \rimg : ( X \rel Y ) \cross \power X \fun \power Y
\where \where \where
\forall r : X \rel Y ; a : \power X @ r \limg a \rimg = {  p : r | p.1 \in a @ p.2  }

The relational image of a set a : \power X through a relation r : X \rel Y is the set of values of type Y that are related under r to a value in a.

Overriding

function 50 leftassoc (_ \oplus _)

[X,Y]

_ \oplus _ : ( X \rel Y ) \cross ( X \rel Y ) \fun ( X \rel Y )
\where \where \where
\forall r , s : X \rel Y @ r \oplus s = ( ( dom s ) \ndres r ) \cup s

If r and s are both relations between X and Y, the overriding of r by s is the whole of s together with those members of r that have no first components that are in the domain of s.

Transitive closure

function (_ +)

[X]

_ + : ( X \rel X ) \fun (X \rel X )
\where \where \where
\forall r : X \rel X @
r + = \bigcap {  s : X \rel X | r \subseteq s \land r \comp s \subseteq s  }

The transitive closure of a relation r : X \rel X is the smallest set that contains r and is closed under the action of composing r with its members.

Reflexive transitive closure

function (_ *)

[X]

_ * : ( X \rel X ) \fun (X \rel X )
\where \where \where
\forall r : X \rel X @ r * = r + \cup id X

The reflexive transitive closure of a relation r : X \rel X is the relation formed by extending the transitive closure of r by the identity relation on X.


IT 5-Jan-2002