0% found this document useful (0 votes)
2 views

Chapter 4- Knowledge and Reasoning(I)

Chapter Four discusses knowledge representation and reasoning using propositional logic, focusing on knowledge base agents that perform actions based on their knowledge. It explains the structure of knowledge bases, the process of inference, and the types of logic used in artificial intelligence. The chapter also covers various logical forms and inference rules, emphasizing the importance of soundness and completeness in reasoning procedures.

Uploaded by

nataniumcscbe
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Chapter 4- Knowledge and Reasoning(I)

Chapter Four discusses knowledge representation and reasoning using propositional logic, focusing on knowledge base agents that perform actions based on their knowledge. It explains the structure of knowledge bases, the process of inference, and the types of logic used in artificial intelligence. The chapter also covers various logical forms and inference rules, emphasizing the importance of soundness and completeness in reasoning procedures.

Uploaded by

nataniumcscbe
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 41

CHAPTER FOUR

KNOWLEDGE & REASONING - I


KNOWLEDGE REPRESENTATION AND INFERENCING UNSING PREPOSITIONAL LOGIC

1
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.(“sentence” is used
as technical term. It is related but not identical to sentences of English
language and other natural language. It represent some assertions about
the world )

2
 There must mechanisms to derive new sentences from old
ones.
 This process is known as inferencing or reasoning.
 Inference must obey the primary requirement that the new
sentences should follow logically from the previous ones
 Logic is the primary vehicle for representing and
reasoning about knowledge
 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

3
Knowledge-based agent program

 It takes a percept as input, returns an action and maintains a


kb(i.e., initial background knowledge)
 Each time the agent program is called, it does three things:
 It TELLs the kb what it perceives
 It ASKs the kb what action it should perform
 The agent program TELLs the kb which action was chosen, and the
agent executes the action

4
 A generic knowledge-based agent
 function KB-AGENT(percept) returns an action
persistent: KB, a knowledge base
t, a counter, initially 0, indicating time
TELL(KB, MAKE-PERCEPT-SENTENCE(percept, t))
action ← ASK(KB, MAKE-ACTION-QUERY(t))
TELL(KB, MAKE-ACTION-SENTENCE(action, t))
t←t+1
return action

5
Knowledge Bases Agent

 The agent must be able to:


 Represent states of the world, actions, etc.
 Incorporate new percepts (facts and rules)
 Deduce hidden properties of the world
 Deduce appropriate actions
 Update internal representations of the world

6
Knowledge Bases Agent

 Representation of state of the world using KB


 Example of KB written in that represent a state of a world
in which only Azieb is living (PROLOG representation)
 Moreover, the required information are gender and age
given name
 FACTS
1. female(azieb).
2. age(azieb, 18).

7
Example
 Agent should incorporate new percept
 For example,
1. Azieb get maried with melaku, they born two kids selam and solomon
2. This can be reflected by incorporating the new percepts
 FACTS
1. female(azieb).
2. Age(azieb, 18).
3. Married(azieb, melaku).
4. male(melaku).
5. female(selam).
6. male(solomon).
7. parent(melaku,selam).
8. parent(azieb,selam).
9. parent(melaku,solomon).
10. parent(azieb,solomon).
11. age(melaku,26).
12. age(selam, 5).
13. age(solomon, 1).
 RULE
1. married(X,Y):-maried(Y,X).
2. father(X,Y):-male(X),parent(X,Y).
3. mother(X,Y):-female(X),parent(X,Y).
4. wife(X,Y):-parent(X,Z),parent(Y,Z).
5. brother(X,Y):-male(X), parent(Z,X),parent(Z,Y).
6. sister(X,Y):-female(X), parent(Z,X),parent(Z,Y).
8
Example
 The agent should deduce hidden portion of the world like azieb and selam
are beautiful.
 If one asks questions like
 ?brother(aster,belay).
 Married(melaku, azieb).
 The system must respond correctly
 Deduce appropriate action to query.
 If one asks questions like
 who is the sister of whom,
 who is the father of belay,
 who is the mother of Selam, etc
 The system must respond correctly
 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.
9
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

10
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

11
Logic

 Logic is the study of the principles of reasoning and arguments


towards the truth of a given conclusion given premises.

 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 systematic study of the general conditions of valid


inferences

12
Types 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
 First order logic can be used to design, represent or infer for any
environment in the real world.

13
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 (unconditional)
 If the winter is severe, students will not succeed. (conditional)
 All are the same iff their color is black (conditional)
 In prepositional logic, symbols represent the whole preposition.
 Examples:
 M = Socrates is mortal
 W = winter is sever
14S = 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

15
Prepositional (Boolean) logic (PL)

 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
16
Types of sentence
 Given a sentence α, this sentence according to the world considered can
be
 Valid (tautology)
 Invalid (contradiction)
 Satisfiable (neither valid nor invalid)

Validity (tautology)
 A sentence is valid iff it is true under any interpretations in all
possible world

 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)

17
Satisfiablility
 A sentence is satisfiable iff there is some interpretation in some
world for which it is true.
 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 or
invalid).

18
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 can’t entails x= 2 and y = 2
 Entailment is a relationship between sentences (i.e., syntax) that is
based on semantics

19
Inference Procedure

 An inference procedure is a procedure used as reasoning engine.


 It can do:
1. Given KB, generate new sentence α that can be entailed by KB and
we call the inference procedure entail α
2. 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)

Inference Procedure property


 Soundness: inference procedure i is said to be sound:
if whenever KB ├i α, it is also true that KB╞ α
 A proof system is sound if everything that is provable is in fact true(if KB ├i α then KB╞ α
)
 Completeness: inference procedure i is said to be complete if whenever KB╞ α, it is also
true that KB ├i α
 A proof system is complete if everything that is true has a proof(if KB╞ α then KB ├i α )

20
Inference Procedure property
 The record of operation of a sound inference procedure is called
a proof
 Soundness of an inference can be established through truth table.
 For example the 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
21
Rules of inference for PL
 There are a set of already identified sound 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
 We will discuss all this one by one in the next slides after discussing normal
forms
22
Normal Forms of Logical expression
 There are different standard forms of expressing PL statement.
 Some inference procedure require their knowledge base to be in one
of the normal forms to infer from it.
 Hence, we need to convert the logical expression which are the
source of knowledge into the appropriate forms
 Some of the normal forms are stated bellow

23
Normal Forms of Logical expression
 Clausal normal form:
 it is a set of one or more literals connected with the disjunction operator
(disjunction of literals).
 It doesn’t allow negation marker except as a prefix to a symbol
Example ~P  Q  ~R is a clausal form
 According to the definition a single symbol or negation of a symbol is in
clausal form
 Conjunctive normal forms (CNF):
 Simply defined as a sequences of one or more clauses connected by the
conjunction operator
 Or it is conjunction of clauses
 Or conjunction of disjunction of literals
Example (A  B)  (C D)
 Note: connector is needed if we have two or more elementary unit to
connect to each other to form complex expression
 This is the basis for the generalized resolution inference procedure

24
Normal Forms of Logical expression
 Disjunctive normal form (DNF):
 disjunction of conjunction of literals.
Example (A  B) (C  D)

 Horn form: conjunction of literals implies a literal.


Example (A  B  C D)=>E

25
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

26
Modes Ponens
 There are a set of already identified 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
27
 Modes Ponens or implication elimination:
 The notation means that, whenever any sentences of
the form and a are given, then the sentence
can be inferred.
 And Elimination
 Is a rule of inference that allows us to derive conjuncts from
a conjunction. If a proof contains the conjunction of a 1 through an,
then we can deduce any of the conjuncts.

28
Generalized Resolution for PL

 Given any two clauses A and B, if there are any literal P 1 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 like
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
 Similarly
F: P  R  S from A and C
G: Q  M  R  S from F and B etc
29
Generalized Resolution for PL
 Resolution can also be used to prove a sentence whether it is valid or
not.
 That can be done using direct method or indirect method (refutation)
 For example Given a KB consists of the sentences
A: P  Q  R
B: ~P  R
C: ~Q
 We need to prove R
 Method One (Direct)
 Entail D: Q  R from A and B
 Entail E: R from D and C

Note: in order to apply resolution for proving a theory, make sure first
all the knowledge is in its clausal form

30
Generalized Resolution for PL
 Method Two (refutation)
 Insert the negation of the statement as valid sentence

A: P  Q  R
B: ~P  R
C: ~Q
D: ~ R
 Find fallacy in the KB that will indicate the added statement is invalid
so that its negation is valid
Entail E: Q  R from A and B
Entail F: R from C and E
Entail G: {} from D and F
An empty clause shows false. This proves the contradiction.

31
Generalized Resolution for PL
 Method Two (refutation) Graphical representation
 Insert the negation of the statement as valid sentence
A: P  Q  R
B: ~P  R
C: ~Q
D: ~ R

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

32
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)
33
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

34
What rule is used for the conclusion?

1. world population couldn’t continues to grow or cities will become


hopelessly crowed; Cities will not be hopelessly crowded, or pollution
will become intolerable. Therefore, world population couldn’t continues
to grow or pollution will become intolerable. 7
2. Either Yohanes or Thomas was in Ethiopia; Yohanes was not in
Ethiopia. Therefore, Thomas was in Ethiopia.6
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.1
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.1
5. If Napoleon was killed in a plane crash, then Napoleon is dead; Napoleon
is dead. Therefore, Napoleon was killed in a plane crash.
35
Logical equivalence (1)
 Two sentences are logically equivalent iff they have the same truth
value in all possible world
 Equivalently α ≡ ß iff α╞ β and β╞ α

36
Logical equivalence (2)

 Prove the following using logical equivalence


1. Prove that (P V H)   H)  P is valid
2. Prove that p  q p  q is valid
3. Prove that (pq)  p is a tautology
4. Prove that (pq)  q  pq is valid

37
Converting to CNF
 Converting the following sentence to CNF:
a ~b↔c
≡ (a  ~ b) ↔ c
 Steps:
1. Remove Bi-implication
[(a  ~ b)  c]  [c  (a  ~ b)]
2. Remove Implication
[~(a  ~ b)  c] [~c  (a  ~ b)]
3. Push Negations Inwards
[~a  ~~b  c]  [~c  (a  ~ b)]
4. Eliminate Double Negations
[~a  b  c]  [~c  (a  ~ b)]
5. Push Disjunctions into Conjunctions
[~a  b  c]  [~c  a] [~c  ~ b]

38
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)

39
Model

 Any world in which a sentence is true under a particular interpretation


is called model of that sentence under that interpretation
 We say m is a model of a sentence α if α is true in m
 M(α) is the set of all models of α
 Then KB ╞ α iff M(KB)  M(α)
 E.g. KB = Giants won and Reds won α = Giants won

40
Complexity of prepositional inference

 The worst case is exponential (2n).


 In this case we can prove using truth table

 Using inference rule we may minimize the time complexity.

 The use of inference rules depends on general principles of logic called mono-tonicity
 Monotonicity says that the set of entailed sentences can only increase as
information is added to the knowledgebase
 Monotonicity means that inference rules can be applied whenever
suitable premises are found in the knowledge base-the conclusion of the
rule must follow regardless of what else is in the knowledge base

 For any sentences α and β , if KB1 ╞ α then KB  β ╞ α

41

You might also like