1 / 143

Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

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

darrin
Download Presentation

Dr. Eng. Farag Elnagahy farahelnagahy@hotmail Office Phone: 67967

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. 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.

  3. 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.

  4. 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

  5. Propositional Logic New propositions, called compound propositions are formed from existing propositions using logical Operators

  6. 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

  7. 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”

  8. Propositional Logic conjunction Suppose p and q are propositions The conjunction of p and q is written as pq The proposition pq is read “p and q” Truth table for the Conjunction of two propositions pq

  9. 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

  10. Propositional Logic disjunction • Inclusive Or • Suppose p and q are propositions • The disjunction of p and q is written as pq • The proposition pq is read “p or q” Truth table for the Disjunction (Inclusive Or) of two propositions pq

  11. 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

  12. Propositional Logic disjunction • Exclusive Or • Suppose p and q are propositions • The Exclusive Or of p and q is written as pq • The proposition pq is read “p or q but not both” Truth table for the Exclusive Orof two propositions pq (pq) (pq)

  13. Propositional Logic disjunction • Exclusive Or • “Tonight I will stay home or go out to a movie.”

  14. Propositional Logic implication Suppose p and q are propositions The conditional statement (implication) pq The proposition pq is read “ ifp, then q” P hypothesis – antecedent – premise q conclusion -consequence Truth table for the Implication pq p q

  15. Propositional Logic implication Terminology used to express pq “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”

  16. Propositional Logic implication p is the proposition “Ahmed learns discrete mathematics” q is the proposition “Ahmed will find a good job” The pq 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

  17. Propositional Logic implication p is the proposition “today is Friday” q is the proposition “2+3=5” The pq is proposition “ if today is Friday, then 2+3=5” This proposition Is true becauseits Conclusion (q) is true“

  18. Propositional Logic implication p is the proposition “today is Friday” q is the proposition “2+3=6” The pq is proposition “ if today is Friday, then 2+3=6” This proposition Is true every day except Friday

  19. Propositional Logic implication The conditional statement (implication) pq “if it is raining, then the home team wins” q p is called contrapositive of pq “if the home team does not win, then it is not raining” The proposition qp is called converse of pq “if the home team wins, then it is raining” p q is called inverse of pq “if it is not raining, then the home team does not win”

  20. Propositional Logic bi-implication Suppose p and q are propositions The biconditional statement (bi-implication) pq The proposition p  q is read “ p if and only if q” p  q is true if both pq  qp are true pq  pq ------- pq Truth table for the Bi-implication pq (p q )  (p q )

  21. Propositional Logic bi-implication The proposition p  q has the same truth value as pq  qp

  22. 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”

  23. Propositional Logic Truth table of compound propositions • Precedence of logical operators     

  24. Propositional Logic Truth table of compound propositions Construct the Truth table of compound propositions (p  q)  (p  q)

  25. 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)

  26. 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.

  27. 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

  28. 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 pq

  29. Propositional Logic • Translating English sentence into a logical expression (System specifications) p  q p pq system specifications are consistent

  30. 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 pq q

  31. Propositional Logic • Translating English sentence into a logical expression (System specifications) p  q p pq q system specifications are inconsistent

  32. 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).

  33. 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”

  34. 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

  35. 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

  36. 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

  37. 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

  38. 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. (pp) • A compound proposition that is neither a tautology nor a contradiction is called a contingency.

  39. 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 ifpq isa tautology. logical equivalence   Note  and  are not logical operators(connectives). Rather they indicate a kind of logical equality.

  40. Propositional Equivalences Prove that [r(q(r  p ))]  r(pq) by using a truth table.

  41. 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 pp  Tp p  F Absorption laws p(pq)  pp(p  q)  p Commutative laws p  q  q  pp  q  q  p Associative laws (pq)r  p(qr) (pq)r  p(qr) De Morgan’s laws(pq)  pq (pq)  pq Distributive laws p(qr)  (pq)(pr) p(qr)  (pq)(pr) T denotes the compound proposition that is always true F denotes the compound proposition that is always false

  42. Propositional Equivalences p  qp q (p q) pq p  qq  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

  43. 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 (pq)  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”

  44. Propositional Equivalences      Show that(p  q) pq Show that (p ( p  q)) pq Show that (p  q)  (p  q) is a tautology

  45. Chapter 1 Exercises Pages (28-30) 1(a,b,f) 4(b) 7,8 9(a,f) 11(a,f) 15 26,27

  46. 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.

  47. 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.

  48. 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) ?

  49. 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

  50. 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.

More Related