Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Knowledge Representation
Knowledge can be defined as the body of facts and principles accumulated by
humankind or the act, or state of knowing.
Knowledge is having a familiarity with language, concepts, procedures, rules, ideas,
abstractions, places, customs, facts and associations coupled with an ability to use these
notions effectively in modeling different aspects of the world. Without this ability, the facts
and concepts are meaningless and therefore, worthless.
In biological organisms, knowledge is stored as complex structures of
interconnected neurons. The structures correspond to symbolic representations of the
knowledge possessed by the organism, the facts, rules, and so on. The average human brain
weights about 3.3 pounds and contains an estimated number of 10 12 neurons.
In computers, knowledge is also stored as symbolic structures, but in the form of
collections of magnetic spots and voltage states.
A common way to represent knowledge is in the form of written language.
For example,
1. John is tall.
2. Ram likes Sekhar.
3. Sam has learned to use recursion to manipulate linked lists in several
programming languages.
To truly understand and make use of the knowledge of one world, a person needs
other world knowledge and the ability to reason with it.
Knowledge may be declarative or procedural. Declarative knowledge is passive
knowledge expressed as statements of facts about the world. Procedural knowledge is
compiled knowledge related to the performance of some task.
Heuristic Knowledge
A special type of knowledge used to solve complex problems.
Heuristics are the knowledge used to make good judgments, strategies,
tricks, or “rules of thumb” used to the solution of problems.
Heuristics are acquired with much experience.
Thus, knowledge includes and requires the use of data and information. But it is
more. It combines relationships, correlations, dependencies.
Belief
It is any meaningful and coherent expression that can be represented. It can be true
or false.
Hypothesis
It is a justified belief that is not known to be true. It is a belief which is backed up
with some evidence, but it may still be false.
Thus, knowledge can be defined as true justified belief.
http://rajakishor.co.cc Page 2
Epistemology
It is the study of the nature of knowledge.
Metaknowledge
It is knowledge about knowledge, that is, knowledge about what we know.
K nowledge-based S ystems
The real power of an expert system comes from the knowledge it possesses rather
than the particular inference schemes and other formalisms it employs.
Knowledge-based systems get their power from the expert knowledge that has been
coded into facts, rules, heuristics, and procedures.
Components of knowledge-based systems
Here, the knowledge is stored in a knowledge base, which is separate from the
control and inferencing components. This makes it possible to add new knowledge or
refine existing knowledge without recompiling the control and inferencing programs.
http://rajakishor.co.cc Page 3
K nowledge R epresentation
Knowledge and reasoning are important for artificial agents because they enable
successful behaviors that would be very hard to achieve otherwise.
The knowledge of problem-solving agents is, however, very specific and inflexible.
Knowledge-based agents can benefit from knowledge expressed in very general forms,
combining and recombining information to suit myriad (a great number of) purposes.
Knowledge and reasoning play a crucial role in dealing with partially observable
environments. A knowledge-based agent can combine general knowledge with current
percepts to infer hidden aspects of the current state prior to selecting actions.
For example, a physician diagnoses a patient infers a disease state that is not
directly observable, prior to choosing a treatment. Some of the knowledge that the
physician uses in the form of rules learned from textbooks and teachers, and some is in the
form of patterns of association that the physician may not be able to consciously describe.
If it is inside the physician's head, it counts as knowledge.
http://rajakishor.co.cc Page 4
K nowledge-based A gents
The agent maintains a knowledge base, KB, which may initially contain some
background knowledge. Each time the agent program is called, it does two things. First, it
TELLS the knowledge base what it perceives. Second, it ASKS the knowledge base what
action it should perform. In the process of answering this query, extensive reasoning may
be done about the current state of the world, about the outcomes of possible action
sequences; and so on. Once the action is chosen, the agent records its choice with TELL and
executes the action. The second TELL is necessary to let the knowledge base know that the
hypothetical action has actually been executed.
T L he ogic
http://rajakishor.co.cc Page 5
In any case, statements in an agent’s knowledge base are real physical
configurations of the agent. Reasoning will involve generating and manipulating those
configurations.
A logic must also define the semantics of the language. The semantics refers to the
"meaning" of sentences. In logic, the definition is more precise. The semantics of the
language defines the truth of each sentence with respect to each possible world.
For example, the usual semantics adopted for arithmetic specifies that the sentence
"x + y =4" is true in a world where x is 2 and y is 2, but false in a world where x is 1 and y is
1. In standard logics, every statement must be either true or false in each possible world -
there is no "in between.”
The logical reasoning involves the relation of logical entailment between
statements. In mathematics, we write it as P Q, which means that the statement P entails
the statement Q, that is, the statement Q logically follows the statement P. This says that
whenever P is true Q must also be true.
http://rajakishor.co.cc Page 6
S yntax and S emantics for P ropositional L ogic
http://rajakishor.co.cc Page 7
Symbols used for logical connectives:
Symbol Meaning
~ For not or negation
& For AND or conjunction
V For OR or disjunction
For if … then or implies
For if and only if or double implication
Syntax:
The syntax of propositional logic is defined recursively as follows:
T and F are formals.
If P and Q are formals, the following are formals:
(~P)
(P & Q)
(P v Q)
(P Q)
(P Q)
All formals are generated from a finite number of the above operations.
The precedence given to the connectives from highest to lowest is ~, &, v, and .
Semantics:
The semantics or meaning of a sentence is just the value true or false. The values
true and false are not same as the truth values T and F that appear in a sentence.
An interpretation for a sentence or group of sentences is an assignment of a truth
value to each propositional symbol. For the sentence (P & ~Q), there can be four distinct
interpretations.
Once an interpretation has been given to a statement, its true value can be
determined.
If A is any statement, t and t’ denote any true statements, and f and f’ denote any
false statements – the semantic rules are summarized below:
http://rajakishor.co.cc Page 8
Rule No. True statement False statement
1. T F
2. ~f ~t
3. t&t’ f&A
4. tvA A&f
5. Avt fvf’
6. At tf
7. fA tf
8. T t’ ft
9. f f’
http://rajakishor.co.cc Page 9
P roperties of S tatements
Theorem: The sentence S is a logical consequence of S1, S2, …, Sn if and only if S1 & S2
& … & Sn S is valid.
Equivalence Laws:
1. Idempotency
PvP=P
P^P=P
2. Associativity
(P v Q) v R = P v (Q v R)
(P & Q) & R = P & (Q & R)
3. Commutativity
PvQ=QvP
P&Q=Q&P
PQQ P
http://rajakishor.co.cc Page 10
4. Distributivity
P & (Q v R) = (P & Q) v (P & R)
P v (Q & R) = (P v Q) & (P v R)
5. De Morgan’s Laws
( P Q) P Q
( P Q) P Q
6. Conditional elimination
P Q P Q
7. Bi-conditional elimination
P Q ( P Q) (Q P )
Theorem: The sentence S is a logical consequence of S1, S2, …, Sn if and only if S1 & S2
& … Sn & ¬S is inconsistent.
Proof:
We have,
S is a logical consequence of S1, S2, …, Sn if and only if
S1 & S2 & … Sn S is valid.
That is, ¬(S1 & S2 & … Sn S) is inconsistent.
But,
¬(S1 & S2 & … Sn S) = ¬(¬ (S1 & S2 & … Sn) v S) [by conditional elimination]
= ¬(¬ (S1 & S2 & … Sn)) & ¬S
= S1 & S2 & … Sn & ¬S which is inconsistent.
Hence the theorem.
One way to determine the equivalence of two sentences is by using truth tables.
Ex: Show that
(i) P Q is equivalent to ¬P v Q.
(ii) P Q is equivalent to ( P Q) (Q P) .
http://rajakishor.co.cc Page 11
I nference R ules
The inference rules of propositional logic provide the means to perform logical
proofs and deductions.
1. Modus Ponens
From P and P Q infer Q. This is written as
P
PQ
----------
Q
Ex:
given: Raj Likes fruits
and : (Raj likes fruits) (Raj likes mangoes)
conclusion: Raj likes mangoes
2. Chain Rule
From P Q and Q R, infer P R.
That is
PQ
QR
---------
PR
Ex:
given: (programmer likes C) (programmer hates COBOL)
and : (programmer hates COBOL) (programmer likes recursion)
conclusion: (programmer likes C) (programmer likes recursion)
3. Substitution
If s is a valid sentence, and s’ derived from s by consistent substitution of
proposition in s, then s’ is also valid.
Ex:
P v ¬P is valid; therefore Q v ¬Q is also valid.
4. Simplification
From P & Q infer P.
5. Conjunction
From P and from Q, infer P & Q.
6. Transposition
From P Q, infer ¬Q ¬P
http://rajakishor.co.cc Page 12
F ormal S ystems
A formal system is a set of axioms S and a set of inference rules L from which new
statements can be logically derived. We will denote a formal system as <S, L> or simply as a
KB (knowledge base).
Soundness:
Let <S, L> be a formal system. We say that the inference procedures L are sound if
and only if any statement s that can be derived from <S, L> is a logical consequence of <S,
L>.
Completeness:
Let <S, L> be formal system. Then the inference procedure L is a complete if and
only if any sentence s logically implied by <S, L> can be derived using that procedure.
Example:
Suppose S = {P, PQ} and L is the modus ponens rule. Then <S, L> is a formal
system, since Q can be derived from the system. Also, the system is both sound and
complete.
http://rajakishor.co.cc Page 13
3. Constants:
Numbers, words etc.
4. Variables:
Those that can be assigned any value.
5. Functions:
These denote relations defined on a domain D. They map n elements (n ≥ 0)
to a single element of the domain. An n-ary function is written a f(t1, t2, …, tn).
A 0-ary function is a constant.
6. Predicates:
Predicate symbols denote relations or functional mappings from the
elements of a domain D to the values TRUE or FALSE.
For example, P, Q, R, EQUAL etc.
Like functions, predicates may have n (n ≥ 0) terms for arguments written as
P(t1, t2, …, tn), where the terms ti are defined over some domain.
Constants, variables and functions are referred to as “terms” and predicates are
referred to as “atomic formulas” or “literals”.
Examples:
E1: All employees earning $1400 or more per year pay taxes.
E2: Some employees are sick today.
E3: No employee earns more than the president.
To represent such expressions in FOPL, we must define abbreviations for the
predicates and functions.
Abbreviation Meaning
E(X) X is an employee
P(X) X is president
i(x) Income of X
GE(u, v) u is greater than or equal to v
S(X) X is sick today
T(X) X pays tax
http://rajakishor.co.cc Page 14
Using the above abbreviations, we can represent E1, E2, and E3 as
E1' : x (( E ( x) & GE (i ( x),1400)) T ( x))
E 2 ' : x ( E ( x) S ( y ))
E 3' : xy (( E ( x) & P( y )) GE (i ( x), i ( y )))
Steps:
1. Indentify all atomic propositions in the given sentence.
2. Define symbols, predicates or functions for each such proposition.
3. Formulate compound predicate with the atomic predicates using logical
connectives.
The expressions E1’, E2’ and E3’ are known as well-formed formulas or WFFs.
WFFs are defined recursively as follows:
An atomic formula is a WFF.
If P and Q are WFFs, then ¬P, P & Q, P v Q, P Q, P Q,, x P(x), x P(x) are
WFFs.
WFFs are formed only by applying the above rules a finite number of times.
Some examples of WFFs:
MAN(John)
Pilot(father-of(Bill))
xyz (( FATHER( x, y ) & FATHER( y, z )) GRANDFATHER( x, z ))
x NUMBER( x) (y GREATER THAN ( y , x ))
Some examples of statements that are not WFFs:
P P( x) Q( x)
MAN (John)
father of (Q( x))
MARRIED( MAN , WOMAN )
Note: We use Upper case letters to denote predicates and lower case letters to
denote functions.
http://rajakishor.co.cc Page 15
If the truth values for two different WFFs are the same under every interpretation,
they are said to be equivalent.
A predicate (or WFF) that has no variable is called a “ground atom”.
When determining the truth value of a compound expression, we must be careful in
evaluating predicates that have variable arguments, since they evaluate to true only if they
are true for the appropriate values of the variables.
For example,
(i) In the predicate x P(x), P(x) is true only if it is true for every value of x in the
domain D.
(ii) The P(x) in x P(x) is true if it is true for at least one value of x in D.
If the above conditions are not satisfied, the predicate evaluates to false.
http://rajakishor.co.cc Page 16
Step2: Move all negations into individual atoms.
For example,
Use P in place of ¬(¬P)
and De Morgan’s laws
x F ( x) in place of (x) F ( x)
and x F ( x) in place of (x) F ( x) .
Step3: Rename variables if necessary so that all remaining quantifiers have different
variable assignments.
For example,
Replace x ( P( x) (x Q( x)))
by x ( P( x) (y Q( y))) .
Step4: Replace existentially quantified variables with special functions and
eliminate the corresponding quantifiers.
Step5: Drop all universal quantifiers and put the remaining expression into
conjunctive normal form (CNF). (Disjunctions are moved down to literals).
Step6: Drop all conjunction symbols writing each clause previously connected by
the conjunctions on a separate line.
I nference R ules
A key inference rule in FOPL is modus ponens.
Example:
If ‘a’ has a property P and all objects that have property P also have property Q, we
conclude that ‘a’ has property Q.
Assertion : P(a)
Implication: x P(x) Q(x)
-----------------------------
Conclusion: Q(a)
Note:
1. We can substitute a for x.
2. Substitution helps in simplifying the expressions.
3. The above can be written as P(a) Q(a).
4. If z can be substituted for y, it can be denoted as z/y.
http://rajakishor.co.cc Page 17
U nification (matching)
Bound – value has been assigned to variables.
Free – value not been assigned to variables.
Two predicates are said to unify (match) if the following three conditions are
satisfied:
1. They have same predicate value.
2. They have same number of arguments.
3. All pairs of corresponding arguments match.
The unification algorithm is based on condition 3. To check the 3 rd condition, we use
unification algorithm.
Unification Algorithm:
Step 1: Take the first pair of corresponding arguments.
Step 2: if both are constants
If the two constants are the same
then they match. Go to step-5.
Else, they do not match. Go to step-7.
Step 3: if both are variables
(a) If both are free
then bind them two each other.
Now, they match. Goto step-5.
(b) If both are bound
If two bound values are same
then they match. Goto step-5.
Else, they do not match. Goto step-7.
(c) If one is bound and the other is free
Bind the free variable to the same value of the bound variable.
Now, they match. Goto Step-5.
Step 4: if one is a constant and other is a variable
(a) If variable is free
Bind the variable to the constant.
Now, they match. Goto step-5.
(b) If variable is bound
If bounded value and the constant are same,
then they match. Goto step-5.
Else, they do not match. Goto step-7.
http://rajakishor.co.cc Page 18
Step 5: if no more arguments
The two predicates unify. End.
Step 6: if there are more arguments
Take the next pair of corresponding arguments. Goto step-2.
Step 7: The two predicates do not unify.
End.
T R he esolution P rinciple
The resolution principle is a systematic inference procedure which, when applied to
a set of clauses, determines if the set is unsatisfiable.
The process
is an inference process in predicate logic.
uses the method of proof by contradiction (reduction ad absurdum).
requires all facts to be in clausal form.
Principle:
If it is possible to draw conclusions from a given set of facts, all those facts are TRUE.
If it is unable to draw the conclusion, one or more facts are FALSE.
Process of resolution:
1. Let C1 and C2 be two clauses with no variables in common.
2. Let L1 and L2 are literals in C1 and C2 respectively.
3. L1 is a complement of L2.
4. Delete both L1 and L2.
5. Form a disjuncted C from the remaining reduced clauses.
6. The new clause C is called the resolution of C1 and C2.
http://rajakishor.co.cc Page 19
Resolution is the process of generating these resolvents from a set of clauses.
Example:
To resolve the two clauses
(¬P v Q) and (¬Q v R)
we write
¬P v Q , ¬Q v R
--------------------
¬P v R
¬P v Q is true and ¬Q v R is true, then ¬P v R is also true.
Types of resolution
1. Binary resolution
Two clauses having complementary literals are combined as disjuncts to produce a
single clause after deleting the complementary literals.
Example:
¬P(x, a) v Q(x) and ¬Q(b) v R(x)
¬P(x, a) v Q(b) and ¬Q(b) v R(x)
[b is substituted for x as Q and ¬Q are complementaries]
¬P(b, a) v Q(b) and ¬Q(b) v R(b)
[b is substituted for x]
¬P(b, a) v R(b) [by deleting the complementary literals]
http://rajakishor.co.cc Page 20
3. Linear resolution
When each resolved clause Ci is a parent to the clause Ci+1 (i = 1, 2, …, n-1) the
process is called linear resolution.
Example:
Given a set S of clauses with C0 S.
Cn is derived by a sequence of resolutions.
C1 is derived from C0 with some clause B0.
C2 is derived from C1 with some clause B1 and so on ... until Cn is derived.
http://rajakishor.co.cc Page 21
or
(b) Some predicate in the resolvent persists (does not get eliminated) even
after any iteration of steps 3 & 4 and unable to make progress.
Step6: If null resolvent (empty clause) is reached:
This is “contradiction”, i.e., unable to draw a conclusion.
This means, one or more facts in the given set are FALSE.
¬P is the only statement that can be FALSE.
Therefore, P must be TRUE.
Step7: If unable to progress:
We are able to draw conclusion from the given set of facts. So, all facts in that
set are TRUE, including ¬P.
Therefore, P must be FALSE.
Note: The empty clause [ ] is always false since no interpretation can satisfy it. It is derived
from combining contradictory clauses such as P and ¬P.
Example:
Known truths
1. One of Ravi, Raghu, Ramu and Rajesh is a spy.
2. Spies do not wear light-colored cloths and do not attract attention to themselves.
3. Ravi is not a spy.
4. Raghu likes wear light colored cloths.
5. Ramu was the main attraction in yesterday’s party.
Find out whether Rajesh is a spy using resolution.
Solution:
1. One of Ravi, Raghu, Ramu and Rajesh is a spy.
SPY(x): x is a spy.
SPY(Ravi) v SPY(Raghu) v SPY(Ramu) v SPY(Rajesh)
2. Spies do not wear light colored cloths and do not attract attention.
SPY(x): x is a spy
WLC(x): x wears light-colored clothes
AA(x): x attracts attention to himself.
Now, we have
http://rajakishor.co.cc Page 22
x SPY ( x) (WLC ( x) & AA( x))
x SPY ( x) (WLC ( x) & AA( x))
SPY ( x) (WLC ( x) & AA( x ))
(SPY ( x) WLC ( x)) & (SPY ( x) AA( x))
http://rajakishor.co.cc Page 23
SPY(Raghu) v SPY(Ramu) v ¬SPY(Raghu) v ¬WLC(Raghu)
SPY(Ramu) v ¬WLC(Raghu) --- (10)
Form (10) and (5) we get
SPY(Ramu) v ¬WLC(Raghu) v WLC(Raghu)
SPY(Ramu) --- (11)
From (11) and (3), we get
SPY(Ramu) v ¬SPY(y) v ¬AA(y)
Applying (y/Ramu)
SPY(Ramu) v ¬SPY(Ramu) v ¬AA(Ramu)
¬AA(Ramu) --- (12)
From (12) and (6), we get
¬AA(Ramu) v AA(Ramu)
[]
The assumption ¬SPY(Rajesh) resulted in FALSE conclusion.
¬SPY(Rajesh) is false.
SPY(Rajesh) is true.
Rajesh is spy.
http://rajakishor.co.cc Page 24