24
An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1 , x 2 , ..., x n , then we write the ordered n-tuple as <x 1 , x 2 , ..., x n > . Let A 1 , ..., A n be n sets. Then the set of all ordered n-tuples <x 1 , ..., x n > , where x i A i for all i, , is called the Cartesian product of A 1 , ..., A n , and is denoted by Two ordered n-tuples <x 1 , ..., x n > and <y 1 , ..., y n > are equal if and only if x i = y i for all i, 1 i n . For example the ordered 3-tuple <1, 2, 3> can be equal to only <1, 2, 3> and nothing else. It is not equal to the ordered n-tuple <2, 3, 1> for example. An ordered pair is a set of a pair of objects with an order associated with them. If objects are represented by x and y, then we write an ordered pair as <x, y> or <y, x>. In general <x, y> is different from <y, x>. The set of all ordered pairs <a, b>, where a is an element of A and b is an element of B, is called the Cartesian product of A and B and is denoted by Two ordered pairs <a, b> and <c, d> are equal if and only if a = c and b = d. . A ... A A n 2 1 B A n i 1

An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered

Embed Size (px)

Citation preview

Page 1: An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered

• An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x1, x2, ..., xn, then we write the ordered n-tuple as <x1, x2, ..., xn> .

• Let A1, ..., An be n sets. Then the set of all ordered n-tuples <x1, ..., xn> , where xi Ai for all i, , is called the Cartesian product of A1, ..., An, and is denoted by

• Two ordered n-tuples <x1, ..., xn> and <y1, ..., yn> are equal if and only if xi = yi for all i, 1 i n . For example the ordered 3-tuple <1, 2, 3> can be equal to only <1, 2, 3> and nothing else. It is not equal to the ordered n-tuple <2, 3, 1> for example.

• An ordered pair is a set of a pair of objects with an order associated with them. If objects are represented by x and y, then we write an ordered pair as <x, y> or <y, x>. In general <x, y> is different from <y, x>.

• The set of all ordered pairs <a, b>, where a is an element of A and b is an element of B, is called the Cartesian product of A and B and is denoted by

• Two ordered pairs <a, b> and <c, d> are equal if and only if a = c and b = d.

. A ...A A n21

B A

n i 1

Page 2: An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered

An n-ary relation on sets A1, ..., An is a set of ordered n-tuples <a1, ..., an> where ai is an element of Ai for all i, . Thus an n-ary relation on sets A1, ..., An is a subset of Cartesian product A1 ... An .

A binary relation from a set A to a set B is a set of ordered pairs <a, b> where a is an element of A and b is an element of B.

Let A and B be sets. A (binary) relation from A to B is a subset of . Given an ordered pair (x,y) in , x is related to y by R, written as x R y, if and only if, (x,y) is in R•x R y (x,y) R• x R y (x,y) R

BA BA

/

Let A = {0, 1, 2} and B = {1, 2, 3}. An element x A is related to an element y B if, and only if, x is less than y. Then

0 R 1 since 0 < 1 0 R 0 since 0 < 0 0 R 2 since 0 < 2 1 R 1 since 1 < 10 R 3 since 0 < 3 2 R 1 since 2 < 11 R 2 since 1 < 2 2 R 2 since 2 < 21 R 3 since 1 < 3Example 10.1.1 page 535, page 535 #2 , 3, page 572-573

/

//

/

/

//

/

n i 1

Page 3: An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered

Arrow diagram of a relationLet A = {1,2,3} and B = {1,3,,5} and define relations S and T from A to B as follows:For all (x, y) (x, y ) x < y T = {(2, 1), (2, 5)}.

BA

S

1

3

5

112233

SS

112233

113355

TT

Page 4: An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered

Let A and B be sets. A function F: A B is a relation that assigns to each x A a unique y B. We write y = f(x) and call y the value of f at x or the image of x under f. We also say that f maps x to y. The set A(input values) is called the domain of f. The set of all possible values of f(x) in B (the output value) is called the codomain or range of f. There is a difference between range and codomain. Range is smaller http://en.wikipedia.org/wiki/Codomain

Example 7.1.7 and 7.1.9 page 350, page 395page 354 # 2, 7

x F(x)

AB

Page 5: An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered

Arrow diagram of a relation and a function

This is a diagram of a relation but not of a function

This is a diagram of afunction

135

112233

A B

This is OK for a diagram of a function

A B

Page 6: An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered

DIGRAPH

A digraph is short for directed graph, and it is a diagram composed of points called vertices (nodes) and arrows called arcs going from a vertex to a vertex. For example the figure below is a digraph with 3 vertices and 4 arcs.

Digraph representation of binary relations A binary relation on a set can be represented by a digraph. Let R be a binary relation on a set A, that is R is a subset of Then the digraph, call it G, representing R can be constructed as follows:     1. The vertices of the digraph G are the elements of A, and     2. <x, y> is an arc of G from vertex x to vertex y if and only if <x, y> is in R.

Example: The less than relation R on the set of integers A = {1, 2, 3, 4} is the set {<1, 2> , <1, 3>, <1, 4>, <2, 3> , <2, 4> , <3, 4> } and it can be represented by the following digraph.

A A

Page 7: An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered

Graph terminology (a detour here)A digraph is short for directed graph and are graphs that have arrows added to each edge. The arrows show that the edge has a direction associated with it.In other words, it is a diagram composed of points called vertices (nodes) and arrows called arcs going from a vertex to a vertex. For example the figure below is a digraph with 3 vertices and 4 arcs.

In this figure the vertices are labeled with numbers 1, 2, and 3.

A digraph is an ordered pair of sets G = (V, A), where V is a set of vertices and A is a set of ordered pairs (called arcs) of vertices of V.

In the example given above, V = { 1, 2, 3 } , and A = { <1, 1>, <1, 2>, <1, 3>, <2, 3> } .

Page 8: An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered

Let R be a binary relation on a set A.1. R is reflexive iff, for all x A, x R x (x, x) R each element is related to

itself 2. R is symmetric iff, for all x, y A, if x R y then y R x for all x and y in A,

if (x, y) R then (y, x) R if any one element is related to any other element, then the second element is related to the first

3. R is transitive iff, for all x, y, z A, if x R y and y R z then x R z if (x, y), ( y, z) R then (x, z) R if any one element is related to a second and that second element is related to a third, then the first element is related to the third

Page 551, example 10.2.3-10.2.5, Page 589

A binary relation R on a set A is an equivalence relation if and only if (1) R is reflexive (2) R is symmetric, and (3) R is transitive.

Which of the relations in the above examples is an equivalence relation ?

Page 9: An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered

Let m and n be integers and let d be a positive integer. The notationis read as m is congruent to n modulo d and means that d | (m-n)

Symbolically d | (m-n)Example 10.3.2 page 559, page 598

EQUIVALENCE CLASSFor an equivalence relation R on a set A, the set of the elements of A that are related to an element, say a, of A is called the equivalence class of element a and it is denoted by [a]. Written symbolically, this definition becomes

Example 10.3.5 page 561, page 600Example: The set of integers equivalent to a number between 1 and 12 in the equivalence relation on hours in the clock are called an equivalence class. So for the equivalence relation of hours on a clock, equivalence classes are [1] = {1, 13, 25, ... } = {1+ 12n: n N} , [2] = {2, 14, 26, ... } = {2+ 12n: n N} , ........, where N is the set of natural numbers. There are altogether twelve of them.

) (mod dnm

a} R x |A {x ][ a

) (mod dnm

Page 10: An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered

Function is actually a special type of binary relation. A function, denote it by f, from a set A to a set B is a relation from A to B that satisfies

1. for each element a in A, there is an element b in B such that <a, b> is in the relation, and

2. if <a, b> and <a, c> are in the relation, then b = c . The set A in the above definition is called the domain of the function and B its

codomain or range

Function Types

one-to-one (injective) onto(surjective) Bijection or one-to-one correspondence

if and only if whenever

f(x) = f(y) , x = y OR

if and only element y of B, x in A such that  f(x) = y ,  that is,  f is onto if and only if  f( A ) = B .

if it is onto and one-to-one.

Example 7.3.1 page 371

Example 7.2.1 page 403

Appl: hash functions

Example 7.3.4 page 375

Example 7.2.4 page 408

Example 7.3.8 page 381

Example 7.2.8 page 413

y x , f(y) f(x)

Page 11: An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered

Inverse functions : Let f be a bijection from a set A to a set B. Then the function g is called the inverse function of f, and it is denoted by f -1 ,  if for every element y of B,  g(y) = x , where f(x) = y . Note that such an x is unique for each y because f is a bijection. Page 383, example 7.3.12

Example 7.2.12 page 416

If X and Y are sets and F: X Y is one–to–one and onto, then F-1: Y Xis also one-to-one and onto.Page 387, #35

#40 page 419

Page 12: An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered

• Given a relation R from a set A to a set B, R is a function iff

1. xA, yB, x R y

2. xA, y1,y2B, x R y1 x R y2 y1 = y2.

Example 1:

Is R a function?

No. (Cond 1)

No. (Cond 2)

Yes.

R = {(1,2)}

R A x BA

{1,2,3}

B

{1,2,3}

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

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

{1,2,3,4} {1,2,3} R = {(1,1),(2,2),(3,3)} No. (Cond 1)

{1,2,3} {1,2,3,4} R = {(1,1),(2,2),(3,3)} Yes.

Page 13: An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered

• Given a relation R from a set A to a set B, R is a function iff

1. xA, yB, x R y

2. xA, y1,y2B, x R y1 x R y2 y1 = y2.

Example 2: Let R Q x Z such that… What is the definition of rational #’s?

(i) x R y iff x = y.

Q: Is R a function?

A: No (1st Condition: ½ maps to nothing)

Q Z

½ ?

(ii) (a/b) R c iff a.b = c.

Q: Is R a function?

A: Yes

Page 14: An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered

• Given a relation R from a set A to a set B, R is a function iff

1. xA, yB, x R y

2. xA, y1,y2B, x R y1 x R y2 y1 = y2.

Example 3: Let R Z x Z such that…

(i) x R y iff y = x2.

Q: Is R a function?

A: Yes.

(ii) x R y iff x = y2.

Q: Is R a function?

A: No. (1st and 2nd Condition violated)

Z Z

3 ?

11

-1

Page 15: An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered

• Functions in real life:1. Hamming distance function (p351, p396).

2. Encoding/decoding functions (p351, p396).

3. Boolean functions (p352, p397).

4. A program is a function.

Page 16: An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered

Eg. 3: F Z x {0,1}, a F b iff (a is even b=1) (a is odd b=0)

• We usually use “f,g,h,F,G,H” to denote functions.

• If the relation f A x B is a function, we write it as:

f : A B

• If there is a way to compute yB from any given xA, we usually write ‘f(x)’ in place of ‘y’.

We will write it as:

Eg. 1: F Z x Z , x F y iff y = x2. ‘F’ is a function.

F : Z Z, F(x) = x2

We will write it as:

Eg. 2: F Z x Z , x F y iff y = x2 + 2x + 1

F : Z Z, F(x) = x2 + 2x + 1

F : Z {0,1}, F(x) =

1, if x is even

0, otherwise

Page 17: An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered

• The identity function on any given set, is a function that maps every element to itself.

idA : A A, xA, idA(x) = x

Page 18: An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered

Finite State Automata

Consider an example of a vending machine that dispenses pieces of candy costing 20 cents each. The machine accepts only nickels and dime and returns no change. As soon as the amount deposited equals or exceeds 20 cents, the machine releases a piece of candy. The next coin deposited starts the process all over again. Page 358, p746

5 5 cents

0 cents

15 15 cents

10 10 cents

20 20 or moreor morecents

dimedime

dimedime

dimedime

dimedime

dimedime

nickelnickelnickelnickel

nickelnickel

nickelnickel

nickelnickel

Page 19: An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered

INPUT

S

T

A

TE

5 10

0 5 10

5 10 15

10 15 20

15 20 20 or more

20 5 10

5 5 cents

0 cents

15 15 cents

10 10 cents

20 20 or moreor morecents

dimedime

dimedime

dimedime

dimedime

dimedime

nickelnickelnickelnickel

nickelnickel

nickelnickel

nickelnickel

Page 20: An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered

A finite state automaton is a quintuple <S,I,N, s0,F>; where: •S is a finite set of states; •I is a finite set of input symbols; •N is the next-state function delta:N:S X I->S; •s0 element of Q is the initial state; •F contained in S is the set of final states (or accepting states).

Page 21: An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered

Finite state automaton given by a state diagram

Consider the finite state automaton given by the transition diagram

Fill up the following table•What are the states of A?•What are the input symbols of A?•What is the initial state of A?•What are the accepting states of A?•Find N(s, 1)•Find the annotated next-state table For A

ss00 ss22ss11

11 11

00

00 0011

INPUT

S

T

A

T

E

Page 22: An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered

INPUT

S

T

A

T

E

0 1

->s0 s1 s0

s1 s1 s2

s2 s1 s0

Page 23: An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered

A finite state automaton given by an automated next state table•What are the states of A?•What are the input symbols of A?•What is the initial state of A?•What are the accepting states of A?•Find N(U, c)•Draw the transition diagram of A.

•Page 367 #1 b, c, 3•Page 760 #1 b, c, 3

INPUT

S

T

A

T

E

a b c

U Z Y Y

V V V V

Y Z V Y

Z Z Z Z

Page 24: An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered

Example of a deterministic Example of a deterministic finite state machinefinite state machine

The following The following exampleexample explains a deterministic explains a deterministic finite state machinefinite state machine with a with a binary alphabet, which determines if the input contains an even number of 0s. binary alphabet, which determines if the input contains an even number of 0s.

•The alphabet Σ = {0, 1} (the two binary digits) The alphabet Σ = {0, 1} (the two binary digits) •The The machinemachine has two states, has two states, SS11 and and SS22

•SS11 is both the start is both the start statestate and the only accepting and the only accepting statestate •The transition function The transition function TT is defined as follows: is defined as follows:

•TT((SS11, 0) = , 0) = SS22

•TT((SS11, 1) = , 1) = SS11

•TT((SS22, 0) = , 0) = SS11

•TT((SS22, 1) = , 1) = SS22

Simply put, the Simply put, the statestate SS11 represents that there has been an even number of 0s in the represents that there has been an even number of 0s in the

input so far, while input so far, while SS22 signifies an odd number. A 1 in the input does not change signifies an odd number. A 1 in the input does not change

the the statestate of the automaton. When the input ends, the of the automaton. When the input ends, the statestate will show whether the will show whether the input contained an even number of 0s or not. input contained an even number of 0s or not.