0% found this document useful (0 votes)
11 views103 pages

AI Chapter Four Updated

Uploaded by

Eliab Woubishet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views103 pages

AI Chapter Four Updated

Uploaded by

Eliab Woubishet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 103

Chapter Four

Knowledge and Reasoning


Outline
 KB agent and KB representation
 General Idea about Logic
 Kinds of logic
 Propositional (Boolean) logic
 PL connector priority
 Types of sentences in Logic (Equivalence, validity, satisfiability)
 Entailment
 Inference rules and theorem proving
Logical equivalence
 Forms of logical expression
 Example of PL Knowledge representation and inferencing (The Wumpus
world)
 Model of a world
Knowledge Base Agent
 Knowledge base agent is an agent that perform action using the knowledge it has and
reason about their action using its inference procedure.

• Knowledge base is a set of representation of facts and their relationships called rules
about the world.
• Each fact/rules are called sentences which is represented using a language called
knowledge representation language.
• Declarative approach to building an agent (or other system):
– Tell it what it needs to know (Knowledge base)
– Ask what it knows
• answers should follow from the KB
– Most AI systems are made up of two basic parts
 Knowledge base: facts about objects in the chosen domain
 Inference mechanism(engine): a set of procedures that are used to examine the
knowledge base in an orderly manner to answer questions, solve problems or make
decisions within the domain
Knowledge Bases Agent
The agent must be able to:
 Represent states of the world, actions, etc.
 Incorporate new percepts (facts and rules)
 Update internal representations of the world
 Deduce hidden properties of the world
 Deduce appropriate actions
Example of KB written in PROLOG
 FACTS
1. female(azieb).
2. male(melaku).
3. female(selam).
4. parent(melaku,selam).
5. parent(azieb,selam).

 RULE
1. father(X,Y):-male(X),parent(X,Y).
2. mother(X,Y):-female(X),parent(X,Y).
3. wife(X,Y):-parent(X,Z),parent(Y,Z).
Example
The above example consider a world of human beings and their relationships (gender,
parent, etc). The complete representation of such information is state representation.
Agent should incorporate new percept like if necessary
father(Kebede, selam).
Mother(Tsehay, selam).
Male(kebede).
Agent should update internal representation of the world.
For example, if died(melaku) is given we should modify any fact that tells us about live
history about melaku.
The agent should deduce hidden portion of the world like azieb and selam are beautiful.
Deduce appropriate action to query.
For example, for the query is aster beautiful? The agent will say yes or no.
Knowledge representation
 Knowledge representation refers to the technique how to express the available facts and
rules inside a computer so that agent will use it to perform well.
 Knowledge representation consists of:
– Syntax (grammar): possible physical configuration that constitute a sentence (fact or
rule) inside the agent architecture.
• For example one possible syntax rule may be every sentence must end with full
stop.
– Semantics (concept): determine the facts in the world to which the sentence refers
• Without semantics a sentence is just a sequence of characters or binary
sequences
• Semantic defines the meaning of the sentence
Knowledge representation
E.g., In the language of arithmetic
– x+2 ≥ y is a sentence;
– x2+y > {} is not a sentence
– x+2 ≥ y is true iff the number x+2 is not less than the number y
– x+2 ≥ y is true in a world where x = 7, y = 1
– x+2 ≥ y is false in a world where x = 0, y = 6
 Given clear definition of semantics and syntax of a language, we call that language:
logical language.
 Knowledge representation is used to represent part of the world (facts and their
association) into ideal computer system
 KB for agent program can be represented using programming language designed for
this purpose like LISP and PROLOG
What is Logic
- Logic is concerned with reasoning and the validity of arguments.
– In general, in logic, we are not concerned with the truth of statements, but rather
with their validity.
– That is to say, although the following argument is clearly logical, it is not something
that we would consider to be true:
 All lemons are blue

 Eleni is a lemon

 Therefore, Eleni is blue

– This set of statements is considered to be valid because the conclusion (Eleni is blue)
follows logically from the other two statements, which we often call the premises.
Logic
• Logic in AI is the key idea for KB design, KB representation and inferencing
(reasoning)
• Logic is formal languages use for representing information so that conclusions can be
drawn.
• Logic is the study of the principles of reasoning and arguments towards the truth of a
given conclusion given premises.
• Logic is the systematic study of the general conditions of valid inferences
 Logic includes…
1. Formal system of defining the world
• Syntax
• Semantics
2. A proof theory:
– It is Rules for determining all entailments (given the hidden property of the world)
– A set of rules for deducing the entailment of a set of sentences.
Kinds of Logic
 In mathematics there are different kinds of logics. Some of these according to order
of their generality are
 Prepositional logic

 First order logic

 Second order logic and more

 Prepositional logic and its application will be discussed in this now then we will
discusse first order logic
 First order logic can be used to design, represent or infer for any environment in the
real world.
Prepositional (Boolean) logic (PL)
 Preposition is statement which is either true or false but not both at any time.
 A statement is a sentence which is either true or false.
 PL uses declarative sentences only
 PL doesn’t involve quantifiers.
 Not all sentences are statement (interrogatives, imperatives and exclamatory)
 Preposition can be conditional or unconditional
Examples
Socrates is mortal
If the winter is severe, students will not succeed.
All are the same iff their color is black
 In prepositional logic, symbols represent the whole preposition.
Examples:
 M = Socrates is mortal, W = winter is sever, S = students will not succeed
Prepositional (Boolean) logic (PL)
 Preposition symbols can be combined using Boolean connectives to generate new preposition
with complex meaning.
 Symbols involved in PL:
– Logical constants (TRUE and FALSE)
– Preposition symbols (also called atomic symbols) like M, W, S
– Logical connectives  (negation),  (conjunction), (disjunction),  (bi-implication or
equivalence),  (implication) and parenthesis
 Rules
– Logical constants and propositional symbols are sentence by them selves.
– Wrapping parenthesis around a sentence yield a sentence like (P V Q)
– Literal are atomic symbols or negated atomic symbols
– Complex sentence can be formed by combining simpler sentences with logical connectors
PL connector priority
 Priority of logical connectives from highest to lowest
– Parenthesis
– Negation
– Conjunction
– Disjunction
– Implication
– Bi-implication
General principle of KB agent function
Types of sentence
 Given a sentence α, this sentence according to the world considered can be
 Valid (tautology)
 Invalid (contradiction)
 Satisfiable (neither valid nor invalid)
 Unsatisfiable (equivalent to Invalid)
Validity (tautology)
 A sentence is valid iff it is true under any interpretations in all possible world.
 Proof methods: Truth -Tables and Inference Rules
 Validity is connected to inference via the Deduction Theorem:
KB ╞ α if and only if (KB  α)
Example:
x>4 or x<=4;
Water boils at 100 degree centigrade
Human has two legs (may not be valid)
Books have page number (may not be valid)
Satisfiablility
 A sentence is satisfiable iff there is some interpretation in some world for which it is
true.
 A set of sentences is satisfiable if there exists an interpretation in which every sentence
is true (it has at least one model).
 Proof Methods: Truth-Tables
 Every valid sentence is satisfiable
– Example: x+2 = 20
– Every student of AI are in their class
 A sentence which is not satisfiable is unsatisfiable (contradiction).
Entailment
 Entailment means that one thing follows from another:
 It can be represented by ╞ symbol (double turnstyle)
 KB ╞ α shows α can be entailed from KB
 Knowledge base KB entails sentence α if and only if α is true in all worlds where KB is
true.
E.g., the KB containing “the Giants won” and “the Reds won” entails “Either the
Giants won or the Reds won”
E.g., x+y = 4 entails 4 = x+y
E.g., x+y = 4 entails x= 2 and y = 2
 Entailment is a relationship between sentences (i.e., syntax) that is based on semantics
Inference Procedure
 An inference procedure is a procedure used as reasoning engine.
 It can do:
- Given KB, generate new sentence α that can be entailed by KB and we call the
inference procedure entail α
- Given KB and α, it will prove whether α is entailed by KB or not
 KB ├i α means sentence α can be derived from KB by procedure i (|- is called
turnstyle or single turnstyle)
 The record of operation of a sound inference procedure is called a proof
Inference Procedure property
 Soundness: inference procedure i is said to be sound:
if whenever KB ├i α, it is also true that KB╞ α
 Completeness: inference procedure i is said to be complete if whenever KB╞ α, it is also
true that KB ├i α
 Soundness of an inference can be established through truth table
for example and inference procedure that entails P from a KB which consists of PQ
& Q is not sound as shown bellow
P Q PQ Remark
1 T T T Q, PQ, & P are true
2 T F F Premises doesn’t satisfied
3 F T T Premises satisfied but not the conclusion
4 F F T Premises doesn’t satisfied
Rules of inference for PL
 Soundness of an inference can be established through truth table
Example (P V H)   H)  P
 To prove validity of a sentence, there are a set of already identified patterns called inference rules.
These are:
1. Modes Ponens or implication elimination

2. And Elimination

3. And introduction

4. Or introduction

5. Double negation elimination

6. Unit resolution

7. Resolution
Following are some terminologies related to inference rules:
Implication: It is one of the logical connectives which can be represented as P → Q.
It is a Boolean expression.
Converse: The converse of implication, which means the right-hand side proposition
goes to the left-hand side and vice-versa. It can be written as Q → P.
Contrapositive: The negation of converse is termed as contrapositive, and it can be
represented as ¬ Q → ¬ P.
Inverse: The negation of implication is called inverse. It can be represented as ¬ P →
¬ Q.
Rule of inference for propositional logic
Rules of Inerence:- are the templates for constructing valid argument
Inference: deriving conclusion from evidences
What rule is used for the conclusion?
1. If world population continues to grow, then cities will become hopelessly crowed; If
cities become hopelessly overcrowded, then pollution will become intolerable.
Therefore, if world population continues to grow then pollution will become intolerable.
2. Either Yohanes or Thomas was in Ethiopia; Yohanes was not in Ethiopia. Therefore,
Thomas was in Ethiopia.
3. If twelve million children die yearly form starvation, then something is wrong with food
distribution; Twelve million children die yearly form starvation. Therefore, something is
wrong with food distribution.
4. If Japan cares about endangered species, then it has stopped killing whales; Japan has
not stopped killing whales. Therefore, Japan does not care about endangered species.
5. If Napoleon was killed in a plane crash, then Napoleon is dead; Napoleon is dead.
Therefore, Napoleon was killed in a plane crash.
Logical equivalence
 Two sentences are logically equivalent iff they have the same truth value in all possible
world
 equivalently α ≡ ß iff α╞ β and β╞ α
Prove that (P V H)   H)  P is valid
Prove S, given that:
(PQ)
(PR)
(QR) S
Forms of Logical expression
There are different standard forms of expressing PL statement. Some of these are:
1. Clausal normal form: it is a set of one or more literals connected with the disjunction
operator (disjunction of literals).
Example ~P  Q  ~R is a clausal form
2. Conjunctive normal forms (CNF): conjunction of disjunction of literals or conjunction of
clauses.
Example (A  B)  (C D)
3. Disjunctive normal form (DNF): disjunction of conjunction of literals.
Example (A  B) (C  D)
4. Horn form: conjunction of literals implies a literal.
Example (A  B  C D)=>E
5. A BNF (Backnus-Naur Form) grammar of sentences in propositional logic.
Sentence  Atomic Sentence  Complex Sentence
AtomicSentence  True  False P  Q  R  …
ComplexSentence  (Sentence) Sentence Connective Sentence  Sentence
Connective        
Inference procedure and normal forms
 The inference procedure that we have seen before are all sound
 If KB is represented in CNF, the generalized resolution inference procedure is complete
 If KB is represented in Horn form, the generalized modes ponens algorithm is complete
 It can be proved that every sentence of human language can be represented using logic as
CNF. However, it is not possible in Horn form.
 Therefore, CNF is a more powerful representation technique for knowledge
 But, Horn form representation of knowledge is easily understandable and convenient. It
also require polynomial time inference procedure.
Generalized Resolution for PL
 Given any two clauses A and B, if there are any literal P1 in A which has a
complementary literal P2 in B, delete P1 and P2 from A and B and construct a
disjunction of the remaining clauses.
 The clause constructed is called the resolvent of A and B.
– For example, consider the following clauses
A: P  Q  R
B: ~P  Q  M
C: ~Q  S
From clause A and B, if we remove P and ~P, it resolves into clause
D : Q  R  Q M  Q  R  M .
If Q of clause D and ~Q of clause C resolved, we get clause
E: R  M  S
Generalized Resolution for PL
As another example, consider the following clauses
 A: P  Q  R

 B: ~P  R

 C: ~Q

 D: ~ R

An empty clause, which is false. This proves the contradiction.

Note: in order to apply resolution for proving a theory, make sure first all the knowledge is in
its clausal form
Example: Resolution
Prove that r follows from:
(p  q)  (r  s) -(1)
p~s -(2)
p q -(3)
Solution:
Clause (1) in Clausal form
~ (p  q)  (r  s)
 {~ p  ~ q  r  s} - (1)
Clause (2) in Clausal form
{~ p  ~ s} - (2)
Clause (3) in Clausal form
{p} - (3)
{q} - (4)
Assume not r which {~ r} in Clausal form - (5)
Example: Resolution
Using inference rules: from unit resolution rule of (1) and (5)
{~p  ~ q  s} - (6) (resolve r with ~r and get resolvent)
from unit resolution of (3) and (6)
{~ q  s} - (7) (resolve p with ~p and get resolvent)
from (4) and (7)
{s} - (8) (resolve q with ~q and get resolvent)
from (2) and (8)
{~ p} - (9) (resolve p with ~p and get resolvent)
from (3) and (9)
{} - (10)
Therefore r follows from the original clauses
Converting to CNF
Converting the following sentence to CNF:
a ~bcd
≡ (a  ~ b)  (c  d)
Steps:
1. Remove Implication
~(a  ~ b)  (c  d)
2. Push Negations Inwards
~a  ~ ~ b  (c  d)
3. Eliminate Double Negations
~a  b  (c  d)
4. Push Disjunctions into Conjunctions
(~a  b  c)  (~a  b  d)
Converting to CNF
Convert the following sentence to CNF:
((a  b)  c)
Eliminate Implication
≡ (~a  b)  c
≡ ~(~a  b)  c
Push Negations Inwards
≡(~~a  ~ b)  c)
Eliminate Double Negations, apply De Morgans law
≡(a  ~ b)  c
Push Disjunctions into Conjunctions
≡(a  c)  (~b  c)
Hence (a  c)  (~b  c) is CNF of ((a  b)  c)
Converting to CNF
Convert the following sentence to CNF:
1. (a  ((b  c) d))
2. P↔¬(¬P)
3. A↔(B  C)
The Wumpus World
The Wumpus world is a simple world example to illustrate the worth of a
knowledge-based agent and to represent knowledge representation.
The Wumpus world is a cave which has 4/4 rooms connected with passageways. So
there are total 16 rooms which are connected with each other.
We have a knowledge-based agent who will go forward in this world. The cave has a
room with a beast which is called Wumpus, who eats anyone who enters the room.
The Wumpus can be shot by the agent, but the agent has a single arrow. In the Wumpus
world, there are some Pits rooms which are bottomless, and if agent falls in Pits, then
he will be stuck there forever.
The exciting thing with this cave is that in one room there is a possibility of finding a
heap of gold. So the agent goal is to find the gold and climb out the cave without fallen
into Pits or eaten by Wumpus. The agent will get a reward if he comes out with gold,
and he will get a penalty if eaten by Wumpus or falls in the pit.
Following is a sample diagram for representing the Wumpus world. It is showing some
rooms with Pits, one room with Wumpus and one agent at (1, 1) square location of the
world.
There are also some components which can help the agent to navigate the cave. These
components are given as follows:
A. The rooms adjacent to the Wumpus room are smelly, so that it would have some stench.
B. The room adjacent to PITs has a breeze, so if the agent reaches near to PIT, then he will
perceive the breeze.
C. There will be glitter in the room if and only if the room has gold.
D. The Wumpus can be killed by the agent if the agent is facing to it, and Wumpus will
emit a horrible scream which can be heard anywhere in the cave.
Sensors:
 The agent will perceive the stench if he is in the room adjacent to the Wumpus. (Not
diagonally).
The agent will perceive breeze if he is in the room directly adjacent to the Pit.
The agent will perceive the glitter in the room where the gold is present.
The agent will perceive the bump if he walks into a wall.
When the Wumpus is shot, it emits a horrible scream which can be perceived anywhere in
the cave.
These percepts can be represented as five element list, in which we will have different
indicators for each sensor.
Example if agent perceives stench, breeze, but no glitter, no bump, and no scream then it
can be represented as:
[Stench, Breeze, None, None, None].
Practical Example (The Wompus world)
 Goal: Agent wants to move to the square which holds Gold, grab it and come back to the original
square and release it there
 Initially agent could be at any of the square

 Environment
 Squares adjacent to wumpus are smelly(stench)
 Squares adjacent to pit are breezy
 Glitter iff gold is in the same square
 Shooting kills wumpus if agent is facing to it
 Shooting uses up the only arrow
 Grabbing picks up gold if in same square
 Releasing drops the gold in same square
Practical Example (The Wompus world)
 Performance measure
 Grab gold has score of 1000,
 death by pits or wompus score -1000
 using the arrow (shooting) score -10 and
 the rest ation score -1

 Sensors: Stench, Breeze, Glitter, Bump, Scream


 Actuators: turn left 90o, turn right 90o, Forward, Grab, Release, Shoot
Practical Example (The Wompus world)
Characterization
 Fully Observable No – only local perception
 Deterministic Yes – outcomes exactly specified
 Episodic No – sequential at the level of actions
 Static Yes – Wumpus and Pits do not move
 Discrete Yes
 Single-agent? Yes – Wumpus is essentially a natural feature
6-45
Exploring the Wumpus world:
Now we will explore the Wumpus world and will
determine how the agent will find its goal by applying
logical reasoning.
Agent's First step:
Initially, the agent is in the first room or on the square [1,1],
and we already know that this room is safe for the agent, so
to represent on the below diagram (a) that room is safe we
will add symbol OK.
Symbol A is used to represent agent, symbol B for the
breeze, symbol G for Glitter or gold, symbol V for the
visited room, P for pits, W for Wumpus.
At Room [1,1] agent does not feel any breeze or any Stench
which means the adjacent squares are also OK.
Agent's second Step:
Now agent needs to move forward, so it will either move to [1, 2], or [2,1].
Let's suppose agent moves to the room [2, 1], at this room agent perceives some breeze
which means Pit is around this room. The pit can be in [3, 1], or [2,2], so we will add symbol
P? to say that, is this Pit room?
Now agent will stop and think and will not make any harmful move. The agent will go back
to the [1, 1] room. The room [1,1], and [2,1] are visited by the agent, so we will use symbol
V to represent the visited squares.
6-47

Agent's third step:


At the third step, now agent will move to the room [1,2] which is
OK. In the room [1,2] agent perceives a stench which means there
must be a Wumpus nearby.
But Wumpus cannot be in the room [1,1] as by rules of the game,
and also not in [2,2] (Agent had not detected any stench when he
was at [2,1]).
Therefore agent infers that Wumpus is in the room [1,3], and in
current state, there is no breeze which means in [2,2] there is no Pit
and no Wumpus. So it is safe, and we will mark it OK, and the
agent moves further in [2,2].
Agent's fourth step:
At room [2,2], here no stench and no breezes present so let's
suppose agent decides to move to [2,3]. At room [2,3] agent
perceives glitter, so it should grab the gold and climb out of the
cave.
Knowledge-base for Wumpus world
The agent starts visiting from first square [1, 1], and we already know that this room is safe
for the agent. To build a knowledge base for wumpus world, we will use some rules and
atomic propositions.
We need symbol [i, j] for each location in the wumpus world, where i is for the location of
rows, and j for column location.
6-49

Atomic proposition variable for Wumpus Some Propositional Rules for the
world: wumpus world:
Let Pi,j be true if there is a Pit in the room [i, j].
Let Bi,j be true if agent perceives breeze in [i, j], (dead or
alive).
Let Wi,j be true if there is wumpus in the square[i, j].
Let Si,j be true if agent perceives stench in the square [i, j].
Let Vi,j be true if that square[i, j] is visited.
Let Gi,j be true if there is gold (and glitter) in the square [i,
j].
Let OKi,j be true if the room is safe.
Following is the Simple KB for wumpus world when an agent moves from room [1, 1], to room [2,1]:

Here in the first row, we have mentioned propositional variables for room[1,1], which is showing that room
does not have wumpus(¬ W11), no stench (¬S11), no Pit(¬P11), no breeze(¬B11), no gold (¬G11), visited
(V11), and the room is Safe(OK11).
In the second row, we have mentioned propositional variables for room [1,2], which is showing that there is
no wumpus, stench and breeze are unknown as an agent has not visited room [1,2], no Pit, not visited yet,
and the room is safe.
In the third row we have mentioned propositional variable for room[2,1], which is showing that there is no
wumpus(¬ W21), no stench (¬S21), no Pit (¬P21), Perceives breeze(B21), no glitter(¬G21), visited (V21),
and room is safe (OK21).
Prove that Wumpus is in the room (1,3) ?
- We can prove that wumpus is in the room (1, 3) using propositional rules which we have
derived for the wumpus world and using inference rule.
Apply Modus Ponens with ¬S11 and R1:
We will firstly apply MP rule with R1 which is ¬S11 → ¬ W11 ^ ¬ W12 ^ ¬ W21, and ¬S11 which
will give the output ¬ W11 ^ W12 ^ W12.
Prove that Wumpus is in the room (1,3) cont’d
Apply And-Elimination Rule:
- After applying And-elimination rule to ¬ W11 ∧ ¬ W12 ∧ ¬ W21, we will get three statements:
¬ W11, ¬ W12, and ¬W21.
Apply Modus Ponens to ¬S21, and R2:
- By applying Modus Ponens to ¬S21 and R2 which is ¬S21 → ¬ W21 ∧¬ W22 ∧ ¬ W31, which will give
the Output as ¬ W21 ∧ ¬ W22 ∧¬ W31
Prove that Wumpus is in the room (1,3) cont’d
Apply And -Elimination rule:
Now again apply And-elimination rule to ¬ W21 ∧ ¬ W22 ∧¬ W31, We will get three
statements:
¬ W21, ¬ W22, and ¬ W31.

Apply MP to S12 and R4:


Apply Modus Ponens to S12 and R4 which is S12 → W13 ∨. W12 ∨. W22 ∨.W11, we will
get the output as W13∨ W12 ∨ W22 ∨.W11.
Prove that Wumpus is in the room (1,3) cont’d
Apply Unit resolution on W13 ∨ W12 ∨ W22 ∨W11 and ¬ W11 :
After applying Unit resolution formula on W13 ∨ W12 ∨ W22 ∨W11 and ¬ W11 we will get
W13 ∨ W12 ∨ W22.
Prove that Wumpus is in the room (1,3) cont’d
Apply Unit resolution on W13 ∨ W12 ∨ W22 and ¬ W22 :

After applying Unit resolution on W13 ∨ W12 ∨ W22, and ¬W22, we will get W13 ∨
W12 as output.

•Apply Unit Resolution on W13 ∨ W12 and ¬ W12 :


After Applying Unit resolution on W13 ∨ W12 and ¬ W12, we will get W13 as an output,
hence it is proved that the Wumpus is in the room [1, 3].
Prove that Wumpus is in the room (1,3) cont’d
The Wumpus World cont’d
- Note that in each case for which the agent draws a conclusion from the available
information, that conclusion is guaranteed to be correct if the available information is
correct. This is a fundamental property of logical reasoning.
First order logic (FOL)
Lecture Outline
Limitations of Proposition Logic
Power of predicate logic
FOL function and predicate symbol
Syntax and semantics of FOPC
FOL sentence
Quantifier in FOL
Property of Quantifier
Free and bounded variable
First Order Logic
Properties of Propositional Logic
Propositional logic is declarative
– Propositional logic allows partial/disjunctive/negated information
 (unlike most data structures and databases)

- Propositional logic is compositional:


1,1  P1,2 is derived from meaning of B1,1 and of P1,2
 meaning of B

- Meaning in propositional logic is context-independent


 (unlike natural language, where meaning depends on context)

- Propositional logic has very limited expressive power


First Order Logic
Propositional logic is a weak language(limitations)
- Propositional logic quickly becomes impractical, even for very small worlds
 Hard to identify “individuals” (e.g., Mary, 3)
 Can’t directly talk about properties of individuals or relations between
individuals (e.g., “Bill is tall”)
 Generalizations, patterns, regularities can’t easily be represented (e.g., “all
triangles have 3 sides”)
 First-Order Logic (abbreviated FOL or FOPC) is expressive enough to
concisely represent this kind of information
 FOL adds relations, variables, and quantifiers,
Propositional Logic Limitations
• Some of the limitations of prepositional logic includes
– Very limited expressive power: unlike natural language, propositional logic has very
limited expressive power
• Example cannot say “pits cause breezes in adjacent squares” except by writing one
sentence for each square
– It only represent declarative sentences: Propositional logic is declarative (sentence
always have truth value)
– Deals with only finite sentences: propositional logic deals satisfactorily with finite
sentences composed using not, and, or, if . . . Then, iff
– e.g., if there are 3 students A, B and C
taking p = “A has red hat”,
q = “B has red hat” and
r = “C has red hat”,
the formula “there exists a student with a red hat” may be modeled as p q  r.
Limitations….
 On infinite models this may require infinite formulas;
Example:- “each natural number is even or odd” has to be translated as (p0  q0)(p1 
q1) (p2  q2)  …
where p0 ,p1,p2,… are even and q0,q1,q2,… are odd. .
– The prepositional logic assumes the world consists of facts.
– Cannot express the following:
All men are mortal
Socrates is a man
Therefore, Socrates is mortal
 Propositional Logic has thus limited expressive power.
First Order Logic
Objects, Relations, Functions
Whereas propositional logic assumes world contains facts, first order logic (like
natural language) assumes the world contains: Objects, Relations, Functions.
 Objects: people, houses, numbers, theories, colors, football games, wars,
centuries …
 Relations: red, round, multistoried, brother of, bigger than, inside, part of,
has color, occurred after, owns, comes between, …
 Functions: father of, best friend, second half of, one more than, beginning of

Combining the best of formal and natural languages

- Indeed, almost any assertion can be thought of as referring to objects and


properties or relations. Some examples follow:
 “One plus two equals three.”

 Objects: one, two, three, one plus two; Relation: equals; Function: plus.

(“One plus two” is a name for the object that is obtained by applying the
function “plus” to the objects “one” and “two.” “Three” is another name for
this object.)
 “Squares neighboring the wumpus are smelly.”

 Objects: wumpus, squares; Property: smelly; Relation: neighboring.


- “Evil King John ruled England in 1200.”
Objects: John, England, 1200; Relation: ruled; Properties: evil, king.
e.g.,“Every elephant is gray”:  x (elephant(x) →
gray(x))
“There is a white alligator”:  x (alligator(X) ^
white(X))
- Consider the problem of representing the following
information:
 Every person is mortal.
 Confucius is a person.
 Confucius is mortal.
- How can these sentences be represented so that we
can infer the third sentence from the first two?
Example….
- In PL we have to create propositional symbols to stand for all or part of each
sentence. For example, we might have: P = “person”; Q = “mortal”; R =
“Confucius”
- So the above 3 sentences are represented as: P  Q; R  P; R  Q
- Although the third sentence is entailed by the first two, we needed an explicit
symbol, R, to represent an individual, Confucius, who is a member of the classes
“person” and “mortal”
- To represent other individuals we must introduce separate symbols for each one,
with some way to represent the fact that all individuals who are “people” are also
“mortal”
Predicate Logic power
• Equivalent names
– Predicate logic
– First Order Logic (FOL)
– First Order Predicate Calculus (FOPC).
• Predicate logic is an extension of propositional logic using variables for objects
• It is much richer and complex than propositional logic.
• Predicate logic has complex expressive power
e.g., If x represents a natural number, then “each natural number is even or odd” ”;may
be written shortly as
• x(E(x)  O(x))
where E(x) = “x is even” and O(x) = “x is odd”
FOL function and predicate symbols
• Function symbols are symbols that takes argument as a set of terms (variables,
constant, functions) that represents a new object
– Father(John)
– Sucessor(X)
– Sucessor(Sucessor(2))
• A predicate symbols is a symbol which describes a relation between objects or
property of an object
– Father(solomon, gizaw)
– Male(teshome)
Example1
Represent the statement “Not all birds can fly”
Let B(x) denotes “x is a bird.”
Let F(x): denotes “x can fly”;
~(x (B(x)  F(x)))
Does this equivalent to
x (B(x)  F(x))
some birds couldn’t fly
Represent the statement “All men are mortal. Socrates is man. Therefore, Socrates is
Mortal”
Let: H(x) denotes “x is man”;
M(x) denotes “x is mortal ”, and s denotes Socrates;
The statement (2) may be described as:
 x(H(x)  M(x)), H(s) |- M(s)
Syntax & Semantics of FOPC
Sentence : Atomic Sentence  Sentence Connective Sentence  Quantifier Variable,
… Sentence ~ Sentence  (Sentence)
AtomicSentence : Predicate(Term1, Term2,…,Termn)Term = Term
Term: Function(Term,…)  Constant  Variable
Connective : 
Quantifier :  
Constant : A X1 KingJohn  ...
Variable : a  x  s  …
Predicate : Before HasColor  Raining …
Function : Mother LeftLegOf ...
Term

A Term is a logical expression that refers to an object .


It is a name for a thing.
There are three kinds of terms which allows us to name things in the world.
1. Constant symbol,
Example: John, Japan, Bacterium
2. Variable symbol,
Example: x,y a, t,…
3. Function symbols,
Example: f(f(x)); mother_of(John); LeftLegOf(John)

Note: A term with no variables is called a ground term.


For example
John, father(solomon)
Equality (=)
Two terms term1 and term2 are equal under a given interpretation if and only if term1 and
term2 refer to the same object.

Example1:
If the object referred by Father(Kaleb) and the object referred to by Ayele are the same,
then
Father(Kaleb ) = Ayele
Predicate symbols
Predicate symbols: are symbols that stands to show a relationship among terms or to
indicate property of a term.

For example:
On(A,B) to mean A is on B (relation between A & B)
Sister(Senait, Biruk) to mean Senaitis sister of Biruk
Female(Azeb) to mean Azeb is female (proprty of azeb being female)

Here ‘On’, ‘Sister’ and Female are predicate symbols, ‘A’, ‘B’, ‘Senait’, ‘Biruk’ and
Azeb are terms.
Atomic sentences
Atomic sentences states the facts of world and is formed from a predicate symbol
followed by a parenthesis list of terms.
Example:
Brother(Ali, Kedir)

Atomic sentences can have arguments that are complex terms:


• Sister(mother_of(John),Jane)
• Married(FatherOf(Richard),MotherOf(John))

An atomic sentence is true if the relation referred to by the predicate symbol holds
between the objects referred to by the arguments.
Complex Sentence
Complex sentences are sentences which is a combination of one or more atomic sentences
with logical connectives
Example:
Older(John,30)  Younger(John,30);
represents John is above 30
Brother(Robin,John)
represents Robin is Brother of John
Hana = daughter(brother(mother(Selam))) ;
represents Hana is Selam’s cousin

Father(Solomon, Tesfaye)father(Solomon, Biruk)


Represents if solomon is father of Tesfaye then he is also father of Biruk
Quantifiers
A quantifier is a symbol that permits one to declare, or identify the range or scope of the
variables in a logical expression.
A quantifier express properties of entire collection of objects.
There are two types of quantifier
 Universal quantifier 

 Existential quantifier 
Universal Quantification ()
 Universal quantifier defines the domain of a variable in a logical expression to be
any element in the universe.

 If x is a variable, then,  x is read as


 for all x OR for each x OR for every x

 The scope of universal quantifier is the whole element in the domain


Syntax: <variables> <sentence>
one or more variables can be quantified by a single quantifier by separating with
comma. Eg. x,y
Example1: “Every student is smart:”
x (Student(x)  Smart(x))
Example2: “All cats are mammals”
 x (cats(x) Mammals(x))
Universal Quantification ()
Roughly speaking,  is equivalent to the conjunction of an instantiations of P

x (Student(x)  Smart(x)) is equivalent to


(Student(KingJohn)  Smart(KingJohn)) 
(Student(Abera)  Smart(Abera)) 
(Student(MyDog)  Smart(MyDog)) ...

x(cats(x) Mammals(x)) is equivalent to


(Cat(Spot)  Mammals(Spot)) 
(Cat(Rebecca)  Mammals (Rebecca)) 
(Cat(Felix)  Mammals (Felix)) 
(Cat(John)  Mammals (John))  …
Universal Quantification ()

Note1: Typically,  is the main connective with 


Note2: Avoid the mistake of using  as the main connective with :

Example:
x (Student(x)  Smart(x)) means “Everyone is a student and everyone is smart”
x(cats(x)  Mammals(x)) means “Everything is a cat and every thing is mammal”

This doesn’t agree in concept with the original sentence which is every student is
smart, every cat are mammal respectively.
Existential quantification ()
 Existential quantifier defines the domain of a variable in a logical expression to be a non
empty set which is the subset of the universal set.
 if y is a variable, then  y is read as
There exists a y OR for some y OR for at least one y
Syntax: <variables> <sentence>
 one or more variables can be quantified by a single quantifier by separating with comma.
Eg. x,y
Example1: “Some students are smart”
x (student(x)  Smart(x))
Example2: “Spot has a sister who is a cat”
x(Sister(x, Spot)  Cat(x))
Existential quantification ()
Roughly speaking,  is equivalent to the disjunction of instantiations of P
x(student(x)  Smart(x)) is equivalent to
(Student(KingJohn)  Smart(KingJohn)) 
(Student(Abera)  Smart(Abera)) 
(Student(MyDog)  Smart(MyDog)) ...
x(Sister(x, Spot)  Cat(x)) is equivalent to
(Sister(Felix, Spot)  Cat(x)) 
(Sister(Rabicca, Spot)  Cat(x)) 
(Sister(chichu, Spot)  Cat(x)) …
Existential quantification ()
Note1: Typically,  is the main connective with .
Note2: Avoid the mistake of using  as the main connective with :
Example:
• Some students are smart is to mean that there are entities that satisfy the property of both
being a student and smart.
• In the figure, the yellow part indicates the set of such groups

However, x(student(x)  Smart(x)) is to means any thing which is either smart or not
a student
Hence this doesn’t infer what we need to say
Examples using Quantifiers
Man(John)
John is a man
 x(Man(x)  ~Woman(x))
Every man is not a woman (there is no man who is a woman)
 x(Man(x)  Handsome(x))
Some man are handsome
 x(Man(x)  y(Woman(y)  Loves(x,y)))
Every man has a woman that he loves
 y(Woman(y)  (x)(Man(x)  Loves(x,y)))
There are some woman that are loved by every man
Nested quantifiers
 Universal and existential quantifiers can be nested one into another.
It is possible to have one or more quantifier nested in another quantifier
Example1
“For all x and all y, if x is the parent of y then y is the child of x” can be represented as
x,y (Parent(x,y)Child(y,x))
Note: Here x,y means x y
Example2
“There is someone who is loved by everyone
yx Loves(x,y)
Nested quantifiers
Difficulty may arise when two quantifiers are used with the same variable name.
For example
x (Cat(x)  x Brother(Richard,x)))
In the sentence above, x in Brother(Richard,x) is existentially qualified and the universal
quantifier has no effect on it.
Rule: To identify which quantifier quantify a variable if the variable is quantified by two
or more of them, the innermost quantifier that mentions it will be choosen.
Examples of Translating English to FOL
1. Every gardener likes the sun.
(x) (gardener(x)likes (x,sun))
2. All purple mushrooms are poisonous
(x) [(mushrooms(x) purple(x))  poisonous(x)]
3. No purple mushroom is poisonous
~(x) (purple(x)  mushroom(x)  poisonous(x))
4. There are exactly two purple mushrooms
(x)(y) {mushroom (x)  purple(x)  mushroom(y)  purple(y)  ~(x=y) 
(z)[(mushroom(z)  purple(z))  ((x=z)(y=z))]}
5. You can fool some of the people all of the time
(x)(person(x)  ( t) (time(t) can-fool(x,t)))
6. Jane is a tall surveyor
Tall(Jane)  Surveyor(Jane)
Examples of Translating English to FOL
7. Everybody loves somebody
x y Loves(x,y)
y x Loves(x,y)
8. Nobody loves Jane
x ~Loves(x,Jane)
~y Loves (y,Jane)
9. Everybody has a father
x y Father(y,x)
10. Everybody has a father and mother
x y,z (Father(y,x)  Mother(z,x))
12. Whoever has a father has a mother
x y (Father(y,x)  z Mother(z,x))
13. Every son of my father is my brother
xy ((MyFather(x)  Son(y,x))  MYBrother(y))
Properties of quantifiers (commutativity)
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,

Example
 x y Loves(x,y) means “There is a person who loves everyone in the world”
 y x Loves(x,y) means “Everyone in the world is loved by at least one
person”
Properties of quantifiers (duality)
Quantifier duality refers to the possibility of expressing one quantifier with the other
equivalently

Universal quantifier can be completely replaced by existential quantifier without affected


the meaning and vise versa
Example
x Likes(x,IceCream)  x Likes(x,IceCream)
x Likes(x,IceCream)  Everyone likes ice cream
x Likes(x,IceCream)  there is no one who does not like ice cream.

x Likes(x,Broccoli)  x Likes(x,Broccoli)


x Likes(x,Broccoli)  Some one likes Broccoli
x Likes(x,Broccoli)  It is not true that every one doesn’t like Broccoli
Properties of quantifiers (duality)
Quantifiers are intimately connected with each other, through negation.
Example: If one says that everyone dislikes bitter guard one is also saying that there does
not exists someone who likes them or vice versa.
  is really conjunction over the universe of objects and
  is a disjunction over the universe, they obey De Morgan’s rules.
De Morgan rules for quantified & un-quantified sentences are as follows:
1. (x P(x))  (x P(x))
2. (x Q(x))  (x Q(x))
3. (x P(x))  (x P(x))
4. (x Q(x))  (x) Q(x))
In fact, one quantifier can do both works, if used with negation in appropriate place.
Properties of quantifiers (duality)
Consider a world consists of only three object A
Hence x P(x)  (P(A)  P(B)  P(C))
  (P(A)  P(B)  P(C))
 ( P(A)   P(B)   P(C))
 (x  P(x) )

Syntax & Semantics of FOPC


x P is false for all x
[~P(x)]
x P is false for some x
[~P(x)]
x [P(x)] P is true for all x
x [P(x)] P is true for some x
Normal Forms:
A well formed formula can be represented in different standard normal forms
Some of the normal forms are

1. Clause Form: disjunction of literals (atomic sentences)


2. Conjunctive Normal Forms (CNF): conjunction of disjunction of literals or
atomic sentences.
 It can also be defined as conjunction of clauses

3. Disjunctive Normal Form (DNF): disjunction of conjunction of literals.


Normal Forms:
Conjunctive Normal Form (CNF) is the focus of the chapter since:
1. Any well formed formula (logical expression) can be converted into CNF
2. Generalized resolution is a complete inference procedure on CNF expression KB
3. It provides an easy way of inference procedure for the computer through
resolution and refutation

A single literal (atomic sentence) or a single clause is in CNF form


Q  Q  False
~Q  ~Q  False
Conjunctive Normal Forms
• Steps to convert form predicate logic formula to CNF.
1) Eliminate implications and bi-conditionals.
(A  B) = ~A B
(aB) = (AB)  (B  A)
2) Reduce the scope of negation and apply De Morgan’s
theorem to bring negations before the atoms
~(AB) = ~A  ~B
~(A  B) = ~A  ~B
3) To bring the signs before the atoms, use the duality relation formulae
~x(A(x)) =  x(~A(x))
~( x (A(x)) =  x( ~A(x))
4) For the sake of clarity (to avoid repetition) rename bound variables if necessary.
5) Use the equivalent formulae to move the quantifiers to the left of the formulae to
obtain the normal form
Conversion exercise into its normal form
1. x (A(x) y B(x,y)) ---(1)
 x (~A(x)  y B(x,y)) implication elimination
 x  y(~A(x)  B(x,y)) pushing  to the front
- (solution)
2. x (A(x)  x B(x))
 x (A(x)  y B(y)) variable renaming
 x (~A(x)  y B(y)) eliminating 
 xy (~A(x)  B(y)) pushing  to the front
Conversion exercise into its NF
3. x A(x)  x B(x)
 (x A(x))  y B(y) scoping and renaming
 ~(xA(x))  y B(y)  elimination
 x ~A(x)  yB(y) pushing ~ inward
 xy (~A(x)  B(y)) pushing  to the front
 x,y (~A(x)  B(y)) using single quantifier
Propositional logic
Assumes that the world contains facts
Problems with propositional logic
• No notion of objects
• No notion of relations among objects
In Propositional Logic, we define A1 as “American sits
at seat 1.” The meaning of A1 is instructive to us, suggesting
– there is an object we call American,
– there is an object we call “seat 1”,
– there is a relationship “sit” between these two objects
• Formally, none of these are in Propositional Logic.
First-Order Logic
It 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 map individuals in the domain to another in the domain.
Examples:
• Objects: Students, lectures, companies, cars ...
• Properties: blue, oval, even, large, ...
• Relations: Brother-of, bigger-than, outside, part-of, has-color,
occurs-after, owns, visits, precedes, ...
Functions: father-of, best-friend, second-half, one-more-than
Quiz
1. What is first order logic, why we need it and how it models the world ?
Translating English to FOL
1. John and Michael are colleagues
2. Some boys play cricket.
3. Brothers are siblings
4. Only one student failed in Mathematics.
5. Each student is registered for at least one degree programme
Conversion exercise into its normal form
6. x (A(x)  x B(x))
7. ∀Y (∀X (taller(Y,X) V wise(X)) => wise(Y))
Quiz

1. What is the limitation of prepositional logic, what is the solution and how the
solution models the world ?
Translating English to FOL
1. Some people like Football.
2. Every man respects his parent.
3. Brothers are siblings.
4. Not all students like both Mathematics and Science.
5. Each student is registered for at least one degree programme.
Conversion exercise into its normal form
6. x (A(x) y B(x,y))
7. ∀Y (∀X (taller(Y,X) V wise(X)) => wise(Y))
1. John and Michael are colleagues
Colleagues (John, Michael)
2. Some boys play cricket.
∃x boys(x) → play(x, cricket).
3. Brothers are siblings.
∀x, y (Brother(x, y) ⇒ Sibling(x, y))
4. Only one student failed in Mathematics.
∃(x) [ student(x) → failed (x, Mathematics) ∧∀ (y) [¬(x==y) ∧ student(y) →
¬failed (x, Mathematics)].
5. Each student is registered for at least one degree programme’
∀x(Student(x)→∃y(registeredfor(x,y)∧DegreeProgramme(y)))
1. Some people like Football.
∃x: people(x) ∧ likes Football(x)
2. Every man respects his parent.
∀x man(x) → respects (x, parent).
3. Brothers are siblings.
∀x, y (Brother(x, y) ⇒ Sibling(x, y))
4. Not all students like both Mathematics and Science.
¬∀ (x) [ student(x) → like(x, Mathematics) ∧ like(x, Science)].
5. Each student is registered for at least one degree programme’
∀x(Student(x)→∃y(registeredfor(x,y)∧DegreeProgramme(y)))
THANKS!!

You might also like