First-order logic (FOL) describes a world of objects and relations among them, and can state general rules compactly.
Objects, Relations and Functions
FOL assumes the world contains objects (people, numbers, squares), relations between them (brother of, greater than, adjacent) and functions (father of, plus). The syntax has constants naming objects (Ravi, 5), variables (x, y), predicates that are true or false of objects (Brother(Ravi, Amit), Human(x)), functions returning objects (FatherOf(Ravi)), the connectives of propositional logic, the equality symbol and the quantifiers. A term refers to an object; an atomic sentence is a predicate applied to terms, such as Likes(Ravi, IceCream); complex sentences join atomic ones with connectives.
Definition: First-order logic. A formal language with objects, predicates, functions, variables and quantifiers, able to express general statements about the objects of a domain.
Quantifiers
The universal quantifier ∀ means "for all": ∀x Human(x) → Mortal(x) says every human is mortal. The natural connective with ∀ is →; writing ∀x Human(x) ∧ Mortal(x) wrongly says everything is a mortal human. The existential quantifier ∃ means "there exists": ∃x Student(x) ∧ Topper(x) says some student is a topper. The natural connective with ∃ is ∧; using → with ∃ is a common mistake. Quantifiers are related by negation: ¬∀x P(x) ≡ ∃x ¬P(x) and ¬∃x P(x) ≡ ∀x ¬P(x). Nested quantifiers differ by order: ∀x ∃y Loves(x, y) ("everybody loves somebody") is not ∃y ∀x Loves(x, y) ("somebody is loved by everybody").
Translating English
"All birds can fly": ∀x Bird(x) → CanFly(x). "Some birds cannot fly": ∃x Bird(x) ∧ ¬CanFly(x). "Every student has a teacher": ∀x Student(x) → ∃y Teacher(y, x). "No one likes a liar": ∀x ∀y Liar(y) → ¬Likes(x, y). The Wumpus World can be written in FOL as ∀s Breezy(s) ⇔ ∃r Adjacent(r, s) ∧ Pit(r), one rule for the whole cave, where propositional logic needed 16.
Using FOL
A knowledge base in FOL consists of axioms and facts. The classic argument is: ∀x Human(x) → Mortal(x); Human(Socrates); therefore Mortal(Socrates), obtained by universal instantiation (replace x by Socrates) and modus ponens. FOL is far more expressive than propositional logic and is the basis of Prolog, semantic web ontologies and many knowledge bases. It is semi-decidable: if a sentence is entailed, a proof can be found, but if not, the search may never end.
Table 3.2: Propositional versus first-order logic
| Basis | Propositional | First-order |
|---|---|---|
| Elements | Facts (true or false) | Objects, relations, functions |
| Quantifiers | None | ∀ and ∃ |
| General rules | One sentence per case | One sentence for all objects |
| Decidability | Decidable | Semi-decidable |
Example 3.2: Translating and instantiating
Problem: Translate "All humans are mortal. Socrates is human." and derive that Socrates is mortal. Then negate "all birds fly".
Solution:
- Axiom: ∀x Human(x) → Mortal(x). Fact: Human(Socrates).
- Universal instantiation with x = Socrates: Human(Socrates) → Mortal(Socrates).
- Modus ponens with the fact: Mortal(Socrates).
- Negation: ¬∀x (Bird(x) → Fly(x)) ≡ ∃x Bird(x) ∧ ¬Fly(x), "some bird does not fly".
Result: Mortal(Socrates) is derived; the negation of "all birds fly" is "some bird does not fly".
domain = ["Socrates", "Plato", "Rex"]
human = {"Socrates", "Plato"}
mortal = {"Socrates", "Plato", "Rex"}
all_rule = all((x not in human) or (x in mortal) for x in domain)
print("forall x Human(x) -> Mortal(x):", all_rule)
print("exists x Human(x) and Mortal(x):",
any(x in human and x in mortal for x in domain))
print("Mortal(Socrates):", "Socrates" in mortal)
Output
forall x Human(x) -> Mortal(x): True
exists x Human(x) and Mortal(x): True
Mortal(Socrates): True
Common mistakes
- Using ∧ with ∀, which claims that everything has both properties.
- Using → with ∃, which becomes true trivially when the premise is false.
- Swapping the order of ∀ and ∃ and changing the meaning.
- Forgetting that a variable must be quantified (free variables make the sentence open).
Key takeaways
- FOL has constants, variables, predicates, functions, connectives and quantifiers.
- ∀ pairs naturally with →; ∃ pairs naturally with ∧.
- ¬∀x P ≡ ∃x ¬P and ¬∃x P ≡ ∀x ¬P.
- FOL is more expressive than propositional logic and is semi-decidable.
Practice questions
- Translate "All students study" into FOL.
- What is the negation of ∀x P(x)?
- Why is FOL more expressive than propositional logic?
Answers to the practice questions
- ∀x Student(x) → Studies(x).
- ∃x ¬P(x).
- It can talk about objects, relations and functions and state general rules with quantifiers.
Sources
- Official BCA syllabus Artificial Intelligence, course code 26BCA404DS04, Unit III
