Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
why3
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
86
Issues
86
List
Boards
Labels
Milestones
Merge Requests
11
Merge Requests
11
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Why3
why3
Commits
0b83243e
Commit
0b83243e
authored
Oct 06, 2011
by
MARCHE Claude
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FoVeOOS competition
parent
0241585e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
0 deletions
+46
-0
examples/foveoos2011/array_max.mlw
examples/foveoos2011/array_max.mlw
+46
-0
No files found.
examples/foveoos2011/array_max.mlw
0 → 100644
View file @
0b83243e
(*
COST Verification Competition. vladimir@cost-ic0701.org
Challenge 1: Maximum in an array
Given: A non-empty integer array a.
Verify that the index returned by the method max() given below points to
an element maximal in the array.
*)
module ArrayMax
use import int.Int
use import int.MinMax
use import module ref.Ref
use import module array.Array
let max (a: array int) =
{ 0 < length a }
let x = ref 0 in
let y = ref (length a - 1) in
while !x <> !y do
invariant { 0 <= !x <= !y < length a /\
forall i:int.
0 <= i < !x \/ !y < i < length a ->
a[i] <= max a[!x] a[!y]
}
variant { !y - !x }
if a[!x] <= a[!y] then x := !x+1 else y := !y-1
done;
!x
{ 0 <= result < length a /\
forall i:int. 0 <= i < a.length -> a[i] <= a[result] }
end
(*
Local Variables:
compile-command: "why3ide array_max.mlw"
End:
*)
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