Presentation is loading. Please wait.

Presentation is loading. Please wait.

Set theory Sets: Powerful tool in computer science to solve real world problems. A set is a collection of distinct objects called elements. Traditionally,

Similar presentations


Presentation on theme: "Set theory Sets: Powerful tool in computer science to solve real world problems. A set is a collection of distinct objects called elements. Traditionally,"— Presentation transcript:

0 Set, Combinatorics, Probability & Number Theory
Mathematical Structures for Computer Science Chapter 3 Copyright © 2006 W.H. Freeman & Co. MSCS Slides Set, Combinatorics, Probability & Number Theory

1 Set theory Sets: Powerful tool in computer science to solve real world problems. A set is a collection of distinct objects called elements. Traditionally, sets are represented by capital letters, and elements by lower case letters. The symbol  means “belongs to” and is used to represent the fact that an element belongs to a particular set. Hence, aA means that element a belongs to set A. bA implies that b is not an element of A. Braces {} are used to indicate a set. A = {2, 4, 6, 8, 10} 3A and 2A Section 3.1 Sets

2 Set theory Ordering is not imposed on the set elements and no element is listed more than once. Two sets are equal if and only if they contain the same elements. In other words, A = B means (x)[(x  A  x  B) Λ (x  B  x  A)] Finite and infinite set: described by number of elements in a set Finite sets can be enumerated: e.g. {1, 4, 9, 16} or {Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday} Other descriptive methods are needed for infinite sets. Section 3.1 Sets

3 Set theory The elements in a set usually share some common characteristic so it’s often possible to describe a set’s members by describing its characteristic property. e.g. S = {x  x is a positive even integer} Sets can also be described using predicate notation: S = {x  P(x)} means (x)[(x  S  P(x)) Λ (P(x) x  S)] where P is the unary predicate. Hence, every element of S has the property P and everything that has a property P is an element of S. To summarize, sets can be described by Enumeration of all set elements Natural language description of set elements Predicate description of set elements Section 3.1 Sets

4 Set Theory Examples Describe each of the following sets by listing the elements: {x | x is a month with exactly thirty days} {April, June, September, November} {x | x is an integer and 4 < x < 9} {5, 6, 7, 8} What is the predicate for each of the following sets? {1, 4, 9, 16} {x | x is one of the first four perfect squares} {2, 3, 5, 7, 11, 13, 17, ….} {x | x is a prime number} Section 3.1 Sets

5 Set Theory Basics A set that has no members is called a null or empty set and is represented by  or {}. Note that  is different from {}. The latter is a set with 1 element, which is the empty set. Some notations used for convenience of defining sets N = set of all nonnegative integers (note that 0  N) Z = set of all integers Q = set of all rational numbers R = set of all real numbers C = set of all complex numbers Using the above notations and predicate symbols, one can describe sets quite easily A = {x | (y)[(y {0,1,2}) and (x = y2)]} Hence, A = {0,1, 4} A = {x | x  N and (y)(y  {2, 3, 4, 5}  x  y)} B = {x | (y)(z)(y  {1,2} and z  {2,3} and x = z – y) } Section 3.1 Sets

6 Open and closed interval
A = {x  R | -2 < x < 3} Denotes the set containing all real numbers between -2 and 3. This is an open interval, meaning that the endpoints -2 and 3 are not included. By all real numbers, we mean everything such as 1.05, -3/4, … (21/2) and every other real number within that interval. A = {x  R | -2  x  3} Similar set but on a closed interval It includes all the numbers in the open interval described above, plus the endpoints. Section 3.1 Sets

7 Relationships Between Sets
Say S is the set of all humans, M is the set of all male humans, and C is the set of all computer science students (also humans). M and C are both subsets of S, because all elements of M and C are also elements of S. M is not a subset of C, however, since there are elements of M that are not in C (specifically, all males who are not studying computer science). For sets M and S, M is a subset of S if, and only if, every element in M is also an element of S. Symbolically: M  S  (x), if x  M, then x  S. S = M if S  M and M  S If M  S and M  S, then there is at least one element of S that is not an element of M, and we say M is a proper subset of S. Symbolically, denoted by M  S Section 3.1 Sets

8 Relationship between Sets
A superset is the opposite of subset. If M is a subset of S, then S is a superset of M. Symbolically, denoted S  M. Likewise, if M is a proper subset of S, then S is a proper superset of M. Symbolically, denoted S  M. Cardinality of a set is simply the number of elements within the set. The cardinality of S is denoted by |S|. By the above definition of subset, it is clear that set M must have fewer members than S, which yields the following symbolic representation: S  M  |M| < |S| Section 3.1 Sets

9 Exercise A = {x | x  N and x  5}  {5, 6, 7, 8, 9, …… }
B = {10, 12, 16, 20} C = {x | (y)(y  N and x = 2y)}  {0, 2, 4, 6, 8, 10, …….} What statements are true? B  C B  A A  C {x | x  N and x < 20}  B {}  B   B Section 3.1 Sets

10 Set of Sets For the following sets, show that A  B.
A = { x | x  R such that x2 – 4x + 3 = 0} A = {1, 3} B = { x | x  N and 1 x  4} B = {1, 2, 3, 4} All elements of A exist in B, hence A  B. From every set, many subsets can be generated. A set S whose elements are all such subsets is called the power set, denoted by (S) For a set S = {1, 2, 3} ; (S) = { ,{1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}} For a set with n elements, the power set has 2n elements. Section 3.1 Sets

11 Set operations Binary and unary operators
Binary acts on two elements; e.g. x-y or y-x. Unary acts on a single element; e.g. negation of an element x is –x. Example: +, - and * are all binary operators on Z. An ordered pair of elements is written as (x,y) and is different from (y,x). Two ordered pairs (a,b) and (c,d) are equal if and only if a = c and b = d. If S = {2,3}, the ordered pairs of this set are (2,2), (2,3), (3,2), (3,3). Binary operation (represented by ) on a set defined as follows: If for every ordered pair (x,y) of elements of S, x  y exists, and is unique, and is a member of S. The fact that x  y exists, and is unique is the same as saying that the binary operation  is well-defined. The fact that x  y always belongs to S means that S is closed under the operation . The operator  is just a placeholder for a real operator like +, -, * etc. Section 3.1 Sets

12 Binary or unary operations
Which of the following are neither binary nor unary operations on the given sets? Why? x  y = x/y; S = set of all positive integers S is not closed under division (x/0 does not exist). x  y = x/y; S = set of all positive rational numbers x  y = xy; S = R 00 is not defined x  y = maximum of x and y; S = N x  y = x + y; S = set of Fibonacci numbers S is not closed under addition since, 1+3 = 4 and 4 is not a Fibonacci number Section 3.1 Sets

13 Operations on Sets New sets can be formed in a variety of ways, and can be described using both set builder notation and Venn diagrams. Let A, B  (S). The union of set A and B, denoted by A  B is the set that contains all elements in either set A or set B, i.e. A  B = {x | x  A or x  B}. The intersection of set A and B, denoted by A  B contain all elements that are common to both sets; i.e., A  B = {x | x  A and x  B} If A = { 1,3,5,7,9} and B = {3,7,9,10,15} ; A  B = {1, 3, 5, 7, 9, 10, 15} and A  B = {3, 7, 9}. Section 3.1 Sets

14 Disjoint, Universal and Difference Sets
Given set A and set B, if A  B = , then A and B are disjoint sets. In other words, there are no elements in A that are also in B. For a set A  (S), the complement of set A, denoted as ~A or A, is the set of all elements that are not in A. A = {x | x  S and x  A } The difference A - B is the set of elements in A that are not in B. This is also known as the complement of B relative to A. A - B = {x | x  A and x  B } or = {x | x  A and x  B } Note A – B = A  B  B – A Section 3.1 Sets

15 Class Exercise Let A = {1, 2, 3, 5, 10} B = {2, 4, 7, 8, 9}
be subsets of S = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}. Find A  B A – C B  (A  C) A  B  C (A  B)  C {1, 2, 3, 4, 5, 7, 8, 9, 10} {1, 2, 3} {1, 3, 5, 10} {} {1, 2, 3, 4, 7, 9} Section 3.1 Sets

16 Cartesian Product If A and B are subsets of S, then the cartesian product (cross product) of A and B denoted symbolically by A  B is defined by A  B = {(x,y) | x  A and y  B } The Cartesian product of 2 sets is the set of all combinations of ordered pairs that can be produced from the elements of both sets. Example, given 2 sets A and B, where A = {a, b, c} and B = {1, 2, 3}, the Cartesian product of A and B can be represented as A  B = {(a, 1), (a, 2), (a, 3), (b, 1), (b, 2), (b, 3), (c, 1), (c, 2), (c, 3)} Is A  B = B  A? Cross-product of a set with itself is represented as A  A or A2 An ordered n-tuple is a set of elements that is defined by the order in which the elements appear, and by the number of times which distinct elements appear. Example, the coordinates of points on a 3-d graph are ordered 3-tuples, where the first value must be the x coordinate, the second value must be the y coordinate, and the third value must be the z coordinate. An represents the set of all n-tuples (x1, x2, …, xn) of elements of A. Section 3.1 Sets

17 Basic Set Identities Given sets A, B, and C, and a universal set S and a null/empty set , the following properties hold: Commutative property (cp) A  B = B  A A  B = B  A Associative property (ap) A  (B  C) = (A  B)  C A  (B  C) = (A  B)  C Distributive properties (dp) A  (B  C) = (A  B)  (A  C) A  (B  C) = (A  B)  (A  C) Identity properties (ip)   A = A   = A S  A = A  S = A Complement properties (comp) A  A = S A  A =  Identities hold for all sets, regardless of their members, as long as all are member of the power set of S. Section 3.1 Sets

18 More set identities Idempotent Laws Absorption properties
Double Complement Law (A) = A Idempotent Laws A  A = A A  A = A Absorption properties A  (A  B) = A A  (A  B) = A Alternate Set Difference Representation A - B = A  B Inclusion in Union A  A  B B  A  B Inclusion in Intersection A  B  A A  B  B Transitive Property of Subsets if A  B, and B  C, then A  C Section 3.1 Sets

19 Exercise Use the set identities to prove
[A  (B  C)]  ([A  (B  C)]  (B  C)) =  Proof: [A  (B  C)]  ([A  (B  C)]  (B  C)) = ([A  (B  C)]  [A  (B  C)])  (B  C) using assoc property ([(B  C)  A]  [(B  C)  A])  (B  C) using comm twice [(B  C)  (A  A)]  (B  C) using distrib [(B  C)  ]  (B  C) using comp (B  C)  (B  C) using identity  using comp Section 3.1 Sets

20 Countable and Uncountable Sets
Elements in a finite set can be placed in some order to give a sequence: s1, s2, s3, …, sk for some integer k. The number of elements in a set is its cardinality; in this case, the cardinality is k. We say that we have put the set elements in one-to-one correspondence with the integers. Some infinite sets can also be arranged in order using the same method; choose a set element, arbitrarily call it the first element, and designate it as s1. Continue choosing elements and numbering them. These sets are said to be denumerable Finite and infinite sets that can be put in 1-1 correspondence with the integers are said to be countable. This doesn’t necessarily mean that we can actually find the total number of elements in the set; for infinite sets this is impossible. Not all infinite sets are countable, however, as we’ll see. Section 3.1 Sets

21 Countable Sets - Example
Prove that the set Q+ of positive rational numbers is countable. Assume that each positive rational number is written as a fraction of positive integers: 1/1 1/2 1/3 1/4 1/ /1 2/2 2/3 2/4 2/ 3/1 3/2 3/3 3/4 3/ 4/1 4/2 4/3 4/4 4/ Section 3.1 Sets

22 Countable Sets - Example
Now imagine drawing a line through the fractions as follows. Choose 1/1 as s1, the first element in the sequence. Now, draw a line from 1/1 to 2/1 and label that element s2. From 1/2 draw a line to 1/3 and make that s1 . From 1/3 draw the line through 2/2, 3/1, 4/1, 3/2, 2/3, 1/4, 1/5, and so on, labeling each element as you go. The enumeration then consists of all these elements, in the order they have been labeled, being sure to eliminate any fractions not in lowest terms. For example you would not include 2/2, 3/3, 4/4, or any other number that is = 1. 1/1 1/2 1/3 1/4 1/ /1 2/2 2/3 2/4 2/ 3/1 3/2 3/3 3/4 3/ 4/1 4/2 4/3 4/4 4/ Section 3.1 Sets

23 Uncountable Sets Some infinite sets are not countable; for example, the real numbers. Proof that the real numbers between 0 and 1 are uncountable can be found on page 200. We will primarily be concerned with countable sets, and in particular finite countable sets, since computers are only able to manipulate finite sets. Section 3.1 Sets


Download ppt "Set theory Sets: Powerful tool in computer science to solve real world problems. A set is a collection of distinct objects called elements. Traditionally,"

Similar presentations


Ads by Google