discrete mathematics relation. cartesian product if a 1, a 2, …, a m are nonempty sets, then the...

36
Discrete Mathematics Relation

Upload: lauren-gibbs

Post on 05-Jan-2016

223 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Discrete Mathematics

Relation

Page 2: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Cartesian Product If A1, A2, …, Am are nonempty sets, then

the Cartesian Product of these sets is the set of all ordered m-tuples (a1, a2, …, am), where ai Ai, i = 1, 2, … m.

Denoted A1 A2 … Am = {(a1, a2, …, am) | ai Ai, i = 1, 2, … m}

Page 3: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Cartesian Product Example If A = {1, 2, 3} and B = {a, b, c}, find A

B A B = {(1,a), (1,b), (1,c), (2,a), (2,b),

(2,c), (3,a), (3,b), (3,c)}

Page 4: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Subsets of the Cartesian Product Many of the results of operations on sets

produce subsets of the Cartesian Product set

Relational database Each column in a database table can be

considered a set Each row is an m-tuple of the elements from

each column or set No two rows should be alike

Page 5: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Using Matrices to Denote Cartesian Product For Cartesian Product of two sets, you can use a

matrix to find the sets. Example: Assume A = {1, 2, 3} and B = {a, b, c}.

The table below represents A × B.

a b c

1 (1, a) (1, b) (1, c)

2 (2, a) (2, b) (2, c)

3 (3, a) (3, b) (3, c)

Page 6: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Cardinality of Cartesian ProductThe cardinality of the Cartesian Product equals the product of the cardinality of all of the sets:

| A1 A2 … Am | = | A1 | | A2 | … | Am |

Page 7: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Subsets of the Cartesian Product Many of the results of operations on sets

produce subsets of the Cartesian Product set

Relational database Each column in a database table can be

considered a set Each row is an m-tuple of the elements from

each column or set No two rows should be alike

Page 8: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Introduction Given two sets X and B, its Cartesian product

XxY is the set of all ordered pairs (x,y) where xX and yY In symbols XxY = {(x, y) | xX and yY}

A binary relation R from a set X to a set Y is a subset of the Cartesian product XxY Example: X = {1, 2, 3} and Y = {a, b} R = {(1,a), (1,b), (2,b), (3,a)} is a relation between X

and Y

Page 9: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Domain and rangeGiven a relation R from X to Y, The domain of R is the set

Dom(R) = { xX | (x, y) R for some yY}

The range of R is the set Rng(R) = { yY | (x, y) R for some x X}

Example: if X = {1, 2, 3} and Y = {a, b} R = {(1,a), (1,b), (2,b)} Then: Dom(R)= {1, 2}, Rng(R) = (a, b}

Page 10: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Example of a relation Let X = {1, 2, 3} and Y = {a, b, c, d}. Define R = {(1,a), (1,d), (2,a), (2,b), (2,c)} The relation can be pictured by a graph:

Page 11: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Example A is a set of students and B is a set of

courses A relation R may be defined as “register

the course”

Paul Giblock R CSCI 2710

Danny Camper R CSCI 2710

Page 12: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Relation on a Single Set Example A is the set of all courses A relation R may be defined as the course

is a prerequisite CSCI 2150 R CSCI 3400 R = {(CSCI 2150, CSCI 3400), (CSCI 1710,

CSCI 2910), (CSCI 2800, CSCI 2910), …}

Page 13: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Matrix of a Relation We can represent a relation between two

finite sets with a matrix MR = [mij], where

1 if (ai, bj) R0 if (ai, bj) R

mij =

Page 14: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Example Using the previous example where A = {1, 2, 3}

and B = {a, b, c}. The matrix below represents the relation R = {(1, a), (1, c), (2, c), (3, a), (3, b)}.

a b c

1 1 0 1

2 0 0 1

3 1 1 0

Page 15: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Digraph of a Relation Let R be a relation on A We can represent R using a diagram

Each element of A is a circle called a vertex If ai is related to aj, then draw an arrow from

the vertex ai to the vertex aj

In degree means number of arrows coming into a vertex

Out degree means number of arrows coming out of a vertex

Page 16: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Representing a RelationThe following three representations depict the same relation on A = {1, 2, 3}.

R = {(1, 1), (1, 3), (2, 3), (3, 2), (3, 3)}

1 0 1

0 0 1

0 1 1

1

2

3

Page 17: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Properties of relations

Let R be a relation on a set X

i.e. R is a subset of the Cartesian product XxX

R is reflexive if (x,x) R for every xX R is symmetric if for all x, y X such that (x,y)

R then (y,x) R R is transitive if (x,y) R and (y,z) R imply

(x,z) R R is antisymmetric if for all x,yX such that

xy, if (x,y) R then (y,x) R

Page 18: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Partial Order RelationsLet X be a set and R a relation on X

R is a partial order on X if R is reflexive, anti-symmetric and transitive.

Page 19: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Inverse of a relationGiven a relation R from X to Y, its inverse R-1

is the relation from Y to X defined by

R-1 = { (y,x) | (x,y) R } Example: if R = {(1,a), (1,d), (2,a), (2,b), (2,c)}

then R -1= {(a,1), (d,1), (a,2), (b,2), (c,2)}

Page 20: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Equivalence relations

Let X be a set and R a relation on X

R is an equivalence relation on X R is reflexive, symmetric and transitive.

Page 21: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Equivalence classes

Let X be a set and let R be an equivalence relation on X. Let a X.

Define [a] ={ xX | xRa }

Page 22: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Matrices of relations Let X, Y be sets and R a relation from X to Y Write the matrix A = (aij) of the relation as

follows: Rows of A = elements of X Columns of A = elements of Y Element ai,j = 0 if the element of X in row i and

the element of Y in column j are not related Element ai,j = 1 if the element of X in row i and

the element of Y in column j are related

Page 23: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

The matrix of a relation (1)Example:

Let X = {1, 2, 3}, Y = {a, b, c, d}

Let R = {(1,a), (1,d), (2,a), (2,b), (2,c)}

The matrix A of the relation R is

A =

a b c d

1 1 0 0 1

2 1 1 1 0

3 0 0 0 0

Page 24: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

The matrix of a relation (2) If R is a relation from a set X to itself and A is the

matrix of R then A is a square matrix. Example: Let X = {a, b, c, d} and R = {(a,a),

(b,b), (c,c), (d,d), b,c), (c,b)}. Then

A =

a b c d

a 1 0 0 0

b 0 1 1 0

c 0 1 1 0

d 0 0 0 1

Page 25: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

The matrix of a relation on a set XLet A be the square matrix of a relation R from

X to itself. Let A2 = the matrix product AA. R is reflexive All terms aii in the main

diagonal of A are 1. R is symmetric aij = aji for all i and j,

i.e. R is a symmetric relation on X if A is a symmetric matrix

R is transitive whenever cij in C = A2 is nonzero then entry aij in A is also nonzero.

Page 26: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Relational databases

A binary relation R is a relation among two sets X and Y, already defined as R X x Y.

An n-ary relation R is a relation among n sets X1, X2,…, Xn, i.e. a subset of the Cartesian product, R X1 x X2 x…x Xn. Thus, R is a set of n-tuples (x1, x2,…, xn) where

xk Xk, 1 < k < n.

Page 27: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Databases

A database is a collection of records that are manipulated by a computer. They can be considered as n sets X1 through Xn, each of which contains a list of items with information.

Database management systems are programs that help access and manipulate information stored in databases.

Page 28: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Relational database model

Columns of an n-ary relation are called attributes An attribute is a key if no two entries have the

same value e.g. social security number

A query is a request for information from the database

Page 29: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Operators

The selection operator chooses n-tuples from a relation by giving conditions on the attributes

The projection operator chooses two or more columns and eliminates duplicates

The join operator manipulates two relations

Page 30: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Functions

A function f from X to Y (in symbols f : X Y) is a relation from X to Y such that Dom (f) = X and if two pairs (x , y) and (x , y’) f, then y = y’

E.g. Dom (f) = X = {a, b, c, d}, Range (f) = {1, 3, 5}f (a) = f (b) = 3, f (c) = 5, f (d) = 1.

Page 31: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Domain and Range Domain of f = X Range of f =

{ y | y = f (x) for some x X} A function f : X Y assigns to

each x in Dom (f) = X a unique element y in Range (f) Y.

Therefore, no two pairs in f have the same first coordinate.

Page 32: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

One-to-one functions A function f : X Y is one-to-one for each y Y there exists at most one x X

with f (x) = y. Alternative definition: f : X Y is one-to-one

for each pair of distinct elements x1, x2 X there exist two distinct elements y1, y2 Y such that f(x1) = y1 and f(x2) = y2.Examples: 1. The function f (x) = 2x from the set of real numbers to itself is

one-to-one 2. The function f : R R defined by f (x) = x2 is not one-to-one,

since for every real number x, f (x) = f (-x).

Page 33: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Onto functions

A function f : X Y is onto

for each y Y there exists at least one x X with f (x) = y, i.e. Range (f) = Y. Example: The function f (x) = ex from the set of real

numbers to itself is not onto Y = the set of all real numbers. However, if Y is restricted to Range (f) = R +, the set of positive real numbers, then f (x) is onto.

Page 34: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Bijective functions

A function f : X Y is Bijective

f is one-to-one and onto Examples:

1. A linear function f (x) = ax + b is a Bijective function from the set of real numbers to itself

2. The function f (x) = x3 is Bijective from the set of real numbers to itself.

Page 35: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Inverse function Given a function y = f (x), the inverse f -1 is the

set {(y, x) | y = f (x)}. The inverse f -1 of f is not necessarily a

function. Example: if f (x) = x2, then f -1 (4) = 4 = ± 2, not a

unique value and therefore f is not a function.

However, if f is a Bijective function, it can be shown that f -1 is a function.

Page 36: Discrete Mathematics Relation. Cartesian Product  If A 1, A 2, …, A m are nonempty sets, then the Cartesian Product of these sets is the set of all ordered

Composition of functions Given two functions g : X Y and f : Y Z,

the composition f ◦ g is defined as follows:

f ◦ g (x) = f( g (x)) for every x X. Example: g (x) = x2 -1, f (x) = 3x + 5. Then

f ◦ g (x) = f (g (x)) = f(3x + 5) = (3x + 5)2 - 1

Composition of functions is associative:

f ◦ (g ◦h) = (f ◦ g) ◦ h, But, in general, it is not commutative:

f ◦ g g ◦ f.