Propositional logic requires a separate symbol for each fact: \(D_{1,1}\), \(D_{1,2}\), \(D_{2,1}\), and so on. We cannot express general rules like "creaking at any location implies adjacent damaged floor." First-order logic (FOL) solves this by introducing objects, relations, and quantifiers (Russell and Norvig, 2020, ch. 8).
Consider the rule for creaking in the Hazardous Warehouse. In propositional logic:
\[\begin{align} C_{1,1} &\Leftrightarrow D_{2,1} \lor D_{1,2} \\ C_{2,1} &\Leftrightarrow D_{1,1} \lor D_{3,1} \lor D_{2,2} \\ \vdots \end{align}\]
The pattern is clear: "Creaking at \(L\) iff damaged floor adjacent to \(L\)." But propositional logic cannot express this pattern directly.
First-order logic introduces:
Now we can write: \[\forall L\ \text{Creaking}(L) \Leftrightarrow \exists L'\ \text{Adjacent}(L, L') \land \text{Damaged}(L')\]
One sentence captures the rule for all locations.
Terms refer to objects:
A term is either a constant, a variable, or a function applied to terms.
Examples:
Our Hazardous Warehouse formalization uses only constants and variables—no functions are needed because the grid locations are finite and explicitly named. Functions become essential in domains with structured objects: for example, \(\text{Father}(\text{Alice})\) denotes a specific person without requiring a named constant for every individual, and in arithmetic, \(+(2, 3)\) constructs a term representing a number. Functions allow terms to be nested (e.g., \(\text{Father}(\text{Father}(\text{Alice}))\)), which means finitely many function and constant symbols can build up terms that name specific objects in an arbitrarily large or even infinite domain—without requiring a separate constant for each one. Variables with quantifiers can range over all objects in a domain, but they do not pick out specific unnamed individuals the way function terms do.
A predicate takes one or more terms as arguments and evaluates to true or false:
Examples for the Hazardous Warehouse:
| Predicate | Meaning |
|---|---|
| \(\text{Damaged}(L)\) | Location \(L\) has damaged floor |
| \(\text{Forklift}(L)\) | The malfunctioning forklift is at \(L\) |
| \(\text{Package}(L)\) | The package is at \(L\) |
| \(\text{Safe}(L)\) | Location \(L\) is safe to enter |
| \(\text{Adjacent}(L_1, L_2)\) | \(L_1\) and \(L_2\) are adjacent |
| \(\text{At}(R, L)\) | Robot \(R\) is at location \(L\) |
| \(\text{Creaking}(L)\) | Creaking is perceived at \(L\) |
| \(\text{Rumbling}(L)\) | Rumbling is perceived at \(L\) |
An atomic sentence is a predicate applied to terms: \[\text{Predicate}(\text{term}_1, \ldots, \text{term}_n)\] An atomic sentence is true or false depending on whether the relation holds.
Examples:
FOL uses the same logical connectives as propositional logic (\(\neg\), \(\land\), \(\lor\), \(\Rightarrow\), \(\Leftrightarrow\)) to build compound sentences.
Example: \[\text{Damaged}(L) \lor \text{Forklift}(L) \Rightarrow \neg\text{Safe}(L)\] "If a location has damaged floor or the forklift, it is not safe."
Quantifiers express generalizations:
Examples:
\[\forall L\ \text{Damaged}(L) \Rightarrow \neg\text{Safe}(L)\] "Every location with damaged floor is unsafe."
\[\exists L\ \text{Package}(L)\] "There exists a location with the package." (The package is somewhere.)
\[\forall L\ \text{Creaking}(L) \Leftrightarrow \exists L'\ \text{Adjacent}(L, L') \land \text{Damaged}(L')\] "For all locations \(L\), creaking at \(L\) iff there exists an adjacent location \(L'\) with damaged floor."
Quantifiers bind variables in their scope. In \(\forall x\ \phi(x)\), the variable \(x\) is bound. Variables not bound by any quantifier are free.
A sentence is a formula with no free variables. Only sentences have well-defined truth values.
Quantifiers can be nested: \[\forall L\ \exists L'\ \text{Adjacent}(L, L')\] "Every location has at least one adjacent location."
The order of different quantifiers matters:
An interpretation for a first-order language specifies:
The extension of a predicate \(P\) in an interpretation is the set of all tuples of objects from the domain for which \(P\) is true. For example, if \(\text{Damaged}\) is true for locations \(L_{2,2}\) and \(L_{3,1}\), then the extension of \(\text{Damaged}\) is the set \(\{L_{2,2}, L_{3,1}\}\). For a binary predicate like \(\text{Adjacent}\), the extension is a set of ordered pairs.
Example interpretation for a \(3 \times 3\) warehouse:
Given interpretation \(I\) with domain \(D\):
\(\mathit{KB} \models \alpha\) (\(\mathit{KB}\) entails \(\alpha\)) if every interpretation that makes all sentences in \(\mathit{KB}\) true also makes \(\alpha\) true.
This generalizes propositional entailment to handle objects, relations, and quantifiers.
Domain: Locations \(\{L_{1,1}, L_{1,2}, \ldots, L_{4,4}\}\)
Predicates:
Adjacency (explicit facts or computed): \[\text{Adjacent}(L_{1,1}, L_{2,1}) \land \text{Adjacent}(L_{1,1}, L_{1,2}) \land \cdots\]
Alternatively, define adjacency via coordinates (requires arithmetic).
Percept rules: \[\forall l\ \text{Creaking}(l) \Leftrightarrow \exists l'\ \text{Adjacent}(l, l') \land \text{Damaged}(l')\] (3.5)
\[\forall l\ \text{Rumbling}(l) \Leftrightarrow \exists l'\ \text{Adjacent}(l, l') \land \text{Forklift}(l')\] (3.6)
Safety: \[\forall l\ \text{Safe}(l) \Leftrightarrow \neg\text{Damaged}(l) \land \neg\text{Forklift}(l)\] (3.7)
Initial conditions: \[\text{Safe}(L_{1,1})\] "The starting square is safe."
\[\exists! l\ \text{Forklift}(l)\] "Exactly one location has the forklift." (Using the uniqueness quantifier, or encoding as: \(\exists l\ \text{Forklift}(l) \land \forall l'\ \text{Forklift}(l') \Rightarrow l' = l\).)
\[\exists! l\ \text{Package}(l)\] "Exactly one location has the package."
Observation: Robot at \(L_{1,1}\), perceives no creaking. \[\neg\text{Creaking}(L_{1,1})\]
Inference: From equation (3.5) and \(\neg\text{Creaking}(L_{1,1})\): \[\neg\exists l'\ \text{Adjacent}(L_{1,1}, l') \land \text{Damaged}(l')\]
This is equivalent to: \[\forall l'\ \text{Adjacent}(L_{1,1}, l') \Rightarrow \neg\text{Damaged}(l')\]
Combined with the adjacency facts \(\text{Adjacent}(L_{1,1}, L_{2,1})\) and \(\text{Adjacent}(L_{1,1}, L_{1,2})\): \[\neg\text{Damaged}(L_{2,1}) \land \neg\text{Damaged}(L_{1,2})\]
The robot has deduced no damaged floor at adjacent squares—with one general rule, not separate sentences for each square.
A key skill is converting natural language statements to formal logic.
"If at any location there is a damaged floor, then that location is adjacent to a location where creaking is heard."
\[\forall l\ \text{Damaged}(l) \Rightarrow \exists l'\ \text{Adjacent}(l, l') \land \text{Creaking}(l')\]
"No location has both damaged floor and the forklift."
\[\forall l\ \neg(\text{Damaged}(l) \land \text{Forklift}(l))\]
"If rumbling is heard at a location, the forklift is not at that location."
\[\forall l\ \text{Rumbling}(l) \Rightarrow \neg\text{Forklift}(l)\]
(Rumbling indicates the forklift is adjacent, not at the current location.)
"There is exactly one package."
\[\exists l\ \text{Package}(l) \land \forall l'\ \text{Package}(l') \Rightarrow l' = l\]
Conversely, using disjunction with \(\exists\) is usually wrong.
Wrong: \(\exists l\ \text{Package}(l) \lor \text{Safe}(l)\) — Merely says some location is either package or safe (trivially true).
Correct: \(\exists l\ \text{Package}(l) \land \text{Safe}(l)\) — Some location has the package and is safe.
Several equivalences are useful for reasoning:
Negation through quantifiers (De Morgan for quantifiers): \[\neg\forall x\ \phi(x) \equiv \exists x\ \neg\phi(x)\] \[\neg\exists x\ \phi(x) \equiv \forall x\ \neg\phi(x)\]
Quantifier distribution: \[\forall x\ (\phi(x) \land \psi(x)) \equiv (\forall x\ \phi(x)) \land (\forall x\ \psi(x))\] \[\exists x\ (\phi(x) \lor \psi(x)) \equiv (\exists x\ \phi(x)) \lor (\exists x\ \psi(x))\]
Quantifier duality: \[\forall x\ \phi(x) \equiv \neg\exists x\ \neg\phi(x)\] \[\exists x\ \phi(x) \equiv \neg\forall x\ \neg\phi(x)\]
For partial observability with uncertainty, we eventually need probabilistic logic (beyond this chapter).
First-order logic extends propositional logic with:
For the Hazardous Warehouse, FOL lets us write:
The next section develops inference procedures to derive conclusions from a FOL knowledge base: forward chaining, backward chaining, and resolution.
Comment 3.5 The Implication Trap
A common error is using conjunction instead of implication with \(\forall\).
Wrong: \(\forall l\ \text{Safe}(l) \land \text{Visited}(l)\) — Claims every location is both safe and visited!
Correct: \(\forall l\ \text{Visited}(l) \Rightarrow \text{Safe}(l)\) — If visited, then safe.