0% found this document useful (0 votes)
53 views23 pages

Relations: An Introduction

The document defines and provides examples of Cartesian products, relations, equivalence relations, partial orderings, and how they relate to databases and the relational data model. Cartesian products combine elements from multiple sets. Relations are subsets of Cartesian products that define relationships between elements. Equivalence relations partition a set into equivalence classes. Partial orderings are relations that are reflexive, antisymmetric, and transitive. The relational data model represents databases as relations between tuples of fields, analogous to tables with rows and columns.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views23 pages

Relations: An Introduction

The document defines and provides examples of Cartesian products, relations, equivalence relations, partial orderings, and how they relate to databases and the relational data model. Cartesian products combine elements from multiple sets. Relations are subsets of Cartesian products that define relationships between elements. Equivalence relations partition a set into equivalence classes. Partial orderings are relations that are reflexive, antisymmetric, and transitive. The relational data model represents databases as relations between tuples of fields, analogous to tables with rows and columns.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Relations

An Introduction

Cartesian Product
Definition
Let A and B be sets. The Cartesian Product is the set of all ordered pairs where the first coordinates are in A and the second coordinates are in B. Notation
AB = { (a,b) aA and bB }

Example A = {1,2 } B = {a,b,c} AB = { (1,a),(1,b),(1,c),(2,a),(2,b),(2,c) } BA = { (a,1),(a,2),(b,1),(b,2),(c,1),(c,2) }

Cartesian Product
Cartesian Product of 3 or more sets (n-fold product)
AB C = { (a, b, c) aA, bB and cC }

Product Rule
if |A| = m and |B| = n, then |AB| = m*n if |C| = k, |ABC| = m*n*k

Cartesian Product
Theorems
1. A (BC)=(AB)(AC) 2. A (BC)=(AB)(AC) 3. A= 4. (AB)(CD)=(AC) (BD) 5. (AB)(CD) (AC) (BD)

Relations
Definition
A Relation on two sets A and B is a subset of AB. A Relation is specified by an open sentence such as a is less than b or a + b = 5. Examples
1. Let R be the Relation from A = { 1, 2, 3, 4 } to B= {1,3,5 } which is defined by x is less than y . R = { ( x,y ) x is less than y } = { (1,3), (1,5), (2,3), (2,5), (3,5) , (4,5) } 2. Let R be the Relation from E = { 2, 3, 4, 5 } to F = { 3, 6, 7, 10 } which is defined by x|y

Relations
Binary Relation: relation defined on two sets that are not
necessarily distinct

Ternary Relation: relation defined on three sets that are


not necessarily distinct

n-ary Relation: relation on n sets Unary Relation: relation on one set


Example
G = { 55, 89, 75, 65, 88, 80, 90 } Define a Unary Relation R on G: x is an element of R if x>74. R={ 89, 75, 88, 80, 90 }

Relations
Domain of a Binary Relation R
set whose elements are all as such that (a,b) R. ( a is related to b or aRb )

Range of a Binary Relation R


set whose elements are all bs such that (a,b) R.

Relations
Properties of Relations
reflexive. aRa for all a A (every element is related to itself) irreflexive: a A b A, aRb ab (every element is not related to itself) symmetric: a A b A, aRb bRa antisymmetric: a A b A, (aRb bRa) a = b transitive: if aRb bRc then aRc for all a,b,c A

Relations
Properties of Relations: Example
Let R be the Relation on the set of Natural Numbers: x is related to y such that x y Reflexive. every Natural Number is itself Not Symmetric. if x y, y is not necessarily x Antisymmetric: x y y x x = y Transitive: x y y z x z

Equivalence Relation
Definition
A Binary Relation R on a set S is an Equivalence Relation if R is reflexive, symmetric and transitive. The set on which an Equivalence Relation is defined can be partitioned into disjoint sets by Equivalence Classes. A Partition of a set S is a collection of nonempty disjoint subsets whose union equals S. For an Equivalence Relation on a set S
if x S [x] denotes the set of all members of S related to x; [x] is called an Equivalence Class of x.

Equivalence Relation
Examples
R on N defined by xRy if x+y is even
R is reflexive, symmetric and transitive. (verify this) R is an equivalence relation Equivalence Classes (partition of N)
[0] = { 0, 2, 4, 6, 8......} [1] = { 1, 3, 5, 7, 9......}

R on N where (x, y) R if x mod 4 = y mod 4


Equivalence Classes
[0] = {0, 4, 8, 12, 16, 20 ...} [1] = {1, 5, 9, 13, 17, 21....} [2] = {2, 6, 10, 14, 18, 22...} [3] = {3, 7, 11, 15, 19, 23...}

Partial Ordering
Definition
A Binary Relation on S that is reflexive, transitive and antisymmetric is a partial ordering. S is a partially ordered set (a.k.a. the poset (S, R), where R is the Partial Relation). Example
R on N = {(x,y) x <= y }

The Hasse Diagram depicts the partial ordering of the set on which the relation is defined

Partial Ordering
Examples
R on (A) : x R y x y where x,y (A) A = { a, b } (A) = { {a}, {b}, {a,b}, } R = { ({a,b}, {a,b}) , ({a}, {a,b}), ({a},{a}), ({b}, {b}), ({b}, {a,b}), (, {a}), (, {b}),( , {a,b}), (, ) } Reflexive. Every set is a subset of itself. Transitive. A B B C A C Antisymmetric. A B B A B = A

Partial Ordering
Examples
R on S = { 1, 2, 3, 6, 12, 18 } where x R y if x|y
R = { (1,2), (1,1), (1,3), (1,6), (1,12), (1,18), (2,6), (2,12), (2,18), (3,6), (3,12), (3,18), (6,12), (6,18), (18,18),(12,12), (2,2), (3,3), (6,6) }

Partial Ordering
1

{a}

{b}

2 6

{a, b} 12 18

Relations and Databases


There are different ways of representing databases. The Relational Data Model is a method of representing databases. The Relational Data Model is based on the concept of a relation.

Relations and Databases


A database consists of records, which are ntuples, made up of fields. The Relational Data Model represents a database of records as an n-ary relation. For example, student records are represented as 4-tuples of the form (STUDENT_NAME, ID_NUMBER, MAJOR, GPA)

4-tuples of the form


(STUDENT_NAME, ID_NUMBER, MAJOR, GPA) (Bieber Justine, 231455, Information Technology, 87.8) (Gaga Lady, 888323, Physics, 82.99) (Swift Taylor, 453876, Music, 84.85)

Relations and Databases


Relations used to represent databases are called tables because the relations are often displayed as tables

Relations and Databases (Students Table)


Name Bieber Justine Gaga Lady Swift Taylor ID Number 231455 888323 453876 Major Information Technology Physics Music GPA 87.8 82.99 84.85

Relations and Databases (Students Table)


Name Ackerman Adams Chou Goodfrend Rao Stevens ID Major Number 231455 888323 102147 453876 678543 78576 Comp Sc Physics Comp Sc Math Math Psycho GPA 3.88 3.45 3.49 3.45 3.90 2.99

Relations and Databases (Class Schedule Table)


Dept CS Math Math Physics Psycho Psycho Zoology Zoology Course No. Room 518 575 611 544 501 617 335 412 N521 N502 N521 B505 A100 A110 A100 A100 Time 2:00PM 3:00PM 4:00PM 4:00PM 3.00PM 11:00AM 9:00PM 8:00AM

Relations and Databases (Teaching Assignments Table)


Professor Cruz Cruz Farber Farber Grammer Grammer Rosen Rosen Dept Zoology Zoology Psycho Psycho Physics Physics CS Math Course Number 335 412 501 617 544 551 518 575

You might also like