Relations

See disclaimer about the slides.
See learning objectives and sources.

Relation (definition)

A relation $R$ is a subset of the cartesian product of some sets $S_1,\ldots S_n$.
Notation for binary relations: $({\mathbb Z},<)$.

Relation (example)

Example: $S$ set of students $\{Ann, Bud, Carla, \ldots\}$, $C$ set of course $\{161,250,\ldots\}$.
Relation $takes \subseteq S \times C$ is defined by, e.g., $takes=\{ (Ann,161), (Bud,161), (Bud,250) \}$.
Infix notation: $Ann~takes~161$.

Binary Relation (notation)

$(S,R)$ where $S$ is a set and $R \subset S \times S$.
Example: ''less than'' over the integers, $({\mathbb Z},<)$.

Representing relations (Example I)

Venn diagrams (a relation is a set).
Arrow diagrams (a relation is a correspondence).

relation_2.png

Binary relation on a set: a directed graph (defined later).
Binary relation on a set: a matrix.

Inverse, composition (definition)

If $A$ and $B$ are sets and $R$ a relation over $A \times B$, then
the inverse $R^{-1}$ of $R$ is defined by:

$\forall a \in A, b \in B ~ ((b,a) \in R^{-1} \leftrightarrow (a,b) \in R$)

Show during lecture the inverse of Example I.
Question: if $R$ is called ''parent'' how is $R^{-1}$ called ?

If $A$, $B$ and $C$ are sets, $R \subseteq A \times B$, and $S \subseteq B \times C$ then
the composition $S \circ R$ of $R$ and $S$ is defined by:

$\forall a \in A, c \in C ~ ((a,c) \in S \circ R \leftrightarrow \exists b \in B ((a,b) \in R \land (b,c) \in S))$.

Ex: compose ''student takes course'' with ''course is taught in classroom''

Inverse, composition (examples)

Relations $F$ and $D$ are binary on ${\mathbb N}$.
Let $F=\{(x,y) \mid xk=y \mbox{ for some } k \in {\mathbb N}\}$.
Let $D=\{(x,y) \mid \mbox{the decimal representation of $x$ and $y$ end with the same digit}\}$.
During the lecture: understand the above relations, find their inverses and compositions.

Properties (definition)

Let $R$ be a binary relation on a set $A$.
reflexive: $\forall x \in A ~ (x ~ R ~ x)$ .
symmetric: $\forall x,y \in A ~ (x ~ R ~ y \to y ~ R ~ x)$ .
transitive: $\forall x,y,z \in A ~ (x ~ R ~ y \land y ~ R ~ z \to x ~ R ~ z)$ .
antisymmetric: $\forall x,y \in A ~ (x ~ R ~ y \land y ~ R ~ x \to x=y)$ .

Properties (examples)

Consider the following binary relations on $A=\{0,1\}$: $\varnothing$, $A \times A$, $=$ and $\lt$.
During the lecture for each relation, for each property, discuss whether the property holds for the relation.

Partial order

Reflexive, transitive, antisymmetric. Often denoted ''$\leq$'' or ''$\preceq$''.
Ex.: $(\mathbb Z, \leq)$, $(\mathbb Z^+, |)$ where $a|b \leftrightarrow \exists t ~ (b = at)$, $(2^A, \subseteq)$ where $A$ is any set.
Note: reflexive is optional for some authors.
Representation: Hasse diagrams, left $2^{\{a,b,c\}}$, right $(\{1,2,\ldots 10\}, |)$.

hasse_powerset_2.jpeg        hasse_divides_2.png

Equivalence

Reflexive, symmetric, transitive. Often denoted ''$\sim$''.
Ex.: on $\mathbb Z$, $x \sim y \leftrightarrow x ~{\rm mod~ } 5 = y ~{\rm mod~ } 5$.
Ex.: on Students, $x \sim y \leftrightarrow x$ and $y$ are born in the same month.
Equivalence class of $x$: $[x] = \{y \mid x \sim y, y \in A\}$.
Quotient: $A/\!\!\sim = \{[x] \mid x \in A\}$.
$A/\!\!\sim$ is a partition $\{A_1,A_2, \ldots \}$ of $A$:
1. $A_i \cap A_j = \varnothing$, for $i \ne j$,
2. $\displaystyle \cup_i A_i = A$.

Notation

Both $\mathbb N_k$ and $\mathbb Z_k$ denote the set $\{0,1,\ldots k-1\}$. Elements in this set can be added, multiplied, etc., always modulo $k$.
E.g., $\mathbb N_5 = \{0,1,2,3,4\}$ and in this set $2-4=3$ because $-2=3$ (everything mod 5).

Programming

Programming with relations

There are programming languages where the program is a set of relations and an execution is telling whether a relation is satisfied for some values.
One such language is Prolog. For a taste see this example.