1 Interactive Proof Assistants
2 ============================
4 Using an Interactive Proof Assistant to Discharge Goals
5 -------------------------------------------------------
7 Instead of calling an automated theorem prover to discharge a goal, Why3
8 offers the possibility to call an interactive theorem prover instead. In
9 that case, the interaction is decomposed into two distinct phases:
11 - Edition of a proof script for the goal, typically inside a proof
12 editor provided by the external interactive theorem prover;
14 - Replay of an existing proof script.
16 An example of such an interaction is given in the :ref:`tutorial section <sec.gui>`.
18 Some proof assistants offer more than one possible editor, e.g., a choice
19 between the use of a dedicated editor and the use of the Emacs editor
20 and the ProofGeneral mode. Selection of the preferred mode can be made
21 in :menuselection:`File --> Preferences`, under the :guilabel:`Editors` tab.
28 Given a Why3 theory, one can use a proof assistant to make a
29 *realization* of this theory, that is to provide definitions for some of
30 its uninterpreted symbols and proofs for some of its axioms. This way,
31 one can show the consistency of an axiomatized theory and/or make a
32 connection to an existing library (of the proof assistant) to ease some
35 Generating a realization
36 ~~~~~~~~~~~~~~~~~~~~~~~~
38 Generating the skeleton for a theory is done by passing to the
39 :why3:tool:`realize` command a driver suitable for realizations, the names of the
40 theories to realize, and a target directory.
44 why3 realize -D path/to/drivers/prover-realize.drv
45 -T env_path.theory_name -o path/to/target/dir/
47 The theory is looked into the files from the environment, e.g., the standard
48 library. If the theory is stored in a different location, option :option:`why3 -L`
51 The name of the generated file is inferred from the theory name. If the
52 target directory already contains a file with the same name, Why3
53 extracts all the parts that it assumes to be user-edited and merges them
54 in the generated file.
56 Note that Why3 does not track dependencies between realizations and
57 theories, so a realization will become outdated if the corresponding
58 theory is modified. It is up to the user to handle such dependencies,
59 for instance using a :file:`Makefile`.
61 .. index:: driver file
63 Using realizations inside proofs
64 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
66 If a theory has been realized, the Why3 printer for the corresponding
67 prover will no longer output declarations for that theory but instead
68 simply put a directive to load the realization. In order to tell the
69 printer that a given theory is realized, one has to add a :why3:meta:`realized_theory` meta
70 declaration in the corresponding theory section of the driver.
74 theory env_path.theory_name
75 meta "realized_theory" "env_path.theory_name", "optional_naming"
78 The first parameter is the theory name for Why3. The second parameter,
79 if not empty, provides a name to be used inside generated scripts to
80 point to the realization, in case the default name is not suitable for
81 the interactive prover.
83 .. index:: configuration file
85 Shipping libraries of realizations
86 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
88 While modifying an existing driver file might be sufficient for local
89 use, it does not scale well when the realizations are to be shipped to
90 other users. Instead, one should create two additional files: a
91 configuration file that indicates how to modify paths, provers, and
92 editors, and a driver file that contains only the needed
93 :why3:meta:`realized_theory` meta declarations. The configuration file should
99 loadpath="path/to/theories"
103 option="-R path/to/vo/files Logical_directory"
104 driver="path/to/file/with/meta.drv"
106 [editor_modifiers coqide]
107 option="-R path/to/vo/files Logical_directory"
109 [editor_modifiers proofgeneral-coq]
110 option="--eval \"(setq coq-load-path (cons '(\\\"path/to/vo/files\\\" \
111 \\\"Logical_directory\\\") coq-load-path))\""
113 This configuration file can be passed to Why3 thanks to the
114 :option:`why3 --extra-config` option.
116 .. index:: Coq proof assistant, proof assistant; Coq
122 This section describes the content of the Coq files generated by Why3
123 for both proof obligations and theory realizations. When reading a Coq
124 script, Why3 is guided by the presence of empty lines to split the
125 script, so the user should refrain from removing empty lines around
126 generated blocks or adding empty lines inside them.
128 #. The header of the file contains all the library inclusions required
129 by the driver file. Any user-made changes to this block will be lost
130 when the file is regenerated by Why3. This part starts with
131 ``(* This file is generated by ... *)``.
133 #. Abstract logic symbols are assumed with the vernacular directive
134 ``Parameter``. Axioms are assumed with the ``Axiom`` directive. When
135 regenerating a script, Why3 assumes that all such symbols have been
136 generated by a previous run. As a consequence, the user should not
137 introduce new symbols with these two directives, as they would be
140 #. Definitions of functions and inductive types in theories are printed
141 in a block that starts with ``(* Why3 assumption *)``. This comment
142 should not be removed; otherwise Why3 will assume that the definition
143 is a user-defined block.
145 #. Proof obligations and symbols to be realized are introduced by
146 ``(* Why3 goal *)``. The user is supposed to fill the script after
147 the statement. Why3 assumes that the user-made part extends up to
148 ``Qed``, ``Admitted``, ``Save``, or ``Defined``, whichever comes
149 first. In the case of definitions, the original statement can be
150 replaced by a ``Notation`` directive, in order to ease the usage of
151 predefined symbols. Why3 also recognizes ``Variable`` and
152 ``Hypothesis`` and preserves them; they should be used in conjunction
153 with Coq’s ``Section`` mechanism to realize theories that still need
154 some abstract symbols and axioms.
156 Why3 preserves any block from the script that does not fall into one of
157 the previous categories. Such blocks can be used to import other
158 libraries than the ones from the prelude. They can also be used to state
159 and prove auxiliary lemmas. Why3 tries to preserve the position of these
160 user-defined blocks relatively to the generated ones.
162 Currently, the parser for Coq scripts is rather naive and does not know
163 much about comments. For instance, Why3 can easily be confused by some
164 terminating directive like ``Qed`` that would be present in a comment.
166 .. index:: Isabelle proof assistant, proof assistant; Isabelle
172 When using Isabelle from Why3, files generated from Why3 theories and
173 goals are stored in a dedicated XML format. Those files should not be
174 edited. Instead, the proofs must be completed in a file with the same
175 name and extension ``.thy``. This is the file that is opened when using
176 the :menuselection:`Tools --> Edit` action in the Why3 IDE.
181 You need version Isabelle2018 or Isabelle2019. Former or later versions are not
182 supported. We assume below that your version is 2019, please replace
183 2019 by 2018 otherwise.
185 Isabelle must be installed before compiling Why3. After compilation and
186 installation of Why3, you must manually add the path
190 <Why3 lib dir>/isabelle
192 into either the user file
196 .isabelle/Isabelle2019/etc/components
198 or the system-wide file
202 <Isabelle install dir>/etc/components
207 The most convenient way to call Isabelle for discharging a Why3 goal is
208 to start the Isabelle/jedit interface in server mode. In this mode, one
209 must start the server once, before launching :why3:tool:`why3 ide`, using
215 Then, inside a Why3 interactive session, any use
216 of :menuselection:`Tools --> Edit` will transfer the file to the already
217 opened instance of :program:`jEdit`. When the proof is completed, the
218 user must send back the edited proof to Why3 IDE by closing
219 the opened buffer, typically by hitting :kbd:`Control-w`.
221 Using Isabelle server
222 ~~~~~~~~~~~~~~~~~~~~~
224 Starting from Isabelle version 2018, Why3 is able to exploit the server
225 features of Isabelle to speed up the processing of proofs in batch mode,
226 e.g., when replaying them from within Why3 IDE. Currently, when replaying
227 proofs using the :program:`isabelle why3` tool, an Isabelle process including a
228 rather heavyweight Java/Scala and PolyML runtime environment has to be
229 started, and a suitable heap image has to be loaded for each proof
230 obligation, which can take several seconds. To avoid this overhead, an
231 Isabelle server and a suitable session can be started once, and then
232 :program:`isabelle why3` can just connect to it and request the server to
233 process theories. In order to allow a tool such as Why3 IDE to use the
234 Isabelle server, it has to be started via the wrapper tool
235 :program:`isabelle use_server`. For example, to process the proofs in
236 :file:`examples/logic/genealogy` using Why3 IDE and the Isabelle server, do the
239 #. Start an Isabelle server using
245 #. Start Why3 IDE using
249 isabelle use_server why3 ide genealogy
254 Realizations must be designed in some :file:`.thy` as follows. The
255 realization file corresponding to some Why3 file :file:`f.why` should have
264 section {* realization of theory T *}
271 why3_vc <some other lemma> by proof
277 See directory :file:`lib/isabelle` for examples.
279 .. index:: PVS proof assistant, proof assistant; PVS
288 You need version 6.0.
293 When a PVS file is regenerated, the old version is split into chunks,
294 according to blank lines. Chunks corresponding to Why3 declarations are
295 identified with a comment starting with ``% Why3``, e.g.,
302 Other chunks are considered to be user PVS declarations. Thus a comment
303 such as ``% Why3 f`` must not be removed; otherwise, there will be two
304 declarations for ``f`` in the next version of the file (one being
305 regenerated and another one considered to be a user-edited chunk).
310 The user is allowed to perform the following actions on a PVS
313 - give a definition to an uninterpreted symbol (type, function, or
314 predicate symbol), by adding an equal sign (``=``) and a right-hand
315 side to the definition. When the declaration is regenerated, the
316 left-hand side is updated and the right-hand side is reprinted as is.
317 In particular, the names of a function or predicate arguments should
318 not be modified. In addition, the ``MACRO`` keyword may be inserted
319 and it will be kept in further generations.
321 - turn an axiom into a lemma, that is to replace the PVS keyword
322 ``AXIOM`` with either ``LEMMA`` or ``THEOREM``.
324 - insert anything between generated declarations, such as a lemma, an
325 extra definition for the purpose of a proof, an extra ``IMPORTING``
326 command, etc. Do not forget to surround these extra declarations with
329 Why3 makes some effort to merge new declarations with old ones and with
330 user chunks. If it happens that some chunks could not be merged, they
331 are appended at the end of the file, in comments.