-
Notifications
You must be signed in to change notification settings - Fork 42
Additions to proof-libs needed for the GCD example #1757
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
base: main
Are you sure you want to change the base?
Conversation
dcfc5ea to
3158389
Compare
|
|
| val impl_u8__trailing_zeros: u8 -> shiftval U8 U32 | ||
| val impl_u16__trailing_zeros: u16 -> shiftval U16 U32 | ||
| val impl_u32__trailing_zeros: u32 -> shiftval U32 U32 | ||
| val impl_u64__trailing_zeros: u64 -> shiftval U64 U32 | ||
| val impl_u128__trailing_zeros: u128 -> shiftval U128 U32 | ||
| val impl_usize__trailing_zeros: usize -> shiftval USIZE U32 |
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 shiftval _ U32 is incorrect: 0u8 has 8 trailing zeros, but 8u32 doesn't fit in shiftval U8 U32.
Indeed, shiftval U8 U32 is defined as a number smaller than bits U8, which is 8.
So here, you can replace shiftval _ _ by (n:u32 {n <= bits U8})
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 meant using shiftval as a return type here, not the definition of shiftval)
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.
Thanks, good catch. Anyway, I'll have to do this differently in the Rust core models, I think.
| val shift_right_le (#t:inttype) (#t':inttype) | ||
| (a:int_t t) (b:shiftval t t'): | ||
| Lemma (requires (unsigned t \/ v a >= 0)) | ||
| (ensures (v (shift_right #t #t' a b) <= v a)) | ||
| [SMTPat (shift_right #t #t' a b)] |
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.
Is this lemma actually required?
It should really follow automatically from shift_right_lemma 🤔
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 looked into this some more. Here is what is missing from making it work via shift_right_lemma:
val div_le
(a:nat) (b:nat):
Lemma (requires (b > 0))
(ensures (a / b <= a))
[SMTPat (a / b)]
|
On the F* side, you could define: But not clear how this fits the Rust core models story, though. |
While working on verifying the GCD crate, I need to add these definitions and lemmas to the proof-libs.
An open question: Is there a way to generalize over all instances of
shift_right_trailing_zeros_nonzero_lemmaas I have managed to do forshift_right_le?And generally, I am not sure if we want these kinds of specific lemmas in the proof-libs.