9 The first step in using Why3 is to write a suitable input file. When one
10 wants to learn a programming language, one starts by writing a basic
11 program. Here is our first Why3 file, which is the file
12 :file:`examples/logic/hello_proof.why` of the distribution. It contains a
15 .. literalinclude:: ../examples/logic/hello_proof.why
18 Any declaration must occur inside a theory, which is in that example
19 called ``HelloProof``. It contains three goals named
20 ``G1``, ``G2``, ``G3``. The first two are basic propositional goals,
21 whereas the third involves some integer arithmetic, and thus it requires
22 to import the theory of integer arithmetic from the Why3 standard
23 library, which is done by the ``use`` declaration above.
25 We don’t give more details here about the syntax and refer to
26 :numref:`chap.whyml` for detailed explanations. In the following, we
27 show how this file is handled in the Why3 GUI (:numref:`sec.gui`) then
28 in batch mode using the :program:`why3` executable (:numref:`sec.batch`).
30 But before running any Why3 command, you should proceed with the
31 automated detection of external provers (see also :numref:`sec.provers`).
32 This is done by running the :why3:tool:`config` tool on the command line,
39 .. %EXECUTE rm -rf doc/hello_proof/
40 .. %EXECUTE cp examples/logic/hello_proof.why doc/
44 Getting Started with the GUI
45 ----------------------------
47 The graphical interface makes it possible to browse into a file or a set of files,
48 and check the validity of goals with external provers, in a friendly
49 way. This section presents the basic use of this GUI. Please refer to
50 :numref:`sec.ideref` for a more complete description.
52 .. %EXECUTE bin/why3 ide --batch="snap doc/images/gui-1.png" doc/hello_proof.why
56 .. figure:: images/gui-1.png
57 :alt: The GUI when started the very first time.
59 The GUI when started the very first time.
61 The GUI is launched on the file above as follows:
65 why3 ide hello_proof.why
67 When the GUI is started for the first time, you should get a window that
68 looks like the screenshot of :numref:`fig.gui1`. The left part is a tree
69 view that makes it possible to browse inside the files and their
70 theories. The tree view shows that the example is made of a single file
71 containing a single theory containing three goals. The top-right pane
72 displays the content of this file. Now click on the row corresponding to
73 goal ``G1``, and then click on the “Task” tab of the top-right pane, so
74 that it displays the corresponding *task*, as show on :numref:`fig.gui2`.
76 .. %EXECUTE bin/why3 ide --batch="type next;view task;snap -crop 1024x384+0+0 doc/images/gui-2.png" doc/hello_proof.why
80 .. figure:: images/gui-2.png
81 :alt: The GUI with goal ``G1`` selected.
83 The GUI with goal ``G1`` selected.
85 Calling provers on goals
86 ~~~~~~~~~~~~~~~~~~~~~~~~
88 You are now ready to call provers on the goals. (If not done yet, you
89 must perform prover autodetection using :why3:tool:`why3 config`.)
91 selected using the context menu (right-click). This prover is then
92 called on the goal selected in the tree view. You can select several
93 goals at a time, either by using multi-selection (typically by clicking
94 while pressing the :kbd:`Shift` or :kbd:`Control` key) or by selecting the parent theory or the
97 Let us now select the theory “HelloProof” and run the Alt-Ergo prover.
98 After a short time, you should get the display of :numref:`fig.gui3`.
100 .. %EXECUTE bin/why3 ide --batch="type alt-ergo;view source;wait 3;type next;snap -crop 1024x384+0+0 doc/images/gui-3.png" doc/hello_proof.why
104 .. figure:: images/gui-3.png
105 :alt: The GUI after running the Alt-Ergo prover on each goal.
107 The GUI after running the Alt-Ergo prover on each goal.
109 Goals ``G1`` and ``G3`` are now marked with a green “checked”
110 icon in the status column. This means that these goals have been proved
111 by Alt-Ergo. On the contrary, goal ``G2`` is not proved; it remains
112 marked with a question mark. You could attempt to prove ``G2``
113 using another prover, though it is obvious here it will not succeed.
115 Applying transformations
116 ~~~~~~~~~~~~~~~~~~~~~~~~
118 Instead of calling a prover on a goal, you can apply a transformation to
119 it. Since ``G2`` is a conjunction, a possibility is to split it into
120 subgoals. You can do that by selecting :guilabel:`Split VC` in the
121 context menu. Now you have two subgoals, and you can try again a prover
122 on them, for example Alt-Ergo. We already have a lot of goals and proof
123 attempts, so it is a good idea to close the sub-trees which are already
124 proved. This can be done by the menu :menuselection:`View --> Collapse
125 proved goals`, or even better by its shortcut :kbd:`!`. You
126 should now see what is displayed on :numref:`fig.gui4`.
128 .. %EXECUTE bin/why3 ide --batch="type alt-ergo;wait 3;type next;type split_vc;wait 1;type up;type alt-ergo;wait 3;type next;snap -crop 1024x384+0+0 doc/images/gui-4.png;save;wait 1" doc/hello_proof.why
132 .. figure:: images/gui-4.png
133 :alt: The GUI after splitting goal ``G2``.
135 The GUI after splitting goal ``G2``.
137 The first part of goal ``G2`` is still unproved. As a last resort,
138 you can try to call the Coq proof assistant, by selecting it in the
139 context menu. A new sub-row appear for Coq, and the Coq proof editor is
140 launched. (It is ``coqide`` by default; see :numref:`sec.ideref` for
141 details on how to configure this). You get now a regular Coq file to
142 fill in, as shown on :numref:`fig.coqide`. Please be mindful of the
143 comments of this file. They indicate where Why3 expects you to fill the
144 blanks. Note that the comments themselves should not be removed, as they
145 are needed to properly regenerate the file when the goal is changed. See
146 :numref:`sec.coq` for more details.
148 .. %EXECUTE bin/why3 ide --batch="type next;type coq;wait 1;save;wait 1" doc/hello_proof.why
152 .. figure:: images/coqide.png
153 :alt: CoqIDE on subgoal 1 of ``G2``.
155 CoqIDE on subgoal 1 of ``G2``.
157 Of course, in that particular case, the goal cannot be proved since it
158 is not valid. The only thing to do is to fix the input file, as
164 You can edit the source file, using the corresponding tab in the
165 top-right pane of the GUI. Change the goal ``G2`` by replacing the first
166 occurrence of ``true`` by ``false``, e.g.,
168 .. code-block:: whyml
170 goal G2 : (false -> false) /\ (true \/ false)
172 You can refresh the goals using menu :menuselection:`File --> Save all and
173 Refresh session`, or the shortcut :kbd:`Control-r`. You get the tree view
174 shown on :numref:`fig.gui5`.
176 .. %EXECUTE sed -i -e 's/true -> false/false -> false/' doc/hello_proof.why
177 .. %EXECUTE bin/why3 ide --batch="type next;type expand;snap -crop 1024x384+0+0 doc/images/gui-5.png" doc/hello_proof.why
181 .. figure:: images/gui-5.png
182 :alt: File reloaded after modifying goal ``G2``.
184 File reloaded after modifying goal ``G2``.
186 The important feature to notice first is that all the previous proof
187 attempts and transformations were saved in a database — an XML file
188 created when the Why3 file was opened in the GUI for the first time.
189 Then, for all the goals that remain unchanged, the previous proofs are
190 shown again. For the parts that changed, the previous proofs attempts
191 are shown but marked with “(:index:`obsolete`)” so that you know the results are
192 not accurate. You can now retry to prove all the goals not yet proved using
195 Replaying obsolete proofs
196 ~~~~~~~~~~~~~~~~~~~~~~~~~
198 Instead of pushing a prover's button to rerun its proofs, you can
199 *replay* the existing but obsolete proof attempts, using
200 menu :menuselection:`Tools --> Replay valid obsolete proofs`. Notice that
201 replaying can be done in batch mode, using the :why3:tool:`why3 replay`
202 command (see :numref:`sec.why3replay`) For example, running the replayer
203 on the ``hello_proof`` example is as follows (assuming ``G2`` still is
204 ``(true -> false) /\ (true \/ false)``).
206 .. code-block:: console
208 > why3 replay hello_proof
210 +--file ../hello_proof.why: 2/3
211 +--theory HelloProof: 2/3
212 +--goal G2 not proved
214 The last line tells us that no differences were detected between the
215 current run and the run stored in the XML file. The tree above reminds
216 us that ``G2`` is not proved.
221 You may want to clean some of the proof attempts, e.g., removing the
222 unsuccessful ones when a project is finally fully proved. A proof or
223 a transformation can be removed by selecting it and using
224 menu :menuselection:`Tools --> Remove node` or the :kbd:`Delete` key.
225 Menu :menuselection:`Tools --> Clean node` or shortcut :kbd:`C` perform
226 an automatic removal of all proofs attempts that are unsuccessful, while
227 there exists a successful proof attempt for the same goal. Beware that
228 there is no way to undo such a removal.
232 Getting Started with the Why3 Command
233 -------------------------------------
235 The :why3:tool:`why3 prove` command makes it possible to check the validity of goals
236 with external provers, in batch mode. This section presents the basic
237 use of this tool. Refer to :numref:`sec.why3prove` for a more complete
238 description of this tool and all its command-line options.
240 This prints some information messages on what detections are attempted.
241 To know which provers have been successfully detected, you can do as
244 .. code-block:: console
246 > why3 --list-provers
252 The first word of each line is a unique identifier for the associated
253 prover. We thus have now the three provers Alt-Ergo :cite:`ergo`,
254 CVC4 :cite:`barrett11cade`, and Coq :cite:`CoqArt`.
256 Let us assume that we want to run Alt-Ergo on the HelloProof example.
257 The command to type and its output are as follows, where the :option:`why3 prove -P`
258 option is followed by the unique prover identifier (as shown by
259 :option:`why3 --list-provers` option).
261 .. code-block:: console
263 > why3 prove -P Alt-Ergo hello_proof.why
264 hello_proof.why HelloProof G1: Valid (0.00s, 1 steps)
265 hello_proof.why HelloProof G2: Unknown (other) (0.01s)
266 hello_proof.why HelloProof G3: Valid (0.00s, 1 steps)
268 Unlike the Why3 GUI, the command-line tool does not save the proof
269 attempts or applied transformations in a database.
271 We can also specify which goal or goals to prove. This is done by giving
272 first a theory identifier, then goal identifier(s). Here is the way to
273 call Alt-Ergo on goals ``G2`` and ``G3``.
275 .. code-block:: console
277 > why3 prove -P Alt-Ergo hello_proof.why -T HelloProof -G G2 -G G3
278 hello_proof.why HelloProof G2 : Unknown: Unknown (0.01s)
279 hello_proof.why HelloProof G3 : Valid (0.01s)
281 Finally, a transformation to apply to goals before proving them can be
282 specified. To know the unique identifier associated to a transformation,
285 .. code-block:: console
287 > why3 --list-transforms
288 Known non-splitting transformations:
291 Known splitting transformations:
295 Here is how you can split the goal ``G2`` before calling Simplify
296 on the resulting subgoals.
298 .. code-block:: console
300 > why3 prove -P Alt-Ergo hello_proof.why -a split_goal_right -T HelloProof -G G2
301 hello_proof.why HelloProof G2: Unknown (other) (0.01s)
302 hello_proof.why HelloProof G2: Valid (0.00s, 1 steps)
304 :numref:`sec.transformations` gives the description of the various
305 transformations available.
307 .. %EXECUTE rm -r doc/hello_proof.why doc/hello_proof/