Unit 3 - Predicate Logic-1

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 70

Knowledge Representation

• Think about knowledge, rather than data in AI


• Facts
• Procedures
• Meaning

• Cannot have intelligence without knowledge
• Always
– been very important in AI

AIML 1
Knowledge Representation

• Choosing the wrong representation


• Could lead to a project failing
• Still a lot of work done on representation issues

AIML 2
Representations for Problem solving
techniques
• For certain problem solving techniques

• The “best” representation has already been worked out

• Often it is an obvious requirement of the technique

• Or a requirement of the programming language (e.g.,


Prolog)

AIML 3
Representations for Problem solving
techniques
• Examples:

• First order theorem proving (first order logic)

• Inductive logic programming (logic programs) Neural


networks learning (neural networks)

• But what if you have a new project?

• What kind of general representations schemes are there?

AIML 4
Four General Representation Types

• Logical Representations

• Semantic Networks

• Production Rules

• Frames

AIML 5
Logical Representations
What is a Logic?
• Lay down some concrete communication rules
• In order to give information to agents, and get info
• Without errors in communication (or at least, fewer)
• Think of a logic as a language
• Many ways to translate from one language to another

AIML 6
Logical Representations
Expressiveness
• How much of natural language (e.g., English)
• We are able to translate into the logical language
• Not to be confused with logical reasoning
• “Sherlock Holmes used pure logic to solve that…”
• This is a process, not a language

AIML 7
Outline
• First Order Predicate Logic (FOPL)
• Limitations of Propositional Logic
• Syntax of FOPL
• Translating English to FOPL
• Translate into predicate logic
• Solution
• Clausal Form
• Equivalent Logical Expressions

AIML 8
First Order Predicate Logic (FOPL)
• FOPL was developed to extend the expressiveness
of Propositional logic.
• Propositional logic works fine in situations where the
result is either true or false. However, there are many
real life situations that cannot be treated this way.
• Predicate logic is the area of logic that deals with

predicates and quantifiers

AIML 9
First Order Predicate Logic (FOPL)
• Predicate – refers to a property that the subject of
a statement can have

E.G. “x is greater than 3”

x -> is the subject and

“is greater than 3” -> is the predicate

AIML 10
Limitations of Propositional Logic
• The propositional logic has its limitations that you cannot
deal properly with general statements of the form
• “All men are mortal”

• You can not derive from the conjunction of this and


“Socrates is a man” that “Socrates is mortal”

AIML 11
Limitations of Propositional Logic
Example:
• If All men are mortal = P

• Socrates is a Man = Q

• Socrates is mortal = R

• Then (P & Q) -> R is not valid

AIML 12
S. No. Predicate logic Propositional logic
1. Predicate logic is a A preposition is a declarative
generalization of propositional statement that’s either TRUE or
logic that allows us to express FALSE (but not both).
and infer arguments in infinite
models.
2. Predicate logic (also called Propositional logic is an
predicate calculus and first-order axiomatization of Boolean logic.
logic) is an extension of Propositional logic is decidable,
propositional logic to formulas for example by the method of
involving terms and predicates. truth table.
The full predicate logic is
undecidable
3. Predicate logic have variables Propositional logic has
variables. Parameters are all
constant.
4. A predicate is a logical statement Propositional logic deals solely
that depends on one or more with propositions and logical
variables (not necessarily connectives.
Boolean variables)

AIML 13
S. No. Predicate logic Propositional logic
5. Predicate logic there are objects, Proposition logic is represented in
properties, functions (relations) terms of Boolean variables and
are involved. logical connectives.
6. In predicate logic, we symbolize In propositional logic, we use
subject and predicate separately. letters to symbolize entire
Logicians often use lowercase propositions. Propositions are
letters to symbolize subjects (or statements of the form “x is y”
objects) and upper case letter to where x is a subject and y is a
symbolize predicates. predicate.
7. Predicate logic uses quantifies Prepositional logic has not
such as universal quantifier quantifiers.
(“ ”), the existential quantifier
(“ ”).
8. Example Example
Everything is a green as “ x Everythingis a green as
Green(x)” or “G” or
“Something is blue as “ x “Something is blue as “B(x)”.
Blue(x)”.

AIML 14
Syntax of FOPL

• Connectives
• Quantifiers
• Constants
• Variables
• Predicates
• Functions

AIML 15
Syntax of FOPL
• Connectives: There are five connective symbols
–~ : not or negation
–& : and or conjuction
–v : or or inclusive disjunction
– -> : implication
– <-> : equivalence or if and only if

AIML 16
Syntax of FOPL

• Quantifiers: There are two quantifier symbols are


– : existential quantification
 Example: x means there exist x
– : universal quantification
 Example: x means for all x

AIML 17
Syntax of FOPL...
• Constants: constants are fixed-values terms that belong
to a given domain of discourse. They are denoted by
numbers, words and small letter.
• Variables: variables are terms that can assume different
values over a given domain.

18
AIML
Syntax of FOPL...

• redicates: a predicate is defined as a relation that


binds two atoms together. Ex: Rabbit likes carrots, is
represented as
 LIKES(rabit, carrots)
Here LIKES is a predicate that links two
atoms “rabbit“ and “carrots“

AIML 19
Syntax of FOPL...

• Functions: it is also possible to have a function as an


argument, e.g. “Ravi‘s father is Rani's father“ is
represented as-
– FATHER(father(Ravi), Rani)
– Here, FATHER is a predicate and father(Ravi)
is a function to indicate Ravi's father.

AIML 20
Syntax of FOPL...
• Constants, variables, and functions are referred to as terms.
• Predicates are referred to as atomic formulas or atoms.
• When we want to refer to an atom or its negation, we often
use the word literal.
• In addition to above symbols, left and right parentheses,
square brackets, braces, and the period are used for
punctuation in symbolic representation.

AIML 21
Translating English to FOPL
1. Bhaskar likes aeroplanes.
6. Rose is red.
2. Ravi’s father is rani‘s
7. John owns gold
father.
8. Ram is taller than mohan
3. Plato is a man
9. My name is khan
4. Ram likes mango.
10. Apple is fruit.
5. Sima is a girl.

AIML 22
Translating English to FOPL
11. Ram is male.
12. Tuna is fish. 18. All kings are person.

13. Dashrath is ram‟s father. 19. Nobody loves john.

14. Kush is son of ram. 20. Every one has a father.

15. Kaushaliya is wife of Dashrath.


16. Clinton is tall.
17. There is a white alligator.

AIML 23
Translating English to FOPL
1. Bhaskar likes aeroplanes. 1. Likes (bhaskar, aeroplanes).
2. Ravi‟s father is rani‟s father. 2. Father(father(ravi), rani )).
3. Plato is a man. 3. Man (plato).
4. Ram likes mango. 4. Likes(ram, mango).
5. Sima is a girl. 5. Girl(sima).
6. Rose is red. 6. Red (rose).
7. John owns gold. 7. Owns(john, gold).
8. Ram is taller than mohan. 8. Taller(ram, mohan).
9. My name is khan. 9. Name (khan) or Name(my, khan)
10. Apple is fruit. 10. Fruit(apple).

AIML 24
Translating English to FOPL
11. Ram is male. 11. Male (ram).
12. Tuna is fish. 12. Fish (tuna).
13. Dashrath is ram‟s father. 13. Father (dashrath, ram).
14. Kush is son of ram. 14. Son(kush, ram).
15. Kaushaliya is wife of Dashrath. 15. Wife(kaushaliya, dashrath).
16. Clinton is tall. 16. Tall(clinton).
17. Alligator (white).
17. There is a white alligator.
18. x: Kings(x) ->
18. All kings are person. Person(x).
19. Nobody loves john. 19. x: ¬Loves(x, john).
20. Every one has a father. 20. x: y: Father(y,x)

AIML 25
Translate into predicate logic
1. Marcus was a man.
2. Marcus was a Pompeian.
3. All Pompeians 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 aren't loyal to.
8. Marcus tried to assassinate Caesar.
9. All men are people.

AIML 26
Solution
1. Marcus was a man.
 Man(Marcus).
2. Marcus was a Pompeian.
 Pompeian(marcus)
3. All Pompeian 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)

AIML 27
Solution
6. Everyone is loyal to someone.
x: y: LoyalTo(x,y)
7. People only try to assassinate rulers they aren't loyal to.
x: y: Person(x) ^ Ruler(y) ^ TryAssassinate(x,y) -> ¬LoyalTo(x,y)]
8. Marcus tried to assassinate Caesar.
TryAssassinate(Marcus, Caesar)

9. All men are people.


x: Men(x) -> People(x)

AIML 28
Translate into predicate logic

i. Hari likes all kind of food.

ii. Bananas are food.

iii. Apples are food.

iv. Anything anyone eats and isn‟t killed by food.

v. Hari eats everything ram eats.

AIML 29
Solution

i. x: Food(x) -> Likes(hari, x).

ii. Food(bananas) .

iii. Food(apples) .

iv. x: y: Eats(y,x) ^ ¬Killedby(y,x) -> Food(x)

v. x: eats(ram, x) -> eats(hari, x) .

AIML 30
Translating English to FOPL
1. Every gardener likes the sun.

2. Not Every gardener likes the sun.

3. You can fool some of the people all of the time.

4. You can fool all of the people some of the time.

5. You can fool all of the people at same time.

6. You can not fool all of the people all of the time.

7. Everyone is younger than his father.

AIML 31
Solution
1. ( x): gardener(x) => likes(x, Sun)
2. ~(( x) :gardener(x) => likes(x, Sun))
3. ( x):( t) :person(x) ^ time(t) => can-be-fooled(x, t)
4. ( x):( t) :person(x) ^ time(t) => can-be-fooled(x ,t)
5. ( t):( x) :person(x) ^ time(t) => can-be-fooled(x, t)
6. ~(( x):( t): person(x) ^ time(t) => can-be-fooled(x, t))
7. ( x) :person(x) => younger(x, father(x))

AIML 32
Translating English to FOPL
1. All purple mushrooms are poisonous.
2. No purple mushroom is poisonous.
3. There are exactly two purple mushrooms.
4. Clinton is not tall.
5. X is above Y if X is 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.
6. no one likes everyone

AIML 33
Solution
1. ( x): (mushroom(x) ^ purple(x)) => poisonous(x)
2. ~( x): purple(x) ^ mushroom(x) ^ poisonous(x)
( x): (mushroom(x) ^ purple(x)) => ~poisonous(x)
3. ( x):( y): mushroom(x) ^ purple(x) ^ mushroom(y)
^ purple(y) ^ ~(x=y)
4. ~tall(Clinton)
5. ( z) :(mushroom(z) ^ purple(z)) => ((x=z) v (y=z))
( x):( y): above(x,y) <=> (on(x,y) v ( z) (on(x,z) ^
above(z,y)))
• 6. ~ ( x):( y):likes(x,y) or ( x):( y):~likes(x,y)

AIML 34
Convert it into clausal form

i. x: Food(x) -> Likes(hari, x).

ii. Food(bananas) .

iii. Food(apples) .

iv. x: y: Eats(y,x) ^ ¬Killedby(y,x) -> Food(x)

v. x: Eats(ram, x) -> Eats(hari, x) .

AIML

35
Convert it into FOPL
i. All lectures are determined.
x: Lecturer(x) -> Determined(x)
ii. Any one who is determined and intelligent will give good service.
x: Determined(x) ^ Intelligent(x) -> Givegoodservice(x)]
Mary is an intelligent lecturer.
Lecturer(mary)

iii. Intelligent(mary) Mary is an intelligent lecturer.


Lecturer(mary)
Intelligent(mary)

AIML 36
Example of FOPL
1. Marcus was a man. - Man(Marcus).
2. Marcus was a Pompeian. - Pompeian(marcus)
3. All Pompeian 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)

AIML

37
Example of FOPL
6. Everyone is loyal to someone.
x: y: LoyalTo(x,y)
7. People only try to assassinate rulers they aren't loyal to.
x: y: Person(x) ^ Ruler(y) ^ TryAssassinate(x,y) -> ¬LoyalTo(x,y)]
8. Marcus tried to assassinate Caesar.
TryAssassinate(Marcus,Caesar)
9. All men are people.
x: Men(x) -> People(x)
AIML

38
Unification

AIML

39
Unification
• Any substitution that makes two or more expression equal

is called a unifier for the expression.

• Two formulas unify if they can be made identical.

• A unification is a function that assigns bindings to


variables.

• A binding is either a constant, a functional expression or

another variable.
AIML

40
Unification process
• 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
tryassassinate (Marcus, Caesar)
hate(Marcus, Caesar)
cannot be unified.
AIML

41
Unification process
• 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.
The following are some fundamental requirements for
unification:
• Atoms or expressions with various predicate symbols can
never be united.
• Both phrases must have the same number of arguments.
AIML

• If two comparable variables appear in the same


expression, unification will fail. 42
Example
P(x, x) P(A,A) {x/A}
P(x, x) P(A,B) fail
P(x, y) P(A,B) {x/A, y/B}
P(x, y) P(A,A) fail
P(x, y) P(A, z) {x/A, y/z}
P(f(x),y) P(f(A),B) {x/A, y/B}
P(x, y) P(f(x),B) fail
P(x, y) P(z, f(z)) {x/z, y/f(z)}
AIML

43
Unification algorithm
• Unify(L1, L2) returns 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 procedure failed.
• The final substitution produced by the unification process will
be used by the resolution procedure.
AIML

44
Unification algorithm
Algorithm: Unify(L1, L2)
I. 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}.
AIML 45
Unification algorithm
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: = APPENDP(S,SUBST)
6. Return SUBST.

AIML 46
Solve
•(Unification) For each pair of atomic sentences,
give the most general unifier if it exists, otherwise
say “fail”:
a. R(A, x), R(y, z)
b. P(A, B, B), P(x, y, z)
c. Q(y, G(A, B)), Q(G(x,x), y)
d. Older(Father(y), y), Older(Father(x), John)
e. Knows(Father(y),y), Knows(x,x)
AIML

47
Solution
• (Unification) For each pair of atomic sentences, give the most
general unifier if it exists, otherwise say “fail”:
a. R(A, x), R(y, z) - y/A, x/z
b. P(A, B, B), P(x, y, z) - x/A, y/B, z/B
c. Q(y, G(A, B)), Q(G(x,x), y)- fail
d. Older(Father(y),y), Older(Father(x),john) - x/y, y/John
e. Knows(Father(y),y), Knows(x,x) - fail
AIML

48
Outline

• Introduction to the Expert System


• Forward Chaining
• Backward Chaining

AIML 49
Introduction to the Expert System

• Backward and forward chaining are methods of


reasoning that exist in the Expert System Domain of
artificial intelligence. These techniques are used in
expert systems such as MYCIN and DENDRAL to
generate solutions to real life problems.

AIML 50
Introduction to the Expert System

• An expert system is a computer application that uses


rules, approaches, and facts to provide solutions to
complex problems. Examples of expert systems include
MYCIN and DENDRAL. MYCIN uses the backward
chaining technique to diagnose bacterial infections.
DENDRAL employs forward chaining to establish the
structure of chemicals.

AIML 51
Introduction to the Expert System
• There are three components in an expert system: user
interface, inference engine, and knowledge base. The user
interface enables users of the system to interact with the
expert system. High-quality and domain-specific knowledge is
stored in the knowledge base.
• Backward and forward chaining stem from the inference
engine component. This is a component in which logical rules
are applied to the knowledge base to get new information or
make a decision.
• The backward and forward chaining techniques are used by
the inference engine as strategies for proposing solutions or
deducing information in the expert system.
AIML 52
Introduction to the Expert System

AIML 53
Forward Chaining

• Forward chaining is a method of reasoning in artificial


intelligence in which inference rules are applied to
existing data to extract additional data until an endpoint
(goal) is achieved.

• In this type of chaining, the inference engine starts by


evaluating existing facts, derivations, and conditions
before deducing new information. An endpoint (goal) is
achieved through the manipulation of knowledge that
exists in the knowledge base.

AIML 54
Forward Chaining

• Forward chaining can be used in planning, monitoring,


controlling, and interpreting applications.
AIML 55
Forward Chaining

Properties of forward chaining

• The process uses a bottom-up approach (bottom to top).


• It starts from an initial state and uses facts to make a
conclusion.
• This approach is data-driven.
• It’s employed in expert systems and production rule
system.

AIML 56
Forward Chaining
Examples of forward chaining
• A simple example of forward chaining can be explained
in the following sequence.
A
A->B
B
• A is the starting point.
• A->B represents a fact.
• This fact is used to achieve a decision B.

• A practical example will go as follows;


• Tom is running (A)
• If a person is running, he will sweat (A->B)
• Therefore, Tom is sweating. (B)
AIML 57
Forward Chaining
• A DENDRAL expert system is a good example of how
forward chaining is used in artificial intelligence.
DENDRAL is used in the prediction of the molecular
structure of substances.
• Deducing the chemical structure starts by finding the
number of atoms in every molecule. The mass spectrum
of the sample is then used to establish the arrangement
of the atoms. We can summarize these steps as follows.
• The chemical formula is determined ( the number of
atoms in every molecule).
• The spectrum machine is used to form mass
spectrums of the sample.
• The isomer and structure of the chemical are
identified.

AIML 58
Forward Chaining
• In this example, the identification of the chemical
structure is the endpoint. In the DENDRAL expert
system, a generate and test technique is employed.
• There are two elements in the generator: a synthesiser
and structural enumerator.
• The synthesiser plays the role of producing the mass
spectrum.
• The structural enumerator identifies the structure of
substances and prevents redundancy in the generator.

AIML 59
Forward Chaining
Advantages
• It can be used to draw multiple conclusions.
• It provides a good basis for arriving at conclusions.
• It’s more flexible than backward chaining because it does
not have a limitation on the data derived from it.

Disadvantages
• The process of forward chaining may be time-
consuming. It may take a lot of time to eliminate and
synchronize available data.
• Unlike backward chaining, the explanation of facts or
observations for this type of chaining is not very clear.
The former uses a goal-driven method that arrives at
conclusions efficiently.
AIML 60
Backward chaining
• Backward chaining is a concept in artificial intelligence
that involves backtracking from the endpoint or goal to
steps that led to the endpoint. This type of chaining starts
from the goal and moves backward to comprehend the
steps that were taken to attain this goal.
• The backtracking process can also enable a person
establish logical steps that can be used to find other
important solutions.

AIML 61
Backward chaining

• Backward chaining can be used in debugging,


diagnostics, and prescription applications.

AIML 62
Backward chaining
Properties of backward chaining
• The process uses an top-down approach (top to bottom).
• It’s a goal-driven method of reasoning.
• The endpoint (goal) is subdivided into sub-goals to prove
the truth of facts.
• A backward chaining algorithm is employed in inference
engines, game theories, and complex database systems.
• The modus ponens inference rule is used as the basis
for the backward chaining process. This rule states that if
both the conditional statement (p->q) and the antecedent
(p) are true, then we can infer the subsequent (q).
AIML 63
Backward chaining
Example of backward chaining
• The information provided in the previous example
(forward chaining) can be used to provide a simple
explanation of backward chaining. Backward chaining
can be explained in the following sequence.
B
A->B
A
• B is the goal or endpoint, that is used as the starting
point for backward tracking. A is the initial state. A->B is a
fact that must be asserted to arrive at the endpoint B.
• A practical example of backward chaining will go as
follows:
• Tom is sweating (B).
• If a person is running, he will sweat (A->B).
• Tom is running (A). AIML 64
Backward chaining
• The MYCIN expert system is a real life example of how
backward chaining works. This is a system that’s used in
the diagnosis of bacterial infections. It also recommends
suitable treatments for this type of infections.

• The knowledge base of a MYCIN comprises many


antecedent-consequent rules, that enable the system to
recognize various causes of (bacterial) infections. This
system is suitable for patients who have a bacterial
infection, but don’t know the specific infection. The
system will gather information relating to symptoms and
history of the patient. It will then analyze this information
to establish the bacterial infection.

AIML 65
Backward chaining
A suitable sequence can be as follows:
• The patient has a bacterial infection.
• The patient is vomiting.
• He/she is also experiencing diarrhea and severe
stomach upset.
• Therefore, the patient has typhoid (salmonella bacterial
infection).
• The MYCIN expert system uses the information collected
from the patient to recommend suitable treatment.
• The recommended treatment corresponds to the
identified bacterial infection. In the case above, the
system may recommend the use of ciprofloxacin.

AIML 66
Backward chaining
Advantages
• The result is already known, which makes it easy to
deduce inferences.
• It’s a quicker method of reasoning than forward chaining
because the endpoint is available.
• In this type of chaining, correct solutions can be derived
effectively if pre-determined rules are met by the
inference engine.
Disadvantages
• The process of reasoning can only start if the endpoint is
known.
• It doesn’t deduce multiple solutions or answers.
• It only derives data that is needed, which makes it less
flexible than forward chaining.
AIML 67
Backward chaining
Forward chaining Backward chaining
1. When based on available data a Backward chaining starts from
decision is taken then the processthe goal and works backward to
is called as Forward chaining. determine what facts must be
asserted so that the goal can be
achieved.
2. It is a bottom-up approach. It is a top-down approach.
3. Forward chaining is also regarded Backward chaining is a goal-
as a data-driven inference driven strategy since it begins
strategy because it allows us to with the objective and divides it
attain our goal using the data we into sub-goals in order to extract
already have. the facts.
4. All of the available rules are Only a few required rules are
subjected to forward chaining tested via backward chaining.
testing.

AIML 68
Backward chaining
Forward chaining Backward chaining
5. Forward chaining is appropriate Backward chaining is a useful
for applications such as planning, technique for diagnosing,
monitoring, control, and prescribing, and debugging.
interpretation.
6. Forward chaining can lead to an The number of possible
unlimited number of different conclusions generated by
outcomes. backward chaining is finite.
7. It works in the forward direction. It works in the backward
direction.
8. The goal of forward chaining is to Backward chaining is only for
reach any conclusion. the data that is required.
9. It applies the Breadth-First It applies the Breadth-First
Strategy. Strategy.
10. Slow as it has to use all the rules. Slow as it has to use all the
Fast as it has to use only a few rules. Fast as it has to use
rules. only a few rules.

AIML 69
END

AIML 70

You might also like