Chapter 4
Chapter 4
• Logical Agents
• Propositional Logic
• Predicate (First-Order)Logic
• Inference in First-Order Logic
• Knowledge Representation
• Knowledge Reasoning
• Knowledge-based Systems
2
Knowledge: What and Why?
Knowledge includes facts about the real world entities and the
relationship between them
Knowledge-based Systems (KBSs) are useless without the ability to
represent knowledge.
Why Knowledge is important ?
We are living in complex environment where there are:
Many actors, prosumers (A customer who customizes a purchase by
being involved in production choices), strong competitors, and high
turnover
It enables to:
Automate reasoning, Discover new facts, Deduce new facts that
follow from the KB, and Answer users queries
Make quality decisions - select courses of actions, etc.
• Hence, there is a need to represent knowledge to ease the
development of an intelligent system.
3
Knowledge-based Agent (KBA)
Agents can be seen as knowing about their world, and reasoning
about their possible courses of action.
KBA begins with some knowledge of the world and of its
actions.
It uses logical reasoning to maintain a description of the world as
new percepts arrive
Learn new facts/knowledge that are inferred and unseen by current
percepts
Deduce a course of actions that will achieve its goals
One can also design an autonomous agent that
learns from experience and construct knowledge with less human
interventions
4
Knowledge Engineering (KE)
KE is the process of building a knowledge base through extracting the
knowledge from the human expert.
It includes:
Extracting the knowledge from the human expert.
Choose knowledge representation formalism
Choose reasoning and problem solving strategy.
A knowledge engineer is someone who investigates a particular domain,
determines what concepts are important in that domain, and creates a
formal representation of the objects and relations in the domain.
A KE has to decide what objects and relations are worth representing, and
which relations hold among which objects
Knowledge Knowledge
acquisition Representation Knowledge
(Extract knowledge (choose KR Method & Base
of Human Expert) reasoning strategy)
5
The two main tasks of KE
Knowledge acquisition: The knowledge engineer interview the real
human experts to be educated about the domain and to elicit the
required knowledge, in a process called knowledge acquisition.
Other acquisition methods also exist
Knowledge Representation techniques such as logic are a powerful
tool for KR and reasoning. However, such techniques consist of only
the syntax, semantics and proof theory.
KR techniques do not offer any guidance as to what facts should be
expressed, nor what vocabulary should be used to express them
Knowledge base is used to store a set of facts and rules about the
domain expressed in a suitable representation language
Each individual representation are called sentences
Sentences are expressed in a (formal) knowledge representation (KR)
language
6
Knowledge Representation & Reasoning
Knowledge Representation (KR): express knowledge explicitly in a
computer-tractable way such that the agent can reason out.
Parts of KR language:
Syntax of a language: describes the possible configuration to form sentences.
E.g.: if x & y denote numbers, then x > y is a sentence about numbers
Semantics: determines the facts in the world to which the sentences refer. E.g.:
x > y is false when y is greater than or equal to x
Reasoning: is the process of constructing new sentences from
existing facts in the KB.
Proper reasoning ensures that the new configuration represent facts that actually
follow from the facts in the KB.
7
Logic as KR
A Logic is a formal language in which knowledge can be represented
such that conclusions can easily be drawn.
It is a declarative language to assert sentences and deduce from sentences.
Components of a formal logic include syntax, semantics, reasoning
and inference mechanism.
Syntax: what expressions/structures are allowed in the language. Describes
how to make sentences
E.g. mycar (red) is ok, but mycar(grey or green) is not.
Semantics: express what sentences mean, in terms of a mapping to real
world.
The meaning of a sentence is not intrinsic to that sentence. Semantics relate
sentences to reality.
E.g. mycar (red) means that my car is red.
10
Propositional logic (PL) sentences
A sentence is made by linking prepositional symbols together
using logical connectives.
There are atomic and complex sentences.
Atomic sentences consist of propositional symbol (e.g. P, Q, TRUE,
FALSE)
Complex sentences are combined by using connectives or parenthesis:
while S and T are atomic sentences, S T, (S T), (S T), (S T), and (S
T) are complex sentences.
Examples: Given the following sentences about the “weather
problem” convert them into PL sentences:
“It is humid.”: Q
“If it is humid, then it is hot” : Q P
“If it is hot and humid, then it is raining”:(P Q) R
11
A BNF(Backus-Naur form) grammar of
sentences in propositional logic
S := <Sentence> ;
"NOT" <Sentence> ;
12
Example
Convert the following English sentences to Propositional logic. Let:
A = Lectures are active
R = Text is readable
P = Yared will pass the exam
the lectures are not active: A
the lectures are active and the text is readable: AR
either the lectures are active or the text is readable: AVR
if the lectures are active, then the text is not readable: AR
the lectures are active if and only if the text is readable: AR
if the lectures are active, then if the text is not readable, Yared will
not pass the exam: A (R P )
13
Terminology
Valid sentence: A sentence is valid sentence or tautology if and
only if it is True under all possible interpretations in all possible
worlds.
Example: “It’s raining or it’s not raining.” (R R).
Satisfiable: A sentence is satisfiable if and only if there is some
interpretations in some world for which the sentence is True.
Example: “It is raining or it is humid”. R v Q, R
Unsatisfiable: A sentence is unsatisfiable (inconsistent sentence or
a self- contradiction) if and only if it is not satisfiable, i.e. a sentence
that is False under all interpretations. The world is never like what it
describes.
Example: “It’s raining and it's not raining.” R R
14
Terminology cont…
Entailment: mirrors the relation of one fact
following from another.
New sentences are generated that are necessarily true, given that
the old sentences are true.
KB entails α (KB |= α) if and only if the conclusion α is true in
every logically possible worlds in which all the premises in KB
are true.
Derivation:
KB |- Q, Q is derived from KB if there is a proof consisting of a
sequence of valid inference steps starting from the premises in
KB and resulting in Q
15
Inference rules
An inference rule is a conditional statement with two
parts namely; if clause and a then clause.
This rule is what gives expert systems the ability to find
solutions to diagnostic and prescriptive problems. An
example of an inference rule is:
If the image has two vertical lines and the lines are
connected at the top with a horizontal line, Then the
character is the Amharic ‘be’.
16
Inference rules cont…
An expert system's rule base is made up of many such inference rules.
They are entered as separate rules and it is the inference engine that
uses them together to draw conclusions.
Because each rule is a unit, rules may be deleted or added without
affecting other rules - though it should affect which conclusions are
reached. One advantage of inference rules over traditional
programming is that inference rules use reasoning which more
closely resembles human reasoning.
Thus, when a conclusion is drawn, it is possible to understand how
this conclusion was reached.
Furthermore, because the expert system uses knowledge in a form
similar to the that of the expert, it may be easier to retrieve this
information directly from the expert.
17
Proof: Inference Rules
Inference is used to create new sentences that logically follow
from a given set of sentences in the KB.
It captures patterns of inferences that occur over and over again.
Once a rule is established, it can be used to make inferences without
going through the tedious process of building truth tables
Given set of inference rules (I) and set of sentences (KB);
Inference is the process of applying successive inference rules
from I to KB, each rule inferring new facts and adding its
conclusion to KB
Example: Modus Ponens: { , } |-
There are different inference rules (including logical equivalence) that
can be used for proofing and reasoning purpose.
18
Logical equivalence
•Two sentences are logically equivalent iff they are true in same models
21
Two important properties of inference
Completeness: If KB |= Q then KB |- Q
A logic is complete if it is capable of proving all consequences that
can be represented in it.
If Q is entailed by a set of sentences in KB, then Q can be derived from KB
using inference rules.
Hence, inference produces all entailments, or all valid sentences can be
proved from the premises.
A set of inference rules is complete if every entailed sentences can be
obtained by applying some finite succession of these rules
Modus ponens alone is not complete. For example, what can we concluded
from the statement:
[A B & B] ? A (Modes Tolens)
[A B & B] ? A (Unit resolution)
[A B & BC]??? A C (Hypothetical Syllogism)
22
Two important properties of inference
Soundness: If KB |- Q then KB |= Q
A logic is sound if it preserves truth (i.e. if a set of premises are all
true, any conclusion drawn from those premises must also be true).
If Q is derived from a set of sentences in the KB using a given set of rules
of inference, then Q is entailed by KB.
Hence, inference produces only real entailments, or any sentence that
follows deductively from the premises is valid.
We can proof soundness by constructing the truth table.
An inference rule is sound if it generates only entailed sentences
All inference rules given on the previous table are sound
A rule is sound if its conclusion is true whenever the premise is true.
E.g. modus ponens: { , }
25
Solution
Let
C: The investigation continues.
B: New evidence is brought to light.
I: Several leading citizens are implicated.
S: The newspapers stop publicizing the case.
1. CB
2. BI
3. IS
4. (C S) (B C)
5. C
6. CI 1,2 (Hypothetical Syllogism)
7. CS 6,3 (Hypothetical Syllogism)
8. BC 7,4 (Modus Ponens)
9. B 8,5 (Modus Tollens)
26
Exercise
Let p stand for the proposition “I bought a lottery ticket” and
q for “I won the jackpot”.
Express the following as natural English sentences:
(a) ¬p
(b) p q
(c) p q
(d) p q
(e) ¬p ¬q
(f ) ¬p (p q)
27
Propositional logic is a weak language
PL cannot handle even a domain with small worlds. The
problem is that there are just too many propositions to handle
since it only has one representational device: the proposition
In PL, the world consists of just facts. It is hard to :
Identify individuals: E.g., Mary, 3
Describe properties of (or relations between) individuals.
E.g. Belete is taller than Tola
Generalize for a given universe.
E.g., all triangles have 3 sides
Example: Prove that “my dog Fido is Nice, given that “all dogs
are Nice.”
This requires to get at the structure and meanings of
statements (where first order logic (FOL) is useful).
28
First Order Logic
First-Order Logic (FOL) is expressive enough to concisely
represent any kind of situation that are expressed in
natural language.
FOL represents objects and relations between objects, variables,
and quantifiers in addition to propositions
Every elephant is gray:
x (elephant(x) → gray(x))
29
Syntax of FOL
Constants symbol
names (like Jonas, Yared, …), numbers (like 1, 2, … n), ...
Predicates:
Predicates used to relate one object with another. E.g. brother, >,...
Functions: Returns value (Sqrt, mother-of,...)
Variables: x, y, a, b,...
Important to increase generalization capability of KB
Connectives:
retains connectives used in PL (, , , , )
Quantifiers:
Quantifiers specify whether all or some objects satisfy properties or
relations between objects
Two standard quantifiers: Universal ( for all, for every) and
Existential ( there exists, some) 30
Universal quantification
Universal Quantifiers: makes statements about every object
<variables> <sentence>
Everyone at HU is smart:
x At(x,HU) Smart(x)
All cats are mammals:
x cat(x) mammal(x)
x sentence P is true iff P is true with x being each possible object in the given
universe
The above statement is equivalent to the conjunction
At(Jonas, HU) Smart(Jonas)
At(Rawad, HU) Smart(Rawad) ...
A common mistake to avoid
Typically, is the main connective with
Common mistake: the use of as the main connective with :
x At(x,HU) Smart(x) is true if “Everyone is at HU & everyone is smart”
31
Existential quantification
Makes statements about some objects in the universe
<variables> <sentence>
Someone at HU is smart:
x At(x,HU) Smart(x)
Spot has a sister who is a cat:
x sister(spot,x) cat(x)
x sentence P is true iff P is true with x being some possible objects
The above statement is equivalent to the disjunction
At(Jonas, HU) Smart(Jonas)
At(Alemu, HU) Smart(Alemu) …..
Common mistake to avoid
Typically, is the main connective with
Common mistake: using as the main connective with :
x At(x,HU) Smart(x) is true if there is anyone who is not at HU
32
Nested quantifiers
x,y parent(x,y) child(y,x)
for all x and y, if x is the parent of y then y is the child of x.
x y Loves(x,y)
There is a person who loves everyone in the given world
y x Loves(x,y)
Everyone in the given universe is loved by at least one person
Properties of quantifiers
x y is the same as y x
x y is the same as y x
x y is not the same as y x
Quantifier duality: each can be expressed using the other, using negation ()
x Likes(x,icecream) x Likes(x,icecream)
Everyone likes ice cream means that there is nobody who dislikes ice cream
x Likes(x,cake) x Likes(x,cake)
There is someone who likes cake means that not everybody dislikes cake 33
Sentence structure
In FOL the basic unit is a predicate (argument/terms) structure called
sentence to represent facts.
Terms refer to objects
Example: likes(muhe, chocolate); tall(fred)
Terms or arguments can be any of: Constant symbol, such as ‘muhe’,
variable symbol, such as X , functions, such as motherof(fred), father-of(
father-of( john))
A predicate is the one that says something about the subject.
E.g., There is a red book
Subject: color of the book, represented as: x book(x)red(x)
Predicate also refers to a particular relation between objects
Example: likes(X, richard)
friends(motherof(jonas), motherof(semu))
A predicate statement takes the value true or false
34
Sentences
Atomic sentences: formed from a predicate symbol followed by a parenthesized
list of terms
Atomic sentence = predicate (term1,...,termn)
Example: Brother(John, Richard)
Atomic sentences can have arguments that are complex terms (e.g. term = function
(term1,...,termn) )
Example: married( fatherof(Richard),motherof(John))
Complex sentences: complex sentences are made by combining atomic
sentences using connectives:
S, S1 S2, S1 S2, S1 S2, S1 S2,
Ex. likes(john, mary) tall(mary)
tall(john) handsome(john)
Sibling(John, Richard) Sibling(Richard, John)
Sentences can also be formed using quantifiers to indicate how to treat variables:
Universal quantifier: x lovely(x) - Everything is lovely.
Existential quantifier: x lovely(x) - Something is lovely.
35
Sentences
We can have several quantifiers together, e.g.,
x y loves(x, y)
x handsome(x) y loves(y, x)
Represent the following in FOL:
Everything in the garden is lovely x in(x, garden) lovely(x)
Everyone likes ice cream x likes(x, icecream)
Peter has some friends y friends(y, Peter)
John plays the piano or the violin
plays(john, piano) v plays(john, violin)
Some people like snakes -- x(person(x) Λ likes(x, snakes))
Winston did not write Hamlet – write( winston, hamlet)
Nobody wrote Hamlet – x write(x, hamlet)
Every city has a dogcatcher who has been bitten by every dog in
town x {city(x) y{dogcatcher(y, x) Λ z{[dog(z) Λ live- in(z, x)] bit(z, y)}}}
36
Semantics
There is a precise meaning to expressions in predicate logic.
Like in propositional logic, it is all about determining whether
something is true or false.
x P(x) means that P(x) must be true for every object x in the domain of
interest.
x P(x) means that P(x) must be true for at least one object x in the
domain of interest.
So if we have a domain of interest consisting of just two people, john and mary,
and we know that tall(mary) and tall(john) are true, we can say that x
tall(x) is true.
Atomic sentence is true if the relation referred by the predicate holds
b/n the objects referred by the arguments
brother(John, Richard)
The truth value of complex sentences depends on logical connectives
used older(John,30) younger(John,30)
37
Proof and inference
We can define inference rules allowing us to say that if
certain things are true, certain other things are sure to be
true,
E.g. All men are mortal
Aristotle is a man
using logical inferences we can deduce that: Aristotle is
mortal
x man(x) mortal(x)
man(Aristotle)
so we can conclude that: mortal(Aristotle)
This involves matching man(x) against man(Aristotle) and
binding the variable x to Aristotle.
38
Unification
Unification is an algorithm for determining the substitutions needed
to make two expressions match
Unification is a "pattern matching" procedure that takes two atomic
sentences as input, and returns the most general unifier, i.e., a
shortest length substitution list that makes the two literals match.
E.g: To make, say p(X, X) and p(Y, Z) match, subst(X/ Y) or subst(X/ Z)
Note: It is possible to substitute two variables with the same value, but
not the same variables with different values.
Example
Sentence 1 Sentence 2 Unifier
group(x, cat(x), dog(Bill)) group(Bill, cat(Bill), y) {x/Bill, y/dog(Bill)}
group(x, cat(x), dog(Bill)) group(Bill, cat(y), z) {x/Bill, y/Bill, z/dog(Bill)}
group(x, cat(x), dog(Jane)) group(Bill, cat(y), dog(y)) Failure
A variable can never be replaced by a term containing that variable. For example,
x/f(x) is illegal.
39
Inference rules
Rules for PL apply to FOL as well. For example,
Modus Ponens
And-Introduction
And-Elimination,
Resolution, etc.
40
Sound Inference Rules
Universal Elimination: If x P(x) is true, then P(c) is true, where c is a
constant in the domain of x.
Example: x eats(x, IceCream).
Using the substitution (x/Ben) we can infer eats(Ben, Icecream).
The variable symbol can be replaced by any constant symbol or function symbol.
Existential Introduction: If P(c) is true, then x P(x) is inferred.
Example: eats(John, IceCream) we can infer x eats(x, icecream).
All instances of the given constant symbol are replaced by the new variable
symbol.
Existential Elimination: From x P(x) infer P(c).
Example: x eats(Sol, x) infer eats(Sol, Cheese)
Note that the variable x is replaced by a brand new constant (like Cheese) that
does not occur in this or any other sentence in the KB
If x is within the scope of y it is replaced by new function f(y)
41
Sound Inference Rules
Example 1: What can we conclude from the following?
x tall(x) strong(x)
tall(john)
x strong(x) loves(mary, x)
42
Proofs
Sound inference: find α such that KB |= α
Proof process is a search, operators are inference rules
It requires the operation of a series of inference rule to come up with some
conclusion
Example:
Bob is a buffalo. Pat is a pig. Buffaloes outrun pigs
Conclude: Bob outruns Pat
1. Buffalo(Bob)
2. Pig(Pat)
3. x,y Buffalo(x) ^ Pig(y) → outrun(x,y)
4. Buffalo(Bob) ^ Pig(Pat) And Introduction (1, 2)
5. Buffalo(Bob) ^ Pig(Pat) → outrun (Bob, Pat)
Universal Elimination (3, {x/Bob,y/Pat})
6. outrun(Bob,Pat) Modus Ponens
43
Generalized Modus Ponens (GMP)
•Combines And-Introduction, Universal-Elimination, and Modus Ponens
• Given atomic sentences P1, P2, ..., PN, and implication sentence (Q1 ^ Q2 ^ ... ^
QN) R, where Q1, ..., QN and R are atomic sentences, derive new sentence
R. That is,
• from P(c), Q(c), and x (P(x) ^ Q(x) R(x)), derive R(c)
Example: Given Faster(Bob,Pat), Faster(Pat,Steve) and
Faster(x,y) ^ Faster(y,z) Faster(x,z);
by substituting {x/Bob, y/Pat, z/Steve}
we can infer in one step the new sentence: Faster(Bob, Steve)
•GMP is not complete for FOL. Natural deduction using GMP is possible
only for KBs containing Horn clauses.
• A Horn clause is a sentence of the form:
x (P1(x) ^ P2(x) ^ ... ^ Pn(x)) Q(x)
where there are zero or more Pi‘s
44
Inference Mechanisms
Inference is a means of interpretation of knowledge in the
KB to reason and give advise to users query.
There are two inference strategies to control and organize
the steps taken to solve problems:
Forward chaining: also called data-driven chaining
It starts with facts and rules in the KB and try to draw conclusions from
the data
Backward chaining: also called goal-driven chaining
It starts with possible solutions/goals and tries to gather information that
verifies the solution
45
Properties of Good KB
A KB should be clear, correct, expressive, concise, context-insensitive and effective.
The relations that matter should be defined, and the irrelevant details should be
suppressed
Separate the KB from inference procedure.
This allows the KE (creator of the KB) to focus on the content of the KB, and not
about how it will be used by the inference procedure
Define a generally applicable KB.
Every KB has two potential consumers: human readers and inference procedure
A common mistake is to choose predicate names that are meaningful to the human
readers, and then assume that the name is somehow meaningful to the inference
procedure as well
E.g. consider the sentence: BearOrVerySmallBrain(Lilly). Do you think the
Inference engine be able to infer from this sentence facts such as: Lilly is a bear or
Lilly has a very small brain; that it has a brain at all
Such very long names do not scale up well
In a properly designed KB, facts that were entered for one situation should be used in
new situations as well
46