-
Notifications
You must be signed in to change notification settings - Fork 61
PR: Allow symbolic assignments for cfold #892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Gustavo2622
wants to merge
1
commit into
main
Choose a base branch
from
improvement_symbolic_cfold
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+163
−17
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
|
|
||
| ======================================================================== | ||
| Tactic: `cfold` | ||
| ======================================================================== | ||
|
|
||
| The `cfold`` tactic is part of the family of tactics that operate by | ||
| rewriting the program into a semantically equivalent form. | ||
| More concretely, given an assignment of the form:: | ||
|
|
||
| a <- b; | ||
|
|
||
| the tactic propagates this (known) values of a through the program | ||
| and inlining this (known) value whenever ``a`` would be used. | ||
|
|
||
| For example, the following excerpt:: | ||
|
|
||
| a <- 3; | ||
| c <- a + 1; | ||
| a <- a + 2; | ||
| b <- a; | ||
|
|
||
| would be converted into:: | ||
|
|
||
| c <- 4; (* 3 + 1 *) | ||
| b <- 5; (* a = 3 + 2 = 5 at this point *) | ||
| a <- 5; (* we need to make sure a has the | ||
| correct value at the end of execution *) | ||
|
|
||
| .. contents:: | ||
| :local: | ||
|
|
||
| ------------------------------------------------------------------------ | ||
| Syntax | ||
| ------------------------------------------------------------------------ | ||
|
|
||
| The general form of the tactic is: | ||
|
|
||
| .. admonition:: Syntax | ||
|
|
||
| ``cfold {side}? {codepos} {n}?`` | ||
|
|
||
| Where: | ||
|
|
||
| - ``{side}`` is optional and only applicable in relational goals | ||
| to specify on which of the two programs the tactic is to be applied. | ||
|
|
||
| - ``{codepos}`` specifies the instruction on which the tactic will begin. | ||
| The tactic will proceed to propagate the assignment as far as possible, | ||
| even through other assignments to the same variable as long as it can or | ||
| until it reaches the line limit (if given). | ||
|
|
||
| - ``{n}`` is an optional integer argument corresponding to the number of | ||
| lines of the program to process in the folding. This serves to limit the | ||
| scope of the tactic application and prevent it from acting in the whole | ||
| program when this would not be desirable. | ||
|
|
||
| .. ecproof:: | ||
| :title: Cfold example | ||
|
|
||
| require import AllCore. | ||
|
|
||
| module M = { | ||
| proc f(a : int) = { | ||
| var x, y : int; | ||
|
|
||
| x <- a + 1; | ||
| y <- 2 * x; | ||
| x <- 3 * y; | ||
|
|
||
| return x; | ||
| } | ||
| }. | ||
|
|
||
| lemma L : hoare[M.f : witness a ==> witness res]. | ||
| proof. | ||
| proc. | ||
| (*$*) cfold 1. | ||
|
|
||
| (* The goal is the same but the program is now rewritten *) | ||
| admit. | ||
| qed. | ||
|
|
||
|
|
||
| The propagated variable is then set at the end of the part of the program | ||
| where the tactic was applied (in this case, the end of the program, since | ||
| the tactic applied to its entirety), and it is set to the value which the | ||
| tactic accumulated. | ||
|
|
||
| Here is an example of using the parameter ``{n}`` for limiting tactic | ||
| application: | ||
|
|
||
| .. ecproof:: | ||
| :title: Cfold line restriction | ||
|
|
||
| require import AllCore. | ||
|
|
||
| module M = { | ||
| proc f() = { | ||
| var x, y : int; | ||
| var i : int; | ||
|
|
||
| i <- 0; | ||
|
|
||
| while (i < 10) { | ||
| x <- i + 1; | ||
| y <- 2 * x; | ||
| x <- 3 * y; | ||
| i <- i + 1; | ||
| } | ||
|
|
||
| return x; | ||
| } | ||
| }. | ||
|
|
||
| lemma L : hoare[M.f : witness ==> witness res]. | ||
| proof. | ||
| proc. | ||
|
|
||
| unroll for 2. | ||
| (*$*) cfold 1 27. | ||
| (* The goal is the same but the program is now rewritten *) | ||
| admit. | ||
| qed. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should use single backtick. (Fix all occurences)