1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946
|
Technical Informations
======================
.. _sec.proverdetectiondata:
Prover Detection
----------------
The data configuration for the automatic detection of installed provers
is stored in the file :file:`provers-detection-data.conf` typically located
in directory :file:`/usr/local/share/why3` after installation.
.. _sec.whyconffile:
The :file:`why3.conf` Configuration File
----------------------------------------
One can use a custom configuration file. The Why3 tools look for it in
the following order:
#. the file specified by the :option:`why3 --config` option,
#. the file specified by the environment variable :envvar:`WHY3CONFIG` if set,
#. the file :file:`$HOME/.why3.conf` (:file:`$USERPROFILE/.why3.conf` under
Windows) or, in the case of local installation, :file:`why3.conf` in the
top directory of Why3 sources.
If none of these files exist, a built-in default configuration is used.
A section begins with a header inside square brackets and ends at the
beginning of the next section. The header of a section can be a single
identifier, e.g., ``[main]``, or it can be composed by a family name and a
single family argument, e.g., ``[prover alt-ergo]``.
Sections contain associations ``key=value``. A value is either an
integer (e.g., ``-555``), a boolean (``true``, ``false``), or a string
(e.g., ``"emacs"``). Some specific keys can be attributed multiple values and
are thus allowed to occur several times inside a given section. In that
case, the relative order of these associations matters.
Extra configuration files
~~~~~~~~~~~~~~~~~~~~~~~~~
In addition to the main configuration file, Why3 commands accept the
option :option:`why3 --extra-config` to read one or more files
containing additional configuration option. It allows the user to pass
extra declarations in prover drivers, as illustrated in
:numref:`sec.userdrivers`, including declarations for
realizations, as illustrated in :numref:`sec.realizations`.
.. _sec.drivers:
Drivers for External Provers
----------------------------
Drivers for external provers are readable files from directory
``drivers``. They describe how Why3 should interact
with external provers.
Files with :file:`.drv` extension represent drivers that might be
associated to a specific solver in the :file:`why3.conf`
configuration file (see :numref:`sec.whyconffile` for more information);
files with :file:`.gen` extension are intended to be imported by
other drivers; finally, files with :file:`.aux` extension are
automatically generated from the main :file:`Makefile`.
.. graphviz:: generated/drivers-smt.dot
:caption: Driver dependencies for SMT solvers
:name: fig.drv.smt
.. graphviz:: generated/drivers-tptp.dot
:caption: Driver dependencies for TPTP solvers
:name: fig.drv.tptp
.. graphviz:: generated/drivers-coq.dot
:caption: Driver dependencies for Coq
:name: fig.drv.coq
.. graphviz:: generated/drivers-isabelle.dot
:caption: Driver dependencies for Isabelle/HOL
:name: fig.drv.isabelle
.. graphviz:: generated/drivers-pvs.dot
:caption: Driver dependencies for PVS
:name: fig.drv.pvs
The most important drivers dependencies are shown in the following
figures: :numref:`fig.drv.smt` shows the drivers files for SMT
solvers, :numref:`fig.drv.tptp` for TPTP solvers, :numref:`fig.drv.coq`
for Coq, :numref:`fig.drv.isabelle` for Isabelle/HOL,
and :numref:`fig.drv.pvs` for PVS.
.. _sec.userdrivers:
Drivers for User Theories
-------------------------
It is possible for the users to augment the system drivers with extra
information for their own declared theories. The process is
described by the following example.
First, we define a new theory in a file :file:`bvmisc.mlw`, containing
.. code-block:: whyml
theory T
use bv.BV8
use bv.BV16
function lsb BV16.t : BV8.t (** least significant bits *)
function msb BV16.t : BV8.t (** most significant bits *)
end
For such a theory, it is a good idea to declare specific translation
rules for provers that have a built-in bit-vector support, such as Z3
and CVC4 in this example. To do so, we write a extension driver file,
:file:`my.drv`, containing
.. code-block:: whyml
theory bvmisc.T
syntax function lsb "((_ extract 7 0) %1)"
syntax function msb "((_ extract 15 8) %1)"
end
Now to tell Why3 that we would like this driver extension when calling
Z3 or CVC4, we write an extra configuration file, :file:`my.conf`,
containing
.. code-block::
[prover_modifiers]
prover = "CVC4"
driver = "my.drv"
[prover_modifiers]
prover = "Z3"
driver = "my.drv"
Finally, to make the whole thing work, we have to call any Why3 command
with the additional option :option:`why3 --extra-config`, such as
::
why3 --extra-config=my.conf prove myfile.mlw
.. _sec.transformations:
Transformations
---------------
This section documents the available transformations. Note that the set
of available transformations in your own installation is given
by :why3:tool:`why3 show transformations`.
.. why3:transform:: apply
Apply an hypothesis to the goal of the task using a *modus ponens*
rule. The hypothesis should be an implication whose conclusion can be
matched with the goal. The intuitive behavior
of :why3:transform:`apply` can be translated as follows.
Given :math:`\Gamma, h: f_1 \rightarrow f_2 \vdash G: f_2`, ``apply h``
generates a new task :math:`\Gamma, h: f_1 \rightarrow f_2 \vdash G: f_1`.
In practice, the transformation also manages to instantiate some variables
with the appropriate terms.
For example, applying the transformation ``apply zero_is_even`` on the
following goal
.. code-block:: whyml
predicate is_even int
predicate is_zero int
axiom zero_is_even: forall x: int. is_zero x -> is_even x
goal G: is_even 0
produces the following goal:
.. code-block:: whyml
predicate is_even int
predicate is_zero int
axiom zero_is_even: forall x:int. is_zero x -> is_even x
goal G: is_zero 0
The transformation first matched the goal against the hypothesis and
instantiated ``x`` with ``0``. It then applied the *modus ponens* rule
to generate the new goal.
This transformation helps automated provers when they do not know
which hypothesis to use in order to prove a goal.
.. why3:transform:: apply with
Variant of :why3:transform:`apply` intended to be used in contexts
where the latter cannot infer what terms to use for variables given in
the applied hypothesis.
For example, applying the transformation ``apply transitivity`` on the
following goal
.. code-block:: whyml
axiom ac: a = c
axiom cb: c = b
axiom transitivity : forall x y z:int. x = y -> y = z -> x = z
goal G1 : a = b
raises the following error:
::
apply: Unable to infer arguments (try using "with") for: y
It means that the tool is not able to infer the right term to
instantiate symbol ``y``. In our case, the user knows that the term
``c`` should work. So, it can be specified as follows:
``apply transitivity with c``
This generates two goals which are easily provable with hypotheses
``ac`` and ``cb``.
When multiple variables are needed, they should be provided as a list
in the transformation. For the sake of the example, we complicate
the ``transitivity`` hypothesis:
.. code-block:: whyml
axiom t : forall x y z k:int. k = k -> x = y -> y = z -> x = z
A value can be provided for ``k`` as follows: ``apply t with c,0``.
.. why3:transform:: assert
Create an intermediate subgoal. This is comparable to ``assert``
written in WhyML code. Here, the intent is only to help provers by
specifying one key argument of the reasoning they should use.
Example: From a goal of the form :math:`\Gamma \vdash G`, the
transformation ``assert (n = 0)`` produces the following two
tasks: :math:`\Gamma \vdash h: n = 0` and :math:`\Gamma, h: n =
0 \vdash G`. This effectively adds ``h`` as an intermediate goal to prove.
.. why3:transform:: assert as
Same as :why3:transform:`assert`, except that a name can be given to
the new hypothesis. Example: ``assert (x = 0) as x0``.
.. why3:transform:: case
Split a goal into two subgoals, using the *excluded middle* on a given
formula. On the task :math:`\Gamma \vdash G`, the transformation
``case f`` produces two tasks: :math:`\Gamma, h: f \vdash G` and
:math:`\Gamma, h: \neg f \vdash G`.
For example, applying ``case (x = 0)`` on the following goals
.. code-block:: whyml
constant x : int
constant y : int
goal G: if x = 0 then y = 2 else y = 3
produces the following goals:
.. code-block:: whyml
constant x : int
constant y : int
axiom h : x = 0
goal G : if x = 0 then y = 2 else y = 3
.. code-block:: whyml
constant x : int
constant y : int
axiom h : not x = 0
goal G : if x = 0 then y = 2 else y = 3
The intent is again to simplify the job of automated provers by giving
them a key argument of the reasoning behind the proof of a subgoal.
.. why3:transform:: case as
Same as :why3:transform:`case`, except that a name can be given to
the new hypothesis. Example: ``case (x = 0) as x0``.
.. why3:transform:: clear_but
Remove all the hypotheses except those specified in the arguments.
This is useful when a prover fails to find relevant hypotheses in
a very large context. Example: ``clear_but h23,h25``.
.. why3:transform:: compute_hyp
Apply the transformation :why3:transform:`compute_in_goal` on the given
hypothesis.
.. why3:transform:: compute_hyp_specified
Apply the transformation :why3:transform:`compute_specified` on the
given hypothesis.
.. why3:transform:: compute_in_goal
Aggressively apply all known computation/simplification rules.
The kinds of simplification are as follows.
- Computations with built-in symbols, e.g., operations on integers, when
applied to explicit constants, are evaluated. This includes
evaluation of equality when a decision can be made (on integer
constants, on constructors of algebraic data types), Boolean
evaluation, simplification of pattern-matching/conditional
expression, extraction of record fields, and beta-reduction. At best,
these computations reduce the goal to ``true`` and the
transformations thus does not produce any sub-goal. For example, a
goal like ``6*7=42`` is solved by those transformations.
- Unfolding of definitions, as done by :why3:transform:`inline_goal`. Transformation
:why3:transform:`compute_in_goal` unfolds all definitions, including recursive
ones. For :why3:transform:`compute_specified`, the user can enable unfolding of a
specific logic symbol by attaching the meta :why3:meta:`rewrite_def` to the
symbol.
.. code-block:: whyml
function sqr (x:int) : int = x * x
meta "rewrite_def" function sqr
- Rewriting using axioms or lemmas declared as rewrite rules. When an
axiom (or a lemma) has one of the forms
.. code-block:: whyml
axiom a: forall ... t1 = t2
or
.. code-block:: whyml
axiom a: forall ... f1 <-> f2
then the user can declare
.. code-block:: whyml
meta "rewrite" prop a
to turn this axiom into a rewrite rule. Rewriting is always done from
left to right. Beware that there is no check for termination nor for
confluence of the set of rewrite rules declared.
Instead of using a meta, it is possible to declare an axiom as a rewrite
rule by adding the :why3:attribute:`[@rewrite]` attribute on the axiom name or on the
axiom itself, e.g.,
.. code-block:: whyml
axiom a [@rewrite]: forall ... t1 = t2
lemma b: [@rewrite] forall ... f1 <-> f2
The second form allows some form of local rewriting, e.g.,
.. code-block:: whyml
lemma l: forall x y. ([@rewrite] x = y) -> f x = f y
can be proved by :why3:transform:`introduce_premises` followed by
:why3:transform:`compute_specified`.
The computations performed by this transformation can take an
arbitrarily large number of steps, or even not terminate. For this
reason, the number of steps is bounded by a maximal value, which is set
by default to 1000. This value can be increased by another meta, e.g.,
.. code-block:: whyml
meta "compute_max_steps" 1_000_000
When this upper limit is reached, a warning is issued, and the
partly-reduced goal is returned as the result of the transformation.
.. why3:transform:: compute_specified
Same as :why3:transform:`compute_in_goal`, but perform rewriting using
only built-in operators and user-provided rules.
.. why3:transform:: cut
Same as :why3:transform:`assert`, but the order of the generated subgoals
is reversed.
.. why3:transform:: destruct
Eliminate the head symbol of a hypothesis.
For example, applying ``destruct h`` on the following goal
.. code-block:: whyml
constant p1 : bool
predicate p2 int
axiom h : p1 = True /\ (forall x:int. p2 x)
goal G : p2 0
removes the logical connective ``/\`` and produces
.. code-block:: whyml
constant p1 : bool
predicate p2 int
axiom h1 : p1 = True
axiom h : forall x:int. p2 x
goal G : p2 0
:why3:transform:`destruct` can be applied on the following constructions:
- ``false``, ``true``,
- ``/\``, ``\/``, ``->``, ``not``,
- ``exists``,
- ``if ... then ... else ...``,
- ``match ... with ... end``,
- (in)equality on constructors of the same type.
.. why3:transform:: destruct_rec
Recursively call :why3:transform:`destruct` on the generated
hypotheses. The recursion on implication and ``match`` stops after the
first occurrence of a different symbol.
For example, applying ``destruct_rec H`` on the following goal
.. code-block:: whyml
predicate a
predicate b
predicate c
axiom H : (a -> b) /\ (b /\ c)
goal G : false
does not destruct the implication symbol because it occurs as
a subterm of an already destructed symbol. This restriction applies
only to implication and ``match`` Other symbols are destructed
recursively. Thus, in the generated task, the second ``/\`` is
simplified:
.. code-block:: whyml
predicate a
predicate b
predicate c
axiom H2 : a -> b
axiom H1 : b
axiom H: c
goal G : false
.. why3:transform:: destruct_term
Destruct an expression according to the type of the expression. The
transformation produces all possible outcomes of a destruction of the
algebraic type.
For example, applying ``destruct_term a`` on the following goal
.. code-block:: whyml
type t = A | B int
constant a : t
goal G : a = A
produces the following two goals:
.. code-block:: whyml
type t = A | B int
constant a : t
constant x : int
axiom h : a = B x
goal G : a = A
.. code-block:: whyml
type t = A | B int
constant a : t
axiom h : a = A
goal G : a = A
The term was destructed according to all the possible outcomes in the
type. Note that, during destruction, a new constant ``x`` has been
introduced for the argument of constructor ``B``.
.. why3:transform:: destruct_term using
Same as :why3:transform:`destruct_term`, except that names can be given to
the constants that were generated.
.. why3:transform:: destruct_term_subst
Same as :why3:transform:`destruct_term`, except that it also
substitutes the created term.
.. why3:transform:: eliminate_algebraic
Replace algebraic data types by first-order definitions :cite:`paskevich09rr`.
.. why3:transform:: eliminate_builtin
Remove definitions of symbols that are declared as builtin in the
driver, with a “syntax” rule.
.. why3:transform:: eliminate_definition_func
Replace all function definitions with axioms.
.. why3:transform:: eliminate_definition_pred
Replace all predicate definitions with axioms.
.. why3:transform:: eliminate_definition
Apply both :why3:transform:`eliminate_definition_func` and
:why3:transform:`eliminate_definition_pred`.
.. why3:transform:: eliminate_if
Apply both :why3:transform:`eliminate_if_term` and :why3:transform:`eliminate_if_fmla`.
.. why3:transform:: eliminate_if_fmla
Replace formulas of the form ``if f1 then f2 else f3`` by an
equivalent formula using implications and other connectives.
.. why3:transform:: eliminate_if_term
Replace terms of the form ``if formula then t2 else t3`` by lifting
them at the level of formulas. This may introduce ``if then else``
in formulas.
.. why3:transform:: eliminate_inductive
Replace inductive predicates by (incomplete) axiomatic definitions,
construction axioms and an inversion axiom.
.. why3:transform:: eliminate_let
Apply both :why3:transform:`eliminate_let_fmla` and :why3:transform:`eliminate_let_term`.
.. why3:transform:: eliminate_let_fmla
Eliminate ``let`` by substitution, at the predicate level.
.. why3:transform:: eliminate_let_term
Eliminate ``let`` by substitution, at the term level.
.. why3:transform:: eliminate_literal
.. why3:transform:: eliminate_mutual_recursion
Replace mutually recursive definitions with axioms.
.. why3:transform:: eliminate_recursion
Replace all recursive definitions with axioms.
.. why3:transform:: encoding_smt
Encode polymorphic types into monomorphic types :cite:`conchon08smt`.
.. why3:transform:: encoding_tptp
Encode theories into unsorted logic.
.. why3:transform:: exists
Instantiate an existential quantification with a witness.
For example, applying ``exists 0`` on the following goal
.. code-block:: whyml
goal G : exists x:int. x = 0
instantiates the symbol ``x`` with ``0``. Thus, the goal becomes
.. code-block:: whyml
goal G : 0 = 0
.. why3:transform:: hide
Hide a given term, by creating a new constant equal to the term and
then replacing all occurrences of the term in the context by this
constant.
For example, applying ``hide t (1 + 1)`` on the goal
.. code-block:: whyml
constant y : int
axiom h : forall x:int. x = (1 + 1)
goal G : (y - (1 + 1)) = ((1 + 1) - (1 + 1))
replaces all the occurrences of ``(1 + 1)`` with ``t``, which gives
the following goal:
.. code-block:: whyml
constant y : int
constant t : int
axiom H : t = (1 + 1)
axiom h : forall x:int. x = t
goal G : (y - t) = (t - t)
.. why3:transform:: hide_and_clear
First apply :why3:transform:`hide` and then remove the equality
between the hidden term and the introduced constant. This means that
the hidden term completely disappears and cannot be recovered.
.. why3:transform:: induction
Perform a reasoning by induction for the current goal.
For example, applying ``induction n`` on the following goal
.. code-block:: whyml
constant n : int
predicate p int
predicate p1 int
axiom h : p1 n
goal G : p n
performs an induction on ``n`` starting at ``0``. The goal for the
base case is
.. code-block:: whyml
constant n : int
predicate p int
predicate p1 int
axiom h : p1 n
axiom Init : n <= 0
goal G : p n
while the recursive case is
.. code-block:: whyml
constant n : int
predicate p int
predicate p1 int
axiom h : p1 n
axiom Init : 0 < n
axiom Hrec : forall n1:int. n1 < n -> p1 n1 -> p n1
goal G : p n
.. why3:transform:: induction from
Same as :why3:transform:`induction`, but it starts the induction from
a given integer instead of ``0``.
.. why3:transform:: induction_arg_pr
Apply :why3:transform:`induction_pr` on the given hypothesis/goal symbol.
.. why3:transform:: induction_arg_ty_lex
Apply :why3:transform:`induction_ty_lex` on the given symbol.
.. why3:transform:: induction_pr
.. why3:transform:: induction_ty_lex
Perform structural, lexicographic induction on goals involving
universally quantified variables of algebraic data types, such as
lists, trees, etc. For instance, it transforms the following goal
.. code-block:: whyml
goal G: forall l: list 'a. length l >= 0
into this one:
.. code-block:: whyml
goal G :
forall l:list 'a.
match l with
| Nil -> length l >= 0
| Cons a l1 -> length l1 >= 0 -> length l >= 0
end
When induction can be applied to several variables, the
transformation picks one heuristically. The :why3:attribute:`[@induction]`
attribute can be used to force induction over one particular
variable, with
.. code-block:: whyml
goal G: forall l1 [@induction] l2 l3: list 'a.
l1 ++ (l2 ++ l3) = (l1 ++ l2) ++ l3
induction will be applied on ``l1``. If this attribute is attached
to several variables, a lexicographic induction is performed on
these variables, from left to right.
.. why3:transform:: inline_trivial
Expand and remove definitions of the form
.. code-block:: whyml
function f x1 ... xn = g e1 ... ek
predicate p x1 ... xn = q e1 ... ek
when each :samp:`e{i}` is either a ground term or one of the
:samp:`x{j}`, and each ``x1 ... xn`` occurs at most once in
all the :samp:`e{i}`.
The attribute :why3:attribute:`[@inline:trivial]` can be used to tag functions, so
that the transformation forcefully expands them (not using the
conditions above). This can be used to ensure that some specific
functions are inlined for automatic provers
(:why3:transform:`inline_trivial` is used in many drivers).
.. why3:transform:: inline_goal
Expand all outermost symbols of the goal that have a non-recursive
definition.
.. why3:transform:: inline_all
Expand all non-recursive definitions.
.. why3:transform:: instantiate
Generate a new hypothesis with quantified variables
replaced by the given terms.
For example, applying ``instantiate h 0, 1`` on the following goal
.. code-block:: whyml
predicate p int
axiom h : forall x:int, y:int. x <= y -> p x /\ p y
goal G : p 0
generates a new hypothesis:
.. code-block:: whyml
predicate p int
axiom h : forall x:int, y:int. x <= y -> p x /\ p y
axiom Hinst : 0 <= 1 -> p 0 /\ p 1
goal G : p 0
This is used to help automatic provers that are generally better at
working on instantiated hypothesis.
.. why3:transform:: inst_rem
Apply :why3:transform:`instantiate` then remove the original
instantiated hypothesis.
.. why3:transform:: introduce_premises
Move antecedents of implications and universal quantifications of
the goal into the premises of the task.
.. why3:transform:: intros
Introduce universal quantifiers in the context.
For example, applying ``intros n, m`` on the following goal
.. code-block:: whyml
predicate p int int int
goal G : forall x:int, y:int, z:int. p x y z
produces the following goal:
.. code-block:: whyml
predicate p int int int
constant n : int
constant m : int
goal G : forall z:int. p n m z
.. why3:transform:: intros_n
Same as :why3:transform:`intros`, but stops after the nth quantified
variable or premise.
For example, applying ``intros_n 2`` on the following goal
.. code-block:: whyml
predicate p int int int
goal G : forall x:int, y:int, z:int. p x y z
produces the following goal:
.. code-block:: whyml
predicate p int int int
constant x : int
constant y : int
goal G : forall z:int. p x y z
.. why3:transform:: inversion_arg_pr
Apply :why3:transform:`inversion_pr` on the given hypothesis/goal symbol.
.. why3:transform:: inversion_pr
.. why3:transform:: left
Remove the right part of the head disjunction of the goal.
For example, applying ``left`` on the following goal
.. code-block:: whyml
constant x : int
goal G : x = 0 \/ x = 1
produces the following goal:
.. code-block:: whyml
constant x : int
goal G : x = 0
.. why3:transform:: pose
Add a new constant equal to the given term.
For example, applying ``pose t (x + 2)`` to the following goal
.. code-block:: whyml
constant x : int
goal G : true
produces the following goal:
.. code-block:: whyml
constant x : int
constant t : int
axiom H : t = (x + 2)
goal G : true
.. why3:transform:: remove
Remove a hypothesis from the context.
For example, applying ``remove h`` on the following goal
.. code-block:: whyml
axiom h : true
goal G : true
produces the following goal:
.. code-block:: whyml
goal G : true
.. why3:transform:: remove_unused
Remove from the context all the logic symbols that are not used by the goal or the hypothesis.
The effect of that transformation can be expanded by adding dependency metas. Namely, with a declaration of the form
.. code-block:: whyml
meta "remove_unused:dependency" axiom a, function f
then occurrences of `f` in axiom `a` are not counted as occurrences
for `f`. The intended meaning is that `a` is a definitional axiom
for `f`, so when `f` is not needed in the remainder, both the axiom
and the declaration of `f` can be removed.
When there are several such definitional axioms for `f`, a meta
must be declared for each axiom. When an axiom is definitional for
several symbols at the same time, several meta must be declared as
well. The rule of thumb is that an axiom is kept as soon as at
least one of the symbols it defines is needed in the remainder,
otherwise it is discarded.
.. why3:transform:: remove_unused_keep_constant
A variant of :why3:transform:`remove_unused` above, where the constant, i.e. the nullary function symbols, are always kept.
The effect of that transformation is controllable with an additional meta of the form
.. code-block:: whyml
meta "remove_unused:remove_constant" constant f
when in that case `f` is also tried to be removed, as if it was
with the full :why3:transform:`remove_unused` transformation.
.. why3:transform:: replace
Replace a term with another one in a hypothesis or in the goal. This
generates a new goal which asks for the proof of the equality.
For example, applying ``replace (y + 1) (x + 2) in h`` on the
following goal
.. code-block:: whyml
constant x : int
constant y : int
axiom h : x >= (y + 1)
goal G : true
produces the following two goals:
.. code-block:: whyml
constant x : int
constant y : int
axiom h : x >= (x + 2)
goal G : true
.. code-block:: whyml
constant x : int
constant y : int
axiom h : x >= (y + 1)
goal G : (y + 1) = (x + 2)
It can be seen as the combination of :why3:transform:`assert`
and :why3:transform:`rewrite`.
.. why3:transform:: revert
Opposite of :why3:transform:`intros`. It takes hypotheses/constants
and quantifies them in the goal.
For example, applying ``revert x`` on the following goal
.. code-block:: whyml
constant x : int
constant y : int
axiom h : x = y
goal G : true
produces the following goal:
.. code-block:: whyml
constant y : int
goal G : forall x:int. x = y -> true
.. why3:transform:: rewrite
Rewrite using the given equality hypothesis.
For example, applying ``rewrite eq`` on the following goal
.. code-block:: whyml
function a int : bool
function b int : bool
constant y : int
axiom eq : forall x:int. not x = 0 -> a x = b x
goal G : a y = True
produces the following goal:
.. code-block:: whyml
function a int : bool
function b int : bool
constant y : int
axiom eq : forall x:int. not x = 0 -> a x = b x
goal G : b y = True
It also produces a goal for the premise of the equality hypothesis (as
would :why3:transform:`apply`):
.. code-block:: whyml
function a int : bool
function b int : bool
constant y : int
axiom eq : forall x:int. not x = 0 -> a x = b x
goal G : not y = 0
.. why3:transform:: rewrite with
Variant of :why3:transform:`rewrite` intended to be used in contexts
where the latter cannot infer what terms to use for the variables of
the given hypotheses (see also :why3:transform:`apply with`).
For example, the transformation ``rewrite eq with 0`` can be applied
to the following goal:
.. code-block:: whyml
function a int : bool
function b int : bool
constant y : int
axiom eq : forall x:int, z:int. z = 0 -> not x = 0 -> a x = b x
goal G : a y = True
Here, a value is provided for the symbol ``z``. This leads to the
following three goals. One is the rewritten one, while the other two
are for the premises of the equality hypothesis.
.. code-block:: whyml
function a int : bool
function b int : bool
constant y : int
axiom eq : forall x:int, z:int. z = 0 -> not x = 0 -> a x = b x
goal G : b y = True
.. code-block:: whyml
function a int : bool
function b int : bool
constant y : int
axiom eq : forall x:int, z:int. z = 0 -> not x = 0 -> a x = b x
goal G : 0 = 0
.. code-block:: whyml
function a int : bool
function b int : bool
constant y : int
axiom eq : forall x:int, z:int. z = 0 -> not x = 0 -> a x = b x
goal G : not y = 0
.. why3:transform:: rewrite_list
Variant of :why3:transform:`rewrite` that allows simultaneous rewriting in
a list of hypothesis/goals.
.. why3:transform:: right
Remove the left part of the head disjunction of the goal.
For example, applying ``right`` on the following goal
.. code-block:: whyml
constant x : int
goal G : x = 0 \/ x = 1
produces the following goal:
.. code-block:: whyml
constant x : int
goal G : x = 1
.. why3:transform:: simplify_array
Automatically rewrite the task using the lemma ``Select_eq`` of
theory ``map.Map``.
.. why3:transform:: simplify_formula
Reduce trivial equalities ``t=t`` to true and then simplify
propositional structure: removes ``true``, ``false``, simplifies
``f /\ f`` to ``f``, etc.
.. why3:transform:: simplify_formula_and_task
Apply :why3:transform:`simplify_formula` and remove the goal if
it is equivalent to true.
.. why3:transform:: simplify_recursive_definition
Reduce mutually recursive definitions if they are not really
mutually recursive, e.g.,
::
function f : ... = ... g ...
with g : ... = e
becomes
::
function g : ... = e
function f : ... = ... g ...
if ``f`` does not occur in ``e``.
.. why3:transform:: simplify_trivial_quantification
Simplify quantifications of the form
::
forall x, x = t -> P(x)
into
::
P(t)
when ``x`` does not occur in ``t``. More generally, this
simplification is applied whenever ``x=t`` or ``t=x``
appears in negative position.
.. why3:transform:: simplify_trivial_quantification_in_goal
Apply :why3:transform:`simplify_trivial_quantification`, but only in the goal.
.. why3:transform:: split_all
Perform both :why3:transform:`split_premise` and :why3:transform:`split_goal`.
.. why3:transform:: split_all_full
Perform both :why3:transform:`split_premise` and :why3:transform:`split_goal_full`.
.. why3:transform:: split_goal
Change conjunctive goals into the corresponding set of subgoals. In
absence of case analysis attributes, the number of subgoals
generated is linear in the size of the initial goal.
The transformation treats specially asymmetric and ``by``/``so``
connectives. Asymmetric conjunction ``A && B`` in goal position is
handled as syntactic sugar for ``A /\ (A -> B)``. The conclusion of
the first subgoal can then be used to prove the second one.
Asymmetric disjunction ``A || B`` in hypothesis position is handled
as syntactic sugar for ``A \/ ((not A) /\ B)``. In particular, a
case analysis on such hypothesis would give the negation of the
first hypothesis in the second case.
The ``by`` connective is treated as a proof indication. In
hypothesis position, ``A by B`` is treated as if it were syntactic
sugar for its regular interpretation ``A``. In goal position, it is
treated as if ``B`` was an intermediate step for proving ``A``.
``A by B`` is then replaced by ``B`` and the transformation also
generates a side-condition subgoal ``B -> A`` representing the
logical cut.
Although splitting stops at disjunctive points like symmetric
disjunction and left-hand sides of implications, the occurrences of
the ``by`` connective are not restricted. For instance:
- Splitting
::
goal G : (A by B) && C
generates the subgoals
::
goal G1 : B
goal G2 : A -> C
goal G3 : B -> A (* side-condition *)
- Splitting
::
goal G : (A by B) \/ (C by D)
generates
::
goal G1 : B \/ D
goal G2 : B -> A (* side-condition *)
goal G3 : D -> C (* side-condition *)
- Splitting
::
goal G : (A by B) || (C by D)
generates
::
goal G1 : B || D
goal G2 : B -> A (* side-condition *)
goal G3 : B || (D -> C) (* side-condition *)
Note that due to the asymmetric disjunction, the disjunction is
kept in the second side-condition subgoal.
- Splitting
::
goal G : exists x. P x by x = 42
generates
::
goal G1 : exists x. x = 42
goal G2 : forall x. x = 42 -> P x (* side-condition *)
Note that in the side-condition subgoal, the context is
universally closed.
The ``so`` connective plays a similar role in hypothesis position,
as it serves as a consequence indication. In goal position,
``A so B`` is treated as if it were syntactic sugar for its regular
interpretation ``A``. In hypothesis position, it is treated as if
both ``A`` and ``B`` were true because ``B`` is a consequence of
``A``. ``A so B`` is replaced by ``A /\ B`` and the transformation
also generates a side-condition subgoal ``A -> B`` corresponding to
the consequence relation between formula.
As with the ``by`` connective, occurrences of ``so`` are
unrestricted. Examples:
- Splitting
::
goal G : (((A so B) \/ C) -> D) && E
generates
::
goal G1 : ((A /\ B) \/ C) -> D
goal G2 : (A \/ C -> D) -> E
goal G3 : A -> B (* side-condition *)
- Splitting
::
goal G : A by exists x. P x so Q x so R x by T x
(* reads: A by (exists x. P x so (Q x so (R x by T x))) *)
generates
::
goal G1 : exists x. P x
goal G2 : forall x. P x -> Q x (* side-condition *)
goal G3 : forall x. P x -> Q x -> T x (* side-condition *)
goal G4 : forall x. P x -> Q x -> T x -> R x (* side-condition *)
goal G5 : (exists x. P x /\ Q x /\ R x) -> A (* side-condition *)
In natural language, this corresponds to the following proof
scheme for ``A``: There exists a ``x`` for which ``P`` holds.
Then, for that witness ``Q`` and ``R`` also holds. The last one
holds because ``T`` holds as well. And from those three
conditions on ``x``, we can deduce ``A``.
The transformations in the “split” family can be controlled by using
attributes on formulas.
The :why3:attribute:`[@stop_split]` attribute can be used to block the splitting
of a formula. The attribute is removed after blocking, so applying
the transformation a second time will split the formula. This is can
be used to decompose the splitting process in several steps. Also,
if a formula with this attribute is found in non-goal position, its
``by``/``so`` proof indication will be erased by the transformation.
In a sense, formulas tagged by :why3:attribute:`[@stop_split]` are handled as if
they were local lemmas.
The :why3:attribute:`[@case_split]` attribute can be used to force case analysis
on hypotheses. For instance, applying :why3:transform:`split_goal` on
::
goal G : ([@case_split] A \/ B) -> C
generates the subgoals
::
goal G1 : A -> C
goal G2 : B -> C
Without the attribute, the transformation does nothing because
undesired case analysis may easily lead to an exponential blow-up.
Note that the precise behavior of splitting transformations in
presence of the :why3:attribute:`[@case_split]` attribute is not yet specified and
is likely to change in future versions.
.. why3:transform:: split_goal_full
Behave similarly to :why3:transform:`split_goal`, but also convert the goal
to conjunctive normal form. The number of subgoals generated may be
exponential in the size of the initial goal.
.. why3:transform:: split_intro
Perform both :why3:transform:`split_goal` and :why3:transform:`introduce_premises`.
.. why3:transform:: split_premise
Replace axioms in conjunctive form by an equivalent collection of
axioms. In absence of case analysis attributes (see :why3:transform:`split_goal`
for details), the number of axiom generated per initial axiom is
linear in the size of that initial axiom.
.. why3:transform:: split_premise_full
Behave similarly to :why3:transform:`split_premise`, but also convert the axioms to
conjunctive normal form. The number of axioms generated per initial
axiom may be exponential in the size of the initial axiom.
.. why3:transform:: subst
Substitute a given constant using an equality found in the context.
The constant is removed.
For example, when applying ``subst x`` on the following goal
.. code-block:: whyml
constant x : int
constant y : int
constant z : int
axiom h : x = y + 1
axiom h1 : z = (x + y)
goal G : x = z
the transformation first finds the hypothesis ``h`` that can be used to
rewrite ``x``. Then, it replaces every occurrences of ``x`` with ``y + 1``.
Finally, it removes ``h`` and ``x``. The resulting goal is as follows:
.. code-block:: whyml
constant y : int
constant z : int
axiom h1 : z = ((y + 1) + y)
goal G : (y + 1) = z
This transformation is used to make the task more easily readable by
a human during debugging. This transformation should not help
automatic provers at all as they generally implement substitution
rules in their logic.
.. why3:transform:: subst_all
Substitute all the variables that can be substituted.
For example, applying ``subst_all`` on the following goal
.. code-block:: whyml
constant x : int
constant x1 : int
constant y : int
constant z : int
axiom h : x = (y + 1)
axiom hx1 : x = x1
axiom h1 : z = (x + y)
goal G : x = z
produces the following goal, where ``x``, ``x1``, and ``z`` have been
removed:
.. code-block:: whyml
constant y : int
goal G : (y + 1) = ((y + 1) + y)
The order in which constants are substituted is not specified.
.. why3:transform:: unfold
Unfold the definition of a logical symbol in the given hypothesis.
For example, applying ``unfold p`` on the following goal
.. code-block:: whyml
predicate p (x:int) = x <= 22
axiom h : forall x:int. p x -> p (x - 1)
goal G : p 21
produces the following goal:
.. code-block:: whyml
predicate p (x:int) = x <= 22
axiom h : forall x:int. p x -> p (x - 1)
goal G : 21 <= 22
One can also unfold in the hypothesis, using ``unfold p in h``, which
gives the following goal:
.. code-block:: whyml
predicate p (x:int) = x <= 22
axiom h : forall x:int. x <= 22 -> (x - 1) <= 22
goal G : 21 <= 22
.. why3:transform:: use_th
Import a theory inside the current context. This is used, in some rare
case, to reduced the size of the context in other goals, since
importing a theory in the WhyML code would the theory available in all
goals whereas the theory is only needed in one specific goal.
For example, applying ``use_th int.Int`` on the following goal
.. code-block:: whyml
predicate p int
goal G : p 5
imports the ``Int`` theory. So, one is able to use the addition over
integers, e.g., ``replace 5 (2 + 3)``.
Any lemma appearing in the imported theory can also be used.
Note that axioms are also imported. So, this transformation should be
used with care. We recommend to use only theories that do not contain
any axiom because this transformation could easily make the context
inconsistent.
.. _sec.strategies:
Proof Strategies
----------------
In the context of Why3, proof strategies are mechanisms that automate
the application of transformations and provers on proof tasks. These
strategies are mainly meant to be invoked in the IDE.
Strategies come into two flavours: first the so-called basic
strategies, and second a more complex mechanism allowing one to
program strategies in OCaml. Such strategies are supposed to be
programmed on top of the module `Strategy` of the Why3 API. Such
strategies can also by called goal-oriented, since programming them in
OCaml provides a way to inspect the formulas in the goal or hypothesis of the task, and apply
transformations depending on their shapes.
Below we document one of such strategy: a strategy for error
propagation in floating-point computations.
Basic Strategies
~~~~~~~~~~~~~~~~
As seen in :numref:`sec.ideref`, the IDE provides a few buttons that
trigger the run of basic proof strategies on the selected goals. Such proof
strategies can be defined using a basic assembly-style language, and put
into the Why3 configuration file. The commands of this basic language
are:
- :samp:`c {p} {t} {m}` calls the prover *p* with a time limit *t*
and memory limit *m*. On success, the strategy ends, it
continues to next line otherwise.
- :samp:`c {p1} {t1} {m1} | ... | {pk} {tk} {mk}` calls the provers *p1* to *pk* in parallel.
On success on one prover, the other provers are interrupted, and the strategy ends. It
continues to next line if none of the provers succeed.
- :samp:`t {n} {lab}` applies the transformation *n*. On success, the
strategy continues to label *lab*, and is applied to each
generated sub-goals. It continues to next line otherwise.
- :samp:`g {lab}` unconditionally jumps to label *lab*.
- :samp:`{lab}:` declares the label *lab*. The default label ``exit``
stops the program.
To exemplify this basic programming language, we give below the default
strategies that are attached to the default buttons of the IDE, assuming
that the provers Alt-Ergo 2.3.0, CVC4 1.7, and Z3 4.8.4 have been detected by
the :why3:tool:`why3 config` command.
Split_VC
is bound to the 1-line strategy
::
t split_vc exit
Auto_level_0
is bound to
::
c Z3,4.8.4, 1 1000
c Alt-Ergo,2.3.0, 1 1000
c CVC4,1.7, 1 1000
The three provers are tried for a time limit of 1 second and memory
limit of 1 Gb, each in turn. This is a perfect strategy for a first
attempt to discharge a new goal.
Auto_level_1
is bound to
::
c Z3,4.8.4, 5 1000 | Alt-Ergo,2.3.0, 5 1000 | CVC4,1.7, 5 1000
Same as Auto_level_0 but with 5 seconds instead of 1, and in parallel.
Auto_level_2
is bound to
::
start:
c Z3,4.8.4, 1 1000
c Alt-Ergo,2.3.0, 1 1000
c CVC4,1.7, 1 1000
t split_vc start
c Z3,4.8.4, 10 4000 | Alt-Ergo,2.3.0, 10 4000 | CVC4,1.7, 10 4000
The three provers are first tried for a time limit of 1 second and
memory limit of 1 Gb, each in turn. If none of them succeed, a split
is attempted. If the split works then the same strategy is retried
on each sub-goals. If the split does not succeed, the provers are
tried again with larger limits, and in parallel.
Auto_level_3
is bound to
::
start:
c Z3,4.8.4, 1 1000
c Eprover,2.0, 1 1000
c Spass,3.7, 1 1000
c Alt-Ergo,2.3.0, 1 1000
c CVC4,1.7, 1 1000
t split_vc start
c Z3,4.8.4, 5 2000 | Eprover,2.0, 5 2000 | Spass,3.7, 5 2000 | Alt-Ergo,2.3.0, 5 2000 | CVC4,1.7, 5 2000
t introduce_premises afterintro
afterintro:
t inline_goal afterinline
g trylongertime
afterinline:
t split_all_full start
trylongertime:
c Z3,4.8.4, 30 4000 | Eprover,2.0, 30 4000 | Spass,3.7, 30 4000 | Alt-Ergo,2.3.0, 30 4000 | CVC4,1.7, 30 4000
Notice that now 5 provers are used. The provers are first tried
for a time limit of 1 second and memory limit of 1 Gb, each in
turn. If none of them succeed, a split is attempted. If the split
works then the same strategy is retried on each sub-goals. If the
split does not succeed, the prover are tried again with limits of
5 s and 2 Gb, and in parallel. If all fail, we attempt the
transformation of introduction of premises in the context,
followed by an inlining of the definitions in the goals. We then
attempt a split again. If the split succeeds, we restart from the
beginning. Otherwise, provers are tried again, in parallel, with 30s and 4
Gb.
Forward propagation in floating-point computations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The specialized strategy ``forward_propagation`` can be used for
automatically computing and proving a rounding error on a term of type
``ufloat`` which is the type of unbounded floats as defined in the
theory `ufloat` of the standard library. More background on
forward error propagation will be available soon in an incoming research report.
The only transformations used are :
- ``assert``, to assert the existence of a forward error.
- ``apply``, to apply one of the forward propagation lemmas.
The strategy uses the following process:
1. Look at the form of the goal. If the goal has the form
``abs (to_real x -. exact_x) <=. C``, it goes to step 2, else it does nothing.
2. Look at term ``x``. There are 2 cases :
* 2.1. : ``x`` is either the result of a supported ufloat operation
(e.g. addition, multiplication) on some arguments or
the result of the application of an approximation of a supported
function (e.g. exponential) to some arguments. Then the strategy
applies recursively step 2 for each argument of the ufloat
operation/function approximation to compute their forward
error. For each forward error computed, the strategy also
generates a proof tree containing the steps to prove it. If at
least one forward error is computed, then the propagation lemma
corresponding to the ufloat operation/approximated function is
used to compute the forward error for ``x`` and ``exact_x``, and a corresponding
proof tree is generated. The root of the proof tree consists of an
assertion of the forward error computed for ``x``, and the child
node will generally be the application of the transformation
``apply`` with the propagation lemma as an argument. The
propagation lemma contains hypotheses about forward errors for the
arguments, therefore the proof trees computed for them recursively
are attached as nodes to the corresponding nodes of the tree.
* 2.2. : ``x`` is something else. Then no forward error is computed
and no proof tree is generated.
Currently, propagation lemmas exist for the following functions :
* ufloat addition, subtraction, multiplication and negation.
* ufloat approximations of ``log`` and ``exp`` functions.
* ufloat approximations of the iterated sum function (defined in stdlib module ``real.Sum``).
The following excerpt is an example of a program that can be proved using the strategy :
::
use real.RealInfix
use real.Abs
use ufloat.USingle
let ghost addition_errors_basic (a b c : usingle)
ensures {
let exact = to_real a +. to_real b +. to_real c in
let exact_abs = abs (to_real a) +. abs (to_real b) +. abs (to_real c) in
abs (to_real result -. exact) <=. 2. *. eps *. exact_abs
}
= a ++. b ++. c
To use the strategy within Why3 IDE in order to prove the program, one
must perform the following steps :
1. Apply the ``split_vc`` transformation to generate the subgoals.
2. Select the proof node of the postcondition and apply the
``forward_propagation`` strategy, either by typing the name of the
strategy in the command line or by right clicking on the proof node
and selecting the strategy.
3. The strategy will generate a proof tree. The nodes of the tree
should be easily proved using one of the ``auto`` strategies.
Note that the ``forward_propagation`` strategy can also be used when
the user has no specific forward error in mind as a way to propose a
provable bound. For instance in the example above, one could have
replaced the term ``2. *. eps *. exact_abs`` by anything in the
postcondition. The strategy would still have worked and it would have
generated an assertion about a forward error that it can prove. One
could then use this forward error in the postcondition.
For more examples of the use of the strategy, see the directory
``examples/numeric`` of the examples repository.
.. _sec.attributes:
WhyML Attributes
----------------
.. why3:attribute:: case_split
.. why3:attribute:: cfg:stackify
.. why3:attribute:: cfg:subregion_analysis
.. why3:attribute:: extraction:inline
If the name of a function is labeled with this attribute, its body
will be inlined at every call site during extraction (see
:numref:`sec.extract`). This is especially useful for trivial
wrapper functions whose only purpose is to provide a slightly
different specification from the original function.
.. why3:attribute:: extraction:likely
This attribute can be applied to a Boolean expression to indicate
whether it is likely to be true. This is used at extraction time
(see :numref:`sec.extract`), assuming the target language supports
it. For example, when extracting to C, the extracted expression
will be tagged with ``__builtin_expect``.
.. why3:attribute:: extraction:unlikely
This attribute can be applied to a Boolean expression to indicate
whether it is likely to be false. This is the opposite of
:why3:attribute:`extraction:likely`.
.. why3:attribute:: extraction:preserve_single_field
This attribute is applied to the declaration of a record type. It is used to
disable an optimization made by the preprocessing step that precedes the
invocation of extraction drivers. During this step, record types with a
single field like:
.. code-block:: whyml
type t = { a : int }
are rewritten as:
.. code-block:: whyml
type t = int
If this attribute is applied to ``t``, then this optimization is disabled.
.. why3:attribute:: induction
.. why3:attribute:: infer
.. why3:attribute:: inline:trivial
.. why3:attribute:: java:class_kind:
This attribute annotates a module. Three suffixes are allowed:
:code:`abstract`, :code:`interface` and :code:`class`. This three attributes
specify what kind of class the Java driver has to generate for the module,
either a regular or an abstract class or an interface.
.. why3:attribute:: java:constructor
This attribute is used to mark functions
.. why3:attribute:: java:exception:
If a module is annotated with the attribute
:why3:attribute:`java:exception:` *exn-class*, the Java driver translates it
into a Java exception class. The `exn-class` part of the attribute indicates
the parent class from which the generated class inherits. Actually `exn-class`
is printed out `as-is` after the `extends` specifier of the generated class.
.. why3:attribute:: java:implements:
This attribute is applied to a module. Its suffix is a coma-separated list of
identifiers of Java interfaces. From the driver point of view, the specified
interfaces are just strings of characters and are printed out `as-is` in the
generated Java code. The driver does not check if theses interfaces are
actually implemented by the module; this verification is left to the Java
compiler.
.. why3:attribute:: java:package:
If the attribute :why3:attribute:`java:package:` *some.package* annotates a module,
the Java driver creates the expected class in the package *some.package*. In
addition to the Java instruction :code:`package`, the driver follows the usual
convention by creating the :code:`.java` file in the directory
:file:`some/package/`. The directory of the package is created
relatively to the output directory specified with the option :code:`-o` (see
:ref:`sec.why3extract`).
.. why3:attribute:: java:visibility:public
.. why3:attribute:: java:visibility:package
.. why3:attribute:: java:visibility:private
By default, in the code generated by the Java driver, classes, instance
variables and methods are declared :code:`public`. The driver allows three
attributes to change this default visibility: :code:`public`,
:code:`private` and :code:`package`. Note that
visibility attributes **are not checked** by the driver.
If :why3:attribute:`java:visibility:private` is used to annotate a module, the
generated class is declared :code:`private`. Even if it is syntactically
allowed, the specification of Java language does not allow private specifier
for top-level classes.
By default, functions and types inherit the visibility attribute of the
module. For instance if a module is declared with
:why3:attribute:`java:visibility:package` then all functions, instance
variables and *Enum*-types will be declared with :code:`package` visibility.
Each element of the module can be annotated with a different visibility
attribute that replaces the default one.
Instance variables actually inherits the visibility attribute of the type that
defines them. Yet, each instance variable may have its own visibility
attribute.
.. why3:attribute:: model_trace
.. why3:attribute:: rewrite
.. why3:attribute:: stop_split
.. why3:attribute:: vc:annotation
This attribute is added by the VC generator, on the user input
formulas which become goals to prove in the resulting VC. It should
not be added manually.
.. why3:attribute:: vc:divergent
This attribute indicates whether VCs for termination should be
generated. See :numref:`sec.terminationvc` for details.
.. why3:attribute:: vc:keep_precondition
This attribute indicates whether preconditions of calls should be kept
as assumptions for the program after the call. See
:numref:`sec.keeppreconditions` for details.
.. why3:attribute:: vc:sp
This attribute, put on a WhyML expression, locally switches the VC
generator to the SP mode, for that expression. See
:numref:`sec.strongestpostconditions` for details.
.. why3:attribute:: vc:white_box
This attribute is added by the Why3 parser for contract attached to
an expression in WhyML code. Such a contract is indeed encoded by a
local function with this attribute. It is for internal use only
and should never be added manually.
.. why3:attribute:: vc:wp
This attribute, put on a WhyML expression, locally switches the VC
generator to the WP mode, for that expression. See
:numref:`sec.strongestpostconditions` for details.
.. _sec.metas:
Why3 Metas
----------
.. why3:meta:: compute_max_steps
.. why3:meta:: keep:literal
.. why3:meta:: realized_theory
.. why3:meta:: rewrite
.. why3:meta:: rewrite_def
.. why3:meta:: vc:proved_wf
Declare a hypothesis as a proof of well-foundedness of a binary
relation. See :numref:`sec.custom_wf`.
.. _sec.debug:
Debug Flags
-----------
The list of debug flags can be obtained using
:file:`why3 --list-debug-flags`. The following excerpt is the
list of flags mentioned in this manual.
.. why3:debug:: infer:loop
.. why3:debug:: infer:print_ai_result
.. why3:debug:: infer:print_cfg
.. why3:debug:: print:inferred_invs
.. why3:debug:: print:domains_loop
.. why3:debug:: stack_trace
Structure of Session Files
--------------------------
The proof session state is stored in an XML file named
:file:`{dir}/why3session.xml`, where *dir* is the directory of the
project. The XML file follows the DTD given in :file:`share/why3session.dtd`
and reproduced below.
.. literalinclude:: ../share/why3session.dtd
:language: dtd
.. _sec.jsonce:
Structure of Counterexamples
----------------------------
Generated counterexamples can be exported in JSON format.
The JSON output follows the JSON Schema given in :file:`share/ce-models.json`
and reproduced below.
.. literalinclude:: ../share/ce-models.json
:language: json
Developer Documentation
-----------------------
Updating messages for syntax errors
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Here is the developer's recipe to update a syntax error message. We do
it on the following illustrative example.
.. code-block:: whyml
function let int : int
If such a file is passed to Why3, one obtains:
::
File "bench/parsing/bad/498_function.mlw", line 1, characters 9-12:
syntax error
The recipe given here provides a way to produce a more informative
message. It is based on handcrafted error messages provided by the
`Menhir <http://gallium.inria.fr/~fpottier/menhir/>`_ parser generator.
The first step is to call :program:`menhir` with option ``--interpret-error``
while giving as input the erroneous input, under the form of a sequence
of tokens as generated by :file:`src/parser/lexer.mll`.
.. code-block:: console
$ echo "decl_eof: FUNCTION LET" | menhir --base src/parser/parser --interpret-error src/parser/parser_common.mly src/parser/parser.mly
decl_eof: FUNCTION LET
##
## Ends in an error in state: 1113.
##
## 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 ]
##
## The known suffix of the stack is as follows:
## FUNCTION
##
<YOUR SYNTAX ERROR MESSAGE HERE>
The text returned by that command should be appended to
:file:`src/parser/handcrafted.messages`, with of course an appropriate error
message, such as this one:
::
expected function name must be a non-reserved uncapitalized identifier (token LIDENT_NQ), found "$0"
|