Module 2 Notes _AI
Module 2 Notes _AI
➢ 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.
Example:
Sentence Truth value Proposition (Y/N)
✓ 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
Note: The propositions and connectives are the basic elements of propositional logic.
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)
▪ 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.
✓ 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))
✓ Note on Quantifiers
The facts described by these sentences can be represented as a set of wff’s in predicate logic as follows:
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)
✓ 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.
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.
✓ 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
¬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.
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: [ ]
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)
¬PV¬QVR ¬R
¬PV¬Q P
¬T V Q ¬Q
¬T T
✓ 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
Example:
p = Knows(John, x)
q = Knows(John, Jane)
Unify(p, q) = {x/Jane}
✓ 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.
✓ 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).
• 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
✓ In this form, the statement suggests a way of deducing that someone is educated. But when the
same statement is converted to clause form,
✓ 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
Now, consider to extract answer to question from this knowledge base and bind that to y.
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.
✓ 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.
✓ 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.
✓ 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.
➢ 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