4. 二元关系
Definition 4.1 Let A \mathbf{A} A and B \mathbf{B} B be sets. Any R ⊆ A × B \mathbf{R} \subseteq \mathbf{A} \times \mathbf{B} R⊆A×B is called a binary relation.
4.1 常见的二元关系
- 如果 A = B = N \mathbf{A} = \mathbf{B} = \mathbb{N} A=B=N, 即它们都为整数集合. 则 R = = { ( 0 , 0 ) , ( 1 , 1 ) , ( 2 , 2 ) , … } \mathbf{R}^{=} = \{(0, 0), (1, 1), (2, 2), \dots\} R=={(0,0),(1,1),(2,2),…}
- 如果 A = B = R \mathbf{A} = \mathbf{B} = \mathbb{R} A=B=R. 则 R < = { ( x , y ) ∈ R 2 ∣ x < y } \mathbf{R}^{<} = \{(x, y) \in \mathbb{R}^2 \vert x < y\} R<={(x,y)∈R2∣x<y}. 在二维平面上, 它表示 y = x y = x y=x 左上方向的区域.
- 稍微复杂一点的关系:
⊆
\subseteq
⊆
令 U = { 1 , 2 } \mathbf{U} = \{1, 2\} U={1,2}
A = 2 U = { ∅ , { 1 } , { 2 } , { 1 , 2 } } \mathcal{A} = 2^\mathbf{U} = \{\emptyset, \{1\}, \{2\}, \{1, 2\}\} A=2U={∅,{1},{2},{1,2}}
R ⊆ = { ( ∅ , ∅ ) , ( ∅ , { 1 } ) , ( ∅ , { 2 } ) , ( ∅ , { 1 , 2 } ) , ( { 1 } , { 1 } ) , ( { 1 } , { 1 , 2 } ) , ( { 2 } , { 2 } ) , ( { 2 } , { 1 , 2 } ) , ( { 1 , 2 } , { 1 , 2 } ) } \mathbf{R}^{\subseteq} = \{(\emptyset, \emptyset), (\emptyset, \{1\}), (\emptyset, \{2\}), (\emptyset, \{1, 2\}), (\{1\}, \{1\}), (\{1\}, \{1, 2\}), (\{2\}, \{2\}), (\{2\}, \{1, 2\}), (\{1, 2\}, \{1, 2\})\} R⊆={(∅,∅),(∅,{1}),(∅,{2}),(∅,{1,2}),({1},{1}),({1},{1,2}),({2},{2}),({2},{1,2}),({1,2},{1,2})}.
4.2 二元关系的性质
对于 A \mathbf{A} A 上的关系, 即 R ⊆ A × A \mathbf{R} \subseteq \mathbf{A} \times \mathbf{A} R⊆A×A.
- 自反性: 如果 ∀ x ∈ A \forall x \in \mathbf{A} ∀x∈A, 均有 ( x , x ) ∈ R (x, x) \in \mathbf{R} (x,x)∈R, 则称 R \mathbf{R} R 具有自反性.
- 对称性: 如果 ∀ ( x , y ) ∈ R \forall (x, y) \in \mathbf{R} ∀(x,y)∈R, 均有 ( y , x ) ∈ R (y, x) \in \mathbf{R} (y,x)∈R, 则称 R \mathbf{R} R 具有对称性.
- 传递性: 如果 ∀ ( x , y ) , ( y , z ) ∈ R \forall (x, y), (y, z) \in \mathbf{R} ∀(x,y),(y,z)∈R, 均有 ( x , z ) ∈ R (x, z) \in \mathbf{R} (x,z)∈R, 则称 R \mathbf{R} R 具有传递性.
4.3 等价关系与划分
如果一个关系同时满足自反性、对称性、传递性, 则称其为一个等价关系.
例如: 自然数 “模 3 同余” 就是一个等价关系.
R
=
{
(
a
,
b
)
∈
N
×
N
∣
a
m
o
d
3
=
b
m
o
d
3
}
\mathbf{R} = \{(a, b) \in \mathbb{N} \times \mathbb{N} \vert a \mod 3 = b \mod 3\}
R={(a,b)∈N×N∣amod3=bmod3}. 源码: \mathbf{R} = \{(a, b) \in \mathbb{N} \times \mathbb{N} \vert a \mod 3 = b \mod 3\}.
R
=
{
(
0
,
3
)
,
(
0
,
6
)
,
(
0
,
9
)
,
…
,
(
1
,
4
)
,
(
1
,
7
)
,
…
,
(
3
,
6
)
,
…
}
\mathbf{R} = \{(0, 3), (0, 6), (0, 9), \dots, (1, 4), (1, 7), \dots, (3, 6), \dots\}
R={(0,3),(0,6),(0,9),…,(1,4),(1,7),…,(3,6),…}.
- 等价关系导致了对原集合的一个划分 (partition), 如
P = { { 0 , 3 , 6 , … } , { 1 , 4 , 7 , … } , { 2 , 5 , 8 , … } } \mathcal{P} = \{\{0, 3, 6, \dots\}, \{1, 4, 7, \dots\}, \{2, 5, 8, \dots\}\} P={{0,3,6,…},{1,4,7,…},{2,5,8,…}}.
集簇 (set family) 用 mathcal. - 等价关系是一些数据挖掘方法 (如粗糙集) 的基础. 例如: 数据按照颜色、形状等符号型属性描述, 则这些属性及其组合就获得了对象集的划分. 于是我们抽象出一些规则:
- 如果是红色的圆球, 那么是塑料制品. (正域)
- 如果是绿色的长方块,那么是木制品. (负域)
- 如果是红色的长方块, 那么既可能是塑料制品, 又可能是木制品. (边界域)
4.4 二元关系的应用
在推荐系统中, 用户集合与项目集合产生二元关系, 可以是购买关系或浏览关系. 该关系可以用一个 n × m n \times m n×m 的 binary 矩阵描述, 其中 n n n 和 m m m 分别是用户数和项目数. 协同过滤算法根据该矩阵确定向哪些用户推荐哪些项目. 参见 推荐系统: 问题、算法与研究思路.
4.5 二元关系的运算
给定
A
=
{
a
,
b
,
c
,
d
}
\mathbf{A} = \{a, b, c, d\}
A={a,b,c,d} 上的关系
R
1
=
{
(
a
,
b
)
,
(
a
,
c
)
}
\mathbf{R}_1 = \{(a, b), (a, c)\}
R1={(a,b),(a,c)} 与
R
2
=
{
(
a
,
b
)
,
(
c
,
d
)
,
(
b
,
d
)
}
\mathbf{R}_2 = \{(a, b), (c, d), (b, d)\}
R2={(a,b),(c,d),(b,d)}, 则
R
2
∘
R
1
=
{
(
a
,
d
)
}
\mathbf{R}_2 \circ \mathbf{R}_1 = \{(a, d)\}
R2∘R1={(a,d)}. 即
R
2
∘
R
1
=
{
(
x
,
y
)
∣
∃
(
x
,
z
)
∈
R
1
and
(
z
,
y
)
∈
R
2
}
\mathbf{R}_2 \circ \mathbf{R}_1 = \{(x, y) \vert \exists (x, z) \in \mathbf{R}_1 \textrm{ and } (z, y) \in \mathbf{R}_2\}
R2∘R1={(x,y)∣∃(x,z)∈R1 and (z,y)∈R2}. 源码: \mathbf{R}_2 \circ \mathbf{R}_1 = \{(x, y) \vert \exists (x, z) \in \mathbf{R}_1 \textrm{ and } (z, y) \in \mathbf{R}_2\}.
说明: 这就是一个接龙游戏. 学习"存在" \exists 的使用.
给定
A
=
{
a
,
b
,
c
,
d
}
\mathbf{A} = \{a, b, c, d\}
A={a,b,c,d} 上的关系
R
\mathbf{R}
R.
- 正闭包: R + = ⋃ i = 1 ∣ A ∣ R i \mathbf{R}^+ = \bigcup_{i = 1}^{\vert \mathbf{A} \vert} \mathbf{R}^i R+=⋃i=1∣A∣Ri.
- 克林闭包: R ∗ = R + ∪ R 0 \mathbf{R}^* = \mathbf{R}^+ \cup \mathbf{R}^0 R∗=R+∪R0, 其中 R 0 = { ( x , x ) ∣ x ∈ A } \mathbf{R}^0 = \{(x, x) \vert x \in A\} R0={(x,x)∣x∈A}.
注意: 这里不是 R 1 ∘ R 2 \mathbf{R}_1 \circ \mathbf{R}_2 R1∘R2. 与函数 g ( f ( x ) ) g(f(x)) g(f(x)) 的道理相同, 先运算的放在右面.
4.6 作业
- 令 A = { 1 , 2 , 5 , 8 , 9 } \mathbf{A} = \{1, 2, 5, 8, 9\} A={1,2,5,8,9}, 写出 A \mathbf{A} A 上的 “模 2 同余” 关系及相应的划分.
- A = { 1 , 2 , 5 , 8 , 9 } \mathbf{A} = \{1, 2, 5, 8, 9\} A={1,2,5,8,9}, 自己给定两个关系 R 1 \mathbf{R}_1 R1 和 R 2 \mathbf{R}_2 R2, 并计算 R 1 ∘ R 2 \mathbf{R}_1 \circ \mathbf{R}_2 R1∘R2, R 1 + \mathbf{R}_1^+ R1+, R 1 ∗ \mathbf{R}_1^* R1∗.
- 查阅粗糙集上下近似的定义并大致描述.