Introduc)on CSC 1300 Discrete Structures Villanova University 1
Discrete Structures Goal: Understand how to use mathema)cs to reason about problems in Computer Sciences: sets and coun)ng func)ons and rela)ons sequences, summa)ons logic proofs, including mathema)cal induc)on recurrences combinatorics trees graphs 2
What is discrete about Discrete Structures? Also called Discrete (or inite) Mathema2cs Mathema)cs for Computer Science finite in nature: Algorithms Data structures Databases Opera)ng Systems Computer Security Digital imaging Unlike calculus which is concerned with infinite processes and the no)on of con)nuity 3
Examples of problems solved using discrete structures How many ways are there to choose a valid password? How can we prove that a list of n numbers cannot be sorted using fewer than nlog 2 n comparisons? Is there a link between two computer systems in a network? How many habitats do you need to create in a zoo so that animals don t eat each other? What is a reasonable way to determine the significance of a webpage (page rank) Prove that in a gathering with 6 people, where each pair is either friends or strangers, there is a group of 3 people who are either all mutual friends or all mutual strangers. 4
Course organiza)on Lectures will cover approximately one chapter per week Exercises of various sorts: Readiness or Warmup exercises Drill exercises Homework problems 3 exams inal 5
An old quote A priest asked: What is ate, Master? And he answered: It is that which gives a beast of burden its reason for existence. It is that which men in former )mes had to bear upon their backs. It is that which has caused na)ons to build byways from City to City upon which carts and coaches pass, and alongside which inns have come to be built to stave off Hunger, hirst and Weariness. And that is ate? said the priest. ate...i thought you said reight, responded the Master. hat's all right, said the priest. I wanted to know what reight was too. - Kehlog Albran Source unknown: his quote appeared as one of the fortunes displayed by the fortune cookie program on old unix systems ( fortune was a program that ran automa?cally every?me you logged out of the system and displayed a random, pithy saying. 6
Introduc)on to Logic Major themes Sentences or proposi)ons Logical connec)ves ruth tables Logical equivalence Open sentences autology and contradic)on Proving logical equivalence
Why Logic? Logic a science of reasoning Basis of sound reasoning - gives precise meaning to mathema)cal (or other) statements - is used to dis)nguish between valid and invalid arguments Applica)ons of logic in CS: - programming - design of hardware - verifica)on of program correctness - modeling in ar)ficial intelligence - inferences, integrity of databases
Statement (or Proposi;on) A declara2ve sentence that is either true or false Are the following statements? 1+2 = 3 today is my birthday New York is the capital of the USA 5-3 + 2 x+y > 5 Is Villanova in Pennsylvania? Don t talk Your feet are ugly his sentence is false
Compound statements and Connec;ves Compound statements are formed from simpler statements using connec?ves, also called logical operators. he connec)ves we will study are: nega?on or not operator denoted or ~ conjunc?on or and operator disjunc?on or or operator exclusive or or xor operator implica?on bicondi?onal
Nega;on (NO) If p is a statement, then It is not the case that p is also a statement, called the nega?on of p, denoted by p (or ~ p) and read not p which is true when p is false, and is false when p is true. Example: What is the nega)on of oday is Wednesday? he truth table for nega)on: p p
Conjunc;on (AND) he statement p and q, denoted by p q, is called the conjunc?on of p and q. It is true when both p and q are true, otherwise it is false. Examples: oday is Wednesday and it is raining. oday is Wednesday but it is not raining. he truth table for conjunc)on: p q p q
Disjunc;on (OR) he statement p or q, denoted by p q, is called the disjunc?on of p and q. It is false when both p and q are false, otherwise it is true. Example: oday is Sunday or a holiday. he truth table for disjunc)on: p q p q
Exclusive OR (XOR) he statement p q is called the exclusive or of p and q. It is true when exactly one of p and q is true, otherwise it is false. Example: his dish comes with soup or salad. he truth table for exclusive or: p q p q
ruth tables for more complex statements p q r r (q p)
Implica;on he implica?on or condi?onal statement p q is the statement that is false only when p is true and q is false. p is called the hypothesis and q is called the conclusion. he truth table for implica)on: p q p q Readings for p q: if p then q p only if q q is necessary for p p is sufficient for q p implies q q if p q whenever p
Examples of Implica;on Wording If John is in L.A., then he is in California. o be in California, it is sufficient for John to be in L.A. o be in LA, it is necessary for John to be in California. You will get an A if you study hard. vs. You will get an A only if you study hard.
More Examples of Implica;on wording: If you place your order by 11:59pm December 21 st, then we guarantee delivery by Christmas. Placing your order by 11:59pm December 21 st guarantees delivery by Christmas. We guarantee delivery by Christmas if you place your order by 11:59pm December 21st.
More Examples of Implica;on wording: If you place your order by 11:59pm December 21 st, then we guarantee delivery by Christmas. Placing your order by 11:59pm December 21 st guarantees delivery by Christmas. We guarantee delivery by Christmas if you place your order by 11:59pm December 21st. is this the same too? We guarantee delivery by Christmas only if you place your order by 11:59pm December 21st.
Bicondi;onal he bicondi?onal p q is the statement that is true when p and q have the same truth values, and is false otherwise. he truth table for bicondi)onal: Readings for p q: p q p q p if and only if q p is necessary and sufficient for q if p, then q, and conversely
autologies and contradic;ons tautology: A statement that is always true (no maoer what the truth values of the statements that occur in it) he truth table for a tautology has in every row. contradic?on: A statement that is always false he truth table for a contradic)on has in every row. 21
Simplest example of a tautology and contradic;on p p p p p p he fish is fresh he fish is fresh or the fish is not fresh he fish is fresh and the fish is not fresh 22
autology? p q r ( p ( p q)) q
More examples of tautologies and contradic;ons? p q p q (p q) p p q (p q) ( p q) 24
Logical equivalence We say that the statements p and q are logically equivalent (and write p q) if p and q have the same truth value for all combina)ons of truth values of their component statements. ie, p q just in case p and q have the same truth table Examples: s u s u, because: p q s u s u s u p ( p), because: p ( p) 25
De Morgan s Laws for Logic irst De Morgan s law for logic: (p q) ( p) ( q) Example: Negate: oday is Sunday or a holiday Second De Morgan s law for logic: (p q) Example: Negate: oday is Sunday and a holiday
Why logical equivalences are important he replacement of a (sub)statement with a logically equivalent statement is a powerful tool in mathema)cal reasoning. he result of such a replacement will always have the same truth value as (will be logically equivalent to) the original statement. E.g., ( p) q p q, because ( p) p. Also, using a chain of this kind of replacements can some)mes be the only way to establish that two statements are logically equivalent. or the truth table for a compound statement with 100 variables would have 2100 rows! 27
Using logical equivalences Equivalence Name Equivalence Name p p p p p p p p p p p p p p Iden)ty laws Domina)on laws Idempotent laws Double nega)on law p q q p p q q p (p q) r p (q r) (p q) r p (q r) p (q r) (p q) (p r) p (q r) (p q) (p r) (p q) p q (p q) p q Commuta)ve laws Associa)ve laws Distribu)ve laws De Morgan s laws denotes a tautology and denotes a contradic)on p p (tautology) p p (contradic)on) p q p q ( elimina)on) p q (p q) (q p) ( elimina)on) 28
Example: Applying logical equivalences to derive a new equivalence Without using truth tables, show that [p ( p q)] p q 29
Some more examples: Without using truth tables, show that : p q and q p (p q ) ( q p) p p are equivalent is a tautology is a contradic)on (p (p q ) (q r) (r s) (s w)) w is a tautology 30
Open Sentences Declara)ve sentences containing variable(s) represen)ng objects from some set D called the domain of discourse (or just the domain) ruth of Open sentence depends on value(s) of variables Nota)on: P(x) or Q(x,y,z) Also called Proposi;onal func;ons Example Let P(x) denote the statement x is even. Domain of x: Posi)ve Integers P(2) P(3)
Open Sentences More Examples: x is enrolled in CSC 1051 and CSC 1300 this semester x loves y x loves y and y loves z x is even or x is odd