1 / 33

CSC2110 Logic

CSC2110 Logic. Isaac Fung. Self Introduction. You can call me Isaac I am responsible for the tutorials of the first 3 weeks and the first homework Email: wsfung@cse.cuhk.edu.hk Office: HSB Room 115. Things you need to know. Checking equivalence of logical expressions

Download Presentation

CSC2110 Logic

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. CSC2110 Logic Isaac Fung

  2. Self Introduction • You can call me Isaac • I am responsible for the tutorials of the first 3 weeks and the first homework • Email: wsfung@cse.cuhk.edu.hk • Office: HSB Room 115

  3. Things you need to know • Checking equivalence of logical expressions • Evaluating, simplifying logical expressions • Writing negation, contrapositive of conditional statements • Checking whether an argument is valid • Making valid arguments • Understanding nested quantified statements

  4. Logical equivalence • Two expressions are equivalent if either both are true or both are false • (p ^ q) v r, p ^ (q v r) Check if their truth values are the same for all values of the variables (same in all rows)

  5. Equivalent or inequivalent?

  6. De Morgan’s law • ~(P ^ Q) = ~P v ~Q • Jesse is not a year one CS student • Jesse is not a year one student or Jesse is not a CS student • ~(P v Q) = ~P ^ ~Q • Eating or drinking is not allowed in the classroom • You can’t eat in the classroom and you can’t drink in the classroom

  7. Distributive law • Distributive law for arithmetic: a*b +a*c = a*(b+c) • (P ^ Q) v (P ^ R) = P ^ (Q v R) • Tom is a year one CS student or a year one Math student • Tom is a year one student and he studies CS or Math • (P v Q) ^ (P v R) = P v (Q ^ R) • Darek had hot dog or burger for lunch and he had burger or pizza for dinner • Darek had burger today or he had eaten both hot dog and pizza • Verify that (P ^ Q) v (P ^ R) v (P ^ S) = P ^ (Q v R v S) and (P v Q) ^ (P v R) ^ (P v S) = P v (Q ^ R ^ S) and generalize them

  8. Simplifying logical expressions • Use Thm 1.1.1 in textbook • e.g. “You can’t say that (I don’t love you and I want to break up). In fact, I love you or I break up with you” De Morgan’s law Distributive law ~q^q = F

  9. More examples De Morgan’s law De Morgan’s law Distributive law ~q ^ q = F or De Morgan’s law Distributive law q v ~q = T

  10. More examples De Morgan’s law Distributive law ~q v q = T

  11. Conditional statements • A conditional statement is false only when its assumption is true and its conclusion is false • Are they true? • If you eat orange, then you die someday • A conditional statement is true if the conclusion is true irrespective of its assumption • If you never die, then you do not eat orange • If the assumption is false, the conditional statement is automatically true • A conditional statement can be true even if the assumption and the conclusion are totally irrelevant

  12. Contrapositive • If P, then Q = If ~Q, then ~P • If it is a pig, it cannot fly • If it can fly, it is not a pig • If tutor is a human, he makes mistake • If tutor does not make mistake, he is not a human • Why? • “If P, then Q” is false only when P=T ^ Q=F • “If ~Q, then ~P” is false only when ~Q=T ^ ~P=F, which is same as P=T ^ Q=F

  13. Different forms of conditional statements • If P, then Q = P only if Q = Q if P • You can apply for grant/loan only if you are a student • If you apply for grant/loan, then you are a student • You are a student if you apply for grant/loan • If P, then Q = ~P v Q • If you take drugs, your life is ruined • Take no drugs or your life is ruined • If P, then Q =/= If Q, then P • If it is a bird, it can fly • If it can fly, it is a bird • Come up with your own examples! This form is especially useful for doing simplification X

  14. Negation of conditional statements • e.g. It is not true that if you work hard then you always get good results • ~ (P->Q) =/= P->~Q (negating the conclusion) • If you work hard, then you get bad results • ~ (P->Q) =/= Q->P (swapping the assumption and conclusion) • If you get good results, then you work hard • ~ (P->Q) =/= ~P->~Q (negating both assumpt. & conclus.) • If you don’t work hard, then you can’t get good results • ~ (P->Q) = P ^ ~Q • You work hard and you can still get bad results

  15. Many faces of conditional statements • Are they the same? • If it rains, I will stay • It rains only if I stay • It does not rain or I will stay • If I do not stay, it does not rain • How about the followings? • If it does not rain, I do not stay • If I stay, it rains • It rains or I will not stay • It rains and I do not stay (1), (2), (3) & (4) are equivalent (5)=(6)=(7)=/=(1) (8) is the negation of (1)

  16. Simplifying expression involving “if then” p->q = ~p v q Distributive law p^~p = F F v p = p ~(p->q) = p ^ ~q associative and commutative law q ^ ~q = F

  17. Proof by contrapositive • Why we need contrapositive? • We don’t know how to directly prove “For an integer n, if n2 is even, then n is even” but we can prove its contrapositive “For an integer n, if n is odd, n2 is odd” • Proof: Suppose n is odd, n = 2k+1 for some integer k. n2 = (2k+1)(2k+1) = 4k2+4k+1 = 2(2k2+2k)+1. So n2 is odd. • More examples in the next tutorial

  18. If and only if • “P if and only if Q” means “P->Q ^ Q->P” • ∆ABC~∆DEF iff AB/DE=BC/EF=CA/FD • ∆ABC~∆DEF if AB/DE=BC/EF=CA/FD and ∆ABC~∆DEF only if AB/DE=BC/EF=CA/FD • Are they the same? • P if and only if Q • P = Q • ~P if and only if ~Q • P->Q and Q->P • P->Q and ~P->~Q They are all equivalent

  19. Deduction and proof • Deduction means to make conclusion based on known facts • e.g. You meet some new face. • All you know is that this person is a med student in HK • You also know in HK, medic faculty is offered only in CUHK and HKU • Therefore you can conclude that this person studies at CUHK or HKU • Your conclusion will be correct if the 2 facts are indeed facts • An argument consists of assumptions and a conclusion • Definition: An argument is valid if the conclusion is true whenever the assumptions are all true • Therefore if an argument is valid and the assumptions are true, then the conclusion is true (otherwise the argument isn’t valid, right?) • So we can do deduction using valid arguments Assumption 1 Assumption 2 Conclusion Super important

  20. Valid arguments • e.g. You are rich or you have to work You are not rich Conclusion: You have to work • Is this valid? Conclusion Assumptions The 2nd row is the only row in which both assumptions are true, and the conclusion is true in this row, so it’s valid

  21. Invalid arguments • e.g. If it rains, I will stay • It does not rain • Conclusion: I will not stay Conclusion Assumptions If p then q ~p ~q The conclusion is false when the assumptions are true, so it is invalid

  22. Invalid arguments • You can show that an argument is invalid by giving ONE example such that the assumptions are true but the conclusion is false “We stay at home when it is good weather” does not contradicts the 1st statement as it says nothing about this case This example shows that there are values of P and Q such that “If p then q” and “~p” are true but “~q” can be false If weather is bad, then we will stay at home. The weather is good but still we stay at home. If p then q ~p ~q

  23. Logical deduction • Jane and Peter won’t both win the Math prize. • Peter wins either the Math prize or the Chem prize. • Jane wins the Math prize. • Which prize does Peter win? ~(J ^ P) (1) Either P or C (2) J (3) (1)^(3) -> ~P (4) (4)^(2) -> C

  24. Given the following information about a computer program, find the mistake in the program There is an undeclared variable or there is a syntax error If there is an syntax error, then a semicolon is missing or a variable name is misspelled There is not a missing semicolon There is not a misspelled variable name P v Q (1) Q->(R v S) (2) ~R (3) ~S (4) (3)^(4)=~(R v S) (5) (5)^(2) -> ~Q (6) (1)^(6) -> P Logical deduction

  25. Who owns the fish? • There are five houses in a row and in five different colors. • In each house lives a person from a different country. • Each person drinks a certain drink, plays a certain sport, and keeps a certain pet. • No two people drink the same drink, play the same sport, or keep the same pet. • The Brit lives in a red house The Swede keeps dogs The Dane drinks tea The green house is on the left of the white house The green house owner drinks coffee The person who plays polo rears birds The owner of the yellow house plays hockey The man living in the house right in the centre drinks milk The Norwegian lives in the first house The man who plays baseball lives next to the man who keeps cats The man who keeps horses lives next to the one who plays hockey The man who plays billiards drinks beer The German plays soccer The Norwegian lives next to the blue house The man who plays baseball has a neighbor who drinks water. Albert Einstein claimed that 98% of the world could not work it out. Can you?

  26. Valid arguments • A valid argument with a false assumption can give a false conclusion • e.g. • An invalid argument with a true conclusion • e.g. If Tom is good at academic, then Tom does not play sport Tom is good at academic Tom does not play sport if this assumption is false, then the conclusion can be anything If Darek lives in Japan for 10 years, he can speak Japanese Darek cannot speak Japanese Darek has not lived in Japan for 10 years

  27. Predicates • Predicates are statements with variables • If we substitute values in the domains into the variables, a predicate becomes either a true or a false statement • e.g. P(x) = “x>0” and the domain of x is the set of integers P(1) is true and P(-1) is false • A predicate can have several variables • e.g. P(x, y, z) = “xy=z” • The variables may have different domains • e.g. P(x, y) = “The height of x is y cm” domain of x is set of some objects, domain of y is the set of +ve real number

  28. Universal quantifier • Suppose x1, x2,x3… are the elements in the domain • x, P(x) is same as P(x1)^ P(x2)^ P(x3)^… e.g. “Every positive even number >2 is not a prime” = “4 is not a prime”^ “ 6 is not a prime”^“ 8 is not a prime…” So x, P(x) is true when every P(xi) is true and x, P(x) is false when at least one P(xi) is false • Are they true? • x in R, x2 ≠ -1 • All squares are quadrilaterals • n in Z, (n-1)/n is not an integer T, square of any real number >= 0 T F, (1-1)/1

  29. Existential quantifier • Similarly, x, P(x) is same as P(x1)v P(x2)v P(x3)v… So x, P(x) is true when at least one P(xi) is true and x, P(x) is false when every P(xi) is false • Are they true? • m in Z such that m2=m • There is at least one even prime number T, 12 = 1 T, e.g. 2

  30. Negation of quantified statements • By De Morgan’s law, ~(P(x1)^ P(x2)^ P(x3)^… ) = ~P(x1)v ~P(x2)v ~P(x3)v… so ~(x, P(x)) = x, ~P(x) Similarly ~(x, P(x)) = x, ~P(x), • Moving the negation from outside to inside and changing the type of quantifier will keep the same meaning e.g. “Not everyone can swim”=“someone cannot swim” “No human can fly”=“All human cannot fly” • Also ~(x, ~P(x)) = x, ~~P(x) = x, P(x) e.g. “Not everyone cannot swim”=“Someone can swim”

  31. Nested quantified statements Which of the following are true? •  item I,  student S, S chose I •  student S,  item I, S chose I •  student S,  item I, S chose I •  item I,  student S, S chose I •  item I, ~ student S, S chose I • ~ item I,  student S, S chose I •  item I,  student S, S does not choose I T, e.g. pie T, everyone chose sth F, no one chose everything T, all items are chosen F, negation of the 4. F, same as 5. F, same as 5, 6

  32. Nested quantified statements Which of the following are true? •  item I,  student S1,  student S2, S1=\=S2 ^ S1 chose I ^ S2 chose I •  student S,  stations Z,  item I in Z s.t. S does not choose I •  student S,  station Z,  item I in Z s.t. S chose I T, Both Tom and Jesse chose spaghetti F, Darek chose all items at the dessert station T, negation of last one

  33. Translating to logic notation • Translate the following into logic notations • x is an even-length string of 0’s • x does not contain both a 0 and a 1 • x is the binary representation of 2k+1 for some integer k>=1 • x, y, z are 01 strings • If x=01 & y=100, then xy=01100 y ((x=yy)^No-1s(y)) ~Substring(0,x) v No-1s(x) y (x=1y1)^No-1s(y)

More Related