AI Chapter 4
AI Chapter 4
CoSc4142
Book: Artificial Intelligence, A Modern Approach (Russell & Norvig)
Enyew T.
1
Chapter Four
2
ΑΙ and KR
• A description of Artificial
Intelligence is:
– The study and development of
systems that demonstrate intelligent
behavior
5
Representation
• Is a relationship between two domains, where the first is meant to “stand
for” or take the place of the second.
– We might start with the sentences “John loves Mary” and “Mary is coming
to the party” and after a certain amount of manipulation produce the
sentence, “Someone John loves is coming to the party.”
– We would call this form of reasoning logical inference because the final
sentence represents a logical conclusion of the propositions represented
by the initial ones.
• Reasoning is a form of calculation, not unlike arithmetic, but over symbols
standing for propositions rather than numbers.
7
How can knowledge be represented ?
• There are mainly four ways of knowledge representation
– Logical Representation
– Semantic Representation
– Frame Representation
– Production Rules
Basic Idea of Logic
9
Knowledge-Based Agents
• Central component of a Knowledge-Based Agent is a Knowledge-Base
– A set of sentences in a formal language
• Sentences are expressed using a knowledge representation language
• Two generic functions:
– TELL - add new sentences (facts) to the KB
• “Tell it what it needs to know”
– ASK - query what is known from the KB
• “Ask what to do next”
10
Knowledge based agent
• Is composed of:
1. Knowledge base: Domain Specific
2. Inference Mechanism: Domain independent algorithm
The inference engine applies logical rules to the
knowledge base and deduced new knowledge.
11
Knowledge-Based Agents
• Declarative
– You can build a knowledge-based agent simply by “TELLing”
it what it needs to know
• Procedural
– Encode desired behaviours directly as program code
• Simple world example:
– Wumpus World
12
Logical Representation
• It is a language with some concrete rules which deals with
propositions & has no ambiguity in representation
• It consists of precisely defines Syntax and Semantics .
• each sentence can be translated into logics using syntax and
semantics.
– Syntax: defines well- formed sentence in the language
– Semantics: defines the truth or meaning of sentence in world
13
Logical Representation
• Can be explained by:
1. Propositional logic
2. Predicate logic
14
Propositional Logic (PL)
15
Logical connectives
Logical connectives are used to connect two simpler propositions or representing a sentence logically.
1. Negation: A sentence such as ¬ P is called negation of P. A literal can be either Positive literal or negative literal.
2. 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.
3. 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.
4. 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
5. 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.
16
…continued
• Truth Table
• E.g. • Conditions
P – It is hot If it is humid, then it is hot QP
Q – It is humid If it is hot and humid then it is not raining (P Ʌ Q) ¬R
R – It is raining
17
WUMPUS World
• Performance Measure
PEAS description of Wumpus world
19
Exploring the Wumpus World
2. [1,1] The first percept is [none, none,none,none,none], Move to safe cell e.g. 2,1
3. [2,1] Breeze indicates that there is a pit in [2,2] or [3,1] Return to [1,1] to try next safe cell 20
…
23
First Order Predicate Logic
24
…continued
• As a natural language, first-order logic also has two
main parts:
– Syntax
– Semantics
• The syntax of FOL determines which collection of
symbols is a logical expression in first-order logic.
• The basic syntactic elements of FOL are symbols.
25
First Order Logic
• More expressive logic than propositional
• Constants are objects: john, apples
• Predicates are properties and relations:
– likes(john, apples)
• Functions transform objects:
– likes(john, fruit_of(apple_tree))
• Variables represent any object: likes(X, apples)
• Quantifiers qualify values of variables
– True for all objects (Universal): X. likes(X, apples)
– Exists at least one object (Existential): X. likes(X, apples)
26
…
Constant 1, 2, A, John,
Addisababa, cat,....
Variables x, y, z, a, b,....
29
…
• 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.
– Example
30
Quantifiers in First-order logic:
• A quantifier is a language element which generates quantification, and
• quantification specifies the quantity of specimen in the universe of discourse.
• These are the symbols that permit to determine or identify the range and scope
of the variable in the logical expression.
• There are two types of quantifier:
– Universal Quantifier, (for all, everyone, everything)
– Existential quantifier, (for some, at least one).
31
Quantifiers in First-order logic:
• Universal quantifier
– is a symbol of logical representation, which specifies that the statement within its
range is true for everything or every instance of a particular thing.
– is represented by a symbol ∀, which resembles an inverted A.
– In universal quantifier we use implication " ⇒ "
– If x is a variable, then ∀x is read as:
• For all x
• For each x
• For every x.
– Example: All man drink coffee.
• Let a variable x which refers to a man so all x can be represented in: ∀x man(x) → drink (x, coffee).
• It will be read as: There are all x where x is a man who drink coffee.
32
Quantifiers in First-order logic:
• Existential quantifiers
– are the type of quantifiers, which express that the statement within its scope is
true for at least one instance of something.
– It is denoted by the logical operator ∃, which resembles as inverted E.
– In Existential quantifier we always use AND or Conjunction symbol (∧).
– If x is a variable, then existential quantifier will be ∃x or ∃(x). And it will be
read as:
• There exists a 'x.'
• For some 'x.'
• For at least one 'x.‘
– Example: Some boys are intelligent.
• ∃x: boys(x) ∧ intelligent(x)
• It will be read as: There is some x where x is a boy who is intelligent. 33
Some Examples of FOL using quantifier:
– All birds fly.
the predicate is "fly(bird)."
And since there are all birds who fly so it will be represented as follows.
∀x bird(x) →fly(x).
– Every man respects his parent.
the predicate is "respect(x, y)," where x=man, and y= parent.
Since there is every man so will use ∀, and it will be represented as follows:
∀x man(x) → respects (x, parent).
– Some boys play football.
the predicate is "play(x, y)," where x= boys, and y= game. Since there are some boys so we will use ∃,
and it will be represented as:
∃x boys(x) ∧ play(x, football).
– Not all students like both Mathematics and Science.
the predicate is "like(x, y)," where x= student, and y= subject.
Since there are not all students, so we will use ∀ with negation, so following representation for this:
¬∀ (x) [ student(x) → like(x, Mathematics) ∧ like(x, Science)]. 34
Inference in FOL
• Inference in FOL is used to deduce new facts or sentences from existing sentences
Terminologies:
• Substitution:
– is a fundamental operation performed on terms and formulas.
– It occurs in all inference systems in first-order logic.
– The substitution is complex in the presence of quantifiers in FOL.
– If we write F[a/x], so it refers to substitute a constant "a" in place of variable "x".
• Equality:
– FOL does not only use predicate and terms for making atomic sentences but also uses another way, which
is equality in FOL.
– For this, we can use equality symbols which specify that the two terms refer to the same object.
– Example: Brother (John) = Smith.
• As in the above example, the object referred by the Brother (John) is similar to the object referred by Smith.
• The equality symbol can also be used with negation to represent that two terms are not the same objects.
– Example: ¬ (x=y) which is equivalent to x ≠y.
35
FOL inference rules for quantifier:
• basic inference rules in FOL are:
– Universal Generalization
– Universal Instantiation
– Existential Instantiation
– Existential introduction
36
…continued
• Universal Generalization:
– is a valid inference rule which states that if premise P(c) is true for any
arbitrary element c in the universe of discourse, then we can have a
conclusion as ∀ x P(x).
– It can be represented as:
– This rule can be used if we want to show that every element has a
similar property.
– Example:
• Let's represent, P(c): "A byte contains 8 bits", so for ∀ x P(x) "All bytes contain 8
bits.", it will also be true.
37
…continued
• Universal Instantiation:
– is also called as universal elimination or UI is a valid inference rule.
– It can be applied multiple times to add new sentences.
– The new KB is logically equivalent to the previous KB.
– As per UI, we can infer any sentence obtained by substituting a ground term
for the variable.
– The UI rule state that we can infer any sentence P(c) by substituting a ground
term c (a constant within domain x) from ∀ x P(x) for any object in the universe
of discourse.
– It can be represented as:
– Example:1.
• IF "Every person like ice-cream"=> ∀x P(x) so we can infer that, "John likes ice-cream" => P(c) 38
…continued
• Existential Instantiation:
– is also called as Existential Elimination, which is a valid inference rule in FOL.
– It can be applied only once to replace the existential sentence.
– The new KB is not logically equivalent to old KB, but it will be satisfiable if old KB was satisfiable.
– This rule states that one can infer P(c) from the formula given in the form of ∃x P(x) for a new
constant symbol c.
– The restriction with this rule is that c used in the rule must be a new term for which P(c ) is true.
– It can be represented as:
– Example:
• From the given sentence: ∃x Crown(x) ∧ OnHead(x, John),
– So we can infer: Crown(K) ∧ OnHead( K, John), as long as K does not appear in the knowledge base.
– The above used K is a constant symbol, which is called Skolem constant.
– The Existential instantiation is a special case of Skolemization process.
39
…continued
• Existential introduction
– An existential introduction is also known as an existential generalization, which is a valid
inference rule in first-order logic.
– This rule states that if there is some element c in the universe of discourse which has a property
P, then we can infer that there exists something in the universe which has the property P.
– It can be represented as:
– Example: Let's say that, “John got good marks in English."
• "Therefore, someone got good marks in English."
40
Generalized Modus Ponens Rule:
• Modus ponens.
• Generalized Modus Ponens.
41