eyeling 1.34.2 → 1.34.4

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.
Files changed (69) hide show
  1. package/README.md +7 -10
  2. package/docs/eyelang-guide.md +8 -30
  3. package/docs/eyelang-language-reference.md +32 -6
  4. package/examples/eyelang/basic-monadic.pl +16 -2
  5. package/examples/eyelang/bayes-therapy.pl +4 -4
  6. package/examples/eyelang/output/basic-monadic.pl +1314 -1314
  7. package/examples/eyelang/output/path-discovery.pl +3 -3
  8. package/examples/eyelang/output/reusable-builtins.pl +5 -0
  9. package/examples/eyelang/output/term-tools.pl +6 -0
  10. package/examples/eyelang/path-discovery.pl +22 -7
  11. package/examples/eyelang/reusable-builtins.pl +32 -0
  12. package/examples/eyelang/term-tools.pl +23 -0
  13. package/lib/eyelang/builtins/arithmetic.js +19 -6
  14. package/lib/eyelang/builtins/control.js +12 -0
  15. package/lib/eyelang/builtins/lists.js +146 -7
  16. package/lib/eyelang/builtins/registry.js +2 -4
  17. package/lib/eyelang/builtins/strings.js +165 -1
  18. package/lib/eyelang/builtins/terms.js +66 -0
  19. package/package.json +1 -1
  20. package/test/eyelang/conformance/README.md +1 -1
  21. package/test/eyelang/conformance/cases/extension/036_reusable_numeric_builtins.pl +10 -0
  22. package/test/eyelang/conformance/cases/extension/037_reusable_list_builtins.pl +11 -0
  23. package/test/eyelang/conformance/cases/extension/038_reusable_string_builtins.pl +12 -0
  24. package/test/eyelang/conformance/cases/extension/039_reusable_term_control_builtins.pl +11 -0
  25. package/test/eyelang/conformance/expected/extension/036_reusable_numeric_builtins.out +8 -0
  26. package/test/eyelang/conformance/expected/extension/037_reusable_list_builtins.out +9 -0
  27. package/test/eyelang/conformance/expected/extension/038_reusable_string_builtins.out +10 -0
  28. package/test/eyelang/conformance/expected/extension/039_reusable_term_control_builtins.out +6 -0
  29. package/examples/eyelang/collatz-1000.pl +0 -14
  30. package/examples/eyelang/complex-matrix-stability.pl +0 -45
  31. package/examples/eyelang/dense-hamiltonian-cycle.pl +0 -92
  32. package/examples/eyelang/gcd-bezout-identity.pl +0 -48
  33. package/examples/eyelang/goldbach-1000.pl +0 -185
  34. package/examples/eyelang/hamiltonian-cycle.pl +0 -55
  35. package/examples/eyelang/kaprekar.pl +0 -32
  36. package/examples/eyelang/matrix.pl +0 -296
  37. package/examples/eyelang/n-queens.pl +0 -23
  38. package/examples/eyelang/output/collatz-1000.pl +0 -1000
  39. package/examples/eyelang/output/complex-matrix-stability.pl +0 -5
  40. package/examples/eyelang/output/dense-hamiltonian-cycle.pl +0 -4
  41. package/examples/eyelang/output/gcd-bezout-identity.pl +0 -36
  42. package/examples/eyelang/output/goldbach-1000.pl +0 -667
  43. package/examples/eyelang/output/hamiltonian-cycle.pl +0 -4
  44. package/examples/eyelang/output/kaprekar.pl +0 -8
  45. package/examples/eyelang/output/matrix.pl +0 -10
  46. package/examples/eyelang/output/n-queens.pl +0 -93
  47. package/examples/eyelang/output/quine-mccluskey.pl +0 -3
  48. package/examples/eyelang/output/sat-dpll.pl +0 -5
  49. package/examples/eyelang/output/traveling-salesman.pl +0 -1
  50. package/examples/eyelang/quine-mccluskey.pl +0 -143
  51. package/examples/eyelang/sat-dpll.pl +0 -80
  52. package/examples/eyelang/traveling-salesman.pl +0 -64
  53. package/lib/eyelang/builtins/matrix.js +0 -226
  54. package/lib/eyelang/builtins/number-theory.js +0 -114
  55. package/lib/eyelang/builtins/search.js +0 -519
  56. package/test/eyelang/conformance/cases/extension/036_extended_gcd.pl +0 -3
  57. package/test/eyelang/conformance/cases/extension/037_collatz_trajectory.pl +0 -3
  58. package/test/eyelang/conformance/cases/extension/038_kaprekar_steps.pl +0 -3
  59. package/test/eyelang/conformance/cases/extension/039_goldbach_pair.pl +0 -3
  60. package/test/eyelang/conformance/cases/extension/040_matrix_operations.pl +0 -5
  61. package/test/eyelang/conformance/cases/extension/042_n_queens_small.pl +0 -3
  62. package/test/eyelang/conformance/cases/extension/043_cnf_model.pl +0 -3
  63. package/test/eyelang/conformance/expected/extension/036_extended_gcd.out +0 -1
  64. package/test/eyelang/conformance/expected/extension/037_collatz_trajectory.out +0 -1
  65. package/test/eyelang/conformance/expected/extension/038_kaprekar_steps.out +0 -1
  66. package/test/eyelang/conformance/expected/extension/039_goldbach_pair.out +0 -2
  67. package/test/eyelang/conformance/expected/extension/040_matrix_operations.out +0 -3
  68. package/test/eyelang/conformance/expected/extension/042_n_queens_small.out +0 -2
  69. package/test/eyelang/conformance/expected/extension/043_cnf_model.out +0 -1
@@ -1,296 +0,0 @@
1
- % Matrix operations example, adapted from Eyelet's input/matrix.pl.
2
- %
3
- % The operations and sample cases follow the Trealla output reference from
4
- % Eyelet: determinant, inversion, triangular inversion, multiplication, sum,
5
- % and Cholesky decomposition. Results are derived by generic matrix rules, not
6
- % asserted as output facts.
7
-
8
- % --- small list helpers -----------------------------------------------------
9
-
10
- % Output declarations: materialize/2 selects the relations written to this example's golden output.
11
- materialize(result, 2).
12
- materialize(checksConsistentWithTreallaReference, 2).
13
-
14
- % Program structure: facts set up the scenario, and rules derive the materialized conclusions.
15
- nth0(0, [H|_T], H).
16
- % Derivation rules: each rule below contributes one logical step toward the displayed results.
17
- nth0(N, [_H|T], V) :-
18
- gt(N, 0),
19
- sub(N, 1, N1),
20
- nth0(N1, T, V).
21
-
22
- flatten_matrix([], []).
23
- flatten_matrix([Row|Rows], Flat) :-
24
- flatten_matrix(Rows, Tail),
25
- append(Row, Tail, Flat).
26
-
27
- list0(0, []).
28
- list0(N, [0|T]) :-
29
- gt(N, 0),
30
- sub(N, 1, N1),
31
- list0(N1, T).
32
-
33
- take(0, Rest, [], Rest).
34
- take(N, [H|T], [H|Row], Rest) :-
35
- gt(N, 0),
36
- sub(N, 1, N1),
37
- take(N1, T, Row, Rest).
38
-
39
- identify_rows([], _N, []).
40
- identify_rows(Elems, N, [Row|Rows]) :-
41
- take(N, Elems, Row, Rest),
42
- identify_rows(Rest, N, Rows).
43
-
44
- get_v(I, J, N, Flat, V) :-
45
- mul(I, N, IN),
46
- add(IN, J, E),
47
- nth0(E, Flat, V).
48
-
49
- set_v(I, J, N, Flat, NewFlat, V) :-
50
- mul(I, N, IN),
51
- add(IN, J, E),
52
- set_nth0(E, Flat, V, NewFlat).
53
-
54
- % --- basic matrix operations ------------------------------------------------
55
-
56
- row_sum([], [], []).
57
- row_sum([A|As], [B|Bs], [C|Cs]) :-
58
- add(A, B, C),
59
- row_sum(As, Bs, Cs).
60
-
61
- matrix_sum([[], []], []).
62
- matrix_sum([[RowA|RowsA], [RowB|RowsB]], [Row|Rows]) :-
63
- row_sum(RowA, RowB, Row),
64
- matrix_sum([RowsA, RowsB], Rows).
65
-
66
- row_diff([], [], []).
67
- row_diff([A|As], [B|Bs], [C|Cs]) :-
68
- sub(A, B, C),
69
- row_diff(As, Bs, Cs).
70
-
71
- matrix_diff([], [], []).
72
- matrix_diff([RowA|RowsA], [RowB|RowsB], [Row|Rows]) :-
73
- row_diff(RowA, RowB, Row),
74
- matrix_diff(RowsA, RowsB, Rows).
75
-
76
- row_mult_scal([], _V, []).
77
- row_mult_scal([A|As], V, [B|Bs]) :-
78
- mul(A, V, B),
79
- row_mult_scal(As, V, Bs).
80
-
81
- matrix_mult_scal([], _V, []).
82
- matrix_mult_scal([Row|Rows], V, [Scaled|ScaledRows]) :-
83
- row_mult_scal(Row, V, Scaled),
84
- matrix_mult_scal(Rows, V, ScaledRows).
85
-
86
- row_div_scal([], _V, []).
87
- row_div_scal([A|As], V, [B|Bs]) :-
88
- div(A, V, B),
89
- row_div_scal(As, V, Bs).
90
-
91
- matrix_div_scal([], _V, []).
92
- matrix_div_scal([Row|Rows], V, [Scaled|ScaledRows]) :-
93
- row_div_scal(Row, V, Scaled),
94
- matrix_div_scal(Rows, V, ScaledRows).
95
-
96
- transpose_matrix([], []).
97
- transpose_matrix([[]|_Rows], []).
98
- transpose_matrix(Matrix, [Column|Columns]) :-
99
- first_column(Matrix, Column, Rest),
100
- transpose_matrix(Rest, Columns).
101
-
102
- first_column([], [], []).
103
- first_column([[H|T]|Rows], [H|Hs], [T|Ts]) :-
104
- first_column(Rows, Hs, Ts).
105
-
106
- dot_product([], [], 0).
107
- dot_product([X|Xs], [Y|Ys], D) :-
108
- dot_product(Xs, Ys, Rest),
109
- mul(X, Y, XY),
110
- add(XY, Rest, D).
111
-
112
- row_multiply(_Transposed, [], []).
113
- row_multiply(Transposed, [Row|Rows], [OutRow|OutRows]) :-
114
- row_multiply_columns(Transposed, Row, OutRow),
115
- row_multiply(Transposed, Rows, OutRows).
116
-
117
- row_multiply_columns([], _Row, []).
118
- row_multiply_columns([Column|Columns], Row, [D|Ds]) :-
119
- dot_product(Row, Column, D),
120
- row_multiply_columns(Columns, Row, Ds).
121
-
122
- matrix_multiply([X, Y], M) :-
123
- transpose_matrix(Y, T),
124
- row_multiply(T, X, M).
125
-
126
- % --- Cholesky decomposition -------------------------------------------------
127
-
128
- cholesky_decomposition(A, L) :-
129
- flatten_matrix(A, FlatA),
130
- length(FlatA, FlatLen),
131
- list0(FlatLen, Work0),
132
- length(A, N),
133
- cholesky_i(0, N, FlatA, Work0, Work),
134
- identify_rows(Work, N, L).
135
-
136
- cholesky_i(I, N, _A, L, L) :-
137
- ge(I, N).
138
- cholesky_i(I, N, A, L, LOut) :-
139
- lt(I, N),
140
- cholesky_j(0, I, N, A, L, L1),
141
- add(I, 1, I1),
142
- cholesky_i(I1, N, A, L1, LOut).
143
-
144
- cholesky_j(J, I, N, A, L, LOut) :-
145
- eq(J, I),
146
- cholesky_k(0, I, I, N, 0, S, L),
147
- get_v(I, I, N, A, Aii),
148
- sub(Aii, S, V2),
149
- pow(V2, 0.5, V),
150
- set_v(I, I, N, L, LOut, V).
151
- cholesky_j(J, I, N, A, L, LOut) :-
152
- lt(J, I),
153
- cholesky_k(0, J, I, N, 0, S, L),
154
- get_v(I, J, N, A, Aij),
155
- get_v(J, J, N, L, Ljj),
156
- sub(Aij, S, Numerator),
157
- div(Numerator, Ljj, V),
158
- set_v(I, J, N, L, L1, V),
159
- add(J, 1, J1),
160
- cholesky_j(J1, I, N, A, L1, LOut).
161
-
162
- cholesky_k(K, J, _I, _N, S, S, _L) :-
163
- ge(K, J).
164
- cholesky_k(K, J, I, N, S0, S, L) :-
165
- lt(K, J),
166
- get_v(I, K, N, L, Lik),
167
- get_v(J, K, N, L, Ljk),
168
- mul(Lik, Ljk, Product),
169
- add(S0, Product, S1),
170
- add(K, 1, K1),
171
- cholesky_k(K1, J, I, N, S1, S, L).
172
-
173
- % --- determinant and inversion ---------------------------------------------
174
-
175
- get_diagonal(Matrix, Diagonal) :-
176
- length(Matrix, N),
177
- get_diag(0, N, Matrix, Diagonal).
178
-
179
- get_diag(I, N, _Matrix, []) :-
180
- ge(I, N).
181
- get_diag(I, N, Matrix, [V|Vs]) :-
182
- lt(I, N),
183
- nth0(I, Matrix, Row),
184
- nth0(I, Row, V),
185
- add(I, 1, I1),
186
- get_diag(I1, N, Matrix, Vs).
187
-
188
- prod_list([], 1).
189
- prod_list([A|As], P) :-
190
- prod_list(As, P0),
191
- mul(A, P0, P).
192
-
193
- determinant(A, Det) :-
194
- cholesky_decomposition(A, L),
195
- get_diagonal(L, Diagonal),
196
- prod_list(Diagonal, DetL),
197
- mul(DetL, DetL, Det).
198
-
199
- matrix_inv_triang(L, Inv) :-
200
- length(L, N),
201
- build_inv_rows(0, N, L, [], Inv).
202
-
203
- build_inv_rows(I, N, _L, _Previous, []) :-
204
- ge(I, N).
205
- build_inv_rows(I, N, L, Previous, [Row|Rows]) :-
206
- lt(I, N),
207
- build_inv_row(0, N, I, L, Previous, Row),
208
- append(Previous, [Row], NextPrevious),
209
- add(I, 1, I1),
210
- build_inv_rows(I1, N, L, NextPrevious, Rows).
211
-
212
- build_inv_row(J, N, _I, _L, _Previous, []) :-
213
- ge(J, N).
214
- build_inv_row(J, N, I, L, Previous, [V|Vs]) :-
215
- lt(J, N),
216
- lower_inverse_value(I, J, N, L, Previous, V),
217
- add(J, 1, J1),
218
- build_inv_row(J1, N, I, L, Previous, Vs).
219
-
220
- lower_inverse_value(I, J, _N, _L, _Previous, 0) :-
221
- gt(J, I).
222
- lower_inverse_value(I, J, N, L, _Previous, V) :-
223
- eq(I, J),
224
- nth0(I, L, Row),
225
- nth0(I, Row, Diagonal),
226
- div(1.0, Diagonal, V).
227
- lower_inverse_value(I, J, N, L, Previous, V) :-
228
- lt(J, I),
229
- sum_lower_inverse(J, I, J, N, L, Previous, 0, Sum),
230
- neg(Sum, NegSum),
231
- nth0(I, L, Row),
232
- nth0(I, Row, Diagonal),
233
- div(NegSum, Diagonal, V).
234
-
235
- sum_lower_inverse(K, I, _J, _N, _L, _Previous, Sum, Sum) :-
236
- ge(K, I).
237
- sum_lower_inverse(K, I, J, N, L, Previous, Sum0, Sum) :-
238
- lt(K, I),
239
- nth0(I, L, RowI),
240
- nth0(K, RowI, Lik),
241
- nth0(K, Previous, InvRowK),
242
- nth0(J, InvRowK, InvKj),
243
- mul(Lik, InvKj, Product),
244
- add(Sum0, Product, Sum1),
245
- add(K, 1, K1),
246
- sum_lower_inverse(K1, I, J, N, L, Previous, Sum1, Sum).
247
-
248
- matrix_inversion(A, B) :-
249
- cholesky_decomposition(A, L),
250
- matrix_inv_triang(L, LI),
251
- transpose_matrix(LI, LIT),
252
- matrix_multiply([LIT, LI], B).
253
-
254
- % --- sample cases mirroring Eyelet's Trealla reference output ---------------
255
-
256
- case(det3, determinant, [[2, -1, 0], [-1, 2, -1], [0, -1, 2]]).
257
- case(inv3, matrix_inversion, [[2, -1, 0], [-1, 2, -1], [0, -1, 2]]).
258
- case(inv4, matrix_inversion, [[18, 22, 54, 42], [22, 70, 86, 62], [54, 86, 174, 134], [42, 62, 134, 106]]).
259
- case(invtri3, matrix_inv_triang, [[2, 0, 0], [-1, 2, 0], [0, -1, 2]]).
260
- case(mul_small, matrix_multiply, [[[1, 2], [3, 4], [5, 6]], [[1, 1, 1], [1, 1, 1]]]).
261
- case(mul_identity_check, matrix_multiply, [[[18, 22, 54, 42], [22, 70, 86, 62], [54, 86, 174, 134], [42, 62, 134, 106]], [[2.515624999999984, 0.4843749999999933, -1.296874999999973, 0.3593749999999767], [0.4843749999999933, 0.1406249999999978, -0.3281249999999918, 0.1406249999999936], [-1.296874999999973, -0.3281249999999918, 1.015624999999971, -0.5781249999999781], [0.3593749999999767, 0.1406249999999936, -0.5781249999999781, 0.5156249999999853]]]).
262
- case(sum_small, matrix_sum, [[[1, 2], [3, 4], [5, 6]], [[1, 2], [3, 4], [5, 6]]]).
263
- case(chol3, cholesky_decomposition, [[25, 15, -5], [15, 18, 0], [-5, 0, 11]]).
264
- case(chol4, cholesky_decomposition, [[18, 22, 54, 42], [22, 70, 86, 62], [54, 86, 174, 134], [42, 62, 134, 106]]).
265
-
266
- result(Case, determinant(Matrix, Det)) :-
267
- case(Case, determinant, Matrix),
268
- determinant(Matrix, Det).
269
-
270
- result(Case, matrix_inversion(Matrix, Inverse)) :-
271
- case(Case, matrix_inversion, Matrix),
272
- matrix_inversion(Matrix, Inverse).
273
-
274
- result(Case, matrix_inv_triang(Matrix, Inverse)) :-
275
- case(Case, matrix_inv_triang, Matrix),
276
- matrix_inv_triang(Matrix, Inverse).
277
-
278
- result(Case, matrix_multiply(Inputs, Product)) :-
279
- case(Case, matrix_multiply, Inputs),
280
- matrix_multiply(Inputs, Product).
281
-
282
- result(Case, matrix_sum(Inputs, Sum)) :-
283
- case(Case, matrix_sum, Inputs),
284
- matrix_sum(Inputs, Sum).
285
-
286
- result(Case, cholesky_decomposition(Matrix, L)) :-
287
- case(Case, cholesky_decomposition, Matrix),
288
- cholesky_decomposition(Matrix, L).
289
-
290
- checksConsistentWithTreallaReference(matrix, true) :-
291
- determinant([[2, -1, 0], [-1, 2, -1], [0, -1, 2]], Det),
292
- gt(Det, 3.9999),
293
- lt(Det, 4.0001),
294
- matrix_multiply([[[1, 2], [3, 4], [5, 6]], [[1, 1, 1], [1, 1, 1]]], [[3, 3, 3], [7, 7, 7], [11, 11, 11]]),
295
- matrix_sum([[[1, 2], [3, 4], [5, 6]], [[1, 2], [3, 4], [5, 6]]], [[2, 4], [6, 8], [10, 12]]),
296
- cholesky_decomposition([[25, 15, -5], [15, 18, 0], [-5, 0, 11]], [[5.0, 0, 0], [3.0, 3.0, 0], [-1.0, 1.0, 3.0]]).
@@ -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).