본문으로 건너뛰기

8. Relations

8.1. Relations and Their Properties

Set A,BA,B에 대해 Binary relation from AA to BBA×BA\times B의 Subset이다.

Binary relation from AA to BB의 첫 번재 Element가 AA에서 오고 두 번재 Element가 BB에서 온 각 Ordered pair의 Set RR이라고 할 때 (a,b)R(a, b)\in R을 나타내기 위해 a R ba\ R\ b라는 Notation을 사용하고 (a,b)R(a,b)\notin R을 Notation으로 a ba \not R\ b로 나타낸다.
(a,b)(a,b)RR에 속할 때 aa는 related to bb by RR(aaRR에 의해 bb와 관계)라고 한다.

Example

A={0,1,2},B={a,b}A=\{0,1,2\}, B=\{a,b\}라고 할 때 relation from AA to BB

  • Solution
    {(0,a),(0,b),(1,a),(1,b),(2,a),(2,b)}\{(0,a),(0,b),(1,a),(1,b),(2,a),(2,b)\}

Functions as Relations

Functrion ff가 Set AA에서 BB로 정의된 경우 ffAA의 각 Element에 대해 BB에 정확히 하나의 Element를 할당한다.
ff의 Graph는 A×BA\times B의 Subset이므로 AA에서 BB로의 Relation이다.
Function의 Graph는 AA의 모든 Element가 Graph의 정확히 하나의 Ordered pair의 첫 Element라는 특성을 가지고 있다.

RRAA에서 BB로의 관계이고 AA의 모든 Element가 RR의 정확히 하나의 Ordered pair의 첫 Element라면 RR을 Graph로 하는 Function이 정의될 수 있다.
AA의 Element aa에 대해 (a,b)R(a,b)\in R인 유일한 Element bBb\in B를 할당함으로 가능해진다.

Relation은 Set A,BA,B의 Element 간 One-to-many relationship을 표현하는 데 사용될 수 있다.
이 경우 AA의 Element는 BB의 여러 Element와 Relation이 있을 수 있다.
Funtion의 경우 AA의 각 Element와 관련된 BB의 정확히 하나의 Element를 나타내는 Relation이다.

Relations on a Set

Set AA에서 AA로의 Relation은 Relation on the set AA라고 하며 A×AA\times A의 Subset이다.

Example

Set A={1,2,3,4}A=\{1,2,3,4\}라고 할 때 Relation R={(a,b)a divides b}R=\{(a,b)\mid a\ divides\ b\}의 Ordered pair

  • Solution
    R={(1,1),(1,2),(1,3),(1,4),(2,2),(2,4),(3,3),(4,4)}R=\{(1,1),(1,2),(1,3),(1,4),(2,2),(2,4),(3,3),(4,4)\}

Example

nn개의 Element를 가진 Set에서 Relation 개수

  • Solution
    Set AA에서의 Relation은 A×AA\times A의 Subset이다.
    A×AA\times An2n^2개의 Element를 가지기에 2n22^{n^2}만큼의 Relation이 존재한다.

Properties of Relations

Set AA에서의 Relation RR은 모든 Element aAa\in A에 대해 (a,a)R(a,a)\in R일 경우 Reflexive(반사적)이라고 한다.

경고

Remark

Quantifier를 사용할 경우 Relation RR이 Set AA에서 Reflexive하다는 것은 aA,(a,a)R\forall a\in A, (a,a)\in R을 의미한다.

Set AA에 대한 Relation RRAA의 모든 a,ba, b에 대해 (a,b)R(a,b)\in R일 때 (b,a)R(b,a)\in R이면 Symmetric(대칭적)이라 하고 a,bAa,b \in A에 대해 (a,b)R,(b,a)R(a, b)\in R, (b,a)\in R을 만족하는 Condition이 a=ba=b일 경우 Antisymmetric(비대칭적)이라고 한다.

경고

Remark

Quantifier를 사용할 경우 Set AA의 Relation RRab((a,b)R(b,a)R)\forall a\forall b((a,b)\in R\to (b,a)\in R)인 경우 Symmetric, ab(((a,b)R(b,a)R)(a=b))\forall a \forall b(((a,b)\in R\land(b,a)\in R)\to (a=b))인 경우 Antisymmetric이라 한다.

Set AA의 Transitive(전이) relation은 Relation RR의 모든 a,b,cAa, b,c \in A에 대해 (a,b)R(a,b)\in R이고 (b,c)R(b,c)\in R이면 (a,c)R(a, c)\in R이 성립함을 의미한다.

경고

Remark

Quantifier를 사용하여 Set AA의 Relation RR이 Transitive인 경우를 abc((a,b)R(b,c)R)(a,c)R\forall a\forall b\forall c((a,b)\in R\land (b,c)\in R)\to(a,c)\in R로 표현 가능하다.

Example

모든 aa가 Positive integer set AA에 속할 때 (a,a)(a,a)는 Positive integer의 Divide relation에서 Reflexive인 지, Symmetric인 지, Transitive인 지

  • Solution
    Reflexive: aa가 Positive integer일 때 항상 aaaa를 나누므로 Divide relation은 Reflexive하다.
    만약 Set을 Nonnegative integer set으로 바꿀 경우 0은 0을 나눌 수 없으므로 Divide relation이 Reflexive하지 못한다.
    Symmetric: Symmetirc이지 않다.
    이유로는 121|2이나 2∤12\not |1이기 때문이다.
    추가적으로 이 Relation은 Antisymmetric인 이유로는 a,ba, b가 Positive integer일 때 aba|b이고 bab|a이면 a=ba=b이기 때문이다.
    Transitive: Positive integer a,b,ca,b,c에 대해 abbcaca|b \land b|c \to a|c이기에 이 Relation은 Transitive이다.

Combining Relation

Set A,BA, B에 대한 Relation은 A×BA\times B의 Subset이다.

RR을 Set AA에서 BB로의 Relation, SS를 Set BB에서 CC로의 Relation이라고 할 때 R,SR, S의 Composite는 aA,cCa\in A, c\in C를 만족하는 Ordered pair (a,c)(a,c)로 이루어진 Releation이며 (a,b)R(b,c)S(a,b)\in R \land (b, c)\in S이다.
Notation으로 SRS\circ R로 표현한다.

Set AA의 Relation RR의 Power Rn,n=1,2,R^n, n=1,2,\dotsR1=R,Rn+1=RnRR^1=R, R^{n+1}=R^n\circ R로 Recursive하게 정의된다.

Example

Relation RR을 모든 사람에 대한 Set의 Relation이라고 할 때 (a,b)R(a, b)\in Raabb의 부모일 때 성립할 때 (a,c)RR(a,c)\in R\circ R

  • Solution
    Relation RR이 부모 Relation을 나타내기에 RRR\circ R은 부모의 부모, 즉 조부모 Relation을 나타낸다.

Example

Relation R={(1,1),(2,1),(3,2),(4,3)}R=\{(1,1),(2,1),(3,2),(4,3)\}이라고 할 때 RnR^n

  • Solution
    R2={(1,1),(2,1),(3,1),(4,2)}R^2=\{(1,1),(2,1),(3,1),(4,2)\}이고 R3={(1,1),(2,1),(3,1),(4,1)}R^3=\{(1,1),(2,1),(3,1),(4,1)\}을 알 수 있다.
    이후 몇 번을 거듭제곱하여도 모든 Ordered pair의 뒤 Element가 1이 되는 것을 알 수 있으므로 n3Rn=R3n\geq 3\to R^n=R^3가 참임을 알 수 있다.
정보

Theorem

Set AA의 Relation RRn=1,2,n=1,2,\dots일 때 RnRR^n\subseteq R일 경우 Transitive이다.

8.2. n-ary Relations and Their Application

n-ary Relations

Set A1,A2,,AnA_1, A_2,\cdots,A_n에 대한 nn-ary Relation은 A1×A2××AnA_1\times A_2\times \cdots \times A_n의 Subset이다.
Set A1,A2,,AnA_1, A_2,\cdots,A_n을 Domain, nn을 Relation의 Degree라고 한다.

Example

RR을 Airplane flight를 나타내는 5-Tuple(A,N,S,D,TA,N,S,D,T)라고 할 때 이 Relation의 예시로 (항공사, 비행기 번호, 출발지, 도착지, 출발 시간)의 꼴로 (Nadir, 963, Mewark, Bangor, 15:00)로 나타낼 수 있다.
이 Relation의 Degree는 5이며 Relation의 Domain은 모든 항공사 Set, 비행기 Set, 출발 도시 Set, 도착 도시 Set, 시간 Set이 된다.

Databases and Relations

DB는 Field로 구성된 nn-tuple인 Record로 이루어져 있다(Field = 각 Tuple의 Item).
DB의 Relation을 Table이라고 부른다(표현이 Table로 되기 때문).
nn-tuple의 Relation의 Domain은 nn-tuple의 Value가 이 Domain에서 nn-tuple을 결정할 때 Primary key라고 한다.
Primary key는 Unique, Not null이다.

Relation에서 현재 nn-tuple의 Set을 Relation의 Extension이라고 한다.
DB의 Name, Attribute들을 포함하는 Permanent part를 Intension이라고 한다.

Domain의 Combination은 nn-ary Relation에서 nn-tuple을 Uniquyely Identifiy 가능하다.
특정 Domain set의 Value가 Relation 내의 nn-tuple을 결정할 때 Domain의 Cartesian product를 Composite key라고 한다.

Operations on n-ary Relations

nn-ary relation RR의 Element가 만족할 수 있는 Condition을 CC라 할 때 Selection operator sCs_Cnn-ary relation RR을 Condition CC를 만족하는 RR의 모든 nn-tuple의 nn-ary relation을 Mapping한다.

Projection(투영 연산) i1<i2<<imi_1<i_2<\cdots<i_m을 만족하는 Pi1i2imP_{{i_1}{i_2}\dots{i_m}}mnm\leq n일 때, nn-tuple(a1,a2,,ana_1, a_2,\dots,a_n)을 mm-tuple(ai1,ai2,,aima_{i_1},a_{i_2},\dots,a_{i_m})로 Mapping한다.

RR이 Degree mm인 Relation이고 SS가 Degree nn인 Relation일 때 pm,pnp\leq m, p\leq n인 Join Jp(R,S)J_p(R,S)는 Degree가 m+npm+n-p인 Relation이며 (m+np)(m+n-p)-tuple(a1,a2,,amp,c1,c2,,cp,b1,b2,,bnpa_1,a_2,\dots,a_{m-p},c_1,c_2,\dots,c_p,b_1,b_2,\dots,b_{n-p})로 구성되며 a1,,amp,c1,,bnpa_1,\dots,a_{m-p},c_1,\dots,b_{n-p}mm-tuple이며 RR에 속하고 c1,,cp,b1,,bnpc_1,\dots,c_p,b_1,\dots,b_{n-p}nn-tuple이며 SS에 속한다.

SQL

SQL(Structured Query Language)는 DB의 Queryu language이다.

AirlineFlight_numberGateDestinationDeparture_time
Nadir12234Detroit08:10
Acme22122Denver08:17
Acme12233Anchorage08:22
Acme32334Honolulu08:30
Nadir19913Detroit08:47
Acme22222Denver09:10
Nadir32234Detroit09:44

Example

SELECT Departure_time FROM Flights WHERE Destination='Detroit';

  • Solution
    위 Table Flights DB에서 Condition Destination='Detroit'를 만족하는 5-tuple의 Selection으로부터 Departure_time Attribute의 Projection P5P_5를 찾는 데 사용된다.

8.3. Representing Relations

Representing Relations Using Matrices

Finite set 간의 Relation은 Zero-one Matrix를 사용하여 표현 가능하다.
RR이 Set A={a1,a2,,am}A=\{a_1,a_2,\dots,a_m\}에서 B={b1,b2,,bn}B=\{b_1,b_2,\dots,b_n\}으로의 Relation이라 가정할 때 A=BA=B와 같을 때 Relation RRMR=[mij]M_R=[m_{ij}](mij=1 if(ai,bj)R,mij=0 if(ai,bj)Rm_{ij}=1\ if(a_i,b_j)\in R, m_{ij}=0\ if(a_i,b_j)\notin R)로 나타낼 수 있다.

Example

Set A={1,2,3},B={1,2}A=\{1,2,3\}, B=\{1,2\}AA에서 BB로의 Relation RR에 대해 aA,bB,a>ba\in A, b \in B, a>b일 때 Ordered pair (a,b)(a,b)일 때 Matrix

  • Solution
    R={(2,1),(3,1),(3,2)}R=\{(2,1),(3,1),(3,2)\}이기에 RR에 해당하는 Matrix는
    MR=[001011]M_R=\begin{bmatrix}0 & 0 \\ 1 & 0 \\ 1 & 1 \end{bmatrix}가 된다.

RR이 Set AA에서 BB로의 Relation이고 SS가 Set BB에서 CC로의 Relation일 때 Set A,B,CA,B,C는 각각 m,n,pm,n,p개의 Element를 가진다고 할 때 SR,R,SS \circ R, R, S에 대한 Zero-one matrix는 각각 MSR=[tij],MR=[rij],MS=[sij]M_{S\circ R}=[t_{ij}], M_R=[r_{ij}], M_S=[s_{ij}]로 표기할 때 Matrix의 크기는 각각 m×p,m×n,n×pm\times p, m\times n, n\times p이다.
Ordered pair (ai,cj)(a_i,c_j)SRS\circ R에 속하기 위해 어떤 Element bkb_k가 존재해야 하며 (ai,bk)(a_i,b_k)RR에, (bk,cj)(b_k, c_j)SS에 속해야 한다.
싸라서 tij=1 if and only if rik=skj=1t_{ij}=1\ if\ and\ only\ if\ r_{ik}=s_{kj}=1을 만족하는 kk에 대해 성립할 경우에만 성립한다.
MSR=MRMSM_{S\circ R}=M_R\odot M_S이다.

Example

MR=[101110000]M_R=\begin{bmatrix} 1&0&1\\1&1&0\\0&0&0\end{bmatrix}이고 MS=[010001101]M_S=\begin{bmatrix}0&1&0\\0&0&1\\1&0&1\end{bmatrix}일 때 SRS\circ R의 Matrix

  • Solution
    MSR=MRMS=[111011000]M_{S\circ R}=M_R\odot M_S=\begin{bmatrix}1&1&1\\0&1&1\\0&0&0\end{bmatrix}이다.

Example

MR=[010011100]M_R=\begin{bmatrix}0&1&0\\0&1&1\\1&0&0\end{bmatrix}일 때 R2R^2의 Matrix

  • Solution
    MR2=MR[2]=[011111010]M_{R^2}=M_R^{[2]}=\begin{bmatrix}0&1&1\\1&1&1\\0&1&0\end{bmatrix}이다.

Representing Relations Using Digraphs

Directed graph(=Digraph)는 Vertex(Node)들로 이루어진 Set VVVV의 Element pair로 구성된 Set EE로 이루어져 있으며 이를 Edge(Arc)라고 부른다.
형태가 (a,a)(a,a)인 Edge는 다시 자기 자신으로 향하는 Arc로 표현되며 Loop라고도 한다.

Example

Vertex a,b,c,da,b,c,d가 존재하고 Edge (a,b),(a,d),(b,b),(b,d),(c,a),(c,b),(d,b)(a,b), (a,d),(b,b),(b,d),(c,a),(c,b),(d,b)가 존재하는 Digraph는 위 Example's Directed graph 1과 같이 존재한다.

Example

주어진 Example's Directed graph 2의 Relation이 Reflexive, Symmetric, Antisymmetric, Transitive인 지

  • Solution
    Reflexive: RR은 매 Vertex에 Loop edge가 존재하여 Reflexive하나 SS는 그렇지 못하다.
    Symmetric / Antisymmetric: 양 방향을 잇는 Edge가 둘 다 존재하지 않으므로 R,SR, S는 Symmetric하지도 Antisymmetric하지도 않다.
    Transitive: (a,c)(a,c)가 존재하지 않아 RR은 Transitive하지 않고 (c,b)(c,b)가 속하지 않아 SS 역시 Transitive하지 않다.

8.4. Closures of Relations

Set A={1,2,3}A=\{1,2,3\}의 Relation R={(1,1),(1,2),(2,1),(3,2)}R=\{(1,1),(1,2),(2,1),(3,2)\}는 Not reflexive이다.
RR을 포함하며 최소한의 Reflexive relation을 생성하기 위해 RR(2,2),(3,3)(2,2),(3,3)을 추가해야 한다.
RR을 포함하며 Reflexive이며 RR을 포함하는 모든 Reflexive relation 내에 위치하는 것을 Reflexive closure of RR(RR의 반사적 닫힘)이라 한다.
Δ={(a,a)aA}\Delta=\{(a,a)\mid a\in A\}를 만족할 때 RΔR\cup \Delta이며 이 Relation은 Diagonal relation이다.

Set A={1,2,3}A=\{1,2,3\}의 Relation R={(1,1),(1,2),(2,2),(2,3),(3,1),(3,2)}R=\{(1,1),(1,2),(2,2),(2,3),(3,1),(3,2)\}는 Not Symmetric이다.
RR을 포함하며 최소한의 Symmetric relation을 생성하기 위해 RR(2,1),(1,3)(2,1),(1,3)을 추가해야 한다.
RR을 포함하며 Symmetric이며 RR을 포함하는 모든 Symmetric relation은 새로 생성된 Relation을 포함해야 한다(모든 Symmetric Relation은 (2,1),(1,3)(2,1),(1,3)을 포함해야 한다.).
이 새로운 Relation을 Symmetric closure of RR(RR의 대칭적 닫힘)이라고 한다.

Example

a,ba,b가 Positive Integer일 때 Relation R={(a,b)a<b}R=\{(a,b)\mid a<b\}의 Reflexive closure

  • Solution
    RR의 Reflexive closure는 RΔ={(a,b)a<b}{(a,a)aZ}={(a,b)ab}R\cup \Delta=\{(a,b)\mid a<b\}\cap\{(a,a)\mid a\in Z\}=\{(a,b)\mid a\leq b\}이다.

Example

a,ba,b가 Positive integer일 때 Relation R={(a,b)a>b}R=\{(a,b)\mid a>b\}의 Symmetric closure

  • Solution
    R의 Symmetric closure는RR1={(a,b)a>b}{(b,a)a>b}={(a,b)ab}R\cap R^{-1}=\{(a,b)\mid a>b\}\cap \{(b,a)\mid a>b\}=\{(a,b)\mid a\not =b\}이다.

Paths in Directed Graphs

Directed graph GG에서 aa에서 bb로 가는 Path는 GG에서 Edge의 Sequence (x0,x1),(x1,x2),(x2,x3),,(xn1,xn)(x_0,x_1),(x_1,x_2),(x_2,x_3),\dots,(x_{n-1},x_n)이다(x0=a,xn=b,n0x_0=a,x_n=b,n\geq 0).
Path 중 Edge의 끝 Vertex가 다음 Edge의 시작 Vertex와 같으며 길이가 0인 경우 Empty set이며, 길이가 nn인 경우 n1n-1 길이의 Circuite나 Cycle이라고 부른다.

정보

Theorem

Set AA 위 Relation RR에 대해 nn이 Positive integer일 경우 aa에서 bb로 가는 길이 nn인 Path가 존재하는 것은 (a,b)Rn(a,b)\in R^n과 필요 충분 조건이다.

  • Proof
    Mathematical induction을 사용하여 aa에서 bb로의 Path는 (a,b)R(a,b)\in R과 필요 충분 조건이다.
    aa에서 bb로 가는 길이가 n+1n+1인 Path가 존재하는 것은 aa에서 cc로 가는 11이 길이인 Path가 존재하고 cc에서 bb로의 가는 길이가 nn인 Path가 존재할 때 필요 충분 조건이다.
    이로써 증명할 수 있다.

Transitive Closures

Set AA에 대한 Relation RR에 대해 RR^\staraa에서 bb로 가는 길이가 1 이상인 Path가 존재하는 Pair (a,b)(a,b)로 구성되는 Connectivity relation이라고 할 때 R=n=1RnR^\star=\sum_{n=1}^\infin R^n이다.

정보

Theorem

Relation RR의 Transitive closure는 Connectivity Relation RR^\star

  • Proof
    RR^\star이 Transitive인 지 qhdlrl dnlgo (a,b)R,(b,c)R(a,b)\in R^\star, (b,c)\in R^\star라면 RR^\star에서 aa에서 b, bb,\ b에서 cc로 가는 Path가 존재한다.
    (a,c)R(a,c)\in R^\star이다.
    SSRR을 포함하는 Transitive relation이라고 할 때 SnS^n 역시 Transitive이며 SnSS^n\subseteq S이다(S=k=1Sk\because S^\star =\sum_{k=1}^\infin S^k).
    SkSS^k\subseteq S이기에 SSS^\star \subseteq S이며 RSR\subseteq S이기에 RSR^\star \subseteq S^\star이다.
    요약하여 RSSR^\star \subseteq S^\star \subseteq S가 되므로 RR을 포함하는 모든 Transitive closure는 RR^\star를 포함하여야 하며 RR의 Transitive closure이다.
정보

Theorem

RR에 대한 Zero-one matrix MRM_R일 때 Transitive closure RR^\star의 Zero-one matrix는 MR=MRMR[2]MR[3]MR[n]M_{R^\star}=M_R \lor M_R^{[2]}\lor M_R^{[3]}\lor \cdots \lor M_R^{[n]}

Example

Relation RR의 Zero-one matrix가 MR=[101010110]M_R=\begin{bmatrix}1&0&1\\0&1&0\\1&1&0\end{bmatrix}일 때 Transitive closure의 Zero-one matrix

  • Solution
    RR^\star의 Zero-one matrix는 MR=MRMR[2]MR[3]M_{R^\star}=M_R \lor M_R^{[2]}\lor M_R^{[3]}이기에 MR[2]=[111010111],MR[3]=[111010111]M_R^{[2]}=\begin{bmatrix}1&1&1\\0&1&0\\1&1&1\end{bmatrix}, M_R^{[3]}=\begin{bmatrix}1&1&1\\0&1&0\\1&1&1\end{bmatrix}임을 이용하여
    MR=[101010110][111010111][111010111]=[111010111]M_{R^\star}=\begin{bmatrix}1&0&1\\0&1&0\\1&1&0\end{bmatrix}\lor \begin{bmatrix}1&1&1\\0&1&0\\1&1&1\end{bmatrix}\lor \begin{bmatrix}1&1&1\\0&1&0\\1&1&1\end{bmatrix}=\begin{bmatrix}1&1&1\\0&1&0\\1&1&1\end{bmatrix}이다.
정보

Pseudocode

Algorithm : A Procedure for Computing the Transitive Closure

procedure transitive closure(MRM_R: zero-one n×nn\times n matrix)
AA := MRM_R
BB := AA
for ii := 2 to nn
begin
AA := AMRA\odot M_R
BB := BAB\lor A
end {BB is the zero-one matrix for RR^\star}

현재 위 Algorithm의 각 거듭제곱을 계산하기 위해 n1n-1n×nn\times n의 Zero-one matrix의 Boolean product를 찾아야하기에 총 n2(2n1)(n1)+n2(n1)n^2(2^n-1)(n-1)+n^2(n-1)만큼의 Bit operator를 사용하여야 하며 Big-O notation으로 O(n4)O(n^4)가 된다.

Warshall's Algorithm

1960년에 Stephen Warshall에 의해 설명된 Warshall's algorithm은 Relation의 Transitive closure를 계산하는 효율적인 Algorithm이다.

RRnn개의 Element를 가진 Set의 Relation으로 가정할 때 v1,v2,,vnv_1, v_2, \dots, v_nnn개의 Element의 임의의 나열일 때 Path의 Interior vertex의 Concept를 사용하여 a,x1,x2,,xm1,ba, x_1, x_2, \dots, x_{m-1}, b가 Path일 때 Interior vertex는 x1,,xm1x_1,\dots,x_{m-1}로 Path에서 첫 번째와 마지막 Vertex를 제외한 모든 Vertex들이다.
Zero-one matrix의 Sequence를 구성하는 데 기반을 두며 W0,W1,,WnW_0, W_1,\dots, W_n들이 이 Matrix라고 할 때 W0=MRW_0=M_R이고 Wk=[wij(k)]W_k=[w_{ij}^{(k)}](wij(k)=1w_{ij}^{(k)}=1 if viv_i에서 vjv_j로 가는 Path가 존재하며 모든 Interior vertex들이 {v1,,ck}\{v_1,\cdots,c_k\}안에 존재할 때, 그렇지 않다면 wij(k)=0w_{ij}^{(k)}=0)이다.
Wn=MRW_n=M_{R^\star}임을 유의하여 MRM_{R^\star}(i,j)(i,j)번째 Element는 viv_i에서 vjv_j로 가는 Path가 존재하고 모든 Interior vertex들이 {v1,,vn}\{v_1,\dots,v_n\} Set 내에 있을 때 1, 그렇지 않다면 0이다.

Example

Relation RR(a,d),(b,a),(b,c),(c,a),(c,d),(d,c)(a,d),(b,a),(b,c),(c,a),(c,d),(d,c)라고 할 때 Matrix W0,W1,W2,W3,W4W_0,W_1,W_2,W_3,W_4

  • Solution
    v1=a,v2=b,v3=c,v4=dv_1=a, v_2=b, v_3=c, v_4=d라고 할 때 W0=[0001101010010010]W_0=\begin{bmatrix}0&0&0&1\\1&0&1&0\\1&0&0&1\\0&0&1&0\end{bmatrix}이다.
    W1W_1(i,j)(i,j)번째 Element는 viv_i에서 vjv_j까지의 Path가 v1=av_1=a를 가질 때에만 Interior vertex이며 즉 1이다.
    모든 길이가 1인 Path는 Interior vertex가 없으므로 여전히 사용 가능하다.
    bb에서 dd의 Path인 b,a,db, a, d가 존재하므로 W1=[0001101110010010]W_1=\begin{bmatrix}0&0&0&1\\1&0&1&1\\1&0&0&1\\0&0&1&0\end{bmatrix}이며 bb가 단말 Vertex인 Edge가 존재하지 않기에 bb를 Interior vertex로 허용할 때 새로운 Path가 생기지 않으므로 W1=W2W_1=W_2이다.
    W3W_3(i,j)(i,j)번째 Element는 viv_i에서 vjv_j까지의 Path가 v1=a,v2=b,v3=cv_1=a, v_2=b, v_3=c를 Interior vertex로 가질 경우 1이므로 W3=[0001101110011011]W_3=\begin{bmatrix}0&0&0&1\\1&0&1&1\\1&0&0&1\\1&0&1&1\end{bmatrix}이며 W4W_4의 경우 viv_i에서 vjv_j까지의 Path가 v1=a,v2=b,v3=c,v4=dv_1=a,v_2=b,v_3=c,v_4=d를 Interior vertex로 가질 경우 1이므로 W4=[1011101110111011]W_4=\begin{bmatrix}1&0&1&1\\1&0&1&1\\1&0&1&1\\1&0&1&1\end{bmatrix}이다.
정보

Lemma

Wk=[wij[k]]W_k=[w_{ij}^{[k]}]를 Zero-one matrix라고 할 때 (i,j)(i,j)위치에 1이 들어가 있는 경우가 {v1,,vk}\{v_1,\dots,v_k\} Set의 Interior vertex를 가진 viv_i에서 vjv_j로 가는 Path가 존재할 때일 때 wij[k]=wijk1(wik[k1]wkj[k1])(, i,j,kn)w_{ij}^{[k]}=w_{ij}^{k-1}\lor (w_{ik}^{[k-1]}\land w_{kj}^{[k-1]})(단,\ i,j,k\leq n)

정보

Pseudocode

Algorithm : Warshall Algorithm

procedure Warshall(MRM_R: n×nn\times n zero-one matrix)
WW := MRM_R
for kk := 1 to nn
begin
for ii := 1 to nn
begin
for jj := 1 to nn
wijw_{ij} := wij(wikwkj)w_{ij}\lor (w_{ik}\land w_{kj})
end
end {WW = [wij][w_{ij}] is MRM_{R^\star}}

8.5. Equivalence Relations

Equivalence Relations

Set AA에서 Relation을 Equivalence relation(동치 관계)라고 하기 위해 Reflexive, Symmetric, Transitive해야 한다.
두 Element a,ba, b가 Equivalence relation라고 할 때 equivalent(동치)라고 하며 Notation으로 aba \sim b로 표현한다.

Example

Positive integer nn과 Character string SS에 대해 RnR_nSS의 Relation이며 sRnts R_n ts=ts=t이거나 sstt가 모두 nn자 이상이며 s,ts, t의 첫 nn자가 같을 때 성립
nn자 미만의 String은 자기 자신과만 Relation이 있으며 nn자 이상의 경우 처음 nn자가 동일할 때만 Relation 존재
n=3n=3이라고 할 때 SS가 모든 Bit string의 Set일 때 sR3tsR_3ts=ts=t거나 3 이상인 Bit string이 동일한 3 Bit로 시작할 때 성립
이때 모든 SS와 모든 nn에 대해 RnR_nSS의 Equivalence relation임을 증명

  • Solution
    RnR_n은 Reflexive하다(s=ss=s).
    만약 sRntsR_nt라면 s=ts=t이거나 s,ts, tnn자 이상이며 같은 String으로 시작한다.
    따라서 sRntsR_nt가 성립할 때 tRnstR_ns 역시 성립하며 RnR_n이 Symmetric하다.
    sRnt,tRnusR_nt, tR_nu라고 가정할 경우 sRnusR_nu가 성립하므로 Transitive하므로 RnR_nSS의Equivalence relation이다.

Example

Positive integer set에서 "Divide" Relation이 Equivalence relation이 아님을 증명

  • Solution
    이전 Example에서 "Divide" Relation은 Reflexive, Transitive이나 Symmetric하지 않으므로(24,4∤22|4,4\not |2) Equivalence relation이 아니다.

Equivalence Classes

Set AA에 정의된 Equivalence relation RR이 있을 때 AA의 Element aa와 관련된 모든 Element의 Set을 Equivalence class라고 한다.
RR에 대한 aa의 Equivalence class를 Notation으로 [a]R[a]_R로 표기하며 하나의 Relation만 고려할 경우 [a][a]로 표기 가능하다.
즉, [a]r={s(a,s)R}[a]_r=\{s\mid (a,s)\in R\}이며 b[a]Rb\in[a]_R일 경우 bb는 Equivalence class의 Representative라고 하며 어떤 Equivalence class의 Element는 Representative로 사용할 수 있으며 특별한 의미가 없다.

Example

0, 1의 Equivalence class는 4로 나눈 나머지에 대해 어떻게 정의되는지

  • Solution
    0의 Equivalence class는 a0(mod4)a\equiv 0(\mod 4)인 모든 Integer들은 4로 나누어 떨어지는 모든 Integer aa를 포함한다.
    따라서 이 Relation에 대한 0의 Equivalence class는 [0]={,8,4,0,4,8,}[0]=\{\dots,-8,-4,0,4,8,\dots\}이다.
    1의 Equivalence class는 [1]={,7,3,1,5,9,}[1]=\{\dots, -7, -3, 1, 5, 9,\dots\}이다.

Example

Bit string set의

R3R_3 Relation에 따라 String 0111의 Equivalence class
(sR3tsR_3ts,ts,t가 Bit string이며 s=ts=t이거나 s,ts, t의 앞 3 Bit가 동일한 3Bit 이상 String)

  • Solution
    [0111]R3=[011]R3={011,0110,0111,01100,01101,01110,01111,}[0111]_{R_3}=[011]_{R_3}=\{011, 0110,0111,01100,01101,01110,01111,\dots\}

Equivalence Classes and Partitions

정보

Theorem

Set AA에 대한 Equivalence relation RR에 대해 AA의 Element a,ba,b에 대해 다음의 Statement들은 Equivalent이다.

(i) aRb(i)\ aRb, (ii) [a]=[b](ii)\ [a]=[b], (iii) [a][b](iii)\ [a]\cap [b]\not= \empty

  • Proof
    (i) & (ii) aRbaRb일 때 [a]=[b][a]=[b]임을 보이기 위해 [a][b][a]\subseteq [b], [b][a][b]\subseteq [a]를 증명한다.
    cc[a][a]에 속한다면 aRcaRc가 성립하며 aRbaRb이고 RR이 Symmetric이므로 bRabRa가 성립함을 알 수 있다.
    RR이 Transitive이고 RR이 Transitive이기에 bRabRaaRcaRc가 주어질 경우 bRcbRc가 성립하므로 [a][b][a]\subseteq [b]이다.
    같은 방법으로 [b][a][b]\subseteq [a]도 증명 가능하다.
    (ii) & (iii)를 의미하기 위해 [a]=[b][a]=[b]일 때 [a][b][a]\cap [b]\not = \empty가 성립한다.
    [a][a]\not= \empty이며 aa[a][a]에 속하기에 RR은 Reflexive이다.
    (iii) & (i)를 위해 [a][b][a]\cap [b]\not= \empty라고 가정할 때 Element cc[a],[b][a],[b]에 모두 속한다.
    aRc,bRcaRc, bRc가 성립하고 Symmetric에 의해 cRbcRb가 성립하고 Transitivity에 의해 aRc,cRbaRc, cRb로 인해 aRbaRb가 성립한다.

RR이 Set AA에 대한 Equivalence relation이라고 할 때 RR의 Equivalence class의 Union은 AA 전체와 동일하다.
aA[a]R=A\sum_{a\in A}[a]_R=A
위 Theorem에 의해 Equivalence class는 서로 같거나 Disjoint일 때 [a]R[b]R=[a]_R \cap [b]_R=\emptyd lek.
두사실로 Equivalence class가 AA를 분리한 Subset으로 나누기에 AA의 Partition을 형성함을 확인할 수 있다.
즉 Subset AiA_iSS의 Partition을 형성하기 위한 Condition은 Ai for iI,AiAj= when ijA_i\not =\ for\ i\in I, A_i\cap A_j=\empty\ when\ i\not=j가 필요충분 조건이다.

정보

Theorem

RR을 Set SS의 Equivalence relation이라고 할 때 RR의 Equivalence class들은 SS의 Partition을 형성하고, Set SS의 Partition {AiiI}\{A_i \mid i\in I\}가 주어지면 AiA_i를 Equivalence class로 가지는 Equivalence relation RR이 존

정보

Example

Congruence modulo 4의 Set의 Partition

  • Solution
    총 4개의 Congruence class들이 존재하며 [0]4,[1]4,[2]4,[3]4[0]_4, [1]_4,[2]_4,[3]_4이다.
    [0]4={,8,4,0,4,8,},[0]_4=\{\dots,-8,-4,0,4,8,\dots\},
    [1]4={,7,3,1,5,9,},[1]_4=\{\dots,-7,-3,1,5,9,\dots \},
    [2]4={,6,2,2,6,10,},[2]_4=\{\dots,-6,-2,2,6,10,\dots \},
    [3]4={,5,1,3,7,11,}[3]_4=\{\dots,-5,-1,3,7,11,\dots \}이다.

8.6. Partial Orderings

Set SS에 대한 Relation RR은 Reflexive, Antisymmetric, Transitive일 때 Partial order라고 한다.
Partial order RR과 함께하는 Set SS를 Partially ordered set(Poset)이라고 하며 Notation으로 (S,R)(S, R)로 표기하며 SS의 Element는 Poset의 Element라고 불린다.

Example

Integer set에서 \geq Relation이 Partial order임을 증명

  • Solution
    모든 Integer aa에 대해 aaa\geq a이므로 Reflexive이며 abbaa\geq b \land b\geq a일 때는 a=ba=b일 때 뿐이므로 Antisymmetric이다.
    abbca\geq b \land b\geq c일 때 aca\geq c이므로 Transitive이다.
    그러므로 \geq는 Integer set에대한 Partial order이다.

Poset(S,S, \preccurlyeq)의 Element a,ba, baba\leq bbab\leq a인 경우 Comparable(비교 가능)하다고 하고, SS의 Element a,ba, baba\leq bbab\leq a가 아닌 경우 Incomparable(비교 불가능)하다고 한다.

Example

Poset(Z+,\mathbf{Z^+}, |)에서 Integer 3, 9 / 5, 7이 Comparable인 지 여부

  • Solution
    393 | 9이므로 Comparable, 5∤7,7∤55\not | 7, 7\not | 5이므로 Incomparable이다.

Poset(S,S,\preccurlyeq)이 모든 SS의 Element가 Comparable이면 SS는 Totally ordered(Linearly ordered) set이라고 하며 \preccurlyeq는 Total order(linear order)라고 하며 Totally ordered set을 Chain이라고도 한다.

Example

Poset (Z,\mathbf{Z},\leq)은 Totally ordered이다.
Integer a,ba,babbaa\leq b \lor b\leq a이기 때문이다.

Poset(S,S,\preccurlyeq)가 Well-ordered set이면서 \preccurlyeqSS의 Non empty subset이 최소 Element를 가지는 경우 Total ordering이다.

Example

Positive integer의 Ordered pair set Z+×Z+\mathbf{Z^+} \times \mathbf{Z^+}에서 (a1,a2)(b1,b2)(a_1,a_2) \preccurlyeq (b_1,b_2)(a1<b1(a1=b1a2b2)a_1<b_1 \lor (a_1 =b_1 \land a_2\leq b_2))(=Lexicographic ordering)으로 Well-ordered set이다.

정보

Theorem

The principle of well-ordered induction

SS가 Well-ordered set일 때 모든 xSx\in S에서 P(x)=TrueP(x)=True일 때
Inductive step: For every ySy\in S, if P(x)P(x) is true for all xSx\in S with xyx\prec y then P(y)P(y) is true

  • Proof
    P(x)P(x)가 모든 xSx\in S에 대해 True가 아니라고 가정할 때 P(y)P(y)가 False인 어떤 ySy\in S가 존재하므로 A={xSP(x) is false}A=\{x\in S\mid P(x)\ is\ false\}가 Nonempty set이 된다.
    SS가 Well-ordered이기에 최소 Element aa를 가진다.
    aaAA의 최소 Element로 선택됨에 따라 xax\leq a인 모든 xSx\in S에 대해 P(x)P(x)가 True임을 알 수 있다.
    Inductive step에서 P(a)P(a)가 True임을 의미하며 이 Contradiction은 P(x)P(x)가 모든 xSx\in S에 대해 True여야 함을 보여준다.

Lexicographic Order

두 개의 Poset((A1,1),(A2,2)(A_1,\preccurlyeq_1),(A_2,\preccurlyeq_2))의 Cartesian product에서 Partial ordering을 구성하기 위해 A1×A2A_1\times A_2에서의 Lexicographic ordering은 (a1,a2)(b1,b2)(a_1,a_2)\prec (b_1,b_2)로 표현할 수 있다.
A1×A2A_1\times A_2에 Equality를 추가하여 \preccurlyeq로 나타낼 수 있다.

Example

Poset (Z×Z,\mathbf{Z}\times\mathbf{Z},\preccurlyeq)에서 (3,5)(4,8),(3,8)(4,5),(4,9)(4,11)(3,5)\prec (4,8), (3,8)\prec(4,5), (4,9)\prec (4,11) 여부

  • Solution
    3<4이므로 (3,5)(4,8),(3,8)(4,5)(3,5)\prec(4,8),(3,8)\prec(4,5) 성립하며, 9<11이므로 (4,9)(4,11)(4,9)\prec(4,11)성립한다.

Hasse Diagrams

Finite poset에 대한 Directed graph에서 많은 Edge들은 반드시 표시할 필요가 없다.

Example

Set {1,2,3,4}\{1, 2,3,4\}에 대한 Partial ordering {(a,b)ab}\{(a,b)\mid a\leq b\}의 Directed graph

  • Solution
    이 Relation은 Partial ordering이므로 Reflexive하고 모든 Vertex에 Loop가 존재한다.
    Partial ordering은 Transitivity하기에 반드시 존재하는 Edge를 나타낼 필요가 없고 방향을 위쪽으로 향한다고 가정하면 Edge의 방향까지 표시할 필요가 없어진다.\

Maximal and Minimal Elements

Poset(S,S,\leq)에 대해 aa가 Maximal element라면 aba\leq bbSb\in S가 존재하지 않고, Poset(S,S,\geq)에 대해 aa가 Minimal element라면 bab\leq abSb\in S가 존재하지 않는다.
Hasse diagram에서 가장 위의 Element가 Maximal, 가장아래의 Element가 Minimal이 된다.

Example

Poset({2,4,5,10,12,20,25},\{2,4,5,10,12,20,25\},|)에서 Maximal과 Minimal element

  • Solution
    Poset의 Hasse Diagram은 아래와 같다.

    Minimal은 2, 5이고 Maximal은 12, 20, 25이다.

Poset에서 모든 다른 Element보다 큰 Element가 존재할 수 있는데 이를 Greatest element라고 하고 모든 다른 Element보다 작은 Element는 Least element라고 한다.

Poset AA의 모든 Element보다 크거나 같은 Element를 찾을 때 SS의 Element uuAA의 모든 Element aa에 대해 aua\leq u라면 uuaa의 Upper bound, uau\leq a라면 Under bound라 한다.

Element xxAA의 Upper bound 중 가장 작은 Upper bound 일 때 xxAA의 Least upper bound라고하고, AA의 Lower bound 중 가장 큰 Lower bound 일 때 xxAA의 Greatest lower bound라 한다.
Notation으로 각각 glb(A),lub(A)glb(A), lub(A)로 표기한다.

Example

Poset(Z+,\mathbf{Z^+},|)의 Set{3,9,12}\{3,9,12\}{1,2,4,5,10}\{1,2,4,5,10\}glb,lubglb, lub

  • Solution
    3,9,12로 나누어 떨어지는 수 중 가장 작은 수 =lcm(3,9,12)=lub({3,9,12})=36= lcm(3,9,12) = lub(\{3,9,12\})=36
    3,9,12를나누어 떨어트리는 수 중 가장 큰 수 =gcd(3,9,12)=glb({3,9,12})=3=gcd(3,9,12)=glb(\{3,9,12\})=3
    1,2,4,5,10의 최대공약수와 최소 공배수 lcm(1,2,4,5,10)=20,gcd(1,2,4,5,10)=1lcm(1,2,4,5,10)=20, gcd(1,2,4,5,10)=1로 구할 수 있다.

Lattices

Lattice(격자)는 lub,glblub, glb를 가지는 Partial ordering을 의미한다.

Example

Poset(Z+,\mathbf{Z^+},|)가 Lattice인 지

  • Solution
    Positive integer a,ba, b에 대해 lub,glblub, glb, 즉 lcm,gcdlcm, gcd가 존재하므로 Lattice라고 한다.

Topological Sorting

Topological sorting(위상 정렬)은 Partial ordering을 Compatible(호환)되게 하여 Total ordering으로 만드는 과정을 의미한다.

정보

Lemma

모든 Finite nonempty poset(S,S, \preccurlyeq)는 적어도 하나의 Minimal element를 가진다.

  • Proof
    임의의 Element a0a_0가 Minimal element가 아닐 때 더 작은 Element를 찾는다.
    이를 반복할 경우 Finite set이기에 Minimal element가 존재할 수 밖에 없다.
정보

Psudocode

Algorithm : Topological Sorting

procedure topological sort((S,)(S,\preccurlyeq) : finite poset)
kk := 1
while SS\not=\empty
begin
aka_k := a minimal element of SS {such an element exists by Lemma}
SS := S{ak}S-\{a_k\}
kk := k+1k+1

end {a1,a2,,ana_1,a_2,\dots,a_n is compatible total ordering of SS}

Example

Poset({1,2,4,5,12,20},\{1,2,4,5,12,20\},|)의 Compatible total ordering(Topological sorting)

  • Solution
    매 Step마다 Minimal elemnt를 고르고 제외한 후 반복한다.
    즉 1 | 2, 5 | 4 | 12, 20에서 |에서의 순서만 지킨 결과값이 나온다.

    위 이미지와 같이 Topological sorting을 한다면 152420121\prec 5\prec 2\prec 4\prec 20\prec 12가 된다.