Commit b9633ad1 authored by Raphael Rieu-Helft's avatar Raphael Rieu-Helft

Merge branch 'new_system' into mp

Conflicts:
	share/emacs/why3.el
	share/vim/syntax/why3.vim
	src/mlw/compile.ml
	src/mlw/dexpr.ml
	src/parser/parser.mly
	src/parser/typing.ml
parents 43806070 54e5a079
......@@ -178,8 +178,8 @@ LIB_DRIVER = prove_client call_provers driver_ast driver_parser driver_lexer dri
collect_data_model parse_smtv2_model_lexer parse_smtv2_model \
parse_smtv2_model
LIB_MLW = ity expr dexpr pdecl eval_match typeinv vc pmodule \
pinterp compile pdriver cprinter ocaml_printer
LIB_MLW = ity expr pdecl eval_match typeinv vc pmodule dexpr \
pinterp mltree compile pdriver cprinter ocaml_printer
LIB_PARSER = ptree glob typing parser lexer
......@@ -1601,8 +1601,9 @@ CLEANDIRS += src/trywhy3
.PHONY: bench test
bench:: bin/why3.@OCAMLBEST@ bin/why3config.@OCAMLBEST@ plugins $(TOOLS) \
share/Makefile.config
# temporarily disabled dependency: bin/why3extract
share/Makefile.config bin/why3extract.@OCAMLBEST@
bash bench/bench ".@OCAMLBEST@"
@echo "=== Checking Why3 API ==="
$(MAKE) test-api-logic.@OCAMLBEST@
# $(MAKE) test-api-mlw-tree.@OCAMLBEST@
# $(MAKE) test-api-mlw.@OCAMLBEST@
......@@ -1611,9 +1612,9 @@ bench:: bin/why3.@OCAMLBEST@ bin/why3config.@OCAMLBEST@ plugins $(TOOLS) \
# desactivé car requiert findlib
# if test -d examples/runstrat ; then \
# $(MAKE) test-runstrat.@OCAMLBEST@ ; fi
bash bench/bench ".@OCAMLBEST@"
@if test "@enable_coq_tactic@" = "yes"; then \
echo "=== checking the Coq tactic ==="; \
echo ; \
echo "=== Checking the Coq tactic ==="; \
$(MAKE) test-coq-tactic.@OCAMLBEST@; fi
###############
......
......@@ -169,10 +169,6 @@ list_stuff () {
fi
}
echo "=== Checking invalid goals ==="
invalid_goals bench/invalid
echo ""
echo "=== Checking theories ==="
goods theories --type-only # FIXME remove --type-only
echo ""
......@@ -193,6 +189,33 @@ bads bench/typing/bad --type-only
bads bench/programs/bad-typing --type-only
echo ""
echo "=== Checking good files ==="
goods bench/typing/good
goods bench/programs/good
goods examples/bts
goods examples/tests
goods examples/tests-provers
goods examples/check-builtin
goods examples/logic
goods examples
goods examples/foveoos11-cm
goods examples/WP_revisited
goods examples/vacid_0_binary_heaps "-L examples/vacid_0_binary_heaps"
goods examples/bitvectors "-L examples/bitvectors"
goods examples/avl "-L examples/avl"
goods examples/verifythis_2016_matrix_multiplication "-L examples/verifythis_2016_matrix_multiplication"
goods examples/double_wp "-L examples/double_wp"
goods examples/in_progress
echo ""
echo "=== Checking valid goals ==="
valid_goals bench/valid
echo ""
echo "=== Checking invalid goals ==="
invalid_goals bench/invalid
echo ""
echo "=== Checking execution ==="
execute examples/euler001.mlw Euler001.bench
execute examples/euler002.mlw Solve.bench
......@@ -225,7 +248,7 @@ execute examples/vstte10_queens.mlw NQueens.test8
echo ""
echo "=== Extraction to Ocaml ==="
echo "=== Checking extraction to OCaml ==="
extract_and_run examples/euler001 euler001.ml 1000000
extract_and_run examples/gcd gcd.ml 6 15
extract_and_run examples/vstte10_max_sum vstte10_max_sum.ml
......@@ -234,31 +257,6 @@ extract_and_run examples/defunctionalization defunctionalization.ml
extract_and_run examples/sudoku sudoku.ml 2,0,9,0,0,0,0,1,0,0,0,0,0,6,0,0,0,0,0,5,3,8,0,2,7,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,7,5,0,0,3,0,4,1,2,0,8,9,0,0,0,0,4,0,9,0,0,2,0,8,0,0,0,0,1,0,0,5,0,0,0,0,0,0,0,7,6
echo ""
echo "=== Checking good files ==="
goods bench/typing/good
goods bench/programs/good
goods examples/bts
goods examples/tests
goods examples/tests-provers
goods examples/check-builtin
goods examples/logic
goods examples
goods examples/foveoos11-cm
goods examples/WP_revisited
goods examples/vacid_0_binary_heaps "-L examples/vacid_0_binary_heaps"
goods examples/bitvectors "-L examples/bitvectors"
goods examples/avl "-L examples/avl"
goods examples/verifythis_2016_matrix_multiplication "-L examples/verifythis_2016_matrix_multiplication"
goods examples/double_wp "-L examples/double_wp"
goods examples/in_progress
echo ""
echo "=== Checking valid goals ==="
valid_goals bench/valid
echo ""
echo "=== Checking --list-* ==="
list_stuff --list-transforms
list_stuff --list-printers
......
......@@ -127,14 +127,14 @@ we invoke \texttt{extract} from the directory where this file is stored. File
\texttt{aqueue.ml} now contains the following OCaml code:
\begin{whycode}
let enqueue (x: 'a) (q: 'a queue) : 'a queue =
create (q.front) (q.lenf) (x :: (q.rear))
create (q.front) (q.lenf) (x :: (q.rear))
(Z.add (q.lenr) (Z.of_string "1"))
\end{whycode}
Choosing a function symbol as the entry point of extraction allows us to focus
only on specific parts of the program. However, the generated code cannot be
type-checked by the OCaml compiler, as it depends on function \texttt{create}
and on type \texttt{'a queue}, whose definitions are not given. In order to
obtain a \emph{correct} OCaml implementation, we can perform a recursive
obtain a \emph{complete} OCaml implementation, we can perform a recursive
extraction:
\begin{verbatim}
> why3 extraction --recursive -D ocaml64 -L . \
......@@ -162,6 +162,9 @@ let enqueue (x: 'a) (q: 'a queue) : 'a queue =
create (q.front) (q.lenf) (x :: (q.rear))
(Z.add (q.lenr) (Z.of_string "1"))
\end{whycode}
This new version of the code is now accepted by the OCaml compiler.
Let us now consider the
% \label{fig:extract-queens}
% \caption{Recursive extraction of \texttt{queens} function.}
% \end{figure}
......
......@@ -59,21 +59,17 @@ module AddListImp
use import SumList
use import ref.Ref
exception Break
let sum (l: list or_integer_float) : (int, real) =
returns { si, sf -> si = add_int l /\ sf = add_real l }
let si = ref 0 in
let sf = ref 0.0 in
let ll = ref l in
try
while True do
invariant { !si + add_int !ll = add_int l /\
!sf +. add_real !ll = add_real l
}
!sf +. add_real !ll = add_real l }
variant { !ll }
match !ll with
| Nil -> raise Break
| Nil -> return (!si, !sf)
| Cons (Integer n) t ->
si := !si + n; ll := t
| Cons (Real x) t ->
......@@ -81,8 +77,6 @@ let sum (l: list or_integer_float) : (int, real) =
end
done;
absurd
with Break -> (!si, !sf)
end
let main () =
......
......@@ -2,176 +2,223 @@
<!DOCTYPE why3session PUBLIC "-//Why3//proof session v5//EN"
"http://why3.lri.fr/why3session.dtd">
<why3session shape_version="4">
<prover id="0" name="Alt-Ergo" version="0.99.1" timelimit="5" memlimit="1000"/>
<prover id="1" name="CVC4" version="1.4" timelimit="5" memlimit="1000"/>
<prover id="2" name="Z3" version="4.3.2" timelimit="5" memlimit="1000"/>
<prover id="0" name="Alt-Ergo" version="0.99.1" timelimit="30" steplimit="0" memlimit="1000"/>
<prover id="3" name="Alt-Ergo" version="1.30" timelimit="5" steplimit="0" memlimit="1000"/>
<file name="../algo63.mlw" expanded="true">
<theory name="Algo63" sum="194369664eddb4417ee380157f3a70d4" expanded="true">
<theory name="Algo63" sum="b10646244317d97681f582ddcef2be31" expanded="true">
<goal name="VC exchange" expl="VC for exchange">
<transf name="split_goal_wp">
<goal name="VC exchange.1" expl="1. index in array bounds">
<proof prover="0"><result status="valid" time="0.01" steps="6"/></proof>
<proof prover="3"><result status="valid" time="0.01" steps="7"/></proof>
</goal>
<goal name="VC exchange.2" expl="2. index in array bounds">
<proof prover="0"><result status="valid" time="0.02" steps="6"/></proof>
<proof prover="3"><result status="valid" time="0.01" steps="7"/></proof>
</goal>
<goal name="VC exchange.3" expl="3. index in array bounds">
<proof prover="0"><result status="valid" time="0.02" steps="6"/></proof>
<proof prover="3"><result status="valid" time="0.01" steps="7"/></proof>
</goal>
<goal name="VC exchange.4" expl="4. index in array bounds">
<proof prover="0"><result status="valid" time="0.01" steps="8"/></proof>
<proof prover="3"><result status="valid" time="0.01" steps="9"/></proof>
</goal>
<goal name="VC exchange.5" expl="5. assertion">
<proof prover="0"><result status="valid" time="0.02" steps="30"/></proof>
<proof prover="3"><result status="valid" time="0.02" steps="28"/></proof>
</goal>
<goal name="VC exchange.6" expl="6. postcondition">
<proof prover="0"><result status="valid" time="0.01" steps="11"/></proof>
<proof prover="3"><result status="valid" time="0.01" steps="12"/></proof>
</goal>
<goal name="VC exchange.7" expl="7. postcondition">
<proof prover="0"><result status="valid" time="0.02" steps="15"/></proof>
<proof prover="3"><result status="valid" time="0.01" steps="17"/></proof>
</goal>
</transf>
</goal>
<goal name="VC partition_" expl="VC for partition_">
<transf name="split_goal_wp">
<goal name="VC partition_.1" expl="1. index in array bounds">
<proof prover="0"><result status="valid" time="0.02" steps="5"/></proof>
<proof prover="3"><result status="valid" time="0.01" steps="6"/></proof>
</goal>
<goal name="VC partition_.2" expl="2. loop invariant init">
<proof prover="0"><result status="valid" time="0.02" steps="15"/></proof>
<proof prover="3"><result status="valid" time="0.00" steps="16"/></proof>
</goal>
<goal name="VC partition_.3" expl="3. loop invariant init">
<proof prover="0"><result status="valid" time="0.02" steps="22"/></proof>
<proof prover="3"><result status="valid" time="0.01" steps="23"/></proof>
</goal>
<goal name="VC partition_.4" expl="4. index in array bounds">
<proof prover="0"><result status="valid" time="0.01" steps="18"/></proof>
<proof prover="3"><result status="valid" time="0.01" steps="19"/></proof>
</goal>
<goal name="VC partition_.5" expl="5. loop invariant preservation">
<proof prover="0"><result status="valid" time="0.01" steps="20"/></proof>
<goal name="VC partition_.5" expl="5. loop variant decrease">
<proof prover="3"><result status="valid" time="0.01" steps="21"/></proof>
</goal>
<goal name="VC partition_.6" expl="6. loop invariant preservation">
<proof prover="0"><result status="valid" time="0.03" steps="27"/></proof>
<proof prover="3"><result status="valid" time="0.00" steps="21"/></proof>
</goal>
<goal name="VC partition_.7" expl="7. loop variant decrease">
<proof prover="0"><result status="valid" time="0.02" steps="20"/></proof>
<goal name="VC partition_.7" expl="7. loop invariant preservation">
<proof prover="3"><result status="valid" time="0.01" steps="30"/></proof>
</goal>
<goal name="VC partition_.8" expl="8. loop invariant init">
<proof prover="0"><result status="valid" time="0.01" steps="17"/></proof>
<proof prover="3"><result status="valid" time="0.01" steps="18"/></proof>
</goal>
<goal name="VC partition_.9" expl="9. loop invariant init">
<proof prover="0"><result status="valid" time="0.02" steps="24"/></proof>
<proof prover="3"><result status="valid" time="0.01" steps="25"/></proof>
</goal>
<goal name="VC partition_.10" expl="10. index in array bounds">
<proof prover="0"><result status="valid" time="0.01" steps="20"/></proof>
<proof prover="3"><result status="valid" time="0.01" steps="21"/></proof>
</goal>
<goal name="VC partition_.11" expl="11. loop invariant preservation">
<proof prover="0"><result status="valid" time="0.02" steps="22"/></proof>
<goal name="VC partition_.11" expl="11. loop variant decrease">
<proof prover="3"><result status="valid" time="0.01" steps="23"/></proof>
</goal>
<goal name="VC partition_.12" expl="12. loop invariant preservation">
<proof prover="0"><result status="valid" time="0.02" steps="29"/></proof>
<proof prover="3"><result status="valid" time="0.01" steps="23"/></proof>
</goal>
<goal name="VC partition_.13" expl="13. loop variant decrease">
<proof prover="0"><result status="valid" time="0.02" steps="22"/></proof>
<goal name="VC partition_.13" expl="13. loop invariant preservation">
<proof prover="3"><result status="valid" time="0.01" steps="32"/></proof>
</goal>
<goal name="VC partition_.14" expl="14. precondition">
<proof prover="0"><result status="valid" time="0.02" steps="22"/></proof>
<proof prover="3"><result status="valid" time="0.01" steps="21"/></proof>
</goal>
<goal name="VC partition_.15" expl="15. variant decrease">
<proof prover="0"><result status="valid" time="0.04" steps="87"/></proof>
<proof prover="3"><result status="valid" time="0.05" steps="100"/></proof>
</goal>
<goal name="VC partition_.16" expl="16. precondition">
<proof prover="0"><result status="valid" time="0.02" steps="34"/></proof>
<proof prover="3"><result status="valid" time="0.01" steps="33"/></proof>
</goal>
<goal name="VC partition_.17" expl="17. precondition">
<proof prover="0"><result status="valid" time="0.06" steps="128"/></proof>
<proof prover="3"><result status="valid" time="0.05" steps="156"/></proof>
</goal>
<goal name="VC partition_.18" expl="18. precondition">
<proof prover="0"><result status="valid" time="1.93" steps="780"/></proof>
<proof prover="3"><result status="valid" time="0.16" steps="215"/></proof>
</goal>
<goal name="VC partition_.19" expl="19. precondition">
<proof prover="2"><result status="valid" time="0.36"/></proof>
<proof prover="3"><result status="valid" time="0.17" steps="217"/></proof>
</goal>
<goal name="VC partition_.20" expl="20. precondition">
<proof prover="0"><result status="valid" time="0.08" steps="129"/></proof>
<proof prover="3"><result status="valid" time="0.07" steps="146"/></proof>
</goal>
<goal name="VC partition_.21" expl="21. postcondition">
<proof prover="0"><result status="valid" time="0.04" steps="55"/></proof>
<proof prover="3"><result status="valid" time="0.01" steps="32"/></proof>
</goal>
<goal name="VC partition_.22" expl="22. postcondition">
<proof prover="0"><result status="valid" time="0.31" steps="588"/></proof>
<proof prover="3"><result status="valid" time="0.07" steps="192"/></proof>
</goal>
<goal name="VC partition_.23" expl="23. postcondition">
<proof prover="0"><result status="valid" time="0.03" steps="57"/></proof>
<proof prover="3"><result status="valid" time="0.02" steps="33"/></proof>
</goal>
<goal name="VC partition_.24" expl="24. postcondition">
<proof prover="0"><result status="valid" time="0.02" steps="51"/></proof>
<proof prover="3"><result status="valid" time="0.02" steps="33"/></proof>
</goal>
<goal name="VC partition_.25" expl="25. postcondition">
<proof prover="0"><result status="valid" time="0.03" steps="52"/></proof>
<proof prover="3"><result status="valid" time="0.01" steps="33"/></proof>
</goal>
<goal name="VC partition_.26" expl="26. postcondition">
<proof prover="0"><result status="valid" time="0.07" steps="142"/></proof>
<proof prover="3"><result status="valid" time="0.02" steps="50"/></proof>
</goal>
<goal name="VC partition_.27" expl="27. postcondition">
<proof prover="0"><result status="valid" time="0.07" steps="142"/></proof>
<proof prover="3"><result status="valid" time="0.02" steps="50"/></proof>
</goal>
<goal name="VC partition_.28" expl="28. precondition">
<proof prover="0"><result status="valid" time="0.02" steps="8"/></proof>
<goal name="VC partition_.28" expl="28. postcondition">
<proof prover="3"><result status="valid" time="0.01" steps="21"/></proof>
</goal>
<goal name="VC partition_.29" expl="29. precondition">
<proof prover="0"><result status="valid" time="0.02" steps="18"/></proof>
<goal name="VC partition_.29" expl="29. postcondition">
<proof prover="3"><result status="valid" time="0.04" steps="105"/></proof>
</goal>
<goal name="VC partition_.30" expl="30. precondition">
<proof prover="0"><result status="valid" time="0.01" steps="9"/></proof>
<goal name="VC partition_.30" expl="30. postcondition">
<proof prover="3"><result status="valid" time="0.01" steps="25"/></proof>
</goal>
<goal name="VC partition_.31" expl="31. precondition">
<proof prover="0"><result status="valid" time="0.01" steps="9"/></proof>
<goal name="VC partition_.31" expl="31. postcondition">
<proof prover="3"><result status="valid" time="0.01" steps="25"/></proof>
</goal>
<goal name="VC partition_.32" expl="32. precondition">
<proof prover="0"><result status="valid" time="0.02" steps="0"/></proof>
<goal name="VC partition_.32" expl="32. postcondition">
<proof prover="3"><result status="valid" time="0.01" steps="23"/></proof>
</goal>
<goal name="VC partition_.33" expl="33. assertion">
<proof prover="0"><result status="valid" time="0.01" steps="18"/></proof>
<goal name="VC partition_.33" expl="33. postcondition">
<proof prover="3"><result status="valid" time="0.02" steps="33"/></proof>
</goal>
<goal name="VC partition_.34" expl="34. precondition">
<proof prover="0"><result status="valid" time="0.01" steps="15"/></proof>
<goal name="VC partition_.34" expl="34. postcondition">
<proof prover="3"><result status="valid" time="0.01" steps="33"/></proof>
</goal>
<goal name="VC partition_.35" expl="35. precondition">
<proof prover="0"><result status="valid" time="0.02" steps="19"/></proof>
<proof prover="3"><result status="valid" time="0.01" steps="9"/></proof>
</goal>
<goal name="VC partition_.36" expl="36. postcondition">
<proof prover="0"><result status="valid" time="0.03" steps="39"/></proof>
<goal name="VC partition_.36" expl="36. precondition">
<proof prover="3"><result status="valid" time="0.01" steps="25"/></proof>
</goal>
<goal name="VC partition_.37" expl="37. postcondition">
<proof prover="0"><result status="valid" time="0.22" steps="673"/></proof>
<goal name="VC partition_.37" expl="37. precondition">
<proof prover="3"><result status="valid" time="0.00" steps="14"/></proof>
</goal>
<goal name="VC partition_.38" expl="38. postcondition">
<proof prover="1"><result status="valid" time="0.10"/></proof>
<proof prover="2"><result status="valid" time="0.44"/></proof>
<goal name="VC partition_.38" expl="38. precondition">
<proof prover="3"><result status="valid" time="0.01" steps="14"/></proof>
</goal>
<goal name="VC partition_.39" expl="39. postcondition">
<proof prover="1"><result status="valid" time="0.10"/></proof>
<proof prover="2"><result status="valid" time="1.85"/></proof>
<goal name="VC partition_.39" expl="39. precondition">
<proof prover="3"><result status="valid" time="0.00" steps="1"/></proof>
</goal>
<goal name="VC partition_.40" expl="40. postcondition">
<proof prover="1"><result status="valid" time="0.11"/></proof>
<proof prover="2"><result status="valid" time="0.79"/></proof>
<goal name="VC partition_.40" expl="40. assertion">
<proof prover="3"><result status="valid" time="0.01" steps="18"/></proof>
</goal>
<goal name="VC partition_.41" expl="41. precondition">
<proof prover="3"><result status="valid" time="0.01" steps="19"/></proof>
</goal>
<goal name="VC partition_.42" expl="42. postcondition">
<proof prover="3"><result status="valid" time="0.01" steps="20"/></proof>
</goal>
<goal name="VC partition_.43" expl="43. postcondition">
<proof prover="3"><result status="valid" time="0.06" steps="147"/></proof>
</goal>
<goal name="VC partition_.44" expl="44. postcondition">
<proof prover="3"><result status="valid" time="0.25" steps="385"/></proof>
</goal>
<goal name="VC partition_.45" expl="45. postcondition">
<proof prover="3"><result status="valid" time="0.41" steps="609"/></proof>
</goal>
<goal name="VC partition_.46" expl="46. postcondition">
<proof prover="3"><result status="valid" time="0.24" steps="373"/></proof>
</goal>
<goal name="VC partition_.47" expl="47. precondition">
<proof prover="3"><result status="valid" time="0.01" steps="20"/></proof>
</goal>
<goal name="VC partition_.48" expl="48. postcondition">
<proof prover="3"><result status="valid" time="0.02" steps="28"/></proof>
</goal>
<goal name="VC partition_.49" expl="49. postcondition">
<proof prover="3"><result status="valid" time="0.05" steps="148"/></proof>
</goal>
<goal name="VC partition_.50" expl="50. postcondition">
<proof prover="3"><result status="valid" time="0.32" steps="538"/></proof>
</goal>
<goal name="VC partition_.51" expl="51. postcondition">
<proof prover="3"><result status="valid" time="0.38" steps="610"/></proof>
</goal>
<goal name="VC partition_.52" expl="52. postcondition">
<proof prover="3"><result status="valid" time="0.28" steps="386"/></proof>
</goal>
<goal name="VC partition_.53" expl="53. postcondition">
<proof prover="3"><result status="valid" time="0.01" steps="18"/></proof>
</goal>
<goal name="VC partition_.54" expl="54. postcondition">
<proof prover="3"><result status="valid" time="0.01" steps="18"/></proof>
</goal>
<goal name="VC partition_.55" expl="55. postcondition">
<proof prover="3"><result status="valid" time="0.01" steps="25"/></proof>
</goal>
<goal name="VC partition_.56" expl="56. postcondition">
<proof prover="3"><result status="valid" time="0.02" steps="26"/></proof>
</goal>
<goal name="VC partition_.57" expl="57. postcondition">
<proof prover="3"><result status="valid" time="0.01" steps="25"/></proof>
</goal>
</transf>
</goal>
<goal name="VC partition" expl="VC for partition" expanded="true">
<transf name="split_goal_wp" expanded="true">
<goal name="VC partition.1" expl="1. precondition">
<proof prover="0"><result status="valid" time="0.01" steps="3"/></proof>
<proof prover="3"><result status="valid" time="0.01" steps="4"/></proof>
</goal>
<goal name="VC partition.2" expl="2. postcondition">
<proof prover="0"><result status="valid" time="0.02" steps="8"/></proof>
<proof prover="3"><result status="valid" time="0.01" steps="9"/></proof>
</goal>
<goal name="VC partition.3" expl="3. postcondition">
<proof prover="0"><result status="valid" time="0.02" steps="8"/></proof>
<proof prover="3"><result status="valid" time="0.00" steps="9"/></proof>
</goal>
<goal name="VC partition.4" expl="4. postcondition" expanded="true">
<proof prover="0" timelimit="30"><result status="valid" time="18.04" steps="455"/></proof>
<proof prover="0"><result status="valid" time="13.34" steps="455"/></proof>
</goal>
</transf>
</goal>
......
module Bag
use BuiltIn
use import int.Int
type bag 'a = 'a -> int
......@@ -13,10 +12,10 @@ module Bag
fun _ -> 0
let ghost function add (e: 'a) (b: bag 'a): bag 'a =
fun x -> if BuiltIn.(=) x e then b x + 1 else b x
fun x -> if pure {x = e} then b x + 1 else b x
let ghost function remove (e: 'a) (b: bag 'a): bag 'a =
fun x -> if BuiltIn.(=) x e then b x - 1 else b x
fun x -> if pure {x = e} then b x - 1 else b x
end
......
......@@ -11,14 +11,13 @@ module BinarySearch
(* the code and its specification *)
exception Break int (* raised to exit the loop *)
exception Not_found (* raised to signal a search failure *)
let binary_search (a : array int) (v : int) : int
requires { forall i1 i2 : int. 0 <= i1 <= i2 < length a -> a[i1] <= a[i2] }
ensures { 0 <= result < length a /\ a[result] = v }
raises { Not_found -> forall i:int. 0 <= i < length a -> a[i] <> v }
= try
=
let l = ref 0 in
let u = ref (length a - 1) in
while !l <= !u do
......@@ -33,12 +32,9 @@ module BinarySearch
else if a[m] > v then
u := m - 1
else
raise (Break m)
return m
done;
raise Not_found
with Break i ->
i
end
end
......@@ -51,7 +47,6 @@ module BinarySearchAnyMidPoint
use import ref.Ref
use import array.Array
exception Break int (* raised to exit the loop *)
exception Not_found (* raised to signal a search failure *)
val midpoint (l:int) (u:int) : int
......@@ -61,7 +56,7 @@ module BinarySearchAnyMidPoint
requires { forall i1 i2 : int. 0 <= i1 <= i2 < length a -> a[i1] <= a[i2] }
ensures { 0 <= result < length a /\ a[result] = v }
raises { Not_found -> forall i:int. 0 <= i < length a -> a[i] <> v }
= try
=
let l = ref 0 in
let u = ref (length a - 1) in
while !l <= !u do
......@@ -75,12 +70,9 @@ module BinarySearchAnyMidPoint
else if a[m] > v then
u := m - 1
else