eyelang 1.7.11 → 1.7.12
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 +1 -1
- package/docs/guide.md +1 -1
- package/examples/stirling-bell-numbers.eye +50 -13
- package/package.json +2 -2
- package/test/run-regression.mjs +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/eyelang)
|
|
4
4
|
[](https://doi.org/10.5281/zenodo.20761726)
|
|
5
5
|
|
|
6
|
-
Eyelang is a small logic programming language for rules, goals, answers, and proofs.
|
|
6
|
+
Eyelang is a small logic programming language for facts, rules, goals, answers, and proofs.
|
|
7
7
|
Its source syntax is Prolog-like Horn-clause syntax with deliberate eyelang choices, including `?x` variables for N3/SPARQL-style readability, explicit `table(path, 2).` declarations for tabled predicates, advisory `mode/3` declarations for host tooling, explicit Herbrand witness terms for executable existential-style consequences, and stratified-negation diagnostics for portable `not/1` usage.
|
|
8
8
|
It grew out of logic-language experiments in the EYE/N3 reasoning tradition, but is packaged here as its own project.
|
|
9
9
|
|
package/docs/guide.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Eyelang Guide
|
|
2
2
|
|
|
3
|
-
This guide introduces Eyelang, a small Horn-clause language and engine whose source syntax is Prolog-like but deliberately its own compact language for rules, goals, answers, and proofs. Eyelang works over ordinary terms, lists, arithmetic, strings, and finite search. Run it with the `eyelang` CLI, or use `node bin/eyelang.js` when working directly from a source checkout.
|
|
3
|
+
This guide introduces Eyelang, a small Horn-clause language and engine whose source syntax is Prolog-like but deliberately its own compact language for facts, rules, goals, answers, and proofs. Eyelang works over ordinary terms, lists, arithmetic, strings, and finite search. Run it with the `eyelang` CLI, or use `node bin/eyelang.js` when working directly from a source checkout.
|
|
4
4
|
|
|
5
5
|
Programs write relations directly, for example `ancestor(pat, emma)` or `status(case1, accepted)`. Absolute IRI atoms can be written explicitly with angle brackets, for example `<https://schema.org/name>`, when a program needs web identifiers without prefix declarations. Eyelang output is ordinary Eyelang syntax: by default, the CLI materializes selected answer facts and prints those facts only. Pass `--proof` (or `-p`) when you also want each answer followed by a `why/2` explanation fact that records the proof. Programs may add `materialize/2` declarations such as `materialize(answer, 2).` to focus output on selected predicates.
|
|
6
6
|
|
|
@@ -1,30 +1,67 @@
|
|
|
1
1
|
% Stirling numbers of the second kind and Bell numbers.
|
|
2
2
|
%
|
|
3
|
-
%
|
|
4
|
-
%
|
|
5
|
-
%
|
|
6
|
-
%
|
|
3
|
+
% The Stirling count S(N,K) is computed with the inclusion-exclusion formula
|
|
4
|
+
% S(N,K) = (1/K!) * sum(I=0..K, (-1)^(K-I) * C(K,I) * I^N)
|
|
5
|
+
% instead of the overlapping two-branch recurrence. Bell numbers use
|
|
6
|
+
% B(0) = 1, B(N) = sum(K=0..N-1, C(N-1,K) * B(K)).
|
|
7
|
+
% The table declarations memoize the smaller helper relations used by both formulas.
|
|
7
8
|
materialize(stirling_bell_answer, 2).
|
|
8
9
|
|
|
10
|
+
table(factorial, 2).
|
|
11
|
+
table(binomial, 3).
|
|
9
12
|
table(stirling2, 3).
|
|
13
|
+
table(bell, 2).
|
|
14
|
+
|
|
15
|
+
factorial(0, 1).
|
|
16
|
+
factorial(?n, ?value) :-
|
|
17
|
+
gt(?n, 0),
|
|
18
|
+
sub(?n, 1, ?n1),
|
|
19
|
+
factorial(?n1, ?previous),
|
|
20
|
+
mul(?n, ?previous, ?value).
|
|
21
|
+
|
|
22
|
+
binomial(0, 0, 1).
|
|
23
|
+
binomial(?n, 0, 1) :- gt(?n, 0).
|
|
24
|
+
binomial(?n, ?n, 1) :- gt(?n, 0).
|
|
25
|
+
binomial(?n, ?k, ?value) :-
|
|
26
|
+
gt(?n, 0),
|
|
27
|
+
gt(?k, 0),
|
|
28
|
+
lt(?k, ?n),
|
|
29
|
+
sub(?n, 1, ?n1),
|
|
30
|
+
sub(?k, 1, ?k1),
|
|
31
|
+
binomial(?n1, ?k1, ?left),
|
|
32
|
+
binomial(?n1, ?k, ?right),
|
|
33
|
+
add(?left, ?right, ?value).
|
|
34
|
+
|
|
35
|
+
signed_term(?n, ?k, ?i, ?term) :-
|
|
36
|
+
binomial(?k, ?i, ?c),
|
|
37
|
+
pow(?i, ?n, ?p),
|
|
38
|
+
mul(?c, ?p, ?unsigned),
|
|
39
|
+
sub(?k, ?i, ?d),
|
|
40
|
+
mod(?d, 2, 0),
|
|
41
|
+
eq(?term, ?unsigned).
|
|
42
|
+
signed_term(?n, ?k, ?i, ?term) :-
|
|
43
|
+
binomial(?k, ?i, ?c),
|
|
44
|
+
pow(?i, ?n, ?p),
|
|
45
|
+
mul(?c, ?p, ?unsigned),
|
|
46
|
+
sub(?k, ?i, ?d),
|
|
47
|
+
mod(?d, 2, 1),
|
|
48
|
+
neg(?unsigned, ?term).
|
|
10
49
|
|
|
11
|
-
% Boundary cases define the empty partition and the impossible zero-block columns.
|
|
12
50
|
stirling2(0, 0, 1).
|
|
13
51
|
stirling2(?n, 0, 0) :- gt(?n, 0).
|
|
14
52
|
stirling2(0, ?k, 0) :- gt(?k, 0).
|
|
15
53
|
stirling2(?n, ?k, ?count) :-
|
|
16
54
|
gt(?n, 0),
|
|
17
55
|
gt(?k, 0),
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
stirling2(?n1, ?k, ?existingblocks),
|
|
22
|
-
mul(?k, ?existingblocks, ?extended),
|
|
23
|
-
add(?newblock, ?extended, ?count).
|
|
56
|
+
sumall(?term, (between(0, ?k, ?i), signed_term(?n, ?k, ?i, ?term)), ?sum),
|
|
57
|
+
factorial(?k, ?factorial),
|
|
58
|
+
div(?sum, ?factorial, ?count).
|
|
24
59
|
|
|
25
|
-
|
|
60
|
+
bell(0, 1).
|
|
26
61
|
bell(?n, ?count) :-
|
|
27
|
-
|
|
62
|
+
gt(?n, 0),
|
|
63
|
+
sub(?n, 1, ?n1),
|
|
64
|
+
sumall(?term, (between(0, ?n1, ?k), binomial(?n1, ?k, ?choose), bell(?k, ?bell), mul(?choose, ?bell, ?term)), ?count).
|
|
28
65
|
|
|
29
66
|
stirling_bell_answer(stirling_10_4, ?count) :- stirling2(10, 4, ?count).
|
|
30
67
|
stirling_bell_answer(stirling_12_5, ?count) :- stirling2(12, 5, ?count).
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eyelang",
|
|
3
|
-
"version": "1.7.
|
|
4
|
-
"description": "A small Prolog-like logic programming language for rules, goals, answers, and proofs.",
|
|
3
|
+
"version": "1.7.12",
|
|
4
|
+
"description": "A small Prolog-like logic programming language for facts, rules, goals, answers, and proofs.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
|
7
7
|
"types": "./index.d.ts",
|
package/test/run-regression.mjs
CHANGED
|
@@ -800,7 +800,7 @@ function whiteBoxCases() {
|
|
|
800
800
|
['matrix-chain-order.eye', 'cost', 3, false],
|
|
801
801
|
['modular-exponentiation.eye', 'pow_mod', 4, true],
|
|
802
802
|
['pell-equation.eye', 'pell', 3, true],
|
|
803
|
-
['stirling-bell-numbers.eye', 'stirling2', 3,
|
|
803
|
+
['stirling-bell-numbers.eye', 'stirling2', 3, false],
|
|
804
804
|
['totient-summatory.eye', 'gcd', 3, true],
|
|
805
805
|
['totient-summatory.eye', 'totient', 2, false],
|
|
806
806
|
['weighted-interval-scheduling.eye', 'best_from', 2, true],
|