Relations
(関係)
Discrete Mathematics I
9th lecture, November 25, 2022
https://www.sw.it.aoyama.ac.jp/2022/Math1/lecture9.html
Martin J. Dürst

© 2005-22 Martin
J. Dürst Aoyama Gakuin
University
Today's Schedule
- Summary and homework from last lecture
- Importance of relations for IT
- Definitions: Tuples, cross products, and relations
- Representations of relations
- Operations on relations: Inversion, Composition
- Relations, functions, and predicates
- This week's homework
Homework 1: Ternary Logic
For ternary (three-valued) logic, create defining truth tables for
conjunction, disjunction, and negation. The three values are T, F, and
?, where ? stands for "unknown" (in more
words: "maybe true, maybe false, we don't know").
Hint: What's the result of "?∨T"? ? can
be T or F, but in both cases the result will be T, so
?∨T=T.
[solution remonved]
Homework 2:
Examples for Laws for Quantifiers
Give one example for law 4 and two examples (one for each direction) for law
11 of the laws for quantifiers. Do not use students in your example. There will
be a deduction for examples that are too similar to those submitted by other
students.
Summary of Last Lecture
- Predicate logic allows more general statements and inferences than
propositional logic
- Formulæ including quantifiers can be rewritten using the laws for
quantifiers
- The universal quantifier (∀) and the existential quantifier (∃)
correspond to operations such as sum (∑) and product (∏)
- Universal quantification over an empty set produces T because the neutral
element of conjunction is T (vacuous truth)
Examples of Relations
- Relation between students, teachers, lectures, and rooms:
Hanako Aoyama, Martin J. Dürst, Discrete Mathematics I, E-202
Taro Sagamihara, Martin J. Dürst, Discrete Mathematics I, E-202
...
- Relation of train stations that can be reached without changing
trains:
Fuchinobe, Machida
Machida, Shinjuku
Yokohama, Narita
...
Importance of Relations for IT
- Relational databases
- Relations and graphs
- Relations and logical operations
Tuples
- Sets are not ordered. Tuples are ordered.
- An ordered pair is a tuple with two elements.
- The ordered pair of a and b is written
(a, b).
- {a, b} = {b, a}.
(a, b) ≠ (b, a).
- An n-tuple is an ordered sequence of
n elements.
- Tuples with a fixed number of elements are called
triple (3), quadruple (4), quintuple (5), sextuple (6), septuple (7),
octuple (8), nonuple (9),...
- Example: Quintuple of (student, teacher, lecture, room, time)
(Hanako Aoyama, Martin J. Dürst, Discrete Mathematics I, E-202,
Friday-2)
Cartesian Product
- The Cartesian product (set) of two sets A and
B is the set of all ordered pairs of elements from A
and B.
- The Cartesian product of A and B is written
A × B.
- A × B = {(x, y) |
x ∈ A, y ∈ B}
Example: A = {2, 3}, B = {5, 6}, A ×
B = {(2, 5), (2, 6), (3, 5), (3, 6)}
- Size of A × B: |A × B| =
|A|·|B|
- Instead of A × A, one often writes
A2.
- The Cartesian product is also defined for more than two sets.
Example 1: Cartesian product of A, B, C,
D:
A × B × C × D = {(x, y, z, v) |
x ∈ A∧ y ∈ B ∧
z ∈ C ∧ v ∈ D}
Example 2: Cartesian product of lectures, teachers, rooms, and students at
Aoyama Gakuin University
(totally about 3000×1000×200×20000 ≅ 1013 quadruples)
Definition of Relation
- A relation R between two sets A and
B is defined as a subset of the Cartesian product
A × B.
- Example: A = {1, 2, 3, 4, 5, 6, 7, 8}, B = {3, 4,
5}; R is the relation "is divisible by" (also called
divisibility)
R = {(3, 3), (6, 3), (4, 4), (8, 4), (5,
5)}
- (x, y) ∈ R can be written as
x R y.
Examples: x>y,...
- A relation between two sets is called a binary relation.
There are also ternary relations, and so on.
- Example: The quaternary relation including all quadruples of (lecture
l, teacher t, room r, student
s) where student s takes lecture l with
teacher t in room r
- A binary relation between A and A is called a
binary relation on A.
Example: A = {1, 2, 3, 4}, a>b: {(2,1), (3,1), (4,1), (4,2), (4,3), (3,2)}
Representation of Relations
(Example: A = {1, 2, 3, 4, 5, 6, 7, 8}, B = {3, 4, 5};
R is the divisibility relation)
- Set representations (because every relation is a set):
- Denotation
Example: R = {(3, 3), (6, 3), (4, 4),
(8, 4), (5, 5)}
- Connotation
Example: R = {(x,
y)| x ∈ A, y ∈ B,
x mod y = 0}
- Matrix representation
- Table representation
- Graph representation
Matrix Representation
A relation between sets A and B is represented as a
matrix where:
- Each row of the matrix corresponds to an element of
A
- Each column of the matrix corresponds to an element of
B
- If the row and column elements are related,
the entry is 1 (true), otherwise 0 (false)
Matrix representation is suited for binary relations. For ternary,...
relations, we need a tensor.
A matrix with only 1 or 0 as entries is called a logical matrix
(also binary matrix, relation matrix, or Boolean
matrix)
Table Representation
A relation between several sets is represented in a table as
follows:
- Use a column for each set of the relation
(i.e. two columns for a binary relation, three columns for a ternary
relation)
- Use a row for each element of the relation (each tuple)
Table representation is suited for relations of any arity.
Table representation is suited for sparse relations
(relations with very few entries).
Table representation is used in relational databases.
Graph Representation
A relation between sets A and B is represented as a
graph as follows:
- The elements of A and B are represented as
vertices (shown as dots).
- A relation from an element of A to an element of B
is represented as a directed edge between the corresponding
vertices (shown as arrows).
- If the vertices of A and B are well separated (e.g.
A on the left, B on the right), then there may be no
need to indicate direction.
- For a binary relation on A, the vertices are often drawn only
once.
Graph representation is only suited for binary relations.
Inverse Relation
- The inverse relation of a binary relation R is written
R-1.
- The inverse relation is the relation with the order of the pairs
reversed.
- xRy ⇔
yR-1x; R-1 =
{(y, x) | (x, y) ∈
R}
- Example: R = {(3, 3), (6, 3), (4, 4), (8, 4), (5, 5)}
R-1 = {(3, 3), (3, 6), (4, 4),
(4, 8), (5, 5)}
- (R-1)-1 = R
Representations of Inverse Relations
- Graph representation: Invert the direction of the edges in the graph
- Table representation: Exchange the two columns
- Matrix representation: Transpose the matrix (exchange vertical and
horizontal direction)
Composition of Relations
- For two binary relations P (from A to B)
and Q (from B to C), we can define the
composition R of P and Q
- We write the composition R of P and Q as
R = P∘Q
- R = {(x, z) | (x,
y) ∈ P ∧ (y, z) ∈
Q}
Examples of Composition of Relations
Example 1: P: Set of (student, lecture) tuples (e.g.: (Hanako
Aoyama, Discrete Mathematics I)); Q: Set of (lecture, teacher)
tuples (e.g.: (Discrete Mathematics I, Martin Dürst)); R =
P∘Q: Set of (student, teacher) tuples (e.g.: (Hanako
Aoyama, Martin Dürst)).
Example 2: P: Set of (parent, child) tuples (e.g. (Ieyasu,
Hidetada), (Hidetada, Iemitsu)); P∘P: Set of
(grandparent, grandchild) tuples (e.g. (Ieyasu, Iemitsu))
Example 3: T: Trips made by riding on a single train ((Fuchinobe,
Nagatsuta) ∈ T) → trips made by changing trains once (i.e. two
train rides): (Fuchinobe, Shibuya) ∈ T∘T
Composition of Relation: Additional Comments
- The composition of two relations corresponds to the matrix
multiplication of their matrix representations
(in the matrix multiplication, scalar multiplication is replaced by
conjunction, and addition is replaced by disjunction; in other words, when
F and T are represented by 0 and 1, any results >1 are changed to 1)
- Attention: Depending on the field of mathematics, sometimes
Q∘P is also used
- P∘Q is derived from matrix multiplication
- Q∘P is derived from function composition
[the composition of functions p() and q() is
q(p())]
- In this lecture, we use P∘Q
Relations and Functions
- An n-ary relation is equivalent to a function f
from n arguments to a Boolean value (T/F)
R = {(x, y, z) |
f(x, y, z)=T }
- A function returns only one result for each input
- An n-ary relation can be seen as a function g with
n-1 arguments and a set as a return value
g(x, y) = {z | (x,
y, z) ∈ R}
- A function with n-1 arguments can be expressed as an
n-ary relation
f(x, y) = z ⇒ R =
{(x, y, z) | f(x,
y) = z}
Relations and Predicates
- Example of function: parent (x) = y (the parent of
x is y)
- Example of predicate: parent (y, x) (y
is the parent of x)
- Predicates express properties (mainly predicates with 1 argument)
and relations (predicates with 2 or more arguments)
- Relations and predicates are very closely related concepts
- The difference is mostly in field of use:
predicates: logic
relations: structure, databases
- There are also 1-tuples (singletons), and even a 0-tuple,
but relations (subsets) defined with them are not very interesting
Summary
- A relation is a mathematical concept important in many fields of
information technology
- A relation is a subset of the Cartesian product of a number of sets
- Relations can be represented as sets (using denotation or connotation),
as a matrix, as a graph, or as a table
- Binary relations can be inverted and composed
This Week's Homework
Deadline: December 1, 2022 (Thursday), 18:40.
Format: A4 single page (using both sides is okay; NO cover
page), easily readable handwriting (NO printouts), name (kanji
and kana) and student number at the top right
Where to submit: Box in front of room O-529 (building O, 5th floor)
Describe three relations from the real world (not just made-up toy examples)
that can be expressed as mathematical relations:
- A binary relation on a single set.
- A binary relation between two different sets.
- A relation between more than two sets.
For each relation, describe the set(s) used (including approximate size) and
the conditions for a tuple to be a member of the relation. Give the approximate
sizes of the Cartesian product and the relation, and give three examples of
tuples belonging to the relation. Make sure you describe the sets, and do not
enumerate them. E.g. "prefectures of Japan", not {Tokyo,
Kanagawa, Chiba, Saitama}
Example (for a binary relation between two different sets): Teachers (size
~1000) and lecture halls (size ~200) at AGU: The relation is true if a teacher
t teaches in lecture hall l. Size of Cartesian product:
~200,000; size of relation: ~2000; Example elements: (Martin Dürst, E-202),
(Martin Dürst, E-203).
Hint: If you do not understand the concept of
relation very well yet, consult additional references (books, the
Web)
Important: There will be a deduction if different students
submit the same or very similar relations.
Glossary
- relational database
- 関係データベース
- tuple
- タプル
- ordered pair
- 順序対
- n-tuple
- n 項組、n 字組
- triple
- 三項組、三字組
- quadruple
- 四項組、四字組
- quintuple
- 五項組、五字組
- sextuple
- 六項組、六字組
- septuple
- 七項組、七字組
- octuple
- 八項組、八字組
- nonuple
- 九項組、九字組
- Cartesian product (set)
- 直積 (集合)
- definition
- 定義
- divisible
- 割り切りが可能
- binary relation
- 2項関係
- ternary relation
- 3項関係
- (binary) relation on A
- A の中の関係、A の上の関係、A
における関係
- representation
- 表現
- matrix
- 行列
- binary (logical) matrix
- 論理行列
- row
- 行
- column
- 列、欄
- correspond to
- と対応する
- tensor
- テンソル
- arity
- アリティ
- sparse
- スパース、まばら (な)
- vertex (plural: vertices)
- 頂点、節
- edge
- 辺
- directed
- 有向 (の)
- opposite
- 反対
- inverse relation
- 逆関係
- composition
- 合成
- matrix multiplication
- 行列の掛け算、(通常の) 行列の積