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
34a6bcff
Commit
34a6bcff
authored
Nov 16, 2010
by
Jean-Christophe Filliâtre
Browse files
binary search: relaxing the condition wrt the array length (no condition is needed, actually)
parent
39d2ec48
Changes
1
Hide whitespace changes
Inline
Side-by-side
examples/programs/binary_search.mlw
View file @
34a6bcff
(* Binary search *)
(* Binary search
The classical example. Searches a sorted array for a given value v.
*)
(* the usual array modeling *)
{
use array.ArrayLength as A
...
...
@@ -19,12 +24,13 @@ let array_set (a : ref array) i v =
let length (a : ref array) =
{ } A.length !a { result = A.length !a }
exception Break of int
exception Not_found
(* the code and its specification *)
exception Break of int (* raised to exit the loop *)
exception Not_found (* raised to signal a search failure *)
let binary_search (a : ref array) (v : int) =
{ A.length !a >= 1 and
forall i1 i2 : int. 0 <= i1 <= i2 < A.length !a -> !a#i1 <= !a#i2 }
{ forall i1 i2 : int. 0 <= i1 <= i2 < A.length !a -> !a#i1 <= !a#i2 }
try
let l = ref 0 in
let u = ref (length a - 1) in
...
...
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