AI Unit-3 ppt
AI Unit-3 ppt
AI Unit-3 ppt
o Knowledge-base
o Inference system.
Inference system
• Inference means deriving new sentences from old.
• Inference system allows us to add a new sentence to the knowledge
base.
• A sentence is a proposition about the world.
• Inference system applies logical rules to the KB to deduce new
information.
• An inference system works mainly in two rules which are given as:
• Forward chaining
• Backward chaining
A generic knowledge-based agent
• Inheritable knowledge
• All data must be stored into a hierarchy of classes.
• Inferential knowledge
• Inferential knowledge approach represents knowledge in the form of formal
logics.
• Example: 1. Marcus is a man. 2.All men are mortal
man(Marcus)
∀x = man (x) ----------> mortal (x)s
• Procedural knowledge
• Procedural knowledge approach uses small programs and codes which
describes how to do specific things, and how to proceed.
• In this approach, one important rule is used which is If-Then rule.
• In this knowledge, we can use various coding languages such as LISP
language and Prolog language.
Techniques of knowledge representation
• Frame Representation
• Production Rules
Logical Representation
• Logical representation is a language with some concrete rules which deals with propositions and
has no ambiguity in representation.
• Logical representation means drawing a conclusion based on various conditions.
• This representation lays down some important communication rules.
• It consists of precisely defined syntax and semantics which supports the sound inference.
• Each sentence can be translated into logics using syntax and semantics.
Syntax:
• Syntaxes are the rules which decide how we can construct legal sentences in the logic.
• It determines which symbol we can use in knowledge representation.
• How to write those symbols.
Semantics:
• Semantics are the rules by which we can interpret the sentence in the logic.
• Semantic also involves assigning a meaning to each sentence.
• Logical representation can be categorised into mainly two logics:
• Propositional Logics
• Predicate logics
Propositional logic in Artificial intelligence
• Propositional logic (PL) is the simplest form of logic where all the
statements are made by propositions.
• A proposition is a declarative statement which is either true or false.
• It is a technique of knowledge representation in logical and
mathematical form.
• Example:
• a) It is Sunday.
• b) The Sun rises from West (False proposition)
• c) 3+3= 7(False proposition)
• d) 5 is a prime number.
Following are some basic facts about propositional logic:
• Propositional logic is also called Boolean logic as it works on 0 and 1 / true
or false.
• In propositional logic, we use symbolic variables to represent the logic,
such A, B, C, P, Q.
• Propositional logic consists of an object, relations or function, and logical
connectives.
• These connectives are also called logical operators.
• Connectives can be said as a logical operator which connects two
sentences.
• A proposition formula which is always true is called tautology, and it is also
called a valid sentence.
• A proposition formula which is always false is called Contradiction.
• Statements which are questions, commands, or opinions are not
propositions such as "Where is Rohini", "How are you", "What is your
name", are not propositions.
Syntax of propositional logic:
• The syntax of propositional logic defines the allowable sentences for the
knowledge representation. There are two types of Propositions:
• Atomic Propositions
• Compound propositions
• Atomic Proposition are the simple propositions. It consists of a single
proposition symbol. These are the sentences which must be either true or
false.
• Example:
• a) 2+2 is 4, it is an atomic proposition as it is a true fact.
• b) "The Sun is cold" is also a proposition as it is a false fact.
• Compound proposition are constructed by combining simpler or atomic
propositions, using parenthesis and logical connectives.
• Example:
• a) "It is raining today, and street is wet."
• b) "Ankit is a doctor, and his clinic is in Mumbai."
Logical Connectives:
• We can create compound propositions with the help of logical connectives. There
are mainly five connectives, which are given as follows:
• Negation: A sentence such as ¬ P is called negation of P. A literal can be either
Positive literal or negative literal.
• Conjunction: A sentence which has ∧ connective such as, P ∧ Q is called a
conjunction.
• Example: Rohan is intelligent and hardworking. It can be written as,
P= Rohan is intelligent, Q= Rohan is hardworking. P∧ Q.
• Disjunction: A sentence which has ∨ connective, such as P ∨ Q. is called
disjunction, where P and Q are the propositions.
• Example: "Ritika is a doctor or Engineer",
Here P= Ritika is Doctor. Q= Ritika is Engineer so we can write it as P ∨ Q.
• Implication: A sentence such as P → Q, is called an implication. Implications are
also known as if-then rules. It can be represented as
If it is raining, then the street is wet.
Let P= It is raining, and Q= Street is wet, so it is represented as P → Q
• Biconditional: A sentence such as P⇔ Q is a Biconditional sentence, example If I
am breathing, then I am alive
P= I am breathing, Q= I am alive, it can be represented as P ⇔ Q.
Thank
You
Artificial Intelligence
Topic: Theory of First order Logic
by
Dr. Vikas Goel
Department of IT
KIET Group of Institutions
Predicate logic / First Order Logic (FOL)
o First-order logic is another way of knowledge representation in artificial intelligence. It
is an extension to propositional logic.
o FOL is sufficiently expressive to represent the natural language statements in a concise
way.
o First-order logic is also known as Predicate logic.
o First-order logic is a powerful language that develops information about the objects in
a more easy way and can also express the relationship between those objects.
o First-order logic (like natural language) does not only assume that the world
contains facts like propositional logic but also assumes the following things in
the world:
o Objects: A, B, people, numbers, colours, wars, theories, squares…….
o Relations: It can be unary relation such as: red, round, is adjacent, or n-any
relation such as: the sister of, brother of, has color, comes between
o Function: Father of, best friend, third inning of, end of, ......
o As a natural language, first-order logic also has two
main parts:
o Syntax
o Semantics
Basic Elements of First-order logic:
Constant 1, 2, A, John, Mumbai, cat,....
Variables x, y, z, a, b,....
Connectives ∧, ∨, ¬, ⇒, ⇔
Equality ==
Quantifier ∀, ∃
First Order Logic
First-order logic statements can be divided into two parts:
Subject: Subject is the main part of the statement.
Predicate: A predicate can be defined as a relation, which binds two atoms together in
a statement.
Consider the statement: "x is an integer.", it consists of two parts, the first part x is the
subject of the statement and second part "is an integer," is known as a predicate.
Atomic sentences:
o Atomic sentences are the most basic sentences of first-order logic. These sentences are
formed from a predicate symbol followed by a parenthesis with a sequence of terms.
o We can represent atomic sentences as Predicate (term1, term2, ......, term n). Integer(X)
p q θ
Knows(John,x) Knows(John,Jane) {x/Jane}
Algorithm
Examples
RESOLUTION
• Resolution yields a complete inference algorithm when coupled with
any complete search algorithm.
• Resolution makes use of the inference rules.
• Resolution performs deductive inference.
• Resolution uses proof by contradiction.
• One can perform Resolution from a Knowledge Base.
• A Knowledge Base is a collection of facts or one can even call it a
database with all facts.
ALGORITHM
Let f be a set of given statements and S is a statement to be proved.
• 1. Covert all the statements of F to clause form.
• 2. Negate S 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 or no progress can be
made or a predetermined amount of effort has been expended.
a. Select two clauses. Call them parent clauses.
b. Resolve them together. The resolvent will be the
disjunction of all of these literals of both clauses.
• If there is a pair of literals T1 and T2 such that one parent clause
contains T1 and the other contains T2 and if T1 and T2 are unifiable,
then neither T1 nor T2 should appear in the resolvent.
• Here T1 and T2 are called complimentary literals.
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.
Steps for Resolution
1. Conversion of facts into first-order logic.
2. Convert FOL statements into CNF
3. Negate the statement which needs to prove (proof by contradiction)
4. Draw resolution graph (unification).
• To better understand all the above steps, we will take an example in
which we will apply resolution.
• Example:
• Convert the following sentence into predicate logic and then prove "Was
Marcus loyal to Caesar? using resolution:
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 are not loyal to.
8. Marcus tried to assassinate Caesar.
• Step-1: Conversion of Facts into FOL
• 1. Marcus was a man. man(Marcus)
• 2. Marcus was a Pompeian. Pompeian(Marcus)
• 3. All Pompeians were Romans. ∀x: Pompeian(x) → Roman(x)
• 4. Caesar was a ruler. ruler(Caesar)
• 5. All Romans were either loyal to Caesar or hated him.
∀x: Roman(x) → loyalto(X. Caesar) V hate(x, Caesar)
• 6. Everyone is loyal to someone.
∀x : → y: Ioyalto(x,y)
• 7. People only try to assassinate rulers they are not loyal to.
∀ x : ∀ y : person(x) ∧ ruler(y) ∧ tryassassinate(x,y) → ¬ Ioyalto(x,y)
• 8. Marcus tried to assassinate Caesar.
tryassassinate (Marcus, Caesar)
• Additional: ∀x: man(x) → person(x)
∀x: rman(x) V person(x)
• 9. rman(x) V person(x)
• Step-2: Conversion of FOL into CNF
• Eliminate all implication (→) and rewrite
• Move negation (¬)inwards and rewrite
• Rename variables or standardize variables
• Eliminate existential instantiation quantifier by elimination
• Drop Universal quantifiers
CNF
• man(Marcus)
• Pompeian(Marcus)
• ¬ Pompeian(x1) V Roman(x1)
• ruler(Caesar)
• ¬ Roman(x2) V loyalto(x2, Caesar) V hate(x2, Caesar)
• loyalto(x3, S1(x3))
• ¬ person(x4) V ¬ruler(y1) V ¬Vtryassassinate(x4, y1) V ¬loyalto(x4, y1)
• tryassassinate(Marcus, Caesar)
• Step-3: Negate the statement to be proved
Forward Chaining
Backward Chaining
Examples
Inference engine
• The inference engine is the component of the intelligent system in
artificial intelligence,
• which applies logical rules to the knowledge base to infer new
information from known facts.
• The first inference engine was part of the expert system.
• Inference engine commonly proceeds in two modes, which are:
• Forward chaining
• Backward chaining
Forward Chaining
• Forward chaining is also known as a forward deduction or forward
reasoning method when using an inference engine.
• Forward chaining is a form of reasoning which start with atomic
sentences in the knowledge base and applies inference rules in the
forward direction to extract more data until a goal is reached.
• The Forward-chaining algorithm
• starts from known facts,
• triggers all rules whose premises are satisfied, and
• add their conclusion to the known facts.
•
Example:
• "As per the law, it is a crime for an American to sell weapons to
hostile nations. Country A, an enemy of America, has some missiles,
and all the missiles were sold to it by Robert, who is an American
citizen."
• Prove that "Robert is criminal."
• To solve the above problem, first, we will convert all the above facts
into first-order definite clauses, and then we will use a forward-
chaining algorithm to reach the goal.
Facts Conversion into FOL
• It is a crime for an American to sell weapons to hostile nations.
American (p) ∧ weapon(q) ∧ sells (p, q, r) ∧ hostile(r) → Criminal(p)
...(1)
• Country A has some missiles. ∃p Owns(A, p) ∧ Missile(p). It can be
written in two definite clauses by using Existential Instantiation,
introducing new Constant T1.
Owns(A, T1) ......(2)
Missile(T1) .......(3)
• All of the missiles were sold to country A by Robert.
∀p Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) ......(4)
• Missiles are weapons.
Missile(p) → Weapons (p) .......(5)
• Enemy of America is known as hostile.
Enemy(p, America) →Hostile(p) ........(6)
• Country A is an enemy of America.
Enemy (A, America) .........(7)
• Robert is American
American(Robert). ..........(8)
Forward chaining proof
Step-1:
• In the first step we will start with the known facts and will choose the
sentences which do not have implications
Criminal(Robert)
Step-2:
• At the second step, we will infer other facts form goal fact which
satisfies the rules.
• So as we can see in Rule-1, the goal predicate Criminal (Robert) is
present with substitution {Robert/P}.
• So we will add all the conjunctive facts below the first level and will
replace p with Robert.
• American (p) ∧ weapon(q) ∧ sells (p, q, r) ∧ hostile(r) → Criminal(p)
...(1)
Step-3:
• At step-3, we will extract further fact Missile(q) which infer from
Weapon(q), as it satisfies Rule-(5).
• Weapon (q) is also true with the substitution of a constant T1 at q.
• Missile(p) → Weapons (p) .......(5)
Step-4:
• At step-4, we can infer facts Missile(T1) and Owns(A, T1) form
Sells(Robert, T1, r) which satisfies the Rule- 4, with the substitution
of A in place of r. So these two statements are proved here.
• ∀p Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) ......(4)
Step-5:
• At step-5, we can infer the fact Enemy (A, America) from Hostile (A)
which satisfies Rule- 6.
• And hence all the statements are proved true using backward
chaining.
• Enemy(p, America) →Hostile(p) ........(6)
Thank
You