Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Why3
why3
Commits
bebc04f4
Commit
bebc04f4
authored
Sep 25, 2013
by
Jean-Christophe Filliâtre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
maximum_subarray: proof of algo 2
parent
84129ca3
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
541 additions
and
3 deletions
+541
-3
examples/in_progress/maximum_subarray.mlw
examples/in_progress/maximum_subarray.mlw
+34
-0
examples/in_progress/maximum_subarray/why3session.xml
examples/in_progress/maximum_subarray/why3session.xml
+507
-3
No files found.
examples/in_progress/maximum_subarray.mlw
View file @
bebc04f4
...
...
@@ -53,3 +53,37 @@ module Algo1
end
(* Slightly less naive solution, in O(N^2) *)
module Algo2
use import ref.Refint
use import Spec
let maximum_subarray (a: array int) (ghost lo hi: ref int): int
ensures { 0 <= !lo <= !hi <= length a && result = sum a !lo !hi }
ensures { maxsub a result }
= lo := 0;
hi := 0;
let n = length a in
let ms = ref 0 in
for l = 0 to n-1 do
invariant { 0 <= !lo <= l && !lo <= !hi <= n && 0 <= !ms = sum a !lo !hi }
invariant { maxsublo a l !ms }
let s = ref 0 in
for h = l+1 to n do
invariant
{ 0 <= !lo <= l && !lo <= !hi <= n && 0 <= !ms = sum a !lo !hi }
invariant { maxsublo a l !ms }
invariant { forall h': int. l <= h' < h -> sum a l h' <= !ms }
invariant { !s = sum a l (h-1) }
s += a[h-1];
assert { !s = sum a l h };
if !s > !ms then begin ms := !s; lo := l; hi := h end
done
done;
!ms
end
examples/in_progress/maximum_subarray/why3session.xml
View file @
bebc04f4
This diff is collapsed.
Click to expand it.
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