Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS100 : Discrete Structures

Similar presentations


Presentation on theme: "CS100 : Discrete Structures"— Presentation transcript:

1 CS100 : Discrete Structures
4/24/2017 CS100 : Discrete Structures Chapter 1 Logic Theory Dr.Saad Alabbad Department of Computer Science Office # SR 068 Tel # 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

2 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed
4/24/2017 Propositional Logic Proposition: A proposition is a declarative statement ( a statement that declares a fact) that is either TRUE or FALSE, but not both. The area of logic that deals with propositions is called propositional logic. Propositions Not Propositions Riyadh is the capital of Saudi Arabia How many students in this class? Every cow has 4 legs. Bring me coffee! 3 + 2 = 32 4 + 3 = 7 X + 2 = 3 Y + Z = X "x +2=3", where x is a variable representing a number, is not a proposition, because unless a specific value is given to x we can not say whether it is true or false, nor do we know what x represents. 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

3 Propositional Logic - Negation
4/24/2017 Propositional Logic - Negation We use letters to denote propositional variables Truth value of true proposition is denoted by T Truth value of false proposition is denoted by F Negation: Suppose p is a proposition. The negation of p is written p and has meaning: “It is not the case that p.” The proposition p is read “NOT p” Example: p: “Today is Friday” p: “Today is NOT Friday” Truth table for negation: p p T F Notice that p is a proposition! 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

4 Propositional Logic - Conjunction
4/24/2017 Propositional Logic - Conjunction Conjunction corresponds to English “and.” Conjunction: Let p and q be two propositions. The conjunction of p and q, denoted by p  q, is the proposition “p and q”. The p  q is true when both p and q are true, otherwise false. Example: p: “Today is Friday” q: “It is raining today” p  q: “Today is Friday and it is raining today” Truth table for conjunction: P q p  q T F 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

5 Propositional Logic - Disjunction
4/24/2017 Propositional Logic - Disjunction Disjunction corresponds to English “or.” Disjunction: Let p and q be two propositions. The disjunction of p and q, denoted by p  q, is the proposition “p or q”. The p  q is false when both p and q are false, otherwise true. Example: p: “Today is Friday” q: “It is raining today” p  q: “Today is Friday or it is raining today” Truth table for disjunction: p q p  q T F Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed 4/24/2017 Prepared by Dr. Zakir H. Ahmed

6 Propositional Logic – Exclusive Or
4/24/2017 Propositional Logic – Exclusive Or Exclusive Or: Let p and q be two propositions. The exclusive or of p and q, denoted by p ⊕ q, is the proposition that is true when exactly one of p and q is true, otherwise false. Example: p: “Today is Friday” q: “It is raining today” p ⊕ q: “Today is Friday exclusive or it is raining today” Truth table for Exclusive Or: p q p ⊕ q T F 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

7 Propositional Logic – Conditional Statement
4/24/2017 Propositional Logic – Conditional Statement It corresponds to English “if p then q” or “p implies q.” Conditional: Let p and q be two propositions. The conditional statement (implication) p  q is the proposition “if p, then q”. The conditional statement p  q is false when p is true and q is false, otherwise true. (p is called the hypothesis ,q is the conclusion) Example: If it is raining, then it is cloudy. If I am elected, then I will lower taxes. If you get 100% in the final, then you will get Grade A+. Truth table for implication: p q p  q T F 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

8 Propositional Logic - Special Definitions
4/24/2017 Propositional Logic - Special Definitions Converse: q  p is converse of p  q. Ex. p  q: “If it is noon, then I am hungry.” q  p: “If I am hungry, then it is noon.” Contrapositive: q  p is contapositive of p  q. Ex. p  q: “If it is noon, then I am hungry.” q  p: “If I am not hungry, then it is not noon.” Inverse: p  q is inverse of p  q. p  q: “If it is not noon, then I am not hungry.” p  q has same truth values as q  p 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

9 Propositional Logic - Questions
4/24/2017 Propositional Logic - Questions Q1: Give some examples of p  q, then tell what is q  p q  p p  q Q2: State the converse, contrapositive, and inverse of each of them If it rains today, then I will stay at home I come to class whenever there is going to be a examination A positive integer is prime only if it has no divisors other than 1 and itself. 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

10 Propositional Logic – Biconditional Statement
4/24/2017 Propositional Logic – Biconditional Statement It corresponds to English “p if and only if q”. Biconditional: Let p and q be two propositions. The biconditional statement (bi-implication) p ↔ q is the proposition “if p and only if q”. The biconditional statement p ↔ q is true when p and q have the same truth values, otherwise false. p ↔ q has same truth value as (p q)  (q  p). Example: p: “You can take the flight” q : “You buy a ticket” p ↔ q : “You can take the flight if and only if you buy a ticket” p q p ↔ q T F 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

11 Propositional Logic – Precedence
4/24/2017 Propositional Logic – Precedence Precedence of Logical Operators: P Λ ¬ q νr →s ↔w νm (((P Λ (¬ q)) ν r) →s) ↔(w νm) Operator Precedence Λ ν 1 2 3 4 5 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

12 Propositional Logic – Precedence
4/24/2017 Propositional Logic – Precedence A compound proposition that is: (1) always true is called a tautology (2) always false is called a contradiction (3) neither a tautology nor a contradiction is called contingency or satisfiable. p p p  p p  p T F 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

13 Propositional Logic – Compound Propositions
4/24/2017 Propositional Logic – Compound Propositions Construct truth table for (p  q) → (p  q). Q3: Construct truth table for (p  q) ↔ (p  q). (p ⊕ q) → (p ⊕ q). (p  q) → (p  q) p  q p  q q q p T F 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

14 Propositional Logic – Translating English Sentences
4/24/2017 Propositional Logic – Translating English Sentences The sentence “The automated reply cannot be sent when the file system is full” can be translated as q → p where p: “The automated reply can be sent ” q: “The file system is full” The sentence “You cannot drive a car if you are under 4 feet tall unless you are older than 16 years old” can be translated as (q r) → p where p: “You can drive a car ” q: “You are under 4 feet tall ” r: “You are older than 16 years old” 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

15 Propositional Logic – Translating English Sentences
4/24/2017 Propositional Logic – Translating English Sentences The sentence “You can access the Internet from campus only if you are a computer science major or you are not a freshman” can be translated as p → (q  r) where p: “You can access the Internet from campus” q: “You are a computer science major” r: “You are a freshman” Q4: Translate the following sentences into logical expressions: “Access is granted whenever the user has paid the subscription fee and enters a valid password” “If the user has not entered a valid password but has paid the subscription fee, then access is granted” 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

16 Propositional Equivalences – Logic and Bit Operations
4/24/2017 Propositional Equivalences – Logic and Bit Operations Bit: A bit is a symbol with two possible values, namely, 0 (zero) and 1 (one). A bit can be used to represent a truth value as 1 for T and 0 for F Bit string: A bit string is a sequence of bits. The length of the string is number of bits in the string. Example: is a bit string of length eight We define the bitwise OR, AND, and XOR of two strings of same length to be the strings that have as their bits the OR, AND, and XOR of the corresponding bits in the two strings, respectively. We use the symbols , , and ⊕ to represent bitwise OR, AND, and XOR, respectively. 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

17 Propositional Equivalences – Logic and Bit Operations
4/24/2017 Propositional Equivalences – Logic and Bit Operations Truth table for bitwise OR, AND, and XOR: Q5: Find bitwise OR, AND, and XOR of the bit strings and and and x ⊕ y x  y x  y y x 1 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

18 Propositional Logic - Applications
4/24/2017 Propositional Logic - Applications We are using propositional logic as a foundation for formal proofs. Propositional logic is also the key to writing good code…you can’t do any kind of conditional (if) statement without understanding the condition you’re testing. All the logical connectives we have discussed are also found in hardware and are called “gates.” 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

19 Propositional Equivalences – Logical Equivalences
4/24/2017 Propositional Equivalences – Logical Equivalences Equivalence: The compound propositions p and q are logically equivalent if p↔q is a tautology. In other words, p and q are logically equivalent if their truth tables are the same. We write p  q. Example: (p  q)  p  q. Truth tables for (p  q) and p  q : p  q q p (p  q) p  q q p F T 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

20 Propositional Equivalences – Logical Equivalences
4/24/2017 Propositional Equivalences – Logical Equivalences Example: p  q  p  q. Truth tables for p  q and p  q: Q5: Show that p  (q  r)  (p  q)  (p  r) Note: if we have n logical variable then the size of the truth table is 2n p  q p p  q q p T F 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

21 Propositional Equivalence – Prove the following Logical Equivalences
4/24/2017 Equivalence Name p Λ T  p and p ν F  p Identity laws p ν T  T and p Λ F  F Domination laws p ν p  p and p Λ p  p Idempotent laws ¬( ¬ p)  p Double negation law p ν q  q ν p and p Λ q  q Λ p Commutative laws (p ν q) ν r  p ν (q ν r) and (p Λ q) Λ r  p Λ (q Λ r) Associative laws p  (q  r)  (p  q)  (p  r) p  (q  r)  (p  q)  (p  r) Distributive laws ¬(p ν q)  ¬p Λ ¬q and ¬(p Λ q)  ¬p ν ¬q De Morgan’s laws p  (p  q)  p and p  (p  q)  p Absorption laws p ν ¬p  T and p Λ ¬p  F Negation laws 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

22 Propositional Equivalence – Prove the following Logical Equivalences
4/24/2017 Propositional Equivalence – Prove the following Logical Equivalences 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

23 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed
4/24/2017 Propositional Equivalences – Another way of proving Logical Equivalences In addition to truth table we can use logical identities that we already know to establish new logical equivalences Examples: ¬(p  q)  p ¬q (see p.26) Show that ¬(p (¬ p  q)) and ¬ p  ¬ q are equivalent. Show that p q  p  q is a tautology .(see p.27 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

24 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed
4/24/2017 Predicate Logic Introduction: x>20 (We must know x to tell if it is true or false) All students passed. (We have to write a proposition for every student asserting that he passed and take the conjunction of all these propositions) Some students didn’t pass (Can you make such an assertion without referring to a particular student?) X is father of y The above assertions are not propositions. However, they appear quite often in mathematics and we want to do deal with such assertions. Predicate logic is a more powerful logic than propositional logic and it addresses some of the limitations of propositional logic 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

25 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed
4/24/2017 Predicate Logic Predicate: refers to a property that the subject of the statement can have or relationships among other subjects Examples X>20. This statements has two parts. The variable x and is called the subject The property “is greater than 20” and is called the predicate We can also write P(x) where P is the predicate ‘’is greater than 20” and x is the subject. P(x) is called the propositional function P at x Note: once a value has been assigned to the variable x the statement P(x) becomes a proposition that has a truth value. For example P(8) is the statement that 8>20 which is false 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

26 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed
4/24/2017 Predicate Logic Examples x is father of y. This statements has two parts. The variables x and y and are called the subjects The relationship “is father of ” and is called the predicate We can also write P(x,y) where P is the predicate ‘is father of ” and x,y are the subjects. P(x,y) is called the propositional function P at x and y. As we have seen predicate logic can describe both relationships and properties of subjects 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

27 Predicate Logic: Quantifiers
4/24/2017 Predicate Logic: Quantifiers Quantification expresses the extent to which a predicate is true over a range of elements. In English: all,some,none anf few are used. All birds have wings Some birds do not fly. The area of logic that deals with predicates and quantifiers is called predicate calculus or first order logic. 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

28 Predicate Logic: Universal Quantifier
4/24/2017 Predicate Logic: Universal Quantifier Universal Quantifier: Asserts that a property is true for all values of a variable in a particular domain. Let P(x) be a propostional function.The universal quantifier of P(x) is the statement: P(x) is true for all x in the domain. The domain is called the universe of discourse We write We read it as “for all x P(x)” An element for which P(x) is false is called counterexample of The statement is either true of false, so is a proposition. 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

29 Predicate Logic: Universal Quantifier
4/24/2017 Predicate Logic: Universal Quantifier Examples: Let P(x) be “x2 > 0” then Statement is not true when the universe of discourse consists of all real numbers P(0) is false ( counterexample) Statement is true when the universe of discourse consists of all real numbers which are greater than 0. What is the truth value of if the domain consists of all real numbers? 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

30 Predicate Logic: Existential Quantifier
4/24/2017 Predicate Logic: Existential Quantifier Existential Quantifier: Asserts that there is an element with a certain property in a particular domain. Let P(x) be a propostional function.The Existential quantifier of P(x) is the statement: There exists an element x in the domain such that P(x) is true. The domain is called the universe of discourse We write We read it as “There is an x such that P(x)” or “For some x P(x)” The statement is false iff there is no element x in the domain for which P(x) is true The statement is either true of false, so is a proposition. 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

31 Predicate Logic: Existential Quantifier
4/24/2017 Predicate Logic: Existential Quantifier Examples: Let P(x) be “x2 > 0” then Statement is true since for example P(2) is true Statement is false iff there is no element in the domain for which P(x) is true. Finding at least one element for which P(x) is true is sufficient to asserts that is true. What is the truth value of if the domain consists of all real numbers? 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

32 Predicate Logic: Quantifiers
4/24/2017 Predicate Logic: Quantifiers When all the elements in domain can be listed as:x1,x2,…,xn then: is the same as P(x1) P(x2)…  P(xn) is the same as P(x1)  P(x2)…  P(xn) Quantifiers with restricted domain (note that it is the same as The two quantifiers have precedence over all logical operators from propositional logic. 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

33 Predicate Logic: Negation of Quantified Expression
4/24/2017 Predicate Logic: Negation of Quantified Expression Examples Every Students in this class has taken calculus course Can be represented as: where P(x) is”x has taken calculus course” To negate it we write “there is a student in this class who has not taken calculus course” which can be translated to There is a man who can fly Can be represented as: where F(x) is”x can fly” To negate it we write “There is no man who can fly” Which can be stated as ”every man can not fly” 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

34 Predicate Logic: From English to Logic(1)
4/24/2017 Predicate Logic: From English to Logic(1) Every student in the class has taken calculus course 1- For every student x in the class, x has taken calculus 2- where T(x) is “x has taken calculus” The domain of x is students of this class For every Man, if the man has a job then he has a car 1- For every man x, if x has a job then x has a car where J(x) is “x has a job” C(x) is “x has a car” The domain of x is all the men Some student in this class has visited Abha or Dammam For every Saudi, if he is a student then he has visitd Abha 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

35 Predicate Logic: Nested Quantifiers
4/24/2017 Predicate Logic: Nested Quantifiers (1) The statement says that For every number x, there is a number y such that x+y=0 (additive inverse) (2) The statement says that (the domain is all non-negative integers) There exists x, such that for every number y, y is greater than or equal to x (0 is the smallest non-negative number) (3) The statement says that X+y=y+x for all numbers x and y (commutative law of addition). (4) The statement says that There exist two numbers x and y such that their product equals 17 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

36 Predicate Logic: From English to Logic and vice versa(2)
4/24/2017 Predicate Logic: From English to Logic and vice versa(2) The sum of two positive integers is always positive Every real number except zero has a multiplicative inverse or Translate(p.55) Translate If a person is a male and is a parent then this person is someone’s father. x(Male(x)Parent(x)y Father(x,y)) 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

37 Predicate Logic: From English to Logic(3)
4/24/2017 Predicate Logic: From English to Logic(3) Example: Let 1) S(x) be “x is s student” 2)F(x) be “x is a faculty member” 3) E(x,y) be “x has sent an to y” and the domain is every person in our college. Translate the following sentences into logical Expressions: Every person in the college has sent an to every person including himself xy(E(x,y)) Every person in the college has sent an to every other person not including himself xy(xy  E(x,y)) At least one has been sent from one person to another xy(xyE(x,y)) There is a person who sent an to every other person xy(xyE(x,y)) Every person has been sent at least one xy(xyE(y,x)) 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

38 Predicate Logic: From English to Logic(4)
4/24/2017 Predicate Logic: From English to Logic(4) Example: Let 1) S(x) be “x is s student” 2)F(x) be “x is a faculty member” 3) E(x,y) be “x has sent an to y” and the domain is every person in our college. Translate the following sentences into logical Expressions: Ayman has sent an to Dr.Saad: E(Ayman,Dr.Saad) Every student sent an to Dr.Zakir x(S(x)E(x,Dr.Zakir)) Every Faculty member has either sent an to Dr.Ahmad or has been sent an by Dr.Ahmad. x(F(x)E(x,Dr.Ahmad) E(Dr.Ahmad,x)) Some student has not sent an to any faculty member x(S(x) y(F(y)E(x,y)) There is a faculty member who has never been sent an by a student. x(F(x) y(S(y)E(y,x)) Some student has sent an to every faculty member x(S(x) y(F(y)E(x,y)) 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed

39 Predicate Logic: Negating Nested Quantifiers
4/24/2017 Predicate Logic: Negating Nested Quantifiers Negating Nested Quantifiers Negate 1- 2- 3- 4- 4/24/2017 Prepared by Dr.Saad Alabbad & Dr. Zakir Ahmed Prepared by Dr. Zakir H. Ahmed


Download ppt "CS100 : Discrete Structures"

Similar presentations


Ads by Google