Guest User

Untitled

a guest
May 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. method toArrayConvert(s:seq<int>) returns(a:array<int>)
  2. requires |s|>0;
  3. ensures |s| == a.Length;
  4. ensures multiset(s[..]) == multiset(old(s[..]))
  5. ensures forall i::0<=i<a.Length ==> s[i] == a[i]; //This is the postcondition that might not hold.
  6. {
  7. a :=new int[|s|];
  8. var i:int :=0;
  9. while i<|s|
  10. decreases |s| - i;
  11. invariant 0<=i<=|s|;
  12. invariant perm(a,old(a));
  13. {
  14. a[i]:=s[i];
  15. i:=i+1;
  16. }
  17. return a; //A postcondition might not hold on this return path.
  18. }
Add Comment
Please, Sign In to add comment