Press Ctrl+D to draw

Drawing Tools

Log in for saved annotations

1px

3.4  First-Order Logic

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).

3.4.1 From Propositions to Predicates

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:

  • Objects: things in the world (locations, robots, packages), referred to by constants
  • Relations: properties of and connections among objects (Damaged, Adjacent, At), expressed by predicates
  • Variables: placeholders for objects (\(x\), \(y\), \(L\))
  • Quantifiers: "for all" (\(\forall\)) and "there exists" (\(\exists\))

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.

3.4.2 Syntax of First-Order Logic

3.4.2.1 Terms: Referring to Objects

Definition 3.23  Terms

Terms refer to objects:

  • Constants: Named objects, e.g., \(\mathit{Loc}_{2,3}\), \(\mathit{Robot1}\), \(\mathit{Package}_A\)
  • Variables: Placeholders, e.g., \(x\), \(y\), \(L\)
  • Functions: Mappings from objects to objects, e.g., \(\text{Adjacent-East}(\mathit{Loc}_{2,3}) = \mathit{Loc}_{3,3}\)

A term is either a constant, a variable, or a function applied to terms.

Examples:

  • \(\mathit{Loc}_{1,1}\) — constant referring to square \((1,1)\)
  • \(x\) — variable that could refer to any object
  • \(\text{Location}(\mathit{Robot1})\) — function returning the location of Robot1

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.

3.4.2.2 Predicates: Properties and Relations

Definition 3.24  Predicates

A predicate takes one or more terms as arguments and evaluates to true or false:

  • Unary predicates: Properties of single objects, e.g., \(\text{Damaged}(L)\)
  • Binary predicates: Relations between pairs, e.g., \(\text{Adjacent}(L_1, L_2)\)
  • N-ary predicates: Relations among \(n\) objects, e.g., \(\text{Nearby}(L_1, L_2, L_3)\)

Examples for the Hazardous Warehouse:

Key predicates 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\)

3.4.2.3 Atomic Sentences

Definition 3.25  Atomic Sentence

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:

  • \(\text{Damaged}(\mathit{Loc}_{2,1})\) — "Square \((2,1)\) has damaged floor"
  • \(\text{Adjacent}(\mathit{Loc}_{1,1}, \mathit{Loc}_{2,1})\) — "\((1,1)\) is adjacent to \((2,1)\)"
  • \(\text{At}(\mathit{Robot1}, x)\) — "Robot1 is at some location \(x\)" (contains variable)

3.4.2.4 Connectives

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."

3.4.2.5 Quantifiers

Definition 3.26  Quantifiers

Quantifiers express generalizations:

  • Universal quantifier \(\forall\): "for all," "every"
    • \(\forall x\ \phi(x)\) is true if \(\phi(x)\) holds for every object \(x\)
  • Existential quantifier \(\exists\): "there exists," "some"
    • \(\exists x\ \phi(x)\) is true if \(\phi(x)\) holds for at least one object \(x\)

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."

3.4.2.6 Variable Scope and Nesting

Quantifiers bind variables in their scope. In \(\forall x\ \phi(x)\), the variable \(x\) is bound. Variables not bound by any quantifier are free.

Definition 3.27  Sentence

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:

  • \(\forall x\ \exists y\ \text{Loves}(x, y)\) — "Everyone loves someone" (possibly different people)
  • \(\exists y\ \forall x\ \text{Loves}(x, y)\) — "Someone is loved by everyone" (one specific person)

3.4.3 Semantics of First-Order Logic

3.4.3.1 Interpretations

Definition 3.28  Interpretation

An interpretation for a first-order language specifies:

  1. A domain \(D\): the set of objects under discussion
  2. For each constant: which object in \(D\) it refers to
  3. For each function: a mapping from \(D^n \to D\)
  4. For each predicate: which tuples of objects make it true

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:

  • Domain: \(D = \{L_{1,1}, L_{1,2}, L_{1,3}, L_{2,1}, L_{2,2}, L_{2,3}, L_{3,1}, L_{3,2}, L_{3,3}\}\)
  • Constants: \(\mathit{Loc}_{i,j}\) refers to \(L_{i,j}\)
  • Predicates:
    • \(\text{Damaged} = \{L_{2,2}, L_{3,1}\}\) (true at these locations)
    • \(\text{Forklift} = \{L_{1,3}\}\)
    • \(\text{Adjacent} = \{(L_{1,1}, L_{2,1}), (L_{1,1}, L_{1,2}), (L_{2,1}, L_{1,1}), \ldots\}\)

3.4.3.2 Truth Under an Interpretation

Given interpretation \(I\) with domain \(D\):

  • Atomic sentence \(P(t_1, \ldots, t_n)\) is true iff the tuple of objects denoted by the terms is in \(P\)'s extension
  • \(\forall x\ \phi(x)\) is true iff \(\phi(d)\) is true for every \(d \in D\)
  • \(\exists x\ \phi(x)\) is true iff \(\phi(d)\) is true for some \(d \in D\)
  • Connectives work as in propositional logic

3.4.3.3 Entailment in FOL

Definition 3.29  First-Order Entailment

\(\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.

3.4.4 Modeling the Hazardous Warehouse in FOL

3.4.4.1 Domain and Predicates

Domain: Locations \(\{L_{1,1}, L_{1,2}, \ldots, L_{4,4}\}\)

Predicates:

  • \(\text{Damaged}(l)\): damaged floor at \(l\)
  • \(\text{Forklift}(l)\): forklift at \(l\)
  • \(\text{Package}(l)\): package at \(l\)
  • \(\text{Adjacent}(l_1, l_2)\): \(l_1\) and \(l_2\) are cardinally adjacent
  • \(\text{Creaking}(l)\): creaking perceived at \(l\)
  • \(\text{Rumbling}(l)\): rumbling perceived at \(l\)
  • \(\text{Safe}(l)\): \(l\) is safe to enter
  • \(\text{Visited}(l)\): robot has visited \(l\)

3.4.4.2 Background Knowledge

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."

3.4.4.3 Reasoning with the KB

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.

3.4.5 Translating English to FOL

A key skill is converting natural language statements to formal logic.

3.4.5.1 Translation Examples

"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\]

3.4.5.2 Common Pitfalls

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.

Comment 3.6  The Disjunction Trap

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.

3.4.6 Quantifier Equivalences

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)\]

3.4.7 Expressiveness and Limitations

3.4.7.1 What FOL Can Express

  • General rules: "All damaged floors cause creaking nearby"
  • Existence and uniqueness: "Exactly one forklift exists"
  • Relations: "Adjacent to," "between," "carrying"
  • Complex patterns: Transitive closure (with some encoding)

3.4.7.2 What FOL Cannot Express

  • Second-order properties: "For all properties P..." (quantifying over predicates)
  • Cardinality constraints without enumeration: "More than half the locations are safe"
  • Probabilistic statements: "Probably safe"

For partial observability with uncertainty, we eventually need probabilistic logic (beyond this chapter).

3.4.8 Summary

First-order logic extends propositional logic with:

  • Objects: Constants and variables referring to things in the world
  • Predicates: Properties and relations over objects
  • Functions: Mappings from objects to objects
  • Quantifiers: \(\forall\) (for all) and \(\exists\) (there exists)

For the Hazardous Warehouse, FOL lets us write:

  • General percept rules: one sentence for all locations
  • Safety conditions: defined in terms of predicates
  • Existence constraints: exactly one forklift, exactly one package

The next section develops inference procedures to derive conclusions from a FOL knowledge base: forward chaining, backward chaining, and resolution.

Bibliography

  1. [AI] Russell, Stuart J. and Peter Norvig. Artificial intelligence: a modern approach. (2020) 4 ed. Prentice Hall. http://aima.cs.berkeley.edu/