First Order Logic Syntax Semantics
First Order Logic Syntax Semantics
We see that propositional logic requires that we turn the concise and general English sentence into
many statements about specific people. This is a completely impractical and unintuitive way to
represent and communicate such knowledge.
As another example, consider the following general statement about natural numbers.
“If n is a natural number, then n+1 is also a natural number.”
We could try to encode this statement in propositional logic as,
N atural1 ⇒ N atural2
N atural2 ⇒ N atural3
.. .. ..
. . .
However, we would need to have an infinite number of propositional formulas, one for each natural
number. We could place a bound on the natural numbers we are willing to consider, but this is
unsatisfactory. For example, with such a bound we would not be able to correctly answer many
simple queries about the typical interpretation of natural numbers, e.g. “Does there exist a largest
natural number?”. Any true AI should certainly be able to reason about the natural numbers or
other infinite domains, yet propositional logic does not allow for this.
1
2 Upgrading Propositional Logic
In both of these examples we need the ability to directly talk about objects (e.g. people or numbers)
and to write down logical statements that generalize (or quantify) over those objects. First-order
logic gives us this ability.
The examples in the last section can be encoded in first-order logic as
and
∀ x N atural(x) ⇒ N atural(x + 1)
where ∀ and ∃ are universal and existential quantifiers, respectively.
As we will see, the syntax and semantics of first-order (FO) logic allow us to explicitly represent
objects and relationships among object, which provides us with much more representational power
than the propositional case. First-order logic, for example, can be used to represent number theory,
set theory, and even the computations of Turing machines.
3 Syntax of FO Logic
Well-formed formulas (wff) of FO logic are composed of six types of symbols (not counting paren-
theses).
1. constants symbols, which will be interpreted as representing objects, e.g. Bob might be a
constant.
2. function symbols, each having a specified arity (i.e. number of input arguments) and will be
interpreted as functions from the specified number of input objects to objects. For example,
fatherOf is a single-arity function symbol, whose natural interpretation is to return the father
of its input. Zero-arity function symbols are thought of as the same as constants.
3. predicate symbols, each having a specified arity. Single argument predicates can be thought
of as specifying properties of objects. For example, let Rich be a single arity predicate,
then Rich(Bob) would be used to denote that Bob is rich. Zero-arity predicate symbols are
treated as propositions as in propositional logic, so first-order logic subsumes propositional
logic. These propositions can be thought of as properties of the world. Multi-arity predi-
cates denote relations among objects. For example, let Owns be a two-arity predicate, then
Owns(Bob, Car) may be indended to indicate that Bob owns Car.
4. variable symbols, will be used to quantify over objects
5. universal and existential quantifiers, will be used to indicate the type of quantification
6. logical connectives and negation (⇒, ∧, ∨, ⇐⇒ , and ¬), which are the usual way of
composing wffs from other wffs.
Using these symbols there are two main types of syntactic objects in first-order logic. First there are
terms, which will be interpreted as objects. Second, there are formulas, which will be interpreted
as either true or false.
2
Formula → AtomicFormula
| Formula Connective Formula
| Quantifier Variable Formula
| ¬ Formula
| (Formula)
Connective → ⇒ | ∧ | ∨ | ⇐⇒
Quantifier → ∀|∃
Figure 1: The BNF grammar for first-order logic. The well-formed formulas (wffs) are defined
relative to given sets of predicate symbols PRED, constant symbols CONST, function symbols
FUNC, and variables VAR.
• Terms are defined recursively as. The atomic terms are either constant symbols or variable
symbols. Terms can also be compositions of a function symbol applied to the appropriate
number of terms. So for example, Bob, F atherOf (Bob), F atherOf (F atherOf (Bob)), X,
and F atherOf (X) are all terms, where Bob is a constant, X is a variable, and F atherOf is
a function symbol.
• Formulas can be primitive formulas, which are simply predicates applied to the appropriate
number of terms. We can also compose formulas from other formulas via logical connectives
and negation. We can also generate formulas by applying a quantifier over a variable to the
formula, where typically the formula will involve a term with the variable. For example,
T allerT han(Bob, F atherOf (Bob)) is a primitive formula, which indicates that Bob is taller
than his father. Another example
T allerT han(Bob, F atherOf (Bob)) ∧ T allerT han(F atherOf (F atherOf (Bob)), Bob)
is a logical combination of formulas that says Bob is taller than his father but shorter than
his grandfather. Finally, ∃ x T allerT han(F atherOf (x), x) is a quantified formula that says
there exists a person who is shorter than their father.
Figure 1 gives the grammar for the syntax of first-order logic, which shows how these symbols are
used to build terms and formulas.
3
Ground atoms/terms are atoms/terms without variables.
Ground terms are used to refer to specific objects, e.g. Bob or F atherOf (Bob). Ground atoms
are often used to state specific facts such as Rich(Bob) or T allerT han(Bob, F atherOf (Bob)).
Ground formulas are formulas without variables.
Closed formulas are formulas in which all variables are associated with quantifiers. For example,
∀x N umber(x) ⇒ N umber(Successor(x)) is a closed formula. While ∀x GreaterT han(x, y) ⇒
LessT han(y, x) is not a closed formula when y is a variable, since y does not have an associated
quantifier.
Free Variables are variables in a formula that do not have an associated quantifier, such as y in
the second example above. Typically free variables are treated as being implicitly universally
quantified in first-order logic. Our primary reason for introducing the concept of free variables
is to help define the semantics of formulas.
Although we have not yet defined the semantics of first-order logic lets consider some example
formulas along with their intuitive natural language interpretations. Our convention will be to
capitalize at least the first letter of constant symbols and use lowercase for variables.
• “Not all birds can fly.”
¬(∀x Bird(x) ⇒ F ly(x)) , which is the same as
∃x Bird(x) ∧ ¬F ly(x)
5 Semantics of FO Logic
As for all logics, the first step in defining the semantics is to define the models of first-order logic.
Recall that one of the benefits of using first-order logic is that it allows us to explicitly talk about
objects and relations among them. Thus, our models will contain objects along with information
about the relationships among objects. After defining the models of FO logic we will then talk
about the interpretation of strings in FO logic. That is, what is the interpretation of wff and terms
given a model.
4
5.1 First Order Models
More formally, a first-order model is a tuple hD, Ii where D is a non-empty domain of objects and
I is an interpretation function. The domain D is simply a set of objects or elements and can be
finite, infinite, even uncountable. The interpretation function I assigns a meaning or interpretation
to each of the available constant, function, and predicate symbols as follows:
• If c is a constant symbol then I(c) is an object in D. Thus, given a model, a constant can be
viewed as naming an object in the domain.
• If f is a function symbol of arity n then I(f ) is a total function from Dn to D. That is the
interpretation of f is a function that maps n domain objects to the domain D.
• If p is a predicate symbol of arity n then I(p) is a subset of Dn ; that is, a predicate symbol
is interpreted as a set of tuples from the domain. If a tuple O = ho1 , · · · , on i is in I(p) then
we say that p is true for the object tuple O.
For example, suppose that we have one predicate T allerT han, one function F atherOf , and one
constant Bob. A model M1 for these symbols might be the following:
D = { BOB, JON, N U LL }
I(Bob) = BOB
I(T allerT han) = { hBOB, JON i }
Recall that I(F atherOf ) is a function, so to give the interpretation of F atherOf we will just show
the value for each input
D = { BOB, JON }
I(Bob) = BOB
I(T allerT han) = { hBOB, JON i, hJON, BOBi }
I(F atherOf )(BOB) = BOB
I(F atherOf )(JON ) = JON
In the above, it is important to note the distinction between Bob which is a constant (a syntactic
entity) and BOB which is an object in the domain (a semantic entity). The second interpretation
is not what we might have in mind (e.g. the objects are fathers of themselves and T allerT han
is inconsistent), but it is still a valid model. It is the job of the knowledge base to rule out such
unintended models from consideration by placing appropriate constraints on the symbols.
Before we define the semantics of wff and terms, we will need to introduce one more piece of
notation for dealing with variables. Given a model M = hD, Ii, a variable x, and object o ∈ D we
define the extended model M [x → o] as a model that is identical to M , except that I is extended
to interpret x as o, (i.e. I(x) = o).
5
5.2 First-Order Interpretations
We are now ready to define the meaning or interpretations of strings (terms and formulas) relative
to a given model M = hD, Ii. Recall that we will denote the interpretation of a string φ relative
to a model M by φM .
tM = I(t) .
Note that if t is a variable, we assume that M has been “extended” to interpret that variable.
• If t is of the form f (t1 , · · · , tn ) where f is a function symbol and the ti are terms, we have
tM = I(f )(tM M
1 , · · · , tn ) .
So we see that each term t will be interpreted as a distinct object of the domain D.
Given the model M1 from Section 5.1, we can make the following interpretations:
F atherOf (Bob)M1 = I(F atherOf )(BobM1 ) = I(F atherOf )(BOB) = JON
and
F atherOf (F atherOf (Bob))M1 = I(F atherOf )(F atherOf (Bob)M1 ) = I(F atherOf )(JON ) = N U LL
φM = φM M
1 ◦ φ2
φM = ¬φM
1
6
• If φ is of the form, ∃x φ1 where φ1 is a formula (that may or may not involve the variable x),
we get
M [x→o]
true if there exists an o ∈ D such that φ1 = true
φM =
f alse otherwise
• If φ is of the form, ∀x φ1 where φ1 is a formula (that may or may not involve the variable x),
we get
M [x→o]
true if for all o ∈ D we have φ1 = true
φM =
f alse otherwise
Notice the use of extended models M [x → o] to define the semantics of quantified formulas.
7
6 Entailment in FO Logic
The notion of entailment for first-order formulas is defined exactly as for propositional logic. That
is KB |= φ if all the models of KB are also models of φ. For example, KB might be a set of
formulas about the natural numbers and φ might ask whether there is a largest prime number. If
KB accurately captures the natural numbers then φ should be entailed.
To get a sense for this we might consider creating such a KB for the natural numbers by first
having a function Succ for successor, and a predicate N N for natural number. We could then add
a formula such as:
∀x N N (x) ⇒ N N (Succ(x))
If this is the only formula we have then we can see that many possible models satisfy it, including
models with only a finite number of objects. This means that if KB |= φ we can’t be confident
that φ is true for the model of natural numbers that we typically think about. We might then add
a predicate called LessT han with the natural intended interpretation and then add a formula:
This captures some additional intuitive structure of the natural numbers, but still allows many
models that seem inconsistent with the natural numbers. For example, we could have a model with
a single object in the domain D = {1} such that I(Succ(1)) = 1 and I(LessT han) = {h1, 1i}. We
might try to rule out such models by add a formula such as:
7 Summary
Make sure you can do the following things:
• Determine which strings are well-formed formulas and terms of first-order logic.
• Translate English statements into first-order logic expressions and vice versa.
• Determine the interpretation of any formula or term relative to any model, showing the
recursive steps. Likewise given a formula create models that the formula is true or false in.