Logic and Planning/First-Order Logic

Lesson 3.32,769 words

First-Order Logic

Propositional logic can only say that facts hold; it cannot talk about the objects a fact is about, or state a rule once and have it cover every object. First-order logic fixes this by committing to a world of objects, relations, and functions.

╌╌╌╌

Propositional logic gave a knowledge-based agent a declarative language: facts are separate from inference, partial information survives through disjunction and negation, and the meaning of a sentence is fixed by the meanings of its parts. Those are the right properties for a representation language. The problem is expressive power. A proposition symbol like is an atom with no internal structure — it says nothing about which square, and it cannot be related to except by writing out, by hand, a fresh biconditional for every square:1

There are sixteen squares in a wumpus world, so this rule has to be stated sixteen times, once per square, even though in English it is one sentence: a square is breezy exactly when a neighbor holds a pit. Propositional logic has no way to say for every square, because it has no notion of a square as an object it can quantify over. First-order logic adds exactly that notion, and with it the ability to state general laws once and have them apply everywhere.2

What propositional logic cannot say

The gap is best seen through what a representation language commits to about reality — its ontological commitment. Propositional logic assumes the world is a collection of facts, each of which holds or does not. That is enough to be declarative and to handle partial information, but it leaves three things out:

  • No objects. You cannot refer to Richard, or to square , as a thing that properties attach to. There are only atomic facts.
  • No relations. You cannot say that two objects stand in a relation — Richard is the brother of John — as a fact built from the two objects and the relation between them. RichardIsBrotherOfJohn is an unanalyzable symbol.
  • No generality. Because there are no objects and no variables ranging over them, there is no way to say every king is a person. Each instance must be written separately.

First-order logic keeps propositional logic's declarative, compositional core and borrows one idea from natural language: sentences are about objects (nouns), the relations among them (verbs), and functions, the special relations that map each input to exactly one output.3 The table below places both logics on the spectrum of ontological commitments AIMA uses (its Figure 8.1).4

LanguageOntological commitment (what exists)Epistemological commitment (belief about facts)
Propositional logicfactstrue / false / unknown
First-order logicfacts, objects, relationstrue / false / unknown
Temporal logicfacts, objects, relations, timestrue / false / unknown
Probability theoryfactsdegree of belief
Fuzzy logicfacts with degree of truth known interval value

The two logics agree on epistemology — an agent believes a sentence true, false, or has no opinion — and differ only in ontology. First-order logic commits to more of the structure of the world, and that is precisely where its extra expressive power comes from.

Propositional logic sees a fact as one unanalyzable symbol (left); first-order logic decomposes the same fact into an object, a relation, and another object (right), which is what lets a rule range over all objects.

The ontology: objects, relations, functions

The building blocks of a first-order world are three kinds of thing.5

Almost any assertion decomposes into these. Evil King John ruled England in 1200 has objects John, England, and 1200; the relation ruled; and the properties evil and king. One plus two equals three has objects one, two, and three; the function plus applied to one and two; and the relation equals. Once the world is objects with relations and functions among them, first-order logic can also quantify over them — say something about some or all objects — which is the source of its ability to state general laws.

Models: a domain and an interpretation

The model of a first-order sentence is a possible world: a set of objects plus a link from the vocabulary to those objects. AIMA's running example is a kinship scene with five objects — Richard the Lionheart, his brother the evil King John, the left legs of each, and a crown.6

A first-order model (after AIMA Fig. 8.2) with five objects, the binary relation holding symmetrically between R and J, the binary relation, three unary relations shown as labels on objects, and the total unary function mapping each person to a leg.

The relations in this model are literally sets of tuples. The brotherhood relation is symmetric, so it contains two tuples:

The on-head relation contains the single tuple . The unary relations are the sets of objects with a property: person holds of both Richard and John, king holds only of John (Richard is dead at this point in the story), crown holds only of the crown. The one function, left leg, maps each person to that person's leg. Because functions must be total, even the crown and the legs must map to something under ; the standard trick is an invisible object that is the left leg of everything without one, which does no harm as long as no assertion mentions the left legs of legless things.7

Symbols and the interpretation

A model supplies objects; the other half is the interpretation that connects the vocabulary to them. The vocabulary comes in three kinds of symbol, which by convention begin with an uppercase letter:8

  • Constant symbols stand for objects: , .
  • Predicate symbols stand for relations: , , , , . Each carries an arity fixing its number of arguments.
  • Function symbols stand for functions: , , also with an arity.

The intended interpretation for the kinship scene sends to Richard the Lionheart, to King John, to the two-tuple brotherhood set, to the leg mapping, and so on. Nothing forces this choice. There is also an interpretation that maps to the crown and to a leg — with five objects there are interpretations of the two constant symbols alone, and not every object needs a name. This freedom mirrors propositional logic, where a model can make and both true; it is the knowledge base's job to rule out the models that clash with what we know.

The set of all models is unbounded (after AIMA Fig. 8.4): models vary in how many objects they hold — from one up to infinity — and in how the two constant symbols R and J map onto them, so enumerating models to check entailment is infeasible for first-order logic.

Because the number of objects ranges from one to infinity, the set of models is unbounded, and checking entailment by enumerating models — the method that works for propositional logic — is not feasible here. Even bounding the objects, the count explodes: for two constants and one binary relation there are already models with six or fewer objects.

Syntax: terms and sentences

With the semantics fixed, the syntax is a short grammar (AIMA's Figure 8.3). Everything is built from terms and sentences.

The syntax of first-order logic in Backus-Naur form (after AIMA Fig. 8.3). A sentence is atomic or complex; an atomic sentence is a predicate applied to terms or an equality of terms; a term is a function applied to terms, a constant, or a variable; operator precedence runs (from KaTeX in the caption) , and a quantifier holds over everything to its right.

The semantics of a term is direct: given a term , the interpretation fixes the function that denotes and the objects that the argument terms denote, and the whole term denotes . If denotes King John and denotes the leg mapping, then denotes King John's left leg. The interpretation fixes the referent of every term.

Complex sentences combine atomic ones with the same connectives as propositional logic — , , , , — with the same truth tables. Under the intended interpretation of the kinship model, all four of these are true:9

Quantifiers

The point of objects is being able to quantify over them. First-order logic has two standard quantifiers, universal and existential.10

Universal quantification,

The rule all kings are persons is written

reads for all; is a variable (lowercase by convention). The semantics is careful but intuitive: is true in a model when is true under every extended interpretation that assigns to some domain object. In the kinship model that means checking five extended interpretations, one sending to each object, and confirming the sentence holds in all of them:

Only John is actually a king, so only the second implication has a true premise — and it holds. The other four are true vacuously: an implication is true whenever its premise is false, so the claims about legs and crowns cost nothing. That vacuous truth is why is the connective that pairs with : it asserts the conclusion only for objects that satisfy the premise and stays silent about the rest.

The standard mistake is to reach for instead of :

This says every object in the universe is both a king and a person — that Richard's leg is a king, that the crown is a king. It is far too strong and plainly not what we meant. Use with .

Existential quantification,

To say that King John has a crown on his head — some object is a crown and is on John's head — we write

reads there exists or for some. Its semantics is dual to : is true when holds in at least one extended interpretation. Checking the crown object makes both conjuncts true, so the sentence is true in the model.

Here the natural connective is , and the mirror-image mistake is to use :

Because an implication is satisfied by any object that fails its premise, this sentence is true as soon as some object is not a crown — which is trivially the case — so it says almost nothing. Use with .

The two standard errors. With , using instead of claims every object satisfies both predicates (far too strong); with , using instead of is satisfied by any object that fails the premise (far too weak). The diagonal pairings are the correct ones.

A worked interpretation: evaluating

A universal sentence is true when it holds under every extended interpretation. Carrying one through on the five-object kinship model shows the procedure an inference engine must eventually mechanize. Number the five domain objects: is Richard, is John, is Richard's leg, is John's leg, is the crown. The unary relations are fixed by the model: and . Evaluating means building five extended interpretations , one per object, and checking the body in each.

Evaluating over the five kinship objects. Each row is one extended interpretation; a filled dot marks membership in or . The implication is true in every row — once because both hold (), four times vacuously because the premise fails — so the universal is true.

Only the John row () has a true premise, and there the conclusion also holds, so that row is true outright. The other four rows are true because their premise is false; an implication with a false antecedent is true regardless. The universal is the conjunction of the five body values, so it comes out true. If we had used in place of , the body would read , which is false in the very first row (Richard is a person but not a king), and the whole sentence would collapse to false — the concrete form of the too strong error from the diagram above.

Nested quantifiers and their order

Multiple quantifiers combine to express richer sentences. Consecutive quantifiers of the same type collapse into one: brothers are siblings is , and siblinghood's symmetry is . The subtle case is mixing types, where order matters. Everybody loves somebody is

which says every person has some object (possibly a different one each time) that they love. Swapping the quantifiers gives a different claim, there is someone who is loved by everyone:

The first says everyone has the property of loving someone; the second says a single individual has the property of being loved by all. When the same variable name appears under two quantifiers, the variable belongs to the innermost one that mentions it, so to avoid confusion use distinct names for nested variables.

A concrete model shows the two readings really do differ. Take three people , , and let the relation be — everyone loves , and nobody loves anyone else. Evaluate the outer- sentence by fixing each and asking whether some witness exists: is witnessed by , by , by . Every finds a witness, so the sentence is true. Now the outer- sentence : here a single must work for every . Object does — , , all hold — so this sentence is also true in this model.

The relation as arrows into . Both nested sentences are true here, but they assert different things: lets the witness depend on , while demands one witness good for all . Delete the arrow from and the second sentence fails while the first can still hold.

The equivalence fails in general. Delete the pair and add : now loves instead of . The outer- sentence still holds — every person loves someone — but no single object is loved by everyone, so the outer- sentence is now false. This is the asymmetry that makes quantifier order carry meaning: always follows from , but not the reverse.

The connection between and

The two quantifiers are linked through negation, and obey De Morgan's rules — as they should, since is really a conjunction over the universe and a disjunction. Everyone dislikes parsnips is the same as no one likes them:

More generally,

So and are interdefinable, just as and are. We keep both because readability beats parsimony.

Equality

First-order logic has one further way to build an atomic sentence: the equality symbol, . The sentence says the object denoted by and the object denoted by are one and the same, and it is true exactly when their referents coincide.11 Equality is what lets us insist that two terms name different objects. Richard has at least two brothers needs it:

Without the final conjunct, the sentence is satisfied by taking and to be the same brother, so it would be true even if Richard had only one. The abbreviation stands for .

Where this continues

We now have the full language: a world of objects with relations and functions over them, a model that fixes truth, terms and sentences, the two quantifiers, and equality. That is enough to write knowledge down. What remains is the pragmatics of using it — the semantic shortcuts a database makes, where first-order logic stops and higher-order begins, the Tell/Ask interface, and the disciplined process of turning a real domain into axioms.

This continues in First-Order Logic in Use, which covers database semantics, the first-order/higher-order boundary, and the seven-step knowledge-engineering process on the kinship and digital-circuit domains.

Footnotes

  1. AIMA, §8.1 — Representation Revisited: propositional logic is declarative and compositional but lacks the expressive power to describe an environment with many objects concisely, forcing a separate breeze-pit rule per square.
  2. AIMA, Ch. 8 introduction: first-order logic (also first-order predicate calculus, FOL or FOPC) is expressive enough to represent much commonsense knowledge and subsumes or founds many other representation languages.
  3. AIMA, §8.1.2 — Combining the best of formal and natural languages: keep propositional logic's declarative, compositional, context-independent foundation and borrow from natural language the ontology of objects (nouns), relations (verbs), and functions.
  4. AIMA, §8.1, Figure 8.1 — Formal languages and their ontological and epistemological commitments: propositional logic commits to facts; first-order logic to facts, objects, and relations; both share true/false/unknown epistemology.
  5. AIMA, §8.1.2 — objects, relations (including unary properties and -ary relations), and functions as relations with a single value per input; almost any assertion decomposes into these.
  6. AIMA, §8.2.1, Figure 8.2 — Models for first-order logic: the five-object kinship model with domain, two binary relations (, ), three unary relations, and one unary function ; a relation is a set of tuples.
  7. AIMA, §8.2.1 — Total functions: models require a value for every input tuple, handled by an invisible object that is the left leg of everything without one.
  8. AIMA, §8.2.2 — Symbols and interpretations: constant, predicate, and function symbols, each with an arity; the interpretation specifies their referents, and the intended interpretation is only one of many possible.
  9. AIMA, §8.2.4–8.2.5 — Atomic and complex sentences: an atomic sentence is a predicate applied to terms (arguments may be complex terms) and is true when the relation holds among the referents; connectives build complex sentences as in propositional calculus.
  10. AIMA, §8.2.6 — Quantifiers: universal () with extended interpretations and its pairing with ; existential () with its pairing with ; the -with- and -with- mistakes; nested quantifiers, order, and the / connection through negation and De Morgan's rules.
  11. AIMA, §8.2.7 — Equality: the equality symbol is true when its two terms have the same referent; (abbreviated ) is needed to state that two objects are distinct.

╌╌ END ╌╌