Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Module 2 Notes _AI

Chapter 5 discusses the use of predicate logic as a language for reasoning and knowledge representation in artificial intelligence. It covers the basics of propositional logic, its limitations, and introduces first-order predicate logic (FOPL) which allows for more expressive representations of facts about individuals and their relationships. The chapter also explains key concepts such as syntax, semantics, inference procedures, and the role of quantifiers in logic.

Uploaded by

rajsharma040424
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Module 2 Notes _AI

Chapter 5 discusses the use of predicate logic as a language for reasoning and knowledge representation in artificial intelligence. It covers the basics of propositional logic, its limitations, and introduces first-order predicate logic (FOPL) which allows for more expressive representations of facts about individuals and their relationships. The chapter also explains key concepts such as syntax, semantics, inference procedures, and the role of quantifiers in logic.

Uploaded by

rajsharma040424
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

Chapter 5

USING PREDICATE LOGIC


Here, we explore one particular way of representing facts - the language of logic.

➢ LOGIC

✓ Logic is a language for reasoning, a collection of rules used while doing logical reasoning. Logic
is studied as Knowledge Representation languages in artificial intelligence
✓ Logic is concerned with the truth of statements about the world.
- Generally each statement is either TRUE or FALSE.
- Logic includes: Syntax, Semantics and Inference Procedure.
✓ Syntax
- Specifies the symbols in the language about how they can be combined to form sentences.
The facts about the world are represented as sentences in logic.
✓ Semantics
- Specifies how to assign a truth value to a sentence based on its meaning in the world. It specifies
what facts a sentence refers to. A fact is a claim about the world, and it may be TRUE or
FALSE.
✓ Inference Procedure
- Specifies methods for computing new sentences from the existing sentences.

➢ REPRESENTING SIMPLE FACTS IN LOGIC

● Propositional Logic (PL)

✓ We use propositional logic as a way to represent world knowledge in AI systems.


Propositional logic is simple and a decision procedure. It is easy to represent real-world
facts as logical propositions written as well-formed formulas (wff’s) in propositional logic.
Some Simple Facts in Prepositional Logic are as shown below.
- It is raining.
RAINING
- It is sunny.
SUNNY
- It is windy.
WINDY
- If it is raining, then it is not sunny.
RAINING SUNNY
Example 2: Socrates is a man.
SOCRATESMAN
Plato is a man.
PLATOMAN
It would be better to represent these facts as:
MAN
(SOCRATES)
MAN (PLATO)
✓ Now the structure of the representation reflects the structure of the knowledge itself. But to do
that, we need to be able to use predicates applied to arguments.
All men are mortal.
We could represent this as: MORTALMAN
✓ A proposition is a statement, which in English would be a declarative sentence. Every
proposition is either TRUE or FALSE.
Examples:
(a) The sky is blue
(b) Snow is cold
(c) 12 * 12=144
– Propositions are “sentences”, either true or false but not both.
– A sentence is smallest unit in propositional logic.
– If proposition is true, then truth value is "true".
– If proposition is false, then truth value is "false".

Example:
Sentence Truth value Proposition (Y/N)

"Grass is green" "true" Yes


"2 + 5 = 5" "false" Yes
"Close the door" - No
"Is it hot outside?" - No
"x > 2" where x is variable - No (since x is not defined)
"x = x" - No
(don't know what is "x" and "=";
"3 = 3" or "air is equal to air" or
"Water is equal to water" has no meaning)

✓ Propositional logic is fundamental to all logic and tells the ways of joining and/or modifying entire
propositions, statements or sentences to form more complicated propositions, statements or
sentences, as well as the logical relationships and properties that are derived from the methods of
combining or altering statements.
✓ Statement, Variables and Symbols
- These and few more related terms, such as, connective, truth value, contingencies,
tautologies, contradictions, antecedent, consequent, argument are explained below.
✓ Statement
- A simple statement (sentences), TRUE or FALSE, that does not contain any other
statement as a part, is basic propositions.
- Lower-case letters, p, q, r, are symbols used to represent simple statements.
- Large, compound or complex statement are constructed from basic propositions by
combining them with connectives.
✓ Connective or Operator
- The connectives join simple statements into compounds, and joins compounds into
larger compounds.
- Table below indicates, the basic connectives and their symbols: listed in decreasing
order of operation priority; operations with higher priority is solved first.
Example of a formula: ((((a Λ ¬b) V c → d) ↔ ¬ (a V c )) Connectives and

Symbols in decreasing order of operation priority

Connective Symbols Read as

Assertion P "p is true"


Negation ¬p ~ ! NOT "p is false"
Conjunction p 𝖠 q && & AND "both p and q are true"
Disjunction p v q || | OR "either p is true, or q is true, or both”
Implication p→q ⊃ ⇒ "if p is true, then q is true"
if …then “p implies q "
Equivalence ↔≡⇔ "p and q are either both true or both false"
if and only if

Note: The propositions and connectives are the basic elements of propositional logic.

➢ LIMITATIONS OF PROPOSITIONAL LOGIC

✓ Propositional logic is declarative. It allows partial/disjunctive/ negated information (unlike


most data structures and databases)
✓ Propositional logic is compositional: meaning of B1,1 P1,2 is derived from meaning of B1,1 and
of P1,2
✓ 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)
– Hard to identify individuals. Example: Mary, 3
– Cannot directly talk about properties of individuals or relations between individuals.
Example: “Bill is tall”
– Generalizations, patterns, regularities can’t easily be represented. E.g., all triangles have 3
sides
✓ Hence, Propositional logic is not powerful enough as a general knowledge representation
language. Impossible to make general statements. Example: “all students sit for exams” or “if
any student sits for an exam, they either pass or fail”.
✓ The facts like: “peter is a man”, “paul is a man”, “john is a man” can be symbolized by p, q
and r, respectively in PL. We cannot draw any conclusions about similarities between p, q and r.
Further, the sentences like “All men are mortal” cannot be represented in PL. MAN(peter),
MAN(paul) and MAN(john), Similarity between these facts that they are all man can be easily
derived.

Note: Learn the following Basics to understand building logic in PL or in FOPL

Give the BNF notation for sentences (Wffs) in Propositional Logic with examples.
▪ The proposition symbols S1, S2 etc., are sentences or Well Formed Formula (wff) in
Propositional Logic
– If S is a sentence, S is also a sentence (negation)
– If S1 and S2 are sentences, S1 S2 is also a sentence (conjunction)
– If S1 and S2 are sentences, S1 S2 is also a sentence (disjunction)
– If S1 and S2 are sentences, S1 S2 is also a sentence (implication)
– If S1 and S2 are sentences, S1 S2 is also a sentence (biconditional)

▪ Rules for evaluating truth with respect to a model m:


S is true Iff S is false
S1 S2 is true Iff S1 is true and S2 is true
S1 S2 is true Iff S1is true or S2 is true
S1 S2 is true Iff S1 is false or S2 is true
i.e., is false Iff S1 is true and S2 is false
S1 S2 is true Iff S1 S2 is true and S2 S1 is true

– Truth tables for connectives


▪ Two sentences are logically equivalent iff they are true in same models: α ≡ ß. Some of the
logical equivalences are :

▪ Tautologies
- A proposition that is always true (for all possible interpretations/assignments) is called a
"tautology".
Example: (P v ¬P) is always true regardless of the truth value of the proposition P.
▪ Contradictions
- A proposition that is always false (for all possible interpretations/assignments) is called a
"contradiction". Nothing but Unsatisfiable.
Example: (P 𝖠 ¬P) is always false regardless of the truth value of the proposition P.
▪ Contingencies
- A proposition is called a "contingency”, if that proposition is (for all possible
interpretations/assignments) neither a tautology nor a contradiction.
Example: (P v Q) is a contingency.
▪ Antecedent, Consequent
- There are two parts of conditional statements. In the conditional statements, p → q, the 1st
statement or "if - clause" (here p) is called antecedent, 2nd statement or "then - clause"
(here q) is called consequent.
▪ Conjunctive Normal Form (CNF).
▪ Satisfiable: If there is at least one true result for set of inputs in its truth table. Eg.,(P v Q)
▪ A clause Ci is a closed formula of the form (L1V L2… V Lm), where each Li is a literal with
all the variables occurring in L1, …, Lm being universally quantified.
▪ Definition: A Horn clause is a clause with at most one positive literal.

➢ FIRST- ORDER PREDICATE LOGIC (FOPL)

✓ Now, we have to move towards first- order predicate logic as a way of representing knowledge
because it permits representations of things that cannot reasonably be represented in prepositional
logic. In predicate logic, we can represent real-world facts as statements written aswff’s.
▪ First-Order Logic (abbreviated FOL or FOPL) is expressive enough to
– concisely represent individuals
– talk about properties of individuals or relations between individuals
– Generalizations, patterns, regularities
▪ FOL adds relations, variables, and quantifiers. Examples:
– Every elephant is gray: x (elephant(x) → gray(x))
– There is a white alligator: x (alligator(x) 𝖠 white(x))
▪ FOL models the world in terms of
– Objects, which are things with individual identities
– Properties of objects that distinguish them from other objects
– Relations that hold among sets of objects
– Functions, which are a subset of relations where there is only one value for any given
input
– Examples:
Objects: Students, lectures, companies, cars ...
Relations: Brother-of, bigger-than, outside, part-of, has-color, occurs-after, owns,
visits, precedes, ...
Properties: blue, oval, even, large, ...
Functions: father-of, best-friend, second-half, one-more-than ...
▪ It has three more logical notions as compared to Propositional Logic.
– Terms, Predicates and Quantifiers Term
A constant (single individual or concept i.e., 5, john etc.),
A variable that stands for different individuals
n-place function f(t1, …, tn) where t1, …, tn are terms. A function is a mapping that
maps n terms to a term.

Predicate
A relation that maps n terms to a truth value True (T) or False (F).
Quantifiers
Universal and Existential quantifiers i.e. and used in conjunction with
variables.
✓ Now will explore the use of predicate logic as a way of representing knowledge by looking at
specific examples.

Examples:
– “x loves y” is represented as LOVE(x, y) which maps it to true or false when x and y get
instantiated to actual values.
– “john’s father loves john” is represented as LOVE(father(john), john).
Here, father is a function that maps john to his father.
– “x is greater than y” is represented in predicate calculus as GT(x, y).
It is defined as follows:
GT( x, y) = T, if x y
= F, otherwise
Symbols like GT and LOVE are called predicates
- Translate the sentence "Every man is mortal” into Predicate formula.
Representation of statement in predicate form
“x is a man” as MAN(x)
“x is mortal” as MORTAL(x)
“Every man is mortal” as ( x): (MAN(x) MORTAL(x))

✓ BNF for FOL: Well formed formula (Wff) in Predicate logic


S: = <Sentence>;
<Sentence>:= <AtomicSentence> | <Sentence> <Connective> <Sentence> |
<Quantifier> <Variable>,... <Sentence> | "NOT" <Sentence> | "("
<Sentence> ")";
▪ Thus a sentence is
– an atomic sentence
– ~P(x) , P(x) Q(y), P(x) Q(y), P(x) → Q(y), P(x) ↔ Q(y) where P(x) and Q(y) are
sentences
– if P (x) is a sentence and x is a variable, then ( x)P(x) and ( x)P(x) are sentences
▪ Constant symbols, which represent individuals in the world
– Mary, 3, Green
▪ Function symbols, which map individuals to individuals
– father-of(Mary) = John, color-of(Sky) = Blue
▪ Predicate symbols, which map individuals to truth values
– greater(5,3) , green(Grass) , color(Grass, Green)
▪ Summary of Components of Predicate Logic:
– Constants: KingJohn, 2, NUS,...
– Predicates: Brother, >,...
– Functions: Sqrt, LeftLegOf,...
– Variables: x, y, a, b,...
– Connectives: , →, , , ↔
– Equality: =
– Quantifiers: ,

✓ Note on Quantifiers

▪ Universal quantifiers are often used with “implies” to form “rules”:


( x) student(x) → smart(x) means “All students are smart”
▪ Existential quantifiers are usually used with “and” to specify a list of properties about an
individual:
( x) student(x) smart(x) means “There is a student who is smart”
▪ Switching the order of universal quantifiers does not change the meaning:
( x)( y) P(x, y) ↔ ( y)( x) P(x, y)
▪ Similarly, you can switch the order of existential quantifiers:
( x)( y) P(x, y) ↔ ( y)( x) P(x, y)
▪ Switching the order of universals and existential does change meaning:
Everyone likes someone: ( x)( y) likes(x, y)
Someone is liked by everyone: ( y) ( x) likes(x, y)
▪ ( x) ~P(x) ↔ ~( x) P(x)
▪ ~( x) P(x) ↔ ( x) ~P(x)
▪ ( x) P(x) ↔ ~ ( x) ~P(x)
▪ ( x) P(x) ↔ ~( x) ~P(x)

✓ Translating English Sentences to FOL


1. Every gardener likes the sun.
( x) gardener(x) → likes(x,Sun)
2. All purple mushrooms are poisonous.
( x) (mushroom(x) purple(x)) → poisonous(x)
3. No purple mushroom is poisonous.
~( x) purple(x) mushroom(x) poisonous(x) ( x)
(mushroom(x) purple(x)) → ~poisonous(x)
4. There are exactly two purple mushrooms.
( x)( y) mushroom(x) purple(x) mushroom(y) purple(y) ~(x=y) (Az) (mushroom(z) purple(z)) → ((x=z) v
(y=z))
5. Harry is not tall
~tall(Harry)
6. X is above Y if X is on directly on top of Y or there is a pile of one or more other objects
directly on top of one another starting with X and ending with Y.
( x)( y) above(x, y) ↔ (on(x, y) v ( z) (on(x, z) above(z, y)))
7. You can fool some of the people all of the time.
( x) ( t) can-fool(x, t)
( x) (person(x) (( t)( time(t) → can-fool(x, t))))
8. You can fool all of the people some of the time.
( x)( t) can-fool(x, t)
( x) (person(x) → (( t) time(t) can-fool(x, t)))
9. In every city there is a thief who is beaten by every policeman in the city
x[city(x) { y((thief(y) lives_in (y,x)) z(policeman(z) beaten_by (z, y)))}]

✓ Consider the following set of sentences


1. Marcus was a man.
2. Marcus was a Pompeian.
3. All Pompeian were Romans.
4. Caesar was a ruler.
5. All Romans were either loyal to Caesar or hated him.
6. Everyone is loyal to someone.
7. People only try to assassinate rulers they are not loyal to.
8. Marcus tried to assassinate Caesar.

The facts described by these sentences can be represented as a set of wff’s in predicate logic as follows:

1. Marcus was a man.


Man (Marcus)
This representation captures the critical fact of Marcus being a man.
2. Marcus was a Pompeian.
Pompeian (Marcus)
3. All Pompeians were Romans.
∀ x: Pompeian (x) → Roman (x)
4. Caesar was a ruler.
Ruler (Caesar)
5. All Romans were either loyal to Caesar or hated him.
∀x: Roman (x) → loyalto(x, Caesar) V hate ( x, Caesar) (OR representation)
or
∀x: Roman(x) → [(loyalto(x, caesar) V hate (x,Caesar)) V ¬(loyato(x, caesar) V hate (x,
Caesar))] (XOR representation)
6. Everyone is loyal to someone
∀X, y: loyalto(x,y)
7. People only try to assassinate rulers they are not loyal to.
∀x, ∀y : Person (x) V ruler (y) V tryassassinate(x,y) → ¬ loyalto(x, y)
8. Marcus tried to assassinate Caesar.
Tryassassinate (Marcus, Caesar)

Now suppose that we want to use these statements to answer the question
Was Marcus loyal to Caesar?
Using 7 and 8, we should be able to prove that Marcus was not loyal to Caesar. Now let’s try to produce
a formal proof, reasoning backward from the desired goal:
loyalto(Marcus, Caesar)
Marcus was a person. We need to add the representation of another fact to our system, namely:
9. All men are people.
∀x: man (x) → person (x)

¬ loyalto (Marcus, Caesar)


↑ (7, substitution)

Person (Marcus) V Ruler (Caesar) 𝖠 Tryassassinate (Marcus, Caesar)


↑ (4)
Person (Marcus)
Tryassassinate (Marcus, Caesar)
↑ (8)
Person (Marcus)
Now we can satisfy the last goal and produce a proof that Marcus was not loyal to Caesar.

➢ REPRESENTING INSTANCE AND ISA RELATIONSHIP


Below example shows the first five sentences of logic in three different ways.

✓ The first part of the representation contains we have already discussed. In these representations,
class membership is represented with unary predicates (such as Roman), each of which
corresponds to a class. Asserting that p(x) is true is equivalent to asserting that X is an instance (or
element) of P.
✓ The second part represents that the use the instance predicate explicitly. The predicate instance
is a binary one, whose first argument is an object and second argument is a class to which the
object belongs. But these representations do not use an explicit isa predicate. Instead, subclass
relationships, such as that between Pompeians and Romans, are described as shown in sentence
3. The implication rule there states that this rule is equivalent to the standard set-theoretic definition
of the subclass-super class relationship.
✓ The third part contains representations that use both the instance and isa predicates explicitly.
The use of the isa predicate simplifies the representation of sentence 3, but it requires that one
additional axiom (shown here as number 6) be provided. This additional axiom describes how an
instance relation and an isa relation can be combined to derive a new instance relation. This one
additional axiom is general, though, and does not need to be provided separately for additional isa
relations.

Three Ways of Representing Class Membership

1. Man(Marcus)
2. Pompeian(Marcus)
3. x : pompeian(x) → Roman (x)
4. Ruler(Caesar)
5. ∀x : Roman (χ) → loyalto(x, Caesar) V hate(x, Caesar)

1. Instance(Marcus, man)
2. Instance(Marcus, 𝑝𝑜𝑚𝑝𝑒i𝑎𝑛)
3. ∀x : Instance(x, pompeian) → Instance(x, Roman)
4. Instance(Caesar, ruler)
5. ∀x : Instance(x, Roman) → loyalto (x, Caesar) V hate(x, Caesar)

1. Instance(Marcus, man)
2. Instance(Marcus, pompeian)
3. Isa(pompeian, Roman)
4. Instance(Caesar, ruler)
5. ∀x : Instance(x, Roman) → loyalto (x, Caesar) V hate(x, Caesar)
6. ∀x, ∀y, ∀z : Instance(x, y) V isa(x, y) → Instance (x, y)

✓ These examples illustrate two points. The first is fairly specific. It is that, although class and super
class membership are important facts that need to be represented, those memberships need not be
represented with predicates labeled instance and isa.
✓ The second point is that there are several different ways of representing a given fact within a
particular representational framework, be it logic or anything else.
✓ There is one additional point that needs to be made here on the subject of the use of isa hierarchies
in logic-based systems. The reason that these hierarchies are so important is not that they permit
the inference of superclass membership. It is that by permitting the inference of superclass
membership, they permit the inference of other properties associated with membership in that
superclass. So, for example, in our sample knowledge base it is important to be able to conclude
that Marcus is a Roman because we have some relevant knowledge about Romans, namely that
they either hate Caesar or are loyal to him.
✓ Suppose, for example, that, in addition to the facts we already have, we add the following.
pompeian(Paulus)
¬ [loyalto (paulus, Caesar) V hate (paulus, Caesar)]

Suppose we want to make paulus an exception to the general rule about Romans and their
feelings toward Caesar. Unfortunately, we cannot simply add these facts to our existing
knowledge base the way we could just add new nodes into a semantic net. The difficulty is that if
the old assertions are left unchanged, then the addition of the new assertions makes the
knowledge base inconsistent. In order to restore consistency, it is necessary to modify the original
assertion to which an exception is being made. So our original sentence 5 must become:

∀x : Roman (x) V ¬ eq (x, paulus) → loyalto (x, Caesar) V hate (x, Caesar)
In this framework, every exception to a general rule must be stated twice, once in a particular
statement and once in an exception list that forms part of the general rule.

➢ COMPUTABLE FUNCTIONS AND PREDICATES

✓ We have explored that all the simple facts were expressed as combinations of individual
predicates, such as: tryassassinate (Marcus, Caesar)
✓ This is fine if the number of facts is not very large. But suppose we want to express facts, such as
the following greater-than and less-than relationships:

gt(1,0) lt(0,1)
gt(2,1) lt(1,2)
gt(3,2) lt(2,3)
. .
. .
. .
We might want to evaluate the truth of gt(2+3,1)
To do so requires that we first compute the value of the plus function given the arguments 2 and
3, and then send the arguments 5 and 1 to gt.
✓ Consider the following set of facts, again involving Marcus:
1. Marcus was a man.
Man(Marcus)
• Marcus was a Pompeian.
Pompeian (Marcus)
• Marcus was born in 40 A.D.
Born
(Marcus, 40)
now =1991
6. Alive means not dead.
∀x, ∀t : [alive (x, t) → ¬ dead (x, t)] 𝖠 [¬ dead (x, t) → alive(x, t)]
7. If someone dies, then he is dead at all later times.
∀x, ∀t1, ∀t2 : died (x, t1) 𝖠 gt(t2,t1) → dead (x, t2)

Now suppose we want to answer the question “Is Marcus alive?” There may be two ways of
deducing an answer. Either we can show that Marcus is dead because he was killed by the
Artificial Intelligence Module - II

volcano or we can show that he must be dead because he would otherwise be more 150 years
old, which we know is not possible.

A Set of Facts about Marcus (above are Rewritten with spilt of 5 into 2 facts)

1. Man(Marcus)
2. Pompeian(Marcus)
3. Born (Marcus, 40)
4. ∀x : man(x) → mortal(x)
5. ∀x : Pompeian(x) → died(x, 79)
6. erupted (yolcano, 79)
7. ∀x, ∀t1, ∀t2: mortal(x) 𝖠 born(x, t1) 𝖠 gt(t2-t1,150) → dead(x, t2)
8. Now = 1991
9. ∀x, ∀t : [alive(x, t) → ¬ dead(x, t)] 𝖠 [¬ dead(x, t) → alive (x, t)]
10. ∀x, ∀t1, ∀t2: died(x, t1) 𝖠 gt (t2,t1) → dead (x, t2)

Now let’s attempt to answer the question “Is Marcus alive?” by proving:¬ alive (Marcus, now)

Two such proofs are shown below. The term nil at the end of each proof indicates that the list of
conditioned remaining to be proved is empty and so the proof has succeeded. One Way of Proving
that Marcus is dead:
¬ alive (Marcus, now)
↑ (9, substitution)
Dead(Marcus, now)
↑ (10, substitution)
Died(Marcus, t1) 𝖠 gt(now,t1)
↑ (5, substitution)
Pompeian (Marcus) 𝖠 gt(now,79)
↑ (2)
gt(now,79)
↑ (8, substitute equals)
gt(1991,79)
(Compute gt)
Nil

Another Way of Proving that Marcus is dead

¬alive (Marcus,now)
↑ (9, substitution)
Dead (Marcus, now)
↑ (7, substitution)
Mortal (Marcus) 𝖠 Born (Marcus, t1) 𝖠 gt(now-t1, 150)
Artificial Intelligence Module - II
↑ (4, substitution)
Man (Marcus) 𝖠 Born (Marcus, t1) 𝖠 gt(now-t1, 150)
↑ (1)
Born (Marcus, t1) 𝖠 gt(now-t1,150)
↑ (3)
gt(now-40,150)
↑ (8)
gt(1991-40,150)
↑ (Compute minus)
gt(1951,150)
↑ (Compute gt)
nil

✓ From looking at the proofs we have just shown, two things should be clear:
– Even very simple conclusions can require many steps to prove.
– A variety of processes, such as matching, substitution, and application of modus ponens are
involved in the production of a proof. This is true even for the simple statements weare
using. This becomes complex for complicated statements. To reduce complexity,next we
consider Resolution.

➢ RESOLUTION

✓ Resolution is a procedure, which gains its efficiency from the fact that it operates on statements
that have been converted to a very convenient standard form, which is described below.
– Resolution produces proofs by refutation. In other words, to prove a statement (i.e., show that
it is valid), resolution attempts to show that the negation of the statement produces a
contradiction with the known statements (i.e., that it is unsatisfiable). This approach contrasts
with the technique that we have been using to generate proofs by chaining backward from
the theorem to be proved to the axioms.

– Resolution Refutation
- Negate the goal
- Convert all pieces of knowledge into clausal form (disjunction of literals)
- See if contradiction indicated by null clause [ ] can be derived through resolution.

• Conversion to Clause Form (Clausal Normal Form)


Algorithm: Convert to Clause Form

1. Eliminate logical implications, → using the fact that A → B is equivalent to ¬A ∨ B


Eliminate all ↔ connectives using the fact that, (P ↔ Q) → ((P → Q) ^ (Q → P))
2. Reduce the scope of each negation to a single term, using the following facts:
¬ (¬P) = P
Artificial Intelligence Module - II
¬ (A ∨ B) = ¬A 𝖠 ¬B
¬ (A 𝖠 B) = ¬A V ¬B
¬ ∀x: P(x) = ∃ x: ¬P(x)
¬ ∃x: P(x) = ∀ x: ¬P(x)
3. Standardize variables so that each quantifier binds a unique variable.
4. Move all quantifiers to the left, maintaining their order.
5. Eliminate existential quantifiers, using Skolem constants or Skolem functions (functions
of the preceding universally quantified variables).
Examples:
( x) P(x) as P(c)
c is a Skolem constant (a new constant symbol that is not used in any other sentence)
( x)( y): P(x,y) as ( x): P(x, f(x))
Since is within the scope of a universally quantified variable, use a Skolem function f to
construct a new value that depends on the universally quantified variable. f must be a new
function name not occurring in any other sentence in the KB.
E.g., ( x)( y) loves(x,y) ⇒ ( x) loves(x, f(x)). In this case, f(x) specifies the person that x
loves
6. Remove universal quantifiers by (1) moving them all to the left end (2) making the scope
of each the entire sentence, and (3) dropping the “prefix” part. Ex: ( x)P(x) as P(x) Drop
the prefix: prefix refers to all the quantifiers.
7. Convert the remaining formula into a conjunction of disjuncts.
– Distribute v over ^
a. (P 𝖠 Q) R as (P R) 𝖠 (Q R)
b. (P Q) R as (P Q R)
8. Create a separate clause corresponding to each conjunct.
9. Standardize the variables in the clauses so that each clause contains only variable names that
do not occur in any other clause

Example 1: Conversion to CNF


“Everyone who loves all animals is loved by someone"
x [ y Animal(y) →Loves(x, y)] → [ y Loves(y, x)]

1. Eliminate biconditionals and implications


x [ y Animal(y) Loves(x, y)] → [ y Loves(y, x)]
x[ y Animal(y) Loves(x, y)] [ y Loves(y, x)]
2. Move inwards: xp≡ x p, xp≡ x p
x [ y ( Animal(y) Loves(x, y))] [ y Loves(y, x)]
x[ y Animal(y) Loves(x, y)] [ y Loves(y, x)]
x [ y Animal(y) Loves(x, y)] [ y Loves(y, x)]
3. Standardize variables: each quantifier should use a different one
x [ y Animal(y) Loves(x, y)] [ z Loves(z, x)]A
Artificial Intelligence Module - II
All quantifiers are on left only
4. Skolemize: a more general form of existential instantiation. Each existential variable is
replaced by a Skolem function of the enclosing universally quantified variables
x [Animal(F(x)) Loves(x, F(x))] Loves(G(x), x)
5. Drop universal quantifiers:
[Animal(F(x)) Loves(x, F(x))] Loves(G(x), x)
6. Distribute over :
[Animal(F(x)) Loves(G(x),x)] [ Loves(x,F(x)) Loves(G(x),x)]
7. Create a separate clause corresponding to each conjunct
[Animal(F(x)) Loves(G(x), x)]
[ Loves(x, F(x)) Loves(G(x), x)]
8. Variables are standardized in the clauses

Example 2: Conversion to CNF


Suppose we know that, “all Romans who know Marcus either hate Caesar or think that
anyone who hates anyone is crazy”. We could represent that in the following wff:
✯x: [Roman(x) 𝖠 know(x, Marcus)] →
[hate(x, Caesar) V ( y, ∃z : hate (y, z) → thinkcrazy(x, y))]

1. x: ¬ [Roman(x) 𝖠 know(x, Marcus)] V


[hate(x, Caesar) V ( y : ¬(∃z : hate(y, z)) V thinkcrazy(x, y))]
2. x: [¬ Roman(x) V ¬ know(x, Marcus)] V
[hate(x, Caesar) V ( y: z: ¬ hate(y, z) V thinkcrazy(x, y))]
3. x: y: z: [¬ Roman(x) V ¬ know(x, Marcus)] V
[hate(x, Caesar) V (¬ hale(y, z) V thinkcrazy(x, y))]
4. [¬ Roman(x) V ¬ know(x, Marcus)] V
[hate(x, Caesar) V (¬ hate(y, z) V thinkcrazy(x, y))]
5. ¬ Roman(x) V ¬ know(x, Marcus) V
hate(x, Caesar) V ¬ hate(y, z) V thinkcrazy(x, y)
• The Basis of Resolution
The resolution procedure is a simple iterative process: at each step, two clauses, called the parent
clauses, are compared (resolved), yielding a new clause that has been inferred from them. The
new clause represents ways that the two parent clauses interact with each other. Suppose that there
are two clauses in the system:
C1: Winter V summer C2:
¬Winter V cold
Now we observe that one of winter and ¬winter will be true at any point. If winter is true,
then cold must be true to guarantee the truth of the second clause. If ¬winter is true, then
summer must be true to guarantee the truth of the first clause. Thus we see that from these two
clauses we can deduce
Artificial Intelligence Module - II

C3: Summer V cold

This is the deduction that the resolution procedure will make. Resolution operates by taking two
clauses that each contains the same literal, in this example, winter. The literal must occur in
positive form in one clause and in negative form in the other. The resolvent is obtained by
combining all of the literals of the two parent clauses except the ones that cancel.

If the clause that is produced is the empty clause, then a contradiction has been found. For
example, the two clauses will produce the empty clause C1:
Winter
C2: ¬Winter
C3: [ ]

• Resolution in propositional Logic


In propositional logic, the procedure for producing a proof by resolution of proposition p with respect
to a set of axioms F is the following.

Algorithm: Propositional Resolution

1. Convert all the propositions of F to clause form.


2. Negate P and convert the result to clause form. Add it to the set of clauses
obtainedin step 1.
3. Repeat until either a contradiction is found or no progress can be made:
(a) Select two clauses. Call these the parent clauses.
(b) Resolve them together. The resulting clause, called the resolvent, will be the disjunction
of all of the literals of both of the parent clauses with the following exception: If there are
any pairs of literals L and ¬ L such that one of the parent clauses contains L and the other
contains ¬ L, then select one such pair and eliminate both L and ¬ L from the resolvent.
(c) If the resolvent is the empty clause, then a contradiction has been found. If it is not,
then add it to the set of clauses available to the procedure.

Look at a simple example: A Few Facts in Propositional Logic

Given Axioms Converted to Clause Form


P P (1)
(P V Q) → R ¬P V ¬ Q V R (2)
(S V T) → Q ¬S V Q (3)
¬T V Q (4)

T T (5)
Artificial Intelligence Module - II

Then we negate R, producing ¬R, which is already in clause form. Then we begin selecting pairs
of clauses to resolve together. Although any pair of clauses can be resolved, only those pairs that
contain complementary literals will produce a resolvent that is likely to lead to the goal ofproducing
the empty clause as shown below. We might, for example, generate the sequence of resolvents as
shown below: Take 2 and 6, then 1, then 4, then 5 and will get Nil.

¬R ¬R (6)

Resolution in Propositional Logic

¬PV¬QVR ¬R

¬PV¬Q P

¬T V Q ¬Q

¬T T

• The Unification Algorithm

✓ In propositional logic, it is easy to determine that two literals cannot both be true at the same time.
Simply look for L and ¬ L in predicate logic, this matching process is more complicated since the
arguments of the predicates must be considered. For example, man(john) and ¬ man(john) is a
contradiction, while man(john) and man(Spot) is not. Thus, in order to determine contradictions,
we need a matching procedure that compares two literals and discoverswhether there exists a set
of substitutions that makes them identical. There is a straightforward recursive procedure, called
the unification algorithm.
✓ The basic idea of unification is very simple. To attempt to unify two literals, we first check if their
initial predicate symbols are the same. If so, we can proceed. Otherwise, there is no way they
can be unified, regardless of their arguments. For example, the two literals cannot be unified.
Artificial Intelligence Module - II
try assassinate(Marcus, Caesar)
hate(Marcus, Caesar)
✓ If the predicate symbols match, then we must check the arguments, one pair at a time. If the
first matches, we can continue with the second, and so on.
✓ A variable can match another variable, any constant, or a predicate expression with the
restriction that the predicate expression must not contain any instances of the variable being
matched. To do this, we must take each substitution that we find and apply it to the remainder of
the literals before we continue trying to unify them.
P (x, x)
P (y, z)
✓ The two instances of P match fine. Next we compare x and y, and decide that if we substitute y
for x, they could match. We will write that substitution as
y/x
✓ But now, if we simply continue and match x and z, we produce the substitution z/x, but we
cannot substitute both 𝑦 and z for x, so we have not produced a consistent substitution.
✓ What we need to do after finding the first substitution y/ x is to make that substitution throughout
the literals, giving
P (y, 𝑦)
P (y, z)
✓ We can attempt to unify arguments y and z, which succeeds with the substitution z/ 𝑦. The entire
unification process has now succeeded with a substitution that is the composition of the two
substitutions we found. We write the composition as following standard notation for function
composition.
(z / y)( y/ x)
✓ In general, the substitution (a1/a2, a3/a4, ….) (b1/b2, b3/b4, …..)… means to apply all the
substitutions of the right-most list, then take the result and apply all the ones of the next list, and
so forth, until all substitutions have been applied.
✓ The object of the unification procedure is to discover at least one substitution that causes two
literals to match. Usually, if there is one such substitution there are many. For example, the literals
hate (x, 𝑦)
hate (Marcus, z)
could be unified with any of the following substitutions:
(Marcus/x, z/y)
(Marcus/x, y/z)
(Marcus/x, Caesar/ y, Caesar/ z)
(Marcus/ x, polonius/ y, polonius/ z)

We describe a procedure Unify (L1, L2), which returns as its value a list representing the
composition of the substitutions that were performed during the match. The empty list, NIL,
indicates that a match was found without any substitutions. The list consisting of the single value
FAIL indicates that the unification that the unification procedure failed.
Artificial Intelligence Module - II

Algorithm: Unify (L1, L2)

1. If L1 or L2 are both variables or constants, then:


a. If L1 and L2 are identical, then return NIL.
b. Else if L1 is a variable, then if L1 occurs in L2 then return {FAIL}, else return (L2/L1).
c. Else if L2 is a variable, then if L2 occurs in L1 then return {FAIL}, else return (L1/L2).
d. Else return {FAIL}.
2. If the initial predicate symbols in L1 and L2 are not identical, then return {FAIL}.
3. If LI and L2 have a different number of arguments, then return {FAIL}.
4. Set SUBST to NIL. (At the end of this procedure, SUBST will contain all the substitutions used
to unify L1 and L2.)
5. For i ← 1 to number of arguments in L1:
a. Call Unify with the ith argument of L1 and the ith argument of L2, putting result in S.
b. If S contains FAIL then return {FAIL}.
c. If S is not equal to NIL then:
i. Apply S to the remainder of both L1 and L2.
ii. SUBST: = APPEND(S, SUBST).
6. Return SUBST.

Example:
p = Knows(John, x)
q = Knows(John, Jane)
Unify(p, q) = {x/Jane}

• Resolution in Predicate Logic

✓ We now have an easy way of determining that two literals are contradictory – they are if one of
them can be unified with the negation of the other. For example, man(x) and ¬man(Spot) are
contradictory, since man(x) and man(Spot) can be unified. This corresponds to the intuition that
man(x) cannot be true for all x if there is known to be some x, say spot, for which man(x) is
false. Thus in order to use resolution for expression in the predicate logic, we use the unification
algorithm to locate pairs of literals that cancel out.
✓ We also need to use the unifier produced by the unification algorithm to generate the resolvent
clause. For example, suppose we want to resolve two clauses.
1. Man(Marcus)
2. ¬man(x1) V mortal(x1)
✓ The literal man(Marcus) can be unified with the literal man(x1) with the substitution Marcus/x1,
telling us that for x1=Marcus, ¬man(Marcus) is false. But we cannot simply cancel out the two
man literals as we did in propositional logic and generate the resolvent mortal(x1). Clause 2 says
that for a given x1, either ¬man(x1) or mortal(x1). So for it to be true for all x1, since for some
values of x1, ¬man(x1) might be true, making mortal(x1) irrelevant to
the truth of the complete clause.
Artificial Intelligence Module - II

We can now state the resolution algorithm for predicate logic as follows, assuming a set of
statements F and statement to be proved P:

Algorithm: Resolution
1. Convert all the statements of F to clause form.
2. Negate P and convert the result to clause form. Add it to the set of clauses obtained in 1.
3. Repeat until either a contradiction is found, no progress can be made, or a
predetermined amount of effort has been expended.
a. Select two clauses. Call these the parent clauses.
b. Resolve them together. The resolvent will be the disjunction of all the literals of parent
clauses with appropriate substitutions performed and with the following exception: If
there is one pair of literals T1 and ¬ T2 such that one of the parent clauses contains T2
and the other contains T1 and if T1 and T2 are unifiable, then neither T1 nor T2 should
appear in the resolvent. We call T1 and T2 Complementary literals. Use the substitution
produced by the unification to create the resolvent. If there is more than one pair of
complementary literals, only one pair should be omitted from the resolvent.
c. If the resolvent is the empty clause, then a contradiction has been found. If it is not,
then add it to the set of clauses available to the procedure.

✓ There exist STRATEGIES for making the choice that can speed up the process considerably:

– Only resolve pairs of clauses that contain complementary literals, since only such
resolutions produce new clauses that are harder to satisfy than their parents.
– Eliminate certain clauses as soon as they are generated so that they cannot participate in later
resolutions. Two kinds of clauses should be eliminated: tautologies (which can never be
unsatisfied) and clauses that are subsumed by other clauses (i.e., they are easier to satisfy.For
example, P V Q is subsumed by P.)
– Whenever possible, resolve either with one of the clauses that is part of the statement we are
trying to refuse or with a clause generated by a resolution with such a clause. This is called
the set-of-support strategy and corresponds to the intuition that the contradiction we are
looking for must involve the statement we are trying to prove.
– Whenever possible, resolve with clauses that have a single literal. Such resolutions generate
new clauses with fewer literals than the larger of their parent clauses and thus are probably
closer to the goal of a resolvent with zero terms. This method is called the unit-preference
strategy.

Example 1: All statements of Marcus are converted to CNF


Axioms in clause form:
1. Man(Marcus)
2. Pompeian(Marcus)
3. ¬ Pompeian( x1) V Roman(x1)
4. Ruler(Caesar)
Artificial Intelligence Module - II

5. Roman(x2) V loyalto(x2, Caesar) V hate (x2, Caesar)


6. loyalto(x3, f1(x3))
7. ¬man(x4) V ¬ ruler (y1) V ¬ tryasssassinate (x4, y1) V loyalto (x4, y1)
8. tryasssassinate (Marcus, Caesar )

Prove: hate (Marcus, Caesar)

Below figure shows a resolution proof of the statement

Below example shows an unsuccessful attempt at Resolution because of no contradiction exists.


Artificial Intelligence Module - II

Example 2: All statements of Marcus are converted to CNF


Axioms in clause form:

Prove: alive (Marcus, now)


Below figure shows use of Resolution with equality and Reduce

• The Need to Try Several Substitutions

✓ Resolution provides a very good way of finding a refutation proof without actually trying all
the substitutions. But it does not always eliminate the necessity of trying more than one
substitution. For example,
hate (Marcus, Paulus)
hate (Marcus, Julian)
Artificial Intelligence Module - II

✓ Now if we want to prove that Marcus hates some ruler, we would be likely to try each
substitution shown in Figure (a) and (b) before finding the contradiction shown in (c).

Prove: x: hate(Marcus, x) ruler (x) Negate:


x: hate(Marcus, x) ruler (x) Clause: hate
(Marcus, x) ruler(x)

Figure shows Trying Several Substitutions

• Question Answering

✓ Here, it shows how resolution can be used to answer fill-in-the-blank questions, such as “when
did Marcus die?” or “who tried to assassinate a ruler?” Answering these questions involves
finding a known statement that matches the terms given in the question and then responding
with another piece of that same statement that fills the slot demanded by the question.
For example, to answer the question “when did Marcus die?” we need a statement of the form
died (Marcus, ??)
With ?? actually filled in by some particular year. So, since we can prove the statement
died(Marcus,79)
We can respond with the answer 79.
✓ It turns out that the resolution procedure provides an easy way of locating just the statement
we need and finding a proof for it. Let’s continue with the example
Artificial Intelligence Module - II

“When did Marcus die?” in order to be able to answer this question, it must first be true that
Marcus died. Thus it must be the case that
t: died(Marcus, t)
✓ A reasonable first step then might be try to prove this. To do so using resolution, we attempt to
shown that
t: died(Marcus, t)
produces a contradiction. What does it mean for that statement to produce a contradiction?
Either it conflicts with a statement of the form
t: died(Marcus, t)
Where t is a variable, in which case we can either answer the question by reporting that there
are many times at which Marcus died, or we can simply pick one such time and respond
with it. The other possibility is that we produce a contradiction with one or more specific
statements of the form for specific value of date
died(Marcus, date)
✓ Figure (a) shows how the resolution process finds the statement for which we looking. The
answer to the question can then be derived from the chain of unifications that lead back to the
starting clause. We can eliminate the necessity for this final step by adding an additional
expression to the one we are going to use to try to find a contradiction.
✓ Figure (b) shows how this process produces an answer to our question. This will not interfere
with resolution process (underlined). Instead of terminating with nil clause, the resolution will
terminate when all that is left is the dummy expression.
x: event(x,79)
Figure shows Answer Extraction Using Resolution
Artificial Intelligence Module - II

✓ We can, however, answer the question if we change our representation. Instead of saying
erupted (volcano, 79)
we can say
event(erupted(volcano), 79)
Then the simple proof shown in Figure below enables us to answer the question.

➢ NATURAL DEDUCTION

✓ We introduced resolution as an easily implementable proof procedure that relies for its simplicity
on a uniform representation of the statements it uses. Unfortunately, uniformity has its price
everything looks the same. Since everything looks the same, there is no easy way to select those
statements that are the most likely to be useful in solving a particular problem. In converting
everything to clause form, we often lose valuable heuristic information that is contained in the
original representation of the facts. For example, suppose “we believe that all judges who are
not crooked are well- educated”, which can be represented as

x: judge(x) crooked(x) → educated(x)

✓ In this form, the statement suggests a way of deducing that someone is educated. But when the
same statement is converted to clause form,

judge(x) crooked(x) educated(x)

✓ It appears also to be a way of deducing that someone is not a judge by showing that he is not
crooked and not educated. Of course, in a logical sense, it is. But it is almost certainly not the
way, or even a very good way, to go about showing that someone is not a judge. The heuristic
information contained in the original statement has been lost in the transformation.
✓ Natural deduction is not a precise term. Rather it describes a mixture of techniques, used in
combination to solve problems that are not tractable by any one method alone. One common
technique is to arrange knowledge, not by predicates, as we have been doing, but rather by the
objects involved in the predicates.
Artificial Intelligence Module - II

Chapter 6

REPRESENTING KNOWLEDGE USING RULES


Here, we discuss the use of rules to encode Knowledge. This is a particularly important issue since rule-
based reasoning systems have played a very important role in the evolution of AI from a purely laboratory
science into a commercially significant one.

➢ PROCEDURAL VERSUS DECLARATIVE KNOWLEDGE

✓ We viewed logical assertion as declarative representations of knowledge. In declarative


representation, the Knowledge is specified, but how to use that Knowledge is not given. To use a
declarative representation, we must augment it with a program that specifies what is to be done to
the Knowledge and how. For example, a set of logical assertions can be combined with a resolution
theorem prover to give a complete program for solving problems. There is different way, though, in
which logical assertions can be viewed, namely as a program, rather than as data to a program. In
this view, the implication statements define the legitimate reasoning paths and the atomic
assertions provide the starting points (or, if we reason backward, the ending points) of those
paths. These reasoning paths define the possible execution paths of the program in much the same
way that traditional control constructs, such as if-then-else.
✓ In other words, we could view logical assertions as procedural representation of Knowledge. A
procedural representation is one in which the control information that is necessary to use the
Knowledge is considered to be embedded in the Knowledge itself. To use the procedural
representation, we need to augment it with an interpreter that follows the instructions given in the
Knowledge. The real difference between the declarative and the procedural views of Knowledge
lies in where control information resides.
✓ For example, consider the Knowledge base:

Now, consider to extract answer to question from this knowledge base and bind that to y.

This knowledge base justifies any of the following answers.

Because there is more than one value that satisfies the predicate, but only one value is needed,
the answer to the question will depend on the order in which the assertions are examined during
the search for a response.
Artificial Intelligence Module - II

✓ If we view the assertions as declarative, then they do not themselves say anything about how they
will be examined. If we view them as procedural, then they do. To see clearly the difference between
declarative and procedural representations, consider the following assertions:

Viewed declaratively, this is the same Knowledge base as above. All the same answers are
supported by the system and no one of them is explicitly selected. But viewed procedurally, and
using the control model we used to get y = Cleopatra as our answer.
✓ But this is a different Knowledge base since now the answer to our question is Marcus. This
happens because the first statement that can achieve the person goal is the inference rule
x: man(x) → person(x). This rule sets up a subgoal to find a man. Again the statements are
examined from the beginning, and now Marcus is found to satisfy the subgoal and thus also the
goal. So Marcus is reported as the answer.
✓ It is important to keep in mind that although we have said that a procedural representation encodes
control information in the Knowledge base, it does so only to the extent that the interpreter for the
Knowledge base recognizes that control information.
✓ There has been a great deal of controversy in AI over whether declarative or procedural Knowledge
representation frameworks are better. There is no clear-cut answer to the question.

➢ LOGIC PROGRAMMING

✓ Logic programming is a programming language paradigm in which logical assertions are viewed
as programs. There are several logic programming systems in use today, the most popular of which
is PROLOG. A PROLOG program is described as a series of logical assertions, each of which is
a Horn clause. A Horn clause is clause that has at most one positive literal. Thus p,
P Q, and P→Q are all Horn clauses.
✓ Programs written in pure PROLOG are composed only of Horn clauses. Any logical expression can
be converted to clause form. If we do that for this example, the resulting clauses is P Q, which is
a well- formed Horn clause. The fact that PROLOG programs are composed only of Horn clauses
because of a simple and efficient interpreter can be written and the logic of Horn clause systems
is decidable.
✓ The control structure that is imposed on a PROLOG program by the PROLOG interpreter is the
same one used to find the answers Cleopatra and Marcus. The input to a program is a goal to be
proved. Backward reasoning is applied to try to prove the goal, given the assertions in the program.
The program is read top to bottom, left to right and depth-first search is performed with
backtracking.
✓ Figure below shows an example of a simple Knowledge base represented in standard logical
notation and then in PROLOG. Both of these representations contain two types of statements,
facts, which contain only constants and rules, which do contain variables. Facts represent
statements about specific objects. Rules represent statements about classes of objects.
Artificial Intelligence Module - II

Representation in logic
Representation in Prolog

✓ Notice that there are several superficial, syntactic differences between the logic and the
PROLOG representations, including:
1. In logic, variables are explicitly quantified. In PROLOG, quantification is provided implicitly
by the way the variables are interpreted. The distinction between variables and constants is
made in PROLOG by having all variables begin with upper case letters and all constants
begin with lower case letters or numbers.
2. In logic, there are explicit symbols for AND( ) and OR ( ). In PROLOG, there is an explicit
symbol for AND ( , ) but there is none for OR. Instead, disjunction must be represented as a list
of alternative statements, any one of which may provide the basis for a conclusion.
3. In logic, implications of the “p implies q” are written as p→q. In PROLOG, the same
implication is written “backward,” as q : - p. This form is natural in PROLOG because the
interpreter always works backwards from a goal, and this form causes every rule to begin with
the component that must therefore be matched first. This first component is called the head of
the rule.
✓ The first two of the above differences arise naturally from the fact that PROLOG programs are
actually sets of Horn clauses that have been transformed as follows:
1. If the Horn clause contains no negative literals (i.e., it contains a single literal which is positive),
then leave it as it is.
2. Otherwise, rewrite the Horn clause as an implication, combining all of the negative literals
into the antecedent of the implication and leaving the single positive literal (if there is one) as
the consequent.
✓ This procedure causes a clause, which originally consisted of a disjunction of literals to be
transformed into a single implication whose antecedent is a conjunction of literals. Further, recall
that in a clause, all variables are implicitly universally quantified. But, when we apply this
transformation, any variables that occurred in negative literals and so now occur in the antecedent
become existentially quantified, while the variables in the consequent (the head) are still universally
quantified. For example, the PROLOG clause P(x) : - Q(x, y) is equivalent to the logical expression
x: y: Q(x, y) → P(x)
Artificial Intelligence Module - II

✓ A key difference between logic and the PROLOG representation is that the PROLOG interpreter
has a fixed control strategy, and so the assertions in the PROLOG program define a particular
search path to an answer to any question. In contrast, the logical assertions define only the set
of answers that they justify and they themselves say nothing about how to choose among those
answers if there is more than one.
✓ The basic PROLOG control strategy outlined above is simple. Begin with a problem statement,
which is viewed as a goal to be proved. Look for assertions that can prove the goal. Consider facts,
which prove the goal directly, and also consider any rule whose head matches the goal. To decide
whether a fact or a rule can be applied to the current problem, invoke a standard unification
procedure. Reason backward from that goal until a path is found that terminates with assertions in
the program. Consider paths using a depth-first search strategy with backtracking. At each
choice point, consider options in the order in which they appear, propagating variable (X). We state
this goal to PROLOG as
?- apartmentpet (X).
Think of binding as they are determined during unification. We can illustrate this strategy with
a simple example. Suppose the problem we are given is to find a value of X that satisfy the
predicate apartmentpet as the input to the program. The PROLOG interpreter begins looking fora
fact with the predicate apartmentpet or a rule with that predicate as its head. Usually PROLOG
programs are written with the facts containing a given predicate coming before the rules for that
predicate so that the facts can be used immediately if they are appropriate and rules will only be
used when the desired fact is not immediately available.
✓ Using the rules about dogs and poodles and using the fact poodle (fluffy). This results in the
variable X being bound to fluffy. Now the second clause small(X) of the initial rule must be
checked. Since X is now bound to fluffy, the more specific goal, small (fluffy), must be proved.
This too can be done by reasoning backward to the assertion poodle (fluffy). The program then
halts with the result apartmentpet(fluffy).
✓ Logical negation ( ) cannot be represented explicitly in pure PROLOG. So, for example, it is not
possible to encode directly the logical assertion x: dog(x) → cat(x). Instead, negation is
represented implicitly by the lack of an assertion. This leads to the problem- solving strategy called
negation as failure. If the PROLOG program of figure above were given the goal it would return
FALSE because it is unable to prove that Fluffy is cat. ?- cat (fluffy).
✓ Negation by failure requires that we make what is called the closed world assumption, which states
that all relevant, true assertions are contained in our knowledge base are derivable from assertions
that are so contained. Any assertion that is not present can therefore be assumed to be false.
✓ There is much to say on the topic of PROLOG –style versus LISP- style programming. A great
advantage of logic programming is that the programmer need only specify rules and facts since a
search engine is built directly into the language. The disadvantage is that the search control is
fixed. Although it is possible to write PROLOG code that uses search strategies other than depth-
first with backtracking, it is difficult to do so.

DEPT OF ISE RNSIT


Artificial Intelligence Module - II

✓ More generally, the fact that PROLOG programs must be composed of a restricted set of logical
operators can be viewed as a limitation of the expressiveness of the language. But the other side
of the coin is that it is possible to build PROLOG compilers that produce very efficient code.

➢ FORWARD VERSUS BACKWARD REASONING

✓ The objective of a search procedure is to discover a path through a problem space from an initial
configuration to a goal state. PROLOG only searches from a goal state. There are actually two
directions in which such search could proceed.
– Forward, from the start states
– Backward, from the goal states
✓ The production system model of the search process provides an easy way of viewing forward and
backward reasoning as symmetric process. Consider the problem of solving a particular instance of
the 8-puzzle. The rules to be used for solving the puzzle can be written as shown in Figure below.

Example: Start state Goal State

✓ Reasoning forward from the initial states begins building a tree of move sequence that might be
solutions by starting with the initial configurations(s) at the root of the tree. Generate the next level
of the tree by finding all the rules whose left sides match the root node and using their right sides to
create the new configurations. Generate the next level by taking each node generated at theprevious
level and applying to it all of the rules whose left sides match it. Continue until a configuration that
matches the goal state is generated.
Artificial Intelligence Module - II

✓ Reasoning backward from the goal states begins building a tree of move sequences that might be
solutions by starting with the goal configurations(s) at the root of the tree. Generate the next level
of the tree by finding all the rules whose right sides match the root node. These are all rules that,
if only we could apply them, would generate the state we want. Use the left sides of the rules to
generate the nodes at this second level of the tree. Generate the next level of the tree by taking each
node at the previous level and finding all the rules whose right sides match it. Then use the
corresponding left sides to generate the new nodes. Continue until a node that matches the initial
state is generated. This method of reasoning backward from the desired final state is often called
goal-directed reasoning.
✓ Notice that the same rules can be used both to reason forward from the initial state and to reason
backward from the goal state. To reason forward, the left sides (the preconditions) are matched
against the current state and the right sides (the results) are used to generate new nodes until the goal
is reached. To reason backward, the right sides are matched against the current node and the left
sides are used to generate new nodes representing new goal states to be achieved. This continues
until one of these goal states is matched by an initial state.
✓ In the case of the 8-puzzle, it does not make much difference whether we reason forward or
backward, about the same number of paths will be explored in either case. But this is not always
true. Depending on the topology of the problem space, it may be significantly more efficient to
search in one direction rather than the other.
✓ Four factors influence, the question of whether it is better to reason forward or backward.
– Are there more possible start states or goal states? We would like to move from the smaller
set of states to the larger set of states.
– In which direction is the branching factor greater? We would like to proceed in the
direction with the lower branching factor.
– Will the program be asked to justify its reasoning process to a user? If so, it is important to
proceed in the direction that corresponds more closely with the way the user will think.
– What kind of event is going to trigger a problem-solving episode? If it is the arrival of a
new fact, forward reasoning makes sense. If it is a query to which a response is desired,
backward reasoning is more natural.
Artificial Intelligence Module - II

✓ Although in principle the same set of rules can be used for both forward and backward reasoning,
in practice it has proved useful to define two classes of rules, each of which encodesa particular
kind of knowledge.
– Forward rules, which encode knowledge about how to respond to certain input configurations.
– Backward rules, which encode knowledge about how to achieve particular goals.

• Backward‒Chaining Rule Systems


PROLOG is an example for Backward ‒ Chaining rule systems, of which, are good for goal- directed
problem- solving. For example, a query system would probably use backward chaining to reason
about and answer user questions. In PROLOG, rules are restricted to Horn Clauses. This allows for
rapid indexing because all of the rules for deducing a given fact share the same rule head.Rules are
matched with the unification procedure. Unification tries to find a set of bindings for variables to
equate a (sub) goal with the head of some rule. Rules in a PROLOG program are matched in the order
in which they appear. Other backward‒chaining systems allow for more complex rules. Example is
MYCIN

• Forward‒Chaining Rule Systems


Instead of being directed by goals, we want to be directed by incoming data. For example, suppose
you sense burning heat near your hand. You are likely to jerk your hand away. While this could be
construed as goal‒directed behavior, it is modeled more naturally by the recognize‒act cycle
characteristic of forward‒chaining rule systems. In forward‒chaining systems, left sides of rules are
matched against the state description. Rules that match dump their right‒hand side assertions into the
state, and the process repeats. Matching is typically more complex for forward‒chainingsystems than
backward ones. Most forward‒chaining systems (e.g., OPS5) implement highly efficient matchers
and supply several mechanisms for preferring one rule over another.
Artificial Intelligence Module - II

• Combining Forward and Backward Reasoning


Sometimes certain aspects of a problem are best handled via forward chaining and other aspects by
backward chaining. Consider a forward chaining medical diagnosis program. It might accept twenty
or so facts about a patient’s condition, then forward chain on those facts to try to deduce the nature
and/or cause of the disease. Now suppose that at some point, the left side of a rule was nearlysatisfied-
say, nine out of ten of its preconditions were met. It might be efficient to apply backward reasoning
to satisfy the tenth precondition in a directed manner, rather than wait for forward chaining to supply
the fact by accident. Or perhaps the tenth condition requires further medicaltests. In that case,
backward chaining can be used to query the user. Whether it is possible to use thesame rules for both
forward and backward reasoning also depends on the form of the rules themselves. If both left sides
and right sides contain pure assertions, then forward chaining can match assertions on the left side of
a rule and add to the state description the assertions on the right side.

➢ MATCHING

The process of using search to solve problems as the application of appropriate rules to individual
problem states to generate new states, then to which the rules can then be applied, andso forth, until
a solution is found. The clever search involves choosing from among the rules that can be applied
at a particular point, the ones that are most likely to lead to a solution. But how to extract from the
entire collection of rules those that can be applied at a given point?. To do so requires some kind of
matching between the current state and the preconditions of the rules. How should this be done? The
answer to this question can be critical to the success of a rule-based system. We discuss a few
proposals below.

• Indexing
One way to select applicable rules is to do a simple search through all the rules, comparing each
one’s preconditions to the current state and extracting all the ones that match. But there are two
problems with this simple solution:
– In order to solve very interesting problems, it will be necessary to use a large number of
rules. Scanning through all of them at every step of the search would be inefficient.
– It is not always immediately obvious whether a rule’s preconditions are satisfied by a
particular state.
✓ Sometimes there are easy ways to deal with the first of these problems. Instead of searching
through the rules, use the current state as an index into the rules and select the matching ones
immediately. For example, consider the legal-move generation rule for chess shown in figure
below to be able to access the appropriate rules immediately, all we need to do is assign and index
to each board position. This can be done simply by treating the board description as a large
number. Any reasonable hashing function can then be used to treat that number as an index into
the rules. It is often better to write rules in a more general form, such as that shown infigure below.
Artificial Intelligence Module - II

Rules

When this is done, such simple indexing is not possible. In fact, there is often a trade-off between
the ease of writing rules and the simplicity of matching process. All of this does not mean that
indexing cannot be helpful even when the preconditions of rules are started as fairly high-level
predicates.
Artificial Intelligence Module - II
Artificial Intelligence Module - II
Artificial Intelligence Module - II

You might also like