First-Order Logic
Module 4
Pros and cons of propositional logic
Propositional logic is declarative
mean that it focuses on expressing facts or statements (propositions)
that are either true or false, without specifying how to compute or
achieve the truth of these statements.
Propositional logic allows partial/disjunctive/negated
information
Partial refers to cases where some details are missing or unknown
Disjunctive information refers to statements that involve alternatives, where one or
more possibilities may be true.
It is raining or it is snowing
Propositional logic is compositional:
• meaning of B1,1 P1,2 is derived from meaning of
B1,1 and of P1,2
– If you know "It may rain tomorrow" but don't
know for sure
Pros and cons of propositional logic
Meaning in propositional logic is context-independent
– (unlike natural language, where meaning depends on context)
Propositional logic has very limited expressive power
– (unlike natural language)
– E.g., cannot say "pits cause breezes in adjacent squares“
• except by writing one sentence for each square
•
•
–
•
Predicate logic
• In Preposition logic each possible atomic fact
requires a separate unique propositional
symbol.
– Eg Anil is engineer
• Ramesh is engineer
– For such n person we require n facts.
• But in first order logic, we can represent this
knowledge as
• Some persons are engineers
Logics in General
• Ontological Commitment:
– What exists in the world — TRUTH
– PL : facts hold or do not hold.
– FOL : objects with relations between them that
hold or do not hold
• Epistemological Commitment:
– What an agent believes about facts — BELIEF
First-order logic
• Whereas propositional logic assumes the
world contains facts,
• first-order logic (like natural language)
assumes the world contains
• Objects: people, houses, numbers, colors,
baseball games, wars, …
• Relations: red, round, prime, brother of,
bigger than, part of, comes between,
Functions: father of, best friend, one more
than, plus, …
Objects
• 1. Objects
• Objects are the entities in the domain.
• Examples:
– People: John, Mary
– Numbers: 5, 7
– Items: Car, House
Relations
2. Relations
• Relations describe how objects interact or relate to each
other.
• A relation can involve one or more objects (unary, binary,
ternary, etc.).
• Examples of Relations:
– Unary Relation: IsTall(John)
(Describes a property of a single object, i.e., "John is tall.")
– Binary Relation: Loves(John, Mary)
(Describes a relationship between two objects, i.e., "John loves Mary.")
– Ternary Relation: Between(A, B, C)
(Describes a relationship among three objects, e.g., "A is between B
and C.")
Functions
3. Functions
• Functions map objects to other objects.
• Functions return a single output for a given input (unlike
relations, which can involve multiple objects without
producing a single result).
• Examples of Functions:
– MotherOf(Mary) → Anna
(A function that maps Mary to her mother, Anna.)
– Age(John) → 30
(A function that maps John to his age, 30.)
– Plus(2, 3) → 5
(A function that maps two numbers to their sum.)
Example in Context:
• "Mary is the mother of John, and John
loves Alice."
• Objects: Mary, John, Alice
• Function: MotherOf(John) → Mary
• Relation: Loves(John, Alice)
FOL (Defnition)
• First-Order Logic (FOL) is a formal system used to
represent and reason about relationships between
objects, their properties, and the rules.
• Components:
– Constants: Represent specific objects in the domain.
– Variables: Represent any object in the domain.
– Predicates: Represent properties or relations between
objects.
– Logical
Connectives: ∧ (and), ∨ (or), ¬ (not), → (implies), etc.
FOL
• Quantifiers:
– Universal Quantifier (∀): Indicates that a statement holds for all
elements in the domain.
– Existential Quantifier (∃): Indicates that there exists at least
one element in the domain for which the statement holds.
• Domain of Discourse:
The set of all objects being considered (e.g., humans,
animals, numbers).
• Syntax and Semantics:
– Syntax: Specifies the rules for forming valid statements in FOL.
– Semantics: Defines the meaning of the terms, predicates, and
the truth of the logical expressions in a given domain.
Advantages
• Expressive Power:
– FOL can represent a wide range of statements involving
objects, their properties, and relationships between them.
– Example: "Every person who owns a car loves driving."
– FOL: ∀x (OwnsCar(x) → LovesDriving(x))
• Precise and Unambiguous:
– FOL has a well-defined syntax and semantics, ensuring
clarity and eliminating ambiguity in logical statements.
• Supports Automated Reasoning:
– FOL is ideal for formal automated theorem proving, where
computers can derive new facts from known facts using
inference rules.
Advantages
• Knowledge Representation in AI:
– FOL is a cornerstone in artificial intelligence for
representing knowledge and enabling automated reasoning about
that knowledge. It is used in expert systems, semantic web
technologies, and logical agents.
• Efficient Querying and Reasoning:
– FOL is effective in databases for querying relationships and retrieving
meaningful information. It's also used in knowledge bases to infer new
facts from existing data.
– Example: "Is there a person who loves programming?"
– FOL: ∃x (Person(x) ∧ LovesProgramming(x))
• Flexibility:
• Unlike propositional logic (which deals only with simple true/false
statements), FOL allows for a richer language capable of expressing
statements about individual objects, their properties, and relationships.
Models for FOL: Example
Syntax of FOL: Basic elements
• Constants KingJohn, 2, NUS,...
• Predicates Brother, >,...
• Functions Sqrt, LeftLegOf,...
• Variables x, y, a, b,...
• Connectives , , , ,
• Equality =
• Quantifiers ,
Syntax of first order logic
Syntax of first order logic
Quantifiers
• They specify whether a statement applies
to all objects or some objects
• Types of Quantifiers
• Universal Quantifier ( ∀ )
– Meaning: "For all" or "Every."
– Symbol: ∀.
– Usage: Asserts that a statement is true for all objects in the
domain.
– Example:
• Statement: "All humans are mortal."
• FOL: ∀x (IsHuman(x) → Mortal(x))
• Meaning: For every object x, if x is human, then x is mortal.
Quantifiers
• Existential Quantifier ( ∃ )
– Meaning: "There exists" or "At least one."
– Symbol: ∃.
– Usage: Asserts that a statement is true for at least
one object in the domain.
– Example:
• Statement: "There exists a person who loves Mary."
• FOL: ∃x (Loves(x, Mary))
• Meaning: There is at least one object x such that x loves
Mary.
Nested Quantifiers
• Nesting of quantifiers occurs when one
quantifier is used inside the scope of
another.
• "Every person has a friend."
• FOL:
– ∀x ∃y (IsFriend(x, y))
– Explanation:
• For every person x (universal quantifier ∀x), there
exists a person y (existential quantifier ∃y) such
that y is a friend of x.
Nested Quantifiers
• "There is someone who is liked by
everyone."
• FOL:
– ∃x ∀y (Likes(y, x))
– Explanation:
• There exists a person x (existential quantifier ∃x)
such that every person y (universal quantifier ∀y)
likes x.
Semantics of FOL
• Semantics defines the meaning of sentences in FOL. It
tells us how to interpret symbols and decide if a
sentence is true or false.
• Key Ideas of Semantics:
– Domain(Universe) of Discourse:
The set of all objects we are talking about.
Example: If the domain is "all people," it might
include John, Mary.
– Interpretation:
Assigns meaning to constants, predicates, and functions:
• John → A specific person.
• IsHuman(x) → True if x is a human.
• Mortal(x) → True if x is mortal.
– Truth:
A statement is true if it matches the meaning assigned to its
components.
Semantics of FOL
• Example of Semantics:
– Statement:
• ∀x (IsHuman(x) → Mortal(x))
– Domain:
• {John, Mary}
– Interpretation:
• IsHuman(John) = true, Mortal(John) = true.
• IsHuman(Mary) = true, Mortal(Mary) = true.
Syntax vs Sematics
Using FOL
• An assertion is a statement or proposition that
is declared as true in a logical system. It asserts a fact
about the domain of discourse.
• Purpose: To make a claim or state something about
the objects in the domain.
• Examples of Assertions:
• "John is a human."
– FOL: IsHuman(John)
– This asserts that the object John is indeed a human.
• "There exists a person who loves Mary."
– FOL: ∃x Loves(x, Mary)
– This asserts that there is at least one object x such that x loves
Mary.
Using FOL
• A query is a request for information or an evaluation of a statement,
usually in the form of a question. A query asks whether a certain
condition is true, and the answer is either true or false.
• Purpose: To check whether a specific statement or property holds in
the domain.
• Examples of Queries:
• "Is John a human?"
– FOL: IsHuman(John)?
– This is a query asking whether John is a human. The answer will
depend on the interpretation (if IsHuman(John) is true in the current
domain).
• "Does everyone love Mary?"
– FOL: ∀x Loves(x, Mary)?
– This is a query asking whether for all x, x loves Mary. The answer
will be true if Loves(x, Mary) holds for every object in the domain.
Assertion in (FOL)
• An assertion in FOL is a logical statement that declares
a fact or relationship about objects in the domain.
Assertions are used to describe the knowledge base of a
system and are assumed to be true.
• Key Characteristics
– Purpose:
Assertions add information to the knowledge base, representing
what is true about the world.
– Example Use:
– "All humans are mortal.“
• FOL ∀x (Human(x) → Mortal(x))
– "John is a human."
• FOL Human(John)
Assertions vs Query
Substitution/binding list
The wumpus world
• Recall that the wumpus agent receives a percept vector
with five elements.
• The corresponding first-order sentence stored in the
knowledge base must include both the percept and the
time at which it occurred; otherwise, the agent will get
confused about when it saw what.
– Percept([Stench, Breeze, Glitter , None, None], 5) . Here,
Percept is a binary predicate, and Stench and so on are
constants placed in a list.
• The actions in the wumpus world can be represented by
logical terms:
– Turn(Right), Turn(Left), Forward, Shoot, Grab, Climb .
The wumpus world
• To determine which is best, the agent program executes
the query
– ASKVARS(∃ a BestAction(a, 5)) ,
• which returns a binding list such as {a/Grab}.
• The agent program can then return Grab as the action to
take
• Simple “reflex” behavior can also be implemented by
quantified implication sentences.
• For example, ∀ t Glitter (t) ⇒ BestAction(Grab, t) .
Knowledge Engineering in (FOL)
• Definition of Knowledge Engineering:
– The process of building a knowledge base by investigating a domain,
identifying important concepts, and formally representing objects and
relationships.
• Role of a Knowledge Engineer:
– Studies a specific domain.
– Identifies critical concepts, objects, and relationships.
– Develops a formal representation using First-Order Logic (FOL).
• Knowledge Engineering Process:
– Domain Analysis: Investigate and understand the chosen domain.
– Concept Identification: Identify key objects, properties, and relations
within the domain.
– Formal Representation: Use FOL to encode knowledge
as facts, rules, and relationships.
– Validation: Ensure the representation supports the intended range of
queries.
Knowledge Engineering in (FOL)
• Special-Purpose Knowledge Bases:
– Designed for narrowly defined domains.
– Focused on specific queries or tasks.
– Example: Electronic circuit domain (e.g., representing resistors, capacitors, and
connections).
• General-Purpose Knowledge Bases :
– Cover a wide range of human knowledge.
– Support complex tasks like natural language understanding.
– More complex to design compared to special-purpose systems.
• Example: Electronic Circuits:
– Domain: Components and connections in electronic circuits.
– Objects: Resistors, capacitors, wires, etc.
– Relationships: Connected(Component1, Component2) represents connections
between components.
– Queries: "Is Component A connected to Component B?"
•
The knowledge-engineering process
• Knowledge engineering projects vary widely in
content, scope, and difficulty, but all such
projects include the following steps:
• 1. Identify the Task
– Define the purpose of the knowledge base.
– Decide on the range of queries the knowledge base
should support.
– Example: In the Wumpus World, determine if the
agent needs to choose actions or answer questions.
The knowledge-engineering process
• 2. Assemble Relevant Knowledge
– Gather domain knowledge.
• Work with experts or rely on existing rules.
• This is called knowledge acquisition.
– Understand how the domain works.
– Example: For Wumpus World, identify rules like adjacency and
movement.
• 3. Decide on a Vocabulary
– Create names for predicates, functions, and constants.
– This forms the ontology of the domain, which defines what "exists."
– Example:
• Represent pits as a unary predicate Pit(square) or as objects.
• Use Location(Wumpus, Time) if location depends on time.
The knowledge-engineering process
• 4. Encode General Knowledge
– Write down general axioms to define terms.
– Ensure that axioms capture the domain accurately.
– Example:
• Axiom: ∀s Smelly(s) → Adjacent(Wumpus, s).
• 5. Encode Specific Problem Instances
– Add facts about the current problem or scenario.
– Example: For a specific Wumpus World map, encode:
• Pit(2, 3)
• Wumpus(4, 4)
The knowledge-engineering process
• 6. Pose Queries
– Use the knowledge base to answer questions.
– Rely on inference procedures to derive new facts.
– Example: Query: "Is square (3, 2) safe?“
• 7. Debug the Knowledge Base
– Test if the knowledge base gives correct answers.
– Fix issues like missing axioms or incorrect rules.
– Example: If the Wumpus cannot be located, check if
all necessary axioms are included.
Summary
• First-order logic:
– objects and relations are semantic primitives
– syntax: constants, functions, predicates,
equality, quantifiers
• Increased expressive power: sufficient to
define wumpus world
Propositional vs FOL
• This section and the next introduce the ideas
underlying modern logical inference systems.
• We begin with some simple inference rules that
can be applied to sentences with quantifiers to
obtain sentences without quantifiers.
• These rules lead naturally to the idea that first-
order inference can be done by converting the
knowledge base to propositional logic and using
propositional inference, which we already know
how to do.
Logical Inference in (FOL)
• Overview of Logical Inference in FOL
• Logical inference in FOL involves deriving new
facts from existing ones by applying rules.
Two key rules for working with quantifiers are
– Universal Instantiation (UI) and
– Existential Instantiation (EI).
Universal Instantiation (UI)
Existential Instantiation (EI)
Existential Instantiation (EI)
Skolemization
• Definition: A process to eliminate existential
quantifiers by replacing them with Skolem
constants.
• Purpose: Simplifies sentences while preserving
inferential equivalence (i.e., satisfiability remains
unchanged).
• UI can produce many consequences, enabling more
inference steps.
• EI simplifies the knowledge base by replacing
existential quantifiers with constants.
Reduction to Propositional Inference
• 1. Overview
– First-order logic (FOL) can be reduced to
propositional logic for inference.
– This process involves replacing quantified
sentences with non-quantified sentences.
Steps for Propositionalization
Example
Problems of propositionalization
• What is the problem?
The old approach (propositionalization) was inefficient because it
created unnecessary sentences, like "If Richard is a king and
greedy, then Richard is evil," even when we only wanted to find out
if John is evil.
• What do we want?
We want a more direct way to deduce that John is evil based on the
rules and facts we already have.
• What do we have?
Problems of propositionalization
• What should happen?
The computer should directly apply the rule to the facts:
– The rule says anyone who is a king and greedy is evil.
– John is both a king and greedy.
– Therefore, Evil(John)Evil(John)Evil(John).
• This direct application avoids creating unnecessary sentences
about others (like Richard).
• It makes the process clear and efficient, just as it is to a human
reader.
Lifting
• Lifting refers to the process of extending inference methods or rules from a
lower level of abstraction (such as variable-free logic) to a higher level that
can handle variables and quantifiers, such as in first-order logic.
• This makes the inference process more general and efficient.
• Why is Lifting Needed?
– In propositional logic:
– Inference methods work with ground facts (facts without variables).
– You must enumerate all possible substitutions or instances explicitly.
– In first-order logic:
– Facts and rules often involve variables (e.g.,
– Instead of creating many ground instances, lifting allows reasoning to
happen at the variable level, applying substitutions only where
necessary.
Generalized Modus Ponens
• Generalized Modus Ponens (GMP) is an inference rule in first-
order logic that generalizes the basic Modus Ponens rule from
propositional logic to handle variables and quantifiers.
• It allows you to infer conclusions by matching patterns in rules and
facts using substitutions.
Unification
• Definition:
Unification is the process of finding a substitution that makes two
logical expressions identical by mapping variables to terms
(constants or other variables).
• Purpose:
To match logical expressions (facts and rules) by resolving
differences in variables, enabling inference to proceed.
• What is Unification?
Unification is the process of finding a substitution θ\thetaθ that
makes two logical expressions identical.
Storage and Retrieval
• Purpose of Storage and Retrieval:
– STORE(s): Saves a sentence s into the
knowledge base.
– FETCH(q): Finds all sentences in the
knowledge base that unify with the query q.
• Naive Implementation:
– All facts are stored in a long list.
– Each query is unified with every fact in the list.
– Inefficient: Time-consuming when the knowledge
base is large.
• Improved Efficiency:
• Indexing:Predicate Indexing: Facts are grouped by their
predicate.
• Example: All Knows(...) facts go in one bucket, Brother(...) facts in
another.
– Limitations:
• If a bucket contains many facts (e.g., millions of employees for
Employs(x,y), searching within the bucket can still be slow.
• Advanced Indexing:
– Index facts using combinations of predicates
and arguments for faster queries.
• Example:
– Index by the second argument for queries like
Employs(x,Richard).
– Index by the first argument for queries like Employs(IBM,y).
– Multiple keys can be created for one fact,
enabling quick access for various query
patterns.
• Subsumption Lattice:
• A structure that organizes all possible queries that unify with a fact.
• Key Properties:
– Nodes are linked by substitutions.
– The most general query lies at the top of the lattice.
Forward Chaining
• When based on available data a decision is taken
then the process is called as forward chaining
• It works from a initial state and reaches to goal state
• Consider the problem: The law says that it is a
crime for an American to sell weapons to hostile
nations. The country Nono, an enemy of America,
has some missiles, and all of its missiles were sold
to it by Colonel West, who is American.
• We will prove that West is a criminal.
• It is a crime for an American to sell
weapons to enemy of America.
• Country Nono, an enemy of America,
• Nono has some missiles,
• all of its missiles were sold to Nono by
Colonel
• Missile is a weapon
• Colonel is American.
FOL
• Scenario: Prove Colonel West is a criminal based on the following
knowledge
• Law: "It is a crime for an American to sell weapons to hostile nations":
– American(x) ∧ Weapon(y) ∧ Sells(x, y, z) ∧ Hostile(z) ⇒ Criminal(x)
• Nono is an enemy of America:
– Enemy(Nono, America)
• Nono owns some missiles:
– Owns(Nono, M1) (introducing a constant M1 for "some missile").
– Missile(M1)
• All missiles in Nono were sold by Colonel West:
– Missile(x) ∧ Owns(Nono, x) ⇒ Sells(West, x, Nono)
• Missiles are weapons:
– Missile(x) ⇒ Weapon(x)
• An enemy of America is hostile:
– Enemy(x, America) ⇒ Hostile(x)
• West is American:
– American(West)
Proof of forward chaining
Forward Chaining Algorithm
• Input:
– A knowledge base (KB) with rules and facts.
– A query or goal to check if it can be inferred.
• Initialization:
– Start with a set of known facts from the KB.
• Repeat Until No More New Facts:
– For each rule in the KB:
• Check if all conditions in the rule's antecedent (left side) are true based on known
facts.
• If true, infer the consequent (right side) of the rule.
• Add the inferred fact to the set of known facts if it’s not already there.
• Stopping Condition:
– If the query (goal) is in the set of known facts, return true (goal is inferred).
– If no new facts can be inferred and the query is not in the known facts, return
false (goal cannot be inferred).