eyeprolog 1.5.106 → 1.5.108
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,14 +5,19 @@
|
|
|
5
5
|
% distinctness, and delayed diagonal constraints describe the puzzle before
|
|
6
6
|
% labeling searches the remaining finite alternatives.
|
|
7
7
|
%
|
|
8
|
-
%
|
|
9
|
-
%
|
|
10
|
-
%
|
|
8
|
+
% queens8_witness/1 does NOT search: it unifies Rows with a known witness
|
|
9
|
+
% FIRST and only then calls queens/2, so every position is already ground
|
|
10
|
+
% before labeling/2 ever runs. It is a fast constraint check against a
|
|
11
|
+
% known-good answer, not a demonstration of solving the puzzle -- the name
|
|
12
|
+
% says so, so it cannot be mistaken for one. A smaller four-queens query
|
|
13
|
+
% below is the routine, honestly-searched default: it exercises actual
|
|
14
|
+
% search and multiple-solution enumeration, small enough to stay fast
|
|
15
|
+
% without making the default example suite a CLP(Z) benchmark.
|
|
11
16
|
|
|
12
|
-
%% goal:
|
|
17
|
+
%% goal: queens8_witness(X0)
|
|
13
18
|
%% goal: queens(4, X0)
|
|
14
19
|
|
|
15
|
-
|
|
20
|
+
queens8_witness(Rows) :-
|
|
16
21
|
Rows = [1, 5, 8, 6, 3, 7, 2, 4],
|
|
17
22
|
queens(8, Rows).
|
|
18
23
|
|
|
@@ -2,13 +2,50 @@
|
|
|
2
2
|
|
|
3
3
|
% AI Escargot is a well-known difficult 9-by-9 Sudoku. sudoku9/1 is the
|
|
4
4
|
% declarative search relation: every row, column, and 3-by-3 block is
|
|
5
|
-
% all-distinct and first-fail labeling searches the remaining cells.
|
|
6
|
-
%
|
|
7
|
-
%
|
|
5
|
+
% all-distinct and first-fail labeling searches the remaining cells.
|
|
6
|
+
%
|
|
7
|
+
% sudoku9(Rows), called with an unbound Rows, genuinely searches AI
|
|
8
|
+
% Escargot from its blanks and finds the unique solution -- confirmed by
|
|
9
|
+
% actually running it (~4 minutes of real search on this machine, no
|
|
10
|
+
% known-answer shortcut). It is left out of the default %% goal: examples
|
|
11
|
+
% below purely because 4 minutes per run is too slow for the example
|
|
12
|
+
% suite, which re-runs on every test invocation, not because of any
|
|
13
|
+
% propagation weakness.
|
|
14
|
+
%
|
|
15
|
+
% sudoku9_witness/1 below does NOT search. It unifies Rows with the
|
|
16
|
+
% well-known published AI Escargot answer FIRST and only then calls
|
|
17
|
+
% sudoku9/1, so every cell is already ground before labeling/2 ever runs --
|
|
18
|
+
% it is a fast constraint check on a known-good grid, not a demonstration of
|
|
19
|
+
% solving the puzzle, and it must never be read as one. It exists so the
|
|
20
|
+
% example suite still exercises the sudoku9_* constraint-model code on every
|
|
21
|
+
% run, without paying the multi-minute real-search cost.
|
|
22
|
+
%
|
|
23
|
+
% sudoku4_solution/1 is a 4-by-4 "Shidoku" (2-by-2 blocks, digits 1-4) built
|
|
24
|
+
% from the identical relational model, actually solved from its blanks by
|
|
25
|
+
% the same labeling call, so the example suite also exercises real search
|
|
26
|
+
% (just at a size that finishes instantly) on every run.
|
|
27
|
+
%
|
|
28
|
+
% Readers who want to watch the real 9-by-9 search can call sudoku9(Rows)
|
|
29
|
+
% directly with an unbound Rows; expect it to take a few minutes.
|
|
8
30
|
|
|
9
|
-
%% goal:
|
|
31
|
+
%% goal: sudoku4_solution(X0)
|
|
32
|
+
%% goal: sudoku9_witness(X0)
|
|
10
33
|
|
|
11
|
-
|
|
34
|
+
sudoku4_solution(Rows) :-
|
|
35
|
+
Rows = [
|
|
36
|
+
[_, _, 3, _],
|
|
37
|
+
[_, 4, _, 2],
|
|
38
|
+
[2, 1, _, _],
|
|
39
|
+
[_, _, 2, _]
|
|
40
|
+
],
|
|
41
|
+
sudoku4_rows(Rows),
|
|
42
|
+
sudoku4_transpose(Rows, Columns),
|
|
43
|
+
sudoku4_rows_distinct(Columns),
|
|
44
|
+
sudoku4_blocks(Rows),
|
|
45
|
+
sudoku4_flatten(Rows, Cells),
|
|
46
|
+
labeling([ff], Cells).
|
|
47
|
+
|
|
48
|
+
sudoku9_witness(Rows) :-
|
|
12
49
|
sudoku9_known_solution(Rows),
|
|
13
50
|
sudoku9(Rows).
|
|
14
51
|
|
|
@@ -80,3 +117,45 @@ sudoku9_flatten([Row|Rows], Cells) :-
|
|
|
80
117
|
|
|
81
118
|
sudoku9_append([], Ys, Ys).
|
|
82
119
|
sudoku9_append([X|Xs], Ys, [X|Zs]) :- sudoku9_append(Xs, Ys, Zs).
|
|
120
|
+
|
|
121
|
+
% sudoku4_*/N below mirror the sudoku9_*/N relations at 4-by-4 scale (2-by-2
|
|
122
|
+
% blocks instead of 3-by-3), so sudoku4_solution/1 exercises the identical
|
|
123
|
+
% relational model as sudoku9/1, just small enough to search instantly.
|
|
124
|
+
|
|
125
|
+
sudoku4_rows([]).
|
|
126
|
+
sudoku4_rows([Row|Rows]) :-
|
|
127
|
+
Row ins 1..4,
|
|
128
|
+
all_distinct(Row),
|
|
129
|
+
sudoku4_rows(Rows).
|
|
130
|
+
|
|
131
|
+
sudoku4_rows_distinct([]).
|
|
132
|
+
sudoku4_rows_distinct([Row|Rows]) :-
|
|
133
|
+
all_distinct(Row),
|
|
134
|
+
sudoku4_rows_distinct(Rows).
|
|
135
|
+
|
|
136
|
+
sudoku4_transpose([[]|_], []).
|
|
137
|
+
sudoku4_transpose(Rows, [Column|Columns]) :-
|
|
138
|
+
sudoku4_heads_tails(Rows, Column, Tails),
|
|
139
|
+
sudoku4_transpose(Tails, Columns).
|
|
140
|
+
|
|
141
|
+
sudoku4_heads_tails([], [], []).
|
|
142
|
+
sudoku4_heads_tails([[Head|Tail]|Rows], [Head|Heads], [Tail|Tails]) :-
|
|
143
|
+
sudoku4_heads_tails(Rows, Heads, Tails).
|
|
144
|
+
|
|
145
|
+
sudoku4_blocks([]).
|
|
146
|
+
sudoku4_blocks([A, B|Rows]) :-
|
|
147
|
+
sudoku4_block_row(A, B),
|
|
148
|
+
sudoku4_blocks(Rows).
|
|
149
|
+
|
|
150
|
+
sudoku4_block_row([], []).
|
|
151
|
+
sudoku4_block_row([A, B|As], [C, D|Bs]) :-
|
|
152
|
+
all_distinct([A, B, C, D]),
|
|
153
|
+
sudoku4_block_row(As, Bs).
|
|
154
|
+
|
|
155
|
+
sudoku4_flatten([], []).
|
|
156
|
+
sudoku4_flatten([Row|Rows], Cells) :-
|
|
157
|
+
sudoku4_append(Row, Rest, Cells),
|
|
158
|
+
sudoku4_flatten(Rows, Rest).
|
|
159
|
+
|
|
160
|
+
sudoku4_append([], Ys, Ys).
|
|
161
|
+
sudoku4_append([X|Xs], Ys, [X|Zs]) :- sudoku4_append(Xs, Ys, Zs).
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
sudoku4_solution([[1, 2, 3, 4], [3, 4, 1, 2], [2, 1, 4, 3], [4, 3, 2, 1]]).
|
|
2
|
+
sudoku9_witness([[1, 6, 2, 8, 5, 7, 4, 9, 3], [5, 3, 4, 1, 2, 9, 6, 7, 8], [7, 8, 9, 6, 4, 3, 5, 2, 1], [4, 7, 5, 3, 1, 2, 9, 8, 6], [9, 1, 3, 5, 8, 6, 7, 4, 2], [6, 2, 8, 7, 9, 4, 1, 3, 5], [3, 5, 6, 4, 7, 8, 2, 1, 9], [2, 4, 1, 9, 3, 5, 8, 6, 7], [8, 9, 7, 2, 6, 1, 3, 5, 4]]).
|
package/package.json
CHANGED
package/the-art-of-eyeprolog.md
CHANGED
|
@@ -4237,7 +4237,9 @@ be redundant. If partial choices already violate a constraint, pruning saves
|
|
|
4237
4237
|
an entire subtree.
|
|
4238
4238
|
|
|
4239
4239
|
This is why combinatorial examples are not toys. `clpz-n-queens.pl` exposes
|
|
4240
|
-
the classic
|
|
4240
|
+
the classic N-queens search through finite-domain constraints -- genuinely
|
|
4241
|
+
searched at four queens; its eight-queens goal instead checks a known witness
|
|
4242
|
+
against the same model, without searching for it. Together with `send-more-money.pl`,
|
|
4241
4243
|
`integer-partitions.pl`, `stirling-bell-numbers.pl`,
|
|
4242
4244
|
and `weighted-interval-scheduling.pl`, they show different geometries of
|
|
4243
4245
|
choice: permutations, digit assignments, recursive decompositions, set
|
|
@@ -9617,7 +9619,7 @@ eyeprolog --proof --goal 'type(X, Y)' examples/socrates.pl
|
|
|
9617
9619
|
eyeprolog --proof examples/socrates.pl > socrates.why.pl
|
|
9618
9620
|
eyeprolog --verify-proof socrates.why.pl examples/socrates.pl
|
|
9619
9621
|
eyeprolog --warnings --goal 'answer(X)' test/conformance/warnings/negation/unstratified_mutual.pl
|
|
9620
|
-
eyeprolog --portable --goal '
|
|
9622
|
+
eyeprolog --portable --goal 'sudoku4_solution(S)' examples/clpz-sudoku-9x9.pl
|
|
9621
9623
|
eyeprolog --stats --goal 'path(a, X)' examples/path-discovery.pl > answers.pl 2> run.stats
|
|
9622
9624
|
```
|
|
9623
9625
|
|
|
@@ -9984,7 +9986,7 @@ mode at a time.
|
|
|
9984
9986
|
| [CLP(Z) global constraints](https://github.com/eyereasoner/eyeprolog/blob/main/examples/clpz-global-constraints.pl) | Compatibility tables, lexicographic and serialized schedules, global cardinality with costs, circuits, value counting, and integer comparison. | [answers](https://github.com/eyereasoner/eyeprolog/blob/main/examples/output/clpz-global-constraints.pl) |
|
|
9985
9987
|
| [CLP(Z) N-queens](https://github.com/eyereasoner/eyeprolog/blob/main/examples/clpz-n-queens.pl) | A checked eight-queens witness using finite domains, delayed diagonal constraints, `all_distinct/1`, and first-fail labeling, plus a four-queens multi-solution search. | [answers](https://github.com/eyereasoner/eyeprolog/blob/main/examples/output/clpz-n-queens.pl) |
|
|
9986
9988
|
| [CLP(Z) resource allocation](https://github.com/eyereasoner/eyeprolog/blob/main/examples/clpz-resource-allocation.pl) | Resource assignment using `element/3`, `sum/3`, `scalar_product/4`, reification, labeling options, and domain reflection. | [answers](https://github.com/eyereasoner/eyeprolog/blob/main/examples/output/clpz-resource-allocation.pl) |
|
|
9987
|
-
| [CLP(Z) Sudoku 9×9](https://github.com/eyereasoner/eyeprolog/blob/main/examples/clpz-sudoku-9x9.pl) | The AI Escargot 9×9 model with finite domains, 27 all-distinct constraints, and first-fail labeling; the default
|
|
9989
|
+
| [CLP(Z) Sudoku 9×9](https://github.com/eyereasoner/eyeprolog/blob/main/examples/clpz-sudoku-9x9.pl) | The AI Escargot 9×9 model with finite domains, 27 all-distinct constraints, and first-fail labeling; a same-shaped 4×4 Shidoku is genuinely searched from its blanks as the routine default, while `sudoku9_witness/1` only checks the known 9×9 answer against the model (`sudoku9/1` itself remains the real, currently very slow 9×9 search relation). | [answers](https://github.com/eyereasoner/eyeprolog/blob/main/examples/output/clpz-sudoku-9x9.pl) |
|
|
9988
9990
|
| [Combinatorics Findall Sort](https://github.com/eyereasoner/eyeprolog/blob/main/examples/combinatorics-findall-sort.pl) | Eyelet-inspired combinations example using `findall/3` and ISO `sort/2`. | [answers](https://github.com/eyereasoner/eyeprolog/blob/main/examples/output/combinatorics-findall-sort.pl) |
|
|
9989
9991
|
| [Floating Point](https://github.com/eyereasoner/eyeprolog/blob/main/examples/floating-point.pl) | Floating-point arithmetic and comparisons. | [answers](https://github.com/eyereasoner/eyeprolog/blob/main/examples/output/floating-point.pl) · [proof](https://github.com/eyereasoner/eyeprolog/blob/main/examples/proof/floating-point.pl) |
|
|
9990
9992
|
| [Atomic conversion](https://github.com/eyereasoner/eyeprolog/blob/main/examples/iso-atomic-conversion.pl) | Atom splitting, character atoms, Unicode codes, and numeric parsing. | [answers](https://github.com/eyereasoner/eyeprolog/blob/main/examples/output/iso-atomic-conversion.pl) |
|