Lecture from: 14.10.2024 | Video: Videos ETHZ

## Relations

In essence, a relation is simply a **connection or association** between elements from two sets. Imagine you have a set of students ($A$) and a set of courses they enroll in ($B$). A relation could describe which students take which courses. This connection can be represented as pairs: each pair links a student to the course(s) they are enrolled in.

Formally, we define a relation $ρ$ as: $ρ⊆A×B$ $(a,b)∈ρ≡aρb$

This means that $ρ$ is a **subset** of the **Cartesian product** of sets $A$ and $B$. The Cartesian product ($A×B$) is the set of all possible ordered pairs where the first element comes from $A$ and the second element comes from $B$.

**Example: ≤**

- $A=B=N$
- $ρ=≤$
- $2≤5$
- $(2,5)∈≤$

**Example: School**

Let’s say:

- $A={Alice, Bob, Carol}$ (Set of students)
- $B={Math, Physics, History}$ (Set of courses)

A relation $ρ$ could represent the following:

- $ρ={(Alice, Math),(Bob, Physics),(Carol, History)}$

We now introduce a new set:

- $T={David, Emily, Frank}$ (Set of teachers)

And a relation $τ$ that connects subjects with their respective teachers:

- $τ={(Math, David),(Physics, Emily),(History, Frank)}$

**Visualizing the Connections:**

**Students (A):**Alice, Bob, Carol**Courses (B):**Math, Physics, History**Teachers (T):**David, Emily, Frank

And the relations:

- $ρ$ connects students to courses they take (e.g., Alice takes Math).
- $τ$ connects subjects with teachers who teach them (e.g., David teaches Math).

### Inverse

Given a relation $ρ⊆A×B$, its inverse, denoted as $ρ^ $, is defined as:

$ρ^ ={(b,a)∣(a,b)∈ρ}$ $bρ^ a⟺aρb$**Example: Inverse of ≤**

**Example: Inverse of School Example**

- $ρ^ ={(Math, Alice),(Physics, Bob),(History, Carol)}$ — “Subject is taken by Student”
- $τ^={(David, Math),(Emily, Physics),(Frank, History)}$ — “Teacher teaches Subject”

**Example: Parent Relationship**

Let us define $isparentof (ip)$ as $xipy⟺xis parent ofy$. Then the inverse is: $ip =ischildof (ic)$.

### Composition of Relations

The **composition** of two relations, $ρ$ and $σ$, is denoted as $ρ∘σ$. It represents a new relation formed by applying $ρ$ and then $σ$.

**Formal Definition:**

If $ρ⊆A×B$ and $σ⊆B×C$, then their composition, $ρ∘σ$, is defined as:

$ρ∘σ={(a,c)∣∃b∈B:(a,b)∈ρand(b,c)∈σ}$**Example: Student-Subject-Teacher**

- $ρ={(Alice,Math),(Bob,Physics)}$ (Student takes Subject)
- $σ={(Math,David),(Physics,Emily)}$ (Subject is taught by Teacher)

Then $ρ∘σ={(Alice,David),(Bob,Emily)}$ (Student is taught by Teacher).

**Example: Child-Parent**

- $ip∘ip=igp$ (is grandparent of)
- $(ic∘ip)∖id=ihs$ (is half-sibling of) — The identity relation (id) is removed to exclude a person being their own half-sibling.

### Proof of Lemma 3.8

**Lemma 3.8:** $ρ∘σ =σ^∘ρ^ $

**Proof:**

- $aρ∘σ c⟺c(ρ∘σ)a$
- $⟺∃b(cρb∧bσa)$
- $⟺∃b(bρ^ c∧aσ^b)$
- $⟺a(σ^∘ρ^ )c$

### Visualization using Matrices

Relations can be represented visually using matrices, offering a structured way to understand their connections.

**Matrix Representation:**

Consider a relation $R$ on a set $A={a_{1},a_{2},a_{3}}$. We can represent this relation as a matrix $M_{R}$ where:

- The rows and columns of the matrix correspond to the elements in set $A$.
- An entry $M_{ij}$ is 1 if $(a_{i},a_{j})∈R$ (meaning there’s a connection from $a_{i}$ to $a_{j}$) and 0 otherwise.

**Example:**

Let’s say $R={(a_{1},a_{2}),(a_{2},a_{3})}$. The matrix representation of $R$ would be:

$M_{R}= 000 100 010 $**Inverse Relation and Matrix Transposition:**

The inverse relation $R_{−1}$ of a relation $R$ is defined as: $(a,b)∈R_{−1}$ if and only if $(b,a)∈R$.

Importantly, the matrix representation of the inverse relation is simply the **transpose** of the original matrix.

**Example (continued):**

The inverse relation $R_{−1}$ would be: $(a_{2},a_{1}),(a_{3},a_{2})$. The transposed matrix $M_{R_{−1}}$ is:

$M_{R_{−1}}= 010 001 000 $### Properties and Rules

#### 1. Associativity:

Composition of relations is **associative**. If we have three relations $ρ$, $σ$, and $τ$ (where $ρ$ ⊆ $A×B$, $σ$ ⊆ $B×C$, and $τ$ ⊆ $C×D$), then: ($ρ$ ∘ $σ$) ∘ $τ$ = $ρ$ ∘ ($σ$ ∘ $τ$)

#### 2. Non-Commutativity:

Composition of relations is **not commutative**. This means that generally, $ρ$ ∘ $σ$ ≠ $σ$ ∘ $ρ$.

#### 3. Identity Relation:

There exists an **identity relation** for each set, denoted as $I_{A}$ if A is our set.

- $I_{A}$ = {($a$, $a$) | $a$ ∈ $A$} – It connects an element only to itself. Applying the identity relation doesn’t change anything.

**Example with Composition:**
Let $ρ$ be a relation “student takes a subject” and $I_{B}$ be the identity relation on the set of subjects. Then: $ρ$ ∘ $I_{B}$ = $ρ$

This means taking a subject followed by being that same subject doesn’t change anything!

#### 4. Reflexivity, Symmetry, Antisymmetry, Transitivity, Asymmetry:

These are properties that relations can possess. A relation is:

**Reflexive**

If for every element ‘a’ in set A, ($a$, $a$) $∈$ $ρ$ Alternate: $id⊆ρ$

Similarly **irreflexive** is the opposite: $aρ a$ for every ‘a’ in A.

**Symmetric**

If for every pair ($a$, $b$) $∈$ $ρ$, then ($b$, $a$) $∈$ $ρ$ Alternate: $ρ=ρ $

**Antisymmetric**

If for every pair ($a$, $b$) and ($b$, $a$) $∈$ $ρ$, then $a=b$. (If (a, b) and (b, a) are both in the relation, then ‘a’ and ‘b’ must be the same element.) Same as: $aρb⟺bρa$ Alternative: A relation $ρ$ is antisymmetric if it is true for all $a,b∈A$ if $ρ∩ρ ⊆id$

**Transitive**

If for every triple ($a$, $b$), ($b$, $c$) $∈$ $ρ$, then ($a$, $c$) $∈$ $ρ$. Same as: $aρb∧bρc⟹aρc$ Alternative: A relation $ρ$ is transitive if and only if $ρ_{2}⊆ρ$.

**Asymmetric**

If for every pair ($a$, $b$) $∈$ $ρ$, then ($b$, $a$) $∈/$ $ρ$. (In other words, if (a, b) is in the relation, then (b, a) cannot be.)

### Transitive Closure

The transitive closure of a relation $R$ on a set $A$ is the smallest transitive relation containing $R$. In simpler terms, it includes all pairs $(x,y)$ where there exists a path from $x$ to $y$ through $R$, even if that path involves multiple steps.

**Formalization:**

Let $R$ be a relation on set $A$. The transitive closure of $R$, denoted as $R_{∗}$, can be defined recursively as follows:

- $R⊆R_{∗}$ (The original relation is included)
- If $(x,y)∈R_{∗}$ and $(y,z)∈R$, then $(x,z)∈R_{∗}$

**Example: “Parent” and “Ancestor” Relationships”**

Let’s say our set $A$ represents people, and the relation $R$ is defined as “is a parent of.” For instance: (John, Mary) $∈R$ (John is Mary’s parent)

Now, we want to find the transitive closure $R_{∗}$ which would represent the “ancestor” relationship.

**Direct Parents:**The initial relation includes direct parent-child pairs like (John, Mary).**Transitive Steps:**Since John is Mary’s parent, and Mary could potentially have children who are also descendants of John, we include those relationships in $R_{+}$ too.

For example:

- If Mary has a child named David, then (John, David) would be in $R_{∗}$ because John is the ancestor of David through his direct relationship with Mary.

The transitive closure can grow quite large for complex relations with many elements. There are algorithms to efficiently compute the transitive closure, but it’s essential to understand its concept and how it extends a relation beyond direct connections.

**Continue here:** 09 Equivalency Relation and Classes, Partitions, Partially Ordered Sets