Skip to content

Commit f7fe161

Browse files
1 parent b04e7f8 commit f7fe161

14 files changed

Lines changed: 451 additions & 6 deletions

File tree

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
2+
========================================================================
3+
Tactic: `cfold`
4+
========================================================================
5+
6+
The `cfold` tactic is part of the family of tactics that operate by
7+
rewriting the program into a semantically equivalent form.
8+
More concretely, given an assignment of the form::
9+
10+
a <- b;
11+
12+
the tactic propagates this (known) values of a through the program
13+
and inlining this (known) value whenever `a` would be used.
14+
15+
For example, the following excerpt::
16+
17+
a <- 3;
18+
c <- a + 1;
19+
a <- a + 2;
20+
b <- a;
21+
22+
would be converted into::
23+
24+
c <- 4; (* 3 + 1 *)
25+
b <- 5; (* a = 3 + 2 = 5 at this point *)
26+
a <- 5; (* we need to make sure a has the
27+
correct value at the end of execution *)
28+
29+
.. contents::
30+
:local:
31+
32+
------------------------------------------------------------------------
33+
Syntax
34+
------------------------------------------------------------------------
35+
36+
The general form of the tactic is:
37+
38+
.. admonition:: Syntax
39+
40+
`cfold {side}? {codepos} {n}?`
41+
42+
Where:
43+
44+
- `{side}` is optional and only applicable in relational goals
45+
to specify on which of the two programs the tactic is to be applied.
46+
47+
- `{codepos}` specifies the instruction on which the tactic will begin.
48+
The tactic will proceed to propagate the assignment as far as possible,
49+
even through other assignments to the same variable as long as it can or
50+
until it reaches the line limit (if given).
51+
52+
- `{n}` is an optional integer argument corresponding to the number of
53+
lines of the program to process in the folding. This serves to limit the
54+
scope of the tactic application and prevent it from acting in the whole
55+
program when this would not be desirable.
56+
57+
.. ecproof::
58+
:title: Cfold example
59+
60+
require import AllCore.
61+
62+
module M = {
63+
proc f(a : int) = {
64+
var x, y : int;
65+
66+
x <- a + 1;
67+
y <- 2 * x;
68+
x <- 3 * y;
69+
70+
return x;
71+
}
72+
}.
73+
74+
lemma L : hoare[M.f : witness a ==> witness res].
75+
proof.
76+
proc.
77+
(*$*) cfold 1.
78+
79+
(* The goal is the same but the program is now rewritten *)
80+
admit.
81+
qed.
82+
83+
84+
The propagated variable is then set at the end of the part of the program
85+
where the tactic was applied (in this case, the end of the program, since
86+
the tactic applied to its entirety), and it is set to the value which the
87+
tactic accumulated.
88+
89+
Here is an example of using the parameter `{n}` for limiting tactic
90+
application:
91+
92+
.. ecproof::
93+
:title: Cfold line restriction
94+
95+
require import AllCore.
96+
97+
module M = {
98+
proc f() = {
99+
var x, y : int;
100+
var i : int;
101+
102+
i <- 0;
103+
104+
while (i < 10) {
105+
x <- i + 1;
106+
y <- 2 * x;
107+
x <- 3 * y;
108+
i <- i + 1;
109+
}
110+
111+
return x;
112+
}
113+
}.
114+
115+
lemma L : hoare[M.f : witness ==> witness res].
116+
proof.
117+
proc.
118+
119+
unroll for 2.
120+
(*$*) cfold 1 27.
121+
(* The goal is the same but the program is now rewritten *)
122+
admit.
123+
qed.

refman/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ <h1>EasyCrypt reference manual<a class="headerlink" href="#easycrypt-reference-m
7979
<div class="toctree-wrapper compound">
8080
<ul>
8181
<li class="toctree-l1"><a class="reference internal" href="tactics.html">Proof tactics reference</a><ul>
82+
<li class="toctree-l2"><a class="reference internal" href="tactics/cfold.html">Tactic: <code class="code highlight easycrypt docutils literal highlight-easycrypt"><span class="kr">cfold</span></code></a></li>
8283
<li class="toctree-l2"><a class="reference internal" href="tactics/clear.html">Tactic: <code class="code highlight easycrypt docutils literal highlight-easycrypt"><span class="kr">clear</span></code></a></li>
8384
<li class="toctree-l2"><a class="reference internal" href="tactics/hoare-split.html">Tactic: <code class="code highlight easycrypt docutils literal highlight-easycrypt"><span class="kr">hoare</span><span class="w"> </span><span class="kr">split</span></code></a></li>
8485
<li class="toctree-l2"><a class="reference internal" href="tactics/if.html">Tactic: <code class="docutils literal notranslate"><span class="pre">if</span></code></a></li>

refman/objects.inv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# Project: EasyCrypt refman
33
# Version:
44
# The remainder of this file is compressed using zlib.
5-
xڅ��N� ��<��L���^�&��/�0�DZ�Y����7��|�f�E, ~�u�,�H<��1������#*mLQ�Tu����U;l������r#͊u�uȅ���MB����38B����=��?<������'T�g�eu�Z� X �N�Yt��~!#�t��gJ�F)�Q��읨��:v,Č���vsR��`���W�6%p(�Y��"oM�Q��=��V�����o����c����'E�Ob�pOޫ��bET����26�~��7P
5+
xڅ��N� ��<��L���^�&��/0�P��4�f��[J)�`�5����@�qT#��<?k�BM��o�Y�A���Ir7,4:��ͯv�<�(��Ȑ0�@���ƀi�R!&|~Ӹ���a΃�<0�X�F�N�i�����4�'r�������e�#��5�/�#��9�̆�|k�H(�O�NL�v,Čt�eS/k4�P�̀vS�عI+���2e-е�g)ъP�4� ��R/�@H���R��P������r/�@�{�jy-y�Vي(�ݡ��«���_6VK�

refman/searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

refman/tactics.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<script src="_static/js/theme.js"></script>
2525
<link rel="index" title="Index" href="genindex.html" />
2626
<link rel="search" title="Search" href="search.html" />
27-
<link rel="next" title="Tactic: clear" href="tactics/clear.html" />
27+
<link rel="next" title="Tactic: cfold" href="tactics/cfold.html" />
2828
<link rel="prev" title="EasyCrypt reference manual" href="index.html" />
2929
</head>
3030

@@ -49,6 +49,7 @@
4949
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
5050
<ul class="current">
5151
<li class="toctree-l1 current"><a class="current reference internal" href="#">Proof tactics reference</a><ul>
52+
<li class="toctree-l2"><a class="reference internal" href="tactics/cfold.html">Tactic: <code class="code highlight easycrypt docutils literal highlight-easycrypt"><span class="kr">cfold</span></code></a></li>
5253
<li class="toctree-l2"><a class="reference internal" href="tactics/clear.html">Tactic: <code class="code highlight easycrypt docutils literal highlight-easycrypt"><span class="kr">clear</span></code></a></li>
5354
<li class="toctree-l2"><a class="reference internal" href="tactics/hoare-split.html">Tactic: <code class="code highlight easycrypt docutils literal highlight-easycrypt"><span class="kr">hoare</span><span class="w"> </span><span class="kr">split</span></code></a></li>
5455
<li class="toctree-l2"><a class="reference internal" href="tactics/if.html">Tactic: <code class="docutils literal notranslate"><span class="pre">if</span></code></a></li>
@@ -89,6 +90,7 @@
8990
<h1>Proof tactics reference<a class="headerlink" href="#proof-tactics-reference" title="Link to this heading"></a></h1>
9091
<div class="toctree-wrapper compound">
9192
<ul>
93+
<li class="toctree-l1"><a class="reference internal" href="tactics/cfold.html">Tactic: <code class="code highlight easycrypt docutils literal highlight-easycrypt"><span class="kr">cfold</span></code></a></li>
9294
<li class="toctree-l1"><a class="reference internal" href="tactics/clear.html">Tactic: <code class="code highlight easycrypt docutils literal highlight-easycrypt"><span class="kr">clear</span></code></a></li>
9395
<li class="toctree-l1"><a class="reference internal" href="tactics/hoare-split.html">Tactic: <code class="code highlight easycrypt docutils literal highlight-easycrypt"><span class="kr">hoare</span><span class="w"> </span><span class="kr">split</span></code></a></li>
9496
<li class="toctree-l1"><a class="reference internal" href="tactics/if.html">Tactic: <code class="docutils literal notranslate"><span class="pre">if</span></code></a></li>
@@ -106,7 +108,7 @@ <h1>Proof tactics reference<a class="headerlink" href="#proof-tactics-reference"
106108
</div>
107109
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
108110
<a href="index.html" class="btn btn-neutral float-left" title="EasyCrypt reference manual" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
109-
<a href="tactics/clear.html" class="btn btn-neutral float-right" title="Tactic: clear" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
111+
<a href="tactics/cfold.html" class="btn btn-neutral float-right" title="Tactic: cfold" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
110112
</div>
111113

112114
<hr/>

0 commit comments

Comments
 (0)