% $Id: tutor.tex,v 1.19 2008/01/25 13:30:18 logik Exp $

\documentclass[12pt]{amsart}
\usepackage{amssymb,enumerate}

% for pdftex
\usepackage[backref]{hyperref}

\evensidemargin  5mm
\oddsidemargin  5mm
\textwidth  150mm
\textheight 225mm

\allowdisplaybreaks[4]
\parskip 0pt plus 1pt

\def\qedsymbol{{\ \vbox{\hrule\hbox{%
   \vrule height1.3ex\hskip0.8ex\vrule}\hrule}}\par}



% minlog.mac contains the macros for all tex-files of the minlog
% documentation in order to avoid code duplication and different
% notations.
\input{minlog.mac}


\author{L.~Crosilla}

\thanks{I would like to thank Professor Schwichtenberg 
for suggesting to write this tutorial and for useful comments
as well as for providing the example on search.
Monika Seisenberger commented on an early version of 
the tutorial proposing improvements and provided some more 
examples. In writing this tutorial I took inspiration from  
Martin Ruckert's Tutorial for an earlier version of \mi.}

\title{A Tutorial for \mi, Version 4.0}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\maketitle

\section{Introduction}

This is a tutorial for the interactive proof system \mi, version 4.0, 
developed by Helmut Schwichtenberg and members of the logic group at 
the University of Munich 
(http://www.mathematik.uni-muenchen.de/$\sim$logik/welcome.html).

\mi\ is implemented in \textsc{Scheme} and runs under every
\textsc{Scheme} version supporting the Revised$^5$ Report on the
Algorithmic Language \textsc{Scheme}. \mi's favorite dialect is Petite Chez
\textsc{Scheme} from Cadence Research Systems, which is freely distributed at 
the Internet address www.scheme.com.

The \mi\ system can be downloaded from the Internet address:

http://www.minlog-system.de/



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Getting started}


The purpose of this Tutorial is to give a very basic introduction 
to the \mi\ system by means of some simple examples. 
For a thorough presentation of \mi\ and the motivation behind it 
the reader should consult the reference manual \cite{minlogman}.
The papers listed in the \mi\ web page also provide a more 
detailed and advanced description of the system. 
In addition, the \mi\ distribution comes equipped with 
a directory of examples, to which the user is referred. The source 
code finally provides the ultimate reference.

In order to use \mi, one essentially needs a shell in which to run 
\mi\ and also an editor in which to edit and keep a record of the commands for 
later sessions. 
In this tutorial we shall refer to \textsc{GNU Emacs}.
While working with \textsc{Emacs}, the ideal would be to split the window
in two parts, one with the file in which to store the commands, 
and the other with the \mi\ interactive section taking place. 
For this it is recommended to use the
startup script \emph{\mdir/minlog} which takes files as (optional)
arguments. For example\\

\begin{quote}
  \texttt{\mdir/minlog file.scm}\\
\end{quote}

opens a new Emacs-Window which is split into two parts. The upper
part containes the file  \emph{(Buffer file.scm)} whereas the lower part
shows the Minlogresponse \emph{(Buffer *minlog*)}.

If you have already an open emacs window and do not want to open
a new one then you can invoke minlog by loading the file
\emph{minlog.el}:

\begin{quote}
  \texttt{M-x load-file <enter>}\\
  \texttt{\mdir/minlog.el}\\
\end{quote}



REMARKS:

In both cases the file \emph{init.scm} is loaded.

In the description above I assumed tacitly that you are using an
UNIX-like operating system and that minlog is installed in
\mdir, where \~{} denotes as usual your home directory.

% To split the window in two, one types \texttt{Ctrl-x 2}.
% Then, to open a new file where to keep a record of the commands 
% one types \texttt{Ctrl-x Ctrl-f} and digits the name of the file, 
% for example \texttt{tutorial.scm}. Note that this file 
% should have the extension \texttt{scm}.
% In the other window we can first run Petite Chez \textsc{Scheme} by typing:
% \texttt{Meta-x run-petite}.
% After \textsc{Scheme} has started, it will give its prompt, e.g.\
% ``\texttt{>}''. 
% To start \mi, one moves back to \texttt{tutorial.scm} and types  
% the following line (parenthesis included):

% \bv
% (load "minlogdir/init.scm")
% \end{verbatim}

% \noindent
% where ``minlogdir'' has to be replaced with the directory in which \mi\ 
% is installed, with its relevant path.

To execute a command of your file, one simply places the cursor
at the end of it (after the closed parenthesis), and types
\texttt{Ctrl-x Ctrl-e}.  In general, \texttt{Ctrl-x Ctrl-e} will
enable us to process  any command we type in
\texttt{tutorial.scm}, but one at the time.  To process a whole
series of commands, one can  highlight the region of interest and
type \texttt{Ctrl-c Ctrl-r}.  We should also mention at this
point that to undo one step, it is enough  to give the command
\texttt{(undo)}, while \texttt{(undo n)} will undo  the last $n$
steps.  Finally, type  \texttt{(exit)} to end a \textsc{Scheme}
session and   \texttt{Ctrl-x Ctrl-c} to exit \textsc{Emacs}.



%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Propositional logic}


\subsection{A first example}

We shall start from a simple example in propositional logic.

Suppose we want to prove the tautology: 
$$
        (A \ob (B \ob C)) \ob ((A \ob B) \ob (A \ob C)).
$$

In the following we shall make use of the convention of association 
to the right of the parentheses, which is assumed by \mi.
Therefore the formula above becomes:
$(A \ob B \ob C) \ob (A \ob B) \ob A \ob C$. 
It is very important, especially in the beginning, 
to pay the maximum attention to this and similar 
conventions to prevent mistakes. It is probably a 
good idea to rather exceed in parenthesis in the first examples. 
\mi\ will automatically delete the parenthesis which are not 
needed, therefore facilitating the reading.

 

%%%%%%%%%%%%%%%%%

{\bf Making a sketch of the proof}.
We need in the first place to make an informal plan on how to prove 
this tautology.
While making this plan we should consider the following fact.
\mi\ (mainly) implements ``Goal Driven Reasoning'', also called
``Backward Chaining''. That means that we start by writing the 
conclusion we aim at as our goal and then, step by step, refine this 
goal by applying to it appropriate logical rules, until we reach the 
point of having no more goals to solve.
In other words, \mi\ keeps a list of goals and updates it 
each time a logical rule is applied.
A logical rule will have the effect of reducing the proof of 
a formula, the goal, to the proof of one or more other formulas, which will 
become the new goals.
The proof is completed when the list of goals is empty.

%In dealing with this first example we will make a plan of 
%the proof according to a ``backward reasoning'' 
%and try to go as close as possible to the formal argument.
In this case the tautology we want to prove is a series of 
implications, hence we will have to make use of basic 
rules for ``deconstructing'' implications.
The first move will then be to assume that the antecedent of the 
outmost implication is true and try to derive the consequent  
from it.
That is, we assume $A \ob B \ob C$ and want to derive 
$(A \ob B) \ob A \ob C$; hence we set the latter as our new goal.
Then we observe that $(A \ob B) \ob A \ob C$ is an implication 
and can be treated in the same way; so we now assume 
$A \ob B \ob C$ and $A \ob B$ and want to derive $A \ob C$.
Clearly, we can make the same step once more and obtain 
$A \ob B \ob C$, $A \ob B$ and $A$ as our premises and 
try to derive $C$ from them.
Now we observe that in order to prove $C$ under the assumption  
$A \ob B \ob C$, we simply need to prove both $A$ and $B$ 
under the same assumption.
Obviously $A$ is proved, as it is one of our assumptions, 
and $B$ immediately follows from $A \ob B$ and $A$. 

%%%%%%%%%%%%%%%%%

{\bf Writing the formula}.
Once we have an idea on how to prove the formula, we can start 
implementing the proof in \mi. The initial step would then be to  
write the formula in \mi.
For this purpose, we declare three predicate constants $A$, $B$ and $C$ 
by writing:

\bv(add-predconst-name "A" "B" "C" (make-arity))\end{verbatim}

The expression \texttt{(make-arity)} produces the empty arity 
for $A$, $B$ and $C$ (see \cite{minlogman} for a 
description of \texttt{(make-arity)}).
\mi\ will then write:
\bv
; ok, predicate constant A: (arity) added
; ok, predicate constant B: (arity) added
; ok, predicate constant C: (arity) added 
> 
\end{verbatim}

Subsequently, we write the formula and give it a name, say \texttt{distr}
(for distributivity of implication):

\bv
(define distr (pf "(A -> B -> C) -> (A -> B) -> A -> C"))
\end{verbatim}

This command has the effect of defining a new variable \texttt{distr} 
and attaching to it the \textsc{Scheme} term which is produced by the 
function \texttt{pf} applied to the formula we entered.
In fact, the function {\texttt pf}, short for ``parse formula'', takes a 
string as argument and returns a \textsc{Scheme} term. 
This \textsc{Scheme} term is the way \mi\ stores the string, 
or, equivalently, it is the {\em internal form} in \mi\ of our formula, 
and \texttt{distr} is a name referring to it.
By typing \texttt{distr}, one can see the value of this variable. 

%%%%%%%%%%%%%%%%%

{\bf Implementing the Proof}.
We now want to prove this formula with \mi.
In order to do this we clearly need to set the formula as our goal.

{\bf Setting the goal}. Typically, the goals in a proof will be 
numbered and the top goal will be denoted by the number 1, preceded 
by a question mark.

To set \texttt{distr} as our goal, we type:

\bv (set-goal distr)
\end{verbatim}

\mi\ will print:

\bv
; ?_1: (A -> B -> C) -> (A -> B) -> A -> C
>
\end{verbatim}


%%%%%%%%%%%%%%%%%
{\bf The proof}.
We have seen in the sketch of the proof that the first step for proving 
the tautology is to assume the antecedent of the implication and 
turn the consequent into our new goal.
This is simply done by writing:

\bv
(assume 1)
\end{verbatim}

Here the number \texttt{1} is needed in order to identify and name the 
hypothesis. \mi\ will denote this hypothesis by \texttt{1}:

\begin{verbatim} 
; ok, we now have the new goal 
; ?_2: (A -> B) -> A -> C from
;   1:A -> B -> C
> \end{verbatim}

We repeat the assume command to decompose the implication in the 
new goal:

%\newpage

\bv (assume 2)\end{verbatim}


\bv  
; ok, we now have the new goal 
; ?_3: A -> C from
;   1:A -> B -> C
;   2:A -> B
> \end{verbatim}

And we decompose the goal once more:

\bv (assume 3)
\end{verbatim}

\bv 
; ok, we now have the new goal 
; ?_4: C from
;   1:A -> B -> C
;   2:A -> B
;   3:A
> 
\end{verbatim}

We now need to start using our assumptions. As already mentioned, 
in order to prove {\texttt C} it is enough to prove both 
{\texttt A} and {\texttt B}, by assumption \texttt{1}.   
Therefore we write: \sloppy \texttt{(use 1)}.
This has the effect of splitting the goal in two distinct subgoals
(note how the subgoals are numbered):

\bv
(use 1)

; ok, ?_4 can be obtained from
; ?_6: B from
;   1:A -> B -> C
;   2:A -> B
;   3:A

; ?_5: A from
;   1:A -> B -> C
;   2:A -> B
;   3:A
> 
\end{verbatim}

Then we write:

\bv (use 3)
 
; ok, ?_5 is proved.  The active goal now is
; ?_6: B from
;   1:A -> B -> C
;   2:A -> B
;   3:A
> 
\end{verbatim}

And conclude the proof by: 
%\newpage
\bv 
(use 2)

; ok, ?_6 can be obtained from
; ?_7: A from
;   1:A -> B -> C
;   2:A -> B
;   3:A
> 

(use 3)

; ok, ?_7 is proved.  Proof finished.
>
\end{verbatim}

To see a record of the complete proof, simply type
\texttt{(display-proof)}.  Other useful commands are
\texttt{(display-pterm)} and \texttt{(display-proof-expr)}.  See the
manual for a description of the various \texttt{display} commands
available in \mi.

We observe that an alternative to using the 
\texttt{define} command at the beginning of the proof and then 
separately setting the goal, would be to directly set the 
formula one wants to prove as a goal, that is writing 
\texttt{(set-goal (pf "(A -> B -> C) -> (A -> B) -> A -> C"))}.
Note also that the first three \texttt{assume} commands could 
be replaced by only one, i.e.: \texttt{(assume 1 2 3)}.
In alternative to the last two \texttt{use} commands, 
we could have given only one command: \texttt{(use-with 2 3)}, 
which amounts to applying a cut to the premises 2 and 3.
A final remark to the extent that in case of rather complex 
proofs, it is convenient to name specific hypothesis, in place 
of making use of bare numbers. One than can simply 
use the \texttt{assume} commands, followed by the name of the 
assumption in double quotes.

Before starting to read the next section, it is advisable to 
consult the reference manual \cite{minlogman} for a compendium  
of the commands utilized in this example. It is worth noticing 
that in general these commands
have a wider applicability than their usage as now presented.



%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%

\subsection{A second example: classical logic}

\mi\ implements minimal logic. If we want to prove a proposition 
which is true in classical logic but not in minimal logic, 
we explicitly need to state and use principles which are 
classical in nature. In the following example we shall use
Stability, which is added to \mi\ as a global assumption.
Roughly speaking, a global assumption is a proposition which 
can be recalled at any time, if needed, and whose proof does not 
concern us at the moment (hence it can also be an assumption with 
no proof).
In order to check which global assumptions we have at our disposal 
we type: 
\texttt{(display-global-assumptions)}.
To check a particular global assumption whose name we already know, 
we write the above command followed by the name of the assumption we 
want to check, 
e.g.: \texttt{(display-global-assumptions "Stab-Log")}.
Of course we can also introduce our own global assumptions and remove 
them at any time (see the reference manual for the specific commands).

Stability is the logical law for which, for any proposition 
$A$, $\lnot \lnot A \ob A$ holds.
In \mi, $\lnot A$ is defined to be $A \ob \bot$, i.e. $A$ implies 
falsum. Stability is therefore the following proposition:
$((A \ob \bot) \ob \bot) \ob A$.

Suppose we want to prove the tautology:
$$
        ((A \ob B) \ob A) \ob A, 
$$
which is known as {\em Peirce formula}.
For this second example, we will assume that the reader has prepared 
her sketch of the proof, and we will only give an intuitive idea 
of the proof, preferring to
rather concentrate on the \mi\ interaction, which will be 
given in its complete form.
 
As in the previous example, we observe first of all that 
the goal is an implication, hence we will assume its antecedent, 
$(A \ob B) \ob A$, and try to prove its consequent, 
$A$.
Now classical logic comes into play, because in order to prove 
$A$, we will assume that its negation holds and try to get a 
contradiction from it. 
This will be achieved by use of Stability.
We further note that in order to make the argument 
work, we will need at some stage to resort to another global 
assumption, the principle of ``ex falsum quodlibet''. This principle 
allows one to conclude any formula from a proof of falsum, i.e. 
it is the principle: $\bot \ob A$, for arbitrary $A$. 

We start by setting the goal and assuming the antecedent of the 
implication:

\begin{verbatim}
(add-predconst-name "A" "B" (make-arity))
(define peirce-formula  (pf "((A -> B) -> A) -> A"))
(set-goal peirce-formula)
(assume 1)
\end{verbatim}

We obtain:

\bv
; ok, we now have the new goal 
; ?_2: A from
;   1:(A -> B) -> A
> 
\end{verbatim}

We now apply Stability, which is stored in \mi\ with the 
name \texttt{Stab-Log}, so that the goal $A$ will be replaced 
by its double negation: 
$(A \ob \bot) \ob \bot$. Note that $\bot$ is called 
\texttt{bot} in \mi.
\bv
(use "Stab-Log")

; ok, ?_2 can be obtained from
; ?_3: (A -> bot) -> bot from
;   1:(A -> B) -> A
> 
\end{verbatim}

Since this is an implication, we let:

\bv
(assume 2)

; ok, we now have the new goal 
; ?_4: bot from
;   1:(A -> B) -> A
;   2:A -> bot
> 
\end{verbatim}

We then use hypothesis 2 to replace the goal $\bot$ by $A$.

\bv
(use 2)

; ok, ?_4 can be obtained from
; ?_5: A from
;   1:(A -> B) -> A
;   2:A -> bot
> 
\end{verbatim}


Also $A$ can be replaced by $A \ob B$ by use of 
hypothesis 1. Subsequently, we can assume the antecedent of the 
new goal, $A$, and call it ``hypothesis 3'':

\bv
(use 1)

; ok, ?_5 can be obtained from
; ?_6: A -> B from
;   1:(A -> B) -> A
;   2:A -> bot
> 

(assume 3)

; ok, we now have the new goal 
; ?_7: B from
;   1:(A -> B) -> A
;   2:A -> bot
;   3:A
>
\end{verbatim}

Now we can make use of the principle of ex falsum quodlibet:
if we want to prove $B$, we can instead prove falsum, since 
from falsum anything follows, and in particular $B$.
Therefore our goal can be updated to $\bot$ by the following 
instance of \texttt{use}:

\bv
(use "Efq-Log")

; ok, ?_7 can be obtained from:
; ?_8: bot from
;   1:(A -> B) -> A
;   2:A -> bot
;   3:A
> 
\end{verbatim}

The next two steps are obvious.

\bv
(use 2)

; ok, ?_8 can be obtained from
; ?_9: A from
;   1:(A -> B) -> A
;   2:A -> bot
;   3:A
> 

(use 3)

; ok, ?_9 is proved.  Proof finished.
>
\end{verbatim}


\subsection{Conjunction}

To conclude this section on propositional logic, we 
give a short example of a tautology which uses conjunction. 
We want to prove 
$$
A \land B \ob B \land A
$$
We shall simply record the code of our \mi\ proof, asking 
the reader to check \mi's reply at each step. A few comments will 
be added at the end.

\begin{verbatim}
(add-predconst-name "A" "B" (make-arity))
(set-goal (pf "(A & B) -> (B & A)"))
(assume 1)
(split)
(use 1)
(use 1)
\end{verbatim}

The command \texttt{(split)} operates on the goal if it is a 
conjunction and it has the effect of splitting it into its two 
components. The command \texttt{use} is utilized to 
obtain the left (respectively the right) conjunct in the 
assumption and ``\texttt{use}'' it to derive the goal.

The reader is encouraged to try and prove other examples of 
tautologies.


%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%


\section{Predicate logic}


\subsection{A first example.} 
We now exemplify how to prove a statement in predicate logic.

Suppose we want to prove that every total relation 
which is symmetric and transitive is reflexive.
For simplicity we shall work with natural numbers. 
We hence want to prove the following statement:
\begin{align*} 
        &       \forall n\, \forall m\, (R n m \ob R m n) 
                \,\land\, \forall n\, \forall m\, \forall k\, 
                (R n m \;\land\; R m k \ob R n k)\\
        &       \ob \forall n\, (\exists m\, R n m \ob R n n),
\end{align*} 
\noindent
where $n$, $m$, $k$ vary on natural numbers, 
while $R$ is a binary predicate on natural numbers.

Before starting to prove the claim, we observe that 
we can equivalently espress it by another formula which 
is simpler to prove in \mi, e.g. by one in which the  
conjunctions have been replaced by appropriate implications.
That is, we can instead prove the following formula: 
\begin{align*} 
        &       (\forall n,\, m. R n m \ob R m n) 
                \ob (\forall n,\, m,\, k.
                R n m \ob R m k \ob R n k)\\
        &       \ob \forall n,\, m. R n m \ob R n n,
\end{align*} 
where the ``.'' is used to indicate the scope of a 
quantifier, with the convention that it binds as far as possible.

The strategy of first simplifying the goal may in some cases 
allow one to considerably reduce the amount of time needed to prove 
a statement. However, there might be cases in which one prefers 
to prove a more complex formula, for example when proving a lemma 
which is then used in the proof of a more intricate theorem. 
For completeness and for a comparison, we shall also record a proof 
of the original goal, at the end of this section.

Since the predicate $R$ is required to vary on natural numbers, 
we first of all load a file, already available with the distribution,
which introduces the algebra of natural numbers and some
operations on them, like for example addition.
This is obtained by typing:

\bv
(libload "nat.scm")
\end{verbatim}

We can now introduce the constant $R$. We also want to facilitate
our work a bit further and separately introduce the two assumptions
$\forall n\, m. R n m \ob R m n$ and 
$\forall n\, m\, k. R n m \ob R m k \ob R nk$.
We do this by means of a \texttt{define} command, which enables 
us to give a name to each assumption. We then use these name 
to make a formula in implication form. 

In the following \texttt{py} is the analogous for types of 
the function parse formula. Note also that the file 
\texttt{nat.scm} already introduces 
$m$, $n$ and $k$ as ``default'' variables on the natural numbers, 
hence we do not need to explicitly declare them here, too.

\bv
(add-predconst-name "R" (make-arity (py "nat") (py "nat")))
(define Symm (pf "all n,m.R n m  -> R m n"))
(define Tran (pf "all n,m,k.R n m -> R m k -> R n k"))
\end{verbatim}

We now state the goal:
\bv
(set-goal (mk-imp Symm Tran (pf "all n,m.R n m -> R n n")))

; ?_1: (all n,m.R n m -> R m n) 
       -> (all n,m,k.R n m -> R m k -> R n k) 
       -> all n,m.R n m -> R n n
> 
\end{verbatim}

Note that in this specific case, we could have directly  
written the two formulas as antecedents of the implication, 
avoiding the detour through a \texttt{define} command. 
In case of more complex formulas, however, or when 
we need to use the same formulas for various proofs 
through one session, this strategy can be quite useful.


%\bv
%(display-global-assumptions)
%\end{verbatim}


We now observe that the goal is an implication, so that 
the first step would be to write \texttt{(assume "Symm" "Tran")}. 
By this command we would obtain a universally quantified 
formula and we would then need to proceed to eliminate the 
quantifiers. This can be accomplished by another \texttt{assume} 
command in which we specify two natural numbers. 
For simplicity we here fix the natural numbers $n$ and $m$.
So we would write \texttt{(assume "n" "m")}.
This would produce an implication which would also need 
to be eliminate by another \texttt{assume} 
command, say \texttt{(assume 1)}. 
We can put all these commands together by writing:

\bv 
(assume "Symm" "Tran" "n" "m" 1)

; ok, we now have the new goal 
; ?_2: R n n from
;   Symm:all n,m.R n m -> R m n
;   Tran:all n,m,k.R n m -> R m k -> R n k
;   n  m  3:R n m
> 
\end{verbatim}

The next move is to make use of our assumptions.
It is clear that if we take $k$ to be $n$ in \texttt{Tran}, 
then the goal can be obtained by an instance of \texttt{Symm}, 
and the proof is easily completed.
We here utilize \texttt{use} by additionally providing a term, 
\texttt{"m"}, which will instantiate the only variable which can not 
be automatically inferred by unification.
In the following \texttt{pt} stands for parse term.

\bv 
(use "Tran" (pt "m"))

; ?_4: R m n from
;   Symm:all n,m.R n m -> R m n
;   Tran:all n,m,k.R n m -> R m k -> R n k
;   n  m  3:R n m

; ?_3: R n m from
;   Symm:all n,m.R n m -> R m n
;   Tran:all n,m,k.R n m -> R m k -> R n k
;   n  m  3:R n m
>
\end{verbatim}

The \texttt{use} command has the effect of 
replacing the current goal with two new goals.
These are obtained from \texttt{Tran} by instantiating the 
quantifiers with \texttt{n}, \texttt{m} and \texttt{n} (the two 
\texttt{n} being inferred by unification) and then by replacing 
the goal with the antecedents of the resulting instance of 
\texttt{Tran}.

We can now write:
\bv
(use 3)

> ; ok, ?_3 is proved.  The active goal now is
; ?_4: R m n from
;   Symm:all n,m.R n m -> R m n
;   Tran:all n,m,k.R n m -> R m k -> R n k
;   n  m  3:R n m
>
\end{verbatim}

We finally employ \texttt{Symm} and another \texttt{use}:
 
\bv 
(use "Symm")

; ok, ?_4 can be obtained from
; ?_5: R n m from
;   Symm:all n,m.R n m -> R m n
;   Tran:all n,m,k.R n m -> R m k -> R n k
;   n  m  3:R n m
> 

(use 3)

; ok, ?_5 is proved.  Proof finished.
> 
\end{verbatim}


%%%%%%%%%%%%%%%%%%%%%

{\bf The same example.}
We here present a \mi\ proof of the original goal of the previous 
example, as it allows us 
to exemplify the use of some new commands.
We shall leave the proof uncommented and make a few 
remarks at the end. The reader will have to examine the 
proof and check \mi's interaction.

\bv
(libload "nat.scm")
(add-predconst-name "R" (make-arity (py "nat") (py "nat")))
(set-goal (pf "(all n,m. R n m  -> R m n) 
                     & (all n,m,k. R n m & R m k -> R n k) 
                     -> all n. ex m R n m -> R n n"))
(assume 1)
(inst-with 1  'left)
(inst-with 1 'right)
(drop 1)
(name-hyp 2 "Symm")
(name-hyp 3 "Tran")
(assume "n" 4)
(ex-elim 4)
(assume "m" 5)
(cut (pf "R m n"))
(assume 6)
(use-with 3 (pt "n") (pt "m") (pt "n") "?")
(drop "Symm" "Tran" 4)
(split)
(use 5)
(use 6)
(use-with 2 (pt "n") (pt "m") 5)
\end{verbatim}

The \texttt{use-with} command is similar to the \texttt{use} command, 
but when applied to a universal quantifier it requires to explicitly 
specify the terms one wants to instantiate. 
In its first occurrence in the proof above we write \texttt{"?"} to 
indicate that \mi\ will have to replace the current goal with a 
new goal. In the second occurrence of \texttt{use-with}, 
\mi\ will instantiate as specified the universal quantifiers 
in premise 2 and then use hypothesis 5 to prove the goal.

The command \texttt{inst-with} is analogous to  
\texttt{use-with}, but operates for forward reasoning; 
hence it allows one to simplify the hypothesis, instead of 
the conclusion. In this case, \texttt{(inst-with 1 'left)}
has the effect of producing the left component of the  
conjunction which constitutes the first hypothesis. Similarly for 
the right component.

\texttt{ex-elim} eliminates an existential quantifier
and produces a new universally quantified goal. 

As to \texttt{cut}, this command enables one to introduce new goals.
\texttt{(cut A)} has the effect of replacing goal $B$ by two 
new goals, $A \ob B$ and $A$.

In the proof above we have also made use of the commands 
\texttt{drop} and \texttt{name-hyp}. The first allows one 
to remove one or more hypothesis from the present context, to make 
the proof more readable. In fact, it simply replaces 
the current goal with another goal in which the hypothesis 
`dropped' are not displayed anymore (but they are not 
removed in general, as should be clear from the example 
above).
The second command has similar `cosmetic' purposes, 
and allows one to rename a specific hypothesis and hence 
to work with names given by the user instead of numbers
produced by default. 
Both these commands result especially useful in the case of long 
and intricate proofs.


%%%%%%%%%%%%%%%%%%%%%

\subsection{Another example with classical logic}

We conclude this section on predicate logic with a final example 
of a formula which requires classical logic.
We want to prove the following:
$$
        \exists^c x\,. Q x \ob \forall y\, Q y,
$$
where $Q$ is now a unary predicate, and we do not require $Q$ to 
range on the natural numbers. In addition, the existential 
quantifier, $\exists^c$, is here a classical existential quantifier, 
to be distinguished from the existential quantifier we encountered 
in the previous example. A classical quantifier $\exists^c x$ 
is nothing more than an abbreviation for $\lnot\, \forall x\, \lnot$.

The formula we want to prove is known as the ``drinker'' formula, 
as it says something like: ``in a bar, there is a person such that 
if she drinks then everybody drinks''.  

One could state the goal either by direct use of the classical 
existential quantifier (called \texttt{excl} in \mi) 
or by replacing it with its meaning by use of the 
universal quantifier.
In the first case one would write:
\bv
(set-goal (pf "excl x. Q x -> all y Q y"))
\end{verbatim}
\mi\ would then automatically replace the \texttt{excl} quantifier 
by its meaning when performing the first command.

Otherwise we can state the formula as follows:
\bv
(set-goal (pf "(all x.(Q x -> all y Q y) -> bot) -> bot"))
\end{verbatim}

In our implementation we shall introduce $Q$ as a predicate 
on an arbitrary type, say $\alpha$. \mi\ already has a type variable 
\texttt{alpha} as default, and we shall use it 
in the following (hence no declaration of the type 
\texttt{alpha} is needed).

As the proof is quite simple and does not introduce any new notion, we
only write the code, letting the reader verify it in \mi.

\bv
(add-predconst-name "Q" (make-arity (py "alpha")))
(add-var-name "x" "y" (py "alpha"))
(set-goal (pf "(all x.(Q x -> all y Q y) -> bot) -> bot"))
(assume 1)
(use 1 (pt "x"))
(assume 2 "y")
(use "Stab-Log") 
(assume 3)
(use 1 (pt "y"))
(assume 4)
(use "Efq-Log")
(use-with 3 4)
\end{verbatim}

We can store the proof as a theorem to be used later on 
with the command:

\bv
(save "Drinker")
\end{verbatim}

%%%%%%%%%%%%%%%%%

\section{Induction}

{\bf Induction on the natural numbers.} We now present a simple 
proof which exemplifies the use of induction on the natural numbers.
The formula to prove is the following:
$$
        \forall n,\, m.\, n + m = m + n.
$$

This can be proved by induction on the natural numbers as follows:
we fix an $n$ and show that $n + 0 = 0 + n$ and also that 
if $n + m = m + n$ then $n + Succ(m) = Succ(m) + n$.

As before we will make use of a file already available 
in the distribution which contains the definitions of 
the algebra of the natural numbers and also of the 
operations of addition and multiplication on the natural numbers.
These are defined by means of computation and rewrite rules.
If the file is not already loaded\footnote{It is a good practice to 
run a new \mi\ session when loading new files which could 
turn out to be incompatible with previously loaded files 
or previous definitions.}, we type:
\bv
(libload "nat.scm")
\end{verbatim}

We set the goal by letting:
\bv
(set-goal (pf "all n,m.n + m = m + n"))
\end{verbatim}

We now instantiate the first quantifier with \texttt{n}:
\bv
(assume "n")

; ok, we now have the new goal 
; ?_2: all m n+m=m+n from
;   n
> 
\end{verbatim}

We apply induction by simply typing:

\bv
(ind)
\end{verbatim}

The command \texttt{ind} requires a universally quantified goal 
and applies induction to it in accord to the definition of the 
specific algebra type (in this case $nat$).

\mi's reply will be something like this:

\bv 
; ok, ?_2 can be obtained from
; ?_4: all n15.n+n15=n15+n -> n+Succ n15=Succ n15+n from
;   n

; ?_3: n+0=0+n from
;   n
> 
\end{verbatim}

We then replace the goal with its normal form by letting:
\bv
(normalize-goal) 

; ok, the normalized goal is
; ?_5: T from
;   n
>      
\end{verbatim}

The latter command can be abbreviated with \texttt{ng} and it 
will normalize the goal by using the computation rules 
for \texttt{+} introduced in the file \texttt{nat.scm}.

The goal is now proved by simply appealing to the axiom 
\texttt{Truth-Axiom} (which can be used as an argument to 
the \texttt{use} command).

\bv
(use "Truth-Axiom")

; ok, ?_5 is proved.  The active goal now is
; ?_4: all n15.n+n15=n15+n -> n+Succ n15=Succ n15+n from
;   n
> 
\end{verbatim}

We can now instantiate the quantified variable \texttt{n15} 
by \texttt{m}:
\bv
(assume "m" 1)

; ok, we now have the new goal 
; ?_6: n+Succ m=Succ m+n from
;   n  m  1:n+m=m+n
> 
\end{verbatim}

Finally we normalize the goal and use the assumption: 
\bv
(ng) 

; ok, the normalized goal is
; ?_7: n+m=m+n from
;   n  m  1:n+m=m+n
> 
\end{verbatim}

\bv
(use 1)
; ok, ?_7 is proved.  Proof finished.
>
\end{verbatim}

To see the proof:
\bv
(display-proof)

\end{verbatim}


{\bf Another example.} 
We now present another example of induction on the natural numbers, 
which introduces some additional features of \mi.

Suppose we want to prove that for all natural numbers $n$, 
$2 \cdot n$ is even.
We define two new {\em program constants} (see \cite{minlogman}) 
\texttt{Odd} and \texttt{Even} which take a natural number 
as argument and give a boolean (true or false) as output. 
The behaviour of these program constants 
can be specified by means of {\em computation rules}. In this case the 
computation rules will simultaneously characterize \texttt{Odd} 
and \texttt{Even}.
The command used to introduce a new program constant is 
\texttt{add-program-constant}. It will require the name of the 
constant and its type; further arguments may be the degree of totality,
the token type (e.g.\ \texttt{const}) and the arity (see \cite{minlogman}).
In the following, the type of the new constants \texttt{Odd} and 
\texttt{Even} will be introduced by means of the command 
\texttt{mk-arrow}, which produces an arrow type.

The behaviour of a new program constant can be specified by 
introducing one or more computation rules for it. This is accomplished 
by use of the command \texttt{add-computation-rule}, having 
two arguments: a left hand side and a right hand side.
The right hand side specifies the result of the 
computation rule for the argument indicated in the left hand side.

The following implementation of the example should clarify how to 
use these commands.

\bv
(libload "nat.scm")

(add-program-constant  "Odd" (mk-arrow (py "nat") (py "boole")) 1)
(add-program-constant  "Even" (mk-arrow (py "nat") (py "boole")) 1)
(add-computation-rule (pt "Odd 0") (pt "F")) 
(add-computation-rule (pt "Even 0") (pt "T")) 
(add-computation-rule (pt "Odd (Succ n)") (pt "Even n"))
(add-computation-rule (pt "Even (Succ n)") (pt "Odd n"))

(set-goal (pf "all n.Even (2*n)"))
(ind)
(ng)
(use "Truth-Axiom")
(ng)
(assume "n" 1)
(use 1)
\end{verbatim}




%%%%%%%%%%%%%%%%%%%%%%%%

{\bf Induction on Lists.} The following example is an exercise 
on lists over an arbitrary type $\alpha$. 
Also this example illustrates the use of induction,
but since we now deal with {\em infinitary algebras} 
(see \cite{minlogman}) the task will result a bit harder 
than when working with the natural numbers.

Together with the file \texttt{nat.scm}, we now need to load 
also the file \texttt{list.scm}, which contains basic 
definitions and operations on lists over an arbitrary type $\alpha$. 
We recommend to go through the file before starting to work 
at this example.

We shall introduce a function, $\listrev$, on lists which has the effect of 
reverting a list, and then prove the following:
$$
        \forall y,z. Equal (\listrev\, (y \listappend z)) 
        ((\listrev\, z) \listappend (\listrev\, y))),
$$
where $y$ and $z$ are lists over an arbitrary type $\alpha$ and 
$\listappend$ denotes the append function on lists as defined in  
\texttt{list.scm}.
Note that we here need to use the predicate $Equal$ instead of 
$=$ because the algebra of lists over $\alpha$ is an infinitary 
algebra and hence equality for it has to be treated as
a predicate constant with appropriate axioms (see \cite{minlogman}).

Before stating the goal we need to define $\listrev$. This has to be 
defined by induction, by first giving its value for the empty 
list and then saying how it applies to a non-empty list.
The two defining conditions for $\listrev$ will be the following:
\begin{align*}
%
\listrev\,(\nil\, \alpha) &= (\nil\, \alpha),
\\
\listrev\,(a::y) &= (\listrev\, y) \listappend (a{:})
%
\end{align*}
where, according to the notation in \texttt{list.scm}, 
$\nil\, \alpha$ denotes the empty list over the type $\alpha$, 
$a::y$ denotes the list obtained by adding the object $a$ 
of type $\alpha$ to the list $y$ (over $\alpha$), 
while $a{:}$ is the one element list obtained from $a$.

First of all we load the files \texttt{nat.scm} and 
\texttt{list.scm}.

\bv
(libload "nat.scm")
(libload "list.scm")
\end{verbatim}

To simplify our work, we declare some variables of 
the appropriate types: 
\bv
(add-var-name "a" "b" (py "alpha"))
(add-var-name "u" "v" "w" "s" (py "list alpha"))
\end{verbatim}

We then declare a new program constant, 
\texttt{Rev}, which takes a list over \texttt{alpha} 
as argument and gives another list over \texttt{alpha} 
as output.

\bv
(add-program-constant "Rev"
                      (py "list alpha => list alpha") 1 'const 1)
\end{verbatim}

We can now introduce two computation rules which correspond 
to the two conditions for $\listrev$ presented above.

\bv
(add-computation-rule (pt "(Rev alpha) (Nil alpha)") 
                      (pt "(Nil alpha)"))
(add-computation-rule (pt "(Rev alpha) (a::w)") 
		      (pt "((Rev alpha) w) :+: (a:)"))
\end{verbatim}

Now we could start proving the goal:
 
\bv
all w,s. Equal ((Rev alpha)(w :+: s)) 
               (((Rev alpha) s) :+: ((Rev alpha) w)))
\end{verbatim}

With the purpose of simplifying our proof,  
we now deliberately introduce three ``ad hoc'' 
global assumptions which will be used 
as lemmata in the proof of the main goal.
We prove one of these global assumptions  
at the end of the main proof, and leave 
the others as an exercise for the reader. 

We can use \texttt{aga} as an abbreviation for 
\texttt{add-global-assumption}

\bv
(aga "Reff" (pf "all a,w,s. (Equal w s) 
                            -> Equal (a::w) (a::s)"))

(aga "Eqrev" (pf "all w,s,u. Equal w s 
                             -> Equal (w :+: u) (s :+: u)"))

(aga "Asrev" (pf "all v,s,w,u. Equal v ((s :+: w) :+: u) 
                               -> Equal v  (s :+: (w :+: u))"))
\end{verbatim}

We now prove a short lemma which says that any list, $z$, is equal to 
the list obtained by appending the empty list to $z$.

\bv
; Lemma
(set-goal (pf "all s. Equal s (s :+:(Nil alpha))"))
(ind)
(ng)
(use-with "Eq-Refl" (py "list alpha") (pt "(Nil alpha)"))
(assume "a" "w" 1)
(use "Reff")
(use 1)
(save "AppendEmpty")
\end{verbatim}

We note that by writing 
\texttt{(use-with "Eq-Refl" (py "list alpha") (pt "(Nil alpha)"))}, 
we make use of the axiom of reflexivity for \texttt{Equal}, which 
is called \texttt{Eq-Refl}, and apply it to the term 
\texttt{Nil alpha} of type \texttt{list alpha}.

The lemma and the global assumptions stated above can now 
be used to prove the goal.
\bv
(set-goal (pf "all w,s. (Equal ((Rev alpha)(w :+: s))
                        (((Rev alpha) s) :+: ((Rev alpha) w)))"))
(ind)
(ng)
(assume "s")
(use "AppendEmpty")
(assume "a" "w")
(ng)
(assume 1 "s")
(use-with "Asrev" (pt "((Rev alpha)(w :+: s) :+: a:)") 
          (pt "((Rev alpha) s)") 
          (pt "((Rev alpha) w)") (pt "a:") "?")
(use-with "Eqrev" (pt "((Rev alpha)(w :+: s))") 
          (pt "((Rev alpha) s :+: (Rev alpha) w)") (pt "a:") "?")
(use 1)
\end{verbatim}

Finally, we show how to prove the global assumption \texttt{Eqrev},
as it is a typical application of equality reasoning.

\bv 
(set-goal (pf "all w,s,u. Equal w s 
                          -> Equal (w :+: u) (s :+: u)"))
(strip)
(simp 1)
(use-with "Eq-Refl" (py "list alpha") (pt "s:+:u"))
\end{verbatim}

Note the command \texttt{strip} which moves at one time 
all universally quantified variables 
and hypotheses of the current goal into the context.

\texttt{simp} simplifies a proof which involves the predicate 
\texttt{Equal}, by substituting 'Equal' terms in the 
goal.


%%%%%%%%%%
\section{search}

\mi\ allows for automatic proof search. 
There are two distinct facilities for performing an automatic 
search in \mi. 
The first is given by the command \texttt{(prop)} and 
exemplifies Hudelmaier-Dyckhoff's search for the case of 
minimal propositional logic (see e.g.\ \cite{Hudelmaier89},  \cite{Dyckhoff92}). 
The second is given by the command \texttt{(search)} and  
embodies a search algorithm based on Miller's \cite{Miller91b} 
and on ideas of Berger (see \cite{minlogman} for details on the 
algorithm and for some differences with Miller's algorithm).
The command \texttt{search} enables us to automatically find a proof for a 
wider class of formulas compared with \texttt{prop}, 
since it also works for formulae with quantifiers 
(see the reference manual for a detailed description 
of the class of formulae dealt with by \texttt{search}).

{\bf Prop.} One is advised to use \texttt{prop} for propositional (minimal)
logic. \texttt{prop} will first look for a proof 
in propositional minimal logic. If it fails to find a proof for the 
given proposition, 
it will try with intuitionistic logic, by adding appropriate 
instances of ``Ex falsum quodlibet''. If this search also gives
no positive answer, it will try to find a proof in 
classical logic, by adding appropriate instances of 
Stability. 

To apply this search algorithm, one simply needs 
to type \texttt{(prop)} after stating the goal or 
at any point of a proof from which one guesses that 
(minimal) propositional logic would suffice. If \mi\ 
finds a proof, one can then display it by means of any of the 
display commands available for proofs; for example by writing  
\texttt{dnp} (which is a shortcut for  
\texttt{display-normalized-proof}).

The reader is encouraged to apply the command to the first 
examples of propositional logic of this tutorial, 
including ``Peirce's law''.

{\bf Search.} The \texttt{search} command is more powerful then 
\texttt{prop} since it allows us to automatically find proofs also for  
some quantified formulas, but it only operates a search in minimal 
logic. If one wants to apply this command to a classical formula 
like ``Peirce's law'', one could for example add the appropriate 
instance of ``Ex falsum quodlibet'' and of Stability as antecedents of the 
goal. In case of more complex proofs, in which one can not 
easily modify the actual goal, an alternative would be to avail oneself 
of a more complete use of the \texttt{search} command 
which allows us to specify some global assumptions or theorems or 
even hypothesis from the given context which one would like 
to be used in the resulting proof.\footnote{It is important to 
notice that in \mi\ we do not quantify over propositions, 
hence one needs to exercise some care in choosing the global 
assumptions to be used in \texttt{search}. In the case of 
``Peirce's law'', one would need to pass e.g.\ from the global 
assumption \texttt{Efq-Log} to a theorem which is 
a specific instance of it, and make use of the latter 
in \texttt{search}.}
Since the search space in the case of quantified formulas 
can become really vast, this possibility of declaring specific
assumptions to be used in the proof can be very useful, 
especially if we also state 
the maximum number of multiplicities we allow for each 
assumption (i.e. the maximum number of times each
assumption can be used in the proof). One can also use 
this same device to exclude the use of a specific assumption in 
the proof, simply by letting its multiplicity to be 0.

To use the plain version of \texttt{search}, one simply 
writes \texttt{(search)}.  
See the reference manual for the precise syntax of the command 
\texttt{search} when other assumptions are invoked with the 
respective multiplicities.

{\bf An example with \texttt{search}.} As an example for the use of 
\texttt{search}, we apply the algorithm to the following problem:
if $f$ is a continuous function then $f$ composed with itself 
is also a continuous function.
We suggest to solve the problem as follows.

\bv
(add-var-name "x" "y" (py "alpha"))
(add-tvar-name "beta")
(add-var-name "U" "V" "W" (py "beta"))
(add-predconst-name "in" (make-arity (py "alpha") (py "beta")))
(add-var-name "f" (py "alpha=>alpha"))

(set-goal
 (pf
  "all f.(all x,V. in (f x) V -> excl U. in x U 
                  & all y. in y U -> in (f y) V) -> 
          all x,W. in (f(f x)) W -> excl U. in x U 
                  & all y.in y U -> in (f(f y)) W"))
(search)
(dnp)
\end{verbatim}

Note that one can switch on a verbose search by letting: 
\texttt{(set! VERBOSE-SEARCH \#t)} before calling   
\texttt{search}. In this way one can see the single steps 
performed by the search algorithm and detect possible 
difficulties in finding a proof.


%%%%%%%%%%

\section{Conclusion} 
We finally note that one of the main 
motivations for developing \mi\ and one of its most 
important features is program extraction, 
that is, the possibility of using \mi\ to extract 
functional programs from proof terms.
However, the treatment of program extraction would require 
a consistent extension of this tutorial and it is hence omitted 
for the time being. The reader willing to know more about this topic 
is encouraged to consult the reference manual and the relevant papers 
listed on the \mi\ web page.

To conclude, we recall that all the examples of this tutorial can be 
found in the file \texttt{tutorial.scm} located in the examples 
directory of the \mi\ distribution.

\newpage
\section{Useful Commands for \textsc{Emacs} and Petite \textsc{Scheme}}

\begin{center}
\begin{large}
\textsc{Emacs}\\
\end{large}
\end{center}
\vspace{3 mm}

\begin{itemize}
\item Start \textsc{Emacs}: \texttt{Emacs \&}\\
\item Leave \textsc{Emacs}: C-x C-c\\     
\item Split a window in two: \texttt{C-x 2}\\
\item Move to another Buffer: \texttt{C-x b} 
(then specify the Buffer's name)\\
\item Move to another window: \texttt{C-x o}\\
\item Load a file: \texttt{C-x C-f} 
(then give a name of a file with extension \texttt{.scm})\\
\item Save a file: \texttt{C-x C-s}\\
\item Exit from the Minibuffer: \texttt{C-g}\\
\end{itemize}

\begin{center}
\begin{large}
\textsc{Scheme}\\
\end{large}
\end{center}
\vspace{3 mm}

\begin{itemize}
\item Load  \textsc{(Petite) Scheme}:  \texttt{M-x run-petite}\\
\item Evaluate a \textsc{Scheme} expression: \texttt{C-x C-e}\\
\item Evaluate a region: mark the region and then \texttt{C-c C-r}\\
\item Kill a process: \texttt{C-c C-c} \\
\item Leave the Debug: \texttt{r}\\
\item End a \textsc{Scheme} session: \texttt{(exit)}\\
\item Comment: \texttt{;}\\
\end{itemize}

\begin{enumerate}[]
\item \texttt{C = Control} or \texttt{Strg}
\item \texttt{M = Meta} or \texttt{Esc} or \texttt{Alt}.  
\end{enumerate}


\newpage

\section{Useful Commands: \mi}


The following is a list of commands which could be used 
in a `standard' interactive proof with \mi. Rather than explaining 
the commands in detail, we shall write them down, often 
with a short description of their use gathered from 
the reference manual. 
The reader is anyhow advised to check the full details 
in the reference manual. 


\section{Some declarations needed to start a proof}

\begin{enumerate}[]

\item \texttt{(add-tvar-name \textsl{name1} \dots)} 
  \index{add-tvar-name@\texttt{add-tvar-name}}\\

\item \texttt{(add-alg \dots)}, and also \\ 
\texttt{(add-algs \dots)}
\texttt{(add-param-alg \dots)} 
\texttt{(add-param-algs \dots)}
\index{add-param-algs@\texttt{add-param-algs}}\\

\item \texttt{(add-var-name \textsl{name1} \dots\ \textsl{type})} 
  \index{add-var-name@\texttt{add-var-name}}\\

\item \texttt{(add-predconst-name \textsl{name1} \dots\ \textsl{arity})}
  \index{add-predconst-name@\texttt{add-predconst-name}}\\

\item \texttt{(add-pvar-name \textsl{name1} \dots\ \textsl{type})} 
  \index{add-var-name@\texttt{add-pvar-name}}\\

\item \texttt{(add-program-constant \textsl{name} \textsl{type} 
    <\textsl{rest}>)}
  \index{add-program-constant@\texttt{add-program-constant}}\\

\item \texttt{(add-computation-rule \textsl{lhs} \textsl{rhs})} 
  \index{add-computation-rule@\texttt{add-computation-rule}}\\

\item \texttt{(add-rewrite-rule \textsl{lhs} \textsl{rhs})}
  \index{add-rewrite-rule@\texttt{add-rewrite-rule}}\\

\item \texttt{(add-global-assumption \textsl{name} \textsl{formula})}    
  \index{add-global-assumption@\texttt{add-global-assumption}}
  \quad \hbox{(abbr. \texttt{aga}\index{aga@\texttt{aga}})}\\

\end{enumerate}

To each command above there corresponds one to remove 
constants, variables etc already introduced. For example:\\

\texttt{(remove-predconst-name \textsl{name1} \dots)}
\index{remove-predconst-name@\texttt{remove-predconst-name}}\\


There are also numerous display commands, in particular the following:\\

\texttt{(display-program-constants \textsl{name1} \dots)}
\index{display-program-constants@\texttt{display-program-constants}}.\\

\texttt{(display-global-assumptions \textsl{string1} \dots)}    
\index{display-global-assumptions@\texttt{display-global-assumptions}}\\

\texttt{(display-constructors \textsl{alg-name1} \dots)}%
\index{display-constructors@\texttt{display-constructors}}\\

\texttt{(display-theorems \textsl{string1} \dots)}    
\index{display-theorems@\texttt{display-theorems}}\\

\section{Goals}

\texttt{(set-goal \textsl{formula})}\index{set-goal@\texttt{set-goal}}

where \textsl{formula} needs to be closed (if not 
universal quantifiers will be inserted automatically).\\

\texttt{(normalize-goal \textsl{goal})}  (abbr. \texttt{ng})
\index{normalize-goal@\texttt{normalize-goal}}

replaces the goal by its normal form.\\

\texttt{(display-current-goal)}%
\index{display-current-goal@\texttt{display-current-goal}} (abbr. \texttt{dcg})


\section{Generating interactive Proofs}

%{\bf Backward Reasoning}\\

%{\bf Implication}\\
\underline{Implication}\\

\texttt{(assume \textsl{x1}\dots)}\index{assume@\texttt{assume}}

moves the antecedent of a goal in implication form to 
the hypotheses. The hypotheses,  $\textsl{x1}\dots$,  
should be identified by numbers
or strings.\\

\texttt{(use \textsl{x})\index{use@\texttt{use}}}

where \textsl{x} is
\begin{itemize}
\item a number or string identifying a hypothesis from the context,
\item the string \inquotes{Truth},
\item the name of a theorem or global assumption.  
\item a closed proof,
\item a formula with free variables from the context, generating a new
goal.\\
\end{itemize}

%{\bf Conjunction}\\
\underline{Conjunction}\\

\texttt{(split)}\index{split@\texttt{split}} 

expects a conjunction $A \land B$ as goal and splits it into 
two new goals, $A$ and $B$.\\

\texttt{(use \textsl{x} . \textsl{elab-path})}\index{use@\texttt{use}}

where \textsl{x} is as in the description of the \texttt{use} 
command for implication and \textsl{elab-path} consists of \texttt{'left} 
or \texttt{'right}.\\

%{\bf Universal Quantifier}\\
\underline{Universal Quantifier}\\

\texttt{(assume \textsl{x1}\dots)}\index{assume@\texttt{assume}} 

moves universally quantified variables into the context.  The variables
need to be named (by using previously declared names of 
the appropriate types).\\

\texttt{(use \textsl{x} . \textsl{terms})}
\index{use@\texttt{use}} 

where \textsl{x} is as in the 
case of implication and the optional \textsl{terms} 
is here a list of terms.   
One needs to explicitly provide terms for those variables 
that cannot be automatically instantiated by pattern 
unification. On the contrary, when pattern unification succeeds 
in finding appropriate instances for the quantifiers in the goal,
then these instances will be automatically inserted.\\

%{\bf Existential Quantifier}\\
\underline{Existential Quantifier}\\

\texttt{(ex-intro \textsl{term})}\index{ex-intro@\texttt{ex-intro}}

by this command the user provides a term to be used for 
the present (existential) goal.\\

\texttt{(ex-elim \textsl{x})}\index{ex-elim@\texttt{ex-elim}}, 

where \textsl{x} is
\begin{itemize}
%
\item a number or string identifying an existential hypothesis from 
the context,
%
\item the name of an existential global assumption or theorem,
%
\item a closed proof on an existential formula,
%
\item an existential formula with free variables from the context, 
genera\-ting a new goal.\\
%
\end{itemize}
%Let $\ex y A$ be the existential formula identified by \textsl{x}.
%The user is then asked to provide a proof for the present goal,
%assuming that a $y$ satisfying $A$ is available.\\


%{\bf Classical Existential Quantifier}\\
\underline{Classical Existential Quantifier}\\

\texttt{(exc-intro \textsl{terms})}\index{exc-intro@\texttt{exc-intro}}

this command is analogous to \texttt{(ex-intro)}, but 
it is used in the case of a classical existential goal.\\

\texttt{(exc-elim \textsl{x})}\index{exc-elim@\texttt{exc-elim}}

this corresponds to \texttt{(ex-elim)} and applies to a classical 
existential quantifier.\\



\section{Other general commands}

\texttt{(use-with \textsl{x} . \textsl{x-list})}
\index{use-with@\texttt{use-with}} 

is a more verbose form of \texttt{use}, where
the terms are not inferred via unification, but have to be given
explicitly. Here \textsl{x} is
as in \texttt{use}, and \textsl{x-list} is a list consisting of
\begin{itemize}
%
\item a number or string identifying a hypothesis form the context,
%
\item the name of a theorem or global assumption,
%
\item a closed proof,
%
\item the string \inquotes{?} 
%(value of \texttt{DEFAULT-GOAL-NAME}),
generating a new goal,
%
\item \texttt{'left} or \texttt{'right},
%
\item a term, whose free variables are added to the context.\\
%
\end{itemize}
%Notice that \texttt{use-with} allows us to introduce 
%new free variables in the context.  
%This is to allow for proofs with free variables.\\



\texttt{(inst-with \textsl{x} . \textsl{x-list})}\index{inst-with@\texttt{inst-with}}

does for forward chaining the same as \texttt{use-with} for backward 
chaining.   
It adds a new hypothesis which is an instance of a selected  
hypothesis or of a theorem.  
%Notice that this effect could also be obtained by cut.  
Here \textsl{x} and \textsl{x-list} are as in \texttt{use-with}. 

%\begin{itemize}
%%
%\item a number or string identifying a hypothesis form the context,
%%
%\item the name of a theorem or global assumption,
%% 
%\item a closed proof,
%%
%\item a formula with free variables from the context, generating a new
%goal.
%%
%\end{itemize}
% is a list consisting of
%\begin{itemize}
%%
%\item a number or string identifying a hypothesis form the context,
%%
%\item the name of a theorem or global assumption,
%%
%\item a closed proof,
%%
%\item the string \inquotes{?} 
%%(value of \texttt{DEFAULT-GOAL-NAME}),
%generating a new goal,
%%
%\item \texttt{'left} or \texttt{'right},
%%
%\item a type,
%%
%\item a term, whose free variables are added to the context.\\
%%
%\end{itemize}

\newpage
\texttt{(inst-with-to \textsl{x} . \textsl{x-list} \texttt{name-hyp})}
\index{inst-with-to@\texttt{inst-with-to}}

expects a string as its last argument, to name 
the newly introduced instantiated hypothesis.\\



\texttt{(cut \textsl{A})}\index{cut@\texttt{cut}} 

replaces the goal $B$ by the two
new goals $A$ and $A \to B$. 
Note that the same effect can also be produced by means of 
the \texttt{use} command.\\


\texttt{(ind)}\index{ind@\texttt{ind}}

expects a goal $\forall x^\rho A$ with $\rho$ an algebra. 
If $c_1, \dots, c_n$ are the constructors of the algebra 
$\rho$, then \texttt{(ind)} will generate $n$ new goals: 
\sloppy $\forall \vec{x}_i.  \subst{A}{x}{x_{1i}} \to \dots \to
\subst{A}{x}{x_{ki}} \to \subst{A}{x}{c_i \vec{x}_i}$.\\

%\texttt{(ind \textsl{t})} 

%expects a goal $\subst{A}{x}{t}$.  It
%computes the algebra $\rho$ as type of the term $t$.  Then again 
%it produces $n$ new goals:
%$\forall \vec{x}_i.  \subst{A}{x}{x_{1i}} \to \dots \to
%\subst{A}{x}{x_{ki}} \to \subst{A}{x}{c_i \vec{x}_i}$.\\

\texttt{(simind \textsl{all-formula1}
\dots)}\index{simind@\texttt{simind}} 

expects a goal $\forall
x^\rho A$ with $\rho$ an algebra.  The user provides other
 formulas to be proved simultaneously with the given one.\\

\texttt{(cases)}\index{cases@\texttt{cases}} 

expects a goal $\forall x^\rho A$ with $\rho$ an algebra.  
Assume that $c_1,\dots, c_n$ are the constructors of the 
algebra $\rho$.  Then $n$ new (simplified) goals 
$\forall \vec{x}_i \subst{A}{x}{c_i \vec{x}_i}$ are
generated.\\

%\texttt{(cases \textsl{t})} 

%expects a goal $\subst{A}{x}{t}$.  It
%computes the algebra $\rho$ as type of the term $t$.  Then again $n$
%new goals $\forall \vec{x}_i \subst{A}{x}{c_i \vec{x}_i}$ are
%generated.\\

%\texttt{(cases \textsl{'auto})} (or
%\texttt{(casedist)}\index{casedist@\texttt{casedist}}) 

%expects an
%atomic goal and checks whe\-ther its boolean kernel contains an if-term
%whose test is neither an if-term nor contains bound variables.  With
%the first such test \texttt{(cases \textsl{test})} is called.\\

%{\bf General commands}\\

\texttt{(simp x)}\index{simp@\texttt{simp}} 

expects a known fact of the form $r^{\boole}$, $\lnot r^{\boole}$,
$t=s$ or $t \approx s$.  In case $r^{\boole}$, the boolean term $r$ in the goal
is replaced by $T$, and in case $\lnot r^{\boole}$ it is replaced by 
$F$.  
If $t=s$ (resp. $t \approx s$), the goal is written in the form $\subst{A}{x}{t}$.  Using
Compat-Rev (i.e. $\forall x,y.x = y \to P y \to P x$) (resp. Eq-Compat-Rev
(i.e. $\forall x,y.x \approx y \to P y \to P x$))
the goal $\subst{A}{x}{t}$ is replaced by $\subst{A}{x}{s}$, where
$P$ is $\set{x}{A}$, $x$ is $t$ and $y$ is $s$.
Here \textsl{x} is
\begin{itemize}
%
\item a number or string identifying a hypothesis form the context,
%
\item the name of a theorem or global assumption, or
% 
\item a closed proof.\\
%
\item a formula with free variables from the context, generating a new
goal.
\end{itemize}



% \texttt{(simpeq x)}\index{simpeq@\texttt{simpeq}} 

% needs to know $t \approx s$.  The goal is written in the form
% $\subst{A}{x}{t}$.  Using Compat-Rev 
% (i.e. $\forall x,y. x \approx y \to P y \to P x$), the goal 
% $\subst{A}{x}{t}$ is replaced by $\subst{A}{x}{s}$, 
% with $\set{x}{A}$ for $P$, $t$ for $x$ and $s$ for $y$.\\


%\newpage
\texttt{(name-hyp \textsl{i x1}})\index{name-hyp@\texttt{name-hyp}} 

expects an index $i$ and a string.  Then a new goal is created, 
which differs from the previous one only in display aspects: 
the string names the $i$th hypothesis.\\

\texttt{(drop . x-list)}\index{drop@\texttt{drop}}, 

hides (but does not erase) the hypothesis listed in \texttt{x-list}. 
If \texttt{x-list} is empty, all hypotheses are hidden.\\

\newpage
\texttt{(by-assume-with \textsl{x} \textsl{y}
\textsl{u})}\index{by-assume-with@\texttt{by-assume-with}}

is used when proving a goal $G$
from an existential hypothesis $ExHyp \colon \ex y A$. 
It corresponds to saying \inquotes{by $ExHyp$
assume we have a $y$ satisfying $A$}.  Here
\textsl{x} identifies an existential
hypothesis, and we assume the variable $y$
and the kernel $A$ (with label $u$). This command 
corresponds to the sequence
\texttt{(ex-elim \textsl{x})}, \texttt{(assume \textsl{y}
\textsl{u})}, \texttt{(drop \textsl{x})}.\\

%\texttt{(min-pr \textsl{x} \textsl{measure})}
%\index{min-pr@\texttt{min-pr}} 

%where \textsl{x} is
%\begin{itemize}
%%
%\item a number or string identifying a classical existential hypothesis 
%from the context,
%%
%\item the name of a classical existential global assumption or theorem,
%%
%\item a closed proof on a classical existential formula,
%%
%\item a classical existential formula with free variables from the context, 
%generating a new goal.
%%
%\end{itemize}
%The result is a new implicational goal, whose premise provides the
%(classical) existence of instances with least measure.

%{\bf Forward Reasoning}\\

%{\bf Implication, Conjunction, Universal Quantifier}
%\underline{Implication, Conjunction, Universal Quantifier}\\
 

\texttt{(undo)}\index{undo@\texttt{undo}}
or \texttt{(undo \textsl{n})}\index{undon@\texttt{undon}}

has the effect of cancelling the last step in a proof, or the 
last  \textsl{n} steps, respectively.\\


\section{Automation and Search}

\texttt{(strip)}\index{strip@\texttt{strip}} 

moves all universally quantified variables 
and hypotheses of the current goal into the context.\\

\texttt{(strip n)} 

does the same as \texttt{(strip)}
but only for $n$ variables or hypotheses.\\

\texttt{(proceed)}\index{proceed@\texttt{proceed}} 

automatically refines the goal as far as possible 
as long as there is a unique proof.
When the proof is not unique, it prompts with the 
new refined goal, and allows to proceed in an 
interactive way.\\ 

\texttt{(prop)}\index{prop@\texttt{prop}} 

searches for a proof of the stated goal.
It is devised for propositional logic only.\\

\texttt{(search \textsl{m} \textsl{(name1 m1)}
\dots)}\index{search@\texttt{search}}

expects for \textsl{m} a default value of multiplicity 
(i.e. a positive integer stating how often the assumptions 
are to be used).
Here \textsl{name1} $\dots$ are 
\begin{itemize}
%
\item numbers or names of hypotheses from the present context or 
%
\item names of theorems or global assumptions, 
%
\end{itemize}
and \textsl{m1} $\dots$ indicate the multiplicities of the specific 
\textsl{name1} $\dots$.    
To exclude a hypothesis one can list it with multiplicity $0$.\\

%\texttt{(searchex)}\index{searchex@\texttt{searchex}}\\



\section{Displaying proofs objects}

\texttt{(display-proof\ . \textsl{opt-proof})}
\index{display-proof@\texttt{display-proof}}
(abbr. \texttt{dp})\\

\texttt{(display-proof-expr\ . \textsl{opt-proof})}
\index{display-proof-expr@\texttt{display-proof-expr}}
(abbr. \texttt{dpe})\\

\texttt{(display-eterm . \textsl{opt-proof})} (abbr. \texttt{det})\\

\texttt{(check-and-display-proof)}  (abbr. \texttt{cdp})\\

\texttt{(display-normalized-proof\ . \textsl{opt-proof})}
\index{display-normalized-proof@\texttt{display-normalized-proof}}
(abbr. \texttt{dnp}) \\

\texttt{(display-normalized-proof-expr\ . \textsl{opt-proof})}
\index{display-normalized-proof-expr@\texttt{display-normalized-proof-expr}}
(abbr. \texttt{dnpe})\\

\texttt{(display-normalized-eterm . \textsl{opt-proof})}
(abbr. \texttt{dnet}) 



\bibliography{minlog}
\bibliographystyle{amsplain}


\end{document}

%%% Local Variables: 
%%% mode: latex-math
%%% TeX-master: t
%%% End: 
