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
c686623e
Commit
c686623e
authored
Jan 12, 2016
by
MARCHE Claude
Browse files
examples: linked list reversal, main function in_place_reverse resurected
parent
f9449113
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
examples/linked_list_rev.mlw
View file @
c686623e
...
...
@@ -166,6 +166,34 @@ module InPlaceRev
assert { list_seg l2 !next l2M null };
l1
let in_place_reverse (l:loc) (ghost lM:list loc) : loc
requires { list_seg l !next lM null }
ensures { list_seg result !next (reverse lM) null }
= 'Init:
let p = ref l in
let ghost pM = ref lM in
let r = ref null in
let ghost rM = ref (Nil : list loc) in
while !p <> null do
invariant { list_seg !p !next !pM null }
invariant { list_seg !r !next !rM null }
invariant { disjoint !pM !rM }
invariant { (reverse !pM) ++ !rM = reverse lM }
variant { !pM }
let n = get !next !p in
next := set !next !p !r;
assert { list_seg !r !next !rM null };
r := !p;
p := n;
match !pM with
| Nil -> absurd
| Cons h t -> rM := Cons h !rM; pM := t
end
done;
!r
end
(** Using sequences instead of lists *)
...
...
examples/linked_list_rev/why3session.xml
View file @
c686623e
This diff is collapsed.
Click to expand it.
examples/linked_list_rev/why3shapes.gz
View file @
c686623e
No preview for this file type
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