-
Notifications
You must be signed in to change notification settings - Fork 23
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?
Conversation
kwasm-lemmas.md
Outdated
@@ -21,6 +21,11 @@ Basic logic | |||
Basic arithmetic | |||
---------------- | |||
|
|||
```k | |||
rule #signed(_, 0) => 0 [simplification] | |||
rule #signed(_, X -Int Y) => X -Int Y [simplification] |
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
(in data.md
)
rule #signed(ITYPE, N) => N requires 0 <=Int N andBool N <Int #pow1(ITYPE)
rule #signed(ITYPE, N) => N -Int #pow(ITYPE) requires #pow1(ITYPE) <=Int N andBool N <Int #pow (ITYPE)
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 returns X -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?
|
||
module SIMPLE-SPEC | ||
imports KWASM-LEMMAS | ||
|
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.
Write a functional spec:
claim <instrs> run(#signed(ITYPE, X -Int Y)) => done(X -Int Y) ... </k> requires #inUnsignedRange(ITYPE, X -Int Y)
tests/proofs/simple-spec.k
Outdated
requires | ||
#inUnsignedRange(ITYPE, X) andBool | ||
#inUnsignedRange(ITYPE, 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.
requires | |
#inUnsignedRange(ITYPE, X) andBool | |
#inUnsignedRange(ITYPE, Y) | |
requires #inUnsignedRange(ITYPE, X) | |
andBool #inUnsignedRange(ITYPE, Y) |
@@ -0,0 +1,56 @@ | |||
requires "kwasm-lemmas.md" |
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.
For #signed(ITYPE, 0)
, it probably can't tell that 0 <Int #pow1(ITYPE)
, even though ITYPE
can only be i32
or i64
.
rule 0 <Int #pow1(_) => true [simplification]
and see if this works on Ana's branch.
Make sure to check the defniition of #pow1
and make sure this is true.
Added some claims I came up with as an exercise