eyeprolog 1.1.16 → 1.1.18
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.
- package/README.md +5 -4
- package/examples/clpz-factorial.pl +14 -0
- package/examples/clpz-global-constraints.pl +35 -0
- package/examples/clpz-n-queens.pl +29 -0
- package/examples/clpz-resource-allocation.pl +29 -0
- package/examples/output/clpz-factorial.pl +1 -0
- package/examples/output/clpz-global-constraints.pl +7 -0
- package/examples/output/clpz-n-queens.pl +4 -0
- package/examples/output/clpz-resource-allocation.pl +3 -0
- package/examples/output/fast-fourier-transform.pl +1 -1
- package/examples/output/iso-extensions.pl +1 -1
- package/examples/output/iso-operators.pl +1 -1
- package/examples/proof/iso-operators.pl +1 -1
- package/package.json +1 -1
- package/playground.html +5 -1
- package/src/cli.js +5 -1
- package/src/clpz.js +912 -0
- package/src/index.js +7 -2
- package/src/lib/clpz.pl +120 -0
- package/src/parser.js +60 -42
- package/src/playground-worker.js +1 -1
- package/src/program.js +8 -2
- package/src/solver.js +2 -0
- package/src/standard-library.js +14 -2
- package/src/term.js +2 -0
- package/src/write.js +29 -1
- package/test/conformance/expected/iso/logtalk_atom_concat.pl +1 -1
- package/test/conformance/expected/iso/logtalk_clause.pl +1 -1
- package/test/conformance/expected/iso/logtalk_findall.pl +1 -1
- package/test/conformance/expected/iso/logtalk_sub_atom.pl +1 -1
- package/test/conformance/expected/iso/operators.pl +2 -2
- package/test/conformance/expected/iso/scryer_operator_precedence.pl +1 -1
- package/test/conformance/expected/iso/swipl_operator_syntax.pl +1 -1
- package/test/conformance/expected/syntax/infix_subtraction_term.pl +1 -1
- package/test/run-playground.mjs +13 -0
- package/test/run-regression.mjs +57 -10
- package/the-art-of-eyeprolog.md +29 -12
package/README.md
CHANGED
|
@@ -91,12 +91,13 @@ noun --> [world] | [prolog].
|
|
|
91
91
|
%% goal: phrase(sentence, Words)
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
-
EyeProlog also adds
|
|
94
|
+
EyeProlog also adds 99 public library predicate indicators to its 129-entry ISO
|
|
95
95
|
profile. **60 are implemented entirely as ordinary Prolog clauses** in focused
|
|
96
|
-
modules under `src/lib/`;
|
|
97
|
-
|
|
96
|
+
modules under `src/lib/`; the control predicates and finite-domain
|
|
97
|
+
`library(clpz)` kernel use backtrackable host support.
|
|
98
98
|
They are ISO/IEC 13211-2 modules loaded explicitly by purpose, such as
|
|
99
|
-
`library(lists)`, `library(strings)`, or `library(
|
|
99
|
+
`library(lists)`, `library(strings)`, `library(aggregate)`, or `library(clpz)`.
|
|
100
|
+
Portable text
|
|
100
101
|
predicates use ISO atoms or character lists. The old catch-all
|
|
101
102
|
`library(eyeprolog)` module is no longer needed.
|
|
102
103
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
:- use_module(library(clpz)).
|
|
2
|
+
|
|
3
|
+
% Declarative integer constraints replace mode-sensitive is/2 arithmetic.
|
|
4
|
+
% Each recursive step relates the predecessor and product; the constraint
|
|
5
|
+
% kernel propagates the single unknown value without an explicit labeling step.
|
|
6
|
+
|
|
7
|
+
%% goal: factorial(6, X0)
|
|
8
|
+
|
|
9
|
+
factorial(0, 1).
|
|
10
|
+
factorial(N, F) :-
|
|
11
|
+
N #> 0,
|
|
12
|
+
Previous #= N - 1,
|
|
13
|
+
factorial(Previous, PreviousFactorial),
|
|
14
|
+
F #= N * PreviousFactorial.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
:- use_module(library(clpz)).
|
|
2
|
+
|
|
3
|
+
% Finite global constraints cover compatibility tables, lexicographic and
|
|
4
|
+
% non-overlapping schedules, value cardinalities with costs, Hamiltonian
|
|
5
|
+
% circuits, distinct-value counting, and three-way integer comparison.
|
|
6
|
+
|
|
7
|
+
%% goal: advanced_clpz(X0, X1)
|
|
8
|
+
|
|
9
|
+
advanced_clpz(table, compatible(4, Y, Distinct)) :-
|
|
10
|
+
tuples_in([[X, Y]], [[1, 2], [1, 5], [4, 0], [4, 3]]),
|
|
11
|
+
X = 4,
|
|
12
|
+
nvalue(Distinct, [X, Y]),
|
|
13
|
+
labeling([], [Y]).
|
|
14
|
+
|
|
15
|
+
advanced_clpz(schedule, starts([A, B, C])) :-
|
|
16
|
+
[A, B, C] ins 0..3,
|
|
17
|
+
lex_chain([[A, B], [B, C]]),
|
|
18
|
+
serialized([A, B, C], [1, 2, 1]),
|
|
19
|
+
A #< B,
|
|
20
|
+
B #< C,
|
|
21
|
+
labeling([ff], [A, B, C]).
|
|
22
|
+
|
|
23
|
+
advanced_clpz(cardinality, assignment(Values, Cost, Order)) :-
|
|
24
|
+
Values = [_, _, _],
|
|
25
|
+
global_cardinality(Values, [1-2, 3-1],
|
|
26
|
+
[cost(Cost, [[5, 1], [2, 4], [3, 6]])]),
|
|
27
|
+
labeling([ff], Values),
|
|
28
|
+
zcompare(Order, Cost, 10).
|
|
29
|
+
|
|
30
|
+
advanced_clpz(circuit, successors(Values)) :-
|
|
31
|
+
Values = [A, B, _, _],
|
|
32
|
+
circuit(Values),
|
|
33
|
+
A #= 2,
|
|
34
|
+
B #= 3,
|
|
35
|
+
labeling([ff], Values).
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
:- use_module(library(clpz)).
|
|
2
|
+
:- use_module(library(lists), [length/2]).
|
|
3
|
+
|
|
4
|
+
% The list position is a column and its value is a row. Domains, global
|
|
5
|
+
% distinctness, and delayed diagonal constraints describe the puzzle before
|
|
6
|
+
% labeling searches the remaining finite alternatives.
|
|
7
|
+
|
|
8
|
+
%% goal: queens(X0, X1)
|
|
9
|
+
|
|
10
|
+
queens(Size, Rows) :-
|
|
11
|
+
Size = 6,
|
|
12
|
+
length(Rows, Size),
|
|
13
|
+
Rows ins 1..Size,
|
|
14
|
+
all_distinct(Rows),
|
|
15
|
+
safe_diagonals(Rows),
|
|
16
|
+
labeling([ff], Rows).
|
|
17
|
+
|
|
18
|
+
safe_diagonals([]).
|
|
19
|
+
safe_diagonals([Row|Rows]) :-
|
|
20
|
+
safe_from(Row, Rows, 1),
|
|
21
|
+
safe_diagonals(Rows).
|
|
22
|
+
|
|
23
|
+
safe_from(_, [], _).
|
|
24
|
+
safe_from(Row, [Other|Rows], Distance) :-
|
|
25
|
+
Row #\= Other + Distance,
|
|
26
|
+
Row #\= Other - Distance,
|
|
27
|
+
NextDistance is Distance + 1,
|
|
28
|
+
safe_from(Row, Rows, NextDistance).
|
|
29
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
:- use_module(library(clpz)).
|
|
2
|
+
|
|
3
|
+
% A small allocation model exercises element and chain constraints, a scalar
|
|
4
|
+
% product, a sum with a derived total, reification, labeling options, and
|
|
5
|
+
% domain reflection. Worker numbers select job-specific duration tables.
|
|
6
|
+
|
|
7
|
+
%% goal: clpz_example(X0, X1)
|
|
8
|
+
|
|
9
|
+
clpz_example(allocation, plan([A, B, C], durations([DA, DB, DC]), Total)) :-
|
|
10
|
+
[A, B, C] ins 1..3,
|
|
11
|
+
all_distinct([A, B, C]),
|
|
12
|
+
scalar_product([1, 2, 3], [A, B, C], #=, 11),
|
|
13
|
+
element(A, [5, 3, 4], DA),
|
|
14
|
+
element(B, [4, 6, 2], DB),
|
|
15
|
+
element(C, [7, 2, 5], DC),
|
|
16
|
+
chain(#>=, [DA, DB]),
|
|
17
|
+
sum([DA, DB, DC], #=, Total),
|
|
18
|
+
Fast in 0..1,
|
|
19
|
+
Fast #<==> Total #=< 12,
|
|
20
|
+
Fast #= 1,
|
|
21
|
+
labeling([ff, down], [A, B, C, Fast]).
|
|
22
|
+
|
|
23
|
+
clpz_example(domain, domain(Infimum, Supremum, Size, Domain)) :-
|
|
24
|
+
X in 2..4 \/ 7,
|
|
25
|
+
fd_var(X),
|
|
26
|
+
fd_inf(X, Infimum),
|
|
27
|
+
fd_sup(X, Supremum),
|
|
28
|
+
fd_size(X, Size),
|
|
29
|
+
fd_dom(X, Domain).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
factorial(6, 720).
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
advanced_clpz(table, compatible(4, 0, 2)).
|
|
2
|
+
advanced_clpz(table, compatible(4, 3, 2)).
|
|
3
|
+
advanced_clpz(schedule, starts([0, 1, 3])).
|
|
4
|
+
advanced_clpz(cardinality, assignment([1, 1, 3], 13, >)).
|
|
5
|
+
advanced_clpz(cardinality, assignment([1, 3, 1], 12, >)).
|
|
6
|
+
advanced_clpz(cardinality, assignment([3, 1, 1], 6, <)).
|
|
7
|
+
advanced_clpz(circuit, successors([2, 3, 4, 1])).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
fft([0, 1, 2, 3, 4, 5, 6, 7], [n(232, op('+', 216, 231)), n(231, op(*, 217, 230)), n(230, op('+', 222, 229)), n(229, op(*, 223, 228)), n(228, op('+', 224, 227)), n(227, op(*, 225, 226)), n(226, a(7)), n(225,
|
|
1
|
+
fft([0, 1, 2, 3, 4, 5, 6, 7], [n(232, op('+', 216, 231)), n(231, op(*, 217, 230)), n(230, op('+', 222, 229)), n(229, op(*, 223, 228)), n(228, op('+', 224, 227)), n(227, op(*, 225, 226)), n(226, a(7)), n(225, w ^ 4), n(224, a(3)), n(223, w ^ 6), n(222, op('+', 218, 221)), n(221, op(*, 219, 220)), n(220, a(5)), n(219, w ^ 4), n(218, a(1)), n(217, w ^ 7), n(216, op('+', 208, 215)), n(215, op(*, 209, 214)), n(214, op('+', 210, 213)), n(213, op(*, 211, 212)), n(212, a(6)), n(211, w ^ 4), n(210, a(2)), n(209, w ^ 6), n(208, op('+', 204, 207)), n(207, op(*, 205, 206)), n(206, a(4)), n(205, w ^ 4), n(204, a(0)), n(203, op('+', 187, 202)), n(202, op(*, 188, 201)), n(201, op('+', 193, 200)), n(200, op(*, 194, 199)), n(199, op('+', 195, 198)), n(198, op(*, 196, 197)), n(197, a(7)), n(196, w ^ 0), n(195, a(3)), n(194, w ^ 4), n(193, op('+', 189, 192)), n(192, op(*, 190, 191)), n(191, a(5)), n(190, w ^ 0), n(189, a(1)), n(188, w ^ 6), n(187, op('+', 179, 186)), n(186, op(*, 180, 185)), n(185, op('+', 181, 184)), n(184, op(*, 182, 183)), n(183, a(6)), n(182, w ^ 0), n(181, a(2)), n(180, w ^ 4), n(179, op('+', 175, 178)), n(178, op(*, 176, 177)), n(177, a(4)), n(176, w ^ 0), n(175, a(0)), n(174, op('+', 158, 173)), n(173, op(*, 159, 172)), n(172, op('+', 164, 171)), n(171, op(*, 165, 170)), n(170, op('+', 166, 169)), n(169, op(*, 167, 168)), n(168, a(7)), n(167, w ^ 4), n(166, a(3)), n(165, w ^ 2), n(164, op('+', 160, 163)), n(163, op(*, 161, 162)), n(162, a(5)), n(161, w ^ 4), n(160, a(1)), n(159, w ^ 5), n(158, op('+', 150, 157)), n(157, op(*, 151, 156)), n(156, op('+', 152, 155)), n(155, op(*, 153, 154)), n(154, a(6)), n(153, w ^ 4), n(152, a(2)), n(151, w ^ 2), n(150, op('+', 146, 149)), n(149, op(*, 147, 148)), n(148, a(4)), n(147, w ^ 4), n(146, a(0)), n(145, op('+', 129, 144)), n(144, op(*, 130, 143)), n(143, op('+', 135, 142)), n(142, op(*, 136, 141)), n(141, op('+', 137, 140)), n(140, op(*, 138, 139)), n(139, a(7)), n(138, w ^ 0), n(137, a(3)), n(136, w ^ 0), n(135, op('+', 131, 134)), n(134, op(*, 132, 133)), n(133, a(5)), n(132, w ^ 0), n(131, a(1)), n(130, w ^ 4), n(129, op('+', 121, 128)), n(128, op(*, 122, 127)), n(127, op('+', 123, 126)), n(126, op(*, 124, 125)), n(125, a(6)), n(124, w ^ 0), n(123, a(2)), n(122, w ^ 0), n(121, op('+', 117, 120)), n(120, op(*, 118, 119)), n(119, a(4)), n(118, w ^ 0), n(117, a(0)), n(116, op('+', 100, 115)), n(115, op(*, 101, 114)), n(114, op('+', 106, 113)), n(113, op(*, 107, 112)), n(112, op('+', 108, 111)), n(111, op(*, 109, 110)), n(110, a(7)), n(109, w ^ 4), n(108, a(3)), n(107, w ^ 6), n(106, op('+', 102, 105)), n(105, op(*, 103, 104)), n(104, a(5)), n(103, w ^ 4), n(102, a(1)), n(101, w ^ 3), n(100, op('+', 92, 99)), n(99, op(*, 93, 98)), n(98, op('+', 94, 97)), n(97, op(*, 95, 96)), n(96, a(6)), n(95, w ^ 4), n(94, a(2)), n(93, w ^ 6), n(92, op('+', 88, 91)), n(91, op(*, 89, 90)), n(90, a(4)), n(89, w ^ 4), n(88, a(0)), n(87, op('+', 71, 86)), n(86, op(*, 72, 85)), n(85, op('+', 77, 84)), n(84, op(*, 78, 83)), n(83, op('+', 79, 82)), n(82, op(*, 80, 81)), n(81, a(7)), n(80, w ^ 0), n(79, a(3)), n(78, w ^ 4), n(77, op('+', 73, 76)), n(76, op(*, 74, 75)), n(75, a(5)), n(74, w ^ 0), n(73, a(1)), n(72, w ^ 2), n(71, op('+', 63, 70)), n(70, op(*, 64, 69)), n(69, op('+', 65, 68)), n(68, op(*, 66, 67)), n(67, a(6)), n(66, w ^ 0), n(65, a(2)), n(64, w ^ 4), n(63, op('+', 59, 62)), n(62, op(*, 60, 61)), n(61, a(4)), n(60, w ^ 0), n(59, a(0)), n(58, op('+', 42, 57)), n(57, op(*, 43, 56)), n(56, op('+', 48, 55)), n(55, op(*, 49, 54)), n(54, op('+', 50, 53)), n(53, op(*, 51, 52)), n(52, a(7)), n(51, w ^ 4), n(50, a(3)), n(49, w ^ 2), n(48, op('+', 44, 47)), n(47, op(*, 45, 46)), n(46, a(5)), n(45, w ^ 4), n(44, a(1)), n(43, w ^ 1), n(42, op('+', 34, 41)), n(41, op(*, 35, 40)), n(40, op('+', 36, 39)), n(39, op(*, 37, 38)), n(38, a(6)), n(37, w ^ 4), n(36, a(2)), n(35, w ^ 2), n(34, op('+', 30, 33)), n(33, op(*, 31, 32)), n(32, a(4)), n(31, w ^ 4), n(30, a(0)), n(29, op('+', 13, 28)), n(28, op(*, 14, 27)), n(27, op('+', 19, 26)), n(26, op(*, 20, 25)), n(25, op('+', 21, 24)), n(24, op(*, 22, 23)), n(23, a(7)), n(22, w ^ 0), n(21, a(3)), n(20, w ^ 0), n(19, op('+', 15, 18)), n(18, op(*, 16, 17)), n(17, a(5)), n(16, w ^ 0), n(15, a(1)), n(14, w ^ 0), n(13, op('+', 5, 12)), n(12, op(*, 6, 11)), n(11, op('+', 7, 10)), n(10, op(*, 8, 9)), n(9, a(6)), n(8, w ^ 0), n(7, a(2)), n(6, w ^ 0), n(5, op('+', 1, 4)), n(4, op(*, 2, 3)), n(3, a(4)), n(2, w ^ 0), n(1, a(0))]).
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
extension_example(all_colors_are_atoms, true).
|
|
2
|
-
extension_example(successors, [
|
|
2
|
+
extension_example(successors, [1 - 2, 2 - 3, 3 - 4]).
|
|
3
3
|
extension_example(collection_with_tail, [red, green, blue, done]).
|
|
4
4
|
extension_example(repeated_variable_variant, true).
|
|
5
5
|
extension_example(different_variable_shape, true).
|
package/package.json
CHANGED
package/playground.html
CHANGED
|
@@ -464,6 +464,10 @@
|
|
|
464
464
|
"cdcl-sat-solver",
|
|
465
465
|
"chart-parser",
|
|
466
466
|
"clinical-trial-screening",
|
|
467
|
+
"clpz-factorial",
|
|
468
|
+
"clpz-global-constraints",
|
|
469
|
+
"clpz-n-queens",
|
|
470
|
+
"clpz-resource-allocation",
|
|
467
471
|
"collatz-1000",
|
|
468
472
|
"combinatorics-findall-sort",
|
|
469
473
|
"competitive-enzyme-kinetics",
|
|
@@ -958,7 +962,7 @@
|
|
|
958
962
|
runButton.disabled = true;
|
|
959
963
|
stopButton.disabled = false;
|
|
960
964
|
|
|
961
|
-
const workerUrl = new URL('./src/playground-worker.js?playground=
|
|
965
|
+
const workerUrl = new URL('./src/playground-worker.js?playground=20260811c', location.href);
|
|
962
966
|
activeWorker = new Worker(workerUrl, { type: 'module' });
|
|
963
967
|
const worker = activeWorker;
|
|
964
968
|
const request = {
|
package/src/cli.js
CHANGED
|
@@ -173,6 +173,8 @@ async function runDefault(engine, program, options) {
|
|
|
173
173
|
const queriedKeys = new Set(goals.map((goal) => `${goal.name}/${goal.arity}`));
|
|
174
174
|
const writeOptions = {
|
|
175
175
|
doubleQuotes: solver.prologFlags.get('double_quotes')?.value?.name ?? 'chars',
|
|
176
|
+
operators: [...program.operators.values()],
|
|
177
|
+
quoted: true,
|
|
176
178
|
};
|
|
177
179
|
const facts = program.sourceFactLines(queriedKeys, writeOptions);
|
|
178
180
|
const lines = new Set();
|
|
@@ -186,8 +188,10 @@ async function runDefault(engine, program, options) {
|
|
|
186
188
|
|
|
187
189
|
const currentWriteOptions = {
|
|
188
190
|
doubleQuotes: solver.prologFlags.get('double_quotes')?.value?.name ?? 'chars',
|
|
191
|
+
operators: [...program.operators.values()],
|
|
192
|
+
quoted: true,
|
|
189
193
|
};
|
|
190
|
-
const line = `${engine.
|
|
194
|
+
const line = `${engine.formatTermForWrite(goal, env, currentWriteOptions)}.\n`;
|
|
191
195
|
if (facts.has(line) || lines.has(line)) continue;
|
|
192
196
|
|
|
193
197
|
lines.add(line);
|