What first-order predicate logic is
First-order predicate logic is a formal language for stating facts about objects, the properties they have, and the relations between them. It adds two tools to simple true-or-false statements: variables that stand for any object, and quantifiers, “for all” (∀) and “there exists” (∃). With these, one rule can cover every object in a domain. The rule “every human is mortal” becomes a single statement, ∀x (Human(x) → Mortal(x)), which reads: for every x, if x is human, then x is mortal.
“First-order” means the quantifiers range over individual objects, not over properties or sets of objects. Logics that also quantify over properties are called second-order. In AI, first-order logic is one of the standard tools for representing knowledge and drawing conclusions from it.
The building blocks
- Constants name specific objects, such as
socratesorblock_a. - Variables, such as
xandy, stand for any object. - Functions map an object to another object.
father(alice)names Alice’s father. - Predicates state a property or a relation, and they are true or false. Examples are
Human(socrates)andParent(alice, bob). - Connectives combine statements: NOT (¬), AND (∧), OR (∨), IF…THEN (→), and IF AND ONLY IF (↔).
- Quantifiers bind a variable. ∀x means “for every x,” and ∃x means “for at least one x.”
Quantifiers and the pattern to get right
Most useful statements follow one of two patterns. A universal statement about a group pairs ∀ with →. An existence statement pairs ∃ with ∧.
- “All students passed”: ∀x (Student(x) → Passed(x))
- “Some student passed”: ∃x (Student(x) ∧ Passed(x))
Swapping the connectives is a common error. ∀x (Student(x) ∧ Passed(x)) says that everything is a student who passed, which is far stronger than intended. ∃x (Student(x) → Passed(x)) is true whenever some object is not a student, so it often says very little.
The order of nested quantifiers also matters. ∀x ∃y Parent(y, x) means every person has some parent. Swapping the quantifiers to ∃y ∀x Parent(y, x) says that one single person is the parent of everyone.
Worked example: the classic syllogism
Start with two premises: all humans are mortal, and Socrates is human. In first-order form:
- ∀x (Human(x) → Mortal(x))
- Human(socrates)
The conclusion is Mortal(socrates). The reasoning takes two steps. Universal instantiation replaces x with socrates in the first premise, which gives Human(socrates) → Mortal(socrates). Modus ponens then combines that with the second premise to give Mortal(socrates). The first step is an instance of a general rule, and that is what makes first-order logic useful.
Worked example: a rule that derives new facts
Rules can produce facts that were never stated. Suppose a knowledge base contains these:
- Parent(ann, ben)
- Parent(ben, carl)
- ∀x ∀y (Parent(x, y) → Ancestor(x, y))
- ∀x ∀y ∀z ((Parent(x, y) ∧ Ancestor(y, z)) → Ancestor(x, z))
The first rule says every parent is an ancestor. The second says that a parent of someone who is an ancestor is also an ancestor. From Parent(ann, ben) and the first rule, the system derives Ancestor(ann, ben). From Parent(ben, carl) it derives Ancestor(ben, carl). Then the second rule, applied to Parent(ann, ben) and Ancestor(ben, carl), gives Ancestor(ann, carl). That last fact was never listed, and the system derived it from the rules.
How AI systems use first-order logic
- Knowledge bases. Facts and rules are stored in a form that a program can search. Expert systems, which were common in the 1970s and 1980s, used if-then rules, a restricted form of logic.
- Logic programming. Prolog programs are written as facts and rules, and a query is answered by searching for a proof. Prolog’s core uses Horn clauses, a restricted subset of first-order logic that keeps the search manageable.
- Automated theorem proving. Programs check whether a conclusion follows from given premises. Resolution, introduced by J. Alan Robinson in 1965, is a refutation method: it assumes the conclusion is false and looks for a contradiction. It is complete for first-order logic, so if a conclusion follows, the method will eventually find it.
- Ontologies and the semantic web. The OWL web ontology language builds on description logics. These are fragments of first-order logic designed to keep reasoning decidable.
How conclusions are drawn
Three steps do most of the work:
- Universal instantiation: from ∀x P(x), conclude P(c) for any constant c.
- Modus ponens: from P → Q and P, conclude Q.
- Unification: find values for variables that make two formulas match. Parent(x, carl) matches Parent(ben, carl) when x is ben.
Logic is one way to reach conclusions. The wider range of methods, including those that do not use logic, is covered in types of inference in artificial intelligence.
Limits and trade-offs
First-order logic is powerful, but it has real costs.
- Undecidability. No algorithm can decide, for every first-order statement, whether it is valid. Alonzo Church proved this in 1936. A proof procedure can confirm a valid statement in finite time, but for an invalid one it may run forever.
- Uncertainty. Plain predicate logic deals with statements that are true or false. It has no direct way to express “probably” or degrees of belief. Those questions need other tools, which are covered in symbolic reasoning under uncertainty in artificial intelligence.
- Missing facts. A knowledge base that lists On(a, b) and On(b, c) does not, on its own, say that nothing else sits on a. To draw that conclusion, the system needs an explicit rule, or it must assume a closed world, where anything not stated is false. Prolog does this through negation as failure.
- Hand-written knowledge. Facts and rules often have to be written and maintained by people. A wrong or missing rule can lead to wrong or missing conclusions.
- The frame problem. When an action changes the world, a logic-based system also needs to state what stays the same. In large domains that list grows very long. John McCarthy and Patrick Hayes described this problem in 1969.
Where logic fits among knowledge representation approaches
Logic is one of several knowledge representation approaches in AI. Other approaches store knowledge as graphs or structured records. Semantic networks show objects as nodes and relations as labeled links, which makes them easy to draw. Logic takes more effort to read, but a statement has a precise meaning, and a reasoner can check conclusions against it.
Key takeaways
- First-order predicate logic describes objects, properties, relations and rules, and it uses ∀ and ∃ to cover many objects with one statement.
- Universal statements pair ∀ with →, and existence statements pair ∃ with ∧.
- AI uses it in knowledge bases, Prolog-style programs, theorem proving and ontologies.
- It is powerful, but it cannot decide every question, and it does not handle uncertainty on its own.