Set Operations CS 202, Spring 2008 Epp, chapter 5.

Slides:



Advertisements
Similar presentations
CS 202, Spring 2007 Epp, chapter 5 Aaron Bloomfield
Advertisements

 Union  Intersection  Relative Complement  Absolute Complement Likened to Logical Or and Logical And Likened to logical Negation.
Types of Logic Circuits
Copyright © Cengage Learning. All rights reserved.
Sets Lecture 11: Oct 24 AB C. This Lecture We will first introduce some basic set theory before we do counting. Basic Definitions Operations on Sets Set.
Discrete Mathematics Lecture 5 Alexander Bukharovich New York University.
Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
(CSC 102) Discrete Structures Lecture 14.
Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
1 Section 1.7 Set Operations. 2 Union The union of 2 sets A and B is the set containing elements found either in A, or in B, or in both The denotation.
Discrete Mathematics Lecture 4 Harper Langston New York University.
Discrete Structures Chapter 3 Set Theory Nurul Amelina Nasharuddin Multimedia Department.
Copyright © Zeph Grunschlag, Set Operations Zeph Grunschlag.
Discrete Mathematics Lecture 5
Sets 1.
Sets 1.
1 Set Operations CS/APMA 202, Spring 2005 Rosen, section 1.7 Aaron Bloomfield.
Rosen 1.6. Approaches to Proofs Membership tables (similar to truth tables) Convert to a problem in propositional logic, prove, then convert back Use.
Operations on Sets – Page 1CSCI 1900 – Discrete Structures CSCI 1900 Discrete Structures Operations on Sets Reading: Kolman, Section 1.2.
Set Theory A B C.
Set Notation.
Set theory Sets: Powerful tool in computer science to solve real world problems. A set is a collection of distinct objects called elements. Traditionally,
A Brief Summary for Exam 1 Subject Topics Propositional Logic (sections 1.1, 1.2) –Propositions Statement, Truth value, Proposition, Propositional symbol,
1 Sets CS 202, Spring 2007 Epp, chapter 5 Aaron Bloomfield.
Chapter 3 – Set Theory  .
Set, Combinatorics, Probability & Number Theory Mathematical Structures for Computer Science Chapter 3 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Set,
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 15-1 Mälardalen University 2012.
CS 103 Discrete Structures Lecture 10 Basic Structures: Sets (1)
Chapter 7 Logic, Sets, and Counting Section 2 Sets.
CS201: Data Structures and Discrete Mathematics I
CompSci 102 Discrete Math for Computer Science
1 Computability CS 101E Spring 2007 Michele Co. 2 So Far In Class We’ve seen the following programming constructs –if, if-else, if-else-if –switch –for.
Fall 2008/2009 I. Arwa Linjawi & I. Asma’a Ashenkity 11 Basic Structure : Sets, Functions, Sequences, and Sums Sets Operations.
Chapter 2 With Question/Answer Animations. Section 2.1.
Discrete Mathematics SETS. What is a set? ^A set is a unordered collection of “objects”  People in a class: {A yşe, B arış, C anan }  Cities in Turkey.
1 Turing’s Thesis. 2 Turing’s thesis: Any computation carried out by mechanical means can be performed by a Turing Machine (1930)
Based on slides by Patrice Belleville and Steve Wolfman CPSC 121: Models of Computation Unit 11: Sets.
Based on slides by Patrice Belleville and Steve Wolfman CPSC 121: Models of Computation Unit 11: Sets.
Module #3 - Sets 3/2/2016(c) , Michael P. Frank 2. Sets and Set Operations.
Set Operations Section 2.2.
Chapter 2 1. Chapter Summary Sets (This Slide) The Language of Sets - Sec 2.1 – Lecture 8 Set Operations and Set Identities - Sec 2.2 – Lecture 9 Functions.
Introduction to Set Theory (§1.6) A set is a new type of structure, representing an unordered collection (group, plurality) of zero or more distinct (different)
CPCS 222 Discrete Structures I
Sets, Permutations, and Combinations. Lecture 4-1: Sets Sets: Powerful tool in computer science to solve real world problems. A set is a collection of.
Dr. Ameria Eldosoky Discrete mathematics
Applied Discrete Mathematics Week 1: Logic and Sets
Discrete Mathematics Lecture 3 (and 4)
Copyright © Zeph Grunschlag,
Set Theory.
Discrete Structures – CNS 2300
Set, Combinatorics, Probability & Number Theory
Week 7 - Monday CS322.
Chapter 1 Logic and Proofs Homework 2 Given the statement “A valid password is necessary for you to log on to the campus server.” Express the statement.
Chapter 5, Set Theory 1.
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 2 Sets Slides are adopted from “Discrete.
Sets Set Identities Sets and propositional logic have some similar properties In fact both are forms of boolean algebra Compare Set Identities table (p.
Exercises Show that (P  Q)  (P)  (Q)
CS100: Discrete structures
Set Theory A B C.
Set Operations Section 2.2.
Session – 2 SETS & Operations of SETS
Set-Builder Notation.
Sets, Sequences, and Summations
Formal Languages, Automata and Models of Computation
L5 Set Operations.
MCS680: Foundations Of Computer Science
Chapter 7 Logic, Sets, and Counting
Chapter 1 Introduction to the Theory of Computation
Logic Logic is a discipline that studies the principles and methods used to construct valid arguments. An argument is a related sequence of statements.
CSC102 - Discrete Structures (Discrete Mathematics) Set Operations
Presentation transcript:

Set Operations CS 202, Spring 2008 Epp, chapter 5

Sets of Colors Monitor gamut (M) Printer gamut (P) Pick any 3 “primary” colors Triangle shows mixable color range (gamut) – the set of colors

Set operations: Union 1 Monitor gamut (M) A union of the sets contains all the elements in EITHER set Union symbol is usually a U Example: C = M U P Printer gamut (P)

Set operations: Union 2 A U B U A B

Set operations: Union 3 Formal definition for the union of two sets: A U B = { x | x  A or x  B } Further examples {1, 2, 3} U {3, 4, 5} = {1, 2, 3, 4, 5} {New York, Washington} U {3, 4} = {New York, Washington, 3, 4} {1, 2} U  = {1, 2}

Set operations: Union 4 Properties of the union operation A U  = A Identity law A U U = U Domination law A U A = A Idempotent law A U B = B U A Commutative law A U (B U C) = (A U B) U C Associative law

Set operations: Intersection 1 Monitor gamut (M) An intersection of the sets contains all the elements in BOTH sets Printer gamut (P) Intersection symbol is a ∩ Example: C = M ∩ P

Set operations: Intersection 2 A ∩ B U A B

Set operations: Intersection 3 Formal definition for the intersection of two sets: A ∩ B = { x | x  A and x  B } Further examples {1, 2, 3} ∩ {3, 4, 5} = {3} {New York, Washington} ∩ {3, 4} =  No elements in common {1, 2} ∩  =  Any set intersection with the empty set yields the empty set

Set operations: Intersection 4 Properties of the intersection operation A ∩ U = A Identity law A ∩  =  Domination law A ∩ A = A Idempotent law A ∩ B = B ∩ A Commutative law A ∩ (B ∩ C) = (A ∩ B) ∩ C Associative law

Disjoint sets 1 Two sets are disjoint if the have NO elements in common Formally, two sets are disjoint if their intersection is the empty set Another example: the set of the even numbers and the set of the odd numbers

Disjoint sets 2 U A B

Disjoint sets 3 Formal definition for disjoint sets: two sets are disjoint if their intersection is the empty set Further examples {1, 2, 3} and {3, 4, 5} are not disjoint {New York, Washington} and {3, 4} are disjoint {1, 2} and  are disjoint Their intersection is the empty set  and  are disjoint!

Complement sets 1 _ _ Monitor gamut (M) A complement of a set is all the elements that are NOT in the set Printer gamut (P) Difference symbol is a bar above the set name: P or M _ _

Complement sets 2 _ B A U A B

Complement sets 3 Formal definition for the complement of a set: A = { x | x  A } Or U – A, where U is the universal set Further examples (assuming U = Z) {1, 2, 3} = { …, -2, -1, 0, 4, 5, 6, … }

Complement sets 4 Properties of complement sets A = A Complementation law A U A = U Complement law A ∩ A =  Complement law ¯ ¯ ¯ ¯

Set operations: Difference 1 Monitor gamut (M) A difference of two sets is the elements in one set that are NOT in the other Printer gamut (P) Difference symbol is a minus sign Example: C = M - P Also visa-versa: C = P - M

Set operations: Difference 2 B - A A - B U A B

Set operations: Difference 3 Formal definition for the difference of two sets: A - B = { x | x  A and x  B } A - B = A ∩ B  Important! Further examples {1, 2, 3} - {3, 4, 5} = {1, 2} {New York, Washington} - {3, 4} = {New York, Washington} {1, 2} -  = {1, 2} The difference of any set S with the empty set will be the set S _

Set operations: Symmetric Difference 1 Monitor gamut (M) A symmetric difference of the sets contains all the elements in either set but NOT both Printer gamut (P) Symetric diff. symbol is a  Example: C = M  P

Set operations: Symmetric Difference 2 Formal definition for the symmetric difference of two sets: A  B = { x | (x  A or x  B) and x  A ∩ B} A  B = (A U B) – (A ∩ B)  Important! Further examples {1, 2, 3}  {3, 4, 5} = {1, 2, 4, 5} {New York, Washington}  {3, 4} = {New York, Washington, 3, 4} {1, 2}   = {1, 2} The symmetric difference of any set S with the empty set will be the set S

Photo printers Photo printers use many ink colors for rich, vivid color Also a scam to sell you more ink (the razor business model)

Set identities Set identities are basic laws on how set operations work Many have already been introduced on previous slides Just like logical equivalences! Replace U with  Replace ∩ with  Replace  with F Replace U with T

Set identities: DeMorgan again These should look very familiar…

How to prove a set identity For example: A∩B=B-(B-A) Four methods: Use the basic set identities Use membership tables Prove each set is a subset of each other This is like proving that two numbers are equal by showing that each is less than or equal to the other Use set builder notation and logical equivalences

What we are going to prove… A∩B=B-(B-A) A B B-(B-A) A∩B B-A

Proof by using basic set identities Prove that A∩B=B-(B-A) Definition of difference DeMorgan’s law Complementation law Distributive law Complement law Identity law Commutative law

What is a membership table Membership tables show all the combinations of sets an element can belong to 1 means the element belongs, 0 means it does not Consider the following membership table: The bottom row is all elements that belong to neither set A or set B Thus, these elements are neither the union, the intersection, nor difference The third row is all elements that belong to set B but not set A Thus, these elements are in the union, but not the intersection or difference The second row is all elements that belong to set A but not set B Thus, these elements are in the union and difference, but not the intersection The top row is all elements that belong to both sets A and B Thus, these elements are in the union and intersection, but not the difference

Proof by membership tables The following membership table shows that A∩B=B-(B-A) Because the two indicated columns have the same values, the two expressions are identical This is similar to Boolean logic!

Proof by showing each set is a subset of the other 1 Assume that an element is a member of one of the identities Then show it is a member of the other Repeat for the other identity We are trying to show: (xA∩B→ xB-(B-A))  (xB-(B-A)→ xA∩B) This is the biconditional: xA∩B ↔ xB-(B-A) Not good for long proofs Basically, it’s an English run-through of the proof

Proof by showing each set is a subset of the other 2 Assume that xB-(B-A) By definition of difference, we know that xB and xB-A Consider xB-A If xB-A, then (by definition of difference) xB and xA Since xB-A, then only one of the inverses has to be true (DeMorgan’s law): xB or xA So we have that xB and (xB or xA) It cannot be the case where xB and xB Thus, xB and xA This is the definition of intersection Thus, if xB-(B-A) then xA∩B

Proof by showing each set is a subset of the other 3 Assume that xA∩B By definition of intersection, xA and xB Thus, we know that xB-A B-A includes all the elements in B that are also not in A not include any of the elements of A (by definition of difference) Consider B-(B-A) We know that xB-A We also know that if xA∩B then xB (by definition of intersection) Thus, if xB and xB-A, we can restate that (using the definition of difference) as xB-(B-A) Thus, if xA∩B then xB-(B-A)

Proof by set builder notation and logical equivalences 1 First, translate both sides of the set identity into set builder notation Then massage one side (or both) to make it identical to the other Do this using logical equivalences

Proof by set builder notation and logical equivalences 2 Original statement Definition of difference Negating “element of” DeMorgan’s Law Distributive Law Negation Law Identity Law Definition of intersection

Computer representation of sets 1 Assume that U is finite (and reasonable!) Let U be the alphabet Each bit represents whether the element in U is in the set The vowels in the alphabet: abcdefghijklmnopqrstuvwxyz 10001000100000100000100000 The consonants in the alphabet: 01110111011111011111011111

Computer representation of sets 2 Consider the union of these two sets: 10001000100000100000100000 01110111011111011111011111 11111111111111111111111111 Consider the intersection of these two sets: 01110111011111011111011111 00000000000000000000000000

Subset problems Let A, B, and C be sets. Show that: (AUB)  (AUBUC) (A∩B∩C)  (A∩B) (A-B)-C  A-C (A-C) ∩ (C-B) = 

Russell’s paradox Consider the set: Is S an element of itself? S = { A | A is a set and A  A } Is S an element of itself? Consider: Let S  S Then S can not be in itself, by the definition Let S  S Then S is in itself by the definition Contradiction!

Russell’s paradox Consider the set: S = { A | A is a set and A  A } This shows a problem with set theory! Meaning we can define a set that is not viable The solution: Restrict set theory to not include sets which are subsets of themselves

The Halting problem Given a program P, and input I, will the program P ever terminate? Meaning will P(I) loop forever or halt? Can a computer program determine this? Can a human? First shown by Alan Turing in 1936 Before digital computers existed!

A few notes To “solve” the halting problem means we create a function CheckHalt(P,I) P is the program we are checking for halting I is the input to that program And it will return “loops forever” or “halts” Note it must work for any program, not just some programs Or simple programs

Can a human determine if a program halts? Given a program of 10 lines or less, can a human determine if it halts? Assuming no tricks – the program is completely understandable And assuming the computer works properly, of course And we ignore the fact that an int will max out at 4 billion

Halting problem tests function haltingTest1() print “Alan Turing” print “was a genius” return function haltingTest2() for factor from 1 to 10 print factor function haltingTest3() while ( true ) print “hello world” return function haltingTest4() int x = 10 while ( x > 0 ) x := x + 1

Perfect numbers Numbers whose divisors (not including the number) add up to the number 6 = 1 + 2 + 3 28 = 1 + 2 + 4 + 7 + 14 The list of the first 10 perfect numbers: 6, 28, 496, 8128, 33550336, 8589869056, 137438691328, 2305843008139952128, 2658455991569831744654692615953842176, 191561942608236107294793378084303638130997321548169216 The last one was 54 digits! All known perfect numbers are even; it’s an open (i.e. unsolved) problem if odd perfect numbers exist Sequence A000396 in OEIS

Odd perfect number search function searchForOddPerfectNumber() int n = 1 // arbitrary-precision integer while (true) { var int sumOfFactors = 0 for factor from 1 to n - 1 if factor is a factor of n sumOfFactors = sumOfFactors + factor if sumOfFactors = n then break n = n + 2 } return Will this program ever halt?

Where does that leave us? If a human can’t figure out how to do the halting problem, we can’t make a computer do it for us It turns out that it is impossible to write such a CheckHalt() function But how to prove this?

CheckHalt()’s non-existence Consider P(I): a program P with input I Suppose that CheckHalt(P,I) exists Tests if P(I) will either “loop forever” or “halt” A program is a series of bits And thus can be considered data as well Thus, we can call CheckHalt(P,P) It’s using the bytes of program P as the input to program P

CheckHalt()’s non-existence Consider a new function: Test(P): loops forever if CheckHalt(P,P) prints “halts” halts if CheckHalt(P,P) prints “loops forever” Do we agree that Test() is a valid function? Now run Test(Test) If Test(Test) halts… Then CheckHalt(Test,Test) returns “loops forever”… Which means that Test(Test) loops forever Contradiction! If Test(Test) loops forever… Then CheckHalt(Test,Test) returns “halts”… Which means that Test(Test) halts

Why do we care about the halting problem? It was the first algorithm that was shown to not be able to exist You can prove an existential by showing an example (a correct program) But it’s much harder to prove that a program can never exist