Replies: 1 comment 3 replies
-
Why do you think your first version is incorrect and your second is not? What do you think of the error messages Dafny gives? Do you agree or disagree with them and why? Have you ran both programs, either in your mind or on your machine, with particular inputs (start with just |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
// Assuming the code below, I wrote this version, but the dafny doesn't complain about it, but the version where I start with s:= s + k; then k:= k + 1; gives an error!!!
//So I prove it with pen and paper!
//This code is correct iff (1) (2) (3) holds
// 1. the Hoare triple {Q} s:=0;k:=0 {Pinv}: holds : which TRUE √; and
// 2.
{Pinv ∧ k < n } k:= k + 1; s:= s + k; {Pinv} Also holds :
//This one doesn't hold; as at the end of the proof, it gives
//
s + k + 1 = (∑i|0<= i < k + 1 :i) ∧ (0 <= k + 1 <= n)
//
s = (∑i|0<= i < k :i) - 1 ∧ (0 <= k + 1 <= n)
// but start accumulating the value in s,
s:= s + k
; and then increment k,k:= k + 1
;// gives the right proof as follows
//
s + k = (∑i|0<= i < k + 1 :i) ∧ (0 <= k + 1 <= n)
//
s = (∑i|0<= i < k :i) ∧ (0 <= k + 1 <= n)
// which means that the Hoare triple holds
// 3. This one holds too
//
Pinv ∧ ⌝(k<n) => R
// I DON'T KNOW how Dafny works from the inside as I start experimenting with it, but it looks strange.
Dafny doesn't complain about this code (this is an incorrect, i think )
But it complains about this code (This is the correct one i think)
Beta Was this translation helpful? Give feedback.
All reactions