Presentation is loading. Please wait.

Presentation is loading. Please wait.

Discrete Structure Sets.

Similar presentations


Presentation on theme: "Discrete Structure Sets."— Presentation transcript:

1 Discrete Structure Sets

2 Set Theory Set: Collection of objects (“elements”)
aA “a is an element of A” “a is a member of A” aA “a is not an element of A” A = {a1, a2, …, an} “A contains…” Order of elements is meaningless It does not matter how often the same element is listed.

3 Sets Curly braces “{“ and “}” are used to denote sets.
Java note: In Java curly braces denote arrays, a data-structure with inherent ordering. Mathematical sets are unordered so different from Java arrays. Java arrays require that all elements be of the same type. Mathematical sets don’t require this, however. EG: { }

4 Standard Numerical Sets
The natural numbers: N = { 0, 1, 2, 3, 4, … } The integers: Z = { … -3, -2, -1, 0, 1, 2, 3, … } The positive integers: Z+ = {1, 2, 3, 4, 5, … } The real numbers: R --contains any decimal number of arbitrary precision The rational numbers: Q --these are decimal numbers whose decimal expansion repeats Q: Give examples of numbers in R but not Q.

5 Set Theory (a) Z=the set of integers={0,1,-1,2,-1,3,-3,...}
(b) N=the set of nonnegative integers or natural numbers (c) Z+=the set of positive integers (d) Q=the set of rational numbers={a/b| a,b is integer, b not zero} (e) Q+=the set of positive rational numbers (f) Q*=the set of nonzero rational numbers (g) R=the set of real numbers (h) R+=the set of positive real numbers (i) R*=the set of nonzero real numbers (j) C=the set of complex numbers

6 -Notation The Greek letter “” (epsilon) is used to denote that an object is an element of a set. When crossed out “” denotes that the object is not an element.” EG: 3  S reads: “3 is an element of the set S ”. Q: Which of the following are true: 3  R -3  N -3  R 0  Z+ x xR  x2=-5

7 Examples for Sets A =  or A={ } “empty set/null set”
A = {z} Note: zA, but z  {z} A = {{b, c}, {c, x, d}} A = {{x, y}} Note: {x, y} A, but {x, y}  {{x, y}} A = {x | P(x)} “set of all x such that P(x)” A = {x | xN  x > 7} = {8, 9, 10, …} “set builder notation”

8 Set Builder Notation Up to now sets have been defined using the curly brace notation “{ … }” or descriptively “the set of all natural numbers”. The set builder notation allows for concise definition of new sets. For example { x | x is an even integer } { 2x | x is an integer } are equivalent ways of specifying the set of all even integers.

9 Set Operations Union: AB = {x | xA  xB}
Example: A = {a, b}, B = {b, c, d} AB = {a, b, c, d} Intersection: AB = {x | xA  xB} AB = {b}

10 Set Builder Notation. Examples.
A1: U = N. { x | y (y  x ) } = { 0 } A2: U = Z. { x | y (y  x ) } = { } A3: U = Z. { x | y (y  R  y 2 = x )} = { 0, 1, 2, 3, 4, … } = N A4: U = Z. { x | y (y  R  y 3 = x )} = Z A5: U = R. { |x | | x  Z } = N A6: U = R. { |x | } = non-negative reals.

11 -Notation DEF: A set S is said to be a subset of the set T iff every element of S is also an element of T. This situation is denoted by S  T A synonym of “subset” is “contained by”. Definitions are often just a means of establishing a logical equivalence which aids in notation. The definition above says that: S  T  x (xS )  (xT ) We already had all the necessary concepts, but the “” notation saves work. Note that we don’t need to parenthesize x (xS )  (xT ) as x [(xS )  (xT )] because no other interpretation would result in a valid proposition. E.g. isn’t [x (xS )]  (xT ) valid because x remains an unbound variable. On the other hand x [ [ x (xS ) ]  (x T )] is a valid formula, though very confusing. L4

12 -Notation When “” is used instead of “”, proper containment is meant. A subset S of T is said to be a proper subset if S is not equal to T. Notationally: S  T  S T  x (x  S  xT ) Q: What algebraic symbol is  reminiscent of? L4

13 U B C A Subsets Useful rules: A = B  (A  B)  (B  A)
(A  B)  (B  C)  A  C (see Venn Diagram) U C B A

14 Elements in at least one of the two sets:
Union Elements in at least one of the two sets: AB = { x | x  A  x  B } U AB A B

15 Elements in exactly one of the two sets:
Intersection Elements in exactly one of the two sets: AB = { x | x  A  x  B } U A AB B

16 Disjoint Sets U A B DEF: If A and B have no common elements, they
are said to be disjoint, i.e. A B =  . U A B

17 Elements in first set but not second:
Set Difference Elements in first set but not second: A-B = { x | x  A  x  B } U A-B B A

18 Elements in exactly one of the two sets:
Symmetric Difference Elements in exactly one of the two sets: AB = { x | x  A  x  B } AB U A B

19 Elements not in the set (unary operator):
Complement Elements not in the set (unary operator): A = { x | x  A } U A A

20 Set Identities logical identities rewriting as follows:
Identity laws Domination laws Idempotent laws Double complementation Commutativity Associativity Distribuitivity DeMorgan logical identities rewriting as follows: disjunction “” becomes union “” conjunction “” becomes intersection “” negation “” becomes complementation “–” false “F” becomes the empty set  true “T” becomes the universe of reference U

21 Set Identities In fact, the logical identities create the set identities by applying the definitions of the various set operations. For example: LEMMA: (Associativity of Unions) (AB )C = A(B C ) Proof : (AB )C = {x | x  A B  x  C } (by def.) = {x | (x  A  x  B )  x  C } (by def.) = {x | x  A  ( x  B  x  C ) } (logical assoc.) = {x | x  A  (x  B  C ) } (by def.) = A(B C ) (by def.) Other identities are derived similarly.

22 Visual DeMorgan = L5

23 Cardinality The cardinality of a set is the number of distinct elements in the set. |S | denotes the cardinality of S. Q: Compute each cardinality. |{1, -13, 4, -13, 1}| |{3, {1,2,3,4}, }| |{}| |{ {}, {{}}, {{{}}} }|

24 Cardinality Hint: After eliminating the redundancies just look at the number of top level commas and add 1 (except for the empty set). A: |{1, -13, 4, -13, 1}| = |{1, -13, 4}| = 3 |{3, {1,2,3,4}, }| = 3. To see this, set S = {1,2,3,4}. Compute the cardinality of {3,S, } |{}| = || = 0 |{ {}, {{}}, {{{}}} }| = |{ , {}, {{}}| = 3 L4

25 Cardinality DEF: The set S is said to be finite if its cardinality is a nonnegative integer. Otherwise, S is said to be infinite. EG: N, Z, Z+, R, Q are each infinite. Note: We’ll see later that not all infinities are the same. In fact, R will end up having a bigger infinity-type than N, but surprisingly, N has same infinity-type as Z, Z+, and Q. L4

26 Set Theory U 5 A B 20 10 15 Counting and Venn Diagrams
In a class of 50 college freshmen, 30 are studying BASIC, 25 studying PASCAL, and 10 are studying both. How many freshmen are studying either computer language? U 5 A B 20 10 15

27 Set Theory Counting and Venn Diagrams B Defect types of an AND gate:
D1: first input stuck at 0 D2: second input stuck at 0 D3: output stuck at 1 12 4 11 43 3 7 5 A 15 C Given 100 samples set A: with D1 set B: with D2 set C: with D3 with |A|=23, |B|=26, |C|=30, , how many samples have defects? Ans:57

28 Power Set DEF: The power set of S is the set of all subsets of S.
Denote the power set by P (S ) or by 2s . The latter weird notation comes from the following. Lemma: | 2s | = 2|s| We’ll prove this lemma later.

29 Power Set –Example To understand the previous fact consider
Enumerate all the subsets of S : 0-element sets: {} 1-element sets: {1}, {2}, {3} +3 2-element sets: {1,2}, {1,3}, {2,3} +3 3-element sets: {1,2,3} +1 Therefore: | 2s | = 8 = 23 = 2|s| Why is this not a proof of the lemma on previous page?

30 Cartesian Product The most famous example of 2-tuples are points in the Cartesian plane R2. Here ordered pairs (x,y) of elements of R describe the coordinates of each point. We can think of the first coordinate as the value on the x-axis and the second coordinate as the value on the y-axis. DEF: The Cartesian product of two sets A and B –denoted by A B– is the set of all ordered pairs (a, b) where aA and bB . Q: Describe R2 as the Cartesian product of two sets.

31 | A1  A2  … An | = |A1||A2| … |An|
Cartesian Product A: A = {1,2}, B = {3,4}, C = {5,6,7} A B C = { (1,3,5), (1,3,6), (1,3,7), (1,4,5), (1,4,6), (1,4,7), (2,3,5), (2,3,6), (2,3,7), (2,4,5), (2,4,6), (2,4,7) } Lemma: The cardinality of the Cartesian product is the product of the cardinalities: | A1  A2  … An | = |A1||A2| … |An| Q: What does S equal?

32 Set Operations and the Laws of Set Theory

33 Set Operations and the Laws of Set Theory

34 Discrete Mathematics and its Applications
Generalized Union Binary union operator: AB n-ary union: AA2…An : ((…((A1 A2) …) An) (grouping & order is irrelevant) “Big U” notation: Or for infinite sets of sets: (c) , Michael P. Frank

35 Generalized Intersection
Discrete Mathematics and its Applications Generalized Intersection Binary intersection operator: AB n-ary intersection: AA2…An((…((A1A2)…)An) (grouping & order is irrelevant) “Big Arch” notation: Or for infinite sets of sets: (c) , Michael P. Frank

36 Discrete Mathematics and its Applications
Mutual subsets Example: Show A(BC)=(AB)(AC). Show A(BC)(AB)(AC). Assume xA(BC), & show x(AB)(AC). We know that xA, and either xB or xC. Case 1: xB. Then xAB, so x(AB)(AC). Case 2: xC. Then xAC , so x(AB)(AC). Therefore, x(AB)(AC). Therefore, A(BC)(AB)(AC). Show (AB)(AC)  A(BC). … (c) , Michael P. Frank

37 Membership Table Exercise
Discrete Mathematics and its Applications Membership Table Exercise Prove (AB)C = (AC)(BC). (c) , Michael P. Frank

38 Ordered n-tuples Notationally, n-tuples look like sets except that curly braces are replaced by parentheses: ( 11, 12 ) –a 2-tuple aka ordered pair ( , , ) –a 3-tuple ( , , , 11, Leo ) –a 5-tuple Java: n -tuples are similar to Java arrays “{…}”, except that type-mixing isn’t allowed in Java. As opposed to sets, repetition and ordering do matter with n-tuples. (11, 11, 11, 12, 13)  ( 11, 12, 13 ) ( , , )  ( , , )

39 Exercises Question 1: Given a set A = {x, y, z} and a set B = {1, 2, 3, 4}, what is the value of | 2A  2B | ? Question 2: Is it true for all sets A and B that (AB)(BA) =  ? Or do A and B have to meet certain conditions? Question 3: For any two sets A and B, if A – B =  and B – A = , can we conclude that A = B? Why or why not?

40 Blackboard Exercise Prove the following:
If A  B and B  C then A  C .

41 Set Theory

42 Relations Discrete Structure

43 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

44 Relations as Subsets of Cartesian Products
DEF: Let A1, A2, … , An be sets. An n-ary relation on these sets (in this order) is a subset of A1×A2× … ×An. Most of the time we consider n = 2 in which case have a binary relation and also say the the relation is “from A1 to A2”. With this terminology, all functions are relations, but not vice versa. Q: What additional property ensures that a relation is a function?

45 Relations and Functions
1 to 1 many to many 1 to many

46 Relations When (a, b) belongs to R, a is said to be related to b by R.
Example: Let P be a set of people, C be a set of cars, and D be the relation describing which person drives which car(s). P = {Ahmed, Youstina, Hassan, Aya}, C = {Mercedes, BMW, Toktok} D = {(Ahmed, Mercedes), (Youstina, Mercedes), (Hassan, BMW), (Aya, Toktok)}

47 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: The union R S The intersection R  S The symmetric difference R S The difference R-S The complement R L22

48 Representing Relations Using Digraphs
Example: Display the digraph with V = {a, b, c, d}, E = {(a, b), (a, d), (b, b), (b, d), (c, a), (c, b), (d, b)}. a b d c An edge of the form (b, b) is called a loop.

49 Relations on a Set Solution: R = { (1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)} 1 1 R 1 2 3 4 X X X 2 2 X X 3 3 X 4 4

50 (3,2)  < , <(3,2) = 0 , (3 < 2) = 0
Binary Relations A: boolean R(int a, int b, int c){ return (a + b) % 2 == c; } For binary relations, often use infix notation aRb instead of prefix notation R (a,b). EG: R = “<”. Thus can express the fact that 3 isn’t less than two with following equivalent (and confusing) notation: (3,2)  < , <(3,2) = 0 , (3 < 2) = 0

51 Properties of Binary Relations
A: Square. Special properties for relation on a set A: reflexive : every element is self-related. I.e. aRa for all a A symmetric : order is irrelevant. I.e. for all a,b A aRb iff bRa transitive : when a is related to b and b is related to c, it follows that a is related to c. I.e. for all a,b,c A aRb and bRc implies aRc Q: Which of these properties hold for: 1) “Siblinghood” 2) “<” 3) “”

52 Properties of Relations
We will now look at some useful ways to classify relations. Definition: A relation R on a set A is called reflexive if (a, a)R for every element aA. Are the following relations on {1, 2, 3, 4} reflexive? R = {(1, 1), (1, 2), (2, 3), (3, 3), (4, 4)} No. R = {(1, 1), (2, 2), (2, 3), (3, 3), (4, 4)} Yes. R = {(1, 1), (2, 2), (3, 3)} No.

53 Closures of Relations Example I: Find the reflexive closure of relation R = {(1, 1), (1, 2), (2, 1), (3, 2)} on the set A = {1, 2, 3}. Solution: We know that any reflexive relation on A must contain the elements (1, 1), (2, 2), and (3, 3). By adding (2, 2) and (3, 3) to R, we obtain the reflexive relation S, which is given by S = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 2), (3, 3)}. S is reflexive, contains R, and is contained within every reflexive relation that contains R. Therefore, S is the reflexive closure of R.

54 Properties of Relations
Definition: A relation R on a set A is called transitive if whenever (a, b)R and (b, c)R, then (a, c)R for a, b, cA. Are the following relations on {1, 2, 3, 4} transitive? R = {(1, 1), (1, 2), (2, 2), (2, 1), (3, 3)} Yes. R = {(1, 3), (3, 2), (2, 1)} No. R = {(2, 4), (4, 3), (2, 3), (4, 1)} No.

55 Closures of Relations Example II: Find the symmetric closure of the relation R = {(a, b) | a > b} on the set of positive integers. Solution: The symmetric closure of R is given by RR-1 = {(a, b) | a > b}  {(b, a) | a > b} = {(a, b) | a  b}

56 Closures of Relations Example III: Find the transitive closure of the relation R = {(1, 3), (1, 4), (2, 1), (3, 2)} on the set A = {1, 2, 3, 4}. Solution: R would be transitive, if for all pairs (a, b) and (b, c) in R there were also a pair (a, c) in R. If we add the missing pairs (1, 2), (2, 3), (2, 4), and (3, 1), will R be transitive? No, because the extended relation R contains (3, 1) and (1, 4), but does not contain (3, 4). By adding new elements to R, we also add new requirements for its transitivity. We need to look at paths in digraphs to solve this problem.

57 Relations Revisited: Properties of Relations
Define the relation R on the set Z+ by aRb if a exactly divides b. Then R is transitive, reflexive, but not symmetric (2R6, but not 6R2)

58 Equivalence Relations
Example: Suppose that R is the relation on the set of strings that consist of English letters such that aRb if and only if l(a) = l(b), where l(x) is the length of the string x. Is R an equivalence relation? Solution: R is reflexive, because l(a) = l(a) and therefore aRa for any string a. R is symmetric, because if l(a) = l(b) then l(b) = l(a), so if aRb then bRa. R is transitive, because if l(a) = l(b) and l(b) = l(c), then l(a) = l(c), so aRb and bRc implies aRc. R is an equivalence relation.

59 Inverting Relations Relational inversion amounts to just reversing all the tuples of a binary relation. DEF: If R is a relation from A to B, the composite of R is the relation R -1 from B to A defined by setting cR -1a if and only aRc. Q: Suppose R defined on N by: xRy iff y = x 2. What is the inverse R -1 ?

60 Inverting Relations A: xRy iff y = x 2.
R is the square function so R -1 is sqaure root: i.e. the union of the two square-root branches. I.e: yR -1x iff y = x 2 or in terms of square root: xR -1y iff y = ±x where x is non-negative

61 (2, 4), (3, 3), (3, 4), (4, 2), (4, 3), (4, 4)} Combining Relations
Example: Let D and S be relations on A = {1, 2, 3, 4}. D = {(a, b) | b = 5 - a} “b equals (5 – a)” S = {(a, b) | a < b} “a is smaller than b” D = {(1, 4), (2, 3), (3, 2), (4, 1)} S = {(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)} SD = { (2, 4), (3, 3), (3, 4), (4, 2), (4, 3), (4, 4)} D maps an element a to the element (5 – a), and afterwards S maps (5 – a) to all elements larger than (5 – a), resulting in SD = {(a,b) | b > 5 – a} or SD = {(a,b) | a + b > 5}.

62 Combining Relations Another Example: Let X and Y be relations on A = {1, 2, 3, …}. X = {(a, b) | b = a + 1} “b equals a plus 1” Y = {(a, b) | b = 3a} “b equals 3 times a” X = {(1, 2), (2, 3), (3, 4), (4, 5), …} Y = {(1, 3), (2, 6), (3, 9), (4, 12), …} XY = { (1, 4), (2, 7), (3, 10), (4, 13), …} Y maps an element a to the element 3a, and afterwards X maps 3a to 3a + 1. XY = {(a,b) | b = 3a + 1}

63 Digraph Representation
1 1 2 2 3 3 4 4 A: 2 1 3 4

64 Databases and Relations
Example: Consider a database of students, whose records are represented as 4-tuples with the fields Student Name, ID Number, Major, and GPA: R = {(Ackermann, , CS, 3.88), (Adams, , Physics, 3.45), (Chou, , CS, 3.79), (Goodfriend, , Math, 3.45), (Rao, , Math, 3.90), (Stevens, , Psych, 2.99)} Relations that represent databases are also called tables, since they are often displayed as tables.

65 Database Operations Many more operations are useful for databases. We’ll study 2 of these: Join: a generalization of intersection as well as Cartesian product. Projection: restricting to less coordinates.

66 Join The join of two relations R, S is the combination of the relations with respect to the last few types of R and the first few types of S (assuming these types are the same). The result is a relation with the special types of S the common types of S and R and the special types of R.

67 Join EG: Suppose R is mod 2 addition and S is mod 2 multiplication:
In the 2-join we look at the last two coordinates of R and the first two coordinates of S. When these are the same we join the coordinates together and keep the information from R and S. For example, we generate an element of the join as follows: (0,1,1) 2-join (0,1,1,1) (1,1,1) L22

68 Join R = { (0,0,0), (0,1,1), (1,0,1), (1,1,0) } S = { (0,0,0), (0,1,0), (1,0,0), (1,1,1) } We use the notation J2(R,S) for the 2-join. J2(R,S) = { (0,0,0,0), (0,1,1,1), (1,0,1,0), (1,1,0,0) } Q: For general R,S, what does each of the following represent? J0(R,S) Jn(R,S) assuming n is the number of coordinates for both R and S.

69 Projection Projection is a “forgetful” operation. You simply forget certain unmentioned coordinates. EG, consider R again: R = { (0,0,0), (0,1,1), (1,0,1), (1,1,0) } By projecting on to the 1st and 3rd coordinates, we simply forget the 2nd coordinate. we generate an element of the 1,3 projection as follows: 1,3 projection (0,1,1) (0,1) L22

70 Projection R = { (0,0,0), (0,1,1), (1,0,1), (1,1,0) }
We use the notation P1,3(R) for 1,3 projection. P1,3(R) = { (0,0), (0,1), (1,1),(1,0) }

71 Relations Blackboard Exercises
1. Define the relation R by setting R(a,b,c) = “ab = c“ with a,b,c non-negative integers. Describe in English what P1,3 (R ) represents. 2. Define composition in terms of projection and join.

72 Functions Discrete Structure

73 Functions. Basic-Terms.
DEF: A function f : A B is given by a domain set A, a codomain set B, and a rule which for every element a of A, specifies a unique element f (a) in B. f (a) is called the image of a, while a is called the pre-image of f (a). The range (or image) of f is defined by f (A) = {f (a) | a  A }. L6

74 Functions Let us take a look at the function f:PC with
P = {Linda, Max, Kathy, Peter} C = {Boston, New York, Hong Kong, Moscow} f(Linda) = Moscow f(Max) = Boston f(Kathy) = Hong Kong f(Peter) = New York Here, the range of f is C.

75 Functions. Basic-Terms.
f : Z  R is given by f (x ) = x 2 A1: domain is Z, co-domain is R A2: image of -3 = f (-3) = 9 A3: pre-images of 3: none as 3 isn’t an integer! pre-images of 4: -2 and 2 A4: range is the set of perfect squares f (Z) = {0,1,4,9,16,25,…} L6

76 One-to-One, Onto, Bijection. Intuitively.
Represent functions using “node and arrow” notation: One-to-One means that no clashes occur. BAD: a clash occurred, not 1-to-1 GOOD: no clashes, is 1-to-1 Onto means that every possible output is hit BAD: 3rd output missed, not onto GOOD: everything hit, onto L6

77 One-to-One, Onto, Bijection. Intuitively.
Bijection means that when arrows reversed, a function results. Equivalently, that both one-to-one’ness and onto’ness occur. BAD: not 1-to-1. Reverse over-determined: BAD: not onto. Reverse under-determined: GOOD: Bijection. Reverse is a function: L6

78 Properties of Functions
Linda Boston Is f injective? Yes. Is f surjective? Is f bijective? Max New York Kathy Hong Kong Peter Moscow Helena Lübeck

79 One-to-One, Onto, Bijection. Formal Definition.
DEF: A function f : A B is: one-to-one (or injective) if different elements of A always result in different images in B. onto (or surjective) if every element in B is hit by f. I.e., f (A ) = B. a one-to-one correspondence (or a bijection, or invertible) if f is both one-to-one as well as onto. If f is invertible, its inverse f -1 : B A is well defined by taking the unique element in the pre-image of b, for each b  B. Alternate definitions using cardinality of pre-image: Injective: |f -1(b)| ≤ 1 for all b  B. Surjective: |f -1(b)|≥ 1 for all b  B. Bijective: |f -1(b)| = 1 for all b  B. L6

80 One-to-One, Onto, Bijection. Examples.
f : Z  R, f (x ) = x 2: none f : Z  Z, f (x ) = 2x : 1-1 f : R  R, f (x ) = x 3: 1-1, onto, bijection, inverse is f (x ) = x (1/3) f : Z  N, f (x ) = |x |: onto f (x ) = the father of x : none L6

81 Composition When a function f spits out elements of the same kind that another function g eats, f and g may be composed by letting g immediately eat each output of f. DEF: Suppose that g : A  B and f : B  C are functions. Then the composite f g : A  C is defined by setting f g (a) = f ( g (a) ) L6

82 Composition. Examples. Q: Compute g f where
1. f : Z  R, f (x ) = x 2 and g : R  R, g (x ) = x 3 2. f : Z  Z, f (x ) = x + 1 and g = f -1 so g (x ) = x – 1 3. f : {people}  {people}, f (x ) = the father of x, and g = f L6

83 Composition. Examples. 1. f : Z  R, f (x ) = x 2
and g : R  R, g (x ) = x 3 f g : Z  R , f g (x ) = x 6 2. f : Z  Z, f (x ) = x + 1 and g = f -1 f g (x ) = x (true for any function composed with its inverse) 3. f : {people}  {people}, f (x ) = g(x ) = the father of x f g (x ) = grandfather of x from father’s side L6

84 Composition Example: f(x) = 7x – 4, g(x) = 3x, f:RR, g:RR
(fg)(5) = f(g(5)) = f(15) = 105 – 4 = 101 (fg)(x) = f(g(x)) = f(3x) = 21x - 4

85 Ceiling and Floor DEF: Given a real number x : The floor of x is the biggest integer which is smaller or equal to x The ceiling of x is the smallest integer greater or equal to x. NOTATION: floor(x) = x , ceiling(x) = x  Q: Compute 1.7, -1.7, 1.7, -1.7.

86 Ceiling and Floor A: 1.7 = 1, -1.7 = -2, 1.7 = 2, -1.7 = -1
Q: What’s the difference between the floor function and the (int) casting function in Java? L6

87 a0=0 a1=2 an a2=6 an-1 a3=12 a4=20 a2 a1 a0

88 Recursive Definitions
F(0) = 0; F(n + 1) = F(n) + 1; F(0) = 1; F(n + 1) = 2  F(n); F(0) = 1; F(n + 1) = 2F(n)

89 The First-Order Linear Recurrence Relation
There are many sequences that satisfy For example, 5,15,45,135,... or 7,21,63,189,.... To pinpoint the particular sequence described, we need to know one of the terms of the sequence. (boundary condition, or initial condition since usually a0 is specified)

90 nonhomogeneous linear recurrence relation
The First-Order Linear Recurrence Relation nonhomogeneous linear recurrence relation Ex time complexity of bubble sort algorithm an=an-1+(n-1), n>1, a1=0, where an=the number of comparisons to sort n numbers an- an-1= n-1 an-1- an-2= n-2 an-2- an-3= n-3 a2- a1= 1 + an = (n-1)=(n2-n)/2

91 The Second-Order Linear Homogeneous Recurrence Relation
with Constant Coefficients Be careful not to draw conclusions from a few (or even, perhaps, many) particular instances. Ex Arrange pennies contiguously in each row where each penny above the bottom row touches two pennies in the row below it. a1=1,a2=1,a3=2,a4=3,a5=5,a6=8,... Is an=Fn? NO

92 Sequences DEF: Given a set S, an (infinite) sequence in S is a function N  S. Symbolically, a sequence is represented using the subscript notation ai . This gives a way of specifying formulaically Note: Other sets can be taken as ordering models. Q: Give the first 5 terms of the sequence defined by the formula

93 Sequence Examples A: Plug in for i in sequence 0, 1, 2, 3, 4:
Formulas for sequences often represent patterns in the sequence. Q: Provide a simple formula for each sequence: 3,6,11,18,27,38,51, … 0,2,8,26,80,242,728,… 1,1,2,3,5,8,13,21,34,…

94 Sequence Examples A: Try to find the patterns between numbers.
3,6,11,18,27,38,51, … a1=6=3+3, a2=11=6+5, a3=18=11+7, … and in general ai +1 = ai +(2i +3). This is actually a good enough formula. Later we’ll learn techniques that show how to get the more explicit formula: ai = 6 + 4(i –1) + (i –1)2 b) 0,2,8,26,80,242,728,… If you add 1 you’ll see the pattern more clearly. ai = 3i –1 1,1,2,3,5,8,13,21,34,… This is the famous Fibonacci sequence given by ai +1 = ai + ai-1 L6

95 Definition of Finite Automaton
The finite automaton has 5-tuple (Q, ∑, δ, q0, F) Q is a set of states ∑ is a set of input alphabet δ is a transition function or rule for moving q0 is a start state F is a set of accept states

96 Finite automaton 1 q1 q2 q3 1 0, 1 If the input is: & 0100 & & & What is the outputs?

97 The finite automaton M is (Q, ∑, δ, q0, F) Where Q = {q1, q2, q3}
1 q1 q2 q3 1 0, 1 The finite automaton M is (Q, ∑, δ, q0, F) Where Q = {q1, q2, q3} ∑ = {0, 1} q0 is the state q1 F = {q2}

98 q1 q2 q3 1 0, 1 δ is describes as 0 1 q1 q1 q2 q2 q3 q2 q3 q2 q2

99 Example s a b a b q1 r1 b a a b r2 a q2 b

100 For the start state, is even because it is possible to input 0 so far
1 qodd qodd qeven 1 For the start state, is even because it is possible to input 0 so far For the accept state, we consider qodd because we want to test odd numbers

101 Example a q2 b q1 a, b a q3 The inputs a, b, baba, baa, bbb, 

102 Anatomy of a Deterministic Finite Automaton
0,1 1 accept states (F) states q1 q0 q2 The machine accepts a string if the process ends in a double circle start state (q0) q3

103 Anatomy of a Deterministic Finite Automaton
0,1 1 q0 q1 q2 q3 The alphabet of a finite automaton is the set where the symbols come from: {0,1} The language of a finite automaton is the set of strings that it accepts

104  : Q  Σ → Q transition function*
M = (Q, Σ, , q0, F) where Q = {q0, q1, q2, q3} Σ = {0,1}  : Q  Σ → Q transition function* q0  Q is start state F = {q1, q2}  Q accept states q2 0,1 1 q0 q1 q3 M * 1 q0 q1 q2 q3

105 Quiz Prove that Write in logic Write ADJ matrix for graph
((P ᵛ Q) ʌ ( - P ᵛ R))  (Q ᵛ R) Write in logic The difference of two negative integers need not be positive Write ADJ matrix for graph


Download ppt "Discrete Structure Sets."

Similar presentations


Ads by Google