Docsity

Relations and Subsets of Cartesian Products, Study notes of Number Theory

Partial preview of the text

Download Relations and Subsets of Cartesian Products and more Study notes Number Theory in PDF only on Docsity!

Relations

Zeph Grunschlag

Announcements

HW9 due now HWs 10 and 11 are available

Midterm 2 regrades: bring to my attention Monday 4/

Clerical errors regarding scores can be fixed through reading period

Relational Databases

Relational databases standard organizing structure for large databases

 Simple design  Powerful functionality  Allows for efficient algorithms

Not all databases are relational

 Ancient database systems  XML – tree based data structure  Modern database must: easy conversion to relational

Example 1

A relational database with schema :

1 Kate Winslet Leonardo DiCaprio 2 Dove Dial 3 Purple Green 4 Movie star Movie star

1 Name 2 Favorite Soap 3 Favorite Color 4 Occupation

…etc.

Example 3

Example of a pigeon to crumb pairing where pigeons may share a crumb: Crumb 1 Pigeon 1 Crumb 2 Pigeon 2 Crumb 3 Pigeon 3 Crumb 4 Crumb 5

Example 4

The concept of “siblinghood”.

Relations: Represented as

Subsets of Cartesian Products

In more rigorous terms, all 4 examples could be represented as subsets of certain Cartesian products.

Q: How is this done for examples 1, 2, 3 and 4?

Relations: Represented as

Subsets of Cartesian Products

The 4 examples:

  1. Database 

  2. mod 2 addition 

  3. Pigeon-Crumb feeding 

  4. Siblinghood 

Relations as Subsets of

Cartesian Products

A: The subset for mod 2 addition:

{ (0,0,0), (0,1,1), (1,0,1), (1,1,0) }

Relations as Subsets of

Cartesian Products

DEF: Let A 1 , A 2 , … , An be sets. An n- ary

relation on these sets (in this order) is a

subset of A 1 ×A 2 × … ×An.

Most of the time we consider n = 2 in which

case have a binary relation and also say

the the relation is “ from A 1 to A 2 ”. With

this terminology, all functions are relations, but not vice versa.

Q: What additional property ensures that a relation is a function?

Graph Example

A: Visualize both branches of solution to

x = y 2 as the graph of a relation:

-10 0 10 20 30 40 50 60 70 80 90 100

0

2

4

6

8

10

x

y

Relations as Subsets of

Cartesian Products

Q: How many n-ary relations are there on

A 1 , A 2 , … , An?

L22 19

Relations as Subsets:

A: Siblinghood. A = {people} Because relations are just subsets, all the usual set theoretic operations are defined between relations which belong to the same Cartesian product. Q: Suppose we have relations on {1,2} given by R = {(1,1), (2,2)}, S = {(1,1),(1,2)}. Find:

  1. The union R  S
  2. The intersection R  S
  3. The symmetric difference R  S
  4. The difference R-S
  5. The complement R

Relations as Subsets:

A: R = {(1,1),(2,2)}, S = {(1,1),(1,2)}

  1. R  S = {(1,1),(1,2),(2,2)}
  2. R  S = {(1,1)}
  3. R  S = {(1,2),(2,2)}.
  4. R-S = {(2,2)}.
  5. R = {(1,2),(2,1)}