You are on page 1of 28

UNIT II

KNOWLEDGE REPRESENTATION AND REASONING


Proposition Logic – First Order Predicate Logic – Unification – Forward Chaining -Backward Chaining –
Resolution – Knowledge Representation – Ontological Engineering – Categories and Objects – Events –
Mental Events and Mental Objects – Reasoning Systems for Categories – Reasoning with Default
Information – Prolog Programming.

PROPOSITIONAL LOGIC
A proposition is a declarative statement that’s either TRUE or FALSE (but not both).
Propositions Not Propositions
3 + 2 = 32 Bring me coffee!
CS173 is Bryan’s favorite class. CS173 is her favorite class.
Every cow has 4 legs. 3+2
There is other life in the universe. Do you like Cake?

• The symbols of the language:


• Propositional symbols (Prop): A, B, C,…
• Connectives:
•  and
•  or
•  not
•  implies
•  equivalent to
•  xor (different than)
• , > False, True
• Parenthesis :(,).

Propositional Logic Semantics


Negation
 Truth tables define the semantics (=meaning) of the operators
Suppose p is a proposition.
The negation of p is written p and has meaning:
“It is not the case that p.”
 Ex. TFCS is NOT Bryan’s favorite class.
P p
T F
F T
Conjunction
Conjunction corresponds to English “and.”
 p  q is true exactly when p and q are both true.
 Ex. Amy is curious AND clever.
p Q pq
T T T
T F F
F T F
F F F

Disjunction
Disjunction corresponds to English “or.”
 p  q is when p or q (or both) are true.
 Ex. Michael is brave OR nuts.
p Q pq
T T T
T F T
F T T
F F F

Implication
Implication: p  q corresponds to English “if p then q,” or “p implies q.”
 If it is raining then it is cloudy.
 If there are 200 people in the room, then I am the Easter Bunny.
 If p then 2+2=4.
p Q pq
T T T
T F F
F T T
F F T
Propositional Logic: Truth Tables
Truth table for different connectives for Negation, Disjunction (AND), Conjunction (OR), Condition,
Bicondition, NAND, NOR, XOR

Propositional Logic - special definitions

Contrapositives: p  q and q  p
 Ex. “If it is noon, then I am hungry.”
“If I am not hungry, then it is not noon.”
Converses: p  q and q  p
 Ex. “If it is noon, then I am hungry.”
“If I am hungry, then it is noon.”
Inverses: p  q and p  q
 Ex. “If it is noon, then I am hungry.”
“If it is not noon, then I am not hungry.”

Propositional Logic: Logical Equivalences


• Identity
pT p
pF p
• Domination
pTT
p FF
• Idempotence
pp p
pp p
• Double negation
p p
• Commutativity:
p  q q  p
p  q q  p
• Associativity:
(p  q)  r  p  ( q  r )
(p  q)  r  p  ( q  r )
• Distributive:
p  (q  r)  (p  q)  (p  r)
p  (q  r)  (p  q) (p  r)
• De Morgan’s:
(p  q)  p  q (De Morgan’s I)
(p  q)  p  q (De Morgan’s II)
• Excluded Middle:
p  p  T
• Uniqueness:
p  p  F
• A useful Logical Equivalence (LE) involving :
p  q  p  q
Clause- a special form
Literal
A single proposition and its negation. eg., p, p
Clause
A clause is a disjunction of literals.
Eg., PQR
Converting a compound proposition to the clausal form
Consider the sentence
(AB) (CA)
1. Eliminate implication sign
(AB) (CA)
2. Eliminate the double negation and reduce scope of “not sign” (De-Morgans Law)
(A B) (CA)
3. Convert to conjunctive normal form by using distributive and associative laws
(AC A)  (BCA)
4. Get the set of clauses
(AC)
(BCA)

RESOLUTION
Resolution is a procedure used in proving that arguments which are expressible in predicate logic are
correct. Resolution is a procedure that produces proofs by refutation or contradiction. Resolution leads to
refute a theorem-proving technique for sentences in propositional logic and first order logic. Resolution is
a rule of inference. Resolution is a computerized theorem prover
Algorithm: Propositional Resolution
Let F be a set of axioms and P the theorem to prove.
1. Convert all the propositions of F to clause form.
2. Negate P and convert the result to clause form. Add it to the set of clauses obtained in step 1.
3. Repeat until either a contradiction is found or no progress can be made
(a) Select two clauses. Call these the parent clauses.
(b) Resolve them together. The resulting clause called the resolvent, will be the disjunction of all
of the literals of both of the parent clauses with the following exception: If there are any pair of
literals L and L such that one of the parent clauses contains L and the other contains L, then
select one such pair and eliminate both L and L from the resolvent.
(c) If the resolvent is the empty clause, then a contradiction has been found. If it is not, then add
it to the set of clauses available to the procedure.
Example 1
1. If a triangle is equilateral then it is isosceles.
2. If a triangle is isosceles the two sides AB and AC are equal.
3. If AB and AC are equal then angle B and angle C are equal.
4. ABC is an Equilateral triangle.
Prove “Angle B is equal to angle C”
Propositional Logic
4. Equilateral(ABC)
1. Equilateral(ABC)Isosceles(ABC)
2. Isosceles(ABC)Equal(AB,AC)
3. Equal(AB,AC) Equal(B,C)
Convert to clausal form
1. Equilateral(ABC) Isosceles(ABC)
2. Isosceles(ABC) Equal(AB,AC)
3. Equal(AB,AC)  Equal(B,C)
4. Equilateral(ABC)
To prove ” Equal (B,C)”. Let us disprove “Not equal B and C Equal (B,C)”

Equal (B,C) . Equal(AB,AC)  Equal(B,C)

Isosceles(ABC) Equal(AB,AC) Equal(AB,AC)

Equilateral(ABC) Isosceles(ABC) Isosceles(ABC)

Equilateral(ABC) Equilateral(ABC)

None
Thus we proved that angle B is equal to angle C

Example 2
1. Mammals drink milk.
2. Man is mortal.
3. Man is mammal.
4. Tom is a man.

Prove “Tom drinks milk” and Prove “Tom is mortal”


Propositional Logic
1. Mammal(Tom)drink(Tom, Milk)
2. Man(Tom)Mortal(Tom)
3. Man(Tom)Mammal(Tom)
4. Man(Tom)
Convert to clausal form
1. Mammal(Tom) drink(Tom, Milk)
2. Man(Tom) Mortal(Tom)
3. Man(Tom) Mammal(Tom)
4. Man(Tom)
To prove ” Tom drinks milk”
Let us disprove “Not Tom drinks milk”“Drink (Tom, Milk)”
Mammal(Tom) drink(Tom, Milk) . Drink (Tom, Milk)

Man(Tom) Mammal(Tom) Mammal(Tom)

Man(Tom) Man(Tom)

None
Thus we proved “Tom drinks Milk”
ii) To prove ” Tom is Mortal”Mortal(Tom)
Let us disprove “Not Tom is Mortal” Mortal(Tom)

Man(Tom) Mortal(Tom) . Mortal(Tom)

Man(Tom) Man(Tom)

None
Thus we proved “Tom is Mortal”:
Disadvantage: Propositional logic only deals with finite number of propositions.

PREDICATE LOGIC OR FIRST ORDER LOGIC


Definition: A predicate is an expression of one or more variables defined on some specific domain. A
predicate with variables can be made a proposition by either assigning a value to the variable or by
quantifying the variable.
FOL or predicate logic is a generalization of propositional logic that allows us to express and
infer arguments in infinite models like
 All men are mortal
 Some birds cannot fly
Predicates are like functions except that their return type is true or false.
A predicate with no variable is a proposition.
Syntax of First-Order Logic
 Constants KingJohn, 2, …
 Predicates/Relation Brother, >, …
 Functions Sqrt, LeftArmOf, …
 Variables x, y, a, b, …
 Connectives ¬
 Equality =
 Quantifiers $"
Components of First-Order Logic
 Term
 Constant, e.g. Red
 Function of constant, e.g. Color(Block1)
 Atomic Sentence
 Predicate relating objects (no variable)
 Brother (John, Richard)
 Married (Mother(John), Father(John))
 Complex Sentences
 Atomic sentences + logical connectives
 Brother (John, Richard) Brother (John, Father(John))
 Quantifiers
 Each quantifier defines a variable for the duration of the following expression, and
indicates the truth of the expression…
 Universal quantifier “for all” 
 The expression is true for every possible value of the variable
 Existential quantifier “there exists” 
 The expression is true for at least one value of the variable
Examples
1. Some dogs bark.
∃x dog(x)  bark(x)
2. All dogs have four legs.
∀x(dog(x)have_four_legs(x))
(or)
∀x(dog(x)legs(x,4))
3. All barking dogs are irritating
∀x(dog(x) barking(x)irritating(x))
4. No dogs purr.
∃x (dog(x)  purr(x))
5. Fathers are male parents with children.
∀x(father(x)male(x)  haschildren(x))
6. Students are people who are enrolled in courses.
∀x(student(x)enrolled(x, courses))

RESOLUTION:
A resolution inference step chooses two clauses having the property that one contains a disjunction X (a
positive literal) and the other contains a disjunct ¬X (a negative literal), these disjuncts are known as
complementary.
ALGORITHM: RESOLUTION-PREDICATE LOGIC
1. Convert all the statements of F to clause form.
Clausal form is a subset of first order logic. It is a normal form in which a sentence is defined by an
universal prefix (a string of universal quantifiers) and a matrix (a quantifier-free conjunction of a clause).
2. Negate P and convert the result to clause form. Add it to the set of clauses obtained in step 1.
3. Repeat until either a contradiction is found or no progress can be made
(a) Select two clauses. Call these the parent clauses.
(b) Resolve them together. The resolvent will be the disjunction of all the literals of both parent
clauses with appropriate substitutions performed and with the following exceptions: If there is
one pair of literals T1 and ¬T2 such that one of the parent clause contains T2 and the other
contains t1 and if t1 and t2 are unifiable, then neither T1 nor T2 should appear in the resolvent.
We call T1 and T2 as complementary literals. Use the substitution produced by the unificationto
create the resolvent. If there is more than pair of complementary literals, only one pair should be
omitted from the resolvent.
(c) If the resolvent is the empty clause, then a contradiction has been found. If it is not, then add it
to the set of clauses available to the procedure.

There exists a procedure for making the choice that can speed up the process considerably
 Only resolve pairs of clauses that contain complementary literals
 Eliminate certain clauses as soon as they are generated so that they cannot participate in later
resolutions.
 Whenever possible resolve either with one of the clauses that is part of the statement we are
trying to refute or with clause generated by a resolution with such clause. This is called set of
support strategy
 Whenever possible resolve with clauses that have a single literal. Such resolution generate new
clauses with fewer literals. This is called unit preference strategy.
Algorithm: Predicate to Clausal Form Conversion
1- Eliminate the implication (→)
2- Move the negation down to the atomic formulas (by using the following rules)
3- Purge existential quantifiers The function that is eliminate the existential are called “ Skolem
function”
4- Rename variables, as necessary, so that no two variables are the same
5- Move the Universal quantifiers to the left of the statement.
6- Move the disjunction down to the literals, using distributive laws
7- Eliminate the conjunctions
8- Rename all the variables, as necessary, so that no two variables are the same.
9- Eliminate the universal quantifiers.

Problem 1
1. All people who are graduating are happy.
2. All happy people smile.
3. Someone is graduating.
4. Conclusion: Is someone smiling?

Solution:
Convert the sentences into predicate Logic
1. ∀x graduating(x)happy(x)
2. ∀x happy(x)smile(x)
3. ∃x graduating(x)
4. ∃x smile(x)

Convert to clausal form


(i) Eliminate the  sign
1. ∀xgraduating(x) happy(x)
2. ∀xhappy(x) smile(x)
3. ∃x graduating(x)
4. ∃x smile(x)
(ii) Reduce the scope of negation
1. ∀xgraduating(x) happy(x)
2. ∀xhappy(x) smile(x)
3. ∃x graduating(x)
4. ∀x  smile(x)
(iii) Standardize variables apart
1. ∀xgraduating(x) happy(x)
2. ∀yhappy(y) smile(y)
3. ∃x graduating(z)
4. ∀w  smile(w)
(iv) Move all quantifiers to the left
1. ∀xgraduating(x) happy(x)
2. ∀yhappy(y) smile(y)
3. ∃x graduating(z)
4. ∀w  smile(w)
(v) Eliminate ∃
1. ∀xgraduating(x) happy(x)
2. ∀xhappy(y) smile(y)
3. graduating(name1)
4. ∀w  smile(w)
(vi) Eliminate ∀
1. graduating(x) happy(x)
2. happy(y) smile(y)
3. graduating(name1)
4.  smile(w)
(vii) Convert to conjunct of disjuncts form.
(viii) Make each conjunct a separate clause.
(ix) Standardize variables apart again.

happy(y) smile(y)  smile(w)

graduating(x) happy(x) happy(y)

. graduating(name1) graduating(x)

None
Thus, we proved someone is smiling.

Problem 2
Explain the unification algorithm used for reasoning under predicate logic with an example.
Consider the following facts
a. Team India
b. Team Australia
c. Final match between India and Australia
d. India scored 350 runs, Australia scored 350 runs, India lost 5 wickets, Australia lost 7
wickets.
e. The team which scored the maximum runs wins.
f. If the scores are same the team which lost minimum wickets wins the match.
Represent the facts in predicate, convert to clause form and prove by resolution “India wins the
match”.
Solution:
Convert in to predicate Logic
(a) team(India)
(b) team(Australia)
(c) team(India)  team(Australia)final_match(India, Australia)
(d) score(India,350)  score(Australia,350) wicket(India,5)  wicket(Australia,7)
(e) ∃x team(x)  wins(x)score(x, max_runs))
(f) ∃xy score(x,equal(y))  wicket(x, min) final_match(x,y)win(x)

Convert to clausal form


(i) Eliminate the  sign
(a) team(India)
(b) team(Australia)
(c)  (team(India)  team(Australia))  final_match(India, Australia)
(d) score(India,350)  score(Australia,350) wicket(India,5)  wicket(Australia,7)
(e) ∃x  (team(x)  wins(x)) score(x, max_runs))
(f) ∃xy  (score(x,equal(y))  wicket(x, min) final_match(x,y)) win(x)
(ii) Reduce the scope of negation
(a) team(India)
(b) team(Australia)
(c)  team(India)  team(Australia)  final_match(India, Australia)
(d) score(India,350)  score(Australia,350) wicket(India,5)  wicket(Australia,7)
(e) ∃x  team(x)  wins(x) score(x, max_runs))
(f) ∃xy  score(x,equal(y)) wicket(x, min_wicket) final_match(x,y)) win(x)
(iii) Standardize variables apart
(iv) Move all quantifiers to the left
(v) Eliminate ∃
(a) team(India)
(b) team(Australia)
(c)  team(India)  team(Australia)  final_match(India, Australia)
(d) score(India,350)  score(Australia,350) wicket(India,5)  wicket(Australia,7)
(e)  team(x)  wins(x) score(x, max_runs))
(f)  score(x,equal(y)) wicket(x, min_wicket) final_match(x,y)) win(x)

(vi) Eliminate ∀
(vii) Convert to conjunct of disjuncts form.
(viii) Make each conjunct a separate clause.
(a) team(India)
(b) team(Australia)
(c)  team(India)  team(Australia)  final_match(India, Australia)
(d) score(India,350)
score(Australia,350)
wicket(India,5)
wicket(Australia,7)
(e)  team(x)  wins(x) score(x, max_runs))
(f)  score(x, equal(y)) wicket(x, min_wicket) final_match(x, y)) win(x)
(ix) Standardize variables apart again.
To prove: win(India)

Disprove: win(India)
 score(x, equal(y)) wicket(x, min_wicket) final_match(x, y)) win(x) win(India)

 team(India)  team(Australia)  final_match(India, Australia)  score(x, equal(y))


wicket(x,min_wicket)
final_match(x, y))

team(India)
 team(India)  team(Australia)
score(x,equal(y))wick
et(x, min_wicket)

team(Australia) team(Australia) score(x, equal(y))  wicket(x,


min_wicket)

score(India,350) score(x, equal(y))  wicket(x, min_wicket)

wicket(India,5) wicket(x, min_wicket)

None
Thus, proved India wins match.

Problem 3
Consider the following facts and represent them in predicate form:
F1. There are 500 employees in ABC company.
F2. Employees earning more than Rs. 5000 pay tax.
F3. John is a manager in ABC company.
F4. Manager earns Rs. 10,000.
Convert the facts in predicate form to clauses and then prove by resolution: “John pays tax”.
Solution:
Convert in to predicate Logic
1. company(ABC) employee(500,ABC)
2. ∃x company(ABC) employee(x, ABC) earns(x,5000)pays(x, tax)
3. manager(John, ABC)
4. ∃x manager(x, ABC)earns(x,10000)
Convert to clausal form
(i) Eliminate the  sign
1. company(ABC) employee(500,ABC)
2. ∃x (company(ABC) employee(x, ABC) earns(x,5000))  pays(x, tax)
3. manager(John, ABC)
4. ∃x manager(x, ABC)  earns(x, 10000)
(ii) Reduce the scope of negation
1. company(ABC) employee(500,ABC)
2. ∃x company(ABC) employee(x, ABC) earns(x,5000)  pays(x, tax)
3. manager(John, ABC)
4. ∃x manager(x, ABC)  earns(x, 10000)
(iii) Standardize variables apart
1. company(ABC) employee(500,ABC)
2. ∃x company(ABC) employee(x, ABC) earns(x,5000)  pays(x, tax)
3. manager(John, ABC)
4. ∃y manager(x, ABC)  earns(y, 10000)
(iv) Move all quantifiers to the left
(v) Eliminate ∃
1. company(ABC) employee(500,ABC)
2.  company(ABC) employee(x, ABC) earns(x,5000)  pays(x, tax)
3. manager(John, ABC)
4. manager(x, ABC)  earns(y, 10000)
(vi) Eliminate ∀
(vii) Convert to conjunct of disjuncts form.
(viii) Make each conjunct a separate clause.
1. (a)company(ABC)
(b)employee(500,ABC)
2.  company(ABC) employee(x, ABC) earns(x,5000)  pays(x, tax)
3. manager(John, ABC)
4. manager(x, ABC)  earns(y, 10000)
(ix) Standardize variables apart again.
Prove :pays(John, tax)
Disprove: pays(John, tax)

 company(ABC) employee(x, ABC) earns(x,5000)  pays(x, tax) pays(John, tax)

manager(x, ABC)  earns(y, 10000)  company(ABC) employee(x,ABC)


earns(x,5000)

manager(John, ABC) manager(x, ABC) company(ABC)


employee(x, ABC)

company(ABC) company(ABC) employee(x, ABC)

employee(500,ABC) employee(x, ABC)

None
Thus, proved john pays tax.
Problem 4
If a perfect square is divisible by a prime p then it is also divisible by square of p.
Every perfect square is divisible by some prime.
36 is a perfect square.
Convert in to predicate Logic
1. ∀xy perfect_sq(x) prime(y) divides(x,y)divides(x,square(y))
2. ∀x∃y perfect_sq(x) prime(y) divides(x,y)
3. perfect_sq(36)

Problem 5
1. Marcus was a man
man(Marcus)
2. Marcus was a Pompeian
Pompeian(Marcus)
3. All Pompeians were Romans
∀x (Pompeian(x) Roman(x))
4. Caesar was a ruler
ruler(Caesar)
5. All Romans were either loyal to Caesar or hated him
∀x (Roman(x) loyalto(x,Caesar)  hate(x,Caesar))
6. Everyone is loyal to someone
∀x ∃y (person(x)  person(y)  loyalto(x,y))
7. People only try to assassinate rulers they are not loyal to
∀x ∀y (person(x)  ruler(y)  tryassassinate(x,y) ¬loyalto(x,y))
8. Marcus tried to assassinate Caesar
tryassassinate(Marcus, Caesar)
9. All men are persons
∀x (man(x)  person(x))

UNIFICATION ALGORITHM
When attempting to match 2 literals, all substitutions must be made to the entire literal. There
may be many substitutions that unify 2 literals, the most general unifier is always desired

1. Initial predicate symbols must match.


2. For each pair of predicate arguments:
– different constants cannot match.
– a variable may be replaced by a constant.
– a variable may be replaced by another variable.
– a variable may be replaced by a function as long as the function does not contain an instance of the
variable

Algorithm :Unify(L1,L2)
1. If L1 or L2 are both variables or constants, then:
(a) If L1 and L2 are identical, then return NIL.
(b) Else if L1 is a variable, then if L1 occurs in L2 the return {FAIL}, else return (L2/L1).
(c) Else if L2 is a variable, then if L2 occurs in L1 the return {FAIL}, else return (L1/L2).
(d) Else return {FAIL}
2. If the initial predicate symbols in L1 and L2 are not identical, the return {FAIL}.
3. If L1 and L2 have a different number of arguments, then return {FAIL}.
4. Set SUBST to NIL.
5. For i1 to number of arguments in L1:
(a) Call Unify with the ith argument of L1 and the ith argument of L2, putting result in S.
(b)If s contains FAIL then return {FAIL}
(c) If S is not equal to NIL then:
(i) Apply S to the remainder of both L1 and L2
(ii) SUBST=APPEND(S,SUBST).
6. Return SUBST.

Example
P(x) and P(y) :substitution = (x/y)
• P(x,x) and P(y,z) : (z/y)(y/x)
• P(x,f(y)) and P(Joe,z) : (Joe/x, f(y)/z)
• P(f(x)) and P(x) : can’t do it!
• P(x) Ú Q(Jane) and P(Bill)  Q(y): (Bill/x, Jane/y)

FORWARD CHAINING
Forward chaining is one of the two main methods of reasoning when using an inference engine and can
be described logically as repeated application of modus ponens. Forward chaining is a popular
implementation strategy for expert systems, business and production rule systems. Forward chaining is
also known as data driven approach. Forward chaining starts with the facts and see what rules apply.

Facts are held in the working memory (ie., contains the current state of the world). Rules represent the
action to be taken when specified facts occur in the working memory. The actions involve adding or
deleting facts from the working memory.
Algorithm: Forward chaining
i) Collect the rules whose conditions match facts in working memory.
ii) If more than one rule matches then
(a) Use conflict resolution strategy to select the rules.
iii) Do the actions indicated by the rules. ie add facts to working memory or delete facts from working
memory.
iv) Repeat these steps until the goal is reached or no condition match found.\

Example
Rule R1: IF hot and smoky THEN fire
Rule R2: IF alarm_beeps THEN smoky
Rule R3: IF fire THEN switch_on_sprinklers

Fact F1: alarm_beeps (Given)


Fact F2: hot (Given)

Inference
Rule R1: IF hot and smoky THEN fire
Rule R2: IF alarm_beeps THEN smoky
Rule R3: IF fire THEN switch_on_sprinklers

Fact F1: alarm_beeps (Given)


Fact F2: hot (Given)
Fact F3: smoky (Added)
Fact F4: fire (Added)
Fact F5: switch_on_sprinklers (Added)

Suppose that we know the facts A, B, C, D, E and the rules shown in the knowledge base to the left
What facts can we infer from this?

After inferring facts X, L, Y and Z there are no more rules that can be fired.

Properties of forward chaining


 All rules which can fire do fire.
 Can be inefficient, which lead to spurious rule firing, unfocussed problem solving.
 Set of rules that can fire known as conflict set.
 Decision about which rule to fire is conflict resolution.

BACKWARD CHAINING
This is also called goal driven approach. A desired goal is placed in working memory, inference
cycle attempts to find evidence to prove it.
The knowledge base (rule base) is searched for rules that might lead to goal. If condition of such rule
matches fact in working memory then rule is fired and goal is proved.
Backward chaining means reasoning from goals to facts. Rules and facts are processed using
backward chaining interpreter.
Algorithm: Backward Chaining
i) Prove goal G.
ii) if G is the initial fact, it is proven.
iii) Otherwise, find a rule which can be used to conclude G, and try to prove each of the rules conditions.
Example 1
Rule R1: IF hot and smoky THEN fire
Rule R2: IF alarm_beeps THEN smoky
Rule R3: IF fire THEN switch_on_sprinklers

Fact F1: alarm_beeps (Given)


Fact F2: hot (Given)

Goal: Should I switch_on_sprinklers

Suppose that we know the facts A, B, C, D, E and the rules shown in the knowledge base to the
left. Can we infer the fact Z?

Backward chaining inferred Z from the facts and rules that were available.
Advantages
 Most efficient to infer one particular fact.
 User may be asked to input additional facts

KNOWLEDGE REPRESENTATION
A good system for the representation of structured knowledge in a particular domain should possess the
following four properties:
(i) Representational Adequacy:- The ability to represent all kinds of knowledge that are needed in that
domain.
(ii) Inferential Adequacy:- The ability to manipulate the represented structure to derive new structures
corresponding to the new knowledge inferred from old.
(iii) Inferential Efficiency:- The ability to incorporate additional information into the knowledge
structure that can be used to focus the attention of the inference mechanisms in the most promising
directions.
(iv) Acquisitional Efficiency :- The ability to acquire new knowledge using automatic methods wherever
possible rather than reliance on human intervention.

KNOWLEDGE REPRESENTATION SCHEMES


There are four types of knowledge representation
 Relational Knowledge
 Inheritable Knowledge
 Inferential Knowledge
 Procedural Knowledge
(i) Relational Knowledge
Relational knowledge provides a frame work to compare two objects based on equivalent
attributes. This knowledge associates element of one domain with another domain. Relational knowledge
is made up of objects consisting of attributes as their corresponding associated values. The results of this
knowledge type is mapping of elements among different domains.
The table below shows a simple way to store facts. The facts about the set of objects are put
systematically in columns.

Given the fact that it is not [possible to answer a simple question such as “Who is the heaviest
player?”. But, if the procedure for finding the heaviest player is provided, then these facts will be enable
that procedure to compute an answer. This representation provides only little opportunity for inference.

(ii) Inheritable Knowledge


Inheritable knowledge is obtained from associated objects. It describes a structure in which new
objects are created which may inherit all or subset of attributes from existing objects.

Inheritable knowledge representation


The directed arrow represent attributes originates at object being described and terminates at
object or its value. The box nodes represent objects and values of the attributes.
Viewing node as a frame: Baseball Player
isa :Adult-Male
bats : Equal to handed
height : 6.1
bating average:0.252
Algorithm: Property of Inheritance
The steps for retrieving a value v for an attribute A of an instance object O
i) Find object O in the knowledge base.
ii) If there is a value for the attribute A, then report that value.
iii) Otherwise, see if there is a value for the attribute instance. If not then fail.
iv) Otherwise, move to the node corresponding to that value and look for a value for the attribute
A. If one is found, report it.
v) Otherwise, do until there is no value for the isa attribute or until an answer is found.
(a) Get the value of “isa” attribute and move to that node.
(b) See if there is a value for the attribute A; If yes, report it.

Team(Pee-Wee-Reese)=Brooklyn Dodger
Batting average(Three finger Brown)=0.106
Height(Pee-Wee-Reese)=6.1
Bats(Three finger Brown)=right
iii) Inferential Knowledge
Inferential knowledge is inferred from objects through relations among objects. A word alone is a
simple syntax, but with the help of other words in phrase the reader may infer more from a word; this
inference with in linguistic is called semantics.
This knowledge generates new information from the given information. This information does
not require further data gathering from source, but does require analysis of the given information to
generate a new knowledge.
Example
Given a set of values and relations, one may infer other values or relations. Predicate logic is used
to infer from a set of attributes. Inference from a predicate logic uses a set of logical operations to relate
individual data.
i) Wonder is a name of a dog.
Dog(Wonder)
ii) All dogs belong to the class of animals.
∀x:dog(x) animal(x)
iii) All animals either live on land or in water.
∀x:animal(x) live(x, land) ∨ live(x, water)
From these three statements we infer that
Wonder lives either on land or on water
iv) Procedural Knowledge
Procedural Knowledge specifies what to do when. The procedural knowledge is represented in
program in many ways. The machine uses the knowledge when it executes the code to perform a task.
Example: A parser in a natural language has the knowledge that a noun phrase may contain articles
adjectives and nouns. Thus accordingly call routines that know how to process articles, adjectives and
nouns.

ONTOLOGICAL ENGINEERING
An ontology defines a common vocabulary for researchers who need to share information in a
domain. It includes machine-interpretable definitions of basic concepts in the domain and relations among
them.
Ontology is a branch of philosophy studying entities that exist, their classification, and the
relations between them. The types of entities are physical objects, abstract objects, time, locations,
actions, events and beliefs.
Upper ontology which consists of very general terms (such as "object", "property", "relation")
that are common across all domains. Upper ontology is the convention of drawing graphs with the general
concepts at the top and the more specific concepts below them

Differences with Special-Purpose Ontologies


 A general-purpose ontology should be applicable in more or less any special-purpose domain
(with the addition of domain-specific axioms).
 In any sufficiently demanding domain, different areas of knowledge must be unified, because
reasoning and problem solving could involve several areas simultaneously.

CATEGORIES AND OBJECTS


The organization of objects into categories is a vital part of knowledge representation. Although
interaction with the world takes place at the level of individual objects, much reasoning takes place at the
level of categories.
For example, a shopper would normally have the goal of buying a basketball, rather than a particular
basketball such as BB9.
Categories also serve to make predictions about objects once they are classified. There are two
choices for representing categories in first-order logic: predicates and objects. Categories serve to
organize and simplify the knowledge base through inheritance. If we say that all instances of the
category Food are edible, and if we assert that Fruit is a subclass of Food and Apples is a subclass of
Fruit, then we can infer that every apple is edible.
Subclass relations organize categories into a taxonomy, or taxonomic hierarchy. Taxonomies
have been used explicitly for centuries in technical fields. The largest such taxonomy organizes about 10
million living and extinct species.
First-order logic makes it easy to state facts about categories, either by relating objects to
categories or by quantifying over their members. Here are some types of facts, with examples of each:

FIRST ORDER LOGIC AND EXAMPLE


CATEGORIES
An object is a member of a category BB9 ∈ Basketballs
A category is a subclass of another category Basketballs ⊂ Balls
All members of a category have some properties (x∈ Basketballs) ⇒ Spherical(x)
All members of a category can be recognized by Orange(x) ∧ Round(x) ∧ Diameter(x) = 9.5 ∧ x∈ Balls
some properties ⇒ x∈ Basketballs
A category as a whole has some properties Dogs ∈ DomesticatedSpecies

Relations between Categories


1. Disjoint
Two or more categories are disjoint if they have no members in common:
Disjoint(s) ⇔ (∀c1, c2 c1∈s ∧ c2∈s ∧ c1 ≠ c2 ⇒ Intersection (c1, c2) = {})
Example: Disjoint ({animals, vegetables})
2. Exhaustive decomposition
A set of categories s constitutes an exhaustive decomposition of a category c if all members of the set c
are covered by categories in s:
ED (s, c) ⇔ (∀i i∈c ⇒ ∃c2 c2∈s ∧ i∈c2)
Example: Exhaustive Decomposition ({Americans, Canadian, Mexicans}, North Americans).
3. Partitioning
A disjoint exhaustive decomposition is known as a partition.
Partition(s, c) ⇔ Disjoint(s) ∧ ED(s, c)
Example: Partition ({Males, Females}, Persons).
Categories can be defined by providing necessary and sufficient conditions for membership
Example: ∀ x Bachelor(x) ⇔ Male(x) ∧ Adult(x) ∧ Unmarried(x)

Physical Composition
The idea that one object can be part of another.

The general PartOf relation to say that one thing is part of another. Objects can be grouped into PartOf
hierarchies, reminiscent of the Subset hierarchy:
PartOf (Bucharest, Romania)
PartOf (Romania, EasternEurope)
PartOf (EasternEurope, Europe)
PartOf (Europe, Earth)
The PartOf relation is transitive and reflexive; that is, PartOf (x, y) ∧ PartOf (y, z) ⇒ PartOf (x, z)
Therefore, we can conclude PartOf (Bucharest, Earth).

Categories of composite objects are often characterized by structural relations among parts. For example,
a biped has two legs attached to a body:

Biped(a) ⇒ ∃l1,l2,b Leg(l1) ∧ Leg(l2) ∧ Body(b) ∧ PartOf (l1, a) ∧ PartOf (l2, a) ∧ PartOf (b, a) ∧
Attached(l1, b) ∧ Attached(l2, b) ∧ l1 ≠ l2 ∧ [∀ l3 Leg(l3) ∧ PartOf (l3, a) ⇒ (l3 = l1 ∨ l3 = l2)] .

Natural Kinds
Some categories have strict definitions: an object is a triangle if and only if it is a polygon with
three sides. On the other hand, most categories in the real world have no clear-cut definition; these are
called natural kind categories.
For example, tomatoes tend to be a dull scarlet; roughly spherical; with an indentation at the top
where the stem was; about two to four inches in diameter; with a thin but tough skin; and with flesh,
seeds, and juice inside. There is, however, variation. This poses a problem for a logical agent. The agent
cannot be sure that an object it has perceived is a tomato. One useful approach is to separate what is true
of all instances of a category from what is true only of typical instances. So in addition to the category
Tomatoes, we will also have the category
Typical (Tomatoes)
Most knowledge about natural kinds will actually be about their typical instances:
x ∈ Typical(Tomatoes)  Red(x) Spherical(x).

Measurements
In both scientific and commonsense theories of the world, objects have height, mass, cost, and so on.
The values that we assign for these properties are called measures. Length has different names in our
language. We represent the length with a units function that takes a number as argument. If the line
segment is called L1, we can write
Length (L1) = Inches (1.5) = Centimeters (3.81)
Conversion between units is done by equating multiples of one unit to another:
Centimeters (2.54 × d) = Inches (d)
However, some measures have no scale: Beauty, Difficulty, etc.

EVENTS
Event calculus, which is based on points of time rather than on situations. Event calculus reifies
fluents and events. The fluent At(Shankar , Berkeley) is an object that refers to the fact of Shankar being
in Berkeley, but does not by itself say anything about whether it is true. To assert that a fluent is actually
true at some point in time we use the predicate T, as in T(At(Shankar , Berkeley), t).
Events are described as instances of event categories. The event E1 of Shankar flying from San
Francisco to Washington, D.C. is described as
E1 ∈ Flyings ∧ Flyer (E1, Shankar ) ∧ Origin(E1, SF) ∧ Destination(E1, DC )
The complete set of predicates for one version of the event calculus is
T(f, t) Fluent f is true at time t
Happens(e, i) Event e happens over the time interval i
Initiates(e, f, t) Event e causes fluent f to start to hold at time t
Terminates(e, f, t) Event e causes fluent f to cease to hold at time t
Clipped(f, i) Fluent f ceases to be true at some point during time interval i
Restored(f, i) Fluent f becomes true sometime during time interval i

A fluent does not hold if it was terminated by an event and not made true (restored) by another event.
Formally, the axioms are:
Happens(e,(t1, t2)) ∧ Initiates(e, f, t1) ∧ ¬Clipped(f,(t1, t)) ∧ t1 < t ⇒ T(f, t)
Happens(e,(t1, t2)) ∧ Terminates(e, f, t1) ∧ ¬Restored(f,(t1, t)) ∧ t1 < t ⇒ ¬T(f, t)
where Clipped and Restored are defined by
Clipped(f,(t1, t2)) ⇔ ∃ e, t, t3 Happens(e,(t, t3)) ∧ t1 ≤ t<t2∧Terminates(e, f, t)
Restored(f,(t1, t2)) ⇔ ∃ e, t, t3 Happens(e,(t, t3)) ∧ t1 ≤ t

Processes
Any process e that happens over an interval also happens over any subinterval:
(e ∈ Processes) ∧ Happens(e,(t1, t4)) ∧ (t1 < t2 < t3 < t4) ⇒ Happens(e,(t2, t3)).
The distinction between liquid and non-liquid events is exactly analogous to the difference between
substances, or stuff, and individual objects, or things.

Time intervals
Event calculus opens us up to the possibility of talking about time, and time intervals. We will
consider two kinds of time intervals: moments and extended intervals. The distinction is that only
moments have zero duration:
Partition({Moments, ExtendedIntervals},Intervals )
i∈ Moments ⇔ Duration(i) = Seconds(0) .

The complete set of interval relations, as proposed by Allen (1983), is shown


Meet(i, j) ⇔ End(i) = Begin(j)
Before(i, j) ⇔ End(i) < Begin(j)
After (j, i) ⇔ Before(i, j)
During(i, j) ⇔ Begin(j) < Begin(i) < End(i) < End(j)
Overlap(i, j) ⇔ Begin(i) < Begin(j) < End(i) < End(j) Begins(i, j) ⇔ Begin(i) = Begin(j)
Finishes(i, j) ⇔ End(i) = End(j)
Equals(i, j) ⇔ Begin(i) = Begin(j) ∧ End(i) = End(j)

Predicates on time intervals.


Fluents and objects
Physical objects can be viewed as generalized events, in the sense that a physical object is a chunk of
space–time. For example, the term President(USA, t) can denote different objects, depending on the value
of t, but our ontology keeps time indices separate from fluents. The only possibility is that
President(USA) denotes a single object that consists of different people at different times. It is the object
that is George Washington from 1789 to 1797, John Adams from 1797 to 1801. To say that George
Washington was president throughout 1790, we can write
T(Equals(President(USA), GeorgeWashington), AD1790) .

MENTAL EVENTS AND MENTAL OBJECTS


Knowledge about one’s own knowledge and reasoning processes is useful for controlling inference.
For example, suppose Alice asks “what is the square root of 1764” and Bob replies “I don’t know.” If
Alice insists “think harder,” Bob should realize that with some more thought, this question can in fact be
answered. On the other hand, if the question were “Is your mother sitting down right now?” then Bob
should realize that thinking harder is unlikely to help. Knowledge about the knowledge of other agents is
also important; Bob should realize that his mother knows whether she is sitting or not, and that asking her
would be a way to find out.
What we need is a model of the mental objects that are in someone’s head and of the mental
processes that manipulate those mental objects. We begin with the propositional attitudes that an agent
can have toward mental objects: attitudes such as Believes, Knows, Wants, Intends, and Informs. The
difficulty is that these attitudes do not behave like “normal” predicates. For example, suppose we try to
assert that Lois knows that Superman can fly:
Knows(Lois, CanFly(Superman)).
If Superman is Clark,
(Superman = Clark) ∧ Knows(Lois, CanFly(Superman)) |= Knows(Lois, CanFly(Clark )).
If our agent knows that 2+2=4 and 4 < 5, then we want our agent to know that 2+2 < 5. This property is
called referential transparency.
Modal logic includes special modal operators that take sentences as arguments. For example, “A
knows P” is represented with the notation KAP, where K is the modal operator for knowledge. In general,
a knowledge atom KAP is true in world w if and only if P is true in every world accessible from w. For
example, we can say that, even though Lois doesn’t know whether Superman’s secret identity is Clark
Kent, she does know that Clark knows:
KLois [KClark Identity(Superman, Clark ) ∨ KClark¬Identity(Superman, Clark )]

Possible words and accessibility relations: KSuperman (solid arrows) and KLois (dotted arrows)
R means “the weather report for tomorrow is rain” and I means “Superman’s secret identity is
Clark Kent.”

In the diagram, represent the scenario where it is common knowledge that Superman knows his identity,
and Lois might or might not have seen the weather report. We represent this by combining the two top
scenarios.
REASONING SYSTEMS FOR CATEGORIES
The reasoning is the mental process of deriving logical conclusion and making predictions from
available knowledge, facts, and beliefs. Or we can say, "Reasoning is a way to infer facts from existing
data." It is a general process of thinking rationally, to find valid conclusions. Categories are the primary
building blocks of large-scale knowledge representation schemes. There are two closely related families
of systems:
(i) Semantic networks
(ii) Description logics

Semantic networks
Semantic networks provide graphical aids for visualizing a knowledge base and efficient algorithms
for inferring properties of an object on the basis of its category membership. Semantics—are a form of
logic.
There are many variants of semantic networks, but all are capable of representing individual objects,
categories of objects, and relations among objects. A typical graphical notation displays object or
category names in ovals or boxes, and connects them with labeled links.

A semantic network with four objects (John, Mary, 1, and 2) and four categories. Relations are
denoted by labeled links.
For example, has a MemberOf link between Mary and FemalePersons, corresponding to the logical
assertion Mary ∈FemalePersons ; similarly, the SisterOf link between Mary and John corresponds to the
assertion SisterOf (Mary, John). This link asserts that
∀ x x∈Persons ⇒ [∀ y HasMother (x, y) ⇒ y ∈ FemalePersons] .
We might also want to assert that persons have two legs,
∀ x x∈Persons ⇒ Legs(x, 2) .

A fragment of a semantic network showing the representation of the logical assertion


Fly (Shankar , NewYork, NewDelhi, Yesterday).

(i) Inheritance
The semantic network notation makes it convenient to perform inheritance reasoning. Inheritance
becomes complicated when an object can belong to more than one category or when a category can be a
subset of more than one other category; this is called multiple inheritance. In such cases, the inheritance
algorithm might find two or more conflicting values answering the query.
For example, the sentence Fly(Shankar , NewYork, NewDelhi, Yesterday) cannot be asserted directly in a
semantic network
One of the most important aspects of semantic networks is their ability to represent default values for
categories. Examining carefully, one notices that John has one leg, despite the fact that he is a person and
all persons have two legs. In a strictly logical KB, this would be a contradiction, but in a semantic
network, the assertion that all persons have two legs has only default status; that is, a person is assumed to
have two legs unless this is contradicted by more specific information.
We can retain a strictly logical semantics for the network if we say that the Legs assertion for Persons
includes an exception for John:
∀ x x∈Persons ∧ x ≠John ⇒ Legs(x, 2)

Description Logics
Description logics provide a formal language for constructing and combining category definitions
and efficient algorithms for deciding subset and superset relationships between categories. Description
logics are notations that are designed to make it easier to describe definitions and properties of categories.
The principal inference tasks for description logics are subsumption (checking if one category is a
subset of another by comparing their definitions) and classification (checking whether an object belongs
to a category). Some systems also include consistency of a category definition—whether the membership
criteria are logically satisfiable.

The syntax of descriptions in a subset of the CLASSIC language


For example, to say that bachelors are unmarried adult males we would write
Bachelor = And(Unmarried, Adult, Male) .
The equivalent in first-order logic would be
Bachelor (x) ⇔ Unmarried(x) ∧ Adult(x) ∧ Male(x) .
Perhaps the most important aspect of description logics is their emphasis on tractability of inference.
Description logics usually lack negation and disjunction

REASONING WITH DEFAULT INFORMATION


Circumscription
Circumscription can be seen as a more powerful and precise version of the closed world assumption. The
idea is to specify particular predicates that are assumed to be “as false as possible”—that is, false for
every object except those for which they are known to be true. For example, suppose we want to assert
the default rule that birds fly. We would introduce a predicate, say Abnormal1(x), and write
Bird(x) ∧ ¬Abnormal1(x) ⇒ Flies(x)
For circumscription, one model is preferred to another if it has fewer abnormal objects. Let us see how
this idea works in the context of multiple inheritance in semantic networks. It arises from the observation
that Richard Nixon was both a Quaker (and hence by default a pacifist) and a Republican (and hence by
default not a pacifist) [Nixon Diamond Example]. We can write this as follows:
Republican(Nixon) ∧ Quaker(Nixon) .
Republican(x) ∧ ¬Abnormal2(x) ⇒ ¬Pacifist(x)
Quaker(x) ∧ ¬Abnormal3(x) ⇒ Pacifist(x)
Default logic is a formalism in which default rules can be written to generate contigent, nonmonotonic
conclusions. A default rule looks like this:
Bird(x) : Flies(x)/Flies(x)
This rule means that if Bird(x) is true, and if Flies(x) is consistent with the knowledge base, then Flies(x)
may be concluded by default. In general, a default rule has the form
P : J1,...,Jn/C
where P is called the prerequisite, C is the conclusion, and Ji are the justifications—if any one of them can
be proven false, then the conclusion cannot be drawn. Any variable that appears in J i or C must also
appear in P. The Nixon-diamond example can be represented in default logic with one fact and two
default rules:
Republican(Nixon) ∧ Quaker(Nixon)
Republican(x) : ¬Pacifist(x)/¬Pacifist(x)
Quaker(x) : Pacifist(x)/Pacifist(x)

Truth Maintenance System


Truth maintenance systems also provide a mechanism for generating explanations. Problems arise,
however, if any additional sentences were inferred from P and asserted in the KB. For example, the
implication P ⇒ Q might have been used to add Q. The obvious “solution”—retracting all sentences
inferred from P—fails because such sentences may have other justifications besides P. For example, if R
and R ⇒ Q are also in the KB, then Q does not have to be removed after all. Truth maintenance systems,
or TMSs, are designed to handle exactly these kinds of complications. One simple approach to truth
maintenance is to keep track of the order in which sentences are told to the knowledge base by numbering
them from P1 to Pn.
When the call RETRACT(KB, Pi) is made, the system reverts to the state just before Pi was added,
thereby removing both Pi and any inferences that were derived from P i. The sentences Pi+1 through Pn can
then be added again. This is simple, and it guarantees that the knowledge base will be consistent. For
systems to which many facts are being added—such as large commercial databases—this is impractical.
(i) Justification-based truth maintenance system
A more efficient approach is the justification-based truth maintenance system, or JTMS. In a JTMS,
each sentence in the knowledge base is annotated with a justification consisting of the set of sentences
from which it was inferred. For example, if the knowledge base already contains P ⇒ Q, then TELL(P)
will cause Q to be added with the justification {P, P ⇒ Q}. TMSs can be used to speed up the analysis of
multiple hypothetical situations.
ii) Assumption-based truth maintenance system
An assumption-based truth maintenance system, or ATMS, makes this type of context switching
between hypothetical worlds particularly efficient. In a JTMS, the maintenance of justifications allows
you to move quickly from one state to another by making a few retractions and assertions, but at any time
only one state is represented. An ATMS represents all the states that have ever been considered at the
same time.

PROLOG - PROgramming in LOGic


Prolog is a programming language for symbolic, non-numeric computation. It is specially well
suited for solving problems that involve objects and relations between objects. Prolog is a declarative and
logical programming language. Prolog is the example of a fourth generation programming language
supporting declarative programming paradigm. In a declarative language the programmer specifies a goal
to be achieved whereas the prolog system works out how to achieve it.
Traditional programming languages are said to be procedural because the programmer must
specify in detail how to solve a problem. In declarative languages, the programmer only states what the
problem is and leaves the rest to the language system.
Data Objects – Variables
Variables are strings of letters, digits and underscore characters. They start with upper-case letter or an
lower-case character.
Example: X, Sum, Memebr_name, Student_list, Shoppinglist, _a50, _15.
In a clause, when a variable is used once only then the variable name can be replaced by so-called
‘anonymous’ variable, which is written as a single underscore{_} character. For example
hasachild(X):-parent(X,Y)
Can also be written as
hasachild(X):-parent(X,_)

Basic Arithmetic Operators


+ = addition
- = subtraction
* = multiplication
/ = division
* * =power
// = integer division
mod = modulo

Logical Operators
a :- b. /* a if b */ :- means ‘if’ or ‘implied by’
a :- b,c. /* a if b and c. */ comma ‘,’ stands for ‘and’ or ‘conjunction’
a :- b;c. /* a if b or c. */  semicolon ‘;’ stands for ‘or’ or ‘disjunction’
a :- not b. /* a if b fails */
a :- b -> c;d. /* a if (if b then c else d) */

Structured Data Objects


Structured data objects are objects that have multiple components. The components themselves
can, in turn, be structures. For example, the data can be viwed as a structure with three components: day,
month and year. Then the date 9th June 2017 can be written as
date(9, June, 2017)

Prolog program
A program consists of clauses. These are of three types: (i) facts, (ii) rules and (iii) questions. A
procedure is a set of clauses about the same relation.
Facts: Facts describe the explicit relationship between objects and object properties.
Example: Mani is a cat.
Ram has phone number “112233” is written in prolog as
phoneno(ram,112233).
It should be noted that
 Names of properties/relationships begin with lower-case letters
 The relationship name appears as the first term
 Objects appear as comma-separated arguments within parenthesis
 A period ”.” must end a fact
 Objects also begin with lower-case letters. They can also begin with digits and can string
of characters enclosed in quotes, E.g. color(penink, ‘red’).
 color(penink, ‘red’) is also called predicate or clause.

The following are the facts that will be stored in the prolog database
%teaches(X,Y):person x teaches in course Y
teaches(sudhir, course001).
teaches(tapas, course002).
teaches(pranab, course003).
teaches(joydeb, course001).
%student(X,Y):student X studies in course Y
studies(suparna, course001).
studies(santanu, course001).
studies(sudip, course002).
studies(shobana, course003).
studies(subin, course003).
studies(swarna, course003).

Rules: Define implicit relationship between objects (brother realtionship) and object properties
(A is a child of B if B is parent of A).
Consider the following case which produces a general rule
 One teacher will guide a student if that student studies that course id on which the teacher
teaches
 In prolo it will be written as
guide(Teacher, Courseid), studies(Student, Courseid).

 Facts are unit clauses and rules are non-unit clauses.


 Variable names will start with a capital letter.

Queries: Asking questions about relationship between objects and object properties. Example:
Rathna is parent of whom?
 Queries will be based on facts and rules. We can ask questions based on the stored
information.
 Suppose we want to know id sudhir lectures in course001 or not, then we can ask
?-teaches(sudhir,course001).
Yes
 In GNU prolog, queries are terminated by a full stop.
 To answer this query, prolog consults its database to see if this is a known fact or not.
?-teaches(suhir, X).
X=course001
 If the answer is true or yes, then the query succeeded and if the answer is false or no, then
the query failed.

Features of Prolog
 Prolog’s fast incremental development cycle and rapid prototyping capabilities have
encouraged the use of the language as a tool for solving AI problems.
 Prolog is a powerful tool for building robust commercial applications
 Prolog features include interfaces to other languages and database products, stand-alone
application generators, and more recently, support techniques such as object oriented and
constraint based programming.
 Object oriented extensions to prolog have increased the attractiveness and expressive
power of the language and provide prolog users with a powerful and flexible object
oriented development language.
 Constraints replace prolog’s usual pattern-matching mechanisms with a more general
operation called “constraint satisfaction”.
 Constraints are a powerful way to reduce the size of the search space and thus increase
the efficiency of the scheduler.

Applications of prolog
 Intelligent Database Retrieval
 Natural Language Understanding
 Expert System
 Specification Language
 Machine Learning
 Robot Planning
 Automated Reasoning
 Problem Solving

Family Relationship pam tom


parent(pam, bob).
parent(tom, bob).
bob liz
parent(tom, liz).
parent(bob, ann).
parent(bob, pat).
parent(pat, jim). ann pat
parent(bob, peter).
parent(peter, jim).

Additional facts jim


female(pam).
male(tom).
male(bob).
female(liz).
female(pat).
female(ann).
male(jim).
Additional Rules
mother(X,Y):-parent(X,Y),female(X)
sister(X,Y):-parent(Z,X), parent(Z,Y),female(X),X\==Y.
father(X,Y):-parent(X,Y), male(X).
haschild(X
brother(X,Y):-parent(Z,X), parent(Z,Y),male(X),X\==Y.

You might also like