documentation: solution for VSTTE'10 problem 4

parent 8ba811e5
This diff is collapsed.
...@@ -49,7 +49,7 @@ module NQueens ...@@ -49,7 +49,7 @@ module NQueens
exception Inconsistent int exception Inconsistent int
let check_is_consistent (board: array int) pos = let check_is_consistent (board: array int) (pos: int) =
{ 0 <= pos < length board } { 0 <= pos < length board }
try try
for q = 0 to pos - 1 do for q = 0 to pos - 1 do
...@@ -80,28 +80,27 @@ module NQueens ...@@ -80,28 +80,27 @@ module NQueens
exception Solution exception Solution
let rec bt_queens (board: array int) n pos variant { n - pos } = let rec bt_queens (board: array int) (n: int) (pos: int) variant { n - pos } =
{ length board = n and 0 <= pos <= n and solution board pos } { length board = n and 0 <= pos <= n and solution board pos }
label Init: label Init:
if pos = n then raise Solution; if pos = n then raise Solution;
for i = 0 to n - 1 do for i = 0 to n - 1 do
invariant { invariant {
length board = n and eq_board board (at board Init) pos and eq_board board (at board Init) pos and
forall b:array int. length b = n -> is_board b n -> forall b:array int. length b = n -> is_board b n ->
eq_board board b pos -> 0 <= b[pos] < i -> not (solution b n) } eq_board board b pos -> 0 <= b[pos] < i -> not (solution b n) }
board[pos] <- i; board[pos] <- i;
assert { eq_board board (at board Init) pos };
if check_is_consistent board pos then bt_queens board n (pos+1) if check_is_consistent board pos then bt_queens board n (pos+1)
done done
{ (* no solution *) { (* no solution *)
length board = n and eq_board board (old board) pos and eq_board board (old board) pos and
forall b:array int. length b = n -> is_board b n -> forall b:array int. length b = n -> is_board b n ->
eq_board board b pos -> not (solution b n) } eq_board board b pos -> not (solution b n) }
| Solution -> | Solution ->
{ (* a solution *) { (* a solution *)
solution board n } solution board n }
let queens (board: array int) n = let queens (board: array int) (n: int) =
{ 0 <= length board = n } { 0 <= length board = n }
bt_queens board n 0 bt_queens board n 0
{ forall b:array int. length b = n -> is_board b n -> not (solution b n) } { forall b:array int. length b = n -> is_board b n -> not (solution b n) }
......
...@@ -43,14 +43,14 @@ ...@@ -43,14 +43,14 @@
<result status="valid" time="0.60"/> <result status="valid" time="0.60"/>
</proof> </proof>
</goal> </goal>
<goal name="WP_parameter bt_queens" expl="correctness of parameter bt_queens" sum="b59f9ab1ac42b3755b8e06f7dc04fc2a" proved="true" expanded="true"> <goal name="WP_parameter bt_queens" expl="correctness of parameter bt_queens" sum="90c2b563e0abbc3b4a70fec2410b7f1b" proved="true" expanded="true">
<proof prover="cvc3" timelimit="20" edited="" obsolete="false"> <proof prover="cvc3" timelimit="20" edited="" obsolete="false">
<result status="valid" time="0.96"/> <result status="valid" time="0.36"/>
</proof> </proof>
</goal> </goal>
<goal name="WP_parameter queens" expl="correctness of parameter queens" sum="fa29a0090876c2c2eae4d8423017ff3c" proved="true" expanded="true"> <goal name="WP_parameter queens" expl="correctness of parameter queens" sum="67746ab73fbf4bab85d11e7011676a38" proved="true" expanded="true">
<proof prover="alt-ergo" timelimit="20" edited="" obsolete="false"> <proof prover="alt-ergo" timelimit="20" edited="" obsolete="false">
<result status="valid" time="0.03"/> <result status="valid" time="0.05"/>
</proof> </proof>
</goal> </goal>
</theory> </theory>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment