\chapter{Interactive Proof Assistants}
%HEVEA\cutname{itp.html}

% ... We then provide specific information about some ITPs.

\section{Using an Interactive Proof Assistant to Discharge Goals}

Instead of calling an automated theorem prover to discharge a goal,
\why offers the possibility to call an interactive theorem prover
instead. In that case, the interaction is decomposed into two distinct
phases:
\begin{itemize}
\item Edition of a proof script for the goal, typically inside a proof editor
  provided by the external interactive theorem prover;
\item Replay of an existing proof script.
\end{itemize}
An example of such an interaction is given in the tutorial
section~\ref{sec:gui}.

Some proof assistants offer more than one possible editor, \eg a
choice between the use of a dedicated editor and the use of the Emacs
editor and the ProofGeneral mode. Selection of the preferred mode can
be made in \texttt{why3ide} preferences, under the ``Editors'' tab.

\section{Theory Realizations}
\label{sec:realizations}

Given a \why theory, one can use a proof assistant to make a
\emph{realization} of this theory, that is to provide definitions for
some of its uninterpreted symbols and proofs for some of its
axioms. This way, one can show the consistency of an axiomatized
theory and/or make a connection to an existing library (of the proof
assistant) to ease some proofs.
%Currently, realizations are supported for the proof assistants Coq and PVS.

\subsection{Generating a realization}

Generating the skeleton for a theory is done by passing to the
\texttt{realize} command a driver suitable for realizations, the names of
the theories to realize, and a target directory.
\index{realize@\texttt{realize}}

\begin{verbatim}
why3 realize -D path/to/drivers/prover-realize.drv
             -T env_path.theory_name -o path/to/target/dir/
\end{verbatim}
\index{driver@\verb+--driver+}
\index{theory@\verb+--theory+}

The theory is looked into the files from the environment, \eg the standard
library. If the theory is stored in a different location, option \texttt{-L}
should be used.

The name of the generated file is inferred from the theory name. If the
target directory already contains a file with the same name, \why
extracts all the parts that it assumes to be user-edited and merges them in
the generated file.

Note that \why does not track dependencies between realizations and
theories, so a realization will become outdated if the corresponding
theory is modified.
It is up to the user to handle such dependencies, for instance using a
\texttt{Makefile}.

\subsection{Using realizations inside proofs}

If a theory has been realized, the \why printer for the corresponding prover
will no longer output declarations for that theory but instead simply put
a directive to load the realization. In order to tell the printer
that a given theory is realized, one has to add a meta declaration in the
corresponding theory section of the driver.
\index{driver file}

\begin{verbatim}
theory env_path.theory_name
  meta "realized_theory" "env_path.theory_name", "optional_naming"
end
\end{verbatim}

The first parameter is the theory name for \why. The second
parameter, if not empty, provides a name to be used inside generated
scripts to point to the realization, in case the default name is not
suitable for the interactive prover.
\index{realized_theory@\verb+realized_theory+}

\subsection{Shipping libraries of realizations}

While modifying an existing driver file might be sufficient for local
use, it does not scale well when the realizations are to be shipped to
other users. Instead, one should create two additional files: a
configuration file that indicates how to modify paths, provers, and
editors, and a driver file that contains only the needed
\verb+meta "realized_theory"+ declarations. The configuration file should be as
follows.
\index{configuration file}

\begin{verbatim}
[main]
loadpath="path/to/theories"

[prover_modifiers]
name="Coq"
option="-R path/to/vo/files Logical_directory"
driver="path/to/file/with/meta.drv"

[editor_modifiers coqide]
option="-R path/to/vo/files Logical_directory"

[editor_modifiers proofgeneral-coq]
option="--eval \"(setq coq-load-path (cons '(\\\"path/to/vo/files\\\" \
  \\\"Logical_directory\\\") coq-load-path))\""
\end{verbatim}

This configuration file can be passed to \why thanks to the
\verb+--extra-config+ option.
\index{extra-config@\verb+--extra-config+}
\index{prover_modifiers@\verb+prover_modifiers+}
\index{editor_modifiers@\verb+editor_modifiers+}
\index{option@\verb+option+}
\index{driver@\verb+driver+}


\input{./coq.tex}

\input{./coq_tactic.tex}

\input{./isabelle.tex}

\input{./pvs.tex}


%%% Local Variables:
%%% mode: latex
%%% TeX-PDF-mode: t
%%% TeX-master: "manual"
%%% End:
