1.43k likes | 1.63k Views
King ABDUL AZIZ University Faculty Of Computing and Information Technology. CPCS 222 Discrete Structures I The Foundations: Logic and Proofs. Dr. Eng. Farag Elnagahy farahelnagahy@hotmail.com Office Phone: 67967. Propositional Logic. Propositional logic is
E N D
King ABDUL AZIZ UniversityFaculty Of Computing and Information Technology CPCS 222 Discrete Structures I The Foundations: Logic and Proofs Dr. Eng. Farag Elnagahy farahelnagahy@hotmail.com Office Phone: 67967
Propositional Logic • Propositional logic is • the study of propositions (true or false statements) and • The ways of combining them (logical operators) to get new propositions. • It is effectively an algebra of propositions.
Propositional Logic • In this algebra, • the variables stand for unknown propositions (instead of unknown real numbers) and • the operators are and, or, not, implies, and if and only if (rather than plus, minus, negative, times, and divided by). • Just as middle/high school students learn the notation of algebra and how to manipulate it properly, we want to learn the notation of propositional logic and how to manipulate it properly.
Propositional Logic A proposition is a declarative statement that’s either true (T) or false (F), but not both • Propositions • Every cow has 4 legs • Riyadh is the capital of Saudi Arabia • 1+1=2 • 2+2=3 • Not Propositions • What time is it? • X+1=2 • Answer this question
Propositional Logic New propositions, called compound propositions are formed from existing propositions using logical Operators
Propositional Logic negation Suppose p is a proposition The negation of p is written as p and has meaning: “It is not the case that p.” The proposition p is read “not P” Truth table for the negation of proposition p
Propositional Logic negation “ today is Friday” “ it is not the case that today is Friday” or “today is not Friday” “it is not Friday today”
Propositional Logic conjunction Suppose p and q are propositions The conjunction of p and q is written as pq The proposition pq is read “p and q” Truth table for the Conjunction of two propositions pq
Propositional Logic conjunction p is the proposition “Today is Friday” q is the proposition “It is raining today” The conjunction of p and q is proposition “ Today is Friday and it is raining today” This proposition Is true on rainy Fridays Is false on any day that is not a Friday on Fridays when it does not rain
Propositional Logic disjunction • Inclusive Or • Suppose p and q are propositions • The disjunction of p and q is written as pq • The proposition pq is read “p or q” Truth table for the Disjunction (Inclusive Or) of two propositions pq
Propositional Logic disjunction p is the proposition “Today is Friday” q is the proposition “It is raining today” The disjunction of p and q is proposition “ Today is Friday or it is raining today” This proposition Is true on any day that is either a Friday or a rainy day(including rainy Fridays) Is false on days that are not Fridays when it also does not rain
Propositional Logic disjunction • Exclusive Or • Suppose p and q are propositions • The Exclusive Or of p and q is written as pq • The proposition pq is read “p or q but not both” Truth table for the Exclusive Orof two propositions pq (pq) (pq)
Propositional Logic disjunction • Exclusive Or • “Tonight I will stay home or go out to a movie.”
Propositional Logic implication Suppose p and q are propositions The conditional statement (implication) pq The proposition pq is read “ ifp, then q” P hypothesis – antecedent – premise q conclusion -consequence Truth table for the Implication pq p q
Propositional Logic implication Terminology used to express pq “if p, then q” “p is sufficient for q” “q if p” “q when p” “a necessary condition for p is q” “q unless p“ “p implies q” “p only if q” “a sufficient condition for q is p” “q whenever p” “q is necessary for p” “q follows from p” “if p, q”
Propositional Logic implication p is the proposition “Ahmed learns discrete mathematics” q is the proposition “Ahmed will find a good job” The pq is proposition “ if Ahmed learns discrete mathematics, then he will find a good job” This proposition Is false when p is true and q is false Otherwise it is true
Propositional Logic implication p is the proposition “today is Friday” q is the proposition “2+3=5” The pq is proposition “ if today is Friday, then 2+3=5” This proposition Is true becauseits Conclusion (q) is true“
Propositional Logic implication p is the proposition “today is Friday” q is the proposition “2+3=6” The pq is proposition “ if today is Friday, then 2+3=6” This proposition Is true every day except Friday
Propositional Logic implication The conditional statement (implication) pq “if it is raining, then the home team wins” q p is called contrapositive of pq “if the home team does not win, then it is not raining” The proposition qp is called converse of pq “if the home team wins, then it is raining” p q is called inverse of pq “if it is not raining, then the home team does not win”
Propositional Logic bi-implication Suppose p and q are propositions The biconditional statement (bi-implication) pq The proposition p q is read “ p if and only if q” p q is true if both pq qp are true pq pq ------- pq Truth table for the Bi-implication pq (p q ) (p q )
Propositional Logic bi-implication The proposition p q has the same truth value as pq qp
Propositional Logic bi-implication p is the proposition “You can take the flight” q is the proposition “You buy a ticket” The p q is proposition “You can take the flight if and only if You buy a ticket” This proposition Is true if p and q are either both true or both false”
Propositional Logic Truth table of compound propositions • Precedence of logical operators
Propositional Logic Truth table of compound propositions Construct the Truth table of compound propositions (p q) (p q)
Propositional Logic • Translating English sentence into a logical expression “You can access the internet from campus only if you are a computer science major or you are not a freshman” a: “You can access the internet from campus” b: “you are a computer science major” c: “you are a freshman” Where a,b,c are propositional variables a (b c)
Propositional Logic • Translating English sentence into a logical expression (System specifications) • Translating sentences in natural language into logical expressions is an essential part of specifying both hardware and software systems. • System and software engineers take requirements in natural language and produce precise and unambiguous specifications that can be used as the basis for system development.
Propositional Logic • Translating English sentence into a logical expression (System specifications) • Express the specification ”The automated reply cannot be sent when the file system is full“ using logical connectives. P: “The automated reply can be sent” q: “The file system is full” q p • System specifications should be consistent They should not contain conflicting requirements that could be used to drive a contradiction
Propositional Logic • Translating English sentence into a logical expression (System specifications) determine whether these system specifications are consistent : • “The diagnostic message is stored in the buffer or it is retransmitted” • “The diagnostic message is not stored in the buffer” • “if the diagnostic message is stored in the buffer, then it is retransmitted” P: “The diagnostic message is stored in the buffer” q: “The diagnostic message is retransmitted” p q p pq
Propositional Logic • Translating English sentence into a logical expression (System specifications) p q p pq system specifications are consistent
Propositional Logic • Translating English sentence into a logical expression (System specifications) determine whether these system specification are consistent : • “The diagnostic message is stored in the buffer or it is retransmitted” • “The diagnostic message is not stored in the buffer” • “if the diagnostic message is stored in the buffer, then it is retransmitted” • “The diagnostic message is not retransmitted” P: “The diagnostic message is stored in the buffer” q: “The diagnostic message is retransmitted” p q p pq q
Propositional Logic • Translating English sentence into a logical expression (System specifications) p q p pq q system specifications are inconsistent
Propositional Logic • Boolean Searches Logical connectives are used extensively in searches of large collections of information: Indexes of Web pages, these searches employ techniques from propositional logic. The connective AND is used to match records that contain both of the two search items. OR is used to match one or both of two search items. NOT is used to exclude a particular search item (- is used in Google).
Propositional Logic • Logic Puzzles puzzles that can be solved using logical reasoning are known as logic puzzles. Knight “always tell the truth” Knave “always lie” You encounter two people A and B,What are A and B if A says “B is a knight” B says “ the two of us are opposite”
Propositional Logic • Logic Puzzles Let: p: “A is a knight“ q: “B is a knight“ p : “ A is a knave”q: “ B is a knave” A says “B is a knight” q B says “ the two of us are opposite” (p q) ( p q) If A is a knight Then q is true and (p q) ( p q) is true But (p q) ( p q) is false We can conclude that A is a knave
Propositional Logic • Logic Puzzles Let: p: “A is a knight“ q: “B is a knight“ p : “ A is a knave”q: “ B is a knave” A says “B is a knight” q B says “ the two of us are opposite” (p q) ( p q) If B is a knight(q is true) Then (p q) ( p q) is true andq is false We can conclude that B is a knave A and B are knaves
Propositional Logic • Logic and Bit operations A bit string is a sequence of zero or more bits. The length of this string is the number of bits in the string. 101010011 is a bit string of length nine • Bitwise OR(), Bitwise AND (), Bitwise XOR() 0 1 1 0 1 1 0 1 1 0 1 1 0 0 0 1 1 1 0 1 Bitwise OR 1 1 1 0 1 1 1 1 1 1 Bitwise AND 0 1 0 0 0 1 0 1 0 0 Bitwise XOR 1 0 1 0 1 0 1 0 1 1
Chapter 1 Exercises Pages (16-20) 1,3,6,7,9,10 12-14 (b,c) 15,17 20,22,24,25,26 27-33 (e) 36-38 48 50
Propositional Equivalences • Classification of compound propositions • A compound proposition that is always true is called a tautology.(p p) • A compound proposition that is always false is called a contradiction. (pp) • A compound proposition that is neither a tautology nor a contradiction is called a contingency.
Propositional Equivalences Logical equivalences compound propositions that have the same truth values in all possible cases are called Logically equivalent Compound propositions p and q are Logically equivalent ifpq isa tautology. logical equivalence Note and are not logical operators(connectives). Rather they indicate a kind of logical equality.
Propositional Equivalences Prove that [r(q(r p ))] r(pq) by using a truth table.
Propositional Equivalences Identity laws p T p p F p Domination laws p F F p T T Idempotent laws p p p p p p Double negation law(p) p Negation laws pp Tp p F Absorption laws p(pq) pp(p q) p Commutative laws p q q pp q q p Associative laws (pq)r p(qr) (pq)r p(qr) De Morgan’s laws(pq) pq (pq) pq Distributive laws p(qr) (pq)(pr) p(qr) (pq)(pr) T denotes the compound proposition that is always true F denotes the compound proposition that is always false
Propositional Equivalences p qp q (p q) pq p qq p p q p q p q (p q) (p q) (p r) p (q r ) (p q) (p r) p (q r ) (p r) (q r) (p q ) r (p r) (q r) (p q ) r p q (p q) (q p) p q p q p q (p q ) (p q ) (p q) p q
Propositional Equivalences Use De Morgan’s law to express the negation of “Ahmed has a mobile and he has a laptop” p: “Ahmed has a mobile” q: “Ahmed has a laptop” p q (pq) p q p: “Ahmed has not a mobile” q: “Ahmed has not a laptop” “Ahmed has not a mobile or he has not a laptop”
Propositional Equivalences Show that(p q) pq Show that (p ( p q)) pq Show that (p q) (p q) is a tautology
Chapter 1 Exercises Pages (28-30) 1(a,b,f) 4(b) 7,8 9(a,f) 11(a,f) 15 26,27
Predicates and Quantifiers Predicates “x is greater than 3” This statement is neither true nor false when the value of the variable is not specified. This statement has two pats The fist part (subject) is the variable x The second (predicate) is “is greater than 3” We can denote this statement by P(x) Where P denotes the predicate “is greater than 3” Once a value has been assigned to x, the statement P(x) becomes a proposition and has a truth value. P is called Proposition function.
Predicates and Quantifiers Predicates let P(x) denote “is greater than 3” What are the truth values of P(4) and P(2)? let Q(x,y) denote “x=y+3” What are the truth values of Q(1,2) and Q(3,0)? let R(x,y,z) denote “x+y=z” What are the truth values of R(1,2,3) and R(0,0,1)? P(x1,x2,x3,………,xn) P is called n-place(n-ary) predicate.
Predicates and Quantifiers Predicates let A(c,n) denote “computer c is connected to network n” Suppose that the computer MATH1 is connected to network CAMPUS2, but not to network CAMPUS1 What are the truth values of A(MATH1, CAMPUS1) and A(MATH1, CAMPUS2) ?
Predicates and Quantifiers Predicates Proposition functions(Predicates) occur in computer programs. If x>0 then x:=x+1 P(x) : “x>0” If P(x) is true the assignment is executed If P(x) is false the assignment is not executed
Predicates and Quantifiers Universal quantification Which tell us that a predicate is true for every element under consideration. existential quantification Which tell us that there is one or more element under consideration for which the predicate is true. The area of logic that deals with predicates and quantifiers is called predicate calculus.