\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 3}
\author{Jocelyn Ireson-Paine}
\maketitle
 
 
\section{Introduction}
 
This supplement just contains
a brief test of your ease with Prolog, and then explains how the Tutor
manages the translation between Prolog and Logic.
 
 
\section{Damnation and limbo (PP)}
 
The knowledge base
below arose during a lecture by Richard Ennals, who has done a lot of
work on teaching Prolog in schools, especially to historians and other
non-scientists.
\begin{alltt}
    deserves( X, damnation ) :-\idx{deserves/2@\verb#deserves/2#|ee}
        committed( X, Y ),
        is_a( Y, deadly_sin ),
        doesnt_repent( X, Y ).
 
    deserves( X, limbo ) :-
        committed( X, Y ),
        is_a( Y, deadly_sin ),
        repents( X, Y ).
 
    deserves( X, commendation ) :-
        committed( X, Y ),
        is_a( Y, useful_act ),
        doesnt_benefit_just( Y, X ).
\end{alltt}
 
A machine-readable copy is in a file called SIN\idx{SIN|ee}.
Please start up your Tutor, and load it in. You will
have to do this by using the command \verb#load sin#, not \verb#restore sin#. As
mentioned in Supplement 1, \verb#load#\idx{load@\verb#load# command|ee} works like \verb#restore#\idx{restore@\verb#restore# command|ee}, but it only loads
facts into the database\idx{database!and \verb#load#|ee} and not the textbase\idx{textbase!and \verb#load#|ee}, so you can't
\verb#show#\idx{show@\verb#show# command!ignores \verb#load#ed facts|ee} them.
If you could, then you could deduce the answers I want from the
predicate\idx{cheating|ee}
definitions, which would make the exercise a bit pointless.
By the way, if
you try to \verb#restore#\idx{restore@\verb#restore# command|ee} SIN, the Tutor will tell you it can't
find the file.
 
 Having done so, please ask Prolog questions to find out the following
things:
 
\begin{enumerate}
 
\item There are some facts whose predicate is \verb#committed#\idx{committed/2@\verb#committed/2#|ee}. They relate a
person to something he or she has committed. What has \verb#nick# committed?
 
\item Who has committed \verb#overtime#?
 
\item Who has committed both \verb#overtime# and \verb#secret_theft#? Do this by
asking {\it one} question with a comma (``and'') in it, rather than by
asking one question and passing the answer into another.
 
\item There are some \verb#is_a#\idx{is\_a/2@\verb#is_a/2#|ee} facts. They relate an action to its
classification. What kind of action is \verb#overtime#?
 
\item Which people have performed acts that don't benefit themselves
alone?
 
\item Someone has done one thing of which he repents, and another of
which he doesn't. Again, please use {\it one} question with a comma in
it, rather than two or more separate ones.
 
\end{enumerate}
 
%sann
{\it  I have not been terribly explicit about what the predicates
mean: part of the exercise's purpose is to make the student deduce this
by reading the definition of {\tt deserves}. I usually find one or
two students who ignore the code, not realising that they can derive
this information from it.}
 
 
\section{The textbase, and how the Tutor changes mode}
 
\idx{model!of Tutor|(ee}
\idx{textbase!and mode-switching|(ee}
\idx{database!and mode-switching|(ee}
\idx{facts!how processed by Tutor!and Prolog mode|(ee}
\idx{questions!how processed by Tutor!and Prolog mode|(ee}
 
In Supplement 1, I introduced the textbase and database, and talked
about how they are related. You may remember that I said the textbase
contains the text of facts, tidied up by removing extra spaces,
inserting newlines and so on, so that they look readable when listed by
\verb#show#\idx{show@\verb#show# command|ee}. This was actually a fib, but a benign one, intended to give you
a comprehensible model of how the Tutor works. Too often software comes
without any such model, and you're left to fumble about in the dark,
possibly building up a totally misleading impression of what is really
behind that screen. In writing up the Tutor, I have tried to provide an
explicit model, which although it may be simplified, allows you to
predict correctly what the Tutor will do in various circumstances. For
more on the topic of design, and what makes all sorts of things (not
just software)
easy or difficult to use, I strongly recommend you to read {\it The
Psychology of Everyday Things} by Donald Norman.
 
Now back to the Tutor. What
actually happens is that whenever it reads a fact, it first
checks the syntax. If this is OK --- if the fact is grammatically
correct --- the Tutor translates it into Prolog, and stores the
translation in the textbase. It also plonks the fact into the
database, so that it can take part in
inference\idx{inference!in Prolog mode|ee}. This
happens regardless of whether the Tutor is in Logic or Prolog mode,
though of course if the Tutor is already in Prolog mode, it has to do
very little translation.
 
\idx{pretty-printing!in \verb#show#|(ee}
Whenever you call \verb#show#\idx{show@\verb#show# command!and Prolog mode|ee}, the Tutor checks the mode. If it's in Prolog
mode, it can write out the fact almost verbatim, needing
only a bit of tidying up so that each predicate starts
on a new line. If it's in Logic mode, it reverses the process of
translation, taking the Prolog and converting it back into its equivalent
Logic form. This is a lot simpler than translating (say) French to
English; there is only one Logic form for every Prolog form, and vice
versa, so no questions of ambiguity arise. It also means this can be
done for {\it every} fact, no matter how it was input. Having done the
translation, the Tutor can then write out the translated form, again
after some tidying up (or {\it pretty-printing}
as computer scientists
like to call it).
 
So the textbase does not actually contain your original text. Instead it
contains a Prolog translation, which is translated back to Logic if
necessary.
 
Incorrect facts are handled differently. Here, the Tutor does preserve
the original text. It stores this in the textbase, and writes it out
(possibly with some spaces removed) when you show\idx{show@\verb#show# command!and Prolog mode|ee} or change the\idx{change@\verb#change# command}\idx{edit@\verb#edit# command|ee} fact.
\idx{textbase!and \verb#show#|ee}
Incidentally, this text stays the same even if you change modes. The
Tutor could hardly do otherwise --- it would be like trying to take
a mis-spelt word in French and translate it so it has the same kind of
mis-spelling in English.
\idx{pretty-printing!in \verb#show#|)ee}
 
\idx{textbase!and mode-switching|)ee}
\idx{database!and mode-switching|)ee}
\idx{facts!how processed by Tutor!and Prolog mode|)ee}
\idx{questions!how processed by Tutor!and Prolog mode|)ee}
\idx{model!of Tutor|)ee}
 
\end{document}
