0% found this document useful (0 votes)
3 views

module 4

This document discusses the syntax and semantics of First Order Logic (FOL), highlighting its advantages over propositional logic in knowledge representation. It covers key concepts such as models, terms, atomic sentences, and complex sentences, emphasizing the importance of relations and functions in FOL. Additionally, it addresses the limitations of programming languages for knowledge representation and the implications of using formal logic systems.

Uploaded by

CHANDAN C V
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

module 4

This document discusses the syntax and semantics of First Order Logic (FOL), highlighting its advantages over propositional logic in knowledge representation. It covers key concepts such as models, terms, atomic sentences, and complex sentences, emphasizing the importance of relations and functions in FOL. Additionally, it addresses the limitations of programming languages for knowledge representation and the implications of using formal logic systems.

Uploaded by

CHANDAN C V
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 53

MODULE 04

Syntax and Seman cs of First Order logic

Using First Order logic

Knowledge Engineering In First-Order Logic

Proposi onal Versus First Order Inference

Unifica on

Forward Chaining

8.1 REPRESENTATION REVISITED


Representa on Languages: Introduc on

Representa on languages are systems used to store and reason about knowledge. They
enable us to describe, infer, and derive conclusions about the world. The sec on highlights
the transi on from proposi onal logic (covered earlier) to first-order logic (FOL), which is
more expressive and capable of handling complex knowledge.

Programming Languages vs. Representa on Languages

Programming languages (e.g., C++, Java, Lisp) are o en used to represent computa onal
processes and data. However, they have significant limita ons when used as general-
purpose representa on languages:

 Strengths:

o They can represent facts through data structures (e.g., arrays).

o Statements like World[2,2] ← Pit can describe specific facts, such as a pit
being in square [2,2].

 Weaknesses:

o Lack general mechanisms for deriving facts from other facts. This means
updates to data structures are domain-specific and rely on the programmer's
knowledge.

o Cannot easily handle par al informa on (e.g., uncertainty or disjunc on, like
"There is a pit in [2,2] or [3,1]").

o Lack declara ve reasoning, where knowledge representa on and inference


are separate.

These limita ons make programming languages less suited for domain-independent
knowledge representa on compared to declara ve systems like proposi onal logic.
Proposi onal Logic

Proposi onal logic is a declara ve language with key proper es that make it useful for
knowledge representa on:

1. Declara ve Nature:

o Proposi onal logic separates knowledge (facts) from inference (reasoning).

o Inference is domain-independent, allowing general reasoning capabili es.

2. Expressiveness:

o It can represent par al informa on through constructs like disjunc on (OR)


and nega on (NOT).

o For example: "There is a pit in [2,2] or [3,1]" can be wri en as P2,2 ∨ P3,1.

3. Composi onality:

o The meaning of a sentence is determined by its parts.

o For example: S1,4 ∧ S1,2 means "stench in square [1,4] and square [1,2],"
combining the meanings of S1,4 and S1,2.

Drawbacks of Proposi onal Logic:

 Limited expressiveness for environments with many objects or rela onships. For
instance, describing rules like "Squares adjacent to pits are breezy" requires mul ple
individual sentences, leading to redundancy.

First-Order Logic (FOL)

To address the limita ons of proposi onal logic, First-Order Logic was developed. FOL
introduces:

 Objects: En es in the world (e.g., squares, pits).

 Predicates: Rela ons between objects (e.g., Adjacent(x, y)).

 Quan fiers: Universal (∀) and existen al (∃) quan fiers for concise representa on.

o Example: "All squares adjacent to pits are breezy" can be wri en as:

8.1.1 The language of thought


Natural languages (like English or Spanish) are highly expressive, allowing humans to convey
complex ideas. However, they are not ideal for formal knowledge representa on due to the
following issues:

1. Ambiguity:

o Words can have mul ple meanings depending on context. For example,
"spring" could mean a season or a coiled object.

2. Context Dependence:

o Sentences like "Look!" rely heavily on the surrounding context for meaning.
Without storing context, it’s difficult to infer their meaning in a knowledge
base.

3. Sapir-Whorf Hypothesis:

o This hypothesis suggests that language shapes thought. For example:

 Guugu Yimithirr speakers, who lack rela ve direc ons (e.g., le , right),
excel in naviga ng open terrain using absolute direc ons (e.g., north,
south).

 Gramma cal differences (e.g., gendered nouns in Spanish and


German) influence percep on. For example, "bridge" is described
differently by Spanish (masculine) and German (feminine) speakers.

Representa on in the Brain

Recent studies suggest that humans process language and store knowledge using nonverbal
representa ons:

 Wanner’s Experiment (1974):

o Showed that people remember content be er than exact phrasing,


sugges ng abstract knowledge storage.

 fMRI Studies:

o Brain imaging reveals that words and concepts ac vate specific neural
pa erns.

o Computers trained on fMRI data can predict words people think of,
demonstra ng shared representa on across individuals.

Prac cal Implica ons of Representa on

While formal logic treats different representa ons of the same knowledge as equivalent,
prac cal reasoning systems favor certain representa ons because they are more efficient.
For example:
 Succinctness: More concise representa ons lead to faster reasoning.

 Learning: Representa on choice influences how effec vely systems learn from data.

8.1.2 Combining the best of formal and natural languages


Formal Languages and Their Founda on

 Proposi onal Logic:

o Founda on for many logical systems.

o Represents facts as true or false.

o Each proposi on symbol corresponds to a fact.

 Extending Beyond Proposi onal Logic:

o While proposi onal logic is simple and unambiguous, it lacks the richness to
describe rela onships or general rules (e.g., "All neighboring squares are
smelly").

o Enhanced logic systems like first-order logic (FOL) build on proposi onal logic
to address these limita ons.

Incorpora ng Elements of Natural Language

Natural language is expressive but ambiguous. Logic can mimic its expressiveness without
ambiguity. Key elements borrowed include:

 Objects:

o Refer to things or en es: e.g., people, numbers, places.

o Examples: Ronald McDonald, squares, wumpus, numbers.

 Rela ons:

o Connect objects or describe proper es.

o Can be unary (proper es) or n-ary (rela ons).

o Examples:

 Unary rela ons (proper es): red, round, prime.

 N-ary rela ons: brother of, part of, has color.

 Func ons:

o Special rela ons where one input produces one output.

o Examples: father of, beginning of, one more than.


Examples of Logic and Natural Language

 "One plus two equals three":

o Objects: one, two, three, "one plus two."

o Rela on: equals.

o Func on: plus (maps one and two to three).

 "Squares neighboring the wumpus are smelly":

o Objects: wumpus, squares.

o Property: smelly.

o Rela on: neighboring.

 "Evil King John ruled England in 1200":

o Objects: John, England, 1200.

o Rela ons: ruled.

o Proper es: evil, king.

Ontological Commitment (What Exists in the World)

Each logic assumes a different view of reality:

 Proposi onal Logic:

o Reality consists of facts that are true or false.

 First-Order Logic:

o Adds objects and rela ons to proposi onal logic's facts.

 Temporal Logic:

o Adds me as a factor (e.g., facts can hold at specific points or intervals in


me).

 Probability Theory:

o Represents beliefs about facts as probabili es (e.g., 0.75 belief that the
wumpus is in [1,3]).

 Fuzzy Logic:

o Represents facts with degrees of truth (e.g., a glass is "half-full").

Epistemological Commitment (What Can Be Known)

 Logic systems also differ in how they handle knowledge:


o Proposi onal and First-Order Logic:

 Beliefs about facts can be true, false, or unknown.

o Probability Theory:

 Beliefs are expressed as probabili es (ranging from 0 to 1).

o Fuzzy Logic:

 Truth values are intervals (e.g., 0.4 to 0.6).

Higher-Order Logic and Special-Purpose Logics

 Higher-Order Logic:

o Extends first-order logic to treat rela ons and func ons as objects.

o Enables reasoning about proper es of rela ons (e.g., transi vity).

 Special-Purpose Logics:

o Tailored for specific domains (e.g., temporal logic for reasoning about me).

Comparison of Logical Systems

8.2 SYNTAX AND SEMANTICS OF FIRST-ORDER LOGIC


8.2.1 Models for first-order logic
Models in FOL

What is a Model?

A model is a formal structure that represents a possible world and allows us to evaluate the
truth of logical sentences. It links the vocabulary of FOL (symbols) to elements in the
possible world.

 Proposi onal Logic Models: Link proposi on symbols to predefined truth values.

 FOL Models:
o Include objects in a domain.

o Relate objects through rela ons and func ons.

Domain of a Model

 The domain is the set of objects (also called domain elements) in the model.

 Requirement: The domain must be non-empty (there must be at least one object).

 Example:

o The domain contains: Richard the Lionheart, King John, their le legs, and a
crown.

Rela ons in FOL

 A rela on connects objects in the domain.

 Represented as a set of tuples of objects.

o Example:

 Brotherhood rela on:


{ <Richard the Lionheart, King John>, <King John, Richard the
Lionheart> }.

 "On head" rela on:


{ <the crown, King John> }.

Types of Rela ons

1. Binary Rela ons: Relate pairs of objects.


o Example: Brotherhood, "On head".

2. Unary Rela ons (Proper es): Apply to single objects.

o Example:

 Person applies to Richard and John.

 King applies only to John.

 Crown applies only to the crown.

Func ons in FOL

 Func ons are specialized rela ons that map objects uniquely to other objects.

 Example: "Le leg" func on maps:

o Richard the Lionheart → Richard’s le leg.

o King John → John’s le leg.

Total Func ons

 Func ons in FOL must be total, meaning every input has an output.

 Even objects like a crown must have a le leg.

 This is handled technically by introducing an "invisible" object to serve as a


placeholder for impossible mappings.

8.2.2 Symbols and interpreta ons

Syntax of FOL

FOL uses three types of symbols:

1. Constant Symbols: Represent specific objects.

o Example: Richard, John.

2. Predicate Symbols: Represent rela ons.

o Example: Brother, OnHead, Person, King, Crown.

3. Func on Symbols: Represent func ons.

o Example: Le Leg.

Arity

 Arity specifies the number of arguments a predicate or func on takes:

o Unary (1 argument): Person, King.


o Binary (2 arguments): Brother, OnHead.

Interpreta on

 A model’s interpreta on links symbols to specific objects, rela ons, or func ons in
the domain.

Example Interpreta on

1. Constant Symbols:

o Richard → Richard the Lionheart.

o John → King John.

2. Predicate Symbols:

o Brother → Brotherhood rela on: { <Richard, John>, <John, Richard> }.

o OnHead → { <the crown, John> }.

o Person → Set of people: { Richard, John }.

3. Func on Symbols:

o Le Leg → Mapping:

 Richard → Richard’s le leg.

 John → John’s le leg.

Key Characteris cs of Models in FOL

Mul plicity of Interpreta ons

 A single model allows mul ple interpreta ons of symbols.

 Example:

o Richard could refer to Richard the Lionheart or the crown.

o There are 25 possible interpreta ons for two constants (Richard and John)
with five objects in the domain.

Naming Objects

 Not all objects need names in the model.

 Example: The crown and le legs may remain unnamed in an interpreta on.

Overlapping Names

 Objects can have mul ple names.

 Example: Both Richard and John could refer to the crown in one interpreta on.
Complexity of FOL Models

 Models in FOL vary based on:

o The number of objects in the domain.

o The way symbols are mapped to objects.

 Example:

o If the domain has 6 objects, there are 137,506,194,466 possible models.

Prac cal Implica ons

 Enumera ng all models to check logical entailment is infeasible.

 FOL requires more advanced techniques than proposi onal logic for reasoning.
8.2.3 Terms
 Defini on of a term:
A term in logic is an expression that refers to an object. For example:

o A constant symbol refers to a specific object. (e.g., John refers to King John.)

o A func on symbol generates terms to refer to objects indirectly.


Example: Instead of naming King John’s le leg with a constant, we use a
func on like Le Leg(John).

 Complex terms:
A complex term combines a func on symbol with a list of arguments.
Example: Le Leg(John) refers to King John’s le leg.
Key points:

o A complex term is just a name (like a label) for an object.

o It is not a subrou ne that "calculates" a value, as in programming.

 Seman cs of terms:

o If a term is f(t1, ..., tn):

 The func on symbol f refers to a func on in the logical model.

 The arguments t1, ..., tn refer to objects in the domain of the model.

 The term as a whole refers to the output of the func on applied to


those objects.
Example:

 If Le Leg refers to a func on mapping people to their le legs and


John refers to King John, then Le Leg(John) refers to King John’s le
leg.

8.2.4 Atomic Sentences


 Defini on:
An atomic sentence is the simplest type of logical sentence, formed by combining:

1. A predicate symbol, which represents a rela on.

2. A list of terms as arguments (op onal).

Examples:

o Brother(Richard, John) states that Richard is the brother of John.


o Married(Father(Richard), Mother(John)) states that Richard’s father is married
to John’s mother.

 Truth condi ons for atomic sentences:


An atomic sentence is true in a given model if:

o The rela on represented by the predicate holds for the objects referred to
by the terms.

8.2.5 Complex Sentences


 Logical connec ves:
You can combine atomic sentences using logical operators, such as:

o ¬ (not): Nega on. Example: ¬Brother(Le Leg(Richard), John) means


"Richard’s le leg is not John’s brother."

o ∧ (and): Conjunc on. Example: Brother(Richard, John) ∧ Brother(John,


Richard) states both sentences are true.

o ∨ (or): Disjunc on. Example: King(Richard) ∨ King(John) states that either


Richard or John is a king.

o ⇒ (implies): Implica on. Example: ¬King(Richard) ⇒ King(John) means "If


Richard is not a king, then John is a king."

These connec ves func on just as in proposi onal logic.

8.2.6 Quan fiers


Quan fiers allow general statements about groups of objects.

Universal Quan fica on (∀)

 Syntax: ∀x P(x) means "For all x, P(x) is true."


Example: ∀x King(x) ⇒ Person(x) means "All kings are persons."

 Interpreta on:

o A universally quan fied sentence is true if the predicate holds for every
object in the domain of discourse.

o Example:
For the domain {Richard, John, Richard’s le leg, John’s le leg, crown}, the
sentence ∀x King(x) ⇒ Person(x) means:

 If x is a king, then x is a person.

 Objects like legs and crowns are irrelevant since they are not kings
(the premise King(x) is false for them).
o Truth table of ⇒:

 Recall: A ⇒ B is true if either A is false or both A and B are true.

 This ensures the sentence asserts the conclusion only for objects that
sa sfy the premise.

Common Mistake:

 Incorrect sentence: ∀x King(x) ∧ Person(x)

o This asserts that every object in the domain is both a king and a person
(which is clearly incorrect for legs and crowns).

o Correct usage involves implica on, as in ∀x King(x) ⇒ Person(x).

Existen al Quan fica on (∃)

Existen al quan fica on is used to assert that a statement holds true for at least one object
in a given domain. The symbol ∃ (pronounced "there exists") represents this quan fier.

For example:

∃x Crown(x)∧OnHead(x,John)

This sentence can be read as: "There exists an xxx such that x is a crown and x is on John's
head."

Formal Seman cs

The meaning of ∃xP (where P is any logical expression) is that P is true in at least one
extended interpreta on of the model where xxx refers to a specific domain element. This
means:

1. Assign x to an object in the domain.

2. Evaluate whether P is true for at least one such assignment.

For the example:

 x could refer to "Richard the Lionheart," "King John," "Richard's le leg," "John's le
leg," or "the crown."

 The sentence Crown(x)∧OnHead(x,John)

will evaluate as follows:

o Richard the Lionheart is not a crown.

o King John is not a crown.

o Richard's le leg is not a crown.


o John's le leg is not a crown.

o The crown is a crown and is on John's head.

Since one valid interpreta on exists (the crown is on John's head), the existen al statement
is true.

Key Connec ve

The main logical connec ve for existen al quan fiers is conjunc on (∧) because we are
asser ng that the existence of xxx sa sfies all parts of the statement.

Implica ons with ∃

Using ⇒⇒⇒ (implica on) with ∃o en leads to weak or ambiguous statements. For example:
∃x (Crown(x)⇒OnHead(x,John) This translates to:

 If x is a crown, then x is on John's head.

The implica on is true in the following cases:

1. If x is not a crown (premise is false, so the whole implica on is true).

2. If x is a crown and is on John's head (premise and conclusion are true).

In prac ce, this formula on doesn’t effec vely express "there exists a crown on John's head"
because it can be true regardless of whether any crown exists.

Nested Quan fiers

Logical statements o en involve mul ple quan fiers, which can be of the same type (e.g.,
all universal or all existen al) or mixed.

Same-Type Quan fiers

Consider the statement: "Brothers are siblings."


This can be expressed as: ∀x∀y (Brother(x,y)⇒Sibling(x,y))

Here:

 ∀x∀y is shorthand for saying the statement applies to all possible combina ons of x
and y.

 The order of the quan fiers does not ma er in this case.

Mixed Quan fiers

For statements involving universal and existen al quan fiers, order ma ers.

Example 1:
"Everybody loves somebody."
∀x ∃y Loves(x,y)
This means: For every person xxx, there exists someone y such that xxx loves y.

Example 2:
"There is someone who is loved by everyone."
∃y ∀x Loves(x,y)
This means: There exists a person y such that every person x loves y.

The difference:

 In Example 1, the quan fiers assert that each person has someone they love.

 In Example 2, the quan fiers assert that there is one person loved by all.

Variable Scope

Connec on Between ∀ and ∃

The two quan fiers are interconnected through nega on:

1. ∀x P is equivalent to ¬∃x¬P:
"For all x, P" is the same as "There does not exist an xxx for which P is false."

2. ∃x P is equivalent to ¬∀x¬P:
"There exists an x for which P" is the same as "It is not the case that P is false for all
x."

De Morgan’s Laws for Quan fiers

These laws show how nega on interacts with quan fiers:

 ∀x¬P(x)≡¬∃xP(x)

 ¬∀xP(x)≡∃x¬P(x)

 ∀xP(x)≡¬∃x¬P(x)

 ∃xP(x)≡¬∀x¬P(x)

These equivalences show that both ∀ and ∃ can be expressed in terms of each other, just as
logical conjunc on (∧) and disjunc on (∨) are duals.

8.2.7 Equality
First-order logic (FOL) allows comparisons between terms to determine if they refer to the
same object. This is done using the equality symbol (=). For example:

 Father(John) = Henry means that "the father of John is Henry."

Truth Evalua on of Equality

The truth value of an equality statement depends on the interpreta on:

 If Father(John) and Henry both refer to the same object in the model, the statement
is true.

 Otherwise, it is false.

Inequality and Its Use

To assert that two terms are not the same object, we use nega on:

 ¬(x = y) or shorthand x ≠ y.

For instance, to express that Richard has at least two brothers, we write:

 ∃x, y (Brother(x, Richard) ∧ Brother(y, Richard) ∧ x ≠ y).

This ensures:

1. Richard has two brothers (via the Brother predicate).

2. The two brothers are dis nct (via x ≠ y).

Complex Statements with Equality

Some mes, simple asser ons using equality may lead to incorrect interpreta ons. For
example:

 ∃x, y (Brother(x, Richard) ∧ Brother(y, Richard)) does not guarantee Richard has two
dis nct brothers. If both x and y are assigned the same value (e.g., King John), the
statement can s ll hold true.

Adding the condi on x ≠ y ensures dis nctness.

Describing Specific Rela onships

To say "Richard’s brothers are John and Geoffrey":

1. Both John and Geoffrey must sa sfy the Brother predicate.

2. John and Geoffrey must be dis nct.

3. No other individuals are Richard's brothers.

This is expressed as:


 Brother(John, Richard) ∧ Brother(Geoffrey, Richard) ∧ John ≠ Geoffrey

 ∀x (Brother(x, Richard) ⇒ (x = John ∨ x = Geoffrey)).

8.2.8 An alterna ve seman cs?


Standard Seman cs

In standard FOL seman cs:

 Objects in the domain are independent of the symbols used.

 Each interpreta on assigns a unique meaning to predicates, constants, and func ons.

Database Seman cs

To simplify logical expressions in certain contexts, database seman cs introduces


assump ons:

1. Unique-names assump on: Each constant refers to a dis nct object.

o Example: John and Geoffrey must be dis nct.

2. Closed-world assump on: Any statement not explicitly true is considered false.

o Example: If we don’t know that William is Richard's brother, we assume he is


not.

3. Domain closure: The domain contains only the objects explicitly named by constants.

o Example: If John and Geoffrey are the only constants, no unnamed brothers
of Richard exist.

Example with Database Seman cs

Using these assump ons, the statement:

 Brother(John, Richard) ∧ Brother(Geoffrey, Richard) Directly implies:

1. John and Geoffrey are Richard’s only brothers.

2. They are dis nct (due to the unique-names assump on).


8.3 USING FIRST-ORDER LOGIC
First-Order Logic (FOL) is an expressive logical language that allows us to represent and
reason about knowledge in specific domains.

Domains and Knowledge Representa on

What is a Domain?

A domain refers to a specific part of the world we want to represent using knowledge. For
example:

 Kinship domain: Rela onships like parent, sibling, and grandparent.

 Mathema cal domain: Numbers, sets, and lists.

 Wumpus world: A logic-based game environment.

In each domain, FOL is used to express asser ons (facts) and queries about the rela onships
and objects within it.

8.3.1 Asser ons and queries in first-order logic


1. Asser ons (TELL)

 TELL is the mechanism to add knowledge (facts or rules) to a knowledge base.

 For example:

o TELL(KB, King(John)): Assert that John is a king.

o TELL(KB, Person(Richard)): Assert that Richard is a person.

o TELL(KB, ∀x King(x) ⇒ Person(x)): Assert that all kings are persons.

These are stored in the knowledge base as axioms.

2. Queries (ASK)

 ASK is used to retrieve informa on from the knowledge base.

 Queries can be:

o Specific: For example, ASK(KB, King(John)) returns true because John is a


king.

o Derived: For example, ASK(KB, Person(John)) returns true because John is


inferred to be a person (from the rule that all kings are persons).

3. Quan fied Queries

 Queries can involve variables:


o ASK(KB, ∃x Person(x)): Asks if there exists any person in the domain.

o The answer is true, but it does not specify the exact individuals.

4. Finding Bindings (ASKVARS)

 To retrieve specific values that sa sfy a query, ASKVARS is used.

o Example: ASKVARS(KB, Person(x)) returns {x/John} and {x/Richard} if both


John and Richard are persons.

o This is called a binding list or subs tu on.

5. Horn Clause Restric on

 ASKVARS works best with Horn clauses: Knowledge bases where queries can always
bind variables to specific values.

8.3.2 The kinship domain


Objects and Predicates

 Objects: Represent individuals, such as Elizabeth, Charles, and William.

 Predicates:

o Unary: Proper es of individuals, e.g., Male(x) or Female(x).

o Binary: Rela onships between individuals, e.g., Parent(x, y) or Spouse(x, y).

Examples of Defini ons in the Kinship Domain

1. Mother: A mother is a female parent.

o ∀m, c Mother(c) = m ⇔ Female(m) ∧ Parent(m, c)

2. Husband: A husband is a male spouse.

o ∀w, h Husband(h, w) ⇔ Male(h) ∧ Spouse(h, w)

3. Gender Categories: Male and female are disjoint.

o ∀x Male(x) ⇔ ¬Female(x)

4. Parent and Child: Parent and child are inverse rela ons.

o ∀p, c Parent(p, c) ⇔ Child(c, p)

5. Grandparent: A grandparent is the parent of a parent.

o ∀g, c Grandparent(g, c) ⇔ ∃p Parent(g, p) ∧ Parent(p, c)

6. Sibling: A sibling is another child of the same parent.


o ∀x, y Sibling(x, y) ⇔ x ≠ y ∧ ∃p Parent(p, x) ∧ Parent(p, y)

Axioms and Theorems

What are Axioms?

 Axioms are founda onal statements or rules about a domain.

 Examples:

o Defini ons like ∀p, c Parent(p, c) ⇔ Child(c, p).

o General facts, e.g., Male(Jim) or Spouse(Jim, Laura).

What are Theorems?

 Theorems are statements that follow logically from axioms.

o Example: Siblinghood is symmetric:

 ∀x, y Sibling(x, y) ⇔ Sibling(y, x)

 This can be derived from the defini on of siblinghood.

Key Differences

 Axioms must be explicitly added to the knowledge base.

 Theorems are derived through inference.

Prac cal Use of Theorems

 Including theorems in the knowledge base can reduce computa onal cost.

o Example: Sta ng that siblinghood is symmetric avoids recomputa on for


every query.

Par al and Complete Defini ons

 Not all predicates have a complete defini on.

o Example: ∀x Person(x) ⇔ . . . cannot be fully defined.

 Instead, par al specifica ons can describe:

o Necessary proper es: ∀x Person(x) ⇒ ...

o Sufficient proper es: ∀x ... ⇒ Person(x)

Plain Facts

 Plain facts describe specific instances:

o Male(Jim)
o Spouse(Jim, Laura)

Handling Missing Axioms

 If a query result is unexpected, it may indicate a missing axiom.

o Example: From Spouse(Jim, Laura), we expect ¬Spouse(George, Laura), but


this does not follow unless Jim ≠ George is explicitly stated.

o Adding this axiom resolves the ambiguity.

8.3.3 Numbers, sets, and lists


This sec on discusses how mathema cal structures like numbers, sets, and lists can be
represented in first-order logic, using axioms to define their proper es and opera ons.

1. Natural Numbers and Peano Axioms

The theory of natural numbers (non-nega ve integers) can be built from a few basic axioms,
known as the Peano axioms. These axioms define the natural numbers and the fundamental
opera ons on them, like addi on.

Natural Numbers Defini on (Peano Axioms)

We begin by defining natural numbers using a predicate NatNum, which is true for natural
numbers. We also introduce a constant symbol 0 and a func on symbol S, represen ng the
successor func on, which gives the next number.

This recursive defini on allows us to generate all natural numbers: 0, S(0), S(S(0)), and so on.

Successor Func on Proper es

We need to constrain the successor func on S(n):


Defining Addi on with Successor

Once we have the basic structure of natural numbers, we can define addi on using the
successor func on. Addi on is defined recursively:

Using these axioms, we can define addi on using the successor func on. For example, 1 + n
is S(n) (the successor of n), and 2 + n is S(S(n)), and so on.

Infix Nota on as Syntac c Sugar

In first-order logic, we use prefix nota on for func ons (e.g., +(m, 0)), but we can use infix
nota on (m + 0) as syntac c sugar to make the expressions easier to read.

This expresses that adding 1 to a number is equivalent to adding 1 a er the sum of the
number and another.
Sets in First-Order Logic

Sets are fundamental objects in both mathema cs and everyday reasoning. In first-order
logic, we can represent sets, elements, and opera ons on sets with predicates and
func ons.

Basic Set Theory

We need:

 A predicate Set(s) to check if s is a set.

 A binary predicate x ∈ s, which tells whether x is an element of set s.

 A binary predicate s1 ⊆ s2, which tells whether set s1 is a subset of set s2.

We also need func ons for common set opera ons like:

 Union: s1 ∪ s2 (union of sets s1 and s2).

 Intersec on: s1 ∩ s2 (intersec on of sets s1 and s2).

 Set construc on: {x | s} (set formed by adding element x to set s).

Set Axioms
These axioms help define the basic opera ons on sets like union, intersec on, subset, and
equality.

Lists in First-Order Logic

Lists are similar to sets but differ in two important ways:

 Order ma ers: The order of elements in a list is significant.

 Duplicates allowed: A list can have the same element mul ple mes.

We can use func ons like Nil for the empty list, and Cons to construct lists.

List Opera ons

1. Nil: The constant for the empty list.

2. Cons: The func on to add an element to the front of a list.

3. Append: The func on to concatenate two lists.

4. First: A func on to retrieve the first element of a list.

5. Rest: A func on to retrieve the remaining elements of a list (a er the first element).

6. Find: A predicate to check if an element is in a list.

7. List?: A predicate that checks if an object is a list.


Syntac c Sugar for Lists

Just like with sets, we use syntac c sugar to make list expressions more readable:

 The empty list is wri en as [].

 The term Cons(x, y) is wri en as [x | y], where y is a non-empty list.

 For a list [A, B, C], it would be represented as Cons(A, Cons(B, Cons(C, Nil))).

Axioms for Lists

Lists can be axioma zed in a similar manner to sets. We can define recursive proper es of
lists, such as how to add an element to the front, and how to manipulate lists through
func ons like First, Rest, and Append.

8.3.4 The wumpus world


The Wumpus World involves an agent naviga ng a grid to avoid dangers (like pits or a
Wumpus) and gather treasure.

1. Percepts and Ac ons

The agent receives percepts in the form of a vector, represen ng sensory informa on. Each
percept contains elements such as "Stench," "Breeze," "Gli er," etc., and the corresponding
me step when the percept occurred. These percepts are stored as first-order sentences,
with the Percept predicate capturing sensory data and its associated me.

For example:

 Percept([Stench, Breeze, Gli er, None, None], 5) means that at me 5, the agent
perceives a stench, breeze, and gli er.

Ac ons that the agent can take, like moving (turning, going forward), shoo ng, grabbing, or
climbing, are represented by terms like:

 Turn(Right), Turn(Le ), Forward, Shoot, Grab, Climb.

2. Percep on and Reflexive Behavior

The Wumpus World agent's reflexive behavior can be defined using first-order logic. For
instance:

 If the agent perceives gli er, then the agent should grab the treasure:

∀ t Gli er(t) ⇒ BestAc on(Grab, t)

This rule means that at any me t, if the agent perceives gli er, the best ac on is to grab the
treasure.

3. Represen ng Objects in the World


In first-order logic, objects in the Wumpus World can be represented with terms. For
instance:

 Squares: The grid's squares are represented as lists of integers. Instead of naming
each square individually (like Square1,2), you can represent it as [x, y].

 Pits and Wumpus: Since there are many pits, it's inefficient to name them
individually. Instead, a unary predicate Pit is used to indicate if a square contains a
pit. The Wumpus is a special object represented by the constant Wumpus.

4. Adjacency of Squares

To define which squares are adjacent to each other, we use a complex term. For example:

 Adjacent([x, y], [a, b]) means that the square at [x, y] is adjacent to the square at [a,
b]. This is defined with the condi on that squares are adjacent if their rows or
columns differ by 1.

5. Agent's Loca on and Ac ons

The agent’s loca on changes over me, and we represent this using:

 At(Agent, s, t): This means that at me t, the agent is at square s.

For example, we can represent the wumpus's loca on with:

 ∀t At(Wumpus, [2, 2], t), meaning the Wumpus is always located at square [2, 2].

Addi onally, the axiom:

 ∀ x, s1, s2, t At(x, s1, t) ∧ At(x, s2, t) ⇒ s1 = s2 ensures that no two objects can
occupy the same square at the same me.

6. Logical Inference about the Environment

With first-order logic, the agent can deduce facts about its environment based on the
sensory data it perceives. For example:

 If the agent is at a square and perceives a breeze, the square is considered "breezy":

∀ s, t At(Agent, s, t) ∧ Breeze(t) ⇒ Breezy(s)

7. Breezy Squares and Pits

Using the logical representa on, the agent can deduce that a breezy square is adjacent to a
pit. The axiom:

 ∀ s Breezy(s) ⇔ ∃r Adjacent(r, s) ∧ Pit(r) states that a square s is breezy if and only if


one of its adjacent squares contains a pit.
This allows the agent to infer the presence of pits in neighboring squares based on the
breeze percept.

8. Succession of States

The state of the agent changes over me, and successor-state axioms allow us to represent
how certain proper es evolve. For example, for the agent's possession of an arrow:

 ∀ t HaveArrow(t + 1) ⇔ (HaveArrow(t) ∧ ¬Ac on(Shoot, t)) This means that if the


agent has an arrow at me t and does not shoot, it will s ll have the arrow at me
t+1.

9. Inference and Planning

Using logical inference, the agent can reason about the environment and its ac ons. By
applying axioms like the ones above, the agent can determine where the pits are, where the
wumpus is, and what ac ons to take. This allows the agent to make decisions based on
incomplete informa on.

For instance:

 If the agent perceives a breeze, it can infer that one of the adjacent squares contains
a pit.

 If the agent perceives gli er, it knows that it has found the treasure and should grab
it.

8.4 KNOWLEDGE ENGINEERING IN FIRST-ORDER LOGIC


Knowledge engineering is a systema c process of building a knowledge base that uses first-
order logic to represent facts and rules about a specific domain.

Knowledge Engineering

 A knowledge engineer inves gates a domain, iden fies key concepts, and formalizes
the representa on of objects and their rela onships within that domain.

 The aim is to create a special-purpose knowledge base, which focuses on a specific


domain and predefined query types, unlike general-purpose knowledge bases which
encompass broad human knowledge for tasks like natural language understanding.

The Knowledge-Engineering Process

1. Iden fy the Task

 Define the purpose of the knowledge base:

o Determine the range of ques ons the knowledge base will answer.

o Iden fy the kinds of facts available for each specific problem.


o Decide if the knowledge base will:

 Select ac ons (e.g., in a game).

 Simply answer queries (e.g., "Is this loca on safe?").

 The task determines the knowledge required to link specific problems to answers.

 This is analogous to the PEAS (Performance, Environment, Actuators, Sensors)


process in agent design

2. Assemble Relevant Knowledge

 Gather informa on about the domain:

o The knowledge engineer may already be an expert or may consult domain


experts.

o The focus is on understanding the domain and the task's requirements.

 This process is called knowledge acquisi on and involves:

o Collec ng domain rules and rela onships informally.

o Understanding what knowledge is relevant.

 Example:

o In the Wumpus World, knowledge includes adjacency rules and sensory


indicators (e.g., stench, breeze).

 Challenges in Real Domains:

o Determining relevance can be complex. For instance, when simula ng VLSI


designs, factors like stray capacitances might or might not be relevant.

3. Decide on a Vocabulary (Ontology)

 Choose predicates, func ons, and constants to represent domain concepts.

 The set of terms defines the ontology of the domain, which:

o Specifies what "exists" in the domain (e.g., objects, proper es, rela onships).

o Does not determine the specific proper es or rela onships between these
en es.

 Example:

o In the Wumpus World:

 Predicates: Breezy(Loca on), At(Agent, Loca on, Time).


 Func ons: Adjacent(Loca on1, Loca on2).

 Constants: Gold, Wumpus, Agent.

4. Encode General Knowledge

 Formalize general rules and axioms of the domain:

o These axioms define the vocabulary's meaning and ensure consistency.

o They allow the expert to verify the representa on.

 Itera ve Process:

o Misconcep ons or gaps may arise, requiring revisions to the ontology.

 Example:

o In the Wumpus World:

 A square is breezy if it is adjacent to a pit:

∀s Breezy(s) ⟺ ∃r Adjacent(r,s)∧Pit(r)

5. Encode Problem-Specific Knowledge

 Add facts about a specific problem instance:

o This step involves wri ng atomic sentences that describe the problem's ini al
condi ons.

o Problem-specific facts are typically provided by sensors (for agents) or as


input data.

 Example:

o In the Wumpus World:

 The agent starts at [1,1] at me 0:

At(Agent,[1,1],0).

 The agent perceives no signals ini ally:

Percept([None,None,None,None,None],0).

6. Pose Queries

 Use the knowledge base to answer queries or derive new facts:

o Queries are submi ed to the inference procedure.

o Logical reasoning deduces the answers based on the encoded knowledge.


 Example:

o A query to determine the best ac on:

ASKVARS(∃a BestAc on(a,t))

o If the query returns Grab, the agent will act accordingly.

7. Debug the Knowledge Base

 Check the correctness of answers and debug issues:

o Errors might include:

 Missing axioms: Some facts or rules are not encoded.

 Weak axioms: Rules are underspecified, preven ng inference.

 Incorrect axioms: Logical errors leading to false results.

 Debugging Process:

o Missing axioms are iden fied when reasoning stops unexpectedly.

o Incorrect axioms are iden fied by independently verifying their truth.

 Examples:

o Missing Axiom:

 is used instead of a bicondi onal, the agent cannot prove the absence
of Wumpuses.

o Incorrect Axiom:

 is incorrect because it excludes rep les and tables.

Debugging vs. Program Errors

 Debugging logical errors differs from debugging programs:

o In Logic: Errors are independently verifiable (e.g., checking the truth of


axioms).

o In Programs: Errors depend on context (e.g., whether offset = posi on + 1 is


correct depends on how offset is used elsewhere).
8.4.2 The electronic circuits domain
Developing an Ontology and Knowledge Base for Digital Circuits

Step 1: Iden fy the Task

Reasoning tasks include:

1. Analyzing func onality: For example, does the circuit in Figure 8.6 func on as a one-
bit adder? If all inputs are high, what is the output of gate A2?

2. Structural analysis: Ques ons such as which gates connect to a specific input
terminal or if the circuit contains feedback loops.

3. Other detailed analyses: These involve ming delays, circuit area, power
consump on, or produc on costs, which are beyond the scope of this discussion.

Step 2: Assemble the Relevant Knowledge

Key facts about digital circuits:

1. Composi on: Circuits are made of wires and gates.

2. Signal flow: Signals flow through wires to input terminals of gates, which transform
them and produce outputs.

3. Gate types: There are four types—AND, OR, XOR, and NOT. Gates have fixed input
and output configura ons:

o AND, OR, XOR: Two inputs, one output.

o NOT: One input, one output.

4. Relevance: Analysis focuses on connec ons between terminals rather than physical
proper es like wire paths, size, or color.

Step 3: Decide on a Vocabulary


Objects, Predicates, and Func ons:

1. Gates and circuits:

o Gates: Iden fied by predicates like Gate(X1) and type func ons like Type(X1)
= XOR.

o Circuits: Represented by predicates like Circuit(C1).

2. Terminals:

o Iden fied by Terminal(x).

o Input/output terminals for gates/circuits are represented using func ons like
In(n, X1) and Out(n, X1).

3. Connec vity: Connec ons between terminals are represented by Connected(Out(1,


X1), In(1, X2)).

4. Signal values: Signals are either 1 or 0, expressed as Signal(t).

5. Arity: Specifies the number of input and output terminals, e.g., Arity(c, i, j).

Step 4: Encode General Knowledge of the Domain

Axioms:
Step 5: Encode the Specific Problem Instance

Circuit Components:

Step 6: Pose Queries to the Inference Procedure

1. Output condi ons: Find input combina ons where Out(1, C1) = 0 and Out(2, C1) = 1:
∃i1,i2,i3 such that inputs/outputs sa sfy constraints.

o Solu ons: {i1/1, i2/1, i3/0}, {i1/1, i2/0, i3/1}, {i1/0, i2/1, i3/1}.
2. Complete input-output table: ∃i1,i2,i3,o1,o2 All valid terminal values.

Step 7: Debug the Knowledge Base

Example: Missing Asser on of Dis nctness:

Failing to assert 1 ≠ 0 causes incomplete outputs. Debugging involves:

1. Querying outputs of each gate, e.g., Signal(Out(1, X1)).

2. Iden fying the issue in the XOR axiom where Signal(Out(1, X1)) = 1 ⇔ 1 ≠ 0.

9.1 PROPOSITIONAL VS. FIRST-ORDER INFERENCE


1. Overview of Proposi onal vs. First-Order Inference

 Proposi onal Inference: Operates directly on proposi onal logic sentences without
quan fiers.

 First-Order Inference: Deals with sentences containing quan fiers like ∀ (universal)
and ∃ (existen al).

 Conversion between first-order logic and proposi onal logic is possible, allowing the
reuse of proposi onal inference methods.

2. Inference Rules for Quan fiers

a. Universal Instan a on (UI)

 Defini on: Allows subs tu on of variables with ground terms (constants or terms
without variables) in universally quan fied sentences.

 Formal Rule:

∀v α ⟹ SUBST({v/g},α)

Here, v is a variable, g is a ground term, and α is a universally quan fied sentence.

 Example:
From:

∀x (King(x)∧Greedy(x) ⟹ Evil(x))

We can infer:

King(John)∧Greedy(John) ⟹ Evil(John)

using the subs tu on {x/John}.

b. Existen al Instan a on (EI)

 Defini on: Replaces an existen al variable with a new constant symbol that does not
exist elsewhere in the knowledge base.
 Formal Rule:

∃v α ⟹ SUBST({v/k},α)

where k is a new constant symbol.

 Example:
From:

∃x (Crown(x)∧OnHead(x,John))

We can infer:

Crown(C1)∧OnHead(C1,John)

where C1 is a new constant (Skolem constant).

Skolemiza on

 Purpose: Handles existen al quan fiers by introducing Skolem constants or


func ons.

 Constraint: The new constant or func on must not clash with exis ng terms in the
knowledge base.

3. Proper es of Instan a on Rules

 Universal Instan a on:

o Can be applied mul ple mes, genera ng different consequences.

o Retains the original universally quan fied sentence in the knowledge base.

 Existen al Instan a on:

o Applied once per existen ally quan fied sentence.

o Removes the original sentence from the knowledge base a er instan a on.

o Ensures inferen al equivalence: the knowledge base remains sa sfiable if the


original was sa sfiable.

Inferen al Equivalence

 Even though the instan ated knowledge base is not logically equivalent to the
original, it is inferen ally equivalent.

 Sa sfiability remains unchanged, ensuring valid inferences can s ll be drawn.

9.1.2 Reduc on to Proposi onal Inference


1. Overview of Proposi onaliza on
 Proposi onaliza on: The process of conver ng first-order sentences into
proposi onal sentences by replacing quan fied sentences with their instan a ons.

 First-order inference becomes proposi onal inference a er replacing variables with


ground terms from the knowledge base.

2. Example of Proposi onaliza on

Consider the knowledge base:

1. ∀x (King(x)∧Greedy(x) ⟹ Evil(x))

2. King(John)King(John)King(John)

3. Greedy(John)Greedy(John)Greedy(John)

4. Brother(Richard,John)Brother(Richard, John)Brother(Richard,John).

Steps:

1. Apply Universal Instan a on (UI) to the universally quan fied sentence (∀x) using
all possible ground terms:

o Subs tu on {x/John}:
King(John)∧Greedy(John) ⟹ Evil(John)

o Subs tu on {x/Richard}:
King(Richard)∧Greedy(Richard) ⟹ Evil(Richard)

2. Replace the universally quan fied sentence with these instan a ons.

3. Treat the ground atomic sentences (King(John),Greedy(John),Evil(John), etc.) as


proposi onal symbols.

4. Apply any proposi onal inference algorithm (e.g., resolu on) to draw conclusions,
such as Evil(John).

3. Completeness of Proposi onaliza on

 Key Insight: Every first-order knowledge base and query can be proposi onalized
while preserving entailment.

 Jacques Herbrand's Theorem (1930): If a sentence is entailed by the first-order


knowledge base, there exists a proof using a finite subset of the proposi onalized
knowledge base.

Proving via Finite Subsets

1. Generate all instan a ons with constant symbols (e.g., Richard and John).
2. Add instan a ons involving terms of increasing depth (e.g., Father(Richard),
Father(Father(John)), etc.).

3. Stop when a proposi onal proof for the entailed sentence is found.

4. Limita ons of Proposi onaliza on

Infinite Ground-Term Subs tu ons

 If the knowledge base contains func on symbols (e.g., Father), infinitely many
nested terms like Father(Father(John)) can be generated.

 Proposi onal algorithms struggle with an infinite set of sentences.

Semi-Decidability of First-Order Logic

 Semi-Decidability: Algorithms exist that say "yes" to every entailed sentence but
cannot guarantee "no" for non-entailed sentences.

 Similar to the hal ng problem: The procedure may loop indefinitely without
determining whether it is stuck or close to a solu on.

Implica ons:

 Proposi onaliza on is complete (can prove all entailed sentences).

 However, it does not always terminate when sentences are not entailed.

5. Historical Context

 Alan Turing (1936) and Alonzo Church (1936) proved that the entailment problem
for first-order logic is undecidable in general.

 Their work demonstrates the inherent limits of automated reasoning in first-order


logic.

9.2 Unifica on and Li ing


Discusses improvements in first-order inference beyond proposi onaliza on, focusing on the
concept of unifica on and the introduc on of Generalized Modus Ponens. It addresses the
inefficiency of proposi onaliza on by demonstra ng how first-order logic can directly infer
conclusions without expanding all possibili es.
Unifica on

Unifica on is the process of finding a subs tu on θ that makes different logical expressions
iden cal.

Key Points:

 A unifier θ is a set of variable subs tu ons.

 The most general unifier (MGU) is the simplest unifier that applies.

 Example: To unify King(x) and King(John), the unifier is θ={x/John}.

Li ing

 Li ing raises inference from ground (variable-free) proposi onal logic to first-order
logic.

 Generalized Modus Ponens is a li ed version of Modus Ponens.

Advantages of Li ing
1. Efficiency: Avoids genera ng unnecessary ground sentences by directly subs tu ng
variables as needed.

2. Applicability: Supports inference in universally quan fied and more complex


knowledge bases.

3. Integra on: Li ing can be applied to forward chaining, backward chaining, and
resolu on algorithms.

9.2.2 Unifica on
Unifica on is a fundamental process in first-order logic, enabling inference rules to work by
finding subs tu ons that make different logical expressions iden cal. This process is vital in
inference algorithms like Generalized Modus Ponens and ensures expressions can be
compared or combined effec vely.

Defini on of Unifica on

The UNIFY algorithm takes two sentences p and q and returns a subs tu on θ\ that makes
them iden cal, i.e.,

UNIFY(p,q)=θ where SUBST(θ,p)=SUBST(θ,q)

If no such subs tu on exists, unifica on fails.


Unifica on Algorithm

The UNIFY algorithm recursively compares two expressions and constructs a subs tu on θ.

Steps:

1. Match Constants: If two constants differ, unifica on fails.

2. Match Variables:

o If a variable occurs in the other term, subs tute it.

o Perform the occur check to ensure variables are not cyclic (e.g., S(x) cannot
unify with S(S(x)).

3. Match Structures: Recursively unify corresponding components of compound


expressions.

Complexity:

 The occur check can make the algorithm quadra c in the size of expressions.

 Some systems omit the occur check for efficiency, leading to poten al unsound
inferences.

 Advanced algorithms achieve linear- me complexity.

9.2.3 Storage and Retrieval


In first-order logic systems, TELL and ASK are the primary func ons used to add informa on
to a knowledge base and query it, respec vely. These func ons rely on more fundamental
opera ons:

1. STORE(s): Adds a sentence s to the knowledge base.


2. FETCH(q): Retrieves all sentences in the knowledge base that unify with the query q.

Basic Implementa on of STORE and FETCH

The simplest approach involves maintaining all sentences in a single list and a emp ng to
unify q against every sentence in the list. While this method is straigh orward and
func onal, it is inefficient for large knowledge bases. Improving retrieval efficiency is cri cal
in prac cal systems.

Improving FETCH with Indexing

Indexing allows unifica ons to be a empted only with relevant sentences, avoiding
unnecessary comparisons.

Predicate Indexing

 Concept: Group sentences by predicate symbols.

o Example: Place all sentences with the predicate Knows in one "bucket" and
those with Brother in another.

o Storage: Buckets can be stored in a hash table for efficient access.


 Efficiency: Predicate indexing is most effec ve when there are many predicates, each
with rela vely few clauses.

Challenges with Large Buckets

For predicates associated with many clauses (e.g., Employs(x, y), with millions of facts), a
single bucket may s ll require extensive scanning.

Enhanced Indexing

To improve performance for large buckets:

1. Index facts by predicate and specific arguments.

2. Use combined hash table keys to retrieve relevant clauses directly.

Example: Employs(IBM, Richard)


Index keys could include:

 (predicate+1st argument): Employs(IBM,−)

 (predicate+2nd argument): Employs(−,Richard)

This ensures efficient access for queries like:

 Employs(x,Richard): Who employs Richard?

 Employs(IBM,y): Whom does IBM employ?

Mul ple Indices

For maximum flexibility, facts can be indexed under mul ple keys, enabling fast responses to
various query types.

Subsump on La ces

Each sentence in the knowledge base corresponds to a set of queries it can unify with. These
queries form a subsump on la ce:

Example: Employs(IBM, Richard)

Possible queries include:


1. Employs(IBM,Richard): Does IBM employ Richard?

2. Employs(x,Richard): Who employs Richard?

3. Employs(IBM,y): Whom does IBM employ?

4. Employs(x,y): Who employs whom?

La ce Proper es

 Each child node is derived from its parent by a single subs tu on.

 The most general unifier (MGU) gives the "highest" common descendant of any two
nodes.

La ce Complexity

For predicates with n arguments:

 The la ce contains O(2^n) nodes.

 When func on symbols are present, the number of nodes grows exponen ally with
the term size.

Indexing Trade-offs

While indexing improves retrieval efficiency, it also increases storage and maintenance
overhead. Excessive indexing can outweigh its benefits.

Policies for Managing Indices

1. Fixed Policy: Maintain indices only for combina ons like predicate+argument.

2. Adap ve Policy: Dynamically create indices based on query pa erns and demands.

Prac cal Considera ons

1. Small Knowledge Bases: Efficient indexing is generally a solved problem for systems
with a limited number of facts.

2. Large Commercial Databases: Handling billions of facts has driven extensive research
and technological advancements in database indexing.

By balancing retrieval efficiency and indexing costs, systems can achieve op mal
performance tailored to their scale and usage pa erns.

9.3 FORWARD CHAINING


Forward chaining is a data-driven reasoning technique used for inference in knowledge
bases. It applies Modus Ponens itera vely to derive new facts un l no further inferences can
be made or a specific query is sa sfied.
9.3.1 First-Order Definite Clauses
Defini on

First-order definite clauses resemble proposi onal definite clauses but extend them to first-
order logic. A definite clause is:

1. Atomic (e.g., King(John))

2. An implica on with a conjunc on of posi ve literals as the antecedent and a single


posi ve literal as the consequent (e.g., King(x)∧Greedy(x)⇒Evil(x)).

Features

 Variables in the literals are universally quan fied (omi ng quan fiers is a common
shorthand).

 Not all knowledge bases can be converted to definite clauses due to the restric on of
having only one posi ve literal.

Example Problem
Datalog Knowledge Base

This example is an instance of a Datalog knowledge base, which:

 Uses first-order definite clauses without func on symbols.

 Enables efficient inference due to the absence of func on symbols.

Datalog is closely related to rela onal databases and is suitable for represen ng facts and
rules in many prac cal AI systems.

9.3.2 A Simple Forward-Chaining Algorithm


Forward-chaining is a process that itera vely applies rules in a knowledge base to infer new
facts. The FOL-FC-ASK algorithm is one simple method of forward chaining. The basic idea is
to begin with the known facts and repeatedly apply rules whose premises are sa sfied,
adding their conclusions to the knowledge base. This process con nues un l the query is
answered or no new facts can be derived.

Steps in FOL-FC-ASK Algorithm:

1. Start with Known Facts: Begin with the ini al facts in the knowledge base.
2. Trigger Rules: Check the rules (definite clauses). If the premises of a rule are sa sfied
(i.e., all literals in the antecedent are true), apply the rule and add the conclusion
(the consequent) to the knowledge base.

3. Repeat: This process repeats, triggering new rules as the knowledge base expands,
un l:

o The query is answered (the desired fact is derived).

o No new facts are added (the knowledge base reaches a fixed point).

Renaming of Facts:

A fact is considered not new if it is just a renaming of a known fact. This happens when the
fact differs only by the variables used. For example, Likes(x,IceCream) are considered
iden cal facts, as they represent the same meaning (i.e., everyone likes ice cream), but with
different variables.
Soundness and Completeness

 Soundness: The algorithm is sound because it only applies Generalized Modus


Ponens, which is a logically valid inference.

 Completeness: The algorithm is complete for definite clause knowledge bases,


meaning it will always provide an answer if the answer is entailed by the knowledge
base. This is par cularly easy to prove for Datalog knowledge bases, which lack
func on symbols.

For general first-order definite clauses with func on symbols, there may be infinitely many
new facts generated. In such cases, we rely on Herbrand’s Theorem to prove that the
algorithm will eventually find a proof if one exists. However, if there is no answer, the
algorithm might fail to terminate due to infinite genera on of new facts, such as in the case
of the Peano axioms (where natural numbers are represented recursively).

Fixed Point and Termina on

A fixed point is reached when no further facts can be added, indica ng that the inference
process has concluded. However, in cases with recursive facts or func on symbols, such as
the Peano axioms, forward chaining may not terminate, leading to an undecidable process
(i.e., the system cannot determine whether it will eventually terminate or not).

9.3.3 Efficient Forward Chaining


The forward-chaining algorithm can be inefficient due to three main factors:

1. Pa ern Matching: Finding unifiers to match the premises of rules with the facts in
the knowledge base can be computa onally expensive.

2. Rechecking Rules: The algorithm checks every rule on each itera on, even if few new
facts are added, leading to redundant work.

3. Irrelevant Facts: The algorithm may generate many irrelevant facts that do not
contribute to answering the query, leading to inefficiency.

Let's explore each issue and ways to improve efficiency.

1. Matching Rules Against Known Facts (Pa ern Matching)

Pa ern matching involves checking if the premise of a rule matches any facts in the
knowledge base. The challenge arises when rules have mul ple conjuncts, as matching
becomes more computa onally expensive. For example:

 For the rule Missile(x)⇒Weapon(x) we need to find all facts that unify with
Missile(x)Missile(x)Missile(x), which can be done efficiently with an indexed
knowledge base.

 For a more complex rule Missile(x)∧Owns(Nono,x)⇒Sells(West,x,Nono) matching


involves checking for both "missiles" and "ownership," which can be less efficient if
many objects are owned by Nono but few are missiles.

Conjunct Ordering:

Finding the op mal order in which to check the conjuncts of a rule is called the conjunct
ordering problem. The goal is to check the facts in an order that minimizes the
computa onal cost. This problem is NP-hard, but heuris cs can help. For example, the
Minimum-Remaining-Values (MRV) heuris c used in constraint sa sfac on problems
(CSPs) suggests that we should check the fewer number of items first. In the example above,
if Nono owns many objects but only a few are missiles, it would be be er to check for
missiles first.

2. Rechecking Rules on Every Itera on

The algorithm rechecks all rules on every itera on, which is inefficient, especially when few
facts are being added. To address this, we can:

 Track Changes: Only recheck rules whose premises have changed due to the addi on
of new facts.
 Rule Ac va on: Keep track of which rules were ac vated (i.e., those whose premises
were sa sfied) and only check them in subsequent itera ons.

3. Genera ng Irrelevant Facts

The algorithm may generate many facts that are irrelevant to the goal, which can slow down
the process. To mi gate this:

 Prune Irrelevant Facts: Use the goal (the query) to filter out facts that are unlikely to
help answer the query.

 Selec ve Rule Applica on: Apply only those rules that are likely to contribute to the
goal, avoiding unnecessary rule firing.

Efficient Matching with CSPs

Matching rules against facts is NP-hard in the general case, as it involves solving constraint
sa sfac on problems (CSPs). However, there are ways to make matching more efficient:

 Tractable CSPs: For certain types of CSPs, such as those with tree-structured
constraint graphs, matching can be solved in linear me. This is the case when the
constraint graph (represen ng variables and constraints) forms a tree structure.

For example, the map-coloring problem can be formulated as a CSP, and if the map is
simplified (removing certain regions), the CSP may become tractable, allowing efficient
matching of the rule to the facts.

Reducing Redundant Rule Matching

To improve the efficiency of the forward-chaining algorithm:


 Caching: Cache the results of rule matching and avoid redundant a empts.

 Incremental Matching: Only apply rules incrementally, based on newly added facts,
rather than reapplying all rules in each itera on.

Incremental Forward Chaining

In forward chaining, redundancy can be avoided by ensuring that new facts are only used to
derive new facts. This leads to an incremental forward-chaining algorithm, which improves
efficiency by focusing on rules that are triggered by newly inferred facts.

Key Concepts in Incremental Forward Chaining

1. New Fact Dependency:

o Every new fact generated in itera on t must be derived from a fact generated
in itera on t−1. This means that only facts inferred in the previous itera on
are needed to trigger new rules.

o The incremental approach checks each rule only if its premise contains a
conjunct that can unify with a fact generated in the previous itera on,
reducing unnecessary rule matching.

2. Avoiding Redundant Rule Matching:

o In tradi onal forward chaining, redundant rule matching occurs because the
same facts may match the same rules in mul ple itera ons. With the
incremental method, only the facts from the last itera on are considered for
matching, reducing unnecessary work.

o For example, if a rule Missile(x)⇒Weapon(x) is checked in one itera on and


generates Weapon(M1), this new fact is used in subsequent itera ons,
avoiding unnecessary rechecks.

3. Efficient Rule Triggering:

o Real systems o en implement forward chaining in response to new facts


being "told" to the system. When a fact is added, the system checks which
rules are triggered by this new fact and applies them. The process con nues
un l no more facts can be derived, and a "fixed point" is reached.

4. Construc ng Par al Matches:

o Instead of discarding par al matches that are incomplete (such as in the


crime example with the rule
American(x)∧Weapon(y)∧Sells(x,y,z)∧Hos le(z)⇒Criminal(x) incremental
forward chaining keeps track of par al matches. As new facts arrive, par al
matches are gradually completed, making the process more efficient.
Rete Algorithm for Efficient Matching

The Rete algorithm improves the matching process by construc ng a dataflow network that
keeps track of par al matches. Here’s how it works:

 Dataflow Network: Each node in the network represents a literal in the rule's
premise. Variable bindings flow through this network, and they are filtered out when
they fail to match.

 Equality Nodes: When two literals share a variable, their bindings are filtered
through an equality node, ensuring that only consistent bindings con nue through
the network.

 Avoiding Repe on: The network retains par al matches, so when new facts are
added, the matching process can con nue from where it le off, avoiding
unnecessary recomputa on.

The Rete network op mizes forward chaining by elimina ng the need to rebuild par al
matches from scratch. This technique is crucial in systems with large rule sets, as it greatly
reduces computa on me.

Produc on Systems and Cogni ve Architectures

Produc on systems, like XCON (a system for designing computer configura ons), use the
Rete algorithm to handle large numbers of rules efficiently. These systems rely on rules
(condi on-ac on pairs) that are matched against a working memory of facts, where each
match may trigger further rule applica ons.

Cogni ve architectures, such as ACT and SOAR, also use produc on systems to model
human reasoning. In these systems:

 The working memory represents short-term memory.

 Produc ons, represen ng long-term memory, are matched against the working
memory to perform inferences.

These systems o en deal with large numbers of rules and rela vely few facts, making
efficient rule matching even more important.

Addressing Irrelevant Facts in Forward Chaining

Forward chaining can some mes generate irrelevant facts, which are conclusions not related
to the goal. This inefficiency can be addressed in several ways:

1. Using Backward Chaining: As discussed in Sec on 9.4, backward chaining can help
focus the reasoning process on the goal, preven ng irrelevant facts from being
generated.
2. Restric ng to Relevant Rules: Instead of considering all rules, forward chaining can
be restricted to a subset of rules relevant to the goal, improving efficiency.

3. Magic Sets: In deduc ve databases, a technique called the magic set approach helps
restrict forward chaining to relevant facts. This approach involves rewri ng rules to
include addi onal condi ons (or magic facts) that limit the search space.

o For example, if the goal is Criminal(West), the rule Criminal(x)⇒ could be


rewri en to include a magic fact Magic(West), ensuring that only facts
relevant to "West" are considered during the forward inference process.

The magic set approach can be seen as a hybrid between forward inference and backward
preprocessing, making it a powerful op miza on technique for large-scale databases.

You might also like