Chapter 7: Logical Agents — Exercises
Chapter 7: Logical Agents¶
Russell & Norvig, Artificial Intelligence: A Modern Approach (4th ed.), end-of-chapter Exercise prompts — full text is included on this site (same material as the exercises/ch07/ sources in the aima monorepo).
Exercise 7.1¶
Suppose the agent has progressed to the point shown in
Figure wumpus-seq35-figure(a), page wumpus-seq35-figure,
having perceived nothing in [1,1], a breeze in [2,1], and a stench
in [1,2], and is now concerned with the contents of [1,3], [2,2],
and [3,1]. Each of these can contain a pit, and at most one can
contain a wumpus. Following the example of
Figure wumpus
= “There is no pit in [2,2].”
= “There is a wumpus in [1,3].”
Hence show that and .
Exercise 7.2¶
(Adapted from Barwise+Etchemendy:1993 .) Given the following, can you prove that the unicorn is
mythical? How about magical? Horned?
Note: If the unicorn is mythical, then it is immortal, but if it is not mythical, then it is a mortal mammal. If the unicorn is either immortal or a mammal, then it is horned. The unicorn is magical if it is horned.
Exercise 7.3¶
Consider the problem of deciding whether a
propositional logic sentence is true in a given model.
Write a recursive algorithm PL-True? that returns if and only if the sentence is true in the model (where assigns a truth value for every symbol in ). The algorithm should run in time linear in the size of the sentence. (Alternatively, use a version of this function from the online code repository.)
Give three examples of sentences that can be determined to be true or false in a partial model that does not specify a truth value for some of the symbols.
Show that the truth value (if any) of a sentence in a partial model cannot be determined efficiently in general.
Modify your algorithm so that it can sometimes judge truth from partial models, while retaining its recursive structure and linear run time. Give three examples of sentences whose truth in a partial model is not detected by your algorithm.
Investigate whether the modified algorithm makes more efficient.
Exercise 7.4¶
Which of the following are correct?
.
.
.
.
.
.
.
.
.
is satisfiable.
is satisfiable.
has the same number of models as for any fixed set of proposition symbols that includes , , .
Exercise 7.5¶
Which of the following are correct?
.
.
.
.
.
.
.
is satisfiable.
.
.
is satisfiable.
has the same number of models as for any fixed set of proposition symbols that includes , , .
Exercise 7.6¶
Prove each of the following assertions:
is valid if and only if .
For any , .
if and only if the sentence is valid.
if and only if the sentence is valid.
if and only if the sentence is unsatisfiable.
Exercise 7.7¶
Prove, or find a counterexample to, each of the following assertions:
If or (or both) then
If then or (or both).
If then or (or both).
Exercise 7.8¶
Prove, or find a counterexample to, each of the following assertions:
If or (or both) then
If then and .
If then or (or both).
Exercise 7.9¶
Consider a vocabulary with only four propositions, , , , and
. How many models are there for the following sentences?
.
.
.
Exercise 7.10¶
We have defined four binary logical connectives.
Are there any others that might be useful?
How many binary connectives can there be?
Why are some of them not very useful?
Exercise 7.11¶
Using a method of your choice, verify
each of the equivalences in
Table logical
Exercise 7.12¶
Decide whether each of the following
sentences is valid, unsatisfiable, or neither. Verify your decisions
using truth tables or the equivalence rules of
Table logical
Exercise 7.13¶
Decide whether each of the following
sentences is valid, unsatisfiable, or neither. Verify your decisions
using truth tables or the equivalence rules of
Table logical
Exercise 7.14¶
Any propositional logic sentence is logically equivalent to the assertion that each possible world in which it would be false is not the case. From this observation, prove that any sentence can be written in CNF.
Exercise 7.15¶
Use resolution to prove the sentence from the
clauses in Exercise convert
Exercise 7.16¶
This exercise looks into the relationship between
clauses and implication sentences.
Show that the clause is logically equivalent to the implication sentence .
Show that every clause (regardless of the number of positive literals) can be written in the form , where the s and s are proposition symbols. A knowledge base consisting of such sentences is in implicative normal form or Kowalski form Kowalski:1979.
Write down the full resolution rule for sentences in implicative normal form.
Exercise 7.17¶
According to some political pundits, a person who is radical () is
electable () if he/she is conservative (), but otherwise is not
electable.
Which of the following are correct representations of this assertion?
Which of the sentences in (a) can be expressed in Horn form?
Exercise 7.18¶
This question considers representing satisfiability (SAT) problems as
CSPs.
Draw the constraint graph corresponding to the SAT problem
for the particular case .
How many solutions are there for this general SAT problem as a function of ?
Suppose we apply {Backtracking-Search} (page backtracking
-search -algorithm) to find all solutions to a SAT CSP of the type given in (a). (To find all solutions to a CSP, we simply modify the basic algorithm so it continues searching after each solution is found.) Assume that variables are ordered and is ordered before . How much time will the algorithm take to terminate? (Write an expression as a function of .) We know that SAT problems in Horn form can be solved in linear time by forward chaining (unit propagation). We also know that every tree-structured binary CSP with discrete, finite domains can be solved in time linear in the number of variables (Section csp
-structure -section). Are these two facts connected? Discuss.
Exercise 7.19¶
This question considers representing satisfiability (SAT) problems as
CSPs.
Draw the constraint graph corresponding to the SAT problem
for the particular case .
How many solutions are there for this general SAT problem as a function of ?
Suppose we apply {Backtracking-Search} (page backtracking
-search -algorithm) to find all solutions to a SAT CSP of the type given in (a). (To find all solutions to a CSP, we simply modify the basic algorithm so it continues searching after each solution is found.) Assume that variables are ordered and is ordered before . How much time will the algorithm take to terminate? (Write an expression as a function of .) We know that SAT problems in Horn form can be solved in linear time by forward chaining (unit propagation). We also know that every tree-structured binary CSP with discrete, finite domains can be solved in time linear in the number of variables (Section csp
-structure -section). Are these two facts connected? Discuss.
Exercise 7.20¶
Explain why every nonempty propositional clause, by itself, is satisfiable. Prove rigorously that every set of five 3-SAT clauses is satisfiable, provided that each clause mentions exactly three distinct variables. What is the smallest set of such clauses that is unsatisfiable? Construct such a set.
Exercise 7.21¶
A propositional 2-CNF expression is a conjunction of clauses, each containing exactly 2 literals, e.g.,
Prove using resolution that the above sentence entails .
Two clauses are semantically distinct if they are not logically equivalent. How many semantically distinct 2-CNF clauses can be constructed from proposition symbols?
Using your answer to (b), prove that propositional resolution always terminates in time polynomial in given a 2-CNF sentence containing no more than distinct symbols.
Explain why your argument in (c) does not apply to 3-CNF.
Exercise 7.22¶
Prove each of the following assertions:
Every pair of propositional clauses either has no resolvents, or all their resolvents are logically equivalent.
There is no clause that, when resolved with itself, yields (after factoring) the clause .
If a propositional clause can be resolved with a copy of itself, it must be logically equivalent to .
Exercise 7.23¶
Consider the following sentence:
Determine, using enumeration, whether this sentence is valid, satisfiable (but not valid), or unsatisfiable.
Convert the left-hand and right-hand sides of the main implication into CNF, showing each step, and explain how the results confirm your answer to (a).
Prove your answer to (a) using resolution.
Exercise 7.24¶
A sentence is in disjunctive normal form(DNF) if it is the disjunction of
conjunctions of literals. For example, the sentence
is in DNF.
Any propositional logic sentence is logically equivalent to the assertion that some possible world in which it would be true is in fact the case. From this observation, prove that any sentence can be written in DNF.
Construct an algorithm that converts any sentence in propositional logic into DNF. (Hint: The algorithm is similar to the algorithm for conversion to CNF iven in Sectio pl
-resolution -section.) Construct a simple algorithm that takes as input a sentence in DNF and returns a satisfying assignment if one exists, or reports that no satisfying assignment exists.
Apply the algorithms in (b) and (c) to the following set of sentences:
Since the algorithm in (b) is very similar to the algorithm for conversion to CNF, and since the algorithm in (c) is much simpler than any algorithm for solving a set of sentences in CNF, why is this technique not used in automated reasoning?
Exercise 7.25¶
Convert the following set of sentences to
clausal form.
S1: .
S2: .
S3: .
S4: .
S5: .
S6:
Give a trace of the execution of DPLL on the conjunction of these clauses.
Exercise 7.26¶
Convert the following set of sentences to
clausal form.
S1: .
S2: .
S3: .
S4: .
S5: .
S6:
Give a trace of the execution of DPLL on the conjunction of these clauses.
Exercise 7.27¶
Is a randomly generated 4-CNF sentence with symbols and clauses more or less likely to be solvable than a randomly generated 3-CNF sentence with symbols and clauses? Explain.
Exercise 7.28¶
Minesweeper, the well-known computer game, is closely related to the wumpus world. A minesweeper world is a rectangular grid of squares with invisible mines scattered among them. Any square may be probed by the agent; instant death follows if a mine is probed. Minesweeper indicates the presence of mines by revealing, in each probed square, the number of mines that are directly or diagonally adjacent. The goal is to probe every unmined square.
Let be true iff square contains a mine. Write down the assertion that exactly two mines are adjacent to [1,1] as a sentence involving some logical combination of propositions.
Generalize your assertion from (a) by explaining how to construct a CNF sentence asserting that of neighbors contain mines.
Explain precisely how an agent can use {DPLL} to prove that a given square does (or does not) contain a mine, ignoring the global constraint that there are exactly mines in all.
Suppose that the global constraint is constructed from your method from part (b). How does the number of clauses depend on and ? Suggest a way to modify {DPLL} so that the global constraint does not need to be represented explicitly.
Are any conclusions derived by the method in part (c) invalidated when the global constraint is taken into account?
Give examples of configurations of probe values that induce long-range dependencies such that the contents of a given unprobed square would give information about the contents of a far-distant square. (Hint: consider an board.)
Exercise 7.29¶
How long does it take to prove using {DPLL} when is a literal already contained in ? Explain.
Exercise 7.30¶
Trace the behavior of {DPLL} on the knowledge base in
Figure pl
Exercise 7.31¶
Write a successor-state axiom for the predicate, which applies to doors, assuming the only actions available are and .
Exercise 7.32¶
Discuss what is meant by optimal behavior in the wumpus world. Show that the {Hybrid-Wumpus-Agent} is not optimal, and suggest ways to improve it.
Exercise 7.33¶
Suppose an agent inhabits a world with two states, and ,
and can do exactly one of two actions, and . Action does
nothing and action flips from one state to the other. Let be
the proposition that the agent is in state at time , and let
be the proposition that the agent does action at time
(similarly for ).
Write a successor-state axiom for .
Convert the sentence in (a) into CNF.
Show a resolution refutation proof that if the agent is in at time and does , it will still be in at time .
Exercise 7.34¶
Section successor
Exercise 7.35¶
Modify the {Hybrid-Wumpus-Agent} to use the 1-CNF logical state
estimation method described on page 1cnf