You are on page 1of 36

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.

PROPOSITION LOGIC

Syntax: The syntax of propositional logic defines the allowable sentences. The atomic sentences consist
of a single proposition symbol.

Each such symbol stands for a proposition that can be true or false. We use symbols that start with an
uppercase letter and may contain other letters or subscripts, for example: P, Q, R, W1,3 and North.

The names are arbitrary but are often chosen to have some mnemonic value—we use W1,3 to stand for the
proposition that the wumpus is in [1,3]. (Remember that symbols such as W1,3 are atomic, i.e., W, 1, and
3 are not meaningful parts of the symbol.)

There are five connectives in common use:


• ¬ (not). A sentence such as ¬W1,3 is called the negation of W1,3. A literal is either an atomic
sentence (a positive literal) or a negated atomic sentence (a negative literal).
• ∧ (and). A sentence whose main connective is ∧, such as W1,3 ∧ P3,1, is called a conjunction;
its parts are the conjuncts. (The ∧ looks like an “A” for “And.”)
• ∨ (or). A sentence using ∨, such as (W1,3∧P3,1)∨W2,2, is a disjunction of the disjuncts
(W1,3 ∧ P3,1) and W2,2. (Historically, the ∨ comes from the Latin “vel,” which means “or.” For
most people, it is easier to remember ∨ as an upside-down ∧.)
• ⇒ (implies). A sentence such as (W1,3∧P3,1) ⇒ ¬W2,2 is called an implication (or
conditional). Its premise or antecedent is (W1,3 ∧P3,1), and its conclusion or consequent is ¬
W2,2. Implications are also known as rules or if–then statements. The implication symbol is
sometimes written in other books as ⊃ or →.
• ⇔ (if and only if). The sentence W1,3 ⇔ ¬W2,2 is a biconditional. Some other books
• write this as ≡.

Semantics
The semantics defines the rules for determining the truth of a sentence with respect to a particular model.
In propositional logic, a model simply fixes the truth value—true or false—for every proposition symbol.
For example, if the sentences in the knowledge base make use of the proposition symbols P1,2, P2,2, and

P3,1, then one possible model is, m1 = {P1,2 =false, P2,2 =false, P3,1 =true} .
All sentences are constructed from atomic sentences and the five connectives.
Atomic sentences are easy:
• True is true in every model and False is false in every model.
• The truth value of every other proposition symbol must be specified directly in the
model. For example, in the model m1 given earlier, P1,2 is false.

For complex sentences, we have five rules, which hold for any subsentences P and Q in any model m (here
“iff” means “if and only if”):
• ¬P is true iff P is false in m.
• P ∧ Q is true iff both P and Q are true in m.
• P ∨ Q is true iff either P or Q is true in m.
• P ⇒ Q is true unless P is true and Q is false in m.
• P ⇔ Q is true iff P and Q are both true or both false in m.

Inference and proofs

• Inference rules can be applied to derive a proof a chain of conclusions that leads to the desired
goal.
• The best-known rule is called Modus Ponens (Latin for mode that affirms) and is written as α⇒
,α/ β.
• Another useful inference rule is And-Elimination, which says that, from a conjunction, any of the
conjuncts can be inferred: α ∧ β/ α.

FIRST ORDER PREDICATE LOGIC


First-order logic, which is sufficiently expressive to represent a good deal of our commonsense knowledge.
It also either subsumes or forms the foundation of many other representation languages and has been studied
intensively for many decades.
• Objects: people, houses, numbers, theories, Ronald McDonald, colors, baseball games,
wars, centuries . . .
• Relations: these can be unary relations or properties such as red, round, bogus, prime, multistoried
. . ., or more general relations such as brother of, bigger than, inside, part of, has color, occurred
after, owns, comes between, . . .
• Functions: father of, best friend, third inning of, one more than, beginning of . . .
Some examples follow:
• “One plus two equals three.”
Objects: one, two, three, one plus two; Relation: equals; Function: plus. (“One plus two” is a name
for the object that is obtained by applying the function “plus” to the objects “one” an “two. “Three”
is another name for this object.)
• “Squares neighboring the wumpus are smelly.”
Objects: wumpus, squares; Property: smelly; Relation: neighboring.
• “Evil King John ruled England in 1200.”
Objects: John, England, 1200; Relation: ruled; Properties: evil, king.
Syntax and Semantics
Atomic sentences
An atomic sentence (or atom for short) is formed from a predicate symbol optionally followed by a
parenthesized list of terms, such as
Brother (Richard ,John).
This states, under the intended interpretation given earlier, that Richard the Lionheart is the brother of King
John. Atomic sentences can have complex terms as arguments.

An atomic sentence is true in a given model if the relation referred to by the predicate symbol holds among
the objects referred to by the arguments.

Complex sentences
We can use logical connectives to construct more complex sentences, with the same syntax and semantics
as in propositional calculus.
¬Brother (LeftLeg(Richard), John)
Brother (Richard , John) ∧ Brother (John,Richard)
King(Richard ) ∨ King(John)
¬King(Richard) ⇒ King(John) .

QUANTIFIERS
First-order logic contains two standard quantifiers, called universal and existential.
• Universal quantification (∀)
“All kings are persons,” is written in first-order logic as
∀ x King(x) ⇒ Person(x) .
“For all x, if x is a king, then x is a person.” The symbol x is called variable. A term with no variables is
called a ground term.
x → Richard the Lionheart,
x → King John,
x → Richard’s left leg,
x → John’s left leg,
x → the crown.
The universally quantified sentence ∀ x King(x) ⇒ Person(x) is true in the original model if the sentence
King(x) ⇒ Person(x) is true under each of the five extended interpretations. That is, the universally
quantified sentence is equivalent to asserting the following five sentences:
Richard the Lionheart is a king ⇒ Richard the Lionheart is a person.
King John is a king ⇒ King John is a person.
Richard’s left leg is a king ⇒ Richard’s left leg is a person.
John’s left leg is a king ⇒ John’s left leg is a person.
The crown is a king ⇒ the crown is a person.

• Existential quantification (∃)


Universal quantification makes statements about every object. Similarly, we can make a statement about
some object in the universe without naming it, by using an existential quantifier.

for example, that King John has a crown on his head, we write
• ∃ x Crown(x) ∧ OnHead(x, John) .
• ∃x is pronounced “There exists an x such that . . .” or “For some x . . .”.
Intuitively, the sentence ∃x P says that P is true for at least one object x. More precisely, ∃x P is true
in a given model if P is true in at least one extended interpretation that assigns x to a domain element.
That is, at least one of the following is true:
Richard the Lionheart is a crown ∧ Richard the Lionheart is on John’s head;
King John is a crown ∧ King John is on John’s head;
Richard’s left leg is a crown ∧ Richard’s left leg is on John’s head;
John’s left leg is a crown ∧ John’s left leg is on John’s head;
The crown is a crown ∧ the crown is on John’s head.

Assertions and queries in first-order logic


Sentences are added to a knowledge base using TELL, exactly as in propositional logic. Such sentences are
called assertions. For example, we can assert that John is a king, Richard is a person, and all kings are
persons:
TELL(KB, King(John)) .
TELL(KB, Person(Richard)) .
TELL(KB, ∀ x King(x) ⇒ Person(x)) .
We can ask questions of the knowledge base using ASK.
For example,
ASK(KB, King(John)) returns true. Questions asked with ASK are called queries or goals.
Forexample, given the two preceding assertions, the query
ASK(KB, Person(John)) should also return true.

THE KINSHIP DOMAIN


The first example we consider is the domain of family relationships, or kinship. This domain includes facts
such as “Elizabeth is the mother of Charles” and “Charles is the father of William” and rules such as

“One’s grandmother is the mother of one’s parent.”

Clearly, the objects in our domain are people. We have two unary predicates, Male and Female.
Kinship relations parenthood, brotherhood, marriage, and so on are represented by binary predicates:
Parent, Sibling, Brother , Sister , Child , Daughter, Son, Spouse, Wife, Husband, Grandparent ,
Grandchild , Cousin, Aunt, and Uncle.

For example,
1. one’s mother is one’s female parent:
∀ m, c Mother (c)=m ⇔ Female(m) ∧ Parent(m, c) .
2. One’s husband is one’s male spouse:
∀ w, h Husband(h,w) ⇔ Male(h) ∧ Spouse(h,w) .
3. Male and female are disjoint categories:
∀ x Male(x) ⇔ ¬Female(x) .
4. Parent and child are inverse relations:
∀ p, c Parent(p, c) ⇔ Child (c, p) .
5. A grandparent is a parent of one’s parent:
∀ g, c Grandparent (g, c) ⇔ ∃p Parent(g, p) ∧ Parent(p, c) .
6. A sibling is another child of one’s parents:
∀ x, y Sibling(x, y) ⇔ x _= y ∧ ∃p Parent(p, x) ∧ Parent(p, y) .

Axioms
Axioms are commonly associated with purely mathematical domains we will see some axioms for numbers
shortly but they are needed in all domains. They provide the basic factual information from which useful
conclusions can be derived. Our kinship axioms are also definitions;
they have the form ∀ x, y P(x, y) ⇔ . . ..
The axioms define the Mother function and the Husband, Male, Parent, Grandparent, and Sibling
predicates in terms of other predicates.

The wumpus world


The corresponding first-order sentence stored in the knowledge base must include both percept and the time
at which it occurred; otherwise, the agent will get confused about when it saw what. We use integers for
time steps. A typical percept sentence would be Percept ([Stench, Breeze, Glitter , None, None], 5)
.
KNOWLEDGE ENGINEERING IN PREDICATE LOGIC
A knowledge engineer is someone who investigates a particular domain, learns what concepts are important
in that domain, and creates a formal representation of the objects and relations in the domain.
The knowledge-engineering process
Knowledge engineering projects vary widely in content, scope, and difficulty, but all such
projects include the following steps:

1. Identify the task. The knowledge engineer must delineate the range of questions that
the knowledge base will support and the kinds of facts that will be available for each
specific problem instance.
The task will determine what knowledge must be represented in order to connect problem instances to
answers. This step is analogous to the PEAS process for designing agents.

2. Assemble the relevant knowledge. The knowledge engineer might already be an expert in the domain, or
might need to work with real experts to extract what they know a process called knowledge acquisition.
At this stage, the knowledge is not represented formally. The idea is to understand the scope of the
knowledge base, as determined by the task, and to understand how the domain actually works.
For the wumpus world, which is defined by an artificial set of rules, the relevant knowledge is easy to
identify For real domains, the issue of relevance can be quite difficult for example, a system for simulating
VLSI designs might or might not need to take into account stray capacitances and skin effects.

3. Decide on a vocabulary of predicates, functions, and constants. That is, translate the important domain-
level concepts into logic-level names. This involves many questions of knowledge-engineering style. For
example, should pits be represented by objects or by a unary predicate on squares? Should the agent’s
orientation be a function or a predicate? Should the wumpus’s location depend on time? Once the choices
have been made, the ONTOLOGY result is a vocabulary that is known as the ontology of the domain. The word
ontology means a particular theory of the nature of being or existence. The ontology determines what kinds
of things exist, but does not determine their specific properties and interrelationships.

4. Encode general knowledge about the domain. The knowledge engineer writes down
the axioms for all the vocabulary terms. This pins down (to the extent possible) the
meaning of the terms, enabling the expert to check the content. Often, this step reveals
misconceptions or gaps in the vocabulary that must be fixed by returning to step 3 and
iterating through the process.
5. Encode a description of the specific problem instance. If the ontology is well thought out, this step will
be easy. It will involve writing simple atomic sentences about instances of concepts that are already part of
the ontology. For a logical agent, problem instances are supplied by the sensors, whereas a “disembodied”
knowledge base is supplied with additional sentences in the same way that traditional programs are supplied
with input data.

6. Pose queries to the inference procedure and get answers. This is where the reward is: we can let the
inference procedure operate on the axioms and problem-specific facts to derive the facts we are interested
in knowing. Thus, we avoid the need for writing an application-specific solution algorithm.

7. Debug the knowledge base. Alas, the answers to queries will seldom be correct on the first try. More
precisely, the answers will be correct for the knowledge base as written, assuming that the inference
procedure is sound, but they will not be the ones that the user is expecting. For example, if an axiom is
missing, some queries will not be answerable from the knowledge base. A considerable debugging process
could ensue.
Missing axioms or axioms that are too weak can be easily identified by noticing places where the chain of
reasoning stops unexpectedly. For example, if the knowledge base includes a diagnostic rule finding the
wumpus, instead of the biconditional, then the agent will never be able to prove the absence of wumpuses.
∀ s Smelly(s) ⇒ Adjacent (Home(Wumpus), s) ,
Incorrect axioms can be identified because they are false statements about the world. For example, the
sentence is false for reptiles, amphibians, and, more importantly, tables.
∀ x NumOfLegs(x, 4) ⇒ Mammal(x)
The falsehood of this sentence can be determined independently of the rest of the knowledge base.

UNIFICATION
o Unification is a process of making two different logical atomic expressions identical by
finding a substitution. Unification depends on the substitution process.
o It takes two literals as input and makes them identical using substitution.
Conditions for Unification:
Following are some basic conditions for unification:

o Predicate symbol must be same, atoms or expression with different predicate symbol can never be unified.
o Number of Arguments in both expressions must be identical.
o Unification will fail if there are two similar variables present in the same expression.

Let Ψ1 and Ψ2 be two atomic sentences and 𝜎 be a unifier such that, Ψ1𝜎 = Ψ2𝜎, then it can be
expressed as

UNIFY(Ψ1, Ψ2).

Example: Find the MGU for Unify{King(x), King(John)}

Let Ψ1 = King(x), Ψ2 = King(John),

Substitution θ = {John/x} is a unifier for these atoms and applying this substitution, and both
expressions will be identical.

Unification Algorithm
o The UNIFY algorithm is used for unification, which takes two atomic sentences and
returns a unifier for those sentences (If any exist).
o Unification is a key component of all first-order inference algorithms.
o It returns fail if the expressions do not match with each other.
o The substitution variables are called Most General Unifier or MGU.

For example, S(x) can’t unify with S(S(x)).


This is called occur check makes the complexity of the entire algorithm quadratic in the size of the
expressions being unified. Some systems, including all logic programming systems, simply omit the occur
check and sometimes make unsound inferences as a result; other systems use more complex algorithms
with linear-time complexity.
FORWARD CHAINING
A forward-chaining algorithm start with the atomic sentences in the knowledge base and apply Modus
Ponens in the forward direction, adding new atomic sentences, until no further inferences can be made.
Definite clauses such as Situation ⇒ Response are especially useful for systems that make inferences in
response to newly arrived information. Many systems can be defined this way, and forward chaining can
be implemented very efficiently.

First-order definite clauses


First-order definite clauses closely resemble propositional definite clauses. They are disjunctions of literals
of which exactly one is positive. A definite clause either is atomic or is an implication whose antecedent is
a conjunction of positive literals and whose consequent is a single positive literal. The following are first-
order definite clauses:
King(x) ∧ Greedy(x) ⇒ Evil(x) .
King(John) .
Greedy(y) .

Consider the following problem:


The law says that it is a crime for an American to sell weapons to hostile nations. The country
Nono, an enemy of America, has some missiles, and all of its missiles were sold to it by
ColonelWest, who is American.

Solution:
We will prove thatWest is a criminal. First, we will represent these facts as first-order definite clauses. The
next section shows how the forward-chaining algorithm solves the problem.
“. . . it is a crime for an American to sell weapons to hostile nations”:
American(x) ∧Weapon(y) ∧ Sells(x, y, z) ∧ Hostile(z) ⇒ Criminal (x)
“Nono . . . has some missiles.”
Owns(Nono,M1)
M. issile(M1)
“All of its missiles were sold to it by Colonel West”:
Missile(x) ∧ Owns(Nono, x) ⇒ Sells(West, x, Nono)
We will also need to know that missiles are weapons:
Missile(x) ⇒ Weapon(x)
and we must know that an enemy of America counts as “hostile”:
Enemy(x,America) ⇒ Hostile(x) .
“West, who is American . . .”:
American(West)
“The country Nono, an enemy of America . . .”:
Enemy(Nono,America) .
This knowledge base contains no function symbols and is therefore an instance of the class of Datalog
knowledge bases. Datalog DATALOG is a language that is restricted to first-order definite clauses with no function
symbols. Datalog gets its name because it can represent the type of statements typically made in relational
databases.

A simple forward-chaining algorithm


• The first forward-chaining algorithm we consider is a simple one. Starting from the known facts, it
triggers all the rules whose premises are satisfied, adding their conclusions to the known facts.
• The process repeats until the query is answered (assuming that just one answer is required) or no
new facts are added. Notice that a fact is not “new” if it is just a renaming of a known fact. One
sentence is a renaming of another if they are identical except for the names of the variables.

Efficient forward chaining


The“inner loop” of the algorithm involves finding all possible unifiers such that the premise of a rule unifies
with a suitable set of facts in the knowledge base. This is often called pattern matching and can be very
expensive. Second, the algorithm rechecks every rule on every iteration to see whether its premises are
satisfied, even if very few additions are made to the knowledge base on each iteration. Finally, the algorithm
might generate many facts that are irrelevant to the goal.

Matching rules against known facts


The problem of matching the premise of a rule against the facts in the knowledge base might seem simple
enough. For example, suppose we want to apply the rule
Missile(x) ⇒ Weapon(x) .
Then we need to find all the facts that unify with Missile(x); in a suitably indexed knowledge base, this can
be done in constant time per fact. Now consider a rule such as
Missile(x) ∧ Owns(Nono, x) ⇒ Sells(West, x, Nono) .

BACKWARD CHAINING
These algorithms work backward from the goal, chaining through rules to find known facts that support the
proof. We describe the basic algorithm, and then we describe how it is used in logic programming, which
is the most widely used form of automated reasoning.

A backward-chaining algorithm

• FOL-BC-ASK(KB, goal ) will be proved if the knowledge base contains a clause of the form lhs ⇒
goal, where lhs (left-hand side) is a list of conjuncts. An atomic fact like American(West) is
considered as a clause whose lhs is the empty list. Now a query that contains variables might be
proved in multiple ways.
• For example, the query Person(x) could be proved with the substitution {x/John} as well as with
{x/Richard }.
• So we implement FOL-BC-ASK as a generator a function that returns multiple times, each time
giving one possible result.
• Backward chaining is a kind of AND/OR search—the OR part because the goal query can be proved
by any rule in the knowledge base, and the AND part because all the conjuncts in the lhs of a clause
must be proved.
• FOL-BC-OR works by fetching all clauses that might unify with the goal, standardizing the
variables in the clause to be brand-new variables, and then, if the rhs of the clause does indeed
unify with the goal, proving every conjunct in the lhs, using FOL-BC-AND.
• Backward chaining, as we have written it, is clearly a depth-first search algorithm. This means that
its space requirements are linear in the size of the proof (neglecting, for now, the space required to
accumulate the solutions). It also means that backward chaining (unlike forward chaining) suffers
from problems with repeated states and incompleteness. We will discuss these problems and some
potential solutions, but first we show how backward chaining is used in logic programming
systems.

RESOLUTION
Resolution in FOL

Resolution is a theorem proving technique that proceeds by building refutation proofs, i.e.,
proofs by contradictions. It was invented by a Mathematician John Alan Robinson in the year
1965.

Resolution is used, if there are various statements are given, and we need to prove a conclusion
of those statements. Unification is a key concept in proofs by resolutions. Resolution is a single
inference rule which can efficiently operate on the conjunctive normal form or clausal form.

PROPOSITIONAL THEOREM PROVING PROOF AND PROBLEMS IN RESOLUTION


Conjunctive normal form

• The resolution rule applies only to clauses (that is, disjunctions of literals), so it would
seem to be relevant only to knowledge bases and queries consisting of clauses.
• Every sentence of propositional logic is logically equivalent to a conjunction of clauses. A
sentence expressed as a conjunction of clauses is said to be in conjunctive normal form
or CNF.
• First-order resolution requires that sentences be in conjunctive normal form (CNF) that is, a
conjunction of clauses, where each clause is a disjunction of literals.

Conjunctive Normal Form: A sentence represented as a conjunction of clauses is said to


be conjunctive normal form or CNF.

A Simple Resolution Algorithm


We illustrate the procedure by translating the sentence:
“Everyone who loves all animals is loved by someone,” or
∀ x [∀ y Animal(y) ⇒ Loves(x, y)] ⇒ [∃ y Loves(y, x)] .

The steps are as follows:


• Eliminate implications:
∀ x [¬∀ y ¬Animal(y) ∨ Loves(x, y)] ∨ [∃ y Loves(y, x)] .
• Move ¬ inwards: In addition to the usual rules for negated connectives, we need rules
for negated quantifiers. Thus, we have
¬∀x p becomes ∃ x ¬p
¬∃x p becomes ∀ x ¬p .
Our sentence goes through the following transformations:
∀ x [∃ y ¬(¬Animal(y) ∨ Loves(x, y))] ∨ [∃ y Loves(y, x)] .
∀ x [∃ y ¬¬Animal(y) ∧ ¬Loves(x, y)] ∨ [∃ y Loves(y, x)] .
∀ x [∃ y Animal (y) ∧¬Loves(x, y)] ∨ [∃ y Loves(y, x)] .
Notice how a universal quantifier (∀ y) in the premise of the implication has become an existential
quantifier. The sentence now reads “Either there is some animal that x doesn’t love, or (if this is not the
case) someone loves x.” Clearly, the meaning of the original sentence has been preserved.

Standardize variables: For sentences like (∃xP(x))∨(∃xQ(x)) which use the same variable name twice,
change the name of one of the variables. This avoids confusion later when we drop the quantifiers. Thus,
we have
∀ x [∃ y Animal (y) ∧¬Loves(x, y)] ∨ [∃ z Loves(z, x)] .

• Skolemize: Skolemization is the process of removing existential quantifiers by elimination.


translate ∃x P(x) into P(A), where A is a new constant.
∀ x [Animal (A) ∧ ¬Loves(x,A)] ∨ Loves(B, x)
it says that everyone either failsto love a particular animal A or is loved by some particular entity B. In fact,
our original sentence allows each person to fail to love a different animal or to be loved by a different
person. Thus, we want the Skolem entities to depend on x and z:
∀ x [Animal (F(x)) ∧¬Loves(x, F(x))] ∨ Loves(G(z), x) .
Here F and G are Skolem functions.

Steps for Resolution:


1. Conversion of facts into first-order logic.
2. Convert FOL statements into CNF
3. Negate the statement which needs to prove (proof by contradiction)
4. Draw resolution graph (unification).

To better understand all the above steps, we will take an example in which we will apply resolution.

Example:

a. John likes all kind of food.


b. Apple and vegetable are food
c. Anything anyone eats and not killed is food.
d. Anil eats peanuts and still alive
e. Harry eats everything that Anil eats.
Prove by resolution that:
f. John likes peanuts.

Step-1: Conversion of Facts into FOL, In the first step we will convert all the given statements into its
first order logic.

Step-2: Conversion of FOL into CNF

In First order logic resolution, it is required to convert the FOL into CNF as CNF form makes easier for resolution
proofs.

o Eliminate all implication (→) and rewrite


a. ∀x ¬ food(x) V likes(John, x)
b. food(Apple) Λ food(vegetables)
c. ∀x ∀y ¬ [eats(x, y) Λ ¬ killed(x)] V food(y)
d. eats (Anil, Peanuts) Λ alive(Anil)
e. ∀x ¬ eats(Anil, x) V eats(Harry, x)
f. ∀x¬ [¬ killed(x) ] V alive(x)
g. ∀x ¬ alive(x) V ¬ killed(x)
h. likes(John, Peanuts).
Move negation (¬)inwards and rewrite
. ∀x ¬ food(x) V likes(John, x)
a. food(Apple) Λ food(vegetables)
b. ∀x ∀y ¬ eats(x, y) V killed(x) V food(y)
c. eats (Anil, Peanuts) Λ alive(Anil)
d. ∀x ¬ eats(Anil, x) V eats(Harry, x)
e. ∀x ¬killed(x) ] V alive(x)
f. ∀x ¬ alive(x) V ¬ killed(x)
g. likes(John, Peanuts).
Rename variables or standardize variables
. ∀x ¬ food(x) V likes(John, x)
a. food(Apple) Λ food(vegetables)
b. ∀y ∀z ¬ eats(y, z) V killed(y) V food(z)
c. eats (Anil, Peanuts) Λ alive(Anil)
d. ∀w¬ eats(Anil, w) V eats(Harry, w)
e. ∀g ¬killed(g) ] V alive(g)
f. ∀k ¬ alive(k) V ¬ killed(k)
g. likes(John, Peanuts).
Eliminate existential instantiation quantifier by elimination.
In this step, we will eliminate existential quantifier ∃, and this process is known as Skolemization. But in this
example problem since there is no existential quantifier so all the statements will remain same in this step.
Drop Universal quantifiers.
In this step we will drop all universal quantifier since all the statements are not implicitly quantified so we don't
need it.
. ¬ food(x) V likes(John, x)
a. food(Apple)
b. food(vegetables)
c. ¬ eats(y, z) V killed(y) V food(z)
d. eats (Anil, Peanuts)
e. alive(Anil)
f. ¬ eats(Anil, w) V eats(Harry, w)
g. killed(g) V alive(g)
h. ¬ alive(k) V ¬ killed(k)
i. likes(John, Peanuts).
Note: Statements "food(Apple) Λ food(vegetables)" and "eats (Anil, Peanuts) Λ alive(Anil)" can be written in two
separate statements.

o Distribute conjunction ∧ over disjunction ¬.


This step will not make any change in this problem.

Step-3: Negate the statement to be proved

In this statement, we will apply negation to the conclusion statements, which will be written as ¬likes(John,
Peanuts)

Step-4: Draw Resolution graph:

Now in this step, we will solve the problem by resolution tree using substitution. For the above problem, it will be
given as follows:

Hence the negation of the conclusion has been proved as a complete contradiction with the given set of
statements.

Explanation of Resolution graph:


o In the first step of resolution graph, ¬likes(John, Peanuts) , and likes(John, x) get resolved(canceled)
by substitution of {Peanuts/x}, and we are left with ¬ food(Peanuts)
o In the second step of the resolution graph, ¬ food(Peanuts) , and food(z) get resolved (canceled) by
substitution of { Peanuts/z}, and we are left with ¬ eats(y, Peanuts) V killed(y) .
o In the third step of the resolution graph, ¬ eats(y, Peanuts) and eats (Anil, Peanuts) get resolved by
substitution {Anil/y}, and we are left with Killed(Anil) .
o In the fourth step of the resolution graph, Killed(Anil) and ¬ killed(k) get resolve by
substitution {Anil/k}, and we are left with ¬ alive(Anil) .
o In the last step of the resolution graph ¬ alive(Anil) and alive(Anil) get resolved.

Problem 2

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 3

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))wicket(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 4

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.

KNOWLEDGE REPRESENTATION
ONTOLOGICAL ENGINEERING
In “toy” domains, the choice of representation is not that important; many choices will work.
Complex domains such as shopping on the Internet or driving a car in traffic require more general and
flexible representations. This shows how to create these representations, concentrating on general concepts
such as Events, Time, Physical Objects, and Beliefs that occur in many different domains. Representing
these abstract concepts is sometimes called ontological engineering.

The general framework of concepts is called an upper ontology.


– because of the convention of drawing graphs with:
• the general concepts at the top
• the more specific concepts below them
The principal difficulty is that most generalizations have exceptions or hold only to a degree.

• For example, “tomatoes are red” is a useful rule, some tomatoes are green, yellow, or orange.
Similar exceptions can be found to almost all the rules in this chapter.
• The ability to handle exceptions and uncertainty is extremely important, but is orthogonal to the
task of understanding the general ontology.
• If we look at the wumpus world, similar considerations apply. Although we do represent time, it
has a simple structure.
• Nothing happens except when the agent acts, and all changes are instantaneous. A more general
ontology, better suited for the real world, would allow for simultaneous changes extended over
time.
• We also used a Pit predicate to say which squares have pits.
• We could have allowed for different kinds of pits by having several individuals belonging to the
class of pits, each having different properties. Similarly, we might want to allow for other animals
besides wumpuses.
• It might not be possible to pin down the exact species from the available percepts, so we would
need to build up a biological taxonomy to help the agent predict the behavior of cave-dwellers from
scanty clues.

Two major characteristics of general-purpose


Ontologies distinguish them from collections of 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). This means that no representational issue can be finessed or brushed
under the carpet.
• In any sufficiently demanding domain, different areas of knowledge must be unified, because reasoning
and problem solving could involve several areas simultaneously. A robot circuit-repair system, for instance,
needs to reason about circuits in terms of electrical connectivity and physical layout, and about time, both
for circuit timing analysis and estimating labor costs.

Why ontologies are useful?


• Sharing:
– “communication” among people / agents with different needs and viewpoints due
to their different contexts
• unified framework within an “organization” to reduce conceptual and
terminological confusion
– inter-operability among systems by “translating” between different modeling
methods, languages and software tools
• ontologies as inter-lingua
• integration of ontologies
• Modeling
• System engineering:
– re-usability
• Use of standards
• Highly configurable ontologies and libraries of ontologies support re-
usability among different software systems.
– reliability
• Formal ontologies enable the use of consistency checking resulting in
more reliable systems.

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.
There are two choices for representing categories in first-order logic: predicates and objects. That is,
we can use the predicate Basketball, or we can reify the category as an object, Basketballs.

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. We say that the individual apples inherit the
property of edibility, in this case from their membership in the Food category.

Subclass relations organize categories into a taxonomy, or taxonomic hierarchy. Taxonomies


have been used explicitly for centuries in technical fields.

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:
FOL and 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)
• Members of a category can be recognized by some properties.
Orange(x) ∧ Round (x) ∧ Diameter(x)=9.5__ ∧ x∈ Balls ⇒ x∈ Basketballs
• A category as a whole has some properties.
Dogs ∈DomesticatedSpecies

Relations between Categories

Although subclass and member relations are the most important ones for categories, we also want to be able
to state relations between categories that are not subclasses of each other. For example, if we just say that
Males and Females are subclasses of Animals, then we have not said that a male cannot be a female. We
say that two or more categories are disjoint if they have no members in common.

Adisjoint exhaustive decomposition is known as a partition. The following examples illustrate


these three concepts:
Disjoint({Animals,Vegetables})
ExhaustiveDecomposition({Americans,Canadians, Mexicans},NorthAmericans)
Partition({Males, Females}, Animals) .

Physical composition
The idea that one object can be part of another is a familiar one. One’s nose is part of one’s head, Romania
is part of Europe, and this chapter is part of this book. We use 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) .
For example, we might want to say “The apples in this bag weigh two pounds.”

The temptation would be to ascribe this weight to the set of apples in the bag, but this would be a mistake
because the set is an abstract mathematical concept that has elements but does not have weight. Instead, we
need a new concept, which we will call a bunch. For example, if the apples are Apple1, Apple2, and Apple3,
then
BunchOf ({Apple1,Apple2,Apple3})
Notice that BunchOf ({x})= x. Furthermore, BunchOf (Apples) is the composite object consisting of all
apples not to be confused with Apples, the category or set of all apples. We can define BunchOf in terms of
the PartOf relation.
Measurements
The values that we assign for these MEASURE properties are called measures.
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) .
Similar axioms can be written for pounds and kilograms, seconds and days, and dollars and cents. Measures
can be used to describe objects as follows:
Diameter (Basketball 12)=Inches(9.5) .
ListPrice(Basketball 12)=$(19) .
d∈ Days ⇒ Duration(d)=Hours(24) .

Objects
The real world can be seen as consisting of primitive objects (e.g., atomic particles) and composite objects
built from them. By reasoning at the level of large objects such as apples and cars, we can overcome the
complexity involved in dealing with vast numbers of primitive objects individually.

For example, suppose I have some butter and an aardvark in front of me.

• I can say there is one aardvark, but there is no obvious number of “butter-objects,” because any
part of a butter-object is also a butter-object, at least until we get to very small parts indeed. This is
the major distinction between stuff and things. If we cut an aardvark in half, we do not get two
aardvarks (unfortunately).
• The English language distinguishes clearly between stuff and things.

• On the other hand, butter has no particular size, shape, or weight. We can define more specialized
categories of butter such as UnsaltedButter , which is also a kind of stuff. Note that the category
PoundOfButter , which includes as members all butter-objects weighing one pound, is not a kind
of stuff. If we cut a pound of butter in half, we do not, alas, get two pounds of butter.

Intrinsic: they belong to the very substance of the object, rather than to the object as a whole. When you
cut an instance of stuff in half, the two pieces retain the intrinsic properties—things like density, boiling
point, flavor, color, ownership, and so on.

Extrinsic properties weight, length, shape, and so on—are not retained under subdivision. A category of
objects that includes in its definition only intrinsic properties is then a substance, or mass noun; a class
that includes any extrinsic properties in its definition is a count noun.

Events
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)
If this is too verbose, we can define an alternative three-argument version of the category of
flying events and say
E1 ∈ Flyings(Shankar , SF,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

MENTAL EVENTS AND MENTAL OBJECTS


The agents we have constructed so far have beliefs and can deduce new beliefs. Yet none of them has any
knowledge about beliefs or about deduction. 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.

Propositional attitudes that an agent can have toward mental ob-jects: attitudes such as Believes, Knows,
Wants, Intends, and Informs. The difficulty is
REASONING SYSTEMS FOR CATEGORIES
Categories are the primary building blocks of large-scale knowledge representation schemes.
There are two closely related families of systems:
• 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;
• description logics provide a formal language for constructing and combining category definitions
and efficient algorithms for deciding subset and superset relationships between categories.

PROLOG
Prolog is the most widely used logic programming language. It is used primarily as a rapid prototyping
language and for symbol-manipulation tasks such as writing compilers and parsing natural language. Many
expert systems have been written in Prolog for legal, medical, financial, and other domains.
Prolog programs are sets of definite clauses written in a notation somewhat different from standard first-
order logic.

Prolog uses uppercase letters for variables and lowercase for constants the opposite of our convention for
logic.
Commas separate conjuncts in a clause, and the clause is written “backwards” from what we are used to;
instead of A ∧ B ⇒ C in
Prolog we have C :- A, B.

Here is a typical example:


criminal(X) :- american(X), weapon(Y), sells(X,Y,Z), hostile(Z).

• The notation [E|L] denotes a list whose first element is E and whose rest is L.
• Here is a Prolog program for append(X,Y,Z), which succeeds if list Z is the result of appending
lists X and Y:
append([],Y,Y).
append([A|X],Y,[A|Z]) :- append(X,Y,Z).
• The Prolog definition is actually much more powerful, however, because it describes a relation that
holds among three arguments, rather than a function computed from two arguments.

The execution of Prolog programs is done through depth-first backward chaining, Some aspects of Prolog
fall outside standard logical inference:
• Prolog uses the database semantics rather than first-order semantics, and this is apparent in its treatment
of equality and negation.
• There is a set of built-in functions for arithmetic. Literals using these function symbols are “proved” by
executing code rather than doing further inference.

For example, the goal “X is 4+3” succeeds with X bound to 7.


• On the other hand, the goal “5 is X+Y” fails, because the built-in functions do not do arbitrary
equation solving.
• There are built-in predicates that have side effects when executed. These include input output
predicates and the assert/retract predicates for modifying the knowledge base.
• Such predicates have no counterpart in logic and can produce confusing results for example, if facts
are asserted in a branch of the proof tree that eventually fails.

• The occur check is omitted from Prolog’s unification algorithm. This means that some unsound
inferences can be made; these are almost never a problem in practice.
• Prolog uses depth-first backward-chaining search with no checks for infinite recursion. This makes it
very fast when given the right set of axioms, but incomplete when given the wrong ones.
Prolog’s design represents a compromise between declarativeness and execution efficiency in as much as
efficiency was understood at the time Prolog was designed.

Efficient implementation of logic programs

The execution of a Prolog program can happen in two modes: interpreted and compiled.
• First, our implementation had to explicitly manage the iteration over possible results generated by
each of the subfunctions. Prolog interpreters have a global data structure, a stack of choice points,
to keep track of the multiple possibilities that we considered in FOL-BC-OR. This global stack is
more efficient, and it makes debugging easier, because the debugger can move up and down the
stack.
• Second, our simple implementation of FOL-BC-ASK spends a good deal of time generating
substitutions. Instead of explicitly constructing substitutions, Prolog has logic variables that remember their
current binding.
Database semantics of Prolog
• Prolog uses database semantics and the closed world assumption says that the only sentences that
are true are those that are entailed by the knowledge base. There is no way to assert that a sentence
is false in Prolog.
• This makes Prolog less expressive than first-order logic, but it is part of what makes Prolog more
efficient and more concise. Consider the following Prolog assertions about some course offerings:
Course(CS, 101), Course(CS, 102), Course(CS, 106), Course(EE, 101).
Under the unique names assumption, CS and EE are different (as are 101, 102, and 106), so this means that
there are four distinct courses. Under the closed-world assumption there are no other courses, so there are
exactly four courses.
If we wanted to translate Equation into FOL, we would get this:
Course(d, n) ⇔ (d=CS ∧ n = 101) ∨ (d=CS ∧ n = 102)
∨ (d=CS ∧ n = 106) ∨ (d=EE ∧ n = 101) . (9.12)
This is called the completion of Equation.

Example program:

Below student-professor relation table shows the facts, rules, goals and their english
meanings.

Facts English meanings


studies(charlie, csc135). // charlie studies csc135
studies(olivia, csc135). // olivia studies csc135
studies(jack, csc131). // jack studies csc131
studies(arthur, csc134). // arthur studies csc134
teaches(kirke, csc135). // kirke teaches csc135
teaches(collins, csc131). // collins teaches csc131
teaches(collins, csc171). // collins teaches csc171
teaches(juniper, csc134). // juniper teaches csc134

Rules
professor(X, Y) :- // X is a professor of Y if X
teaches(X, C), studies(Y, C). teaches C and Y studies C.

Queries / Goals
?- studies(charlie, What). // charlie studies what? OR
What does charlie study?
?- professor(kirke, Students). // Who are the students of
professor kirke.
Data types
• Prolog's single data type is the term. Terms are either atoms, numbers, variables or compound terms.
• An atom is a general-purpose name with no inherent meaning. Examples of atoms include x, red, 'Taco',
and 'some atom'.
• Numbers can be floats or integers. ISO standard compatible Prolog systems can check the Prolog flag
"bounded". Most of the major Prolog systems support arbitrary length integer numbers.
• Variables are denoted by a string consisting of letters, numbers and underscore characters, and beginning
with an upper-case letter or underscore. Variables closely resemble variables in logic in that they are
placeholders for arbitrary terms.
• A compound term is composed of an atom called a "functor" and a number of "arguments", which are
again terms. Compound terms are ordinarily written as a functor followed by a comma-separated list of
argument terms, which is contained in parentheses. The number of arguments is called the term's arity. An
atom can be regarded as a compound term with arity zero. An example of a compound term is
person_friends(zelda,[tom,jim]).
Special cases of compound terms:
• A List is an ordered collection of terms. It is denoted by square brackets with the terms separated by
commas, or in the case of the empty list, by []. For example, [1,2,3] or [red,green,blue].
Strings: A sequence of characters surrounded by quotes is equivalent to either a list of (numeric) character codes, a
list of characters (atoms of length 1), or an atom depending on the value of the Prolog flag double_quotes. For
example, "to be, or not to be".

Logic programming is a programming paradigm in which logical assertions viewed as


programs.
• These are several logic programming systems, PROLOG is one of them.
A PROLOG program consists of several logical assertions where each is a horn clause
i.e. a clause with at most one positive literal.
Ex : P, P V Q, P → Q
The facts are represented on Horn Clause for two reasons.
1. Because of a uniform representation, a simple and efficient interpreter can write.
2. The logic of Horn Clause decidable.

Also, The first two differences are the fact that PROLOG programs are actually sets of
Horn clause that have been transformed as follows:-
1. If the Horn Clause contains no negative literal then leave it as it is.
2. Also, Otherwise rewrite the Horn clauses as an implication, combining all of the
negative literals into the antecedent of the implications and the single positive
literal into the consequent.
Moreover, This procedure causes a clause which originally consisted of a disjunction of
literals (one of them was positive) to be transformed into a single implication whose
antecedent is a conjunction universally quantified.
But when we apply this transformation, any variables that occurred in negative literals
and so now occur in the antecedent become existentially quantified, while the variables in
the consequent are still universally quantified.
For example the PROLOG clause P(x): – Q(x, y) is equal to logical expression ∀x: ∃y: Q (x,
y) → P(x).
The difference between the logic and PROLOG representation is that the PROLOG
interpretation has a fixed control strategy. And so, the assertions in the PROLOG
program define a particular search path to answer any question.
But, the logical assertions define only the set of answers but not about how to choose
among those answers if there is more than one.
Consider the following example:
1. Logical representation
∀x : pet(x) ۸ small (x) → apartmentpet(x)
∀x : cat(x) ۸ dog(x) → pet(x)
∀x : poodle (x) → dog (x) ۸ small (x)
poodle (fluffy)
2. Prolog representation
apartmentpet (x) : pet(x), small (x)
pet (x): cat (x)
pet (x): dog(x)
dog(x): poodle (x)
small (x): poodle(x)
poodle (fluffy)
The Prolog language:
a Prolog program has the following characteristics:
• A program consists of a sequence of sentences, implicitly conjoined. All variables haveimplicit universal
quantification, and variables in different sentences are considered distinct.
• Only Horn clause sentences are acceptable. This means that each sentence is either anatomic sentence or an
implication with no negated antecedents and an atomic consequent.
• Terms can be constant symbols, variables, or functional terms.
• Queries can include conjunctions, disjunctions, variables, and functional terms.
• Instead of negated antecedents in implications, Prolog uses a negation as failure operator:a goal not P is considered
proved if the system fails to prove P.
• All syntactically distinct terms are assumed to refer to distinct objects. That is, you cannotassert A = B or A = F(x),
where A is a constant. You can assert x = B or x - F(y), where x isa variable.
• There is a large set of built-in predicates for arithmetic, input/output, and various systemand knowledge base
functions. Literals using these predicates are "proved" by executingcode rather than doing further inference.
In Prolog notation (where capitalized names arevariables), the goal X is 4 + 3 succeeds with X bound to 7. However,
the goal 5 is X+Ycannot be proved, because the built-in functions do not do arbitrary equation solving.

You might also like