Published on

AI 4: Logical Agents and First-Order Logic

Authors

1. Proving Logical Entailment

7.4 "Which of the following are correct" (Russell & Norvig, 2010)?

  • "a. False \models True" is true, or more accurately it can be considered "vacuously true." ABA \models B is only false when BB is false.
  • "b. True \models False." is false. Fundamental to semantic entailment is that ABA \models B says "if AA is true then BB must also be true". True \models False violates this and is therefore false.
  • "c. (AB)(AB)(A \wedge B) \models(A \Leftrightarrow B)." is true because all the models where (AB)(A \wedge B) is true (there is only one, seen in green below), (AB)(A \Leftrightarrow B) is also true.
    AB(AB)(AB)FFFTFTFFTFFFTTTT\begin{array}{|r|r|c|c|} \hline A & B & (A \wedge B) & (A \leftrightarrow B) \\ \hline \mathrm{F} & \mathrm{F} & \mathrm{F} & \mathrm{T} \\ \hline \mathrm{F} & \mathrm{T} & \mathrm{F} & \mathrm{F} \\ \hline \mathrm{T} & \mathrm{F} & \mathrm{F} & \mathrm{F} \\ \hline \mathrm{T} & \mathrm{T} & \color{green}{\mathrm{T}} & \color{green}{\mathrm{T}} \\ \hline \end{array}
  • "d. ABABA \Leftrightarrow B \models A \vee B." is false because there is one model where ABA \Leftrightarrow B is true but ABA \vee B is false, which is shown in red below.
    ABABABFFTFFTFTTFFTTTTT\begin{array}{|r|r|c|c|} \hline A & B & A \Leftrightarrow B & A \vee B \\ \hline \mathrm{F} & \mathrm{F} & \color{green}{\mathrm{T}} & \color{red}{\mathrm{F}} \\ \hline \mathrm{F} & \mathrm{T} & \mathrm{F} & \mathrm{T} \\ \hline \mathrm{T} & \mathrm{F} & \mathrm{F} & \mathrm{T} \\ \hline \mathrm{T} & \mathrm{T} & \color{green}{\mathrm{T}} & \color{green}{\mathrm{T}} \\ \hline \end{array}
  • "e. AB¬ABA \Leftrightarrow B \models \neg A \vee B." is true, for the same reasons as in part c.
    ABAB¬ABFFTTFTFTTFFFTTTT\begin{array}{|r|r|c|c|} \hline A & B & A \Leftrightarrow B & \neg A \vee B \\ \hline \mathrm{F} & \mathrm{F} & \color{green}{\mathrm{T}} & \color{green}{\mathrm{T}} \\ \hline \mathrm{F} & \mathrm{T} & \mathrm{F} & \mathrm{T} \\ \hline \mathrm{T} & \mathrm{F} & \mathrm{F} & \mathrm{F} \\ \hline \mathrm{T} & \mathrm{T} & \color{green}{\mathrm{T}} & \color{green}{\mathrm{T}} \\ \hline \end{array}
  • "f. (AB)C(AC)(BC)(A \wedge B) \Rightarrow C \models(A \Rightarrow C) \vee(B \Rightarrow C)" is true, for the same reasons.
    ABC(AB)C(AC)(BC)FFFTTFFTTTFTFTTFTTTTTFFTTTFTTTTTFFFTTTTT\begin{array}{|r|r|c|c|} \hline A & B & C & (A \wedge B) \Rightarrow C & (A \Rightarrow C) \vee(B \Rightarrow C) \\ \hline \mathrm{F} & \mathrm{F} & \mathrm{F} & \color{green}{\mathrm{T}} & \color{green}{\mathrm{T}} \\ \hline \mathrm{F} & \mathrm{F} & \mathrm{T} & \color{green}{\mathrm{T}} & \color{green}{\mathrm{T}} \\ \hline \mathrm{F} & \mathrm{T} & \mathrm{F} & \color{green}{\mathrm{T}} & \color{green}{\mathrm{T}} \\ \hline \mathrm{F} & \mathrm{T} & \mathrm{T} & \color{green}{\mathrm{T}} & \color{green}{\mathrm{T}} \\ \hline \mathrm{T} & \mathrm{F} & \mathrm{F} & \color{green}{\mathrm{T}} & \color{green}{\mathrm{T}} \\ \hline \mathrm{T} & \mathrm{F} & \mathrm{T} & \color{green}{\mathrm{T}} & \color{green}{\mathrm{T}} \\ \hline \mathrm{T} & \mathrm{T} & \mathrm{F} & \mathrm{F} & \mathrm{F} \\ \hline \mathrm{T} & \mathrm{T} & \mathrm{T} & \color{green}{\mathrm{T}} & \color{green}{\mathrm{T}} \\ \hline \end{array}
  • "g. (C(¬A¬B))((AC)(BC))(C \vee(\neg A \wedge \neg B)) \equiv((A \Rightarrow C) \wedge(B \Rightarrow C))" is true, for the same reasons.
    ABC(C(¬A¬B))((AC)(BC))FFFTTFFTTTFTFFFFTTTTTFFFFTFTTTTTFFFTTTTT\begin{array}{|r|r|c|c|} \hline A & B & C & (C \vee(\neg A \wedge \neg B)) & ((A \Rightarrow C) \wedge(B \Rightarrow C)) \\ \hline \mathrm{F} & \mathrm{F} & \mathrm{F} & \color{green}{\mathrm{T}} & \color{green}{\mathrm{T}} \\ \hline \mathrm{F} & \mathrm{F} & \mathrm{T} & \color{green}{\mathrm{T}} & \color{green}{\mathrm{T}} \\ \hline \mathrm{F} & \mathrm{T} & \mathrm{F} & \color{green}{\mathrm{F}} & \color{green}{\mathrm{F}} \\ \hline \mathrm{F} & \mathrm{T} & \mathrm{T} & \color{green}{\mathrm{T}} & \color{green}{\mathrm{T}} \\ \hline \mathrm{T} & \mathrm{F} & \mathrm{F} & \color{green}{\mathrm{F}} & \color{green}{\mathrm{F}} \\ \hline \mathrm{T} & \mathrm{F} & \mathrm{T} & \color{green}{\mathrm{T}} & \color{green}{\mathrm{T}} \\ \hline \mathrm{T} & \mathrm{T} & \mathrm{F} & \color{green}{\mathrm{F}} & \color{green}{\mathrm{F}} \\ \hline \mathrm{T} & \mathrm{T} & \mathrm{T} & \color{green}{\mathrm{T}} & \color{green}{\mathrm{T}} \\ \hline \end{array}
  • "h. (AB)(¬C¬DE)(AB)(A \vee B) \wedge(\neg C \vee \neg D \vee E) \models(A \vee B)." is true because (AB)(A \vee B) will always be true when (AB)(¬C¬DE)(A \vee B) \wedge(\neg C \vee \neg D \vee E) is, since the conjunction with (¬C¬DE)(\neg C \vee \neg D \vee E) doesn't adds models that are true when (AB)(A \vee B) is not.
  • "j. (AB)¬(AB)(A \vee B) \wedge \neg(A \Rightarrow B) is satisfiable." This is correct, the expression is satisfiable because it is true when AA is true and BB is false.
  • "k. (AB)(¬AB)(A \Leftrightarrow B) \wedge(\neg A \vee B) is satisfiable." This is correct, the expression is satisfiable because it is true when both AA and BB are true and when both are false.
  • "l. (AB)C(A \Leftrightarrow B) \Leftrightarrow C has the same number of models as (AB)(A \Leftrightarrow B) for any fixed set of proposition symbols that includes A,B,CA, B, C." This is correct, because the fixed set of propositions includes all symbols found in both expressions.

2. Using Resolution to Prove a Sentence

7.12 "Use resolution to prove the sentence ¬A¬B¬A∧¬B from the clauses in Exercise 7.20."

We start off with a KB that is a conjunction of sentences as in Exercise 7.20 below:

7.20 Convert the following set of sentences to clausal form. S1: A(BE).A \Leftrightarrow(B \vee E) . S2: ED.E \Rightarrow D . S3: CF¬B.C \wedge F \Rightarrow \neg B . S4: EB.E \Rightarrow B . S5: BFB \Rightarrow F S6: BCB \Rightarrow C Give a trace of the execution of DPLL on the conjunction of these clauses (Russell & Norvig, 2010).

We want the contents of KB in CNF so we convert each sentence to CNF. Since S1 has OR operators after converting, it will be broken up into three clauses. The others are one CNF clause each, as shown in boxes below.

S1:A(BE)(A(BE))((BE)A)By αβ(αβ)(βα)(¬ABE)(¬(BE)A)By αβ¬αβ(¬ABE)((¬B¬E)A)By De Morgan(¬ABE)(¬BA)(¬EA)S1 in CNF, by distributivity of  over S2:ED¬EDS3 in CNF, by αβ¬αβS3:CF¬B¬(CF)¬BBy αβ¬αβ¬C¬F¬BS3 in CNF, by De MorganS4:EB¬EBS4 in CNF, by αβ¬αβS5:BF¬BFS5 in CNF, by αβ¬αβS6:BC¬BCS6 in CNF, by αβ¬αβ\begin{array}{rrll} \text{S1:}&& A \Leftrightarrow(B \vee E) \\ &\equiv& (A \Rightarrow(B \vee E)) \wedge((B \vee E) \Rightarrow A) &\text{By }\alpha \Leftrightarrow \beta\equiv(\alpha \Rightarrow \beta) \wedge(\beta \Rightarrow \alpha)\\ &\equiv& (\neg A \vee B \vee E) \wedge(\neg(B \vee E) \vee A) &\text{By }\alpha \Rightarrow \beta \equiv \neg \alpha \vee \beta\\ &\equiv& (\neg A \vee B \vee E) \wedge((\neg B \wedge \neg E) \vee A) &\text{By De Morgan}\\ &\equiv&\boxed{(\neg A \vee B \vee E)} \wedge\boxed{(\neg B \vee A)} \wedge\boxed{(\neg E \vee A)} &\textbf{S1 in CNF}\text{, by distributivity of $∨$ over $∧$}\\ \hline \text{S2:}&& E \Rightarrow D \\ &\equiv& \boxed{\neg E \vee D} &\textbf{S3 in CNF}\text{, by }\alpha \Rightarrow \beta \equiv \neg \alpha \vee \beta\\ \hline \text{S3:}&& C \wedge F \Rightarrow \neg B \\ &\equiv& \neg(C \wedge F) \vee \neg B &\text{By }\alpha \Rightarrow \beta \equiv \neg \alpha \vee \beta\\ &\equiv& \boxed{\neg C \vee \neg F \vee \neg B} &\textbf{S3 in CNF}\text{, by De Morgan}\\ \hline \text{S4:}&& E \Rightarrow B \\ &\equiv& \boxed{\neg E \vee B} &\textbf{S4 in CNF}\text{, by }\alpha \Rightarrow \beta \equiv \neg \alpha \vee \beta\\ \hline \text{S5:}&& B \Rightarrow F \\ &\equiv& \boxed{\neg B \vee F} &\textbf{S5 in CNF}\text{, by }\alpha \Rightarrow \beta \equiv \neg \alpha \vee \beta\\ \hline \text{S6:}&& B \Rightarrow C \\ &\equiv& \boxed{\neg B \vee C} &\textbf{S6 in CNF}\text{, by }\alpha \Rightarrow \beta \equiv \neg \alpha \vee \beta \end{array}

We are trying to prove KB ¬A¬B\models\neg A \wedge \neg B so we have α=¬A¬B\alpha = \neg A \wedge \neg B so ¬α\neg \alpha is ¬(¬A¬B)\neg(\neg A \wedge \neg B), which, by De Morgan's law, is logically equivalent to (AB)(A \vee B). We start with a set of clausesclauses from the CNF clauses in boxes along ¬α¬α which is (AB)(A{∨}B)

We iteratively select a pair from clausesclauses and perform the resolution on each. For example, (a)\color{orange}{\mathbf{(a)}} below shows resolving clauses pairs with complementary literals ABA ∨ B and ¬ABE¬A ∨ B ∨ E by the process AB, ¬ABEBE\dfrac{A ∨ B,\ ¬A ∨ B ∨ E}{B ∨ E}, which cancels the AA because AA and ¬A\neg A are complementary literals and leaves the resolventresolvent BEB ∨ E shown labeled with (b)\color{orange}{\mathbf{(b)}} below. If the calculated resolvent is ever empty, we have proven KB α\models \alpha.

I started to answer this using a full trace using the official Python code but the trace was way too long to list here. But there is more than one way to answer this depending on the order of the pairs being passed PL-RESOLVE so I rearranged the order of the clauses to make the trace short, along with not showing some iterations that don't matter to the result, shown as "//...//..." below.

function PL-RESOLUTION(KB,α)(KB, α)
clauses{ (AB), ¬ABE, ¬C¬F¬B, ¬BF, ¬EB, ¬BC, ¬BA, ¬EA, ¬ED }\quad clauses ← \left\{\ (A{∨}B),\ \boxed{¬A{∨}B{∨}E},\ \boxed{¬C{∨}¬F{∨}¬B},\ \boxed{¬B{∨}F},\ \boxed{¬E{∨}B},\ \boxed{¬B{∨}C},\ \boxed{¬B{∨}A},\ \boxed{¬E{∨}A},\ \boxed{¬E{∨}D}\ \right\}
\quadfor each pair in clauses // (the loop iterations are expanded below):
resolvents\quad\quad resolvents ← PL-RESOLVE(AB, ¬ABE)(A{∨}B,\ ¬A{∨}B{∨}E) 0000(a) in graph\phantom{0000}\color{orange}{\mathbf{(a)}}\text{ in graph}
clausesclauses{ BE }\quad\quad clauses ← clauses ∪ \{\ B{∨}E\ \} 000000000000000000(b) in graph\phantom{000000000000000000}\color{orange}{\mathbf{(b)}}\text{ in graph}
resolvents\quad\quad resolvents ← PL-RESOLVE(¬C¬F¬B, ¬BF(¬C{∨}¬F{∨}¬B,\ ¬B{∨}F)  (c) in graph\ \color{orange}{\mathbf{(c)}}\text{ in graph}
clausesclauses{ ¬B¬C }\quad\quad clauses ← clauses ∪ \{\ ¬B∨¬C\ \} 000000000000000(d) in graph\phantom{000000000000000}\color{orange}{\mathbf{(d)}}\text{ in graph}
//...\quad\quad //...
resolvents\quad\quad resolvents ← PL-RESOLVE(BE, ¬EB)(B{∨}E,\ ¬E{∨}B) 0000000(e) in graph\phantom{0000000}\color{orange}{\mathbf{(e)}}\text{ in graph}
clausesclauses{ B }\quad\quad clauses ← clauses ∪ \{\ B\ \} 000000000000000000000(f) in graph\phantom{000000000000000000000}\color{orange}{\mathbf{(f)}}\text{ in graph}
//...\quad\quad //...
resolvents\quad\quad resolvents ← PL-RESOLVE(¬BC,¬B¬C)(¬B{∨}C, ¬B{∨}¬C) 0000(g) in graph\phantom{0000}\color{orange}{\mathbf{(g)}}\text{ in graph}
clausesclauses{ C }\quad\quad clauses ← clauses ∪ \{\ C\ \} 000000000000000000000(h) in graph\phantom{000000000000000000000}\color{orange}{\mathbf{(h)}}\text{ in graph}
//...\quad\quad //...
resolvents\quad\quad resolvents ← PL-RESOLVE(B,¬B) // empty!(B, ¬B)\ //\text{ empty!} 0000(i) in graph\phantom{0000}\color{orange}{\mathbf{(i)}}\text{ in graph}
\quad\quadif resolventsresolvents contains the empty clause then return truetrue //true is returned!// \color{green}{true\ \text{is returned!}}

Below is the trace shown as a graph. The empty set at (i)\color{orange}{\mathbf{(i)}} proves that KB ¬A¬B\models\neg A \wedge \neg B

7.14

3. Map Coloring Problem

8.9 This exercise uses the function MapColorMapColor and predicates In(x,y){In}(x, y), Borders(x,y)Borders(x, y), and Country(x),Country(x), whose arguments are geographical regions, along with constant symbols for various regions. In each of the following we give an English sentence and a number of candidate logical expressions. For each of the logical expressions, state whether it (1) correctly expresses the English sentence; (2) is syntactically invalid and therefore meaningless; or (3) is syntactically valid but does not express the meaning of the English sentence (Russell & Norvig, 2010)

  • "a. Paris and Marseilles are both in France".
    • "(i) In(ParisMarseilles,France)In(Paris ∧ Marseilles, France )" is (2), is syntactically invalid because of the conjunction's placement.
    • "(ii) In(Paris,France)In(Marseilles,France)In(Paris , France ) ∧ In(Marseilles, France )" is (1), correctly expressed.
    • "(iii) In(Paris,France)In(Marseilles,France)In(Paris , France ) ∨ In(Marseilles, France )" is (3), not expressing English meaning of "both."
  • "b. There is a country that borders both Iraq and Pakistan."
    • "(i)  c Country(c)Border(c,Iraq)Border(c,Pakistan)∃\ c\ Country (c) ∧ Border (c, Iraq ) ∧ Border (c, Pakistan )" is (1), correctly expressed.
    • "(ii)  c Country(c)[Border(c,Iraq)Border(c,Pakistan)]∃\ c\ Country (c) ⇒ [Border (c, Iraq ) ∧ Border (c, Pakistan )]" is (3), not expressing English meaning.
    • "(iii) [ c Country(c)][Border(c,Iraq)Border(c,Pakistan)][∃\ c\ Country (c)] ⇒ [Border (c, Iraq ) ∧ Border (c, Pakistan )]" is (2), is syntactically invalid because of the conjunction's placement.
    • "(iv)  c Border(Country(c),IraqPakistan)∃\ c\ Border (Country(c), Iraq ∧ Pakistan)" is (2), is syntactically invalid because of the conjunction's placement.
  • "c. All countries that border Ecuador are in South America."
    • "(i)  c Country(c)Border(c,Ecuador)In(c,SouthAmerica)∀\ c\ Country(c) ∧ Border (c, Ecuador ) ⇒ In(c, SouthAmerica )" is (1), correctly expressed.
    • "(ii)  c Country(c)[Border(c,Ecuador)In(c,SouthAmerica)]∀\ c\ Country (c) ⇒ [Border (c, Ecuador ) ⇒ In(c, SouthAmerica )]" is (1), correctly expressed.
    • "(iii)  c [Country(c)Border(c,Ecuador)]In(c,SouthAmerica)∀\ c\ [Country (c) ⇒ Border (c, Ecuador )] ⇒ In(c, SouthAmerica )" is (3), not expressing English meaning.
    • "(iv)  c Country(c)Border(c,Ecuador)In(c,SouthAmerica)∀\ c\ Country(c) ∧ Border (c, Ecuador ) ∧ In(c, SouthAmerica )" is (3), not expressing English meaning.
  • "d. No region in South America borders any region in Europe."
    • "(i) ¬[ c,d In(c,SouthAmerica)In(d,Europe)Borders(c,d)]¬[∃\ c, d\ In(c, SouthAmerica ) ∧ In(d, Europe ) ∧ Borders (c, d)]" is (1) correctly expressed.
    • "(ii)  c,d [In(c,SouthAmerica)In(d,Europe)]¬Borders(c,d)]∀\ c, d\ [In(c, SouthAmerica ) ∧ In(d, Europe )] ⇒ ¬Borders (c, d)]" is (1) correctly expressed.
    • "(iii) ¬c In(c,SouthAmerica) d In(d,Europe)¬Borders(c,d)¬c\ In(c, SouthAmerica ) ⇒ ∃\ d\ In(d, Europe ) ∧ ¬Borders (c, d)" is (3), not expressing English meaning.
    • "(iv)  c In(c,SouthAmerica) d In(d,Europe)¬Borders(c,d)∀\ c\ In(c, SouthAmerica ) ⇒ ∀\ d\ In(d, Europe ) ⇒ ¬Borders (c, d)" is (1) correctly expressed.
  • "e. No two adjacent countries have the same map color."
    • "(i)  x,y ¬Country(x)¬Country(y)¬Borders(x,y)¬(MapColor(x)=MapColor(y))∀\ x, y\ ¬Country(x) ∨ ¬Country (y) ∨ ¬Borders (x, y) ∨ ¬(MapColor (x) = MapColor (y))" is (1) correctly expressed.
    • "(ii)  x,y (Country(x)Country(y)Borders(x,y)¬(x=y))¬(MapColor(x)=MapColor(y))∀\ x, y\ (Country (x) ∧ Country (y) ∧ Borders (x, y) ∧ ¬(x = y)) ⇒ ¬(MapColor (x) = MapColor (y))" is (1) correctly expressed but (i) is more simplified (better) since no country can border itself!
    • "(iii)  x, y Country(x)Country(y)Borders(x,y)¬(MapColor(x)=MapColor(y))∀\ x,\ y\ Country (x) ∧ Country (y) ∧ Borders (x, y) ∧ ¬(MapColor (x) = MapColor (y))" is (3), not expressing English meaning.
    • "(iv)  x,y (Country(x)Country(y)Borders(x,y))MapColor(x=y)∀\ x, y\ (Country (x) ∧ Country (y) ∧ Borders (x, y)) ⇒ MapColor (x = y)" is (2), is syntactically invalid because of the inequality's placement.

4. Writing Assertions in First-Order Logic

8.10 Consider a vocabulary with the following symbols:
Occupation(p,o)Occupation(p, o): Predicate. Person pp has occupation oo.
Customer(p1,p2)Customer (p1, p2): Predicate. Person p1p1 is a customer of person p2p2.
Boss(p1,p2)Boss(p1, p2): Predicate. Person p1p1 is a boss of person p2p2.
Doctor,Surgeon,Lawyer,ActorDoctor, Surgeon, Lawyer, Actor: Constants denoting occupations. Emily,JoeEmily, Joe: Constants denoting people.
Use these symbols to write the following assertions in first-order logic (Russell & Norvig, 2010):

  • "a. Emily is either a surgeon or a lawyer."
    • Occupation(Emily, Surgeon)Occupation(Emily, Lawyer)Occupation(Emily,\ Surgeon) \vee Occupation(Emily,\ Lawyer)
  • b. Joe is an actor, but he also holds another job."
    • Occupation(Joe, Actor) p  pActorOccupation(Joe, p)Occupation(Joe,\ Actor) \wedge \exists\ p \ \ p \neq Actor \wedge Occupation(Joe,\ p)
  • "c. All surgeons are doctors."
    •  p  Occupation(p, Surgeon)Occupation(p, Doctor)\forall\ p\ \ Occupation(p,\ Surgeon) \Rightarrow Occupation(p,\ Doctor)
  • "d. Joe does not have a lawyer (i.e., is not a customer of any lawyer)."
    • ¬ p  Customer(Joe, p)Occupation(p, Lawyer)\neg \exists\ p\ \ Customer(Joe,\ p) \wedge Occupation(p,\ Lawyer)
  • "e. Emily has a boss who is a lawyer."
    •  p  Boss(p, Emily)Occupation(p, Lawyer)\exists\ p\ \ Boss(p,\ Emily) \wedge Occupation(p,\ Lawyer)
  • "f. There exists a lawyer all of whose customers are doctors."
    •  p1  Occupation(p1, Lawyer) p2  Customer(p2, p1)Occupation(p2, Doctor)\exists\ p_1\ \ Occupation(p_1,\ Lawyer) \wedge \forall\ p_2\ \ Customer(p_2,\ p_1) \Rightarrow Occupation(p_2,\ Doctor)
  • "g. Every surgeon has a lawyer."
    •  p1  Occupation(p1, Surgeon) p2  Occupation(p2, Lawyer)Customer(p1, p2)\forall\ p_1\ \ Occupation(p_1,\ Surgeon) \Rightarrow \exists\ p_2\ \ Occupation(p_2,\ Lawyer) \wedge Customer(p_1,\ p_2)

References

  • Russell, S., & Norvig, P. (2010). Artificial Intelligence: A Modern Approach (3rd ed.). Pearson Prentice Hall.