CS 2742 (Logic in Computer Science) - Fall 2011: Antonina Kolokolova
CS 2742 (Logic in Computer Science) - Fall 2011: Antonina Kolokolova
CS 2742 (Logic in Computer Science) - Fall 2011: Antonina Kolokolova
Lecture 2
Antonina Kolokolova
September 9, 2011
1.1
Truth tables
Recall the puzzle about twin brothers from last class. It turns out that the question that
allows us to find out the name of the twin in front of us is Is John lying?. Let us consider
all possible situations:
1) Suppose that we met John and John tells the truth. Then he will truthfully reply
No.
2) Suppose that we met John and John lies. Then he will also say No: No, I am not
a liar, its the other guy!
3) Now suppose that we met Jim and Jim tells the truth. Then he will truthfully reply
Yes, since the other brother is the liar.
4) Finally, suppose that we met Jim, and Jim is the liar. Then he will also say Yes:
Yes, it is John who is the liar!
So as you see if the answer was No then it must have been John and if the answer was
Yes then it must have been Jim. Note that here we only learn what is the name of the
brother, not whether he lies or not. Also, you can check that Are you John? does not give
you an answer to this question.
We can write it as a table as follows. Let the propositional variable p denote this is John,
and the propositional variable q denote John tells the truth.
T
T
F
F
T
F
T
F
p q
(p implies q)
T
F
T
T
p q
(p and q)
T
F
F
F
p q
(p or q)
T
T
T
F
p
(not p)
F
F
T
T
p
(contradiction)
F
F
F
F
p p
(tautology)
T
T
T
T
So you can see that the answer to Is John lying? is the negation of This is John.
Definition 1 A truth assignment (to variables in a formulas) is an assignment of values
true/false to every variable.
When values of all variables are known, it is possible to calculate the truth value of the whole
formula, according to rules for logical connectives from the table above.
A truth assignment satisfies a formula if the formula evaluates to true under this assignment.
A formula is satisfiable if such a truth assignment exists. If a formula is not satisfiable by any
truth assignment, we call it a contradiction. If a formula is true under all truth assignments,
we call it a tautology.
To be more formal, we would define a propositional formula by structural induction, that is,
by saying that a proposition is a propositional formula, negation of a formula is a formula,
and two formulas connected by , , or other logical connective is also a formula. That
immediately gives us a way to evaluate propositional formulas starting from the propositions
and evaluating the truth values of the connectives according to the rules in the table above.
Example 1 (It is either not raining, or it is cloudy), and today is Monday.
Lets set p: it is raining, q: it is cloudy and r: today is Monday. Then (setting the
parentheses as above) the formula can be written as (p q) r. Today is Monday, it is
cloudy but not raining. So p is false, q is true and r is true. Then p is true, making the
true. And r is also true, making the true. The whole formula is, thus, true. Now suppose
it is raining, not cloudy and today is Monday (p = T, q = F, r = T ). In this case, both p
5
and q are false, so p q is false, and therefore the whole formula is false. Thus, this formula
is neither a tautology nor a contradiction.
How to evaluate logic formulas? Similar to arithmetic formulas, with being a as in
5, a and a +. Precedence rules: over , over , over . Otherwise, use
parentheses.
1.2
q
T
T
F
F
T
T
F
F
r p
T F
F F
T F
F F
T T
F T
T T
F T
(p q) (p q) r
T
T
T
F
F
F
F
F
T
T
T
F
T
T
T
F
Puzzle 2 (Knights and knaves 1) Some remote island is populated by two kinds of people: knights, who always tell the truth, and knaves, who always lie. Suppose you met two
islanders, call them A and B, and you hear A saying at least one of us is a knave. Can
you tell which of A and B is a knight and which is a knave?