CSC2110 Logic - PowerPoint PPT Presentation

1 / 33
About This Presentation
Title:

CSC2110 Logic

Description:

Jesse is not a year one CS student. Jesse is not a year one student or Jesse is not a CS student ... Jane and Peter won't both win the Math prize. ... – PowerPoint PPT presentation

Number of Views:149
Avg rating:3.0/5.0
Slides: 34
Provided by: CSE
Category:
Tags: csc2110 | jane | jesse | logic

less

Transcript and Presenter's Notes

Title: CSC2110 Logic


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_at_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 Morgans 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 cant eat in the classroom and you cant
    drink in the classroom

7
Distributive law
  • Distributive law for arithmetic
  • ab ac a(bc)
  • (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 cant say that (I dont love you and I
    want to break up). In fact, I love you or I break
    up with you

De Morgans law
Distributive law
qq F
9
More examples
De Morgans law
De Morgans law
Distributive law
q q F
or
De Morgans law
Distributive law
q v q T
10
More examples
De Morgans 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 PT QF
  • If Q, then P is false only when QT PF,
  • which is same as PT QF

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 dont work hard, then you cant 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
pp 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 dont 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 2k1 for some integer k.
    n2 (2k1)(2k1) 4k24k1 2(2k22k)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/DEBC/EFCA/FD
  • ?ABC?DEF if AB/DEBC/EFCA/FD and
  • ?ABC?DEF only if AB/DEBC/EFCA/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 isnt 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?

Assumptions
Conclusion
The 2nd row is the only row in which both
assumptions are true,
and the conclusion is true in this row, so its
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
(J P) (1) Either P or C (2) J (3) (1)(3)
- P (4) (4)(2) - C
  • Jane and Peter wont 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?

24
Logical deduction
  • 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

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) x0 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) xyz
  • 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 Morgans 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 swimsomeone cannot
    swim
  • No human can flyAll human cannot fly
  • Also (?x, P(x)) ?x, P(x) ?x, P(x)
  • e.g. Not everyone cannot swimSomeone 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
  • x, y, z are 01 strings
  • If x01 y100, then xy01100
  • Translate the following into logic notations
  • x is an even-length string of 0s
  • x does not contain both a 0 and a 1
  • x is the binary representation of 2k1 for some
    integer k1

?y ((xyy)No-1s(y))
Substring(0,x) v No-1s(x)
?y (x1y1)No-1s(y)
Write a Comment
User Comments (0)
About PowerShow.com