For your revisions, you have effectively unlimited resources: time, the text, writing code, coming to my office hours. Your revision, therefore, should be flawless. Be careful and thorough.
If you earned a Revision Needed or No Evidence mark for the probability problems on exam 2, the revision process is the same as for exam 1: on a separate sheet of paper, correctly answer the probability-related questions, and also answer this reflection:
What mistakes did you make? What concepts did you not correctly understand?
Submit your original exam and your revision.
Many students struggled with the logic topics. If you earned some combination of Revision Needed or No Evidence marks for the oral component of exam 2, or for the logic-related part of the written exam, complete the exercises below and your mark will be revised to Meets Requirements. Everyone else is welcome and encouraged to complete these – my hope is that you’re motivated not just to get better with the content of the course, but because you find these topics interesting, and perhaps delightfully mind-bending.
If you do quite enjoy this kind of logic stuff, you should definitely check out CSCI 333 Theory of Computation. We don’t have a formal Mathematical Logic course (unlike, say, Math 571 at my undergrad alma mater or MATH5165 at my graduate alma mater) but perhaps a topics course could be spun up.
All of you are quite good at the everyday reasoning and inference process involved in, say, concluding that such-and-such a square in a wumpus world grid has a pit, or gold. But what are the actual logical steps you take when performing that reasoning? Intuitive leaps are fine for people, but not for computers. We want to break down that process and appreciate how to turn it into a sequence of small, completely justified steps, and how we might make a computer program that can produce such sequences of steps automatically.
A step is one rule, applied once, to lines you name. You can use ∧ and ∨ as n-ary operators. Commutativity and associativity hold, so you can rearrange their order and grouping “for free”.
| Code | Rule | Form |
|---|---|---|
| Given | in the KB or perceived | |
| BE | biconditional elimination | α ⇔ β ⊢ (α ⇒ β) ∧ (β ⇒ α) |
| AE | and-elimination | α ∧ β ⊢ α |
| AI | and-introduction | α, β ⊢ α ∧ β |
| OI | or-introduction | α ⊢ α ∨ β |
| MP | modus ponens | α ⇒ β, α ⊢ β |
| CP | contraposition | α ⇒ β ⊢ ¬β ⇒ ¬α |
| DN | double negation | ¬¬α ⊣⊢ α |
| IE | implication elimination | α ⇒ β ⊣⊢ ¬α ∨ β |
| DM | De Morgan | ¬(α ∨ β) ⊣⊢ ¬α ∧ ¬β; ¬(α ∧ β) ⊣⊢ ¬α ∨ ¬β |
| UR | unit resolution | α ∨ ℓ, ¬ℓ ⊢ α |
| RES | resolution (from set 2 on) | α ∨ ℓ, β ∨ ¬ℓ ⊢ α ∨ β |
Here is wumpus world board A. The agent has perceived the following:
col 1 col 2 col 3 col 4
row 4 | | ? | | |
row 3 | pit | stench, breeze | | |
row 2 | | | no stench | |
row 1 | | | | |
Here is the associated KB. “Sij” refers to a stench in
square (i, j). (We will use an (x, y) coordinate order – column, row.)
Similarly for W (the wumpus), P (a pit), and B (a breeze).
| rule | statement |
|---|---|
| A1 | S23 ⇔ W13 ∨ W22 ∨ W33 ∨ W24 |
| A2 | S32 ⇔ W22 ∨ W33 ∨ W31 ∨ W42 |
| A3 | W13 ⇒ ¬P13 |
| A4 | S23 |
| A5 | ¬S32 |
| A6 | P13 |
A fellow student looks at the above board, and reasons thus:
There’s a stench in square (2,3) so the wumpus is next to it. It can’t be at (2,2) or (3,3), because (3,2) doesn’t stink. It can’t be at (1,3), because there’s a pit there. So the wumpus is at (2,4).
As a warmup, you’ll “decompress” that.
Before anything else, predict how many atomic steps that paragraph contains.
Mark every so, because, and can’t. For each one, say which sentence of the KB it silently uses.
When you’ve done that, expand to see the systematic proof. Compare the number of atomic steps you predicted and which rules you said are used.
| Line # | Statement | Reason |
|---|---|---|
| 1-6 | A1 to A6 | Given |
| 7 | (S32 ⇒ W22 ∨ W33 ∨ W31 ∨ W42) ∧ (W22 ∨ W33 ∨ W31 ∨ W42 ⇒ S32) | BE on line 2 |
| 8 | W22 ∨ W33 ∨ W31 ∨ W42 ⇒ S32 | AE 7 |
| 9 | ¬S32 ⇒ ¬(W22 ∨ W33 ∨ W31 ∨ W42) | CP 8 |
| 10 | ¬(W22 ∨ W33 ∨ W31 ∨ W42) | MP 9, 5 |
| 11 | ¬W22 ∧ ¬W33 ∧ ¬W31 ∧ ¬W42 | DM 10 |
| 12 | ¬W22 | AE 11 |
| 13 | ¬W33 | AE 11 |
| 14 | ¬¬P13 ⇒ ¬W13 | CP 3 |
| 15 | ¬¬P13 | DN 6 |
| 16 | ¬W13 | MP 14, 15 |
| 17 | (S23 ⇒ W13 ∨ W22 ∨ W33 ∨ W24) ∧ (W13 ∨ W22 ∨ W33 ∨ W24 ⇒ S23) | BE 1 |
| 18 | S23 ⇒ W13 ∨ W22 ∨ W33 ∨ W24 | AE 17 |
| 19 | W13 ∨ W22 ∨ W33 ∨ W24 | MP 18, 4 |
| 20 | W22 ∨ W33 ∨ W24 | UR 19, 16 |
| 21 | W33 ∨ W24 | UR 20, 12 |
| 22 | W24 | UR 21, 13 |
Study the above. Think of how the computer could accomplish each of those steps.
two proofs. Now it’s your turn to work out these kind of rigorous, structured proofs.
Here’s the proof from the day 8 slides, but without any reasons.
| # | Statement | Reason |
|---|---|---|
| 1 | ¬B12 | Given |
| 2 | B12 ⇔ P13 ∨ P11 ∨ P22 | Given |
| 3 | (B12 ⇒ P13 ∨ P11 ∨ P22) ∧ (P13 ∨ P11 ∨ P22 ⇒ B12) | |
| 4 | P13 ∨ P11 ∨ P22 ⇒ B12 | |
| 5 | ¬B12 ⇒ ¬(P13 ∨ P11 ∨ P22) | |
| 6 | ¬(P13 ∨ P11 ∨ P22) | |
| 7 | ¬P13 ∧ ¬P11 ∧ ¬P22 | |
| 8 | ¬P22 |
Provide the reasons for lines 3 to 8. A reason is one of the rules from above – you can write it out or use the two-letter code.
Also: say why line 4 picks the conjunct it does, and not the other one.
Did you have to actually know the semantics for things like “P22” or “B12” to provide those reasons? What does that mean for our goal to make a computer do this inference?
Now the other way around: fill in the missing statements. The
goal is P31.
| # | Statement | Reason |
|---|---|---|
| 1 | B21 ⇔ P11 ∨ P22 ∨ P31 | Given |
| 2 | B12 ⇔ P11 ∨ P13 ∨ P22 | Given |
| 3 | B21 | Given |
| 4 | ¬B12 | Given |
| 5 | ¬P11 | Given |
| 6 | BE 1 | |
| 7 | AE 6 (the half with B21 on the left) | |
| 8 | MP 7, 3 | |
| 9 | UR 8, 5 | |
| 10 | BE 2 | |
| 11 | AE 10 (the half with B12 on the right) | |
| 12 | CP 11 | |
| 13 | MP 12, 4 | |
| 14 | DM 13 | |
| 15 | AE 14 | |
| 16 | UR 9, 15 |
demonstrating soundness. A rule is sound if the conclusion logically follows from the premises. Use this reasoning strategy:
“Take an arbitrary model for which all the premises are true. [Reason about such models.] So the conclusion is true for any such model. Since the model was arbitrary, the conclusions hold whenever the premises do, so the rule is sound.”
Use that to justify:
and-elimination
A ∨ B, ¬A ⊨ B
trace the unification algorithm
For each pair, provide a θ that unifies them or say why no such substitution exists and show how the unification algorithm does that – in other words, trace the execution of the algorithm for the pair. Recall the tracing tool I showed in class.
has(S13, Pit) ~ has(t, Pit)
has(S13, Pit) ~ has(t, Wumpus)
Knows(John, x) ~ Knows(x, Elizabeth). Those come from these two universally quantified sentences:
∀ x : Knows(John, x)
∀ x : Knows(x, Elizabeth)
Should they be able to match? What’s the fix?
Near(x, Left(x)) ~ Near(Left(y), y)
These problems concern the first-order logic sentence from the Alex problem:
\(∃ p ∈ P : ∀ f ∈ F : ¬ \mathrm{likes}(\mathrm{Alex}, f) ⇒ \mathrm{likes}(p, f)\)
(\(P\) a set of people; \(F\) a set of foods.)
Make a model for which the given sentence is true. Start with this setup: there’s three people: Alex, Dan, and Teresa, and these foods, Apple, Banana, Cherry, and Durian. (We are using the convention that capitalized words are symbols referring to specific objects in our model, and lowercase words/letters are variables.) Alex likes Banana and Durian. So we have
P = {Alex, Dan, Teresa}
F = {Apple, Banana, Cherry, Durian}
and the relation “likes” which may be viewed as a set of (person, food) pairs: the starting point is
{ (Alex, Banana), (Alex, Durian) }
You can also use the term predicate and view the relation as a function that returns true or false.
Define values for “likes” in the table that make the given sentence true. Explain why the sentence is true in your model.
person Apple Banana Cherry Durian Alex ⊥ ⊤ ⊥ ⊤ Dan ? ? ? ? Teresa ? ? ? ?
Here I’m using “⊥” for “false” and “⊤” for “true” – that is, the
relation likes(Alex, Apple) does not hold (or: the
predicate likes(Alex, Apple) evaluates to false), and
likes(Alex, Banana) does hold.
The most common mistake on this problem was reversing the quantification. (A variant mistake was seeming to ignore the quantifications entirely.) “∀” and “∃” do not commute! To see this: compare
\(∀ x : ∃ y : f(x) < y\)
\(∃ y : ∀ x : f(x) < y\)
where \(x\) and \(y\) are real numbers and \(f(x)\) is an ordinary mathematical function. Consider the two specific examples \(f(x) = \sqrt{x}\) and \(f(x) = \sin(x)\). Explain why one of those sentences is true for both function, and the other only holds for one of them.
(optional): is hot
dog is prime
For each of these, predict which \(n\) between 0 and 13 will satisfy the sentence. (For both, \(k\) ranges over ℕ.) Then write some code and see if that logical statement is true for prime numbers and false otherwise. If it mis-identifies any primes or non-primes, explain why.
You can use this starter code or write your own.
def divides(k, n):
if k == 0:
return n == 0
else:
return n % k == 0
def test_statement_N(n, k):
# any necessary setup code
# this should be all nonnegative integers; we'll approximate it by
# looking from 0 to 100.
for k in range(0, 100):
pass
# test the condition
# if it's "∀ k", how do you use the result of the test to
# figure out your return value?
# what about "∃ k"?
def run_tests():
claimed_to_be_prime = [n for n in range(14) if your_test_statement(n) ]
return claimed_to_be_prime