Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

calin1304
Copy link

@calin1304 calin1304 commented Sep 29, 2021

Added some claims I came up with as an exercise

  1. For any X, Y equal integers, X - Y = 0.
  2. For any X, Y integers, maximum of X and Y is greater than or equal to X and to Y
  3. The sum of even integers is even.

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]
Copy link
Member

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.

Copy link
Member

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

Copy link
Member

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)

Comment on lines 29 to 31
requires
#inUnsignedRange(ITYPE, X) andBool
#inUnsignedRange(ITYPE, Y)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
requires
#inUnsignedRange(ITYPE, X) andBool
#inUnsignedRange(ITYPE, Y)
requires #inUnsignedRange(ITYPE, X)
andBool #inUnsignedRange(ITYPE, Y)

@@ -0,0 +1,56 @@
requires "kwasm-lemmas.md"
Copy link
Member

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.

@calin1304 calin1304 marked this pull request as ready for review October 11, 2021 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants