eyeling 1.34.2 → 1.34.3

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.
@@ -1,3 +1,3 @@
1
- airroute(discovered, "Ostend-Bruges International Airport -> Liège Airport -> Heraklion International Nikos Kazantzakis Airport -> Václav Havel Airport Prague").
2
- airroute(discovered, "Ostend-Bruges International Airport -> Liège Airport -> Diagoras Airport -> Václav Havel Airport Prague").
3
- airroute(discovered, "Ostend-Bruges International Airport -> Liège Airport -> Palma De Mallorca Airport -> Václav Havel Airport Prague").
1
+ airroute("Ostend-Bruges International Airport", "Václav Havel Airport Prague", 2, "Ostend-Bruges International Airport -> Liège Airport -> Heraklion International Nikos Kazantzakis Airport -> Václav Havel Airport Prague").
2
+ airroute("Ostend-Bruges International Airport", "Václav Havel Airport Prague", 2, "Ostend-Bruges International Airport -> Liège Airport -> Diagoras Airport -> Václav Havel Airport Prague").
3
+ airroute("Ostend-Bruges International Airport", "Václav Havel Airport Prague", 2, "Ostend-Bruges International Airport -> Liège Airport -> Palma De Mallorca Airport -> Václav Havel Airport Prague").
@@ -1,20 +1,35 @@
1
1
  % Generic path discovery over the air-routes graph.
2
- % Change or add route_request(FromLabel, ToLabel, MaxStopOvers) to answer other routes.
2
+ % Add route_request(FromLabel, ToLabel, MaxStopOvers) facts to answer other routes.
3
+ % MaxStopOvers is converted to a leg limit, and the recursive search keeps a
4
+ % visited list so it works without the removed finite-search helper builtins.
5
+
3
6
  % Output declarations: materialize/2 selects the relations written to this example's golden output.
4
- materialize(airroute, 2).
7
+ materialize(airroute, 4).
5
8
 
6
9
  % Program structure: facts set up the scenario, and rules derive the materialized conclusions.
7
10
  route_request("Ostend-Bruges International Airport", "Václav Havel Airport Prague", 2).
8
11
 
9
12
  % Derivation rules: each rule below contributes one logical step toward the displayed results.
10
- airroute(discovered, RouteText) :-
11
- route_request(From, To, MaxStopOvers),
12
- airport(Source, From),
13
- airport(Destination, To),
13
+ airroute(FromLabel, ToLabel, MaxStopOvers, RouteText) :-
14
+ route_request(FromLabel, ToLabel, MaxStopOvers),
15
+ route_between(FromLabel, ToLabel, MaxStopOvers, RouteText).
16
+
17
+ route_between(FromLabel, ToLabel, MaxStopOvers, RouteText) :-
18
+ airport(Source, FromLabel),
19
+ airport(Destination, ToLabel),
14
20
  add(MaxStopOvers, 1, MaxLegs),
15
- bounded_path(flight, Source, Destination, MaxLegs, Path),
21
+ simple_path(Source, Destination, MaxLegs, [Source], ReversePath),
22
+ reverse(ReversePath, Path),
16
23
  route_text(Path, RouteText).
17
24
 
25
+ simple_path(Node, Node, _RemainingLegs, Visited, Visited).
26
+ simple_path(Node, Goal, RemainingLegs, Visited, Path) :-
27
+ gt(RemainingLegs, 0),
28
+ flight(Node, Next),
29
+ not_member(Next, Visited),
30
+ sub(RemainingLegs, 1, NextRemainingLegs),
31
+ simple_path(Next, Goal, NextRemainingLegs, [Next|Visited], Path).
32
+
18
33
  route_text([Node], Text) :-
19
34
  airport(Node, Text).
20
35
  route_text([Node|Rest], Text) :-
@@ -7,7 +7,6 @@ import { listBuiltins } from './lists.js';
7
7
  import { aggregationBuiltins } from './aggregation.js';
8
8
  import { contextBuiltins } from './context.js';
9
9
  import { controlBuiltins } from './control.js';
10
- import { searchBuiltins } from './search.js';
11
10
  import { numberTheoryBuiltins } from './number-theory.js';
12
11
  import { matrixBuiltins } from './matrix.js';
13
12
 
@@ -36,7 +35,7 @@ export class BuiltinRegistry {
36
35
 
37
36
  export function createDefaultRegistry() {
38
37
  const registry = new BuiltinRegistry();
39
- for (const mod of [coreBuiltins, arithmeticBuiltins, stringBuiltins, listBuiltins, aggregationBuiltins, contextBuiltins, controlBuiltins, searchBuiltins, numberTheoryBuiltins, matrixBuiltins]) {
38
+ for (const mod of [coreBuiltins, arithmeticBuiltins, stringBuiltins, listBuiltins, aggregationBuiltins, contextBuiltins, controlBuiltins, numberTheoryBuiltins, matrixBuiltins]) {
40
39
  mod.register(registry);
41
40
  }
42
41
  return registry;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyeling",
3
- "version": "1.34.2",
3
+ "version": "1.34.3",
4
4
  "description": "A minimal Notation3 (N3) reasoner in JavaScript.",
5
5
  "main": "./index.js",
6
6
  "keywords": [
@@ -36,7 +36,7 @@ The runner executes materialized programs in-process through the public JavaScri
36
36
 
37
37
  `core` covers the portable core language profile from the [eyelang language reference](../../../docs/eyelang-language-reference.md): lexical syntax, facts, definite clauses, first-order terms, lists, conjunction, structured unification through user predicates, left-to-right goal-directed proof search, materialized output, and read-back printing.
38
38
 
39
- `extension` covers the standard built-in and host behavior exercised by the current reference implementation: arithmetic, comparison, strings, list relations, aggregation, context-term helpers, number-theory helpers, finite-search helpers used by the example corpus, matrix helpers, `memoize/2`, `materialize/2`, and default derived output.
39
+ `extension` covers the standard built-in and host behavior exercised by the current reference implementation: arithmetic, comparison, strings, list relations, aggregation, context-term helpers, number-theory helpers, matrix helpers, `memoize/2`, `materialize/2`, and default derived output.
40
40
 
41
41
  The profile name `extension` is a test-suite grouping name. It does not mean that these cases are outside the eyelang language reference; most of them correspond to the standard built-in profile and standard host profile in the [eyelang language reference](../../../docs/eyelang-language-reference.md).
42
42
 
@@ -1,92 +0,0 @@
1
- % Dense weighted Hamiltonian cycle search.
2
- %
3
- % This deliberately stresses finite search: it enumerates symmetry-broken
4
- % permutations of seven non-start vertices in an eight-vertex complete graph,
5
- % scores the closed cycles, and keeps the cheapest candidate with
6
- % aggregate_min/5.
7
-
8
- % Output declarations: materialize/2 selects the relations written to this example's golden output.
9
- materialize(best, 2).
10
- materialize(candidateCount, 2).
11
- materialize(status, 2).
12
- materialize(reason, 2).
13
-
14
- % Program structure: facts set up the scenario, and rules derive the materialized conclusions.
15
- cities([a, b, c, d, e, f, g, h]).
16
-
17
- edge(a, b, 3).
18
- edge(a, c, 47).
19
- edge(a, d, 35).
20
- edge(a, e, 46).
21
- edge(a, f, 34).
22
- edge(a, g, 45).
23
- edge(a, h, 10).
24
- edge(b, c, 4).
25
- edge(b, d, 42).
26
- edge(b, e, 30).
27
- edge(b, f, 41).
28
- edge(b, g, 52).
29
- edge(b, h, 40).
30
- edge(c, d, 5).
31
- edge(c, e, 37).
32
- edge(c, f, 48).
33
- edge(c, g, 36).
34
- edge(c, h, 47).
35
- edge(d, e, 6).
36
- edge(d, f, 32).
37
- edge(d, g, 43).
38
- edge(d, h, 31).
39
- edge(e, f, 7).
40
- edge(e, g, 50).
41
- edge(e, h, 38).
42
- edge(f, g, 8).
43
- edge(f, h, 45).
44
- edge(g, h, 9).
45
-
46
- % Derivation rules: each rule below contributes one logical step toward the displayed results.
47
- weight(A, B, W) :- edge(A, B, W).
48
- weight(A, B, W) :- edge(B, A, W).
49
-
50
- permutation([], []).
51
- permutation(List, [X | Perm]) :-
52
- select(X, List, Rest),
53
- permutation(Rest, Perm).
54
-
55
- last([X], X).
56
- last([_ | Rest], X) :- last(Rest, X).
57
-
58
- path_cost([_Last], 0).
59
- path_cost([A, B | Rest], Cost) :-
60
- weight(A, B, Step),
61
- path_cost([B | Rest], Tail),
62
- add(Step, Tail, Cost).
63
-
64
- symmetry_broken([First | Rest]) :-
65
- last([First | Rest], Last),
66
- lt(First, Last).
67
-
68
- candidate_cycle(Cities, Cycle, Cost) :-
69
- weighted_hamiltonian_cycle(edge, Cities, Cycle, Cost).
70
-
71
- factorial(0, 1).
72
- factorial(N, F) :-
73
- gt(N, 0),
74
- sub(N, 1, N0),
75
- factorial(N0, F0),
76
- mul(N, F0, F).
77
-
78
- best(dense_hamiltonian_cycle, result(Cost, Cycle)) :-
79
- cities(Cities),
80
- aggregate_min([Cost, Cycle], result(Cost, Cycle), candidate_cycle(Cities, Cycle, Cost), _Key, result(Cost, Cycle)).
81
-
82
- candidateCount(dense_hamiltonian_cycle, Count) :-
83
- cities([_Start | Rest]),
84
- length(Rest, N),
85
- factorial(N, Permutations),
86
- div(Permutations, 2, Count).
87
-
88
- status(dense_hamiltonian_cycle, symmetry_broken_complete_graph_searched) :-
89
- eq(ok, ok).
90
-
91
- reason(dense_hamiltonian_cycle, "symmetry-broken permutation search scores Hamiltonian cycles and aggregate_min selects the cheapest candidate") :-
92
- eq(ok, ok).
@@ -1,55 +0,0 @@
1
- % Hamiltonian cycle without cut.
2
- %
3
- % The graph has eight vertices and enough chords to create a non-trivial search
4
- % space. The first vertex is fixed to avoid rotational duplicates; the two
5
- % cycle directions are still distinct, so the count is for cycles from a fixed
6
- % start in traversal order.
7
-
8
- % Output declarations: materialize/2 selects the relations written to this example's golden output.
9
- materialize(status, 2).
10
- materialize(witness, 2).
11
- materialize(vertexCount, 2).
12
- materialize(cycleCountFromA, 2).
13
-
14
- % Program structure: facts set up the scenario, and rules derive the materialized conclusions.
15
- edge(a, b).
16
- edge(a, f).
17
- edge(a, g).
18
- edge(a, h).
19
- edge(b, c).
20
- edge(b, d).
21
- edge(b, g).
22
- edge(b, h).
23
- edge(c, d).
24
- edge(c, e).
25
- edge(c, g).
26
- edge(d, e).
27
- edge(d, g).
28
- edge(d, h).
29
- edge(e, f).
30
- edge(f, g).
31
- edge(g, h).
32
-
33
- % Derivation rules: each rule below contributes one logical step toward the displayed results.
34
- adjacent(X, Y) :- edge(X, Y).
35
- adjacent(X, Y) :- edge(Y, X).
36
-
37
- vertices([a, b, c, d, e, f, g, h]).
38
-
39
- hamiltonian_cycle(Cycle) :-
40
- vertices(Vertices),
41
- hamiltonian_cycle(edge, Vertices, Cycle).
42
-
43
- status(hamiltonian_cycle, exists) :-
44
- once(hamiltonian_cycle(_Cycle)).
45
-
46
- witness(hamiltonian_cycle, Cycle) :-
47
- once(hamiltonian_cycle(Cycle)).
48
-
49
- vertexCount(hamiltonian_cycle, Count) :-
50
- vertices(Vertices),
51
- length(Vertices, Count).
52
-
53
- cycleCountFromA(hamiltonian_cycle, Count) :-
54
- findall(Cycle, hamiltonian_cycle(Cycle), Cycles),
55
- length(Cycles, Count).
@@ -1,23 +0,0 @@
1
- % N-queens search without cut.
2
- %
3
- % A solution is represented as a list of column numbers. The list position is
4
- % the row, so [1, 5, 8, ...] means row 1 uses column 1, row 2 uses column 5,
5
- % and so on. Columns are selected from a finite list, which guarantees that no
6
- % two queens share a column.
7
- %
8
- % The two diagonal sets are carried as accumulator lists. A queen at
9
- % row Row/column Q occupies the down diagonal Row + Q and the up diagonal
10
- % Row - Q. Rejecting repeats in those two lists enforces the remaining
11
- % N-queens constraints declaratively, without cut or destructive update.
12
-
13
- % Output declarations: materialize/2 selects the relations written to this example's golden output.
14
- materialize(solution, 2).
15
- materialize(solved, 2).
16
-
17
- % Program structure: facts set up the scenario, and rules derive the materialized conclusions.
18
- % Derivation rules: each rule below contributes one logical step toward the displayed results.
19
- queens(N, Qs) :-
20
- n_queens(N, Qs).
21
-
22
- solution(nQueens8, Qs) :- queens(8, Qs).
23
- solved(nQueens8, true) :- queens(8, _Qs).
@@ -1,4 +0,0 @@
1
- best(dense_hamiltonian_cycle, result(52, [a, b, c, d, e, f, g, h, a])).
2
- candidateCount(dense_hamiltonian_cycle, 2520).
3
- status(dense_hamiltonian_cycle, symmetry_broken_complete_graph_searched).
4
- reason(dense_hamiltonian_cycle, "symmetry-broken permutation search scores Hamiltonian cycles and aggregate_min selects the cheapest candidate").
@@ -1,4 +0,0 @@
1
- status(hamiltonian_cycle, exists).
2
- witness(hamiltonian_cycle, [a, b, c, d, e, f, g, h, a]).
3
- vertexCount(hamiltonian_cycle, 8).
4
- cycleCountFromA(hamiltonian_cycle, 72).
@@ -1,93 +0,0 @@
1
- solution(nQueens8, [1, 5, 8, 6, 3, 7, 2, 4]).
2
- solution(nQueens8, [1, 6, 8, 3, 7, 4, 2, 5]).
3
- solution(nQueens8, [1, 7, 4, 6, 8, 2, 5, 3]).
4
- solution(nQueens8, [1, 7, 5, 8, 2, 4, 6, 3]).
5
- solution(nQueens8, [2, 4, 6, 8, 3, 1, 7, 5]).
6
- solution(nQueens8, [2, 5, 7, 1, 3, 8, 6, 4]).
7
- solution(nQueens8, [2, 5, 7, 4, 1, 8, 6, 3]).
8
- solution(nQueens8, [2, 6, 1, 7, 4, 8, 3, 5]).
9
- solution(nQueens8, [2, 6, 8, 3, 1, 4, 7, 5]).
10
- solution(nQueens8, [2, 7, 3, 6, 8, 5, 1, 4]).
11
- solution(nQueens8, [2, 7, 5, 8, 1, 4, 6, 3]).
12
- solution(nQueens8, [2, 8, 6, 1, 3, 5, 7, 4]).
13
- solution(nQueens8, [3, 1, 7, 5, 8, 2, 4, 6]).
14
- solution(nQueens8, [3, 5, 2, 8, 1, 7, 4, 6]).
15
- solution(nQueens8, [3, 5, 2, 8, 6, 4, 7, 1]).
16
- solution(nQueens8, [3, 5, 7, 1, 4, 2, 8, 6]).
17
- solution(nQueens8, [3, 5, 8, 4, 1, 7, 2, 6]).
18
- solution(nQueens8, [3, 6, 2, 5, 8, 1, 7, 4]).
19
- solution(nQueens8, [3, 6, 2, 7, 1, 4, 8, 5]).
20
- solution(nQueens8, [3, 6, 2, 7, 5, 1, 8, 4]).
21
- solution(nQueens8, [3, 6, 4, 1, 8, 5, 7, 2]).
22
- solution(nQueens8, [3, 6, 4, 2, 8, 5, 7, 1]).
23
- solution(nQueens8, [3, 6, 8, 1, 4, 7, 5, 2]).
24
- solution(nQueens8, [3, 6, 8, 1, 5, 7, 2, 4]).
25
- solution(nQueens8, [3, 6, 8, 2, 4, 1, 7, 5]).
26
- solution(nQueens8, [3, 7, 2, 8, 5, 1, 4, 6]).
27
- solution(nQueens8, [3, 7, 2, 8, 6, 4, 1, 5]).
28
- solution(nQueens8, [3, 8, 4, 7, 1, 6, 2, 5]).
29
- solution(nQueens8, [4, 1, 5, 8, 2, 7, 3, 6]).
30
- solution(nQueens8, [4, 1, 5, 8, 6, 3, 7, 2]).
31
- solution(nQueens8, [4, 2, 5, 8, 6, 1, 3, 7]).
32
- solution(nQueens8, [4, 2, 7, 3, 6, 8, 1, 5]).
33
- solution(nQueens8, [4, 2, 7, 3, 6, 8, 5, 1]).
34
- solution(nQueens8, [4, 2, 7, 5, 1, 8, 6, 3]).
35
- solution(nQueens8, [4, 2, 8, 5, 7, 1, 3, 6]).
36
- solution(nQueens8, [4, 2, 8, 6, 1, 3, 5, 7]).
37
- solution(nQueens8, [4, 6, 1, 5, 2, 8, 3, 7]).
38
- solution(nQueens8, [4, 6, 8, 2, 7, 1, 3, 5]).
39
- solution(nQueens8, [4, 6, 8, 3, 1, 7, 5, 2]).
40
- solution(nQueens8, [4, 7, 1, 8, 5, 2, 6, 3]).
41
- solution(nQueens8, [4, 7, 3, 8, 2, 5, 1, 6]).
42
- solution(nQueens8, [4, 7, 5, 2, 6, 1, 3, 8]).
43
- solution(nQueens8, [4, 7, 5, 3, 1, 6, 8, 2]).
44
- solution(nQueens8, [4, 8, 1, 3, 6, 2, 7, 5]).
45
- solution(nQueens8, [4, 8, 1, 5, 7, 2, 6, 3]).
46
- solution(nQueens8, [4, 8, 5, 3, 1, 7, 2, 6]).
47
- solution(nQueens8, [5, 1, 4, 6, 8, 2, 7, 3]).
48
- solution(nQueens8, [5, 1, 8, 4, 2, 7, 3, 6]).
49
- solution(nQueens8, [5, 1, 8, 6, 3, 7, 2, 4]).
50
- solution(nQueens8, [5, 2, 4, 6, 8, 3, 1, 7]).
51
- solution(nQueens8, [5, 2, 4, 7, 3, 8, 6, 1]).
52
- solution(nQueens8, [5, 2, 6, 1, 7, 4, 8, 3]).
53
- solution(nQueens8, [5, 2, 8, 1, 4, 7, 3, 6]).
54
- solution(nQueens8, [5, 3, 1, 6, 8, 2, 4, 7]).
55
- solution(nQueens8, [5, 3, 1, 7, 2, 8, 6, 4]).
56
- solution(nQueens8, [5, 3, 8, 4, 7, 1, 6, 2]).
57
- solution(nQueens8, [5, 7, 1, 3, 8, 6, 4, 2]).
58
- solution(nQueens8, [5, 7, 1, 4, 2, 8, 6, 3]).
59
- solution(nQueens8, [5, 7, 2, 4, 8, 1, 3, 6]).
60
- solution(nQueens8, [5, 7, 2, 6, 3, 1, 4, 8]).
61
- solution(nQueens8, [5, 7, 2, 6, 3, 1, 8, 4]).
62
- solution(nQueens8, [5, 7, 4, 1, 3, 8, 6, 2]).
63
- solution(nQueens8, [5, 8, 4, 1, 3, 6, 2, 7]).
64
- solution(nQueens8, [5, 8, 4, 1, 7, 2, 6, 3]).
65
- solution(nQueens8, [6, 1, 5, 2, 8, 3, 7, 4]).
66
- solution(nQueens8, [6, 2, 7, 1, 3, 5, 8, 4]).
67
- solution(nQueens8, [6, 2, 7, 1, 4, 8, 5, 3]).
68
- solution(nQueens8, [6, 3, 1, 7, 5, 8, 2, 4]).
69
- solution(nQueens8, [6, 3, 1, 8, 4, 2, 7, 5]).
70
- solution(nQueens8, [6, 3, 1, 8, 5, 2, 4, 7]).
71
- solution(nQueens8, [6, 3, 5, 7, 1, 4, 2, 8]).
72
- solution(nQueens8, [6, 3, 5, 8, 1, 4, 2, 7]).
73
- solution(nQueens8, [6, 3, 7, 2, 4, 8, 1, 5]).
74
- solution(nQueens8, [6, 3, 7, 2, 8, 5, 1, 4]).
75
- solution(nQueens8, [6, 3, 7, 4, 1, 8, 2, 5]).
76
- solution(nQueens8, [6, 4, 1, 5, 8, 2, 7, 3]).
77
- solution(nQueens8, [6, 4, 2, 8, 5, 7, 1, 3]).
78
- solution(nQueens8, [6, 4, 7, 1, 3, 5, 2, 8]).
79
- solution(nQueens8, [6, 4, 7, 1, 8, 2, 5, 3]).
80
- solution(nQueens8, [6, 8, 2, 4, 1, 7, 5, 3]).
81
- solution(nQueens8, [7, 1, 3, 8, 6, 4, 2, 5]).
82
- solution(nQueens8, [7, 2, 4, 1, 8, 5, 3, 6]).
83
- solution(nQueens8, [7, 2, 6, 3, 1, 4, 8, 5]).
84
- solution(nQueens8, [7, 3, 1, 6, 8, 5, 2, 4]).
85
- solution(nQueens8, [7, 3, 8, 2, 5, 1, 6, 4]).
86
- solution(nQueens8, [7, 4, 2, 5, 8, 1, 3, 6]).
87
- solution(nQueens8, [7, 4, 2, 8, 6, 1, 3, 5]).
88
- solution(nQueens8, [7, 5, 3, 1, 6, 8, 2, 4]).
89
- solution(nQueens8, [8, 2, 4, 1, 7, 5, 3, 6]).
90
- solution(nQueens8, [8, 2, 5, 3, 1, 7, 4, 6]).
91
- solution(nQueens8, [8, 3, 1, 6, 2, 5, 7, 4]).
92
- solution(nQueens8, [8, 4, 1, 3, 6, 2, 7, 5]).
93
- solved(nQueens8, true).
@@ -1,3 +0,0 @@
1
- primeImplicants(quine_mccluskey, [[0, 0, x, x], [0, x, x, 1], [x, x, 1, 1]]).
2
- minimalCover(quine_mccluskey, [[0, 0, x, x], [x, x, 1, 1]]).
3
- equation(quine_mccluskey, "f = ~A~B + CD").
@@ -1,5 +0,0 @@
1
- status(sat_instance, satisfiable).
2
- witness(sat_instance, [value(a, false), value(b, true), value(c, false), value(d, true), value(e, false), value(f, true), value(g, false), value(h, true)]).
3
- modelCount(sat_instance, 18).
4
- variableCount(sat_instance, 8).
5
- clauseCount(sat_instance, 12).
@@ -1 +0,0 @@
1
- optimalTour([aaa, bbb, ccc, ddd, eee, fff, ggg], [[aaa, bbb, fff, ccc, eee, ddd, ggg], 75]).
@@ -1,143 +0,0 @@
1
- % Eyelet-inspired Quine-McCluskey minimization using findall/3 and sort/2.
2
- % Problem: f(A,B,C,D) = Sigma m(1,3,7,11,15) + d(0,2,5).
3
-
4
- % Output declarations: materialize/2 selects the relations written to this example's golden output.
5
- materialize(primeImplicants, 2).
6
- materialize(minimalCover, 2).
7
- materialize(equation, 2).
8
- materialize(reason, 2).
9
-
10
- % Program structure: facts set up the scenario, and rules derive the materialized conclusions.
11
- minterm(1).
12
- minterm(3).
13
- minterm(7).
14
- minterm(11).
15
- minterm(15).
16
-
17
- dont_care(0).
18
- dont_care(2).
19
- dont_care(5).
20
-
21
- bits(0, [0, 0, 0, 0]).
22
- bits(1, [0, 0, 0, 1]).
23
- bits(2, [0, 0, 1, 0]).
24
- bits(3, [0, 0, 1, 1]).
25
- bits(4, [0, 1, 0, 0]).
26
- bits(5, [0, 1, 0, 1]).
27
- bits(6, [0, 1, 1, 0]).
28
- bits(7, [0, 1, 1, 1]).
29
- bits(8, [1, 0, 0, 0]).
30
- bits(9, [1, 0, 0, 1]).
31
- bits(10, [1, 0, 1, 0]).
32
- bits(11, [1, 0, 1, 1]).
33
- bits(12, [1, 1, 0, 0]).
34
- bits(13, [1, 1, 0, 1]).
35
- bits(14, [1, 1, 1, 0]).
36
- bits(15, [1, 1, 1, 1]).
37
-
38
- % Derivation rules: each rule below contributes one logical step toward the displayed results.
39
- initial_pattern(P) :- minterm(M), bits(M, P).
40
- initial_pattern(P) :- dont_care(D), bits(D, P).
41
-
42
- combine(A, B, R) :-
43
- diff_count(A, B, 0, 1, [], Rev),
44
- reverse(Rev, R).
45
-
46
- diff_count([], [], Count, Count, Acc, Acc).
47
- diff_count([X | A], [X | B], Count, Max, Acc, R) :-
48
- diff_count(A, B, Count, Max, [X | Acc], R).
49
- diff_count([X | A], [Y | B], Count, Max, Acc, R) :-
50
- neq(X, Y),
51
- add(Count, 1, Next),
52
- le(Next, Max),
53
- diff_count(A, B, Next, Max, [x | Acc], R).
54
-
55
- combined_once(P) :-
56
- initial_pattern(A),
57
- initial_pattern(B),
58
- combine(A, B, P).
59
-
60
- combined_twice(P) :-
61
- combined_once(A),
62
- combined_once(B),
63
- combine(A, B, P).
64
-
65
- used_initial(P) :-
66
- initial_pattern(Q),
67
- combine(P, Q, _R).
68
-
69
- used_once(P) :-
70
- combined_once(Q),
71
- combine(P, Q, _R).
72
-
73
- prime(P) :-
74
- initial_pattern(P),
75
- not(used_initial(P)).
76
- prime(P) :-
77
- combined_once(P),
78
- not(used_once(P)).
79
- prime(P) :-
80
- combined_twice(P).
81
-
82
- prime_implicants(Primes) :-
83
- minterms(Minterms),
84
- dont_cares(DontCares),
85
- bit_table(Bits),
86
- qm_prime_implicants(Minterms, DontCares, Bits, Primes).
87
-
88
- covers([], []).
89
- covers([x | Pattern], [_Bit | Bits]) :-
90
- covers(Pattern, Bits).
91
- covers([Bit | Pattern], [Bit | Bits]) :-
92
- neq(Bit, x),
93
- covers(Pattern, Bits).
94
-
95
- covers_int(Pattern, Int) :-
96
- bits(Int, Bits),
97
- covers(Pattern, Bits).
98
-
99
- covers_all(_Cover, []).
100
- covers_all(Cover, [M | Minterms]) :-
101
- member(P, Cover),
102
- covers_int(P, M),
103
- covers_all(Cover, Minterms).
104
-
105
- minterms(Minterms) :-
106
- findall(M, minterm(M), Raw),
107
- sort(Raw, Minterms).
108
-
109
- dont_cares(DontCares) :-
110
- findall(D, dont_care(D), Raw),
111
- sort(Raw, DontCares).
112
-
113
- bit_table(Bits) :-
114
- findall(bit(N, Pattern), bits(N, Pattern), Bits).
115
-
116
- pair_from([A | Rest], A, B) :-
117
- member(B, Rest).
118
- pair_from([_Head | Rest], A, B) :-
119
- pair_from(Rest, A, B).
120
-
121
- cover_candidate(Cover) :-
122
- prime_implicants(Primes),
123
- pair_from(Primes, A, B),
124
- sort([A, B], Cover),
125
- minterms(Minterms),
126
- covers_all(Cover, Minterms).
127
-
128
- minimal_cover(Cover) :-
129
- minterms(Minterms),
130
- dont_cares(DontCares),
131
- bit_table(Bits),
132
- qm_minimal_cover(Minterms, DontCares, Bits, Cover).
133
-
134
- primeImplicants(quine_mccluskey, Primes) :-
135
- prime_implicants(Primes).
136
-
137
- minimalCover(quine_mccluskey, Cover) :-
138
- minimal_cover(Cover).
139
-
140
- equation(quine_mccluskey, "f = ~A~B + CD") :-
141
- minimal_cover([[0, 0, x, x], [x, x, 1, 1]]).
142
-
143
- reason(quine_mccluskey, "findall builds implicant sets and sort removes duplicates before cover selection").
@@ -1,80 +0,0 @@
1
- % SAT solving without cut.
2
- %
3
- % A compact DPLL-style example for a finite CNF formula. The program first
4
- % generates truth assignments, then checks every clause declaratively. This
5
- % larger instance has eight variables and twelve clauses, so it is still small
6
- % enough for full model collection but no longer a toy four-variable search.
7
-
8
- % Output declarations: materialize/2 selects the relations written to this example's golden output.
9
- materialize(status, 2).
10
- materialize(witness, 2).
11
- materialize(modelCount, 2).
12
- materialize(variableCount, 2).
13
- materialize(clauseCount, 2).
14
- materialize(reason, 2).
15
-
16
- % Program structure: facts set up the scenario, and rules derive the materialized conclusions.
17
- problem(sat_instance,
18
- [a, b, c, d, e, f, g, h],
19
- [
20
- [pos(a), pos(b)],
21
- [neg(a), pos(c)],
22
- [neg(b), pos(d)],
23
- [pos(c), pos(d)],
24
- [neg(c), pos(e)],
25
- [neg(d), pos(f)],
26
- [pos(e), pos(f)],
27
- [neg(e), pos(g)],
28
- [neg(f), pos(h)],
29
- [pos(g), pos(h)],
30
- [neg(g), pos(a)],
31
- [neg(h), pos(b)]
32
- ]).
33
-
34
- truth(false).
35
- truth(true).
36
-
37
- assignment([], []).
38
- % Derivation rules: each rule below contributes one logical step toward the displayed results.
39
- assignment([Var|Vars], [value(Var, Truth)|Rest]) :-
40
- truth(Truth),
41
- assignment(Vars, Rest).
42
-
43
- literal_true(pos(Var), Assignment) :-
44
- member(value(Var, true), Assignment).
45
- literal_true(neg(Var), Assignment) :-
46
- member(value(Var, false), Assignment).
47
-
48
- clause_true([Literal|_Rest], Assignment) :-
49
- literal_true(Literal, Assignment).
50
- clause_true([_Literal|Rest], Assignment) :-
51
- clause_true(Rest, Assignment).
52
-
53
- cnf_true([], _Assignment).
54
- cnf_true([Clause|Clauses], Assignment) :-
55
- clause_true(Clause, Assignment),
56
- cnf_true(Clauses, Assignment).
57
-
58
- model(Name, Assignment) :-
59
- problem(Name, Variables, Clauses),
60
- cnf_model(Variables, Clauses, Assignment).
61
-
62
- status(sat_instance, satisfiable) :-
63
- once(model(sat_instance, _Assignment)).
64
-
65
- witness(sat_instance, Assignment) :-
66
- once(model(sat_instance, Assignment)).
67
-
68
- modelCount(sat_instance, Count) :-
69
- findall(Assignment, model(sat_instance, Assignment), Models),
70
- length(Models, Count).
71
-
72
- variableCount(sat_instance, Count) :-
73
- problem(sat_instance, Variables, _Clauses),
74
- length(Variables, Count).
75
-
76
- clauseCount(sat_instance, Count) :-
77
- problem(sat_instance, _Variables, Clauses),
78
- length(Clauses, Count).
79
-
80
- reason(sat_instance, "finite 8-variable CNF search succeeds without cut").
@@ -1,64 +0,0 @@
1
- % Traveling salesman problem, adapted from Eyelet input/traveling-salesman.pl.
2
- % The optimal tour matches Eyelet output-swipl/traveling-salesman.pl.
3
-
4
- % Output declarations: materialize/2 selects the relations written to this example's golden output.
5
- materialize(optimalTour, 2).
6
-
7
- % Program structure: facts set up the scenario, and rules derive the materialized conclusions.
8
- % The target list fixes the city set; weighted_hamiltonian_path/4 searches tours.
9
- target_cities([aaa, bbb, ccc, ddd, eee, fff, ggg]).
10
-
11
- distance(aaa, bbb, 10).
12
- distance(aaa, ccc, 15).
13
- distance(aaa, ddd, 20).
14
- distance(aaa, eee, 25).
15
- distance(aaa, fff, 30).
16
- distance(bbb, ccc, 35).
17
- distance(bbb, ddd, 40).
18
- distance(bbb, eee, 20).
19
- distance(bbb, fff, 25).
20
- distance(ccc, ddd, 30).
21
- distance(ccc, eee, 15).
22
- distance(ccc, fff, 10).
23
- distance(ddd, eee, 10).
24
- distance(ddd, fff, 35).
25
- distance(ddd, ggg, 5).
26
- distance(eee, fff, 20).
27
-
28
- % Distances are stored once; distance2/3 makes the graph undirected.
29
- % Derivation rules: each rule below contributes one logical step toward the displayed results.
30
- distance2(A, B, D) :-
31
- distance(A, B, D).
32
- distance2(A, B, D) :-
33
- distance(B, A, D).
34
-
35
- permutation([], []).
36
- permutation(List, [X|Perm]) :-
37
- select(X, List, Rest),
38
- permutation(Rest, Perm).
39
-
40
- total_distance([_Last], 0).
41
- total_distance([X, Y|Tail], D) :-
42
- distance2(X, Y, D1),
43
- total_distance([Y|Tail], D2),
44
- add(D1, D2, D).
45
-
46
- tsp(Cities, Tour, Distance) :-
47
- weighted_hamiltonian_path(distance, Cities, Tour, Distance).
48
-
49
- % Materialized output keeps only the minimum-distance candidate.
50
- optimalTour(Cities, Optimal) :-
51
- target_cities(Cities),
52
- findall([T, D], tsp(Cities, T, D), Solutions),
53
- min_distance(Solutions, Optimal).
54
-
55
- min_distance([Sol|Sols], Optimal) :-
56
- min_distance_acc(Sols, Sol, Optimal).
57
-
58
- min_distance_acc([], Best, Best).
59
- min_distance_acc([[_T, D]|Rest], [_BestTour, BestDistance], Optimal) :-
60
- lt(D, BestDistance),
61
- min_distance_acc(Rest, [_T, D], Optimal).
62
- min_distance_acc([[_T, D]|Rest], [BestTour, BestDistance], Optimal) :-
63
- ge(D, BestDistance),
64
- min_distance_acc(Rest, [BestTour, BestDistance], Optimal).