4 Structure of Session Files
5 --------------------------
7 The proof session state is stored in an XML file named
8 :file:`{dir}/why3session.xml`, where *dir* is the directory of the
9 project. The XML file follows the DTD given in :file:`share/why3session.dtd`
12 .. literalinclude:: ../share/why3session.dtd
15 .. _sec.proverdetectiondata:
20 The data configuration for the automatic detection of installed provers
21 is stored in the file :file:`provers-detection-data.conf` typically located
22 in directory :file:`/usr/local/share/why3` after installation.
26 The :file:`why3.conf` Configuration File
27 ----------------------------------------
29 One can use a custom configuration file. The Why3 tools look for it in
32 #. the file specified by the :option:`why3 --config` option,
34 #. the file specified by the environment variable :envvar:`WHY3CONFIG` if set,
36 #. the file :file:`$HOME/.why3.conf` (:file:`$USERPROFILE/.why3.conf` under
37 Windows) or, in the case of local installation, :file:`why3.conf` in the
38 top directory of Why3 sources.
40 If none of these files exist, a built-in default configuration is used.
42 A section begins with a header inside square brackets and ends at the
43 beginning of the next section. The header of a section can be a single
44 identifier, e.g., ``[main]``, or it can be composed by a family name and a
45 single family argument, e.g., ``[prover alt-ergo]``.
47 Sections contain associations ``key=value``. A value is either an
48 integer (e.g., ``-555``), a boolean (``true``, ``false``), or a string
49 (e.g., ``"emacs"``). Some specific keys can be attributed multiple values and
50 are thus allowed to occur several times inside a given section. In that
51 case, the relative order of these associations matters.
53 Extra Configuration Files
54 ~~~~~~~~~~~~~~~~~~~~~~~~~
56 In addition to the main configuration file, Why3 commands accept the
57 option :option:`why3 --extra-config` to read one or more files
58 containing additional configuration option. It allows the user to pass
59 extra declarations in prover drivers, as illustrated in
60 :numref:`sec.apiextradrivers`, including declarations for
61 realizations, as illustrated in :numref:`sec.realizations`.
66 Drivers for External Provers
67 ----------------------------
69 Drivers for external provers are readable files from directory
70 ``drivers``. They describe how Why3 should interact
71 with external provers.
73 Files with :file:`.drv` extension represent drivers that might be
74 associated to a specific solver in the :file:`why3.conf`
75 configuration file (see :numref:`sec.whyconffile` for more information);
76 files with :file:`.gen` extension are intended to be imported by
77 other drivers; finally, files with :file:`.aux` extension are
78 automatically generated from the main :file:`Makefile`.
80 .. graphviz:: generated/drivers-smt.dot
81 :caption: Driver dependencies for SMT solvers
84 .. graphviz:: generated/drivers-tptp.dot
85 :caption: Driver dependencies for TPTP solvers
88 .. graphviz:: generated/drivers-coq.dot
89 :caption: Driver dependencies for Coq
92 .. graphviz:: generated/drivers-isabelle.dot
93 :caption: Driver dependencies for Isabelle/HOL
94 :name: fig.drv.isabelle
96 .. graphviz:: generated/drivers-pvs.dot
97 :caption: Driver dependencies for PVS
100 The most important drivers dependencies are shown in the following
101 figures: :numref:`fig.drv.smt` shows the drivers files for SMT
102 solvers, :numref:`fig.drv.tptp` for TPTP solvers, :numref:`fig.drv.coq`
103 for Coq, :numref:`fig.drv.isabelle` for Isabelle/HOL,
104 and :numref:`fig.drv.pvs` for PVS.
106 .. _sec.apiextradrivers:
108 Adding extra drivers for user theories
109 --------------------------------------
111 It is possible for the users to augment the system drivers with extra
112 information for their own declared theories. The processus is
113 described by the following example.
115 First, we define a new theory in a file :file:`bvmisc.mlw`, containing
117 .. code-block:: whyml
122 function lsb BV16.t : BV8.t (** least significant bits *)
123 function msb BV16.t : BV8.t (** most significant bits *)
126 For such a theory, it is a good idea to declare specific translation
127 rules for provers that have a built-in bit-vector support, such as Z3
128 and CVC4 in this example. To do so, we write a extension driver file,
129 :file:`my.drv`, containing
131 .. code-block:: whyml
134 syntax function lsb "((_ extract 7 0) %1)"
135 syntax function msb "((_ extract 15 8) %1)"
138 Now to tell Why3 that we would like this driver extension when calling
139 Z3 or CVC4, we write an extra configuration file, :file:`my.conf`,
152 Finally, to make the whole thing work, we have to call any Why3 command
153 with the additional option :option:`why3 --extra-config`, such as
157 why3 --extra-config=my.conf prove myfile.mlw
159 .. _sec.transformations:
164 This section documents the available transformations. Note that the set
165 of available transformations in your own installation is given
166 by :option:`why3 --list-transforms`.
168 .. why3:transform:: apply
170 Apply an hypothesis to the goal of the task using a *modus ponens*
171 rule. The hypothesis should be an implication whose conclusion can be
172 matched with the goal. The intuitive behavior
173 of :why3:transform:`apply` can be translated as follows.
174 Given :math:`\Gamma, h: f_1 \rightarrow f_2 \vdash G: f_2`, ``apply h``
175 generates a new task :math:`\Gamma, h: f_1 \rightarrow f_2 \vdash G: f_1`.
177 In practice, the transformation also manages to instantiate some variables
178 with the appropriate terms.
180 For example, applying the transformation ``apply zero_is_even`` on the
183 .. code-block:: whyml
185 predicate is_even int
186 predicate is_zero int
187 axiom zero_is_even: forall x: int. is_zero x -> is_even x
190 produces the following goal:
192 .. code-block:: whyml
194 predicate is_even int
195 predicate is_zero int
196 axiom zero_is_even: forall x:int. is_zero x -> is_even x
199 The transformation first matched the goal against the hypothesis and
200 instantiated ``x`` with ``0``. It then applied the *modus ponens* rule
201 to generate the new goal.
203 This transformation helps automated provers when they do not know
204 which hypothesis to use in order to prove a goal.
206 .. why3:transform:: apply with
208 Variant of :why3:transform:`apply` intended to be used in contexts
209 where the latter cannot infer what terms to use for variables given in
210 the applied hypothesis.
212 For example, applying the transformation ``apply transitivity`` on the
215 .. code-block:: whyml
219 axiom transitivity : forall x y z:int. x = y -> y = z -> x = z
222 raises the following error:
226 apply: Unable to infer arguments (try using "with") for: y
228 It means that the tool is not able to infer the right term to
229 instantiate symbol ``y``. In our case, the user knows that the term
230 ``c`` should work. So, it can be specified as follows:
231 ``apply transitivity with c``
233 This generates two goals which are easily provable with hypotheses
236 When multiple variables are needed, they should be provided as a list
237 in the transformation. For the sake of the example, we complicate
238 the ``transitivity`` hypothesis:
240 .. code-block:: whyml
242 axiom t : forall x y z k:int. k = k -> x = y -> y = z -> x = z
244 A value can be provided for ``k`` as follows: ``apply t with c,0``.
246 .. why3:transform:: assert
248 Create an intermediate subgoal. This is comparable to ``assert``
249 written in WhyML code. Here, the intent is only to help provers by
250 specifying one key argument of the reasoning they should use.
252 Example: From a goal of the form :math:`\Gamma \vdash G`, the
253 transformation ``assert (n = 0)`` produces the following two
254 tasks: :math:`\Gamma \vdash h: n = 0` and :math:`\Gamma, h: n =
255 0 \vdash G`. This effectively adds ``h`` as an intermediate goal to prove.
257 .. why3:transform:: assert as
259 Same as :why3:transform:`assert`, except that a name can be given to
260 the new hypothesis. Example: ``assert (x = 0) as x0``.
262 .. why3:transform:: case
264 Split a goal into two subgoal, using the *excluded middle* on a given
265 formula. On the task :math:`\Gamma \vdash G`, the transformation
266 ``case f`` produces two tasks: :math:`\Gamma, h: f \vdash G` and
267 :math:`\Gamma, h: \neg f \vdash G`.
269 For example, applying ``case (x = 0)`` on the following goals
271 .. code-block:: whyml
275 goal G: if x = 0 then y = 2 else y = 3
277 produces the following goals:
279 .. code-block:: whyml
284 goal G : if x = 0 then y = 2 else y = 3
286 .. code-block:: whyml
291 goal G : if x = 0 then y = 2 else y = 3
293 The intent is again to simplify the job of automated provers by giving
294 them a key argument of the reasoning behind the proof of a subgoal.
296 .. why3:transform:: case as
298 Same as :why3:transform:`case`, except that a name can be given to
299 the new hypothesis. Example: ``case (x = 0) as x0``.
301 .. why3:transform:: clear_but
303 Remove all the hypotheses except those specified in the arguments.
304 This is useful when a prover fails to find relevant hypotheses in
305 a very large context. Example: ``clear_but h23,h25``.
307 .. why3:transform:: compute_hyp
309 Apply the transformation :why3:transform:`compute_in_goal` on the given
312 .. why3:transform:: compute_hyp_specified
314 Apply the transformation :why3:transform:`compute_specified` on the
317 .. why3:transform:: compute_in_goal
319 Aggressively apply all known computation/simplification rules.
321 The kinds of simplification are as follows.
323 - Computations with built-in symbols, e.g., operations on integers, when
324 applied to explicit constants, are evaluated. This includes
325 evaluation of equality when a decision can be made (on integer
326 constants, on constructors of algebraic data types), Boolean
327 evaluation, simplification of pattern-matching/conditional
328 expression, extraction of record fields, and beta-reduction. At best,
329 these computations reduce the goal to ``true`` and the
330 transformations thus does not produce any sub-goal. For example, a
331 goal like ``6*7=42`` is solved by those transformations.
333 - Unfolding of definitions, as done by :why3:transform:`inline_goal`. Transformation
334 :why3:transform:`compute_in_goal` unfolds all definitions, including recursive
335 ones. For :why3:transform:`compute_specified`, the user can enable unfolding of a
336 specific logic symbol by attaching the meta :why3:meta:`rewrite_def` to the
339 .. code-block:: whyml
341 function sqr (x:int) : int = x * x
342 meta "rewrite_def" function sqr
344 - Rewriting using axioms or lemmas declared as rewrite rules. When an
345 axiom (or a lemma) has one of the forms
347 .. code-block:: whyml
349 axiom a: forall ... t1 = t2
353 .. code-block:: whyml
355 axiom a: forall ... f1 <-> f2
357 then the user can declare
359 .. code-block:: whyml
361 meta "rewrite" prop a
363 to turn this axiom into a rewrite rule. Rewriting is always done from
364 left to right. Beware that there is no check for termination nor for
365 confluence of the set of rewrite rules declared.
367 Instead of using a meta, it is possible to declare an axiom as a rewrite
368 rule by adding the :why3:attribute:`[@rewrite]` attribute on the axiom name or on the
371 .. code-block:: whyml
373 axiom a [@rewrite]: forall ... t1 = t2
374 lemma b: [@rewrite] forall ... f1 <-> f2
376 The second form allows some form of local rewriting, e.g.,
378 .. code-block:: whyml
380 lemma l: forall x y. ([@rewrite] x = y) -> f x = f y
382 can be proved by :why3:transform:`introduce_premises` followed by
383 :why3:transform:`compute_specified`.
385 The computations performed by this transformation can take an
386 arbitrarily large number of steps, or even not terminate. For this
387 reason, the number of steps is bounded by a maximal value, which is set
388 by default to 1000. This value can be increased by another meta, e.g.,
390 .. code-block:: whyml
392 meta "compute_max_steps" 1_000_000
394 When this upper limit is reached, a warning is issued, and the
395 partly-reduced goal is returned as the result of the transformation.
397 .. why3:transform:: compute_specified
399 Same as :why3:transform:`compute_in_goal`, but perform rewriting using
400 only built-in operators and user-provided rules.
402 .. why3:transform:: cut
404 Same as :why3:transform:`assert`, but the order of generated subgoals
407 .. why3:transform:: destruct
409 Eliminate the head symbol of a hypothesis.
411 For example, applying ``destruct h`` on the following goal
413 .. code-block:: whyml
417 axiom h : p1 = True /\ (forall x:int. p2 x)
420 removes the logical connective ``/\`` and produces
422 .. code-block:: whyml
427 axiom h : forall x:int. p2 x
430 :why3:transform:`destruct` can be applied on the following constructions:
432 - ``false``, ``true``,
433 - ``/\``, ``\/``, ``->``, ``not``,
435 - ``if ... then ... else ...``,
436 - ``match ... with ... end``,
437 - (in)equality on constructors of the same type.
439 .. why3:transform:: destruct_rec
441 Recursively call :why3:transform:`destruct` on the generated
442 hypotheses. The recursion on implication and ``match`` stops after the
443 first occurence of a different symbol.
445 For example, applying ``destruct_rec H`` on the following goal
447 .. code-block:: whyml
452 axiom H : (a -> b) /\ (b /\ c)
455 does not destruct the implication symbol because it occurs as
456 a subterm of an already destructed symbol. This restriction applies
457 only to implication and ``match`` Other symbols are destructed
458 recursively. Thus, in the generated task, the second ``/\`` is
461 .. code-block:: whyml
471 .. why3:transform:: destruct_term
473 Destruct an expression according to the type of the expression. The
474 transformation produces all possible outcomes of a destruction of the
477 For example, applying ``destruct_term a`` on the following goal
479 .. code-block:: whyml
485 produces the following two goals:
487 .. code-block:: whyml
495 .. code-block:: whyml
502 The term was destructed according to all the possible outcomes in the
503 type. Note that, during destruction, a new constant ``x`` has been
504 introduced for the argument of constructor ``B``.
506 .. why3:transform:: destruct_term using
508 Same as :why3:transform:`destruct_term`, except that names can be given to
509 the constants that were generated.
511 .. why3:transform:: destruct_term_subst
513 Same as :why3:transform:`destruct_term`, except that it also
514 substitutes the created term.
516 .. why3:transform:: eliminate_algebraic
518 Replace algebraic data types by first-order definitions :cite:`paskevich09rr`.
520 .. why3:transform:: eliminate_builtin
522 Remove definitions of symbols that are declared as builtin in the
523 driver, with a “syntax” rule.
525 .. why3:transform:: eliminate_definition_func
527 Replace all function definitions with axioms.
529 .. why3:transform:: eliminate_definition_pred
531 Replace all predicate definitions with axioms.
533 .. why3:transform:: eliminate_definition
535 Apply both :why3:transform:`eliminate_definition_func` and
536 :why3:transform:`eliminate_definition_pred`.
538 .. why3:transform:: eliminate_if
540 Apply both :why3:transform:`eliminate_if_term` and :why3:transform:`eliminate_if_fmla`.
542 .. why3:transform:: eliminate_if_fmla
544 Replace formulas of the form ``if f1 then f2 else f3`` by an
545 equivalent formula using implications and other connectives.
547 .. why3:transform:: eliminate_if_term
549 Replace terms of the form ``if formula then t2 else t3`` by lifting
550 them at the level of formulas. This may introduce ``if then else``
553 .. why3:transform:: eliminate_inductive
555 Replace inductive predicates by (incomplete) axiomatic definitions,
556 construction axioms and an inversion axiom.
558 .. why3:transform:: eliminate_let
560 Apply both :why3:transform:`eliminate_let_fmla` and :why3:transform:`eliminate_let_term`.
562 .. why3:transform:: eliminate_let_fmla
564 Eliminate ``let`` by substitution, at the predicate level.
566 .. why3:transform:: eliminate_let_term
568 Eliminate ``let`` by substitution, at the term level.
570 .. why3:transform:: eliminate_literal
572 .. why3:transform:: eliminate_mutual_recursion
574 Replace mutually recursive definitions with axioms.
576 .. why3:transform:: eliminate_recursion
578 Replace all recursive definitions with axioms.
580 .. why3:transform:: encoding_smt
582 Encode polymorphic types into monomorphic types :cite:`conchon08smt`.
584 .. why3:transform:: encoding_tptp
586 Encode theories into unsorted logic.
588 .. why3:transform:: exists
590 Instantiate an existential quantification with a witness.
592 For example, applying ``exists 0`` on the following goal
594 .. code-block:: whyml
596 goal G : exists x:int. x = 0
598 instantiates the symbol ``x`` with ``0``. Thus, the goal becomes
600 .. code-block:: whyml
604 .. why3:transform:: hide
606 Hide a given term, by creating a new constant equal to the term and
607 then replacing all occurences of the term in the context by this
610 For example, applying ``hide t (1 + 1)`` on the goal
612 .. code-block:: whyml
615 axiom h : forall x:int. x = (1 + 1)
616 goal G : (y - (1 + 1)) = ((1 + 1) - (1 + 1))
618 replaces all the occurrences of ``(1 + 1)`` with ``t``, which gives
621 .. code-block:: whyml
625 axiom H : t = (1 + 1)
626 axiom h : forall x:int. x = t
627 goal G : (y - t) = (t - t)
629 .. why3:transform:: hide_and_clear
631 First apply :why3:transform:`hide` and then remove the equality
632 between the hidden term and the introduced constant. This means that
633 the hidden term completely disappears and cannot be recovered.
635 .. why3:transform:: induction
637 Perform a reasoning by induction for the current goal.
639 For example, applying ``induction n`` on the following goal
641 .. code-block:: whyml
649 performs an induction on ``n`` starting at ``0``. The goal for the
652 .. code-block:: whyml
661 while the recursive case is
663 .. code-block:: whyml
670 axiom Hrec : forall n1:int. n1 < n -> p1 n1 -> p n1
673 .. why3:transform:: induction from
675 Same as :why3:transform:`induction`, but it starts the induction from
676 a given integer instead of ``0``.
678 .. why3:transform:: induction_arg_pr
680 Apply :why3:transform:`induction_pr` on the given hypothesis/goal symbol.
682 .. why3:transform:: induction_arg_ty_lex
684 Apply :why3:transform:`induction_ty_lex` on the given symbol.
686 .. why3:transform:: induction_pr
688 .. why3:transform:: induction_ty_lex
690 Perform structural, lexicographic induction on goals involving
691 universally quantified variables of algebraic data types, such as
692 lists, trees, etc. For instance, it transforms the following goal
694 .. code-block:: whyml
696 goal G: forall l: list 'a. length l >= 0
700 .. code-block:: whyml
705 | Nil -> length l >= 0
706 | Cons a l1 -> length l1 >= 0 -> length l >= 0
709 When induction can be applied to several variables, the
710 transformation picks one heuristically. The :why3:attribute:`[@induction]`
711 attribute can be used to force induction over one particular
714 .. code-block:: whyml
716 goal G: forall l1 [@induction] l2 l3: list 'a.
717 l1 ++ (l2 ++ l3) = (l1 ++ l2) ++ l3
719 induction will be applied on ``l1``. If this attribute is attached
720 to several variables, a lexicographic induction is performed on
721 these variables, from left to right.
723 .. why3:transform:: inline_trivial
725 Expand and remove definitions of the form
727 .. code-block:: whyml
729 function f x1 ... xn = g e1 ... ek
730 predicate p x1 ... xn = q e1 ... ek
732 when each :samp:`e{i}` is either a ground term or one of the
733 :samp:`x{j}`, and each ``x1 ... xn`` occurs at most once in
734 all the :samp:`e{i}`.
736 The attribute :why3:attribute:`[@inline:trivial]` can be used to tag functions, so
737 that the transformation forcefully expands them (not using the
738 conditions above). This can be used to ensure that some specific
739 functions are inlined for automatic provers
740 (:why3:transform:`inline_trivial` is used in many drivers).
742 .. why3:transform:: inline_goal
744 Expand all outermost symbols of the goal that have a non-recursive
747 .. why3:transform:: inline_all
749 Expand all non-recursive definitions.
751 .. why3:transform:: instantiate
753 Generate a new hypothesis with quantified variables
754 replaced by the given terms.
756 For example, applying ``instantiate h 0, 1`` on the following goal
758 .. code-block:: whyml
761 axiom h : forall x:int, y:int. x <= y -> p x /\ p y
764 generates a new hypothesis:
766 .. code-block:: whyml
769 axiom h : forall x:int, y:int. x <= y -> p x /\ p y
770 axiom Hinst : 0 <= 1 -> p 0 /\ p 1
773 This is used to help automatic provers that are generally better at
774 working on instantiated hypothesis.
776 .. why3:transform:: inst_rem
778 Apply :why3:transform:`instantiate` then remove the original
779 instantiated hypothesis.
781 .. why3:transform:: introduce_premises
783 Move antecedents of implications and universal quantifications of
784 the goal into the premises of the task.
786 .. why3:transform:: intros
788 Introduce universal quantifiers in the context.
790 For example, applying ``intros n, m`` on the following goal
792 .. code-block:: whyml
794 predicate p int int int
795 goal G : forall x:int, y:int, z:int. p x y z
797 produces the following goal:
799 .. code-block:: whyml
801 predicate p int int int
804 goal G : forall z:int. p n m z
806 .. why3:transform:: intros_n
808 Same as :why3:transform:`intros`, but stops after the nth quantified
811 For example, applying ``intros_n 2`` on the following goal
813 .. code-block:: whyml
815 predicate p int int int
816 goal G : forall x:int, y:int, z:int. p x y z
818 produces the following goal:
820 .. code-block:: whyml
822 predicate p int int int
825 goal G : forall z:int. p x y z
827 .. why3:transform:: inversion_arg_pr
829 Apply :why3:transform:`inversion_pr` on the given hypothesis/goal symbol.
831 .. why3:transform:: inversion_pr
833 .. why3:transform:: left
835 Remove the right part of the head disjunction of the goal.
837 For example, applying ``left`` on the following goal
839 .. code-block:: whyml
842 goal G : x = 0 \/ x = 1
844 produces the following goal:
846 .. code-block:: whyml
851 .. why3:transform:: pose
853 Add a new constant equal to the given term.
855 For example, applying ``pose t (x + 2)`` to the following goal
857 .. code-block:: whyml
862 produces the following goal:
864 .. code-block:: whyml
868 axiom H : t = (x + 2)
871 .. why3:transform:: remove
873 Remove a hypothesis from the context.
875 For example, applying ``remove h`` on the following goal
877 .. code-block:: whyml
882 produces the following goal:
884 .. code-block:: whyml
888 .. why3:transform:: replace
890 Replace a term with another one in a hypothesis or in the goal. This
891 generates a new goal which asks for the proof of the equality.
893 For example, applying ``replace (y + 1) (x + 2) in h`` on the
896 .. code-block:: whyml
900 axiom h : x >= (y + 1)
903 produces the following two goals:
905 .. code-block:: whyml
909 axiom h : x >= (x + 2)
912 .. code-block:: whyml
916 axiom h : x >= (y + 1)
917 goal G : (y + 1) = (x + 2)
919 It can be seen as the combination of :why3:transform:`assert`
920 and :why3:transform:`rewrite`.
922 .. why3:transform:: revert
924 Opposite of :why3:transform:`intros`. It takes hypotheses/constants
925 and quantifies them in the goal.
927 For example, applying ``revert x`` on the following goal
929 .. code-block:: whyml
936 produces the following goal:
938 .. code-block:: whyml
941 goal G : forall x:int. x = y -> true
943 .. why3:transform:: rewrite
945 Rewrite using the given equality hypothesis.
947 For example, applying ``rewrite eq`` on the following goal
949 .. code-block:: whyml
951 function a int : bool
952 function b int : bool
954 axiom eq : forall x:int. not x = 0 -> a x = b x
957 produces the following goal:
959 .. code-block:: whyml
961 function a int : bool
962 function b int : bool
964 axiom eq : forall x:int. not x = 0 -> a x = b x
967 It also produces a goal for the premise of the equality hypothesis (as
968 would :why3:transform:`apply`):
970 .. code-block:: whyml
972 function a int : bool
973 function b int : bool
975 axiom eq : forall x:int. not x = 0 -> a x = b x
978 .. why3:transform:: rewrite with
980 Variant of :why3:transform:`rewrite` intended to be used in contexts
981 where the latter cannot infer what terms to use for the variables of
982 the given hypotheses (see also :why3:transform:`apply with`).
984 For example, the transformation ``rewrite eq with 0`` can be applied
985 to the following goal:
987 .. code-block:: whyml
989 function a int : bool
990 function b int : bool
992 axiom eq : forall x:int, z:int. z = 0 -> not x = 0 -> a x = b x
995 Here, a value is provided for the symbol ``z``. This leads to the
996 following three goals. One is the rewritten one, while the other two
997 are for the premises of the equality hypothesis.
999 .. code-block:: whyml
1001 function a int : bool
1002 function b int : bool
1004 axiom eq : forall x:int, z:int. z = 0 -> not x = 0 -> a x = b x
1007 .. code-block:: whyml
1009 function a int : bool
1010 function b int : bool
1012 axiom eq : forall x:int, z:int. z = 0 -> not x = 0 -> a x = b x
1015 .. code-block:: whyml
1017 function a int : bool
1018 function b int : bool
1020 axiom eq : forall x:int, z:int. z = 0 -> not x = 0 -> a x = b x
1023 .. why3:transform:: rewrite_list
1025 Variant of :why3:transform:`rewrite` that allows simultaneous rewriting in
1026 a list of hypothesis/goals.
1028 .. why3:transform:: right
1030 Remove the left part of the head disjunction of the goal.
1032 For example, applying ``right`` on the following goal
1034 .. code-block:: whyml
1037 goal G : x = 0 \/ x = 1
1039 produces the following goal:
1041 .. code-block:: whyml
1046 .. why3:transform:: simplify_array
1048 Automatically rewrite the task using the lemma ``Select_eq`` of
1051 .. why3:transform:: simplify_formula
1053 Reduce trivial equalities ``t=t`` to true and then simplify
1054 propositional structure: removes ``true``, ``false``, simplifies
1055 ``f /\ f`` to ``f``, etc.
1057 .. why3:transform:: simplify_formula_and_task
1059 Apply :why3:transform:`simplify_formula` and remove the goal if
1060 it is equivalent to true.
1062 .. why3:transform:: simplify_recursive_definition
1064 Reduce mutually recursive definitions if they are not really
1065 mutually recursive, e.g.,
1069 function f : ... = ... g ...
1076 function g : ... = e
1077 function f : ... = ... g ...
1079 if ``f`` does not occur in ``e``.
1081 .. why3:transform:: simplify_trivial_quantification
1083 Simplify quantifications of the form
1087 forall x, x = t -> P(x)
1095 when ``x`` does not occur in ``t``. More generally, this
1096 simplification is applied whenever ``x=t`` or ``t=x``
1097 appears in negative position.
1099 .. why3:transform:: simplify_trivial_quantification_in_goal
1101 Apply :why3:transform:`simplify_trivial_quantification`, but only in the goal.
1103 .. why3:transform:: split_all
1105 Perform both :why3:transform:`split_premise` and :why3:transform:`split_goal`.
1107 .. why3:transform:: split_all_full
1109 Perform both :why3:transform:`split_premise` and :why3:transform:`split_goal_full`.
1111 .. why3:transform:: split_goal
1113 Change conjunctive goals into the corresponding set of subgoals. In
1114 absence of case analysis attributes, the number of subgoals
1115 generated is linear in the size of the initial goal.
1117 The transformation treats specially asymmetric and ``by``/``so``
1118 connectives. Asymmetric conjunction ``A && B`` in goal position is
1119 handled as syntactic sugar for ``A /\ (A -> B)``. The conclusion of
1120 the first subgoal can then be used to prove the second one.
1122 Asymmetric disjunction ``A || B`` in hypothesis position is handled
1123 as syntactic sugar for ``A \/ ((not A) /\ B)``. In particular, a
1124 case analysis on such hypothesis would give the negation of the
1125 first hypothesis in the second case.
1127 The ``by`` connective is treated as a proof indication. In
1128 hypothesis position, ``A by B`` is treated as if it were syntactic
1129 sugar for its regular interpretation ``A``. In goal position, it is
1130 treated as if ``B`` was an intermediate step for proving ``A``.
1131 ``A by B`` is then replaced by ``B`` and the transformation also
1132 generates a side-condition subgoal ``B -> A`` representing the
1135 Although splitting stops at disjunctive points like symmetric
1136 disjunction and left-hand sides of implications, the occurrences of
1137 the ``by`` connective are not restricted. For instance:
1143 goal G : (A by B) && C
1145 generates the subgoals
1151 goal G3 : B -> A (* side-condition *)
1157 goal G : (A by B) \/ (C by D)
1164 goal G2 : B -> A (* side-condition *)
1165 goal G3 : D -> C (* side-condition *)
1171 goal G : (A by B) || (C by D)
1178 goal G2 : B -> A (* side-condition *)
1179 goal G3 : B || (D -> C) (* side-condition *)
1181 Note that due to the asymmetric disjunction, the disjunction is
1182 kept in the second side-condition subgoal.
1188 goal G : exists x. P x by x = 42
1194 goal G1 : exists x. x = 42
1195 goal G2 : forall x. x = 42 -> P x (* side-condition *)
1197 Note that in the side-condition subgoal, the context is
1200 The ``so`` connective plays a similar role in hypothesis position,
1201 as it serves as a consequence indication. In goal position,
1202 ``A so B`` is treated as if it were syntactic sugar for its regular
1203 interpretation ``A``. In hypothesis position, it is treated as if
1204 both ``A`` and ``B`` were true because ``B`` is a consequence of
1205 ``A``. ``A so B`` is replaced by ``A /\ B`` and the transformation
1206 also generates a side-condition subgoal ``A -> B`` corresponding to
1207 the consequence relation between formula.
1209 As with the ``by`` connective, occurrences of ``so`` are
1210 unrestricted. Examples:
1216 goal G : (((A so B) \/ C) -> D) && E
1222 goal G1 : ((A /\ B) \/ C) -> D
1223 goal G2 : (A \/ C -> D) -> E
1224 goal G3 : A -> B (* side-condition *)
1230 goal G : A by exists x. P x so Q x so R x by T x
1231 (* reads: A by (exists x. P x so (Q x so (R x by T x))) *)
1237 goal G1 : exists x. P x
1238 goal G2 : forall x. P x -> Q x (* side-condition *)
1239 goal G3 : forall x. P x -> Q x -> T x (* side-condition *)
1240 goal G4 : forall x. P x -> Q x -> T x -> R x (* side-condition *)
1241 goal G5 : (exists x. P x /\ Q x /\ R x) -> A (* side-condition *)
1243 In natural language, this corresponds to the following proof
1244 scheme for ``A``: There exists a ``x`` for which ``P`` holds.
1245 Then, for that witness ``Q`` and ``R`` also holds. The last one
1246 holds because ``T`` holds as well. And from those three
1247 conditions on ``x``, we can deduce ``A``.
1249 The transformations in the “split” family can be controlled by using
1250 attributes on formulas.
1252 The :why3:attribute:`[@stop_split]` attribute can be used to block the splitting
1253 of a formula. The attribute is removed after blocking, so applying
1254 the transformation a second time will split the formula. This is can
1255 be used to decompose the splitting process in several steps. Also,
1256 if a formula with this attribute is found in non-goal position, its
1257 ``by``/``so`` proof indication will be erased by the transformation.
1258 In a sense, formulas tagged by :why3:attribute:`[@stop_split]` are handled as if
1259 they were local lemmas.
1261 The :why3:attribute:`[@case_split]` attribute can be used to force case analysis
1262 on hypotheses. For instance, applying :why3:transform:`split_goal` on
1266 goal G : ([@case_split] A \/ B) -> C
1268 generates the subgoals
1275 Without the attribute, the transformation does nothing because
1276 undesired case analysis may easily lead to an exponential blow-up.
1278 Note that the precise behavior of splitting transformations in
1279 presence of the :why3:attribute:`[@case_split]` attribute is not yet specified and
1280 is likely to change in future versions.
1282 .. why3:transform:: split_goal_full
1284 Behave similarly to :why3:transform:`split_goal`, but also convert the goal
1285 to conjunctive normal form. The number of subgoals generated may be
1286 exponential in the size of the initial goal.
1288 .. why3:transform:: split_intro
1290 Perform both :why3:transform:`split_goal` and :why3:transform:`introduce_premises`.
1292 .. why3:transform:: split_premise
1294 Replace axioms in conjunctive form by an equivalent collection of
1295 axioms. In absence of case analysis attributes (see :why3:transform:`split_goal`
1296 for details), the number of axiom generated per initial axiom is
1297 linear in the size of that initial axiom.
1299 .. why3:transform:: split_premise_full
1301 Behave similarly to :why3:transform:`split_premise`, but also convert the axioms to
1302 conjunctive normal form. The number of axioms generated per initial
1303 axiom may be exponential in the size of the initial axiom.
1305 .. why3:transform:: subst
1307 Substitute a given constant using an equality found in the context.
1308 The constant is removed.
1310 For example, when applying ``subst x`` on the following goal
1312 .. code-block:: whyml
1318 axiom h1 : z = (x + y)
1321 the transformation first finds the hypothesis ``h`` that can be used to
1322 rewrite ``x``. Then, it replaces every occurrences of ``x`` with ``y + 1``.
1323 Finally, it removes ``h`` and ``x``. The resulting goal is as follows:
1325 .. code-block:: whyml
1329 axiom h1 : z = ((y + 1) + y)
1330 goal G : (y + 1) = z
1332 This transformation is used to make the task more easily readable by
1333 a human during debugging. This transformation should not help
1334 automatic provers at all as they generally implement substitution
1335 rules in their logic.
1337 .. why3:transform: subst_all
1339 Substitute all the variables that can be substituted.
1341 For example, applying ``subst_all`` on the following goal
1343 .. code-block:: whyml
1349 axiom h : x = (y + 1)
1351 axiom h1 : z = (x + y)
1354 produces the following goal, where ``x``, ``x1``, and ``z`` have been
1357 .. code-block:: whyml
1360 goal G : (y + 1) = ((y + 1) + y)
1362 The order in which constants are substituted is not specified.
1364 .. why3:transform:: unfold
1366 Unfold the definition of a logical symbol in the given hypothesis.
1368 For example, applying ``unfold p`` on the following goal
1370 .. code-block:: whyml
1372 predicate p (x:int) = x <= 22
1373 axiom h : forall x:int. p x -> p (x - 1)
1376 produces the following goal:
1378 .. code-block:: whyml
1380 predicate p (x:int) = x <= 22
1381 axiom h : forall x:int. p x -> p (x - 1)
1384 One can also unfold in the hypothesis, using ``unfold p in h``, which
1385 gives the following goal:
1387 .. code-block:: whyml
1389 predicate p (x:int) = x <= 22
1390 axiom h : forall x:int. x <= 22 -> (x - 1) <= 22
1393 .. why3:transform:: use_th
1395 Import a theory inside the current context. This is used, in some rare
1396 case, to reduced the size of the context in other goals, since
1397 importing a theory in the WhyML code would the theory available in all
1398 goals whereas the theory is only needed in one specific goal.
1400 For example, applying ``use_th int.Int`` on the following goal
1402 .. code-block:: whyml
1407 imports the ``Int`` theory. So, one is able to use the addition over
1408 integers, e.g., ``replace 5 (2 + 3)``.
1410 Any lemma appearing in the imported theory can also be used.
1412 Note that axioms are also imported. So, this transformation should be
1413 used with care. We recommend to use only theories that do not contain
1414 any axiom because this transformation could easily make the context
1422 As seen in :numref:`sec.ideref`, the IDE provides a few buttons that
1423 trigger the run of simple proof strategies on the selected goals. Proof
1424 strategies can be defined using a basic assembly-style language, and put
1425 into the Why3 configuration file. The commands of this basic language
1428 - :samp:`c {p} {t} {m}` calls the prover *p* with a time limit *t*
1429 and memory limit *m*. On success, the strategy ends, it
1430 continues to next line otherwise.
1432 - :samp:`t {n} {lab}` applies the transformation *n*. On success, the
1433 strategy continues to label *lab*, and is applied to each
1434 generated sub-goals. It continues to next line otherwise.
1436 - :samp:`g {lab}` unconditionally jumps to label *lab*.
1438 - :samp:`{lab}:` declares the label *lab*. The default label ``exit``
1441 To examplify this basic programming language, we give below the default
1442 strategies that are attached to the default buttons of the IDE, assuming
1443 that the provers Alt-Ergo 2.3.0, CVC4 1.7 and Z3 4.8.4 were detected by
1444 the :why3:tool:`why3 config` command.
1447 is bound to the 1-line strategy
1459 c Alt-Ergo,2.3.0, 1 1000
1462 The three provers are tried for a time limit of 1 second and memory
1463 limit of 1 Gb, each in turn. This is a perfect strategy for a first
1464 attempt to discharge a new goal.
1472 c Alt-Ergo,2.3.0, 5 1000
1475 Same as Auto_level_0 but with 5 seconds instead of 1.
1484 c Alt-Ergo,2.3.0, 1 1000
1488 c Alt-Ergo,2.3.0, 10 4000
1491 The three provers are first tried for a time limit of 1 second and
1492 memory limit of 1 Gb, each in turn. If none of them succeed, a split
1493 is attempted. If the split works then the same strategy is retried
1494 on each sub-goals. If the split does not succeed, the provers are
1495 tried again with larger limits.
1504 c Eprover,2.0, 1 1000
1506 c Alt-Ergo,2.3.0, 1 1000
1510 c Eprover,2.0, 5 2000
1512 c Alt-Ergo,2.3.0, 5 2000
1514 t introduce_premises afterintro
1516 t inline_goal afterinline
1519 t split_all_full start
1522 c Eprover,2.0, 30 4000
1523 c Spass,3.7, 30 4000
1524 c Alt-Ergo,2.3.0, 30 4000
1527 Notice that now 5 provers are used. The provers are first tried for
1528 a time limit of 1 second and memory limit of 1 Gb, each in turn. If
1529 none of them succeed, a split is attempted. If the split works then
1530 the same strategy is retried on each sub-goals. If the split does
1531 not succeed, the prover are tried again with limits of 5 s and 2 Gb.
1532 If all fail, we attempt the transformation of introduction of
1533 premises in the context, followed by an inlining of the definitions
1534 in the goals. We then attempt a split again, if the split succeeds,
1535 we restart from the beginning, if it fails then provers are tried
1536 again with 30s and 4 Gb.
1541 .. why3:attribute:: case_split
1543 .. why3:attribute:: induction
1545 .. why3:attribute:: infer
1547 .. why3:attribute:: inline:trivial
1549 .. why3:attribute:: model_trace
1551 .. why3:attribute:: rewrite
1553 .. why3:attribute:: stop_split
1555 .. why3:attribute:: vc:annotation
1557 .. why3:attribute:: vc:divergent
1559 .. why3:attribute:: vc:keep_precondition
1561 .. why3:attribute:: vc:sp
1563 .. why3:attribute:: vc:wp
1565 .. why3:attribute:: vc:white_box
1572 .. why3:meta:: compute_max_steps
1574 .. why3:meta:: keep:literal
1576 .. why3:meta:: realized_theory
1578 .. why3:meta:: rewrite
1580 .. why3:meta:: rewrite_def
1587 .. why3:debug:: infer-loop
1589 .. why3:debug:: infer-print-ai-result
1591 .. why3:debug:: infer-print-cfg
1593 .. why3:debug:: print-inferred-invs
1595 .. why3:debug:: print-domains-loop
1597 .. why3:debug:: stack_trace
1600 Updating Syntax Error Messages
1601 ------------------------------
1603 Here is the developer's recipe to update a syntax error message. We do
1604 it on the following illustrative example.
1606 .. code-block:: whyml
1608 function let int : int
1610 If such a file is passed to Why3, one obtains:
1614 File "bench/parsing/bad/498_function.mlw", line 1, characters 9-12:
1617 The recipe given here provides a way to produce a more informative
1618 message. It is based on handcrafted error messages provided by the
1619 `Menhir <http://gallium.inria.fr/~fpottier/menhir/>`_ parser generator.
1621 The first step is to call :program:`menhir` with option ``--interpret-error``
1622 while giving as input the erroneous input, under the form of a sequence
1623 of tokens as generated by :file:`src/parser/lexer.mll`.
1625 .. code-block:: console
1627 $ echo "decl_eof: FUNCTION LET" | menhir --base src/parser/parser --interpret-error src/parser/parser_common.mly src/parser/parser.mly
1628 decl_eof: FUNCTION LET
1630 ## Ends in an error in state: 1113.
1632 ## pure_decl -> FUNCTION . function_decl list(with_logic_decl) [ VAL USE TYPE THEORY SCOPE PREDICATE MODULE META LET LEMMA INDUCTIVE IMPORT GOAL FUNCTION EXCEPTION EOF END CONSTANT COINDUCTIVE CLONE AXIOM ]
1634 ## The known suffix of the stack is as follows:
1638 <YOUR SYNTAX ERROR MESSAGE HERE>
1640 The text returned by that command should be appended to
1641 :file:`src/parser/handcrafted.messages`, with of course an appropriate error
1642 message, such as this one:
1646 expected function name must be a non-reserved uncapitalized identifier (token LIDENT_NQ), found "$0"