8. Relations
8.1. Relations and Their Properties
Set 에 대해 Binary relation from to 는 의 Subset이다.
Binary relation from to 의 첫 번재 Element가 에서 오고 두 번재 Element가 에서 온 각 Ordered pair의 Set 이라고 할 때 을 나타내기 위해 라는 Notation을 사용하고 을 Notation으로 로 나타낸다.
가 에 속할 때 는 related to by (는 에 의해 와 관계)라고 한다.
Example
라고 할 때 relation from to
- Solution
Functions as Relations
Functrion 가 Set 에서 로 정의된 경우 는 의 각 Element에 대해 에 정확히 하나의 Element를 할당한다.
의 Graph는 의 Subset이므로 에서 로의 Relation이다.
Function의 Graph는 의 모든 Element가 Graph의 정확히 하나의 Ordered pair의 첫 Element라는 특성을 가지고 있다.
이 에서 로의 관계이고 의 모든 Element가 의 정확히 하나의 Ordered pair의 첫 Element라면 을 Graph로 하는 Function이 정의될 수 있다.
의 Element 에 대해 인 유일한 Element 를 할당함으로 가능해진다.
Relation은 Set 의 Element 간 One-to-many relationship을 표현하는 데 사용될 수 있다.
이 경우 의 Element는 의 여러 Element와 Relation이 있을 수 있다.
Funtion의 경우 의 각 Element와 관련된 의 정확히 하나의 Element를 나타내는 Relation이다.
Relations on a Set
Set 에서 로의 Relation은 Relation on the set 라고 하며 의 Subset이다.
Example
Set 라고 할 때 Relation 의 Ordered pair
- Solution
Example
개의 Element를 가진 Set에서 Relation 개수
- Solution
Set 에서의 Relation은 의 Subset이다.
는 개의 Element를 가지기에 만큼의 Relation이 존재한다.
Properties of Relations
Set 에서의 Relation 은 모든 Element 에 대해 일 경우 Reflexive(반사적)이라고 한다.
Remark
Quantifier를 사용할 경우 Relation 이 Set 에서 Reflexive하다는 것은 을 의미한다.
Set 에 대한 Relation 은 의 모든 에 대해 일 때 이면 Symmetric(대칭적)이라 하고 에 대해 을 만족하는 Condition이 일 경우 Antisymmetric(비대칭적)이라고 한다.
Remark
Quantifier를 사용할 경우 Set 의 Relation 은 인 경우 Symmetric, 인 경우 Antisymmetric이라 한다.
Set 의 Transitive(전이) relation은 Relation 의 모든 에 대해 이고 이면 이 성립함을 의미한다.
Remark
Quantifier를 사용하여 Set 의 Relation 이 Transitive인 경우를 로 표현 가능하다.
Example
모든 가 Positive integer set 에 속할 때 는 Positive integer의 Divide relation에서 Reflexive인 지, Symmetric인 지, Transitive인 지
- Solution
Reflexive: 가 Positive integer일 때 항상 는 를 나누므로 Divide relation은 Reflexive하다.
만약 Set을 Nonnegative integer set으로 바꿀 경우 0은 0을 나눌 수 없으므로 Divide relation이 Reflexive하지 못한다.
Symmetric: Symmetirc이지 않다.
이유로는 이나 이기 때문이다.
추가적으로 이 Relation은 Antisymmetric인 이유로는 가 Positive integer일 때 이고 이면 이기 때문이다.
Transitive: Positive integer 에 대해 이기에 이 Relation은 Transitive이다.
Combining Relation
Set 에 대한 Relation은 의 Subset이다.
을 Set 에서 로의 Relation, 를 Set 에서 로의 Relation이라고 할 때 의 Composite는 를 만족하는 Ordered pair 로 이루어진 Releation이며 이다.
Notation으로 로 표현한다.
Set 의 Relation 의 Power 를 로 Recursive하게 정의된다.
Example
Relation 을 모든 사람에 대한 Set의 Relation이라고 할 때 은 가 의 부모일 때 성립할 때
- Solution
Relation 이 부모 Relation을 나타내기에 은 부모의 부모, 즉 조부모 Relation을 나타낸다.
Example
Relation 이라고 할 때
- Solution
이고 을 알 수 있다.
이후 몇 번을 거듭제곱하여도 모든 Ordered pair의 뒤 Element가 1이 되는 것을 알 수 있으므로 가 참임을 알 수 있다.
Theorem
Set 의 Relation 은 일 때 일 경우 Transitive이다.
8.2. n-ary Relations and Their Application
n-ary Relations
Set 에 대한 -ary Relation은 의 Subset이다.
Set 을 Domain, 을 Relation의 Degree라고 한다.
Example
을 Airplane flight를 나타내는 5-Tuple()라고 할 때 이 Relation의 예시로 (항공사, 비행기 번호, 출발지, 도착지, 출발 시간)의 꼴로 (Nadir, 963, Mewark, Bangor, 15:00)로 나타낼 수 있다.
이 Relation의 Degree는 5이며 Relation의 Domain은 모든 항공사 Set, 비행기 Set, 출발 도시 Set, 도착 도시 Set, 시간 Set이 된다.
Databases and Relations
DB는 Field로 구성된 -tuple인 Record로 이루어져 있다(Field = 각 Tuple의 Item).
DB의 Relation을 Table이라고 부른다(표현이 Table로 되기 때문).
-tuple의 Relation의 Domain은 -tuple의 Value가 이 Domain에서 -tuple을 결정할 때 Primary key라고 한다.
Primary key는 Unique, Not null이다.
Relation에서 현재 -tuple의 Set을 Relation의 Extension이라고 한다.
DB의 Name, Attribute들을 포함하는 Permanent part를 Intension이라고 한다.
Domain의 Combination은 -ary Relation에서 -tuple을 Uniquyely Identifiy 가능하다.
특정 Domain set의 Value가 Relation 내의 -tuple을 결정할 때 Domain의 Cartesian product를 Composite key라고 한다.
Operations on n-ary Relations
-ary relation 의 Element가 만족할 수 있는 Condition을 라 할 때 Selection operator 은 -ary relation 을 Condition 를 만족하는 의 모든 -tuple의 -ary relation을 Mapping한다.
Projection(투영 연산) 을 만족하는 은 일 때, -tuple()을 -tuple()로 Mapping한다.
이 Degree 인 Relation이고 가 Degree 인 Relation일 때 인 Join 는 Degree가 인 Relation이며 -tuple()로 구성되며 는 -tuple이며 에 속하고 은 -tuple이며 에 속한다.
SQL
SQL(Structured Query Language)는 DB의 Queryu language이다.
| Airline | Flight_number | Gate | Destination | Departure_time |
|---|---|---|---|---|
| Nadir | 122 | 34 | Detroit | 08:10 |
| Acme | 221 | 22 | Denver | 08:17 |
| Acme | 122 | 33 | Anchorage | 08:22 |
| Acme | 323 | 34 | Honolulu | 08:30 |
| Nadir | 199 | 13 | Detroit | 08:47 |
| Acme | 222 | 22 | Denver | 09:10 |
| Nadir | 322 | 34 | Detroit | 09:44 |
Example
SELECT Departure_time FROM Flights WHERE Destination='Detroit';
- Solution
위 TableFlightsDB에서 ConditionDestination='Detroit'를 만족하는 5-tuple의 Selection으로부터Departure_timeAttribute의 Projection 를 찾는 데 사용된다.
8.3. Representing Relations
Representing Relations Using Matrices
Finite set 간의 Relation은 Zero-one Matrix를 사용하여 표현 가능하다.
이 Set 에서 으로의 Relation이라 가정할 때 와 같을 때 Relation 은 ()로 나타낼 수 있다.
Example
Set 의 에서 로의 Relation 에 대해 일 때 Ordered pair 일 때 Matrix
- Solution
이기에 에 해당하는 Matrix는
가 된다.
이 Set 에서 로의 Relation이고 가 Set 에서 로의 Relation일 때 Set 는 각각 개의 Element를 가진다고 할 때 에 대한 Zero-one matrix는 각각 로 표기할 때 Matrix의 크기는 각각 이다.
Ordered pair 는 에 속하기 위해 어떤 Element 가 존재해야 하며 는 에, 는 에 속해야 한다.
싸라서 을 만족하는 에 대해 성립할 경우에만 성립한다.
즉 이다.
Example
이고 일 때 의 Matrix
- Solution
이다.
Example
일 때 의 Matrix
- Solution
이다.
Representing Relations Using Digraphs
Directed graph(=Digraph)는 Vertex(Node)들로 이루어진 Set 와 의 Element pair로 구성된 Set 로 이루어져 있으며 이를 Edge(Arc)라고 부른다.
형태가 인 Edge는 다시 자기 자신으로 향하는 Arc로 표현되며 Loop라고도 한다.
Example
Vertex 가 존재하고 Edge 가 존재하는 Digraph는 위 Example's Directed graph 1과 같이 존재한다.
Example
주어진 Example's Directed graph 2의 Relation이 Reflexive, Symmetric, Antisymmetric, Transitive인 지
- Solution
Reflexive: 은 매 Vertex에 Loop edge가 존재하여 Reflexive하나 는 그렇지 못하다.
Symmetric / Antisymmetric: 양 방향을 잇는 Edge가 둘 다 존재하지 않으므로 는 Symmetric하지도 Antisymmetric하지도 않다.
Transitive: 가 존재하지 않아 은 Transitive하지 않고 가 속하지 않아 역시 Transitive하지 않다.
8.4. Closures of Relations
Set 의 Relation 는 Not reflexive이다.
을 포함하며 최소한의 Reflexive relation을 생성하기 위해 에 을 추가해야 한다.
앞 을 포함하며 Reflexive이며 을 포함하는 모든 Reflexive relation 내에 위치하는 것을 Reflexive closure of (의 반사적 닫힘)이라 한다.
즉 를 만족할 때 이며 이 Relation은 Diagonal relation이다.
Set 의 Relation 는 Not Symmetric이다.
을 포함하며 최소한의 Symmetric relation을 생성하기 위해 에 을 추가해야 한다.
앞 을 포함하며 Symmetric이며 을 포함하는 모든 Symmetric relation은 새로 생성된 Relation을 포함해야 한다(모든 Symmetric Relation은 을 포함해야 한다.).
이 새로운 Relation을 Symmetric closure of (의 대칭적 닫힘)이라고 한다.
Example
가 Positive Integer일 때 Relation 의 Reflexive closure
- Solution
의 Reflexive closure는 이다.
Example
가 Positive integer일 때 Relation 의 Symmetric closure
- Solution
R의 Symmetric closure는이다.
Paths in Directed Graphs
Directed graph 에서 에서 로 가는 Path는 에서 Edge의 Sequence 이다().
Path 중 Edge의 끝 Vertex가 다음 Edge의 시작 Vertex와 같으며 길이가 0인 경우 Empty set이며, 길이가 인 경우 길이의 Circuite나 Cycle이라고 부른다.
Theorem
Set 위 Relation 에 대해 이 Positive integer일 경우 에서 로 가는 길이 인 Path가 존재하는 것은 과 필요 충분 조건이다.
- Proof
Mathematical induction을 사용하여 에서 로의 Path는 과 필요 충분 조건이다.
에서 로 가는 길이가 인 Path가 존재하는 것은 에서 로 가는 이 길이인 Path가 존재하고 에서 로의 가는 길이가 인 Path가 존재할 때 필요 충분 조건이다.
이로써 증명할 수 있다.
Transitive Closures
Set 에 대한 Relation 에 대해 이 에서 로 가는 길이가 1 이상인 Path가 존재하는 Pair 로 구성되는 Connectivity relation이라고 할 때 이다.
Theorem
Relation 의 Transitive closure는 Connectivity Relation
- Proof
이 Transitive인 지 qhdlrl dnlgo 라면 에서 에서 에서 로 가는 Path가 존재한다.
즉 이다.
가 을 포함하는 Transitive relation이라고 할 때 역시 Transitive이며 이다().
이기에 이며 이기에 이다.
요약하여 가 되므로 을 포함하는 모든 Transitive closure는 를 포함하여야 하며 의 Transitive closure이다.
Theorem
에 대한 Zero-one matrix 일 때 Transitive closure 의 Zero-one matrix는
Example
Relation 의 Zero-one matrix가 일 때 Transitive closure의 Zero-one matrix
- Solution
의 Zero-one matrix는 이기에 임을 이용하여
이다.
Pseudocode
Algorithm : A Procedure for Computing the Transitive Closure
procedure transitive closure(: zero-one matrix)
:=
:=
for := 2 to
begin
:=
:=
end { is the zero-one matrix for }
현재 위 Algorithm의 각 거듭제곱을 계산하기 위해 의 의 Zero-one matrix의 Boolean product를 찾아야하기에 총 만큼의 Bit operator를 사용하여야 하며 Big-O notation으로 가 된다.
Warshall's Algorithm
1960년에 Stephen Warshall에 의해 설명된 Warshall's algorithm은 Relation의 Transitive closure를 계산하는 효율적인 Algorithm이다.
을 개의 Element를 가진 Set의 Relation으로 가정할 때 이 개의 Element의 임의의 나열일 때 Path의 Interior vertex의 Concept를 사용하여 가 Path일 때 Interior vertex는 로 Path에서 첫 번째와 마지막 Vertex를 제외한 모든 Vertex들이다.
Zero-one matrix의 Sequence를 구성하는 데 기반을 두며 들이 이 Matrix라고 할 때 이고 ( if 에서 로 가는 Path가 존재하며 모든 Interior vertex들이 안에 존재할 때, 그렇지 않다면 )이다.
임을 유의하여 의 번째 Element는 에서 로 가는 Path가 존재하고 모든 Interior vertex들이 Set 내에 있을 때 1, 그렇지 않다면 0이다.
Example
Relation 을 라고 할 때 Matrix
- Solution
라고 할 때 이다.
의 번째 Element는 에서 까지의 Path가 를 가질 때에만 Interior vertex이며 즉 1이다.
모든 길이가 1인 Path는 Interior vertex가 없으므로 여전히 사용 가능하다.
에서 의 Path인 가 존재하므로 이며 가 단말 Vertex인 Edge가 존재하지 않기에 를 Interior vertex로 허용할 때 새로운 Path가 생기지 않으므로 이다.
의 번째 Element는 에서 까지의 Path가 를 Interior vertex로 가질 경우 1이므로 이며 의 경우 에서 까지의 Path가 를 Interior vertex로 가질 경우 1이므로 이다.
Lemma
를 Zero-one matrix라고 할 때 위치에 1이 들어가 있는 경우가 Set의 Interior vertex를 가진 에서 로 가는 Path가 존재할 때일 때
Pseudocode
Algorithm : Warshall Algorithm
procedure Warshall(: zero-one matrix)
:=
for := 1 to
begin
for := 1 to
begin
for := 1 to
:=
end
end { = is }
8.5. Equivalence Relations
Equivalence Relations
Set 에서 Relation을 Equivalence relation(동치 관계)라고 하기 위해 Reflexive, Symmetric, Transitive해야 한다.
두 Element 가 Equivalence relation라고 할 때 equivalent(동치)라고 하며 Notation으로 로 표현한다.
Example
Positive integer 과 Character string 에 대해 이 의 Relation이며 는 이거나 와 가 모두 자 이상이며 의 첫 자가 같을 때 성립
즉 자 미만의 String은 자기 자신과만 Relation이 있으며 자 이상의 경우 처음 자가 동일할 때만 Relation 존재
이라고 할 때 가 모든 Bit string의 Set일 때 는 거나 3 이상인 Bit string이 동일한 3 Bit로 시작할 때 성립
이때 모든 와 모든 에 대해 이 의 Equivalence relation임을 증명
- Solution
은 Reflexive하다().
만약 라면 이거나 는 자 이상이며 같은 String으로 시작한다.
따라서 가 성립할 때 역시 성립하며 이 Symmetric하다.
라고 가정할 경우 가 성립하므로 Transitive하므로 은 의Equivalence relation이다.
Example
Positive integer set에서 "Divide" Relation이 Equivalence relation이 아님을 증명
- Solution
이전 Example에서 "Divide" Relation은 Reflexive, Transitive이나 Symmetric하지 않으므로() Equivalence relation이 아니다.
Equivalence Classes
Set 에 정의된 Equivalence relation 이 있을 때 의 Element 와 관련된 모든 Element의 Set을 Equivalence class라고 한다.
에 대한 의 Equivalence class를 Notation으로 로 표기하며 하나의 Relation만 고려할 경우 로 표기 가능하다.
즉, 이며 일 경우 는 Equivalence class의 Representative라고 하며 어떤 Equivalence class의 Element는 Representative로 사용할 수 있으며 특별한 의미가 없다.
Example
0, 1의 Equivalence class는 4로 나눈 나머지에 대해 어떻게 정의되는지
- Solution
0의 Equivalence class는 인 모든 Integer들은 4로 나누어 떨어지는 모든 Integer 를 포함한다.
따라서 이 Relation에 대한 0의 Equivalence class는 이다.
1의 Equivalence class는 이다.
Example
Bit string set의
Relation에 따라 String 0111의 Equivalence class
(는 가 Bit string이며 이거나 의 앞 3 Bit가 동일한 3Bit 이상 String)
- Solution
Equivalence Classes and Partitions
Theorem
Set 에 대한 Equivalence relation 에 대해 의 Element 에 대해 다음의 Statement들은 Equivalent이다.
, ,
- Proof
(i) & (ii) 일 때 임을 보이기 위해 , 를 증명한다.
가 에 속한다면 가 성립하며 이고 이 Symmetric이므로 가 성립함을 알 수 있다.
이 Transitive이고 이 Transitive이기에 와 가 주어질 경우 가 성립하므로 이다.
같은 방법으로 도 증명 가능하다.
(ii) & (iii)를 의미하기 위해 일 때 가 성립한다.
이며 가 에 속하기에 은 Reflexive이다.
(iii) & (i)를 위해 라고 가정할 때 Element 는 에 모두 속한다.
즉 가 성립하고 Symmetric에 의해 가 성립하고 Transitivity에 의해 로 인해 가 성립한다.
이 Set 에 대한 Equivalence relation이라고 할 때 의 Equivalence class의 Union은 전체와 동일하다.
위 Theorem에 의해 Equivalence class는 서로 같거나 Disjoint일 때 d lek.
두사실로 Equivalence class가 를 분리한 Subset으로 나누기에 의 Partition을 형성함을 확인할 수 있다.
즉 Subset 는 의 Partition을 형성하기 위한 Condition은 가 필요충분 조건이다.
Theorem
을 Set 의 Equivalence relation이라고 할 때 의 Equivalence class들은 의 Partition을 형성하고, Set 의 Partition 가 주어지면 를 Equivalence class로 가지는 Equivalence relation 이 존
Example
Congruence modulo 4의 Set의 Partition
- Solution
총 4개의 Congruence class들이 존재하며 이다.
이다.
8.6. Partial Orderings
Set 에 대한 Relation 은 Reflexive, Antisymmetric, Transitive일 때 Partial order라고 한다.
Partial order 과 함께하는 Set 를 Partially ordered set(Poset)이라고 하며 Notation으로 로 표기하며 의 Element는 Poset의 Element라고 불린다.
Example
Integer set에서 Relation이 Partial order임을 증명
- Solution
모든 Integer 에 대해 이므로 Reflexive이며 일 때는 일 때 뿐이므로 Antisymmetric이다.
일 때 이므로 Transitive이다.
그러므로 는 Integer set에대한 Partial order이다.
Poset()의 Element 는 나 인 경우 Comparable(비교 가능)하다고 하고, 의 Element 가 나 가 아닌 경우 Incomparable(비교 불가능)하다고 한다.
Example
Poset()에서 Integer 3, 9 / 5, 7이 Comparable인 지 여부
- Solution
이므로 Comparable, 이므로 Incomparable이다.
Poset()이 모든 의 Element가 Comparable이면 는 Totally ordered(Linearly ordered) set이라고 하며 는 Total order(linear order)라고 하며 Totally ordered set을 Chain이라고도 한다.
Example
Poset ()은 Totally ordered이다.
Integer 가 이기 때문이다.
Poset()가 Well-ordered set이면서 가 의 Non empty subset이 최소 Element를 가지는 경우 Total ordering이다.
Example
Positive integer의 Ordered pair set 에서 ()(=Lexicographic ordering)으로 Well-ordered set이다.
Theorem
The principle of well-ordered induction
가 Well-ordered set일 때 모든 에서 일 때
Inductive step: For every , if is true for all with then is true
- Proof
가 모든 에 대해 True가 아니라고 가정할 때 가 False인 어떤 가 존재하므로 가 Nonempty set이 된다.
가 Well-ordered이기에 최소 Element 를 가진다.
가 의 최소 Element로 선택됨에 따라 인 모든 에 대해 가 True임을 알 수 있다.
Inductive step에서 가 True임을 의미하며 이 Contradiction은 가 모든 에 대해 True여야 함을 보여준다.
Lexicographic Order
두 개의 Poset()의 Cartesian product에서 Partial ordering을 구성하기 위해 에서의 Lexicographic ordering은 로 표현할 수 있다.
에 Equality를 추가하여 로 나타낼 수 있다.
Example
Poset ()에서 여부
- Solution
3<4이므로 성립하며, 9<11이므로 성립한다.
Hasse Diagrams
Finite poset에 대한 Directed graph에서 많은 Edge들은 반드시 표시할 필요가 없다.
Example
Set 에 대한 Partial ordering 의 Directed graph
- Solution
이 Relation은 Partial ordering이므로 Reflexive하고 모든 Vertex에 Loop가 존재한다.
Partial ordering은 Transitivity하기에 반드시 존재하는 Edge를 나타낼 필요가 없고 방향을 위쪽으로 향한다고 가정하면 Edge의 방향까지 표시할 필요가 없어진다.\
Maximal and Minimal Elements
Poset()에 대해 가 Maximal element라면 인 가 존재하지 않고, Poset()에 대해 가 Minimal element라면 인 가 존재하지 않는다.
Hasse diagram에서 가장 위의 Element가 Maximal, 가장아래의 Element가 Minimal이 된다.
Example
Poset()에서 Maximal과 Minimal element
- Solution
Poset의 Hasse Diagram은 아래와 같다.
Minimal은 2, 5이고 Maximal은 12, 20, 25이다.
Poset에서 모든 다른 Element보다 큰 Element가 존재할 수 있는데 이를 Greatest element라고 하고 모든 다른 Element보다 작은 Element는 Least element라고 한다.
Poset 의 모든 Element보다 크거나 같은 Element를 찾을 때 의 Element 가 의 모든 Element 에 대해 라면 는 의 Upper bound, 라면 Under bound라 한다.
Element 가 의 Upper bound 중 가장 작은 Upper bound 일 때 는 의 Least upper bound라고하고, 의 Lower bound 중 가장 큰 Lower bound 일 때 는 의 Greatest lower bound라 한다.
Notation으로 각각 로 표기한다.
Example
Poset()의 Set와 의
- Solution
3,9,12로 나누어 떨어지는 수 중 가장 작은 수
3,9,12를나누어 떨어트리는 수 중 가장 큰 수
1,2,4,5,10의 최대공약수와 최소 공배수 로 구할 수 있다.
Lattices
Lattice(격자)는 를 가지는 Partial ordering을 의미한다.
Example
Poset()가 Lattice인 지
- Solution
Positive integer 에 대해 , 즉 가 존재하므로 Lattice라고 한다.
Topological Sorting
Topological sorting(위상 정렬)은 Partial ordering을 Compatible(호환)되게 하여 Total ordering으로 만드는 과정을 의미한다.
Lemma
모든 Finite nonempty poset()는 적어도 하나의 Minimal element를 가진다.
- Proof
임의의 Element 가 Minimal element가 아닐 때 더 작은 Element를 찾는다.
이를 반복할 경우 Finite set이기에 Minimal element가 존재할 수 밖에 없다.
Psudocode
Algorithm : Topological Sorting
procedure topological sort( : finite poset)
:= 1
while
begin
:= a minimal element of {such an element exists by Lemma}
:=
:=
end { is compatible total ordering of }
Example
Poset()의 Compatible total ordering(Topological sorting)
- Solution
매 Step마다 Minimal elemnt를 고르고 제외한 후 반복한다.
즉 1 | 2, 5 | 4 | 12, 20에서 |에서의 순서만 지킨 결과값이 나온다.
위 이미지와 같이 Topological sorting을 한다면 가 된다.