-
Notifications
You must be signed in to change notification settings - Fork 24
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
Add some simple proofs #437
base: master
Are you sure you want to change the base?
Changes from 1 commit
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,59 @@ | ||
requires "kwasm-lemmas.md" | ||
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. For
and see if this works on Ana's branch. Make sure to check the defniition of |
||
|
||
module SIMPLE-SPEC | ||
imports KWASM-LEMMAS | ||
|
||
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. Write a functional spec:
|
||
// forall X Y : Nat, X = Y -> X - Y = 0 | ||
claim | ||
<instrs> | ||
ITYPE:IValType . const X ~> | ||
ITYPE:IValType . const Y ~> | ||
ITYPE:IValType . sub | ||
=> . | ||
... | ||
</instrs> | ||
<valstack> S => < ITYPE > 0 : S </valstack> | ||
requires #inUnsignedRange(ITYPE, X) andBool X ==Int Y | ||
|
||
// forall X Y : Nat, X <= max X Y && Y <= max X Y | ||
claim | ||
<instrs> | ||
ITYPE:IValType . const X ~> | ||
ITYPE:IValType . const Y ~> | ||
ITYPE:IValType . sub ~> | ||
ITYPE:IValType . const 0 ~> | ||
ITYPE:IValType . ge_s ~> | ||
#if([ITYPE:IValType .ValTypes], ITYPE:IValType.const X, ITYPE:IValType.const Y, _) | ||
=> . | ||
... | ||
</instrs> | ||
<valstack> S => < ITYPE > ?MAX : S </valstack> | ||
requires | ||
#inUnsignedRange(ITYPE, X) andBool | ||
#inUnsignedRange(ITYPE, Y) andBool | ||
#inUnsignedRange(ITYPE, X -Int Y) | ||
ensures | ||
#inUnsignedRange(ITYPE, ?MAX) andBool | ||
X <=Int ?MAX andBool | ||
Y <=Int ?MAX | ||
|
||
// forall X Y : Nat, even X -> even Y -> even (X + Y) | ||
claim | ||
<instrs> | ||
ITYPE:IValType . const X:Int ~> | ||
ITYPE:IValType . const Y:Int ~> | ||
ITYPE . add => . | ||
... | ||
</instrs> | ||
<valstack> S:ValStack => < ITYPE > Z : S </valstack> | ||
requires | ||
0 <=Int X andBool | ||
0 <=Int Y andBool | ||
0 <=Int Z andBool | ||
Z ==Int (X +Int Y) andBool | ||
Z <Int #pow(ITYPE) andBool | ||
X modInt 2 ==Int 0 andBool | ||
Y modInt 2 ==Int 0 | ||
ensures | ||
Z modInt 2 ==Int 0 | ||
endmodule |
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.
This isn't true. Consider the definition of
#signed
(indata.md
)So if we have that
notBool (0 <=Int X -Int Y andBool X - Int Y <Int #pow1(ITYPE))
, and we also have that#pow1(ITYPE) <=Int X -Int Y andBool X -Int Y <Int #pow(ITYPE)
, we should be returning(X -Int Y) -Int #pow(ITYPE)
, but your simplification rule returnsX -Int Y
.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.
You can add a requires clause to your second rule which says
0 <=Int X -Int Y andBool X -Int Y <Int #pow1(ITYPE)
, but that would be saying the same thing as the original rule in the semantics.So instead, we should make it so the prover can know that
0 <=Int X -Int Y andBool X -Int Y <Int #pow1(ITYPE)
is true. Which proof is this lemma needed for?