\documentstyle[a4,alltt]{article}
 
 
\topmargin 0.9 in         %   Nominal distance from top of paper
                          %   to top of page - 1in
\textheight 7.3 in        %   Height of body of page
\textwidth  5.25 in       %   Width of text area
\oddsidemargin  0.5 in    %   (Left margin on odd-numbered pages-1in)
\evensidemargin 0.5 in    %   (Left margin on even-numbered pages-1in)
\marginparwidth 1 in      %   Width of marginal notes.
\parindent 0.25 in        %   Amount of indent on first line of para
 
\begin{document}
 
\newcommand{\idx}[1]{}
 
\title{Supplement 1}
\author{Jocelyn Ireson-Paine}
\maketitle
 
 
\section{Introduction}
 
    These exercises follow on from Lesson 1, and show you some more
examples of how you can use Logic to represent everyday situations.
 
  If you are in the Tutor, then before
going any further, please delete  any facts that may be in your
knowledge base. I'll be asking you to load various new knowledge bases,
and I don't want them to get mixed up with whatever facts you already
have. Remember, you can delete the old facts by typing
\begin{verbatim}
    delete all.
\end{verbatim}
If you want  to save them for future  use, then before deleting,
use the \verb#save# command, for example
\begin{verbatim}
    save myfacts.
\end{verbatim}
 
%sann
%{\it The
%request to delete existing facts is not necessary if the student
%always uses \verb#restore#\idx{restore@\verb#restore# command} to load new knowledge bases. However, there are
%some exercises on composing questions which ask for files to be
%\verb#load#ed,\idx{load@\verb#load# command}
%so that students can't ``cheat''\idx{cheating}
%by inferring answers from the
%predicate definitions.
%With these, we must ensure that none of the loaded
%facts\idx{facts!over-written by \verb#load#}
%are already in the textbase\idx{textbase!and \verb#load#}:
%as mentioned in
%section~\ref{ch:examples:load}, \verb#load# does not check this.}
 
 
\section{A geographical knowledge base (PP)}
 
    The knowledge base called \verb#countries#\idx{COUNTRIES|ee}
contains a number of facts about
European countries, capitals, rivers and seas, some shown below:
\begin{alltt}
    ireland has_capital dublin.\idx{has\_capital/2@\verb#has_capital/2#|ee}
    uk has_capital london.
    portugal has_capital lisbon.
    dublin is_on liffey.\idx{is\_on/2@\verb#is_on/2#|ee}
    london is_on thames.
    lisbon is_on tagus.
 
    liffey linked_to irish_sea.\idx{linked\_to/2@\verb#linked_to/2#|ee}
    thames linked_to north_sea.
    manzanares linked_to jarama.
 
    atlantic is_a sea.\idx{is\_a/2@\verb#is_a/2#|ee}
    mediterranean is_a sea.
    baltic is_a sea.
 
    ireland borders uk.\idx{borders/2@\verb#borders/2#|ee}
    portugal borders spain.
    spain borders france.
 
    black_sea next_to mediterranean.\idx{next\_to/2@\verb#next_to/2#|ee}
    baltic next_to kattegat.
    kattegat next_to skagerrak.
 
    rumania on_sea black_sea.\idx{on\_sea/2@\verb#on_sea/2#|ee}
    bulgaria on_sea black_sea.
    turkey on_sea black_sea.
\end{alltt}
 
    I hope the meaning is clear. In the facts for
\verb#has_capital#\idx{has\_capital/2@\verb#has_capital/2#|ee}, the first name is always that of a country, the second of
a town (or city). In those for \verb#is_on#\idx{is\_on/2@\verb#is_on/2#|ee}, the first name is a town, and
the second is either a river or a sea.
 
    \verb#linked_to#\idx{linked\_to/2@\verb#linked_to/2#|ee} is about rivers and seas: there is one fact for each
river that flows into another river or a sea. \verb#next_to#\idx{next\_to/2@\verb#next_to/2#|ee} tells you which
seas (not rivers) are next to one another.
 
    \verb#borders#\idx{borders/2@\verb#borders/2#|ee} is like \verb#next_to#\idx{next\_to/2@\verb#next_to/2#|ee}, but is about countries, not seas. It
tells you which countries share a common border.
 
    Finally, \verb#on_sea#\idx{on\_sea/2@\verb#on_sea/2#|ee} tells you which countries adjoin a given sea.
 
 
\subsection{Some questions}
 
    To start, please delete any existing facts,
as described above, and then
load the new knowledge base by doing
\begin{verbatim}
    load countries.
\end{verbatim}
The \verb#load#\idx{load@\verb#load# command|ee} command is a bit like \verb#restore#\idx{restore@\verb#restore# command|ee} in that it expects to be
given the name of a file. However, the
files it loads have been treated in such a way as to make their facts\idx{facts!loading|ee}
un-showable. What really happens is that the Tutor copies the facts
into the memory\idx{memory, Tutor's} it uses for inference\idx{inference!in Logic|ee}, but not into the one used for
text. This means that you can't see the text, and so it stops
you getting answers to questions by reading the
predicate\idx{cheating|ee}
definitions
instead of asking questions. Incidentally,
files that you \verb#load#\idx{load@\verb#load# command|ee} are also inaccessible to \verb#restore#\idx{restore@\verb#restore# command|ee} (and
vice versa): if you try to \verb#restore# \verb#countries#, the Tutor will tell
you that it can't find such a file.
 
    Now try some questions. Can you:
\begin{itemize}
\item Ask a question to find the capital of \verb#bulgaria#. Remember that
all names of things are in lower case, even though in English, they
would begin with a capital letter.
 
\item Ask which country has capital \verb#vaduz#.
 
\item Find on which river \verb#vaduz# lies.
 
\item Find which countries adjoin the \verb#irish_sea#.
 
\item Find which countries have exactly the same name as their capitals.
\end{itemize}
 
Was this knowledge base written before or after German unification?
Before or after Berlin became capital?
Before or after the breakup of the USSR?
 
%sann
%{\it
%\begin{sloppypar}
%This knowledge base is in COUNTRIES.PL\idx{COUNTRIES}. I last
%updated the final question on the 9th of September 1991, by which time
%Berlin had taken over from Bonn. Asking \verb#X has_capital berlin# will
%bind \verb#X# to \verb#germany#, whereas \verb#X has_capital bonn# will fail.
%\end{sloppypar}
%
%Asking for all solutions to an appropriate predicate and seeing what
%names correspond to Germany or the Germanies while checking against
%bordering countries and seas will show that only one Germany is
%mentioned. The check against neighbours is necessary because I might
%have been perverse and just referred to West Germany as \verb#germany#
%omitting East Germany altogether. Doing the same for the USSR will show
%that it is still treated as one country.
%
%Many variations on this kind of exercise are possible --- though history
%does not often provide the opportunity taken here. Such variations
%include those where one student prepares a knowledge base and then sets
%problems for a friend to answer by appropriate questioning. Another
%possibility would be to put students in the place of detectives, using
%the Tutor to interrogate the environment for clues.
%
%With all these exercises, one needs care with names, ensuring that the
%questioner knows the conventions followed in writing them as unquoted
%atoms\idx{atoms!conventions for, in exercises} --- where are underlines\idx{underlines!in atoms} inserted, are the middle initials of
%people's names included, is ``North'' written in full or abbreviated\idx{abbreviations!of atom names!choosing} as
%\verb#n# and so on. }
 
 
\subsection{Using {\tt and}}
 
\idx{and@\verb#and#|(ee}
 
    Can you ask questions to find out:
\begin{itemize}
 
\item Which country is both on the \verb#baltic# and the \verb#skagerrak#?
 
\item Which country is on the \verb#black_sea#, and has a capital which is
on the \verb#dimbo_vita#?
 
\end{itemize}
 
\idx{flows\_to/2@\verb#flows_to/2#|(ee}
 
    There is another fact in this knowledge base, called \verb#flows_to#.
This is defined as follows:
\begin{alltt}
    X flows_to Y if
        X linked_to Y.
 
    X flows_to Y if
        X linked_to Z and
        Z flows_to Y.
\end{alltt}
The idea it expresses is that river X flows to river or sea Y if the
water from X flows directly or indirectly to Y. Try the question
\verb#X flows_to Y?#
and compare it with the results from
\verb#X linked_to Y?#.
 
    Translate the definition into good English (using pronouns instead
of variables\idx{variables!as pronouns|ee}). Why do you think it works? \verb#flows_to# is
your first example of a technique, very common in
logic programming, called {\it recursion\idx{recursion|ee}},
where something is defined in
terms of itself. If you have studied grammars in linguistics, or
programmed in high-level languages before, you may have encountered it
already. We shall see several more examples.
 
%sann
%{\it Similar examples can be constructed using other knowledge bases,
%such as ROYALTY.PL\idx{ROYALTY}, a family tree of European
%royalty, taken from the DEC-10\idx{DEC-10 library} public domain library. Students can also
%be asked to build their own knowledge bases. The lack of unary
%predicates\idx{predicates!unary!in Logic}
%(which is addressed when we change to Prolog) can be overcome
%by writing (for example) not \verb#is_sea(X)# but \verb#X is_a sea#.
%
%\idx{flows\_to/2@\verb#flows_to/2#|)ee}
%
%A point made in Lesson 1, but worth
%making again is the fact that the Tutor knows
%nothing about a relation beyond what it is told. The countries\idx{COUNTRIES}
%knowledge base contains the fact
%\verb#ireland borders uk#\idx{borders/2@\verb#borders/2#},
%but the
%question \verb#uk borders ireland# will fail. Consequently, we must
%resort to the usual trick of defining a new predicate ---
%\verb#X adjoins Y#\idx{adjoins/2@\verb#adjoins/2#}, say --- to be true if X borders Y or Y borders X. Similar
%remarks apply to transitive relations. This is one example of how Prolog
%is not a knowledge representation\idx{Prolog!as
%knowledge representation language} language. More on this is said in the
%supplement to Lesson 2, concerning the caves world.\idx{caves world}}
 
\idx{and@\verb#and#|)ee}
 
 
\section{A ski-resort advisor (PP,AI)}
\label{ch:lesson1:ski}
 
\idx{ski advisor|(ee}
\idx{expert system!Logic as a|(ee}
 
    In this section, I'm going to show you how you can use Logic as a
simple ``expert system'': a program that can be used to give expert
advice about some rather restricted area of knowledge, and which can
justify its conclusions.
 
    Please
\verb#restore# (not \verb#load#) the \verb#skier#\idx{SKIER} knowledge-base. This is a set of nine rules
which advise skiers on their choice of resort, depending on fitness
(as measured by the number of pressups that can be done
without collapsing),
purpose (is it serious training, or just entertainment), and the
number of lessons already taken.
 
 
\subsection{Translating into English}
 
    Have a good look at the facts you've restored. You can do so by using
\verb#show#. You may need to use a command like \verb#show 10/40#,
or perhaps \verb#show suits#, to display the earlier facts so they don't
get pushed off the screen. Alternatively, you can make a copy on paper
with a command such as \verb#show ctc#.
 
    When
you have
done that, write down in colloquial English what these facts mean.
Don't keep to the ``if---and'' form used by Logic (unless you are
in the habit of phrasing your sentences like that anyway :-).
Instead, act
as though you are translating from (say) French, and trying
to make your translation read as naturally as possible.
 
    You will see that the knowledge base uses the symbols \verb#<#\idx{</2@\verb#</2#|ee} and \verb#>=#\idx{>=/2@\verb#>=/2#|ee}.
\verb#<# means ``less-than'', as you might expect. \verb#>=# means
``greater-than-or-equal'', and is the nearest the keyboard can come to
the standard mathematical symbol for this operation.
We'll say more about ways to compare numbers in Lesson 5.
 
\idx{facts!conditional!mutually exclusive|(ee}
    Notice that all the conditions are complete and mutually
exclusive. For example,
the three rules for \verb#is_a#\idx{is\_a/2@\verb#is_a/2#|ee} cover all possible combinations of fitness
and number of lessons, and no two rules overlap. The same goes for
\verb#has_fitness#\idx{has\_fitness/2@\verb#has_fitness/2#|ee}.
When you write your own rules, you need not make them
complete (i.e. covering all possible cases), but you should think
carefully about which cases are left out. It is a good idea to make
rules mutually exclusive. To see what happens when they're not, consider
these rules:
\begin{alltt}
    Skier has_fitness poor if\idx{has\_fitness/2@\verb#has_fitness/2#|ee}
        Skier max_pressups P and
        P < 15.
 
    Skier has_fitness good if
        Skier max_pressups P and
        P >= 10.
\end{alltt}
 
    Suppose that a skier can do a maximum of twelve pressups before
dropping dead. The first rule then says that he has poor fitness; but the
second contradicts it, saying he's got good fitness. If you were to make
this change, and then ask for advice about someone in this situation
(the next section tells how to do this), you'll find that you get two
solutions, offering conflicting advice. This is not surprising: given
the rules above, both solutions would be logically correct. In general,
this is something to avoid. Unfortunately, the need to make rules
mutually exclusive can make them rather verbose. There are ways to avoid
this, but they require more knowledge of Prolog and of the order
in which it visits facts during inference.
\idx{facts!conditional!mutually exclusive|)ee}
 
 
\subsection{Running the program}
 
    Assume you are advising a prospective skier. Not being terribly
good, he can perform only four pressups without collapsing, and he has
taken so far 174 skiing lessons. Not surprisingly, his purpose in
seeking a resort is to have fun rather than taking the subject
seriously. You can express this in Logic as follows:
\begin{alltt}
    eddie max_pressups 4.\idx{max\_pressups/2@\verb#max_pressups/2#|ee}
    eddie had_lessons 174.\idx{had\_lessons/2@\verb#had_lessons/2#|ee}
    eddie wants fun.\idx{wants/2@\verb#wants/2#|ee}
\end{alltt}
The name of the skier is of course arbitrary, and any name would do as
long as you use it consistently.
 
    Enter this information into the Tutor. Then ask the Tutor what
resort he should go to. Which facts do you think it used to infer the
answer? Check by using the \verb#why#\idx{why@\verb#why# command|ee} command.
 
    Now, consider another skier --- Charles. Charles has had 10 lessons,
his purpose is entirely serious, and he can do 62 pressups in one
session. Enter these three facts in such a way that they replace the
three you have about Eddie.
 
    Where does the Tutor say Charles should go? Which facts would it
have used?
 
 
\subsection{Changing the knowledge-base}
 
    People who write expert systems often need to update the
knowledge bases to reflect
changes in their subject. There are now a number of commercially
available expert systems for
giving advice on tax --- how to get the
best relief on your mortgage, how to minimise corporation tax, and so on
--- and at least one experimental system for advising on
Social Security benefits, though the Government seems to have decided
not to
make the latter generally available to claimants.
Such systems have to be modified yearly to keep up with the annual
amendments to income tax and decreases in
benefits. In other cases, changes are needed because our
knowledge, or the way we expressed it in rules, was incorrect and needs
modifying. This is often the case with systems for treating
electronics faults, for instance. This
section puts you in the place of an expert systems
programmer.
 
    As it stands, the meaning of good fitness is rather optimistic. It
would be more sensible to say that at least 50 pressups are needed.
Change the knowledge base to reflect this.
 
    Also, we would get finer gradation with a new fitness level: medium.
So let's say now that someone who can do at least 25 pressups
is medium fit. If they can't do that many, they're still of poor
fitness. Make such a change.
 
    Now, let's have two new ratings together with beginner and advanced:
pro and semi-skilled.
 
    Pro is better than advanced. Obviously, someone can be a pro only
with a fitness level of good. And every pro must not only have good
fitness, but also have taken at least 70 skiing lessons.
 
    We shall downgrade the meaning of beginner. Now, we shall say that
everyone is a beginner if they have taken nine or fewer lessons. A skier
who has taken up to 20 lessons is also a beginner if his (or her)
fitness is poor; but counts as semi-skilled if of medium (or good)
fitness. With 20 lessons or above, any person whose fitness is poor
is still a beginner no matter how many lessons they have had. Likewise, a
skier of medium fitness is semi-skilled, regardless of the number of
lessons.
 
    Actually, you are also only semi-skilled even up to 40 lessons,
even if your fitness is good. But should you have had 40 or more, you
count as advanced.
 
    Now, add new facts (replacing existing ones if necessary) so they
correctly reflect these regulations. Test what you've done by adding
facts as you did for Eddie and Charles, and asking questions about
rating.
 
    Note that the Tutor can't
find resorts for the new ratings. This is not
surprising, as there are no facts covering them. Think of some new
resorts, and add them to your knowledge base.
 
%sann
%{\it The description above can be interpreted in several ways,
%depending on which defaults one assumes.
%
%The best way to construct the new knowledge base is probably to draw a
%three-by-five table. Down the left-hand side, write the five different
%lesson bands: less than 10; 10 to 20; 20 to 40; 40 to 70; and greater
%than 70. Along the top, write the three fitness values: poor, medium,
%and good. Then fill in each cell with the corresponding rating.
%Translating the result into Logic gives the knowledge base SKIER2.LOGIC\idx{SKIER2}.
%
%As SKIER2\idx{SKIER2} stands, the first two rules for
%\verb#is_a#\idx{is\_a/2@\verb#is_a/2#} overlap --- one
%concludes that anyone with fewer than ten lessons is a beginner, the
%other that anyone with poor fitness is. This does no harm since the two
%are consistent, but it will yield two solutions with the same answer.
%This can be used to demonstrate that the Tutor
%is not clever
%enough to eliminate repeated answers: it just displays each one as it
%was returned.\idx{questions!repeated solutions to}.
%
%When building the new knowledge base, many students will run along the
%description, typing in new rules as they go, and getting into a mess as
%a result. This can be used to show how it is better to work out a
%complicated program completely before typing it in.}
 
 
\subsection{Comparison with expert systems (AI)}
 
    Some of you have seen the Alvey expert system video in the
introductory lecture for this course, or have encountered them in H.C.I.
or A.I. tutorials.
 
    Like an expert system, the Tutor uses rules to
infer new facts from old. But the user interface differs from that of a
typical expert system. How?
 
    If you don't know anything about expert systems, then imagine
yourself as a novice skier who wants advice on the most suitable resort.
You also have little experience with computers, and you can't type. Do
you think this means of getting advice is ideal?
 
    What about the expert system programmer? What aids would be useful
when updating the knowledge base?
 
%sann
%{\it I added this
%question when the Department introduced an A.I.
%paper for finals: most of the students on the practical course that year
%had already had tutorials on expert systems. The video is \cite{alvey},
%mentioned earlier. It's worth emphasising that Logic
%and Prolog are {\it
%not} expert systems. Now the Prolog hype has died down, this
%mistake is less common than it was.}
 
\idx{ski advisor|)ee}
\idx{expert system!Logic as a|)ee}
 
 
\section{Inference (AI)}
 
\idx{inference|(ee}
 
Lesson 1 introduced the term {\it inference}, which is the deduction of
new facts from old ones. In expert systems\idx{expert system!and inference methods|ee} work, and logic programming
generally, we distinguish two main kinds of inference.
 
 
\subsection{Forward chaining}
 
\idx{inference!forward chaining|(ee}
 
One kind is called {\it forward chaining}, and sometimes {\it data
directed},
because inference is triggered by the arrival of new data in
the knowledge base. For example, suppose we have the knowledge base:
\begin{alltt}
    10 X has_exam finals if X is_in_year 3.\idx{has\_exam/2@\verb#has_exam/2#|ee}
    20 X lives in_college if X is_in_year 3.\idx{lives/2@\verb#lives/2#|ee}
    30 X needs_to work if X has_exam finals.\idx{needs\_to/2@\verb#needs_to/2#|ee}
\end{alltt}
and we add the fact
\begin{alltt}
    john is_in_year 3.\idx{is\_in\_year/2@\verb#is_in_year/2#|ee}
\end{alltt}
A forward-chaining system would immediately trigger any rules whose
conditions are satisfied by this fact. In this example, the conditions
of rules 10 and 20 are both satisfied --- i.e. both are true when we set
X=\verb#john#.
So the system would create the two facts below and add them
to the database\idx{database!in forward chaining|ee}:
\begin{alltt}
    john has_exam finals.\idx{has\_exam/2@\verb#has_exam/2#|ee}
    john lives in_college.\idx{lives/2@\verb#lives/2#|ee}
\end{alltt}
As each new fact\idx{facts!created by forward chaining} is created, the system would look for yet more rules
that its arrival could trigger. In this case, the fact
\verb#john has_exam finals# would trigger rule 30, because
\verb#X has_exam finals# is true if X=\verb#john#. This would result
in the addition of
another new fact:
\begin{alltt}
    john needs_to work.\idx{needs\_to/2@\verb#needs_to/2#|ee}
\end{alltt}
The fact \verb#john lives in_college# would not trigger anything else
though.
 
Generally speaking, in a forward-chaining system, once a fact is
created, it is there to stay until explicitly deleted. If this is so,
answering a question need not itself
require any inference. If on receiving a new fact, the system makes all
possible inferences from it, then answering a question need only involve
scanning these facts one by one.
 
\idx{inference!forward chaining|)ee}
 
 
\subsection{Backward chaining}
 
\idx{inference!backward chaining|(ee}
 
In distinction to forward chaining is {\it backward chaining}. This is
sometimes called {\it goal-directed inference},
because inferences are
not made until the system is made to prove a particular goal (i.e. a
question). This is a lazy kind of inference. It does no work until
absolutely necessary, in distinction to
forward chaining\idx{inference!forward chaining|ee}, where the
system eagerly snaps up new
facts and immediately tries applying existing rules to them
as soon as they arrive.
 
So, if we had the same knowledge base again
\begin{alltt}
    10 X has_exam finals if X is_in_year 3.\idx{has\_exam/2@\verb#has_exam/2#|ee}
    20 X lives in_college if X is_in_year 3.\idx{lives/2@\verb#lives/2#|ee}
    30 X needs_to work if X has_exam finals.\idx{needs\_to/2@\verb#needs_to/2#|ee}
\end{alltt}
and we were to add
\begin{alltt}
    john is_in_year 3.\idx{is\_in\_year/2@\verb#is_in_year/2#|ee}
\end{alltt}
the system would not try to trigger any conditions. But suppose we were
then to ask the question
\begin{alltt}
    X needs_to work?\idx{needs\_to/2@\verb#needs_to/2#|ee}
\end{alltt}
 
The system would try to prove this by searching for a suitable rule or
unconditional fact, i.e. ones whose conclusions are about the same
``verb'', \verb#needs_to#\idx{needs\_to/2@\verb#needs_to/2#|ee}.
Here, fact 30 is the only one. What this fact
means, in effect, is
``to
prove someone needs to work, prove they have Finals''. So the
system would then pose itself the subtask of proving that John has
finals. Fact 10 says something about this: ``to prove someone has
Finals, prove they're a third year''. So the system now poses the
sub-sub-task of proving John to be a third year. And we have an
unconditional fact
which says he is. So we can complete the proof.
 
\idx{inference!backward chaining|)ee}
 
 
\subsection{Which does the Tutor use?}
 
\idx{response time!symptom of internal behaviour|(ee}
 
In psychology, a common way of investigating human information
processing is by response time experiments. Suppose with the Tutor that
you had some way of measuring the time between adding a fact and getting
the prompt\idx{prompt|ee},
and between asking a question and getting the answer.
How could you determine which kind of
inference is going on? Note that you can't determine this by seeing
whether new facts appear in the text memory\idx{memory, Tutor's}:
if forward chaining\idx{inference!forward chaining|ee} were going
on, it might be putting new facts into the memory\idx{memory, Tutor's} used for inference, but
not into the one used to hold text
(like \verb#load#\idx{load@\verb#load# command|ee} does).
 
If you don't like thinking about the psychology of computers, put
yourself in the place of a psychologist who has just discovered
live Martians. They speak a kind of English: to be
more exact, they behave just as the Tutor would if it
worked on speech not text. Our psychologist has discovered that the
Martians make the same kind of inferences as the Tutor: but
is this by forward or backward chaining?
%sann
%{\it This question was inspired by a chapter in
%{\it Perceptions and Representations}~\cite{oatley} in which the author
%exposes some of psychology's methodological shortcomings by imagining
%intelligent aliens coming to Earth and performing lesion experiments
%on computers. Given my assumptions, one
%would expect the time taken after inputting a fact to depend only on its
%position during
%backward chaining\idx{inference!backward chaining}, but on the number of
%possible inferences during
%forward chaining\idx{inference!forward chaining}. There are of course other ways
%of inferring in each direction: for example, question-answering might
%provoke a forward-chaining cycle that terminates once a solution is
%found.
%
%It is worth telling the students that the set of new facts that can be
%inferred is the same whatever the inference method. Logic is separate
%from control.}
 
\idx{inference|)ee}
\idx{response time!symptom of internal behaviour|)ee}
 
 
\section{English versus Logic (PP)}
 
 
\subsection{The uses of ``and''}
 
\idx{and@\verb#and#!English usages of|(ee}
 
Consider this knowledge base, which expresses some facts
about various under- and post-graduates. \verb#gcr#, incidentally, stands
for ``Graduate Common Room'': in some colleges, it would be called
the Middle Common Room.
\begin{alltt}
    paul is_friends_with stan.\idx{is\_friends\_with/2@\verb#is_friends_with/2#|ee}
    stan is_friends_with paul.
    paul is_in_year 1.\idx{is\_in\_year/2@\verb#is_in_year/2#|ee}
    stan is_in_year 2.
 
    Student has_status post_graduate if\idx{has\_status/2@\verb#has_status/2#|ee}
        Student is_in_year N and N > 3.\idx{>/2@\verb#>/2#|ee}
 
    Student belongs_to gcr if\idx{belongs\_to/2@\verb#belongs_to/2#|ee}
        Student has_status post_graduate.
 
    paul has_post jcr_treasurer.\idx{has\_post/2@\verb#has_post/2#|ee}
    stan has_post jcr_president.
 
    Officer has_duty attend_governing_body_meetings if\idx{has\_duty/2@\verb#has_duty/2#|ee}
        Officer has_post jcr_president.
    Officer has_duty attend_ousu_meetings if
        Officer has_post jcr_president.
    Officer has_duty organise_elections if
        Officer has_post jcr_president.
    Officer has_duty keep_the_books if
        Officer has_post jcr_treasurer.
\end{alltt}
 
Write, in Logic, the sentences below. Explain the different meanings of
``and'' in each.
\begin{itemize}
    \item Dave and Jason are third-years.
 
    \item Dave and Jason are friends.
 
    \item The JCR Warden's duties are mending the pinball machine and the
video-games and selling punt cards.
 
    \item First-years, second-years, and third-years are undergraduates and
members of the JCR.
 
\end{itemize}
 
%sann
%{\it The file COLLEGE.LOGIC\idx{COLLEGE}
%contains a translation of these sentences.
%This exercise was inspired by one in \cite{rowe}.}
 
\idx{and@\verb#and#!English usages of|)ee}
 
 
\subsection{The uses of ``if''}
 
\idx{if@\verb#if#!English usages of|(ee}
 
Suppose a friend of yours asks, having seen you do this practical: ``I
want to go skiing for fun. If I can do 45 pressups in one go, and I've
taken 6 lessons so far, which resort should I go to?''.
 
How does his use of the word ``if'' differ from that in a statement like
``Someone is a beginner if they have taken no more than ten lessons''?
 
%sann
%{\it I have found that students frequently use ``if'' in questions when
%trying to set up assumptions. For example}
%\begin{verbatim}
%    Where suits me if me had_lessons 6 and me max_pressups 45?
%\end{verbatim}
%
%sann
%{\it This is why one of the Tutor's diagnostics checks for \verb#if#
%\idx{if@\verb#if#!erroneous use in questions}
%\idx{errors!common}
%in questions. To represent such assumptions in Logic, as we did in the
%skiing example\idx{ski advisor}, they must be asserted as facts.}
 
\idx{if@\verb#if#!English usages of|)ee}
 
 
\subsection{``And'' versus ``or''}
 
\idx{and@\verb#and#!English usages of|ee}
\idx{or@\verb#or#!English usages of|(ee}
 
It can seem that the connection between two
facts for the same ``verb'' sometimes means ``and'' and
sometimes ``or''. For example
\begin{alltt}
    earth has_moons 1.
    mars has_moons 2.
\end{alltt}
mean ``Earth has one moon {\it and} Mars has two moons'', while
\begin{alltt}
    Skier is_a beginner if\idx{is\_a/2@\verb#is_a/2#|ee}
        Skier had_lessons L and
        L < 10.
 
    Skier is_a beginner if
        Skier has_fitness poor.
\end{alltt}
means ``A skier is a beginner if they had fewer than ten lessons, {\it
or} if their fitness is poor''? Why is this?
 
%sann
%{\it
%Formally, this is easy to see using the definition of implication.
%Consider the two skiing rules\idx{ski advisor} above: schematically,
%\begin{eqnarray*}
%P \mbox{\ if\ } Q \\
%P \mbox{\ if\ } R
%\end{eqnarray*}
%that is,
%\begin{displaymath}
%(Q \vee R) \rightarrow P
%\end{displaymath}
%which, using the standard definition of implication, becomes
%\begin{displaymath}
%\neg(Q \vee R) \vee P
%\end{displaymath}
%Applying De Morgan's law, we get
%\begin{displaymath}
%(\neg Q \wedge \neg R) \vee P
%\end{displaymath}
%and expanding out gives
%\begin{displaymath}
%(\neg Q \vee P) \wedge (\neg R \vee P)
%\end{displaymath}
%Re-inserting implication gives
%\begin{displaymath}
%(Q \rightarrow P) \wedge (R \rightarrow P)
%\end{displaymath}
%}
 
\idx{and@\verb#and#!English usages of|ee}
\idx{or@\verb#or#!English usages of|)ee}
 
 
\subsection{How rules are phrased}
 
Go through the section on the ski advisor.\idx{ski advisor|ee}
Make a list of all the different English
phrases there that you translated into conditional
facts\idx{facts!conditional!English equivalents|ee}, and note
the way pronouns are used in each. Can you think of any other phrasings?
 
 
\section{Knowledge engineering (AI)}
\label{ch:lesson1:ke}
 
\idx{knowledge engineering|(ee}
\idx{expert system!Logic as a|(ee}
 
    Much of the business of programming is converting vague everyday
language into precise programs. In A.I., we often have to do this when
putting the knowledge into expert systems, as
we saw earlier.
 
    It is the job of the {\it knowledge engineer} to interview experts
and set them trial problems, then convert the results into something
an expert system can handle.
Experts usually are not able to talk
systematically through a topic, giving neat syllogisms like those in the
other exercises. Instead, they'll ramble, throwing in little snippets of
information as something prompts its recall. Below, I imagine such a
monologue from a G.P. who's being interviewed during the construction of
a medical expert system.
 
  Can you translate this into Logic? What you need to do is to
identify key concepts in the monologue: kinds of treatment, different
types of illness, the various symptoms, and so on. Then tease out all
the logical connections, throwing away any un-necessary ones. Finally,
write down the rules, after choosing suitable names for your facts.
 
 
\begin{quotation}
You were asking what drugs I bought last month. Well, the main one's a
new product from Hoffnung-Gavroche called brontomycin --- if I buy more
than 30 g each month, they throw in a free skiing holiday at the end of
the year. They're very good with these perks. I must have gone on at
least 50 skiing lessons since I started with Hoffnung. Of course, I only
go for fun; to train seriously you need to be really fit, and with all
these drug company bashes I've been to recently, I couldn't even do a
pressup without collapsing, let alone the daily half-marathons those
professional skiers seem to thrive on.
 
It seems to be good stuff though\ldots Treats what we call remediable
infections. Fowlpox's one such. Very easy to prescribe, because it works
the same for all remediables. Just give the patient a daily dose of 10
mg for four weeks.
 
I treated the Mayor with it last week when he returned from a holiday in
Enschede in Holland. He had Dutch measles. That's another remediable
infection. You want to know the symptoms \ldots itchy red spots all over
and high temperature. As with all remediable infections, you have to
quarantine for three weeks, otherwise the kids get it. And that's where
you must take care to halve the dose, if you don't then some children
may develop eczma, hyperactivity and floating ribs.
 
I remember that because the hairdresser caught fowlpox recently. He does
pets as a sideline, and the local chicken farmer had called him in for a
root-perm and auburn rinse on his prize Leghorns before they went up to
the Royal Poultry Show. It's like Dutch measles, but the temperature
crashes to 92 or so. Anyway, he refused my quarantine order \ldots
wanted the money I suppose \ldots it was just before the school sports
day, and all the parents were bringing in their brats to be smartened
up. Whole school went down with it.
 
Thought at first he might have an allergy. Some people are allergic to
the plant extracts in deodorants, and get itchy red spots \ldots or
sometimes hard black lumps in the armpits instead. No trouble to treat
--- like all allergies you remove the cause for a trial period, that's
ten days, and then desensitise. He never uses them though --- most
unpleasant in there on a hot day. Smells like the Black Hole of
Calcutta\ldots
 
There's another allergy. James the florist came in last month, he'd was
shaking with cold, had severe itching and red spots all over. Not the
chickens this time; I knew he works with exotic plants from the nursery
up there, and so I asked him whether he'd handled any of those Rumanian
``Devil's Lovebite'' creepers. That causes a plant allergy too: ``False
Fowlpox'' because it looks the same if you don't know the cause.
 
Someone else had that \ldots well actually it wasn't the allergy but
something else. A senior chemist from the Grimbledon Down bio-warfare
place. She had exactly the same symptoms. Nasty place, Grimbledon
Down\ldots they run recombinant-DNA analysis on plague
strains. Suppose it's safe, but\ldots standing instructions from the MoD
if anyone shows up with high temperatures and black lumps or itchy red
spots: plague's non-remediable, so there's no treatment, not even
brontomycin. But you must take safety precautions. Not really
quarantine, no \ldots evacuate the country for a radius of five miles,
burn the corpses, and shoot all the foxes, rats, badgers, and voles. Oh,
and the chickens.
 
Anyway, get back to the chemist \ldots she'd been refining batavium.
They use it in cold-fusion research. Left the fume-cupboard open, and
got a whiff \ldots came down with the same symptoms as ``Devil's
Lovebite''. But if it's caused by batavium, then it's not a plant
extract allergy, but heavy metal poisoning. You have to flush out the
whole system with chelates, and place on dialysis for four weeks. That
reminds me \ldots if she'd had a remediable infection, I'd have to
replace the brontomycin by 30 mg daily of prestatine \ldots it seems
that more than 500 gm daily of bronto causes birth defects in rats, so
it's been forbidden for pregnant women\ldots \end{quotation}
 
Now translate the following question, and use the Tutor to answer it:
Kylie, having just returned from a holiday in Eindhoven, has itchy red
spots all over and a high temperature. Do you recommend any safety
precautions such as quarantine? What treatment is recommended? Would you
change this if she were pregnant? What's the cause?
 
%sann
%{\it This exercise is definitely one where students will get into
%trouble if they type a translation straight into the terminal without
%first working it out on paper. A possible answer
%is in DISEASE.LOGIC.\idx{DISEASE}}
 
\idx{expert system!Logic as a|)ee}
\idx{knowledge engineering|)ee}
 
 
\section{Some terminology}
 
\idx{predicates|(ee}
 
    I want to finish with some terminology. So far, I've talked about
the ``verb'': the middle word in a fact, such as \verb#loves# or \verb#suits# or
\verb#has_duty#. This is not a very good name, because the word often doesn't
take the form of a verb. It may for example be a preposition or a
preposition plus a verb, such as \verb#february is_after january#.
Programmers often write like this when describing spatial or temporal
relationships.
In future therefore, I shall borrow the terminology of
formal logic, and call this part of a fact the {\it predicate}. All the
Prolog literature uses this name.
 
\idx{predicates|)ee}
 
\idx{arguments|(ee}
 
    The things either side of the predicate are its {\it arguments}. So,
in \verb#john loves mary#, the arguments are \verb#john# and \verb#mary#. This is a
specialised meaning of ``argument'', and it has nothing to do with
disputes or disagreements; again, it comes from logic.
 
\idx{arguments|)ee}
 
    I shall use the word {\it rule}\idx{rules|ee} to mean a conditional fact\idx{facts!conditional|ee} from now
on, that is one containing an \verb#if#. Prolog is not the only type of
programming system to use ``if \ldots then \ldots'' statements; many
expert\idx{expert system|ee} systems and other AI programs do too, and such statements are
generally referred to as rules.
 
    When I want to talk about an unconditional fact\idx{facts!unconditional|ee} (no \verb#if#) I shall
say so specifically; I shall use the word {\it fact} on its own to mean
either. Sometimes I may use the word {\it clause}\idx{clauses|ee} instead of fact,
following the custom of the Prolog literature.
 
    I shall also talk about {\it defining a predicate}. In logic
programming, the meaning of a predicate\idx{predicates!meaning of!not
understood by Tutor|ee}
is defined solely by the clauses
for it. There is no other authority the Tutor can appeal to; it does not
have an internal encyclopaedia telling it what a predicate ``ought'' to
mean (apart from a very few ``built-in'' predicates, which you'll meet
later).
 
Predicate\idx{intensional definitions|ee} definitions can be of two kinds.
Some are what logicians call {\it intensional}: they
consist of a general rule or two which try to capture the essence of
(say) what it means for one person to be the ancestor of another, or
what it means for one number to be the factorial of another. You will
see some of these in Lesson 2. For example, if Bert is an ancestor of
Charles, and Amanda of Caroline, there is something in common about the
way both are related. Bert has a child who is Charles, or who has a
child who is Charles, or who has a child who is Charles, \ldots Amanda
has a child who is Caroline, or who has a child who is Caroline, or who
has a child who is Caroline, \ldots. To write intensional definitions,
you have to extract these structural regularities and work out how to
formalise them in logic.
 
    Other predicates
are {\it extensional}\idx{extensional definitions|ee}. Here, the definition is
often just a long list of unconditional facts. For example, the facts
you accumulated about \verb#loves# in Lesson 1. Expert system\idx{expert system} rules for
domains like medicine are often of this form; lacking a decent theory of
the underlying principles, all you can do is to write down all the rules
of thumb that experts have built up by experience. The knowledge bases
of the skiing and disease exercises are of this kind.
 
    In either case, the definition of a predicate will consist of one or
more clauses. Each clause will express some part of the meaning, but you
need them all in order for the definition to be complete.
 
 
\subsection{Naming predicates}
 
    Finally, a note about names. When writing new facts, you may have to
choose names for your predicates\idx{predicates!choosing names for|ee}
--- names like \verb#is_a#, or \verb#loves#, or
\verb#has_part#. Please avoid the name \verb#is#\idx{is/2@\verb#is/2#!a misleading name|ee}. That's because it means
something special to Prolog. If you try to define a fact whose predicate
is \verb#is#, you will get confusing messages about updating built-in facts.
 
 
\section{How the Tutor works}
\label{ch:lesson1:studentsmodel}
 
 
\subsection{What the Tutor really does}
 
\idx{model!of Tutor|(ee}
 
The objective of these lessons is to teach you the programming language
Prolog. To make this easier, I have started with a simpler language
called Logic. Now, it is important to realise that Logic is in fact just
a less forbidding way of writing Prolog. As the course goes on, I shall
show you how what you say in Logic translates into Prolog.
 
Prolog is a commercially-available programming language. For \pounds 100
or so, you can walk down to your local computer shop and buy a version
of Prolog for an IBM PC. For rather more, I can go to one of numerous
suppliers and buy a more comprehensive version of Prolog that will run
on the computer you're using now. The Prolog we use here was written
by Sussex University and forms part of what's called the Poplog system.
 
Logic, however, is not available off the shelf. I designed it
specially for this course. The original version was devised by Steve
Hardy and extended by Aaron Sloman, also at Sussex; I have based the
Tutor on their idea, though with many modifications.
 
\idx{memory, Tutor's|(ee}
Let's start by talking about what kinds of memory the Tutor
has. If it had none at all, it would have to react in the same way to
every sentence you typed, because it would have nowhere to store
information that could change its reactions. So knowing what information
is stored, where, and what for, is important. In fact, this is true for
any program, indeed any system, not just the Tutor.
 
 
\subsection{Textbase and database}
 
\idx{facts!storage of|(ee}
 
\idx{database|(ee}
The two most important memory areas are the {\it database}
and the {\it
textbase}\idx{textbase|ee}.
The database is where facts are held for inference\idx{inference!in Logic|ee}. From
Lesson 1, you saw that if you type an incorrect fact, such as
\verb#zwoogle loves#, then the Tutor will not make any inferences with it. However,
it can still \verb#show#\idx{show@\verb#show# command|ee} you the fact. This is because the fact, being
grammatically incorrect, means nothing, and the database can only hold
meaningful facts. Compare human language: you can still sing the lyrics
to ``Fr\`{e}re Jacques'' or ``Mairzey Doats'', even if you don't
understand them.
\idx{database|)ee}
 
The textbase\idx{textbase|(ee}
is where the text of facts is held. It, not the database\idx{database|ee},
is what \verb#show# reveals. You may now be asking: but if I type a fact, it
always gets \verb#show#n\idx{show@\verb#show# command|ee} neatly printed, with the conditions neatly indented
and each on a new line. This is because the Tutor tidies up the
text somewhat before putting it into the textbase,\idx{textbase!and \verb#show#|ee}
to make it easier for
you to read.
\idx{textbase|)ee}
\idx{information representation!in Tutor|(ee}
Why have these two areas? Because inference\idx{inference!in Logic|ee} requires a fact to be
encoded or represented in a different way from editing. The editor is
interested in a fact's text, and wants something close to what you
typed. But in inference\idx{inference!in Logic|ee}, facts have to be stored in such a way that
Prolog can get quickly from one fact to a related one. Text is is not
ideal for this; those representations that are good for inference look
nothing at all like the original text and typically involve added
indexes so that the relevant parts of a fact can be found quickly. If
this comment doesn't mean much, it will after Supplement 7, which demonstrates
how the way that information is represented by a program can affect
efficiency.
\idx{information representation!in Tutor|)ee}
 
\idx{facts!storage of|)ee}
 
 
\subsection{The question buffer}
 
We also have a kind of mini-textbase\idx{textbase!question buffer as a|ee}
for the previous question\idx{question buffer|ee}. You have
seen that \verb#why#\idx{why@\verb#why# command|ee} gives a justification; it works by picking up
the previous question and re-asking it, while making a record at each
step in the inference\idx{inference!in Logic|ee}. The last question\idx{questions!editing|ee} can also be edited and re-asked
(ask your teacher about this if necessary). So we need to store it.
 
Why not store all the old questions? Because doing so would complicate
the commands\idx{commands}. If the Tutor did
store all the questions, you would need some way
of referring to them: some kind of question range\idx{ranges!question|ee}. You might say: well,
I could cope with \verb#show q 1/3#\idx{show@\verb#show# command!with questions|ee} to display questions 1 to 3, and just
keep \verb#show 1/3#\idx{show@\verb#show# command|ee} for showing facts 1 to 3. But experience shows that with
two such similar commands, people would always be forgetting the \verb#q# and
showing facts when they wanted questions. This could cause confusion,
since simple questions, those without an \verb#and#\idx{and@\verb#and#|ee}, look just like facts. So it's better
to keep things simple.
 
 
\subsection{Other memories --- script positions and the sentence buffer}
 
The Tutor also remembers a few other things. One is your position in the
script\idx{scripts!position in!as part of Tutor's state|ee},
which is stored as a number, and the name of the current script.
So when you do a \verb#next#\idx{next@\verb#next# command|ee} or \verb#again#\idx{again@\verb#again# command|ee}, the Tutor knows which section to go
to next.
 
Another is the {\it sentence buffer}\idx{sentence buffer|ee},
which holds your input. Before I
can explain this, I have to digress to a bit and discuss operating
systems and the RETURN
key.
\idx{memory, Tutor's|)ee}
 
 
\subsection{Operating systems}
 
\idx{operating system|(ee}
\idx{model!of student's computer system|(ee}
 
When you log into the VAX, you get a start-up message saying something
like ``This is VMS version 5.1'', together with a lot of extraneous
garbage. Modern multi-user computers all come with a master control
program or {\it operating system} which sits in the machine continuously
looking after all the other programs. Generally, such computers are
designed so that they can only run one program at a time. To
give the appearance of dealing simultaneously with the twenty people in
this class plus all the other users elsewhere, the operating system
{\it time-shares}. It picks one terminal, sees which program is to be
run there, and runs it for a few milliseconds. It then interrupts this,
saving the state the program had got to, and picks another terminal. It
runs that program for a few milliseconds, interrupts it, saves it, and
picks yet another terminal. Eventually, it gets back to the first. If
each program is only run for a very short time on each round, you get an
effect like that of film frames, where the operating system comes back to
you so frequently that your program {\it appears} to be running all the
time. This resembles some theories of attention in psychology, and
indeed they were probably inspired by this idea of a master controller
sharing out resources amongst lots of subordinate programs.
 
If there are many other users, the operating system can devote less
proportion of its time to each, so the programs appear to be running
slower. This happens especially in mid-morning and mid-afternoon, and
accounts for all those irritating pauses.
 
 
\subsection{What happens to your input --- inside the operating system}
 
To remain in control --- to give everyone a fair share of the machine
--- the operating system has to take charge of everything that goes into
it, including your input. Generally, when you press a key, it gets sent
to a storage area called a {\it buffer} inside the operating system.
When you
press another key, the same happens. It continues happening until you
hit RETURN. When this happens, the operating system
has collected a whole line of input, and it
now sends this all at once to your program. Why does the operating system
store
input in this way? Partly for efficiency. It's quicker to batch up the
characters and send a whole batch to the terminal in one go than it is
to send them one-by-one, because there's a constant overhead associated
with every transmission. Partly for historical reasons, in that early
computers worked on punched cards, and programming languages
were designed
to
fit one sentence on each card. With such languages, you might as well
wait until the whole card has been read before sending any of it.
 
The important point then is that whatever you type gets held by the
operating system, and will not get to the Tutor --- ever --- unless you
press RETURN. You can visualise this if you imagine each character moving
along a conveyer belt from the terminal to the operating system. The
latter puts each character into a box. Only when it sees a RETURN does
the system send the entire box (the line) on to the Tutor.
 
%sann
%{\it This analogy is due to Gyan Mathur.}
 
If you forget RETURN, it is easy to think that the Tutor is just
being very slow to deal with your sentence. This is why I kept
emphasising the need for it.
 
%sann
%{\it If your Prolog can manage it, consider making the Tutor give a
%warning if a certain time elapses without a new sentence being
%typed.}
 
 
\subsection{What happens to your input --- inside the Tutor}
 
\idx{sentence buffer|(ee}
When the input reaches the Tutor, there are more complications caused by
the fact that sentences need not be exactly one line long. If they were,
it would be easy to tell where they ended. But consider a long sentence
like this
\begin{verbatim}
    john loves mary
    if
    mary drinks wine
    and
    mary drinks beer.
\end{verbatim}
 
You type \verb#john loves mary# and hit RETURN. The operating system has
collected up these characters and sent them to the Tutor on seeing the
RETURN. Now, has the Tutor got a complete sentence? The answer is that
it can't tell. \verb#john loves mary# could be a fact in its own right; but
it could also be a question, or part of a larger fact or question. So
the Tutor has to hang on and wait until it knows it has got to the end.
Using dot or question-mark gives it an easy way to tell, and also
provides a convenient signal
that distinguishes
facts\idx{facts!distinguishing from questions|ee} from
questions\idx{questions!distinguishing from facts|ee}.
 
\idx{memory, Tutor's|(ee}
You can now see why the Tutor needs a sentence buffer.
As it receives
each line, it scans from left to right looking for the first dot or
question mark. When it finds one, it takes everything upto that point as
the sentence and processes it. The rest of the line, if any, is left in
the buffer.
When the Tutor has finished processing the first sentence,
it looks at the buffer again.
If there's another dot or question-mark,
the Tutor grabs the next sentence. If not, it waits until another line
arrives from the operating system, then joins that onto the end of the
buffer\,
and scans again for a terminator\idx{sentence terminator|ee}. And so on.
\idx{memory, Tutor's|)ee}
 
The upshot of this is that even if you hit RETURN, if you don't finish a
sentence with a terminator\idx{sentence terminator|ee}, the Tutor will again just keep waiting.
However, because it has the sentence buffer,
it knows when a sentence
has been started but not finished, and it changes its
prompt\idx{prompt|ee}
from \verb#*# to
\verb#*...# to remind you.
 
Note that the Tutor does not use any other cue than the terminator\idx{sentence terminator|ee}. Even
if a sentence looks complete, the Tutor will wait until it sees a
terminator\idx{sentence terminator|ee}. This is partly because, as in the last
example, complete-looking sentences need not be, and partly because it
makes the programming easier.
 
Note also that you can type facts with
numbers\idx{numbers!internal point not recognised as terminator|ee} in, like
\verb#march rainfall_was 31.42#. This is discussed in Lessons 4 and 5. These
dots don't confuse the Tutor because when scanning for dots, it
recognises numbers and skips over their decimal points.
\idx{sentence buffer|)ee}
 
 
\subsection{How sentences are processed}
 
This is simple. Any sentence that starts with the name of a command\idx{commands!how processed by
Tutor|ee} is
assumed to be a command, regardless of its terminator\idx{sentence terminator|ee}. Any other
sentence ending in a question-mark is assumed to be a question\idx{questions!how processed by Tutor|ee}, and any
other ending in a dot is assumed to be a fact\idx{facts!how processed by Tutor|ee}.
 
This can give the Tutor the appearence of being very stupid. If you type
\verb#shw 10/40#\idx{show@\verb#show# command|ee} in mistake for \verb#show 10/40#, we find it obvious that it was
meant to be a command\idx{commands!errors in}. However, the Tutor does not share our ability for
this kind of intuitive correction. This is something that's very
difficult to program, and is itself part of A.I.\@ In consequence,
programmers usually adopt very simple strategies of looking for cue
words and symbols to tell one class of input from another, and that is
what I did in writing the Tutor.
 
Because \verb#shw 10/40#\idx{show@\verb#show# command|ee} is not (in the Tutor's eyes) a command, and it ends
with a dot, the Tutor therefore assumes it to be a fact\idx{facts!incorrect sentences assumed to be|ee}. But it isn't
grammatically correct, so it gets error-reported as an incorrect fact,
and when you \verb#show# it you will see pointy brackets around it. Luckily
you can delete it without any difficulty, and since it's deemed to be
incorrect, it plays no part in inference\idx{inference!in Logic|ee}, so that it is there does not
matter in the slightest.
 
Sometimes questions\idx{questions!errors in|ee}
\idx{facts!incorrect sentences assumed to be|ee}
cause a similar error. When asking them, some
students accidentally type a dot instead of question-mark. The Tutor
uses only the dot as a cue, and so treats the sentence as a fact.
Sometimes it will look grammatically correct --- \verb#john loves mary# ---
and will go into the textbase\idx{textbase|ee} and the database\idx{database|ee}. Sometimes it
will be incorrect ---
\verb#john loves mary and mary likes wine# --- and will go into the textbase\idx{textbase|ee}
only.\idx{database!ignored by bad facts|ee}
 
 
\subsection{The {\tt save} and {\tt restore} commands}
 
\idx{facts!saving|(ee}
\idx{facts!restoring|(ee}
 
Finally a word about saving. When you do a \verb#save#\idx{save@\verb#save# command|ee}, the Tutor makes a
copy of the text of your facts, and sends them to a file. When you do a
\verb#restore#\idx{restore@\verb#restore# command|ee}, the Tutor looks in the appropriate file, and reads the text
sentence by sentence, copying correct facts to both textbase\idx{textbase!and \verb#restore#|ee} and
database\idx{database!ignored by bad facts|ee},
and incorrect ones to the textbase\idx{textbase!and \verb#restore#|ee}
only (where you can correct
them).
 
Why is it necessary to have these commands at all? This brings us onto the
topic of computer memory.
 
\idx{facts!saving|)ee}
\idx{facts!restoring|)ee}
 
 
\subsection{Types of memory}
 
\idx{memory, Tutor's|(ee}
Beginners to computing are often confused because they don't know how
long their work will stay around after they go, and they don't
appreciate the difference between the different kinds of memory the
computer has.
 
All modern computers have two kinds of memory. The first is made out of
silicon chips. These chips are expensive (though they become less so
every year), so there is economic pressure to use as little as possible.
The second type of memory stores information on magnetic storage
devices.
These
are called discs, and are much bigger versions of the floppy
discs and the hard disc that modern microcomputers have. This kind of
memory is cheaper than silicon chips, so manufacturers can
afford to build more of it into their computers.
 
Magnetic storage is cheaper --- but it's also slower, because it has
moving parts. This is why we need chip memory at all: a computer that
used only magnetic storage would be far too slow to be useful.
 
I talked earlier about how the operating system time-shares between
programs, picking one after another and running them each for a very
short time, round-robin fashion. When it does this, it stores the
programs in chip memory, for speed. Once it has finished running a
program, that portion of memory is then allocated to some other program.
So when you type \verb#bye#\idx{bye@\verb#bye# command|ee} and exit from the Tutor, the chip memory that it
occupied gets given to someone else, and whatever stuff you have left
there is overwritten. Hence when you next start up the Tutor, it will
not see any of the stuff that it left in chip memory last time.
 
 
\subsection{Files}
 
\idx{files|(ee}
Because magnetic storage is so much cheaper, we need not be so
parsimonious with it. As with micro-computer discs, the VAX discs are
used for long-term storage of data --- stuff created one day, and used a
day, week, or year hence. The information in magnetic storage will stay
around after your program has stopped; it will also stay around if the
computer is switched off (for repair maybe), or crashes. This is
something else chip memory won't do. So files stored on discs are
definitely a good thing.
 
To end this section, remember that the Tutor may, when you restart it,
appear to be picking up facts that you entered during the previous
session. This is because, as I said in Lesson 1, it periodically saves
all your facts to a file called AUTO\idx{AUTO|ee}, thus ensuring that some work
survives even if you forget to save it. On being started up, it looks
for this file, and restores from it if it exists. This gets round the
problem of stuff vanishing from chip memory when a program finishes
running.
\idx{memory, Tutor's|)ee}
\idx{files|)ee}
 
 
\subsection{Who are you talking to?}
 
\idx{subsystems|(ee}
A common source of bewilderment on this system is that although you are
communicating with the same computer all the time (a VAX computer, in
fact), you are not talking to the same {\it program} all the time.
Beginners often talk about ``the computer'', as though it
were one indivisible entity. It is more accurate to think in terms of
multiple personalities, each program having its own personality,
memory, and language, and knowing nothing of the others sharing the same
machine.
 
So although the operating system and the Tutor both share the VAX, they
follow completely different conventions. The Tutor needs sentence
terminators\idx{sentence terminator|ee}; the operating system does not. Beginners will often type
\begin{verbatim}
    logic lesson1.
\end{verbatim}
to the operating system, and get understandably confused when it
complains about an unwanted dot. Similarly, some people forget to start
up the Tutor after logging in, and try typing facts and commands at the
operating system, provoking cascades of error messages. To get round
this, the best advice is: watch the prompt\idx{prompt|ee}!
The Tutor's prompt is \verb#*# or
\verb#*...#; the operating system's is always \verb#$#.
 
The networks and intermediate stages are another source of bewilderment.
When you start up the terminals in C.T.C., you begin by talking to a
program running on the micro-computer there. The commands you give that
tell it to connect to the University master switchboard. In turn, you
must tell the switchboard to connect to the VAX. Then you tell a VAX
LOGIN program to log you in, typing your username and password; then you
tell the operating system to start up the Tutor; and finally you talk to
the Tutor. So you have all these sub-systems to deal with.
\begin{verbatim}
    Micro <-> switchboard <-> LOGIN  <-> VAX operating <-> Tutor
                                         system
                                                             ^
                                                       ______|_______
                                                       |You are here|
                                                       --------------
\end{verbatim}
 
It is difficult at first to remember which sub-system you are talking
to at any stage, but practice makes it all seem easy, eventually.
 
%sann
%{\it Though parts of this have little direct connection with the Tutor,
%they do provide something I think to be essential, and that is a
%conceptual model of the rest of the computer system. Some of this
%was inspired by the Poplog HELP files.}
 
\idx{operating system|)ee}
\idx{subsystems|)ee}
\idx{model!of Tutor|)ee}
\idx{model!of student's computer system|)ee}
 
\end{document}
