Sets, Propositional Logic, Predicates, and Quantifiers
Total Page:16
File Type:pdf, Size:1020Kb
COMP 182 Algorithmic Thinking Sets, Propositional Logic, Luay Nakhleh Computer Science Predicates, and Quantifiers Rice University !1 Reading Material ❖ Chapter 1, Sections 1, 4, 5 ❖ Chapter 2, Sections 1, 2 !2 ❖ Mathematics is about statements that are either true or false. ❖ Such statements are called propositions. ❖ We use logic to describe them, and proof techniques to prove whether they are true or false. !3 Propositions ❖ 5>7 ❖ The square root of 2 is irrational. ❖ A graph is bipartite if and only if it doesn’t have a cycle of odd length. ❖ For n>1, the sum of the numbers 1,2,3,…,n is n2. !4 Propositions? ❖ E=mc2 ❖ The sun rises from the East every day. ❖ All species on Earth evolved from a common ancestor. ❖ God does not exist. ❖ Everyone eventually dies. !5 ❖ And some of you might already be wondering: “If I wanted to study mathematics, I would have majored in Math. I came here to study computer science.” !6 ❖ Computer Science is mathematics, but we almost exclusively focus on aspects of mathematics that relate to computation (that can be implemented in software and/or hardware). !7 ❖Logic is the language of computer science and, mathematics is the computer scientist’s most essential toolbox. !8 Examples of “CS-relevant” Math ❖ Algorithm A correctly solves problem P. ❖ Algorithm A has a worst-case running time of O(n3). ❖ Problem P has no solution. ❖ Using comparison between two elements as the basic operation, we cannot sort a list of n elements in less than O(n log n) time. ❖ Problem A is NP-Complete. !9 ❖ “Algorithm A is correct” is a proposition that requires a mathematical proof. ❖ All students in the course thinking that it is true is not a proof. ❖ Showing it is true on 1 million examples is not a proof. !10 ❖ “Problem P has no solution” is a proposition that requires a mathematical proof. ❖ Your inability to come up with a solution to Problem P is not a proof that a solution doesn’t exist. ❖ All your 5,000 Facebook friends not being able to come up with a solution doesn’t make the statement true either. !11 ❖ Despite decades of work by so many brilliant researchers, no one has been able to come up with a polynomial-time algorithm for the Traveling Salesman Problem (TSP). ❖ Still, no computer scientist or mathematician would state “TSP has no polynomial-time solution” because such a statement would require a mathematical proof and such a proof has not been found yet. !12 ❖ It is important to note that decades of work by brilliant researchers not resulting in a polynomial-time algorithm for TSP do strengthen our belief that the conjecture that “TSP has no polynomial-time solution” is true. ❖ This belief could, for example, direct other brilliant researchers to focus on proving the conjecture true (rather than false). ❖ However, no matter how strong our belief is, it is still not a proof. !13 Sets ❖ A set is an unordered collection of items. ❖ We write a∈S to denote that a is an element of set S, or that set S contains element a. ❖ Roster method description of sets: B={0,1}, C={a,b,c,d}, D={#,$,%,&,@} ❖ Set builder or set comprehension description of sets: F={x|x is an odd integer}, G={y| y is an integer that is divisible by 7} !14 Sets ❖ An element of a set cannot appear more than once in the set. ❖ For example, {a,b,b,c} is not a set. ❖ A mathematical structure that allows for an element to appear more than once is called multiset or bag. In this course, we will only work with sets. !15 Special Sets ❖ N = 0, 1, 2, 3,... The set of natural numbers { } ❖ The set of integers Z = ..., 2, 1, 0, 1, 2,... { − − } + ❖ Z = 1, 2,... The set of positive integers { } p ❖ The set of rational numbers Q = p, q Z,q =0 { q | 2 6 } ❖ The set of real numbers R + ❖ The set of positive real numbers R !16 The Empty Set ❖ The empty set is the set that contains no elements. ❖ Denoted by ∅ or {}. ❖ Important: The set {∅} is not empty. Rather, it is a set that contains one element that is ∅. !17 Cardinality of Sets ❖ The cardinality of a finite set S, denoted by |S|, is the number of elements in S. ❖ |{a,b,c}| = 3 ❖ |∅| = 0 ❖ |{∅}| = 1 !18 Cardinality of Sets ❖Not all sets are finite. ❖Infinite sets can be countable or uncountable. ❖More on this later in the semester. !19 Propositional Logic !20 Propositions ❖ A proposition is a declarative sentence that is either true or false, but not both. ❖ We use propositional variables (e.g., p, q, r, s,…) to represent propositions. !21 Propositions ❖ Propositions: ❖ 3∈{1,2,4} ❖ |{0,1}|=2 ❖ 7∉{a,b,c} ❖ Not propositions: ❖ 1+1 ❖ {a,b,c} ❖ |{5,12,19}| !22 Compound Propositions ❖ If p is a proposition, ¬p is its negation. ❖ If p and q are two propositions, then ❖ p∧q (“p and q”) is their conjunction ❖ p∨q (“p or q”) is their disjunction !23 Truth Values ❖ The truth value of a proposition is true, denoted by T, if it is a true proposition, and the truth value is false, denoted by F, if it is a false proposition. ❖ True propositions: ❖ |{a,b}|=2 |∅|<|{1}| 7∉{1,5,9,12} ❖ False propositions: ❖ |{∅}|=0 7∈{1,5,9,12}!24 Truth Table ❖ For a compound proposition, one way to determine the truth value of the proposition is by using a truth table. ❖ The truth table has one row for each combination of T and F for the primitive propositions. !25 4 41 / The1 / The Foundations: Foundations: Logic Logic and Proofsand Proofs TableTable 1 displays 1 displays the thetruthtruth table tablefor thefor negationthe negation of a of proposition a propositionp. Thisp. This table table has ahas row a row TABLETABLE 1 The 1 The for each of the two possible truth values of a propositionp p. Each row shows the truth value of TruthTruth Table Table for for for each of the two possible truth values of a proposition . Each row shows the truth value of the Negation of a p correspondingp corresponding to the to truththe truth value value of p offorp thisfor this row. row. the Negation of a ¬ ¬ Proposition.Proposition. TheThe negation negation of a of proposition a proposition can can also also be considered be considered the theresult result of the of operationthe operation of the of the negationnegation operator operatoron aon proposition. a proposition. The The negation negation operator operator constructs constructs a new a new proposition proposition from from p p p p ¬ ¬ a singlea single existing existing proposition. proposition. We Wewill will now now introduce introduce the logical the logical operators operators that that are used are used to form to form T T F F newnew propositions propositions from from two two or more or more existing existing propositions. propositions. These These logical logical operators operators are also are also called called F F T T connectivesconnectives. DEFINITIONDEFINITION 2 2 Let Letp andp andq beq propositions.be propositions. The Theconjunctionconjunctionof pofandp andq, denotedq, denoted by p by pq, isq the, is proposition the proposition ∧ “p and“p andq.” Theq.” The conjunction conjunctionp pq isq trueis true when when both bothp andp andq areq trueare true and∧ and is false is false otherwise. otherwise. ∧ ∧ TableTable 2 displays 2 displays the the truth truth table table of p of pq. Thisq. This table table has has a row a row for each for each of the of four the four possible possible ∧ combinationscombinations of truth of truth values values of p ofandp ∧andq. Theq. The four four rows rows correspond correspond to the to pairs the pairs of truth of truth values values TT,TT, TF, TF, FT, FT, and and FF, FF,where where the firstthe first truth truth value value in the in pair the pair is the is truth the truth value value of p ofandp and the second the second truthtruth value value is the is truththe truth value value of q of. q. NoteNote that that in logic in logic the wordthe word “but” “but” sometimes sometimes is used is used instead instead of “and” of “and” in a in conjunction. a conjunction. For For example,example, the statementthe statement “The “The sun sun is shining, is shining, but it but is it raining” is raining” is another is another way way of saying of saying “The “The sun sun is shiningis shining and and it is it raining.” is raining.” (In natural (In natural language, language, there there is a subtle is a subtle difference difference in meaning in meaning between between “and”“and” and and “but”; “but”; we will we will not notbe concerned be concerned with with this this nuance nuance here.) here.) EXAMPLEEXAMPLE 5 5FindFind the conjunctionthe conjunction of the of propositions the propositionsp andp andq whereq wherep isp theis proposition the proposition “Rebecca’s “Rebecca’s PC has PC has moremore than than 16 GB 16 GB free free hard hard disk disk space” space” and andq isq theis propositionthe proposition “The “The processor processor in Rebecca’s in Rebecca’s PCPC runs runs faster faster than than 1 GHz.” 1 GHz.” Solution:Solution:TheThe conjunction conjunction of these of these propositions, propositions,p pq, isq the, is proposition the proposition “Rebecca’s “Rebecca’s PC has PC has moremore than than 16 GB 16 GB free free hard hard disk disk space, space, and and the processorthe∧ processor∧ in Rebecca’s in Rebecca’s PC runs PC runs faster faster than than 1 1 GHz.”GHz.” This This conjunction conjunction can can be expressed be expressed more more simply simply as “Rebecca’s as “Rebecca’s PC has PC morehas more than than 16 GB 16 GB freefree hard hard disk disk space, space, and and its processor its processor runs runs faster faster than than 1 GHz.” 1 GHz.” For Forthis this conjunction conjunction to be to true, be true, ▲ bothboth conditions conditions given given must must be true.