csc2110 logic
DESCRIPTION
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: [email protected] Office: HSB Room 115. Things you need to know. Checking equivalence of logical expressions - PowerPoint PPT PresentationTRANSCRIPT
CSC2110 CSC2110 LogicLogic
Isaac FungIsaac Fung
Self IntroductionSelf Introduction• You can call me Isaac
• I am responsible for the tutorials of the first 3 weeks and the first homework
• Email: [email protected]
• Office: HSB Room 115
Things you need to knowThings 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
Logical equivalenceLogical equivalence• Two expressions are equivalent if either both are true or
both are false
• (p ^ q) v r, p ^ (q v r)
p q r p ^ q q v r (p ^ q) v r p ^ (q v r)
T T T T T T TT T F T T T TT F T F T T T
T F F F F F FF T T F T T FF T F F T F FF F T F T T FF F F F F F F
Check if their truth values are the same for all values of the variables (same in all rows)
Equivalent or inequivalent?Equivalent or inequivalent?
p ~p p ^ ~p F
T F F FF T F F
p q p ^ q ~p ~q ~(p ^ q) ~p ^ ~q
T T T F F F FT F F F T T FF T F T F T FF F F T T T T
p p v T
T TF F
De Morgan’s lawDe 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
Distributive lawDistributive 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
Simplifying logical expressionsSimplifying 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”
p
Fp
qqp
qpqp
qpqp
)(~
)()~(
)()(~~
De Morgan’s law
Distributive law
~q^q = F
More examplesMore examples
p
Fp
qqp
qpqp
qpqp
qpqp
~
)(~
))(~(~
))()~((~
)(~)~(~
)~(~)~(~
De Morgan’s law
De Morgan’s law
Distributive law
~q ^ q = F
p
Tp
qqp
qpqp
qpqp
~
~
)~(~
)~(~)(~
)~(~)~(~
De Morgan’s law
Distributive law
q v ~q = T
or
More examplesMore examples
p
Tp
qqp
qpqp
qpqpp
qpqpp
)(~
)()~(
)())~((
)()))(~(~(
De Morgan’s law
Distributive law
~q v q = T
Conditional statementsConditional 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
ContrapositiveContrapositive• 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
Different forms of conditional statementsDifferent 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!
X
This form is especially useful for doing simplification
Negation of conditional statementsNegation 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
Many faces of conditional statementsMany faces of conditional statements
• Are they the same?1. If it rains, I will stay2. It rains only if I stay3. It does not rain or I will stay4. If I do not stay, it does not rain
• How about the followings?5. If it does not rain, I do not stay6. If I stay, it rains7. It rains or I will not stay8. It rains and I do not stay
(1), (2), (3) & (4) are equivalent
(5)=(6)=(7)=/=(1)
(8) is the negation of (1)
Simplifying expression involving “if then”Simplifying expression involving “if then”
qp
qpF
qppp
qpp
qpp
)(
)()~(
)(~
)(
p->q = ~p v q
Distributive law
p^~p = F
F v p = p
F
Fp
qqp
qpq
qpq
~
)~(
)(~
~(p->q) = p ^ ~q
associative and commutative law
q ^ ~q = F
Proof by contrapositiveProof 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
If and only ifIf 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
Deduction and proofDeduction 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
Super important
Assumption 1
Assumption 2
Conclusion
Valid argumentsValid arguments• e.g. You are rich or you have to work
You are not richConclusion: You have to work
• Is this valid?
The 2nd row is the only row in which both assumptions are true,
p q p v q ~q
T T T F
T F T T
F T T F
F F F T
AssumptionsConclusion
and the conclusion is true in this row, so it’s valid
Invalid argumentsInvalid arguments
If p then q~p~q
p q p -> q ~p ~q
T T T F F
T F T F T
F T T T F
F F F T T
Assumptions Conclusion
The conclusion is false when the assumptions are true, so it is invalid
• e.g. If it rains, I will stayIt does not rainConclusion: I will not stay
Invalid argumentsInvalid arguments• You can show that an argument is invalid by giving ONE
example such that the assumptions are true but the conclusion is 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
“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
Logical deductionLogical 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
Logical deductionLogical 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
Who owns the fish?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?
Valid argumentsValid 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 Darek lives in Japan for 10 years, he can speak Japanese
Darek cannot speak Japanese
Darek has not lived in Japan for 10 years
if this assumption is false, then the conclusion can be anything
PredicatesPredicates• 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
Universal quantifierUniversal 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
TF, (1-1)/1
Existential quantifierExistential 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
Negation of quantified statementsNegation 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 meaninge.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”
Nested quantified statementsNested quantified statements
Which of the following are true?1. item I, student S, S chose I2. student S, item I, S chose I3. student S, item I, S chose I4. item I, student S, S chose I5. item I, ~ student S, S chose I6. ~ item I, student S, S chose I7. item I, student S, S does not choose I
salad main course dessert beverage
green salad
fruit salad
spaghetti fish pie cake milk soda coffee
Tom * * * *
Darek * * * * * *
Jesse * * * *
T, e.g. pieT, everyone chose sth
F, no one chose everything
T, all items are chosenF, negation of the 4.
F, same as 5.F, same as 5, 6
Nested quantified statementsNested 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
salad main course dessert beverage
green salad
fruit salad
spaghetti fish pie cake milk soda coffee
Tom * * * *
Darek * * * * * *
Jesse * * * *
T, Both Tom and Jesse chose spaghetti
F, Darek chose all items at the dessert station
T, negation of last one
Translating to logic notationTranslating 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
Meaning Logic notation Name
x is a prefix of y z (xz=y) Prefix(x,y)
x is a substring of y u v (uxv=y) Substring(x,y)
x is empty or a string of 0’s ~Substring(1,x) No-1s(x)
• 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)