跳转至

Chapter 9 - Relations

约 3029 个字 8 行代码 预计阅读时间 15 分钟

Section 1 Relations and Their Properties

Binary relation

A binary relation R from a set A to a set B is a subset of A×B.

  • A binary relation R is a set
  • RA×B
  • R={(a,b)|aA,bB,aRb}

Example:

Let A={2,3,4} and B={2,3,4,5,6}. Then R={(x,y)|xA,yB,x divides y}={(2,2),(2,4),(3,3),(3,6),(4,4),(4,6)}

n-ary relation

Let A1,A2,...,An be sets. An n-ary relation R from A1,A2,...,An is a subset of A1×A2×...×An.

Relations On A Set

Let A be a set. A relation on A is a subset of A×A.

There are 2n binary relations on a set with n elements.


Properties of Binary Relations

Reflexive 自反关系

A binary relation R on a set A is reflexive if (a,a)R for every aA.

x(xA(x,x)R) \forall x(x \in A \rightarrow (x, x) \in R)

Matrix:All the elements on the main diagonal of the matrix of a reflexive relation are 1s.

MR=[11..1]

Digraph: There is a loop at every vertex of a reflexive relation.

Irreflexive 非自反关系

A binary relation R on a set A is irreflexive if (a,a)R for every aA.

x(xA(x,x)R) \forall x(x \in A \rightarrow (x, x) \notin R)

Matrix: All the elements on the main diagonal of the matrix of an irreflexive relation are 0s.

MR=[00..0]

Digraph: There is no loop at any vertex of an irreflexive relation.

Symmetric 对称关系

A binary relation R on a set A is symmetric if (b,a)R whenever (a,b)R for all a,bA.

xy((x,y)R(y,x)R) \forall x \forall y((x, y) \in R \rightarrow (y, x) \in R)

Matrix: If MR is the matrix of a symmetric relation, then MR=MRT.

Example: MR=[0100110000010010], MRT=[0100110000010010]

Digraph: If there is an edge from vertex u to vertex v in a symmetric relation, then there is an edge from vertex v to vertex u.

Antisymmetric 反对称关系

A binary relation R on a set A is antisymmetric if (a,b)R and (b,a)R imply that a=b for all a,bA.

xy((x,y)R(y,x)Rx=y) \forall x \forall y((x, y) \in R \land (y, x) \in R \rightarrow x = y)

Matrix: If MR is the matrix of an antisymmetric relation, then MRMRT is a matrix with 0 or 1 on the main diagonal and 0s everywhere else.

Example: MR=[0100010001010000], MRMRT=[0000010000000000]

Digraph: If there is an edge from vertex u to vertex v in an antisymmetric relation, then there is no edge from vertex v to vertex u unless u=v.

One relation can be both symmetric and antisymmetric. For example, the relation R={(a,a),(b,b),(c,c)} is both symmetric and antisymmetric.

Asymmetric 非对称关系

A binary relation R on a set A is asymmetric if (a,b)R and (b,a)R imply that ab for all a,bA.

xy((x,y)R(y,x)Rxy) \forall x \forall y((x, y) \in R \land (y, x) \in R \rightarrow x \neq y)

Matrix: If MR is the matrix of an asymmetric relation, then MRMRT is a matrix with 0s on the main diagonal and 0s everywhere else.

Example: MR=[0100000001010000], MRMRT=[0000000000000000]

Digraph: If there is an edge from vertex u to vertex v in an asymmetric relation, then there is no edge from vertex v to vertex u.

Transitive 传递关系

A binary relation R on a set A is transitive if (a,b)R and (b,c)R imply that (a,c)R for all a,b,cA.

xyz((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)

Matrix: If MR is the matrix of a transitive relation, then MR2MR.

Example: MR=[0100010001010000], MR2=[0100010001010000]

Digraph: If there is a path from vertex u to vertex v and a path from vertex v to vertex w in a transitive relation, then there is a path from vertex u to vertex w.


The logical operations of matrices

Let MR1=[cij] and MR2=[dij] be the matrices of relations R1 and R2 , the following are the matrices of the logical operations of R1 and R2.

Union: MR1R2=[cijdij]

Intersection: MR1R2=[cijdij]

Difference: MR1R2=[cij¬dij]

Complement: MR1=[¬cij]

Inverse Relations

Let R be a relation from a set A to a set B. The inverse of R, denoted by R1(RC), is the relation from B to A such that (b,a)R1 if and only if (a,b)R.

More formally, R1={(b,a)(a,b)R}.

Matrix of R1 is MR1=MRT.

Composition of Relations

Let R be a relation from a set A to a set B and let S be a relation from B to a set C. The composition of R and S, denoted by SR, is the relation from A to C such that (a,c)SR if and only if there is an element bB such that (a,b)R and (b,c)S.

More formally, SR={(a,c)bB((a,b)R(b,c)S)}.

Matrix of SR is MSR=MRMS.

注意:MSRMSMR.


Section 2 Closure of Relations

Closure of Relations

Definition: Let R be a relation on a set A. A relation S on A is said to be a closure of R if RS and S has a certain property P that R does not necessarily have. The closure of R with respect to property P is the intersection of all relations on A that contain R and have property P.

人话:R的关于性质P的闭包是包含R且具有性质P的最小关系。

How to proof a relation is the closure of another relation?

  1. contain R.
  2. have property P.
  3. is the smallest set that contain R and have property P.

Reflexive Closure

Let R be a relation on a set A. The reflexive closure of R, denoted by r(R), is the union of R and the identity relation on A.

More formally, r(R)=RIA, where IA={(a,a)aA}.

Matrix of r(R) is Mr(R)=MRIA.

Digraph of r(R) is the digraph of R with a loop at each vertex.

Symmetric Closure

Let R be a relation on a set A. The symmetric closure of R, denoted by s(R), is the union of R and R1.

More formally, s(R)=RR1.

Matrix of s(R) is Ms(R)=MRMRT.

Digraph of s(R) is the digraph of R adding an edge from vertex v to vertex u whenever there is an edge from vertex u to vertex v.

Transitive Closure

Let R be a relation on a set A. The transitive closure of R, denoted by t(R), is the smallest transitive relation on A that contains R.

Theorem: Let R be a relation on a set A. There is a path of length n from a to b if and only if (a,b)Rn.

R ,the connectivity relation , is the set of all ordered pairs (a,b) such that there is a path from a to b in the digraph of R.

More formally, t(R)=R=i=1Ri.

Matrix of t(R) is Mt(R)=MRMR2MR3, until MRn=MRn+1.

Warshall's Algorithm:

W=[wij]

for (k = 1 ;k <= n; k++)
{
    for (i = 1; i <= n; i++)
    {
        for (j = 1; j <= n; j++)
        w_{ij} = w_{ij}  (w_{ik}  w_{kj});
    }
}

The complexity of Warshall's algorithm is O(n3).

计算方法:关于k,新元素=元素+同列第k行的元素同行第k列的元素.

Section 3 Equivalence Relations

Equivalence Relations

Definition: A relation R on a set A is an equivalence relation if R is

  • reflexive
  • symmetric
  • transitive

a and b are equivalent if (a,b)R, denoted by ab.

Example: The similarity relation on the set of all triangles in the plane is an equivalence relation.

Equivalence Classes

Definition: Let R be an equivalence relation on a set A. The equivalence class of an element aA is the set of all elements in A that are equivalent to a.

More formally, [a]={xAxa}.

Example:Congruence Modulo 3.

[0] = {,6,3,0,3,6,}

[1] = {,5,2,1,4,7,}

[2] = {,4,1,2,5,8,}

The set of all equivalence classes of R is denoted by A/R.

Partition of a Set

Definition: A partition of a set A is a collection of nonempty subsets of A such that every element of A is in exactly one of these subsets.

  • AiAj= for ij.
  • aA,isuchthataAi.
  • Ai for all i.

Notation: pr(A)={A1,A2,,An} is a partition of A.

Equivalence Relations and Partitions

Theorem: Let R be an equivalence relation on a set A. The following are equivalent:

  1. aRb
  2. [a]=[b]
  3. [a][b]

Theorem: Let R be an equivalence relation on a set A. Then A/R is a partition of A.

Q:If |A|=n, the p(n)=? p(n) is the number of different equivalence relations on a set with n elements.

A: p(n)=S(n,1)+S(n,2)++S(n,n), where S(n,k) is the Stirling number of the second kind.

Operations on Equivalence Relations

If R1, R2 are equivalence relations on a set A.

  • R1R2 is an equivalence relation on A.
  • R1R2 is a reflexive and symmetric relation on A.
  • (R1R2) is an equivalence relation on A.

Partial Orderings

Definition: A relation R on a set A is a partial ordering if R is

  • reflexive
  • antisymmetric
  • transitive

和等价关系的区别:等价关系是对称的,而偏序关系是反对称的。

Notation: (A,R) is a partially ordered set (poset).

Example: (Z,) is a poset.

Notation:

ab means (S,R) is a poset and (a,b)R.

ab means ab and ab.

Comparability: a and b are comparable if ab or ba.

Totally ordered set: If every two elements of a poset are comparable, then the poset is called a totally ordered set or a chain.

Example: (Z,) is a totally ordered set.

Example: (Z+,|) is a poset but not a totally ordered set.

Well-ordered set: A poset (S,) is a well-ordered set if it is a totally ordered set and every nonempty subset of S has a least element.

Example: (N,) is a well-ordered set.

The principle of well-ordering induction:

假设S是一个非空的well-ordered set,如果P(x)是一个关于xS的命题,且满足:对所有的xS,如果P(y)对所有的yx都成立,则P(x)成立。那么P(x)对所有的xS都成立。

Lexico-graphic order: Let R1 and R2 be partial orderings on sets A1 and A2, respectively. The lexicographic order on A1×A2 is the partial ordering R such that (a1,a2)(b1,b2) if and only if either a1b1 or a1=b1 and a2b2.

Theorem: Let R1 and R2 be partial orderings on sets A1 and A2, respectively. The lexicographic order on A1×A2 is a partial ordering.

Hasse Diagrams

Hasse diagram: A Hasse diagram of a poset (S,) is a digraph such that the vertices of D correspond to the elements of S and there is an edge from vertex x to vertex y if and only if xy and there is no element z such that xzy.

没有箭头,没有环,没有重复的边。

Example: A={1,2,3,4,5,6,7,8,9}, R={(a,b)a | b,a,bA}, D is the Hasse diagram of (A,R).

original digraph:

Hasse diagram:

Maximal element: An element a of a poset (S,) is a maximal element if there is no element bS such that ab.

Minimal element: An element a of a poset (S,) is a minimal element if there is no element bS such that ba.

Greatest element: An element a of a poset (S,) is a greatest element if ab for all bS.

Least element: An element a of a poset (S,) is a least element if ba for all bS.

In the last example, 8,6,9,5,7 are maximal elements, 1 is a minimal element, there is no the greatest element, 1 is the least element.

Upper bound: Let S be a poset and let A be a subset of S. An element bS is an upper bound of A if ab for all aA.

Least upper bound: Let S be a poset and let A be a subset of S. An element bS is a least upper bound of A if b is an upper bound of A and bc for every upper bound c of A. The least upper bound of A is denoted by lub(A).

Lower bound: Let S be a poset and let A be a subset of S. An element bS is a lower bound of A if ba for all aA.

Greatest lower bound: Let S be a poset and let A be a subset of S. An element bS is a greatest lower bound of A if b is a lower bound of A and cb for every lower bound c of A. The greatest lower bound of A is denoted by glb(A).

此时是对于集合而言的,而不是对于元素而言的。

只要求小于等于,所以该集合中的元素可以是集合的上界,也可以是集合的最小上界。

Example: S={a,b,c,d,e,f,g,h,i,j,k},A={a,b,c,d,e,f,g}, A=h,i,j,k

the upper bounds of A : h,i,j,k.

the lower bounds of A : / .

the upper bounds of A : / .

the lower bounds of A : a,b,c,d,e,f,g .

lub and glb of A : / .

lub and glb of A : / .

Lattices

Lattice: A poset (S,) is a lattice if every two elements of S have a least upper bound and a greatest lower bound. Every totally ordered set is a lattice.

Example: (Z,) is a lattice.

lub: the larger one.

glb: the smaller one.

Example: (Z+,|) is a lattice.

lub: the least common multiple.

glb: the greatest common divisor.

Example: (P(S),) is a lattice.

lub: the union.

glb: the intersection.

Topological Sortings

拓扑排序:对于一个有向无环图,将所有的顶点排成一个序列,使得对于每一条边(u,v)u在序列中都在v的前面。