-
Notifications
You must be signed in to change notification settings - Fork 63
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
Rewriting SAW core vector folds #1811
Changes from all commits
5a8f2fd
d617daf
edc0dd5
0e10161
8f7d9c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
$SAW tupletest.saw |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module tupletest where | ||
|
||
foldFunction : [8] -> [16] -> [16] -> [8] | ||
foldFunction x y z = output.0 | ||
where | ||
output = foldl fnc (x, y, z) [0 .. 15] | ||
|
||
fnc : ([8], [16], [16]) -> [4] -> ([8], [16], [16]) | ||
fnc (x, y, z) i = returnTup | ||
where | ||
returnTup = (x ^ take y' ^ take z', y', z') | ||
y' = y <<< i | ||
z' = z >>> i | ||
|
||
foldFunction' : [8] -> [16] -> [16] -> [8] | ||
foldFunction' x y z = output.0 | ||
where | ||
output = foldl fnc' (x, y, z) [15, 14 .. 0] | ||
|
||
fnc' : ([8], [16], [16]) -> [4] -> ([8], [16], [16]) | ||
fnc' (x, y, z) i = returnTup | ||
where | ||
returnTup = (x ^ take y ^ take z, y', z') | ||
y' = y >>> i | ||
z' = z <<< i | ||
|
||
property foldFunctionInverse x y z = | ||
foldFunction' (foldFunction x y z) y z == x |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
enable_experimental; | ||
|
||
let use_lemmas lemmas = | ||
simplify (addsimps lemmas | ||
(add_prelude_eqs ["foldl_cons","foldl_nil","head_gen","tail_gen"] (cryptol_ss()))); | ||
|
||
let proveit p script = | ||
do { | ||
print (str_concat "Proving " (show_term p)); | ||
time (prove_print script p); | ||
}; | ||
|
||
import "tupletest.cry"; | ||
|
||
fnc_lemma <- proveit {{ \x y z i -> (fnc' (fnc (x, y, z) i) i).0 == x }} z3; | ||
|
||
proveit {{ foldFunctionInverse }} do { | ||
unfolding [ "foldFunctionInverse" | ||
, "foldFunction" | ||
, "foldFunction'" | ||
]; | ||
goal_normalize ["fnc", "fnc'"]; | ||
simplify (add_prelude_eqs ["foldl_cons","foldl_nil", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you mean to use Also, this script would be more convincing if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, that it would be a better example if we could figure out a way to use
So There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The purpose of this example for now is to demonstrate rewriting folds, and it does that. So I'm going to merge this PR now. I'd love to figure out the "right" way to write this lemma, but let's not wait on that before merging this PR. |
||
"head_gen","tail_gen"] (cryptol_ss())); | ||
z3; | ||
}; |
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.
I think this is redundant,
goal_normalize ["fnc", "fnc'"];
should do this as well.