Professional Documents
Culture Documents
Textbook Prolog Programming For Artificial Intelligence Ivan Bratko Ebook All Chapter PDF
Textbook Prolog Programming For Artificial Intelligence Ivan Bratko Ebook All Chapter PDF
Textbook Prolog Programming For Artificial Intelligence Ivan Bratko Ebook All Chapter PDF
https://textbookfull.com/product/the-quest-for-artificial-
intelligence-nils-nilsson/
https://textbookfull.com/product/beginning-game-ai-with-unity-
programming-artificial-intelligence-with-c-sebastiano-m-cossu/
https://textbookfull.com/product/artificial-intelligence-for-
coronavirus-outbreak-simon-james-fong/
https://textbookfull.com/product/artificial-intelligence-for-big-
data-complete-guide-to-automating-big-data-solutions-using-
artificial-intelligence-techniques-anand-deshpande/
Artificial Intelligence and Industrial Applications:
Artificial Intelligence Techniques for Cyber-Physical,
Digital Twin Systems and Engineering Applications
Tawfik Masrour
https://textbookfull.com/product/artificial-intelligence-and-
industrial-applications-artificial-intelligence-techniques-for-
cyber-physical-digital-twin-systems-and-engineering-applications-
tawfik-masrour/
https://textbookfull.com/product/artificial-intelligence-by-
example-develop-machine-intelligence-from-scratch-using-real-
artificial-intelligence-use-cases-denis-rothman/
https://textbookfull.com/product/unity-2017-game-ai-programming-
leverage-the-power-of-artificial-intelligence-to-program-smart-
entities-for-your-games-raymundo-barrera/
https://textbookfull.com/product/artificial-intelligence-for-
marketing-practical-applications-1st-edition-jim-sterne/
https://textbookfull.com/product/learning-embedded-android-n-
programming-1st-edition-ivan-morgillo/
Prolog Programming for Artificial Intelligence FOURTH EDITION «. *
# >St*A v. kit-, Ivan Bratko
VIM Contents 13.3 RBFS - recursive best-first search 305 13.4 RTA*
- real-time A* algorithm 311 Summary 316 References 317 14
Problem Decomposition and AND/OR Graphs 318 14.1 AND/OR
graph representation of problems 318 14.2 Examples of AND/OR
representation 322 14.3 Basic AND/OR search procedures 325 14.4
Best-first AND/OR search 330 Summary 341 References 342 15
Knowledge Representation and Expert Systems 343 15.1 Functions
and structure of an expert system 343 15.2 Representing knowledge
with if-then rules 345 15.3 Forward and backward chaining in rule-
based systems 348 15.4 Generating explanation 353 15.5
Introducing uncertainty 357 15.6 Semantic networks and frames 360
Summary 367 References 368 16 Probabilistic Reasoning with
Bayesian Networks 370 16.1 Probabilities, beliefs and Bayesian
networks 370 16.2 Some formulas from probability calculus 375 16.3
Probabilistic reasoning in Bayesian networks 376 16.4 d-separation
381 Summary 383 References 383 17 Planning 385 17.1
Representing actions 385 17.2 Deriving plans by means-ends
analysis 388 17.3 Goal regression 393 17.4 Combining regression
planning with best-first heuristic 396 17.5 Uninstantiated actions and
goals 399 17.6 Partial order planning 401 Summary 403 References
and historical notes 404
Preface xxi to Cem Say for testing many programs and his gift of
finding hidden errors. Several readers helped by pointing out errors
in the previous editions, most notably G. Oulsnam and Iztok Tvrdy. I
would also like to thank Patrick Bond, Robert Chaundy, Rufus
Curnow, Philippa Fiszzon and Simon Lake of Pearson Education for
their work in the process of producing this book. Simon Plumtree,
Debra Myson-Etherington, Karen Mosman, Julie Knight and Karen
Sutherland provided support in the previous editions. Much of the
artwork was done by Darko Simersek. Finally, this book would not be
possible without the stimulating creativity of the international logic
programming community. Ivan Bratko January 2011
1.1 Defining relations by facts 7 • The user can easily query the
Prolog system about relations denned in the program. • A Prolog
program consists of clauses. Each clause terminates with a full stop.
• The arguments of relations can (among other things) be: concrete
objects, or constants (such as torn and ann), or general objects such
as X and Y. Objects of the first kind in our program are called atoms.
Objects of the second kind are called variables. Atoms are
distinguished from variables by syntax. Atoms are strings that start
with a lower-case letter. The names of variables are strings that start
with an upper-case letter or an underscore. Later we will see some
other syntactic forms for atoms and variables. • Questions to Prolog
consist of one or more goals. A sequence of goals, such as: parent(
X, ann), parent( X, pat) means the conjunction of the goals: X is a
parent of Ann, and X is a parent of Pat. The word 'goals' is used
because Prolog interprets questions as goals that are to be satisfied.
To 'satisfy a goal' means to logically deduce the goal from the
program. • An answer to a question can be either positive or
negative, depending on whether the corresponding goal can be
satisfied or not. In the case of a positive answer we say that the
corresponding goal was satisfiable and that the goal succeeded.
Otherwise the goal was unsatisfiable and it failed. • If several
answers satisfy the question then Prolog will find as many of them
as desired by the user. EXERCISES 1.1 Assuming the parent relation
as defined in this section (see Figure 1.1), what will be Prolog's
answers to the following questions? (a) ?- parent( jim, X). (b) ?-
parent( X, jim). (c) ?- parent( pam, X), parent( X, pat). (d) ?-
parent( pam, X), parent( X, Y), parent( Y, jim). 1.2 Formulate in
Prolog the following questions about the parent relation: (a) Who is
Pat's parent? (b) Does Liz have a child? (c) Who is Pat's
grandparent?
1.3 Recursive rules 13 Recursive rules Let us add one more relation
to our family program, the ancestor relation. This relation will be
defined in terms of the parent relation. The whole definition can be
expressed with two rules. The first rule will define the direct
(immediate) ancestors and the second rule the indirect ancestors.
We say that some X is an indirect ancestor of some Z if there is a
chain of parents between X and Z, as illustrated in Figure 1.5. In our
example of Figure 1.1, Tom is a direct ancestor of Liz and an indirect
ancestor of Pat. The first rule is simple and can be written in Prolog
as: ancestor( X, Z) :- parent( X, Z). The second rule, on the other
hand, is more complicated. The chain of parents may present some
problems because the chain can be arbitrarily long. One attempt to
define indirect ancestors could be as shown in Figure 1.6. According
to this, the ancestor relation would be defined by a set of clauses as
follows: ancestor( X, Z) :- parent( X, Z). ancestor( X, Z) :- parent( X,
Y), parent (Y, Z). ancestor( X, Z) :- parent( X, Yl), parent( Yl, Y2),
parent( Y2, Z). ancestor( X, Z) :- parent( X, Yl), parent( Yl, Y2),
parent( Y2, Y3), parent( Y3, Z). parent I • ancestor (a) I J ancestor
parent Figure 1.5 Examples of the ancestor relation: (a) X is a direct
ancestor of Z; (b) X is an indirect ancestor of Z.
1.3 Recursive rules 15 A Prolog clause with the above meaning is:
ancestor( X, Z) :- parent( X, Y), ancestor( Y, Z). We have thus
constructed a complete program for the ancestor relation, which
consists of two rules: one for direct ancestors and one for indirect
ancestors. Both rules are rewritten together as: ancestor( X, Z) :-
parent( X, Z). ancestor( X, Z) :- parent( X, Y), ancestor( Y, Z). The
key to this formulation was the use of ancestor itself in its definition.
Such a definition may look surprising in view of the question: When
defining something, can we use this same thing that has not yet
been completely defined? Such definitions are called recursive
definitions. Logically, they are perfectly correct and understandable,
which is also intuitively obvious if we look at Figure 1.7. But will the
Prolog system be able to use recursive rules in computation? It turns
out that Prolog can indeed easily use recursive definitions. Recursive
programming is, in fact, one of the fundamental principles of
programming in Prolog. It is not possible to solve tasks of any
significant complexity in Prolog without the use of recursion. Going
back to our program, we can ask Prolog: Who are Pam's successors?
That is: Who is a person that has Pam as his or her ancestor? ?-
ancestor( pam, X). X = bob; X = ann; X = pat; X = jim Prolog's
answers are, of course, correct and they logically follow from our
definition of the ancestor and the parent relation. There is, however,
a rather important question: How did Prolog actually use the
program to find these answers? An informal explanation of how
Prolog does this is given in the next section. But first let us put
together all the pieces of our family program, which was extended
gradually by adding new facts and rules. The final program is shown
in Figure 1.8. Looking at Figure 1.8, two further points are in order
here: the first will introduce the term 'procedure', the second will be
about comments in programs. The program in Figure 1.8 defines
several relations - parent, male, female, ancestor, etc. The ancestor
relation, for example, is defined by two clauses. We say that these
two clauses are about the ancestor relation. Sometimes it is
convenient to consider the whole set of clauses about the same
relation. Such a set of clauses is called a procedure.
1.5 How Prolog answers questions 19 This can be read: from parent(
bob, pat) it follows that ancestor( bob, pat), by rule al. Further, we
know that parent( torn, bob) is a fact. Using this fact and the
derived fact ancestor( bob, pat) we can conclude ancestor( torn,
pat), by rule a2. We have thus shown that our goal statement
ancestor( torn, pat) is true. This whole inference process of two
steps can be written as: parent( bob, pat) =>■ ancestor( bob, pat)
parent( torn, bob) and ancestor( bob, pat) => ancestor( torn, pat)
We will now show how Prolog finds such a proof that the given goals
follow from the given program. Prolog starts with the goals and,
using rules in the program, substitutes the current goals with new
goals, until new goals happen to be simple facts. Let us see how this
works for the question: ?- mother( pam, bob). Prolog tries to prove
the goal mother( pam, bob). To do this, Proog looks for clauses
about the mother relation. So it finds the rule: mother( X, Y) :-
parent( X, Y), female( X). This rule is true for all X and Y, so it must
also be true for the special case when X = pam, and Y = bob. We
say that variables X and Y get 'instantiated', and this results in the
special case of the mother rule: mother( pam, bob) :- parent( pam,
bob), female( pam). The head of this clause is the goal Prolog wants
to prove. If Prolog manages to prove the body of the clause, then it
will have proved mother(pam,bob). Prolog therefore substitutes the
original goal mother(pam,bob) with the goals in the body: parent(
pam, bob), female( pam) These now become Prolog's next goals.
Prolog tries to prove them in turn: first parent (pam,bob), and then
female (pam). The first goal is easy because Prolog finds that
parent(pam,bob) is given as a fact in the program. So it remains to
prove female(pam). Prolog finds that this is also given as a fact in
the program, so it is also true. Thus the proof of mother(pam,bob) is
completed and Prolog answers the question with 'yes'. Now consider
a more complicated question that involves recursion: ?- ancestor(
torn, pat). To satisfy this goal, Prolog will try to find a clause in the
program about the ancestor relation. There are two clauses relevant
to this end: the clauses labelled by al and a2. We say that the heads
of these rules match the goal. The two clauses, al and a2, represent
two alternative ways for Prolog to proceed. This is graphically
illustrated in Figure 1.9 which shows the complete execution trace.
We now follow Figure 1.9. Prolog first tries the clause that appears
first in the program, that is ah ancestor( X, Z):- parent( X, Z). Since
the goal is ancestor(tom,pat), the variables in the rule must be
instantiated as follows: X = torn, Z = pat
The mind is generally clear in the early stage; afterward there may
be delirium, especially along with cerebral complication.
MORBID ANATOMY.—It is rarely that the pia mater is the only tissue
involved in the inflammation. Frequently the inner surface of the dura
is the seat of a fine injection, with delicate false membranes, and the
cord itself—at least its exterior portions—probably always
participates more or less in the congestion. The pia is reddened and
thickened, the surface showing small bloody extravasations, and the
space between its two layers is the seat of a fibro-purulent deposit.
The spinal fluid is turbid and flocculent. The seat and extent of the
morbid appearances vary in different cases; they are always more
abundant in the posterior than the anterior part of the cord, and may
be confined to a limited space or extend throughout its whole length.
It is remarkable that the region of the medulla oblongata is generally
free or only slightly affected; but since bulbar symptoms are often
prominent in grave cases, Leyden6 accounts for it by supposing that
the exudation is washed away by the constant movement of the
cerebro-spinal fluid. If the cord be involved in the inflammation, it is
softened and injected, the nerve-sheaths are destroyed, and the
axis-cylinders swollen in places. The nerve-roots show hyperæmia,
infiltration of the interstitial tissue with round cells, and destruction of
the nerve-sheaths.
6 Klinik der Rückenmarks-krankheiten, von E. Leyden, Berlin, 1874, vol. i. p. 407.
Chronic spinal meningitis may follow the acute form, or it may arise
from chronic disease of the vertebræ or of the cord, especially
myelitis and sclerosis. It is most apt to accompany sclerosis of the
posterior columns, and it is often difficult to say in any particular case
whether the meningeal affection preceded or followed that of the
cord. Probably some cases of chronic myelitis, especially of the
disseminated form, owe their origin to chronic meningitis.7 It has
been thought to follow blows on the back, and also to arise from
general concussion without traumatism, and has been considered as
a frequent result of accidents from railroad collisions, etc. This view
has been disputed by Herbert W. Page,8 who says: “Of the
exceeding rarity of spinal meningitis as an immediate result of
localized injury to the vertebral column we are well assured.... And
we know of no one case, either in our own experience or in the
experience of others, in which meningeal inflammation has been
indisputably caused by injury to some part of the body remote from
the vertebral column.” Chronic alcoholism and syphilis, especially the
latter, predispose to the disease. In many cases no adequate cause
can be assigned.
7 Leyden, op. cit., vol. i. p. 442.
8 Injuries of the Spine and Spinal Cord, without Apparent Mechanical Lesion and
Nervous Shock, in their Medico-legal Aspects, London, 1883, p. 128.
13 A case of scorbutic spinal hemorrhage is reported in the British Med. Journal, Nov.
19, 1881.
As may be inferred from what has already been said, the course of
spina bifida is usually rapid and toward a fatal termination. In some
instances, however, as in cases observed by Holmes, and more
recently by Lithgow, spontaneous recovery has followed the
obliteration of the channel which unites the sac with the cavity of the
spinal membranes; and in other instances, without a cure having
been effected, life has been prolonged for very many years. Thus,
Behrend reports a case in which a patient with spina bifida lived to
the age of fifty, and Holmes refers to another in which death resulted
from an independent disease at the age of forty-three. But a still
more remarkable case was recorded by Callender, the patient in this
instance having reached the age of seventy-four.
The introduction of iodine into the sac of a spina bifida is, according
to Morton, only justifiable in cases unattended by paralysis; under
opposite circumstances I should be disposed to try a plan recently
employed with success by Noble Smith in a case of meningocele—
viz. injecting the iodo-glycerin solution into the coverings of the sac,
and as close to it as possible without perforating it.
(3) and (4). Ligation and excision have each occasionally effected a
cure, but more often have but helped to precipitate a fatal issue. A
successful case of ligation followed by excision has been recently
recorded by Löbker. The elastic ligature, applied around the neck of
the sac (if this be pedunculated), has been employed by Laroyenne,
Ball, Colognese, Baldossare, Mouchet, and other surgeons, and of 6