情報数学 I
第七回 (2013年11月22日)
関係
Relations
Martin J. Dürst
http://www.sw.it.aoyama.ac.jp/2013/Math1/lecture7.html
© 2005-13 Martin
J. Dürst 青山学院大学
今日の予定
- 前回の復習と宿題
- 関係の基本
- 関係の情報テクノロジーでの役割
- 関係の定義
- 関係の表現
- 逆関係、関係の合成
- 関数と関係
前回の復習
- NAND, NOR, XOR
- 論理回路の役割と書き方
- 記号論理 (→ と ↔)
前回の宿題
二つの変数 (例: A, B)
で可能な論理関数を全て表に列挙し、それぞれの関数を
NAND (又は NOR) だけの式で書きなさい。
NAND と NOR
の他に一つの論理関数からすべての論理関数を作れるものはあるか調べなさい。例えば
→ ではどうでしょうか。
[本年度のために削除]
宿題を解くプログラム
[本年度のために削除]
発展問題
[本年度のために削除]
関係(relation)
- 関係の情報テクノロジーでの役割
- 関係の定義
- 関係の表現
- 関数と関係
関係の情報テクノロジーでの役割
- 関係データベース (relational database)
- 関係とグラフ
- 関係と論理演算
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: Quadruple of (lecture, teacher, student, room)
(Mathematics for Computer Scientists I, Martin J. Dürst, Hanako Aoyama,
E101)
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, students, rooms
(totally about 3000×1000×20000×200 ≅ 1013 quadruples)
Definition of Relation
- A relation R between two sets A and B is
defined as a subset of A × B.
- Example: A = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, B = {3, 4}; R is
the relation "is divisible by"
R = {(3, 3), (6, 3), (9, 3), (4, 4), (8,
4)}
- (a, b) ∈ R can be written as
aRb.
Examples: a>b,...
- A relation between two sets is called a binary relation.
There are also ternary relations, and so on.
- A binary relation between A and A is called a
binary relation on A.
Example: A = {1, 2, 3, 4, 5},
Representation of Relations
- A relation is a set. We can therefore use set representations:
- denotation
Example: R = {(3, 3), (6, 3), (9, 3),
(4, 4), (8, 4)}
- 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, otherwise 0
Matrix representation is suited for binary relations.
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.
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.
- A relation from an element of A to an element of B
is represented as a directed edge between the corresponding vertices.
- 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 suited for binary relations.
逆関係
(inverse relation)
- 二項関係の逆関係は順序対を逆にした関係
- R の逆関係を R-1 と書く
- xRy ⇔
yR-1x
- (R-1)-1 = R
- Example: R = {(3, 3), (6, 3), (9, 3), (4, 4), (8, 4)}
R-1 = {(3, 3), (3, 6), (3, 9),
(4, 4), (8, 4)}
関係の合成
- A から B への関係 P、B
からC への関係 Q に対して P と
Q の合成 (composition) が定義されている
- P と Q の合成 R の場合
R = P∘Q と書く
- R = {(x, z) | (x,
y) ∈ P, (y, z) ∈
Q}
- 行列表現では合成は通常の行列の積と相当
(但し、掛け算と足し算の代わりに論理積と論理和を使う)
- 注: 数学の分野などによって、Q∘P
と書くこともある
- P∘Q は行列の掛け算が由来
- Q∘P は関数の合成が由来
(p() と q() の合成は
q(p())
- この授業では P∘Q を使用
関係と関数
- n 項関係は n
項組から真理値への関数
R = {(x, y, z) |
f(x, y, z)=T }
- 関数はある入力に対し一つだけの出力
- n 項関係は n-1
変数の「複数の出力が許されている」関数 (多値関数)
に相当
- n-1 変数の関数は n
項の関係で表現可能
f(x, y) = z ⇔ R =
{(x, y, z) | f(x,
y) = z}
次回の予定
- 次回 (11月29日) は30分間のミニテストを実施
- 今までの授業の内容の範囲
- 問題の例:
- 用語の説明と使い方 (英語を含む)
- 論理式の計算や単純化
- 集合と関係
- 問題文の一部は英語
- 答えは日本語で結構
Glossary
- 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
- 行列
- row
- 行
- column
- 列、欄
- correspond to
- と対応する
- arity
- アリティ
- sparse
- スパース、まばら (な)
- vertex (plural: vertices)
- 頂点、節
- edge
- 辺
- directed
有向 (の)