Ch9 Relations

Binary Relations

A 二元关系(binary relation) RR from a set AA to a set BB is a subset of A×BA\times B.

  • 关系是集合:“A binary relation RR” is a set.
  • R⊆A×BR\subseteq A\times B
  • R={(a,b)∣a∈A,b∈B,a  R  b}R=\{(a,b)\mid a\in A, b\in B, a\;R\;b\}.
  • “A relation on set AA” means a relation from set AA to itself.
Question: How many binary relations are there on a set AA with nn elements?
2n22^{n^2}
关系的证明题的解题思路
  • 利用定义。
  • 利用数学归纳法。

Representations

Relation Matrices

举个例子,RR 是一个二元关系,表示两个集合中按位或不为零的对:

A={2,3,4},B={2,3,4,5,6}R={(x,y)∣x∈A, y∈B, x∣y}  ⟹  R={(2,2),(2,4),(2,6),(3,3),(3,6),(4,4)}\begin{aligned} A =\{2,&3,4\},B=\{2,3,4,5,6\} \quad R = \{(x,y) \mid x \in A,\ y \in B,\ x \mid y\} \\ &\implies R =\{(2,2),(2,4),(2,6),(3,3),(3,6),(4,4)\} \end{aligned}

可以通过连接矩阵(connection matrix) 表示二元关系:

Directed Graphs

关系 (V,E)(V,E) 对应的有向图(directed graph = digraph) 是将 VV 作为点集,EE 作为边集的图。

对于一条边 (a,b)(a,b),aa 被叫作其起始节点(initial vertice),bb 被叫作其终止节点(terminal vertice)。

Special Properties of Binary Relations

性质条件备注举例
自反性(reflexive)∀x(x∈A→(x,x)∈R)\forall x (x\in A\rightarrow (x,x)\in R)(Z,=)(\mathbb Z, =)
非自反性(irreflexive)∀x(x∈A→(x,x)∉R)\forall x (x\in A\rightarrow (x,x)\not\in R)(Z,≠)(\mathbb Z, \neq)
对称性(symmetric)∀x∀y((x,y)∈R→(y,x)∈R)\forall x\forall y((x,y)\in R\rightarrow (y,x)\in R)(Z+,⊥)(\mathbb Z_+, \perp)
反对称性(antisymmetric)∀x∀y((x,y)∈R∧(y,x)∈R→x=y)\forall x \forall y((x,y)\in R \land (y,x)\in R\rightarrow x=y)与非对称性的差别在于允许有自环。(Z,≤)(\mathbb Z, \leq)
非对称性(asymmetric)∀x∀y((x,y)∈R→¬((y,x)∈R))\forall x \forall y ((x,y) \in R \rightarrow \lnot ((y,x)\in R))与反对称性的差别在于不允许有自环,是更强的条件。(Z,<)(\mathbb Z, <)
传递性(transitive)∀x∀y∀z((x,y)∈R∧(y,z)∈R→(x,z)∈R)\forall x \forall y \forall z ((x,y)\in R \land (y,z)\in R \rightarrow (x,z)\in R)若同时存在 x→yx\rightarrow y 和 y→zy \rightarrow z 的边,则必存在 x→zx\rightarrow z 的边。(Z,≤)(\mathbb Z, \leq)
讨论题

Is a relation RR is reflexive if it is symmetric and transitive?

Yet a wrong proof

(a,b)∈R(a,b) \in R and RR is symmetric implys (b,a)∈R(b,a) \in R.

(a,b)∈R(a,b) \in R, (b,a)∈R(b,a)\in R and RR is transitive (a,a)∈R(a,a) \in R.

Which means that RR is reflexive.

Incorrect. Because it cannot be guaranteed that for all a∈Sa \in S, there exists a bb such that (a,b)∈R(a,b)\in R. Therefore, there might exist such an a∈Ra\in R for which there is no relation concerning aa.”

Combining Relations

因为定义在集合 A,BA, B 上的任意关系 RR 是 A×BA\times B 的子集,我们可以对关系定义任意组合运算。

Set Operations

定义在关系上的集合运算可以直接类比集合上的集合运算。

Let A={a1,a2,⋯ ,an}A=\{a_1,a_2,\cdots,a_n\}, B={b1,b2,⋯ ,bn}B=\{b_1,b_2,\cdots,b_n\}, MR1=[cij]M_{R_1} = [c_{ij}], MR2=[di,j]M_{R_2}=[d_{i,j}], the set operations of two relations are defined by

MR1∪R2=[cij∨dij]=MR1∨MR2MR1∩R2=[cij∧dij]=MR1∧MR2MR1‾=[cij‾]MR1−R2=MR1∩R2‾=[cij∧dij‾]\begin{aligned} M_{R_1 \cup R_2} &= [c_{ij} \lor d_{ij}] = M_{R_1} \lor M_{R_2} \\ M_{R_1 \cap R_2} &= [c_{ij} \land d_{ij}] = M_{R_1} \land M_{R_2}\\ M_{\overline{R_1}}&=[\overline{c_{ij}}]\\ M_{R_1-R_2} &= M_{R_1\cap \overline{R_2}} = [c_{ij} \land \overline{d_{ij}}]\\ \end{aligned}

Composition of Relations

对于关系 R={(a,b)∣a∈A,b∈B,aRb}R=\{(a,b)\mid a\in A,b\in B,aRb\} 和关系 S={(b,c)∣b∈B,c∈C,bSc}S=\{(b,c)\mid b\in B, c\in C, bSc\},定义 SS 与 RR 的复合(the composite of RR and SS) 为:

S∘R={(a,c)∣a∈A∧c∈C∧∃b(b∈B∧aRb∧bSc)}S \circ R =\{(a,c)\mid a\in A \land c\in C \land \exists b(b\in B\land aRb \land bSc)\}
  • 关系合成运算满足结合律:(R∘Q)∘S=R∘(Q∘S)(R\circ Q)\circ S = R \circ (Q \circ S)。

于此我们还可以递归定义关系的幂(the power of relation):

R1=R, and Rn+1=Rn∘RR^1=R,\text{ and }R^{n+1}=R^n\circ R
Theorem

The relation RR on a set AA is transitive if and only if Rn⊆R, n=1,2,3,…R^n \subseteq R,\, n=1,2,3,\ldots.

Proof

(1) ∀n(Rn⊆R)⇒R is transitive\forall n (R^n\subseteq R) \Rightarrow R \text{ is transitive}

(a,b)∈R(a,b)\in R,(b,c)∈R(b,c)\in R,故 (a,b)∈R2(a,b)\in R^2;由于 R2⊆RR^2\subseteq R,可以得到 (a,c)∈R(a,c)\in R,故 R is transitiveR\text{ is transitive}。

(2) R is transitive⇒∀n(Rn⊆R)R\text{ is transitive} \Rightarrow \forall n (R^n \subseteq R)

使用数学归纳法,对于所有 (a,b)∈Rn+1=Rn∘R(a,b)\in R^{n+1}=R^n\circ R,那么 (a,x)∈Rn⊆R, (x,b)∈R(a,x)\in R^n\subseteq R,\ (x,b)\in R 且 RR 有传递性可以推出 (a,b)∈R(a,b)\in R。

Inverse Relations

对于定义在集合 AA 到 BB 上的关系 R={(a,b)∣a∈A,b∈B,aRb}R=\{(a,b)\mid a\in A,b\in B,aRb\},我们可以定义 BB 到 AA 的逆关系(inverse relation):

R−1={(b,a)∣(a,b)∈R,a∈A,b∈B}R^{-1} = \{(b,a) \mid (a,b)\in R ,a\in A,b\in B\}
一些关于逆关系的恒等式

设 R,SR,S 是从集合 AA 到集合 BB 上的关系,TT 是从集合 BB 到集合 CC 的关系,PP 是从集合 CC 到集合 DD 的关系。

  • (R∪S)−1=R−1∪S−1(R \cup S)^{-1} = R^{-1} \cup S^{-1}
  • (R∩S)−1=R−1∩S−1(R\cap S)^{-1} = R^{-1} \cap S^{-1}
  • (R‾)−1=R−1‾(\overline R)^{-1} = \overline{R^{-1}}
  • (R−S)−1=R−1−S−1(R-S)^{-1} = R^{-1} - S^{-1}
  • (A×B)−1=B×A(A\times B)^{-1} = B \times A:
  • R‾=A×B−R\overline R= A \times B - R
  • (S∘T)−1=T−1∘S−1(S \circ T)^{-1} = T^{-1} \circ S^{-1}
  • (R∘T)∘P=R∘(T∘P)(R \circ T) \circ P = R \circ (T \circ P)
  • (R∪S)∘T=R∘T∪S∘T(R \cup S) \circ T = R \circ T \cup S \circ T

Closures of Relations

Definition: 关系的闭包

The 闭包(closure) of a relation RR with respect to property PP is the relation SS with property if and only if

(1) SS contains RR;

(2) SS is a subset of every relation with property PP.

(3) SS is the smallest relation satisfying (1) and (2).

Reflexive Closure

给定关系 RR,其自反闭包(reflexive closure) 是在 RR 上添加元素,使得对于每一个元素 aa,都有 (a,a)(a, a) 在 R 中。

Theorem

关系 RR 的自反闭包用 r(R)r(R) 表示,且满足 r(R)=R∪IAr(R) = R \cup I_A。

  • 这里 IAI_A 表示集合 AA 上的对角线关系,即 IA={(x,x)∣x∈A}I_A = \{(x,x) \mid x \in A\}。

Proof
Corollary

R=R∪IAR = R \cup I_A 当且仅当 RR 是自反关系。

Proof

Symmetric Closure

给定关系 RR,其对称闭包(symmetric closure) 是在 RR 上添加元素,使得对于每一对元素 (a,b)(a, b),如果 (a,b)(a, b) 在 R 中,那么 (b,a)(b, a) 也在 RR 中。

Theorem

关系 RR 的对称闭包用 s(R)s(R) 表示,且满足 s(R)=R∪R−1s(R) = R \cup R^{-1}。

Proof
Corollary

R=R∪R−1R = R \cup R^{-1} 当且仅当 RR 是对称关系。

Transitive Closure

给定关系 RR,其传递闭包(transitive closure) 是在 RR 上添加元素,使得对于每一对元素 (a,b)(a, b) 和 (b,c)(b, c),如果 (a,b)(a, b) 和 (b,c)(b, c) 在 RR 中,那么 (a,c)(a, c) 也在 RR 中。

Theorem 1

设 RR 是定义在 AA 上的关系,则有一条从 aa 到 bb 的长度为 nn 的路径当且仅当 (a,b)∈Rn(a,b) \in R^n。

一些来自下一章的概念:

  • A 路径(path) of length nn in a digraph GG: A sequence of edges (x0,x1),(x1,x2),…,(xn−1,xn)(x_0,x_1),(x_1,x_2),\ldots,(x_{n-1},x_n).

  • 环(cycle): A path of length nn with x0=xn(n≥1)x_0=x_n (n\ge 1).

Proof (by induction)
Theorem 2

The 传递闭包(transitive closure) of a relation RR is t(R)=R∗t(R) = R^\ast.

Definition: 连通关系

连通关系(connectivity relation) 是所有可通过 RR 上的边连通的有序对的集合,即:

R∗=⋃i=1∞RiR^\ast = \displaystyle{\bigcup_{i=1}^\infty R^i}
Proof

证明 R∗R^\ast 是 RR 的传递闭包:

(1) R⊆R∗R \subseteq R^\ast。

(2) R∗R^\ast is transitive:对于任意 (a,b)∈R∗∧(b,c)∈R∗(a,b) \in R^\ast \land (b,c) \in R^\ast,有一条从 aa 到 bb 的路径和一条从 bb 到 cc 的路径,那自然也有一条从 aa 到 cc 的路径,故 (a,c)∈R∗(a,c) \in R^\ast。

(3) R∗R^\ast is the smallest:对于任意 SS 满足 SS 具有传递性且 R⊆SR\subseteq S。我们有 R∗⊆S∗=SR^\ast \subseteq S^\ast = S,故 R∗⊆SR^\ast \subseteq S,得证。

实际上,通过 R∗=⋃i=1nRiR^\ast = \displaystyle{\bigcup_{i=1}^n R^i} 即可计算,因为根据鸽笼原理可以证明,长度 >n>n 的环至少有一个环。

Floyd-Warshall Algorithm

可以通过 Floyd-Warshall 算法求解关系的传递闭包。(这就是最经典的 O(n3)O(n^3) 的 Floyd 算法。)

Equivalence Relations

Definition: Equivalence relation

A relation RR on a set AA is an 等价关系(equivalence relation) if RR is (1) reflexive; (2) symmetric; (3) transitive.

We call aa and bb is 等价的(equivalent) if (a,b)∈R(a,b) \in R, denoted as a∼ba\sim b.

如果我们想要证明一个关系是等价关系,通常可以通过证明这一关系满足以上三个性质。

Equivalence Classes

Definition: Equivalence class

The 等价类(equivalence class) of xx: the set of all elements that is equivalent to xx, denoted as [x]R[x]_R or [x][x].

Theorem

如果 RR 是集合 AA 上的等价关系,则以下三个命题等价:

(1) aRbaRb

(2) [a]=[b][a]=[b]

(3) [a]∩[b]≠∅[a]\cap[b] \neq \emptyset

Note

(2) 和 (3) 的区别在于我们需要说明 [a][a] 和 [b][b] 不是空集。

Proof
Theorem 1

设 R1,R2R_1,R_2 是集合 AA 上的等价关系,则 R1∩R2R_1 \cap R_2 也是集合 AA 上的等价关系。

Theorem 2

设 R1,R2R_1,R_2 是集合 AA 上的等价关系,则 R1∪R2R_1 \cup R_2 具有自反性和对称性。进一步的,(R1∪R2)∗(R_1\cup R_2)^\ast 是集合 AA 上的等价关系。

Partitions

Definition: Partition

A 划分(partition) of set AA is a collection of disjoint nonempty subsets of AA that have AA as their union, denoted as pr(A)={A1,A2,⋯An}pr(A) = \{A_1,A_2,\cdots A_n\}.(两两不交,并为全集)

Theorem

Let RR be an equivalence relation on a set AA. Then the equivalence classes of RR form a partition of AA.

Conversely, given a partition {Ai∣i∈I}\{A_i\mid i \in I\} of the set AA, there is an equivalence relation RR that has the sets Ai,i∈IA_i,i\in I, as its equivalence classes.

集合 AA 的所有等价类是原集合的一个划分;任给一个划分存在一个关系 RR 使得划分出的每个子集都是等价类。

Partial Orderings

Partially Ordered Sets (Posets)

Definition: Partial ordering

A relation RR on a set AA is an 偏序关系(partial ordering) if RR is (1) reflexive; (2) antisymmetric; (3) transitive.

Notation:

  • (S,R)(S,R): partially ordered set or 偏序集(poset).
  • a≼ba\preccurlyeq b: (S,R)(S,R) is a poset and (a,b)∈R(a,b) \in R.

如 (Z,≤)(\mathbb Z, \leq) 对应的关系为 R={(a,b)∣a,b∈Z∧a≤b}R=\{(a,b)\mid a,b\in \mathbb Z\land a\le b\}。

Lexicographic Order

Definition: 字典序(lexicographic order)

Given two posets (A1,≼1)(A_1,\preccurlyeq_1) and (A2,≼2)(A_2,\preccurlyeq_2), the lexicographic ordering on A1×A2A_1\times A_2 is defined by specifying that (a1,a2)(a_1,a_2) is less than (b1,b2)(b_1,b_2), that is, (a1,a2)≺(b1,b2)(a_1, a_2)\prec (b_1,b_2), either if a1≺1b1a_1 \prec_1 b_1 or if a1=1b1a_1 =_1 b_1 and a2≺2b2a_2 \prec_2 b_2.

相当于就是从低位到高位依次比较大小。这是定义在两个偏序集的笛卡尔积上,可以通过此定义递推得到多个偏序集的笛卡尔积的字典序的定义。

Theorem

由多个偏序集的笛卡尔积得到的字典序是一个偏序关系。

Hasse Diagrams

Hasse 图(Hasse diagram) 是一种表示偏序集或者格的图形工具。构架 Hasse 图的步骤如下:

  1. 根据偏序集 (A,R)(A,R) 构造有向图,并使所有边都指向上方。(一般来说 Hasse 图是上大下小的)
  2. 消除所有的自环。
  3. 消除所有可由偏序集的传递性导出的边。
  4. 消除所有边的箭头,因为所有的边都应该是指向上方的。
Definition: maximal/minimal elements

设 (A,≼)(A,\preccurlyeq) 是一个偏序集,称 aa 是一个最大元素(maximal element) 当且仅当 AA 中不存在元素 bb 满足 a≺ba \prec b。称 aa 是一个最小元素(minimal element) 当且仅当 AA 中不存在元素 bb 满足 b≺ab\prec a。

显然,最小元素和最大元素可能不止一个。进一步地,在任意有限偏序集中,其最大元素和最小元素一定存在。体现在 Hasse 图中,则最大元素是位于其顶端的点,最小元素是位于其底端的点。正确性显然。

Definition: greatest/least element

设 (A,≼)(A,\preccurlyeq) 是一个偏序集,称 aa 是其最大值(greatest element) 当且仅当对于每个 AA 中的元素 bb 都有 b≼ab \preccurlyeq a;称 aa 是其最小值(least element) 当且仅当对于每个 AA 中的元素 bb 都有 a≼ba \preccurlyeq b。

偏序集的最大值和最小值不一定存在,且如果存在则一定是唯一的。

Definition: upper/lower bounds

设 (S,≼)(S,\preccurlyeq) 是一个偏序集,A⊂SA \subset S。若存在一个 SS 中的元素 aa 满足对于 AA 中的所有元素 bb 都有 b≼ab\preccurlyeq a,则称 aa 是 AA 的一个上界(upper bound)。若存在一个 SS 中的元素 aa 满足对于所有 AA 中的元素 bb 都有 a≼ba\preccurlyeq b,则称 aa 是 AA 的一个下界(lower bound)。

类似的,上下界可能不止一个,也可能不存在。

可以通过 Hasse 图帮助我们找到子集的上下界。

Hasse 图示例
Hasse 图示例
Definition: least upper bound / greatest lower bound

如果 aa 是子集 AA 的上界中最小的,则称其是 AA 的最小上界(least upper bound),记为 lub(A)\text{lub}(A)。如果 aa 是子集 AA 的下界中最大的,则称其是 AA 的最大下界(greatest lower bound)。

Chain

Definition: comparable / incomparable

The elements aa and bb of a poset (S,≼)(S,\preccurlyeq) are 可比较的(comparable) if either a≼ba\preccurlyeq b or b≼ab\preccurlyeq a. When aa and bb are elements of SS so that neither a≼ba\preccurlyeq b nor b≼ab\preccurlyeq a, then aa and bb are called 不可比较的(incomparable).

对于偏序集 (S,R)(S,R) 如果集合 SS 中的元素两两都是可比较的,那么认为 SS 是全序的(total ordered) 或者说线性关系(linear order)。

Definition: Chain

(A,≼)(A,\preccurlyeq) 是一个偏序集,B⊆AB\subseteq A。如果 (B,≼)(B,\preccurlyeq) 是全序的,则称 BB 是 AA 的一条链(chain)。

Definition: Antichain

(A,≼)(A,\preccurlyeq) 是一个偏序集,B⊆AB\subseteq A。如果 ∀a,b,∈B(a≠b), (a,b)∉R,(b,a)∉R\forall a, b ,\in B(a \neq b),\space (a, b)\not\in R, (b, a)\not\in R,则称 BB 是 AA 的一条反链(antichain)。

Well-ordered Sets

Definition: Well-ordered set

一个偏序集 (A,R)(A,R) 是良序集(well-ordered set) 当且仅当其每一个非空子集都有一个最小值。

一个良序集一定是一个全序集(totally ordered set)。

Lattices

Definition: Lattices ★

一个偏序集被称为格(lattice) 当且仅当其每一对元素都有一个最小上界和最大下界。

如 (Z+,∣)(\mathbb Z^+, \mid) 是一个格,对于其任意一对元素 (x,y)(x,y),他们的 lub 为他们的最小公倍数(least common multiple),记为 lcm(x,y)\text{lcm}(x,y);他们的 glb 为他们的最大公因数(great common divisor),记为 gcd⁡(x,y)\gcd(x,y)。

Comments