Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Why3
why3
Commits
0481a32c
Commit
0481a32c
authored
Sep 05, 2011
by
Jean-Christophe Filliâtre
Browse files
n-queens: no more use of store_solution (adequation to the paper)
parent
42c7502b
Changes
2
Hide whitespace changes
Inline
Side-by-side
examples/programs/queens.mlw
View file @
0481a32c
...
...
@@ -82,6 +82,11 @@ theory Solution
predicate sorted (s: solutions) (a b: int) =
forall i j: int. a <= i < j < b -> lt_sol s[i] s[j]
(* a sorted array of solutions contains no duplicate *)
lemma no_duplicate:
forall s: solutions, a b: int. sorted s a b ->
forall i j: int. a <= i < j < b -> not (eq_sol s[i] s[j])
end
(* 1. Abstract version of the code using sets (not ints) *******************)
...
...
@@ -98,14 +103,6 @@ module NQueensSets
val sol: ref solutions (* all solutions *)
val s : ref int (* next slot for a solution = number of solutions *)
let store_solution () =
{ solution !col }
sol := !sol[!s <- !col];
incr s
{ !s = old !s + 1 /\
eq_prefix (old !sol) !sol (old !s) /\
!sol[old !s] = !col }
let rec t3 (a b c : set int) variant { cardinal a } =
{ 0 <= !k /\ !k + cardinal a = n /\ !s >= 0 /\
(forall i: int. mem i a <->
...
...
@@ -142,7 +139,8 @@ module NQueensSets
done;
!f
end else begin
(* ghost *) store_solution ();
(* ghost *) sol := !sol[!s <- !col];
(* ghost *) incr s;
1
end
{ result = !s - old !s >= 0 /\ !k = old !k /\
...
...
@@ -240,14 +238,6 @@ module NQueensBits
val sol: ref solutions (* all solutions *)
val s : ref int (* next slot for a solution = number of solutions *)
let store_solution () =
{ solution !col }
sol := !sol[!s <- !col];
incr s
{ !s = old !s + 1 /\
eq_prefix (old !sol) !sol (old !s) /\
!sol[old !s] = !col }
let rec t (a b c: int) variant { cardinal (bits a) } =
{ 0 <= !k /\ !k + cardinal (bits a) = n /\ !s >= 0 /\
(forall i: int. mem i (bits a) <->
...
...
@@ -286,7 +276,8 @@ module NQueensBits
done;
!f
end else begin
(* ghost *) store_solution ();
(* ghost *) sol := !sol[!s <- !col];
(* ghost *) incr s;
1
end
{ result = !s - old !s >= 0 /\ !k = old !k /\
...
...
examples/programs/queens/why3session.xml
View file @
0481a32c
This source diff could not be displayed because it is too large. You can
view the blob
instead.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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