eyeprolog 1.3.4 → 1.3.7
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 +66 -0
- package/examples/book/README.md +2 -1
- package/examples/book/chapter-07/02-move.pl +4 -0
- package/index.d.ts +7 -0
- package/package.json +1 -1
- package/src/datalog.js +354 -0
- package/src/iso.js +107 -9
- package/src/program.js +258 -20
- package/src/solver.js +841 -41
- package/src/standard-library.js +5 -0
- package/src/term.js +1 -1
- package/src/wfs.js +338 -0
- package/test/conformance/ISO-COMPLIANCE.md +2 -1
- package/test/conformance/README.md +4 -1
- package/test/run-regression.mjs +188 -1
- package/the-art-of-eyeprolog.md +70 -8
- package/why-eyeprolog.md +17 -0
- /package/examples/book/chapter-07/{02-all_tests_pass.pl → 03-all_tests_pass.pl} +0 -0
package/the-art-of-eyeprolog.md
CHANGED
|
@@ -1121,13 +1121,36 @@ particular user is unblocked.
|
|
|
1121
1121
|
<figcaption>Absence becomes informative only inside a declared complete boundary: Clara is allowed because the event registry is complete and she is not on its blocked list.</figcaption>
|
|
1122
1122
|
</figure>
|
|
1123
1123
|
|
|
1124
|
-
|
|
1125
|
-
negate it from a higher layer. Use `--warnings`
|
|
1124
|
+
For ordinary `\+/1`, negative dependencies should normally be stratified:
|
|
1125
|
+
compute a lower relation, then negate it from a higher layer. Use `--warnings`
|
|
1126
|
+
to report negative recursion:
|
|
1126
1127
|
|
|
1127
1128
|
```sh
|
|
1128
1129
|
eyeprolog --warnings program.pl
|
|
1129
1130
|
```
|
|
1130
1131
|
|
|
1132
|
+
Some finite rule systems intentionally contain recursion through negation. In
|
|
1133
|
+
normal mode, EyeProlog provides explicit `tnot/1` for that case. When the
|
|
1134
|
+
reachable component is finite, function-free, and range-restricted Datalog,
|
|
1135
|
+
cycles through `tnot/1` are evaluated with the well-founded semantics (WFS)
|
|
1136
|
+
rather than ordinary negation-as-failure. WFS has three truth states: true,
|
|
1137
|
+
false, and undefined. A negative cycle may therefore produce a conditional
|
|
1138
|
+
answer instead of forcing an arbitrary true/false choice.
|
|
1139
|
+
|
|
1140
|
+
```eyeprolog
|
|
1141
|
+
move(a, b).
|
|
1142
|
+
move(b, a).
|
|
1143
|
+
win(X) :- move(X, Y), tnot(win(Y)).
|
|
1144
|
+
```
|
|
1145
|
+
|
|
1146
|
+
Here neither `win(a)` nor `win(b)` is unconditionally established; both belong
|
|
1147
|
+
to the undefined part of the well-founded model. EyeProlog exposes undefined
|
|
1148
|
+
WFS answers as conditional successes, including inside finite collectors.
|
|
1149
|
+
Direct calls to `tnot/1` must be ground. In WFS rules, variables occurring in
|
|
1150
|
+
the head or a negated literal must be range-restricted by positive body
|
|
1151
|
+
literals. Ordinary `\+/1` is unchanged, and strict ISO mode does not provide
|
|
1152
|
+
`tnot/1`.
|
|
1153
|
+
|
|
1131
1154
|
Universal checking needs no extension predicate: define the counterexample and
|
|
1132
1155
|
negate it.
|
|
1133
1156
|
|
|
@@ -1574,9 +1597,20 @@ analysis, and other recursive relations with overlapping subproblems.
|
|
|
1574
1597
|
|
|
1575
1598
|
Ordinary goals use indexed depth-first resolution. Positive recursive groups
|
|
1576
1599
|
are tabled automatically. Bound recursive calls reuse answers and cyclic calls
|
|
1577
|
-
iterate toward a fixed point.
|
|
1578
|
-
|
|
1579
|
-
|
|
1600
|
+
iterate toward a fixed point. For sufficiently large finite, function-free
|
|
1601
|
+
Datalog dependency cones, EyeProlog may share one most-general relation table
|
|
1602
|
+
across call variants. This turns an open closure such as `tc(X, Y)` into one
|
|
1603
|
+
finite relation computation rather than many overlapping bound subcomputations;
|
|
1604
|
+
bound consumers can then use indexes over the stored answers. The exact
|
|
1605
|
+
admission policy is an engine optimization, not part of the language contract.
|
|
1606
|
+
Fully open or structurally unbounded recursive programs may retain ordinary
|
|
1607
|
+
resolution.
|
|
1608
|
+
|
|
1609
|
+
Recursive components with negative dependencies are not positive least-fixed-
|
|
1610
|
+
point problems. When such a component uses explicit `tnot/1` and satisfies the
|
|
1611
|
+
finite, range-restricted, function-free Datalog restrictions, EyeProlog instead
|
|
1612
|
+
computes the alternating fixed point of the well-founded semantics. Existing
|
|
1613
|
+
`\+/1` code remains ordinary negation-as-failure.
|
|
1580
1614
|
|
|
1581
1615
|
### Deeper implementation: how clause indexing stays semantic
|
|
1582
1616
|
|
|
@@ -1612,8 +1646,12 @@ eyeprolog --stats examples/observability-log-correlation.pl
|
|
|
1612
1646
|
The reported counters include completed goal lists, calls to the goal solver
|
|
1613
1647
|
and single-goal solver, unification attempts, maximum depth and goal-list size,
|
|
1614
1648
|
deterministic built-in successes and failures, and table fixed-point rounds.
|
|
1615
|
-
|
|
1616
|
-
|
|
1649
|
+
WFS execution additionally reports `wfs_fixpoint_rounds` and
|
|
1650
|
+
`wfs_undefined_answers`. The latter counts undefined-answer observations made
|
|
1651
|
+
while producing query results; it is an execution statistic, not a declaration
|
|
1652
|
+
that those atoms are true. All statistics describe work performed, not logical
|
|
1653
|
+
truth. Compare counters only across equivalent queries and the same
|
|
1654
|
+
implementation version.
|
|
1617
1655
|
|
|
1618
1656
|
Common sources of nontermination are recursive calls made before constraints,
|
|
1619
1657
|
ever-growing terms, infinite open mathematical queries, negative cycles, and
|
|
@@ -1947,6 +1985,8 @@ Part III moved from obtaining answers to trusting them:
|
|
|
1947
1985
|
- a query selects a question; a proof records one successful justification;
|
|
1948
1986
|
- an explicit integrity query identifies input that a host may reject;
|
|
1949
1987
|
- automatic tabling computes fixed points for eligible positive recursion;
|
|
1988
|
+
- explicit `tnot/1` gives eligible finite Datalog components well-founded,
|
|
1989
|
+
three-valued negation without changing ordinary `\+/1`;
|
|
1950
1990
|
- indexing and ready filters improve control without changing intended meaning;
|
|
1951
1991
|
- knowledge engineering separates sources, concepts, decisions, and reasons;
|
|
1952
1992
|
- explicit host boundaries divide input validation from logical derivation;
|
|
@@ -1965,7 +2005,10 @@ turned fixed-point ideas into a goal-directed technique that shares recursive
|
|
|
1965
2005
|
calls and accumulates answers. EyeProlog's automatic positive tabling is smaller
|
|
1966
2006
|
than the general systems in that literature, but inherits their central
|
|
1967
2007
|
insight: remembering a recursive question can change termination without
|
|
1968
|
-
changing what the relation says.
|
|
2008
|
+
changing what the relation says. For finite Datalog with recursion through
|
|
2009
|
+
explicit `tnot/1`, EyeProlog also uses the alternating-fixed-point account of
|
|
2010
|
+
the well-founded semantics so a negative cycle may remain undefined instead of
|
|
2011
|
+
being collapsed into ordinary negation-as-failure.
|
|
1969
2012
|
|
|
1970
2013
|
In parallel, deductive databases asked where facts come from and how derived
|
|
1971
2014
|
claims retain provenance. EyeProlog adopts the expectation that conclusions
|
|
@@ -3556,6 +3599,25 @@ component grows monotonically with newly discovered answers until no rule adds
|
|
|
3556
3599
|
another. The implementation is performing a local, demand-driven fixed-point
|
|
3557
3600
|
calculation.
|
|
3558
3601
|
|
|
3602
|
+
There is an important lifetime distinction between a table that is needed to
|
|
3603
|
+
finish one fixed point and a cache of tables retained for possible later reuse.
|
|
3604
|
+
For recursive grammars invoked through `phrase/2-3`, EyeProlog uses a separate
|
|
3605
|
+
invocation-keyed table scope rather than the caller's general table map. Static
|
|
3606
|
+
analysis also recognizes the normalized DCG form of strict list-tail recursion
|
|
3607
|
+
(for example `... --> [_], ...`). On a new input, such a grammar runs directly
|
|
3608
|
+
without automatic tabling because every recursive call consumes the input and
|
|
3609
|
+
there is no fixed-point cycle to close. This prevents a stream of distinct
|
|
3610
|
+
sequences from constructing a useless suffix-table family for every input.
|
|
3611
|
+
|
|
3612
|
+
The optimization is deliberately asymmetric. If the same `phrase/2-3`
|
|
3613
|
+
invocation repeats, normal tabling is allowed again so the compact completed
|
|
3614
|
+
table from that invocation can serve subsequent repetitions. That is useful for
|
|
3615
|
+
workloads that probe one grammar/input many thousands of times. Only one
|
|
3616
|
+
invocation signature is retained in the phrase scope, completed entries are
|
|
3617
|
+
still subject to a bound, and active fixed points are never evicted. Thus the
|
|
3618
|
+
policy limits cross-call retention without turning each distinct input into an
|
|
3619
|
+
O(cache-size) eviction pass or changing the declarative answers.
|
|
3620
|
+
|
|
3559
3621
|
**Exercises.**
|
|
3560
3622
|
|
|
3561
3623
|
1. Run the triple program with one, two, and three arguments bound. Compare the
|
package/why-eyeprolog.md
CHANGED
|
@@ -31,6 +31,8 @@ keeps a narrow architecture:
|
|
|
31
31
|
|
|
32
32
|
- one parser and term model;
|
|
33
33
|
- one solver with automatic tabling for eligible positive recursion;
|
|
34
|
+
- explicit `tnot/1` with well-founded semantics for finite, range-restricted,
|
|
35
|
+
function-free Datalog components;
|
|
34
36
|
- the ISO built-in registry;
|
|
35
37
|
- lean portable ISO Part 2 library modules;
|
|
36
38
|
- ISO Part 3 definite clause grammars and `phrase/2-3`;
|
|
@@ -43,6 +45,21 @@ relations such as list processing remain ordinary Prolog clauses imported with
|
|
|
43
45
|
standard sorting, arithmetic, meta-calls, streams, and database operations use
|
|
44
46
|
their ISO definitions directly.
|
|
45
47
|
|
|
48
|
+
|
|
49
|
+
## Why keep well-founded negation explicit?
|
|
50
|
+
|
|
51
|
+
Ordinary Prolog `\+/1` is negation-as-failure and remains useful when a closed,
|
|
52
|
+
usually stratified relation has already been computed. Non-stratified rule
|
|
53
|
+
systems need a different semantic choice. EyeProlog therefore does not silently
|
|
54
|
+
change `\+/1`; normal mode provides `tnot/1` for finite Datalog components that
|
|
55
|
+
need the three-valued well-founded semantics. This keeps the extension visible
|
|
56
|
+
in source code and lets strict ISO mode remove it cleanly.
|
|
57
|
+
|
|
58
|
+
The same boundary guides performance work. EyeProlog may evaluate large finite
|
|
59
|
+
positive Datalog closures with a shared relation-wide table, but the admission
|
|
60
|
+
heuristics are implementation details. Programs should rely on the documented
|
|
61
|
+
semantics and finiteness conditions, not on a particular internal threshold.
|
|
62
|
+
|
|
46
63
|
## Why proofs?
|
|
47
64
|
|
|
48
65
|
An answer says that a goal succeeded. A proof records one successful route
|
|
File without changes
|