Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Why3
why3
Commits
4850f8fb
Commit
4850f8fb
authored
Feb 10, 2014
by
Jean-Christophe Filliâtre
Browse files
remove_duplicate: slightly prettier code
parent
0ebb4d5f
Changes
1
Hide whitespace changes
Inline
Side-by-side
examples/remove_duplicate.mlw
View file @
4850f8fb
...
...
@@ -25,14 +25,13 @@ module RemoveDuplicateQuadratic
use import Spec
use import ref.Refint
let rec test_appears (ghost w:ref int) (v: 'a) (a: array 'a) (s: int) : bool
let rec test_appears (ghost w:
ref int) (v: 'a) (a: array 'a) (s: int) : bool
requires { 0 <= s <= length a }
ensures { result=true <-> appears v a s }
ensures { result=true -> 0 <= !w < s && a[!w] = v }
ensures
{ result=true -> 0 <= !w < s && a[!w] = v }
variant { s }
= s > 0 && if a[s-1] = v
then begin w := s - 1 ; true end
else test_appears w v a (s-1)
= s > 0 &&
if a[s-1] = v then begin w := s - 1; true end else test_appears w v a (s-1)
let remove_duplicate (a: array 'a) : int
ensures { 0 <= result <= length a }
...
...
@@ -41,7 +40,7 @@ module RemoveDuplicateQuadratic
= let n = length a in
let r = ref 0 in
let ghost from = make n 0 in
let ghost to_ = make n 0 in
let ghost to_
= make n 0 in
'L:
for i = 0 to n - 1 do
invariant { 0 <= !r <= i }
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment