You are on page 1of 28

ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV

Module-IV
Contents:
Propositional vs first order inference
Unification and lifting
Forward chaining
Backward chaining
 A backward chaining algorithm
Resolution
 Conjunctive normal form for first-order logic
 The resolution inference rule
 Example proofs
Planning
 The planning problem
 Planning with state space search
Partial order planning
 A partial-order planning example

1
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV

Propositional Vs first order logic:


Propositional Logic:
• Logic is a great knowledge representation language for many AI problems
• Propositional logic is the simple foundation and fine for some AI problems
• First order logic (FOL) is much more expressive as a Knowledge Representation language
and more commonly used in AI
• There are many variations: horn logic, higher order logic, three-valued logic, probabilistic
logics, etc.
• Logical constants: true, false
• Propositional symbols: P, Q,... (atomic sentences)
• Wrapping parentheses: ( … )
• Sentences are combined by connectives:
 and [conjunction]
 or [disjunction]
 implies [implication / conditional]
 is equivalent [biconditional]
 not [negation]
 Literal: atomic sentence or negated atomic sentence
P,  P
• Simple language for showing key ideas and definitions
• User defines set of propositional symbols, like P and Q
• User defines semantics of each propositional symbol:
P means ―It is hot‖, Q means ―It is humid‖, etc.
• A sentence (well formed formula) is defined as follows:
• A symbol is a sentence
• If S is a sentence, then S is a sentence
• If S is a sentence, then (S) is a sentence
• If S and T are sentences, then (S  T), (S  T), (S  T), and (S ↔ T) are sentences
• A sentence results from a finite number of applications of the rules
• The meaning or semantics of a sentence determines its interpretation
• Given the truth values of all symbols in a sentence, it can be ―evaluated‖ to determine its
truth value (True or False)

2
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV

• A model for a KB is a possible world – an assignment of truth values to propositional


symbols that makes each sentence in the KB True
• A valid sentence or tautology is a sentence that is True under all interpretations, no matter
what the world is actually like or what the semantics is. Example: ―It’s raining or it’s not
raining‖
• An inconsistent sentence or contradiction is a sentence that is False under all interpretations.
The world is never like what it describes, as in ―It’s raining and it’s not raining.‖
• P entails Q, written P |= Q, means that whenever P is True, so is Q. In other words, all
models of P are also models of Q.
Advantages
• Simple KR language sufficient for some problems
• Lays the foundation for higher logics (e.g., FOL)
• Reasoning is decidable, though NP complete, and efficient techniques exist for many
problems
Disadvantages
• Not expressive enough for most problems
• Even when it is, it can very ―un-concise‖
• Hard to identify ―individuals‖ (e.g., Mary, 3)
• Can’t directly talk about properties of individuals or relations between individuals
(e.g., ―Bill is tall‖)
• Generalizations, patterns, regularities can’t easily be represented (e.g., ―all triangles
have 3 sides‖)
First-Order Logic (FOL) is expressive enough to represent this kind of information using relations,
variables and quantifiers, e.g.,
• Every elephant is gray:  x (elephant(x) → gray(x))
• There is a white alligator:  x (alligator(X) ^ white(X))
Wumpus domain:
 Some atomic propositions:
S12 = There is a stench in cell (1,2)
B34 = There is a breeze in cell (3,4)
W22 = Wumpus is in cell (2,2)
V11 = We’ve visited cell (1,1)

3
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV

OK11 = Cell (1,1) is safe.


• Some rules:
(R1) S11  W11   W12   W21
(R2)  S21  W11   W21   W22   W31
(R3)  S12  W11   W12   W22   W13
(R4) S12  W13  W12  W22  W11

• The lack of variables requires us to give similar rules for each cell!

4
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV

Proving W1,3:
Apply MP with S11 and R1:
 W11   W12   W21
Apply And-Elimination to this, yielding 3 sentences:
 W11,  W12,  W21
Apply MP to ~S21 and R2, then apply And-elimination:
 W22,  W21,  W31
Apply MP to S12 and R4 to obtain:
W13  W12  W22  W11
Apply Unit resolution on (W13  W12  W22  W11) and W11:
W13  W12  W22
Apply Unit Resolution with (W13  W12  W22) and W22:
W13  W12
Apply UR with (W13  W12) and W12:
W13 Hence proved
Propositional Wumpus hunter problems:
• Lack of variables prevents stating more general rules
– We need a set of similar rules for each cell
• Change of the KB over time is difficult to represent
– Standard technique is to index facts with the time when they’re true
– This means we have a separate KB for every time point
• Inference is the process of deriving new sentences from old
– Sound inference derives true conclusions given true premises
– Complete inference derives all true conclusions from a set of premises
Summary Of Proposition Logic:
• A valid sentence is true in all worlds under all interpretations
• If an implication sentence can be shown to be valid, then—given its premise—its consequent
can be derived
• Different logics make different commitments about what the world is made of and what kind
of beliefs we can have
• Propositional logic commits only to the existence of facts that may or may not be the case in
the world being represented
– Simple syntax and semantics suffices to illustrate the process of inference

5
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV

– Propositional logic can become impractical, even for very small worlds
First-Order Logic (FOL):
• First-order logic (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 ...
User provides the following:
• 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)
FOL provides the following:
• Variable symbols
– E.g., x, y, foo
• Connectives
– Same as in PL: not (), and (), or (), implies (), if and only if (biconditional )
• Quantifiers
– Universal x or (Ax)

6
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV

– Existential x or (Ex)
Sentences are built from terms and atoms:
• A term (denoting a real-world individual) is a constant symbol, a variable symbol, or an n-
place function of n terms.
x and f(x1, ..., xn) are terms, where each xi is a term.
A term with no variables is a ground term
• An atomic sentence (which has value true or false) is an n-place predicate of n terms
• A complex sentence is formed from atomic sentences connected by the logical connectives:
P, PQ, PQ, PQ, PQ where P and Q are sentences
• A quantified sentence adds quantifiers  and 
• A well-formed formula (wff) is a sentence containing no ―free‖ variables. That is, all
variables are ―bound‖ by universal or existential quantifiers.
(x)P(x,y) has x bound as a universally quantified variable, but y is free.
Quantifiers:
• Universal quantification
– (x)P(x) means that P holds for all values of x in the domain associated with that
variable
– E.g., (x) dolphin(x)  mammal(x)
• Existential quantification
– ( x)P(x) means that P holds for some value of x in the domain associated with that
variable
– E.g., ( x) mammal(x)  lays-eggs(x)
– Permits one to make a statement about some object without naming it
• Universal quantifiers are often used with ―implies‖ to form ―rules‖:
(x) student(x)  smart(x) means ―All students are smart‖
• Universal quantification is rarely used to make blanket statements about every individual in
the world:
(x) student(x) smart(x) means ―Everyone in the world is a student and is 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‖
• A common mistake is to represent this English sentence as the FOL sentence:
(x) student(x)  smart(x)

7
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV

Inference rules for quantifiers:


 Universal Instantiation(UI):
The rule of UI says that we can infer any sentence obtained by substituting a ground term (a term without
variables) for the variable. To write out the inference rule formally, we use the notion of substitutions.

Let S UBST(θ,α) denote the result of applying the substitution θ to the sentence α. Then the rule is written

for any variable v and ground term g. For example, the three sentences given earlier are obtained with the

substitutions {x/John}, {x/Richard }, and {x/Father (John)}.

 Existential Instantiation:
In the rule for Existential Instantiation, the variable is replaced by a single new constant symbol. The formal
statement is as follows: for any sentence α, variable v, and constant symbol k that does not appear elsewhere
in the knowledge base,

For example, from the sentence

we can infer the sentence


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

Crown(C1) ∧ OnHead(C1, John)


as long as C1 does not appear elsewhere in the knowledge base. Basically, the existential sentence
says there is some object satisfying a condition, and applying the existential instantiation rule just
gives a name to that object. Of course, that name must not already belong to another object. In logic,
the new name is called a Skolem constant. Existential Instantiation is a special case of a more general process
called skolemization.
Whereas Universal Instantiation can be applied many times to produce many different consequences,
existential Instantiation can be applied once, and then the existentially quantified sentence can be discarded.

Reduction to propositional inference:


Once we have rules for inferring non quantified sentences from quantified sentences, it becomes possible
to reduce first-order inference to propositional inference.

8
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV

The first idea is that, just as an existentially quantified sentence can be replaced by one instantiation, a
universally quantified sentence can be replaced by the set of all possible instantiations. For example, suppose
our knowledge base contains just the sentences

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

King(John)

Greedy(John)

Brother (Richard, John)

Then we apply UI to the first sentence using all possible ground-term substitutions from the vocabulary of the
knowledge base—in this case, {x/John} and {x/Richard }. We obtain

King(John) ∧ Greedy(John) ⇒ Evil(John)

King(Richard ) ∧ Greedy(Richard) ⇒ Evil(Richard) ,

and we discard the universally quantified sentence. Now, the knowledge base is essentially propositional if we

view the ground atomic sentences King(John), Greedy(John), and so on, as proposition symbols. Therefore,

we can apply any of the complete propositional algorithms to obtain conclusions such as,

Evil(John)

This technique of propositionalization can be made completely general; that is, every first-order knowledge
base and query can be propositionalized in such a way that entailment is preserved. Thus, we have a complete
decision procedure for entailment . . . or perhaps not.
There is a problem: when the knowledge base includes a function symbol, the set of possible ground-term
substitutions is infinite!
Unification and lifting:
The process of finding all legal substitutions that make logical expressions look identical.

The inference that John is evil—that is, that {x/John} solves the query Evil(x)—works like this: to use the
rule that greedy kings are evil, find some x such that x is a king and x is greedy, and then infer that this x is
evil.
This inference process can be captured as a single inference rule that we call Generalized Modus Ponens.
For atomic sentences pi, pi', and q, where there is a substitution θsuch that SUBST(θ, pi' )= SUBST(θ, pi),
for all i,
p1', p2', … , pn', ( p1  p2  …  pn q)

Subst(θ,q)

Example:
x King(x)  Greedy(x)  Evil(x)

9
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV

King(John)
y Greedy(y)
Brother(Richard, John)
We would like to infer Evil(John) without propositionalization.
Basic Idea: Use Modus Ponens, Resolution when literals unify.

King(John), Greedy(John) ,x King(x)  Greedy(x)  Evil(x)

p1' is King(John) p1 is King(x)


p2' is Greedy(John) p2 is Greedy(x)
θ is {x/John} q is Evil(x)
Subst(θ,q) is Evil(John)

Generalized Modus Ponens is a lifted version of Modus Ponens—it raises Modus Ponens from
ground (variable-free) propositional logic to first-order logic. The key advantage of lifted inference
rules over propositionalization is that they make only those substitutions that are required to allow
particular inferences to proceed.
Lifted inference rules require finding substitutions that make different logical expressions look
identical. This process is called unification and is a key component of all first-order inference
algorithms. The UNIFY algorithm takes two sentences and returns a unifier for them if one exists:
UNIFY(p, q)=θ where SUBST(θ, p)= SUBST(θ, q)
Example:
p = Knows(John,x)
q = Knows(John, Jane)
Unify(p,q) = {x/Jane}
Simple example: query = Knows(John,x), i.e., who does John know?
P Q θ
Knows(John,x) Knows(John,Jane) {x/Jane}
Knows(John,x) Knows(y,OJ) {x/OJ,y/John}
Knows(John,x) Knows(y,Mother(y)) {y/John,x/Mother(John)}
Knows(John,x) Knows(x,OJ) {fail}

Last unification fails: only because x can’t take values John and OJ at the same time.
Problem is due to use of same variable x in both sentences
Simple solution: Standardizing apart eliminates overlap of variables, e.g., Knows(z,OJ)

10
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV

The unification algorithm:

The algorithm works by comparing the structures of the inputs, element by element. The substitution
θ that is the argument to UNIFY is built up along the way and is used to make sure that later
comparisons are consistent with bindings that were established earlier. In a compound expression
such as F(A,B), the OP field picks out the function symbol F and the ARGS field picks out the
argument list (A,B).

 Forward chaining
The basic idea of forward-chaining algorithm for propositional definite clauses is, start with the
atomic sentences in the knowledge base and apply Modus Ponens in the forward direction, adding
new atomic sentences, until no further inferences can be made.
First-order definite clauses
First-order definite clauses closely resemble propositional definite clauses: they are disjunctions of
literals of which exactly one is positive. A definite clause either is atomic or is an implication whose
antecedent is a conjunction of positive literals and whose consequent is a single positive literal. The
following are first-order definite clauses:
King(x) ∧ Greedy(x) ⇒ Evil(x).
King(John).
Greedy(y).
Unlike propositional literals, first-order literals can include variables, in which case those variables
are assumed to be universally quantified. (Typically, we omit universal quantifiers when writing
definite clauses.) Not every knowledge base can be converted into a set of definite clauses because of
the single-positive-literal restriction, but many can.

11
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV

Consider the following problem:


The law says that it is a crime for an American to sell weapons to hostile nations. The country
Nono, an enemy of America, has some missiles, and all of its missiles were sold to it by Colonel
West, who is American.
We will prove that West is a criminal. First, we will represent these facts as first-order definite
clauses.
1) it is a crime for an American to sell weapons to hostile nations:
American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)
2) Nono … has some missiles, i.e., x Owns(Nono,x)  Missile(x):
Owns(Nono,M1) and Missile(M1)
3) … all of its missiles were sold to it by Colonel West
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
4) Missiles are weapons:
Missile(x)  Weapon(x)
5) An enemy of America counts as "hostile―:
Enemy(x,America)  Hostile(x)
6) West, who is American …
American(West)
7) The country Nono, an enemy of America
Enemy(Nono,America)
Query: Criminal(West)?
Definite clauses  disjunctions of literals of which exactly one is positive.
Forward chaining algorithm:

Forward chaining proof:

12
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV

Properties of forward chaining:


 Sound and complete for first-order definite clauses
 Datalog = first-order definite clauses + no functions
 FC terminates for Datalog in finite number of iterations
 May not terminate in general if α is not entailed

 Backward chaining
Backward chaining is the logical process of inferring unknown truths from known conclusions by
moving backward from a solution to determine the initial conditions and rules. Backward chaining is
often applied in artificial intelligence (AI) and may be used along with its counterpart, forward
chaining.
In AI, backward chaining is used to find the conditions and rules by which a logical result or
conclusion was reached. An AI might utilize backward chaining to find information related to
conclusions or solutions in reverse engineering or game theory applications. Backward chaining is
used in automated theorem proving tools, inference engines, proof assistants and other artificial
intelligence applications.
Backward chaining algorithm

Backward chaining example

13
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV

Properties of backward chaining


 Depth-first recursive proof search: space is linear in size of proof
 Incomplete due to infinite loops
  fix by checking current goal against every goal on stack
 Inefficient due to repeated subgoals (both success and failure)
  fix using caching of previous results (extra space)
 Widely used for logic programming
 Resolution
KB |  equivalent to
The resolution algorithm tries to prove:
KB   unsatisfiable

• Generate all new sentences from KB and the query.


• One of two things can happen:
1. We find P  P which is unsatisfiable,
i.e. we can entail the query.
2. We find no contradiction: there is a model that satisfies the Sentence (non-trivial) and hence
we cannot entail the query. KB  

Steps for Resolution Theorem Proving (FOL):
1. Convert everything to CNF
2. Converting sentences to clausal form: Skolem constants and functions (Resolve, with
unification)
– Save bindings as you go!
3. If resolution is successful, proof succeeds
4. If there was a variable in the item to prove, return variable’s value from unification bindings

Step 1: Converting sentences to CNF


1. Eliminate all ↔ connectives
(P ↔ Q)  ((P  Q) ^ (Q  P))
2. Eliminate all  connectives
(P  Q)  (P  Q)
3. Reduce the scope of each negation symbol to a single predicate
P  P
(P  Q)  P  Q
(P  Q)  P  Q
(x)P  (x)P
(x)P  (x)P

14
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV

4. Standardize variables: rename all variables so that each quantifier has its own unique variable
name
Step2: Converting sentences to clausal form: Skolem constants and functions
Eliminate existential quantification by introducing Skolem constants/functions (x)P(x)  P(c)
c is a Skolem constant (a brand-new constant symbol that is not used in any other sentence)
(x)(y)P(x,y) becomes (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 brand-new
function name not occurring in any other sentence in the KB.
E.g., (x)(y)loves(x,y) becomes (x)loves(x,F(x))
In this case, F(x) specifies the person that x loves
E.g., x1 x2 x3 y P(… y …) becomes
x1 x2 x3 P(… FF(x1,x2,x3) …) (FF is a new name)
Converting sentences to clausal form
 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)  P(x)
 Put into conjunctive normal form (conjunction of disjunctions) using distributive and
associative laws
(P  Q)  R  (P  R)  (Q  R)
(P  Q)  R  (P  Q  R)
 Split conjuncts into separate clauses
 Standardize variables so each clause contains only variable names that do not occur in any
other clause
An example:
1. (x)(P(x)  ((y)(P(y)  P(F(x,y)))  (y)(Q(x,y)  P(y))))
2. Eliminate 
(x)(P(x)  ((y)(P(y)  P(F(x,y)))  (y)(Q(x,y)  P(y))))
3. Reduce scope of negation
(x)(P(x)  ((y)(P(y)  P(F(x,y))) (y)(Q(x,y)  P(y))))
4. Standardize variables

15
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV

(x)(P(x)  ((y)(P(y)  P(F(x,y))) (z)(Q(x,z)  P(z))))


5. Eliminate existential quantification
(x)(P(x) ((y)(P(y)  P(F(x,y))) (Q(x,G(x))  P(G(x)))))
6. Drop universal quantification symbols
(P(x)  ((P(y)  P(F(x,y))) (Q(x,G(x))  P(G(x)))))
7. Convert to conjunction of disjunctions
(P(x)  P(y)  P(F(x,y)))  (P(x)  Q(x,G(x))) 
(P(x)  P(G(x)))
8. Create separate clauses
P(x)  P(y)  P(F(x,y))
P(x)  Q(x,G(x))
P(x)  P(G(x))
9. Standardize variables
P(x)  P(y)  P(F(x,y))
P(z)  Q(z,G(z))
P(w)  P(G(w))
Note: Now that quantifiers are gone, we do need the upper/lower-case distinction
Example:
... it is a crime for an American to sell weapons to hostile nations:
American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)
Nono … has some missiles, i.e., x Owns(Nono,x)  Missile(x):
Owns(Nono,M1) and Missile(M1)
… all of its missiles were sold to it by Colonel West
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
Missiles are weapons:
Missile(x)  Weapon(x)
An enemy of America counts as "hostile―:
Enemy(x,America)  Hostile(x)
West, who is American …
American(West)
The country Nono, an enemy of America …
Enemy(Nono,America)

16
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV

Can be converted to CNF


Query: Criminal(West)?
Resolution proof:

Conjunctive normal form for first-order logic:


Original sentence:
Anyone who likes all animals is loved by someone:
x [y Animal(y)  Likes(x,y)]  [y Loves(y,x)]
1. Eliminate biconditionals and implications
x [y Animal(y)  Likess(x,y)]  [y Loves(y,x)]
2. Move  inwards:
Recall: x p ≡ x p,  x p ≡ x p
x [y (Animal(y)  Likes(x,y))]  [y Loves(y,x)]
x [y Animal(y)  Likes(x,y)]  [y Loves(y,x)]
x [y Animal(y)  Likes(x,y)]  [y Loves(y,x)]
Either there is some animal that x doesn’t like if that is not the case then someone loves x
3. Standardize variables: each quantifier should use a different one
x [y Animal(y)  Likes(x,y)]  [z Loves(z,x)]
4. Skolemize:
x [Animal(A)  Likes(x,A)]  Loves(B,x)

17
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV

Everybody fails to love a particular animal A or is loved by a particular person B


Animal(cat)
Likes(marry, cat)
Loves(john, marry)
Likes(cathy, cat)
Loves(Tom, cathy)
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)
(reason: animal y could be a different animal for each x.)
5. Drop universal quantifiers:
[Animal(F(x))  Loves(x,F(x))]  Loves(G(x),x)
(all remaining variables assumed to be universally quantified)
6. Distribute  over  :
[Animal(F(x))  Loves(G(x),x)]  [Loves(x,F(x))  Loves(G(x),x)]
Original sentence is now in CNF form – can apply same ideas to all sentences in KB to convert into
CNF
Also need to include negated query Then use resolution to attempt to derive the empty clause
which show that the query is entailed by the KB.
Skolemization and Quantifier Elimination
Problem: how can we use Horn clauses and apply unification with existential quantifiers?
 Not allowed by Prolog.
 Example.
 For all x. there is y. Loves(y,x).
 For all x. for all y. Loves(y,x) => Good(x).
 This entails (for all x. Good(x)) and Good(jack).
 Replace existential quantifiers by Skolem functions.
 For all x. Loves(f(x),x).
 For all x. for all y. Loves(y,x) => Good(x).
 This entails (for all x. Good(x)) and Good(jack).
 Sentences with [for all there is …] structure become [for all …].
 Can use unification of terms.

18
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV

Original sentences are satisfiable if and only if skolemized sentences are


Complex Skolemization Example
KB:
 Everyone who loves all animals is loved by someone.
 Anyone who kills animals is loved by no-one.
 Jack loves all animals.
 Either Curiosity or Jack killed the cat, who is named Tuna.
Query: Did Curiosity kill the cat?
Inference Procedure:
1. Express sentences in FOL.
2. Eliminate existential quantifiers.
3. Convert to CNF form and negated query.

After converting FOL to CNF:

 Basic FOL inference algorithm (satisfiability check).


1. Use Skolemization to eliminate quantifiers
1. Only universal quantifiers remain.
2. Convert to clausal form.
3. Use resolution + unification.

19
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV

Planning
• Planning means devising a plan of action to achieve one’s goals—is a critical part of AI, in
other words, Planning is the task of coming up with a sequence of actions that will achieve the
goal.
• The problem-solving agent of Module-II can find sequences of actions that result in a goal state.
But it deals with atomic representations of states and thus needs good domain-specific heuristics
to perform well.
• The hybrid propositional logical agent of Module-III can find plans without domain-specific
heuristics because it uses domain-independent heuristics based on the logical structure of the
problem. But it relies on ground (variable-free) propositional inference, which means that it may
be swamped when there are many actions and states. For example, in the wumpus world, the
simple action of moving a step forward had to be repeated for all four agent orientations, T time
steps, and n2 current locations.
• The planning researchers have settled on a factored representation— one in which a state of the
world is represented by a collection of variables.
• We use a language called PDDL, the Planning Domain Definition Language that allows us to
express all 4Tn2 actions with one action schema.
• PDDL describes the four things we need to define a search problem: the initial state, the actions
that are available in a state, the result of applying an action, and the goal test.
– Each state is represented as a conjunction of fluents that are ground, functionless atoms.
For example, Poor ∧ Unknown might represent the state of a hapless agent, and a state
in a package delivery problem might be At(Truck 1, Melbourne) ∧ At(Truck 2, Sydney).
– Actions are described by a set of action schemas that implicitly define the ACTIONS(s)
and RESULT(s, a) functions needed to do a problem-solving search.
– A set of ground (variable-free) actions can be represented by a single action schema.
The schema is a lifted representation—it lifts the level of reasoning from propositional
logic to a restricted subset of first-order logic.
– The result of executing action a in state s is defined as a state s which is represented by

20
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV
the set of fluents formed by starting with s, removing the fluents that appear as negative
literals in the action’s effects.
• Classical planning environments
– Fully observable, deterministic, finite, static (change only happens when the agent
acts), and discrete (in time, action, objects)
• A plan is complete if and only if every precondition is achieved.
• A precondition is achieved if and only if it is the effect if an earlier step and no possibly
intervening step undoes it.
Planning Systems do the following:
• Open up action and goal representation to allow selection.
• Divide-and-conquer by sub-goaling.
• Relax requirement for sequential construction of solutions.
The Language of Planning Problems
• Representation of states
– Decompose the world into logical conditions and represent a state as a conjunction of
positive literals
– Must be ground and function-free
– Examples:
• Poor  Unknown
• At( Plane1, CLE )  At( Plane2, LAS )
• At(x,y) or At( Father(Fred), CLE) (not allowed)

• Representation of goals
– A partially specified state
– Represented as a conjunction of ground literals
– Examples
• At( Plane1, LAS )
• Rich  Famous
– State s satisfies goal g if s contains all the atoms in g (and possibly others)
• Rich  Famous  Miserable satisfies Rich  Famous
• Representation of actions
– Specified in terms of the preconditions that must hold before it can be executed and
the effects that ensue when it is executed
– Action( Fly( p, from, to ))
• Precond: At(p, from)  Plane(p)  Airport(from)  Airport(to)
21
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV
• Effect: ¬ At(p, from)  At(p, to)
This is also known as an action schema.
Search vs. Planning
• Search
– States: program data structures
– Actions: program code
– Goal: program code
– Plan: sequence from S0
• Planning
– States: logical sentences
– Actions: preconditions and outcomes
– Goal: logical sentences (conjunction)
– Plan: constraints on actions
Example:
• Suppose our current state is:
– At(P1, CLE)  At(P2, LAS)  Plane(P1)  Plane(P2)  Airport(CLE)  Airport(LAS)
• This state satisfies the precondition
– At(p, from)  Plane(p)  Airport(from)  Airport(to)
• Using the substitution
– {p/P1, from/CLE, to/LAS}

• The following concrete action is applicable


– Fly( P1, CLE, LAS)

The planning problems:


Example: Air Cargo Transport
• Init(At(C1, CLE)  At(C2, LAS)  At(P1, CLE)  At(P2, LAS)  Cargo(C1)  Cargo(C2) 
Plane(P1)  Plane(P2)  Airport(CLE)  Airport(LAS))
• Goal( At(C1, LAS) At(C2, CLE))
1. Action( Load(c, p, a),
Precond: At(c, a)  At(p, a)  Cargo(c)  Plane(p)  Airport(a)
Effect: ¬ At(c, a)  In(c, p))
2. Action( Unload(c, p, a),
Precond: In(c, p)  At( p, a)  Cargo(c) Plane(p)  Airport(a)

22
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV

Effect: At(c, a)  ¬ In(c, p))


3. Action( Fly( p, from, to),
Precond: At(p, from)  Plane(p)  Airport(from)  Airport(to)
Effect: ¬ At(p, from)  At(p, to))
[ Load(C1, P1, CLE), Fly(P1, CLE, LAS), Unload( C1, P1, LAS),
Load(C2, P2, LAS), Fly(P2, LAS, CLE), Unload( C2, P2, CLE)]
Is it possible for a plane to fly to and from the same airport?
Example: The Spare Tire Problem
• Init( At( Flat, Axle)  At( Spare, Trunk))
• Goal( At(Spare, Axle))
1. Action( Remove( Spare, Trunk ),
Precond: At( Spare, Trunk )
Effect: ¬ At( Spare, Trunk)  At( Spare, Ground))
2. Action( Remove( Flat, Axle ),
Precond: At(Flat, Axle )
Effect: ¬ At(Flat, Axle)  At(Flat, Ground))
3. Action( PutOn( Spare, Axle ),
Precond: At( Spare, Ground )  ¬ At (Flat, Axle )
Effect: ¬ At( Spare, Ground )  At( Spare, Axle ))
Example: The Blocks World
• Init( On(A, Table)  On(B, Table)  On(C, Table)  Block(A)  Block(B)  Block(C) 
Clear(A)  Clear(B)  Clear(C))
• Goal( On(A, B)  On(B, C))
1. Action( Move( b, x, y ),
Precond: On(b,x)  Clear(b)  Clear(y)  Block(b)  (b ≠ x) (b≠y)  (x ≠ y)
Effect: On(b, y)  Clear(x)  ¬ On(b,x)  ¬ Clear(y))
2. Action( MoveToTable(b, x ),
Precond: On(b, x)  Clear(b)  Block(b)  (b ≠ x)
Effect: On(b, Table)  Clear(x)  ¬ On(b, x))
A plan for building a three block tower
• [Move(B, Table, C), Move(A, Table, B)]

23
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV

Planning with state space search:


ALGORITHMS FOR PLANNING AS STATE-SPACE SEARCH
One of the nice advantages of the declarative representation of action schemas is that we can also
search backward from the goal, looking for the initial state. Following Figure compares forward and
backward searches.

Two approaches to searching for a plan. Figure (a) Forward (progression) search through the space of
states, starting in the initial state and using the problem’s actions to search forward for a member of
the set of goal states. Figure (b) Backward (regression) search through sets of relevant states, starting
at the set of states representing the goal and using the inverse of the actions to search backward for
the initial state.

Forward (progression) state-space search


First, forward search is prone to exploring irrelevant actions. Consider the noble task of buying a
copy of AI: A Modern Approach from an online bookseller. Suppose there is an action schema
Buy(isbn) with effect Own(isbn). ISBNs are 10 digits, so this action schema represents 10 billion
ground actions. An uninformed forward-search algorithm would have to start enumerating these 10
billion actions to find one that leads to the goal.

Second, planning problems often have large state spaces. Consider an air cargo problem with 10
airports, where each airport has 5 planes and 20 pieces of cargo. The goal is to move all the cargo at
airport A to airport B. There is a simple solution to the problem: load the 20 pieces of cargo into one
of the planes at A, fly the plane to B, and unload the cargo. Finding the solution can be difficult
because the average branching factor is huge: each of the 50 planes can fly to 9 other airports, and
each of the 200 packages can be either unloaded (if it is loaded) or loaded into any plane at its airport
(if it is unloaded). So in any state there is a minimum of 450 actions (when all the packages are at
airports with no planes) and a maximum of 10,450 (when all packages and planes are at the same
airport). On average, let’s say there are about 2000 possible actions per state, so the search graph up
to the depth of the obvious solution has about 200041 nodes.

Clearly, even this relatively small problem instance is hopeless without an accurate heuristic.
Although many real-world applications of planning have relied on domain-specific heuristics, it turns
out that strong domain-independent heuristics can be derived automatically; that is what makes
forward search feasible.

24
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV
Backward (regression) relevant-states search
In regression search we start at the goal and apply the actions backward until we find a sequence of
steps that reaches the initial state. It is called relevant-states search because we only consider actions
that are relevant to the goal (or current state). As in belief-state search, there is a set of relevant states
to consider at each step, not just a single state.
We start with the goal, which is a conjunction of literals forming a description of a set of States. In
general, backward search works only when we know how to regress from a state description to the
predecessor state description. For example, it is hard to search backwards for a solution to the n-
queens problem because there is no easy way to describe the states that are one move away from the
goal. Happily, the PDDL representation was designed to make it easy to regress actions—if a domain
can be expressed in PDDL, then we can do regression search on it.
Heuristics for planning
Neither forward nor backward search is efficient without a good heuristic function. A heuristic function h(s)
estimates the distance from a state s to the goal and that if we can derive an admissible heuristic for
this distance—one that does not overestimate—then we can use A* search to find optimal solutions.
An admissible heuristic can be derived by defining a relaxed problem that is easier to solve. The
exact cost of a solution to this easier problem then becomes the heuristic for the original problem. By
definition, there is no way to analyze an atomic state, and thus it it requires some ingenuity by a
human analyst to define good domain-specific heuristics for search problems with atomic states.
Planning uses a factored representation for states and action schemas. That makes it possible to
define good domain-independent heuristics and for programs to automatically apply a good domain-
independent heuristic for a given problem.

Partial order planning:


• An alternative is to represent plans as partially ordered structures: a plan is a set of actions and a
set of constraints of the form Before(ai, aj) saying that one action occurs before another. In the
following bottom of Figure, we see a partially ordered plan that is a solution to the spare tire
problem.

• Actions are boxes and ordering constraints are arrows. Note that Remove(Spare, Trunk ) and

25
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV
Remove(Flat, Axle) can be done in either order as long as they are both completed before the
PutOn(Spare, Axle) action.
• Partially ordered plans are created by a search through the space of plans rather than through the
state space.
• We start with the empty plan consisting of just the initial state and the goal, with no actions in
between, as in the top of Figure. The search procedure then looks for a flaw in the plan, and
makes an addition to the plan to correct the flaw (or if no correction can be made, the search
backtracks and tries something else).
• A flaw is anything that keeps the partial plan from being a solution. For example, one flaw in
the empty plan is that no action achieves At(Spare, Axle). One way to correct the flaw is to
insert into the plan.
• Partially Ordered Plan
– A partially ordered collection of steps
• Start step has the initial state description and its effect
• Finish step has the goal description as its precondition
• Causal links from outcome of one step to precondition of another step
• Temporal ordering between pairs of steps
– An open condition is a precondition of a step not yet causally linked
– A plan is complete iff every precondition is achieved
– A precondition is achieved iff it is the effect if an earlier step and no possibly
intervening step undoes it
Fig(a): Partial order Plan Fig(b): Classical Planning

 Advantages and Disadvantages of Partial ordering Planning


o In the 1980s and 90s, partial-order planning was seen as the best way to handle planning
problems with independent subproblems—after all, it was the only approach that
explicitly represents independent branches of a plan.
o On the other hand, it has the disadvantage of not having an explicit representation of
states in the state-transition model. That makes some computations cumbersome.
Partial-order planning remains an important part of the field. For some specific tasks, such as
operations scheduling, partial-order planning with domain specific heuristics is the technology of
choice.

26
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV
POP Algorithm

27
GITAM School of Technology, Bengaluru
ECS 302: ARTIFICIAL INTELLIGENCE MODULE IV

Example: To Buy milk, banana, and a cordless drill

28
GITAM School of Technology, Bengaluru

You might also like