eyemind 0.5.23 → 0.5.24
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 +2 -2
- package/SPEC.md +30 -9
- package/package.json +1 -1
- package/src/closure.js +52 -3
- package/src/fidelity.js +12 -4
- package/src/version.js +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ eyemind is a **JavaScript rule language** with forward and backward reasoning an
|
|
|
7
7
|
|
|
8
8
|
[Playground](https://eyereasoner.github.io/eyemind/playground/) · [Specification](https://eyereasoner.github.io/eyemind/SPEC) · [Conformance](https://eyereasoner.github.io/eyemind/conformance/) · [Examples](https://eyereasoner.github.io/eyemind/examples/)
|
|
9
9
|
|
|
10
|
-
The playground runs programs in your browser; the specification defines the language, its canonical text, the proof format and the C1–C10 checks. The examples are 135 runnable programs, each with a card deck and saved conclusions, proofs and check reports. The conformance suite has
|
|
10
|
+
The playground runs programs in your browser; the specification defines the language, its canonical text, the proof format and the C1–C10 checks. The examples are 135 runnable programs, each with a card deck and saved conclusions, proofs and check reports. The conformance suite has 1384 cases that test any implementation of the specification through its command line; run it [in your browser](https://eyereasoner.github.io/eyemind/playground/conformance).
|
|
11
11
|
|
|
12
12
|
## Contents
|
|
13
13
|
|
|
@@ -480,7 +480,7 @@ A negation `not(G)` concludes from what is *absent* and a collection `findall(T,
|
|
|
480
480
|
- **Negate only what is bound.** The variables of `not(G)` must be bound when it runs; write `not(q(X, _))` for "no value at all".
|
|
481
481
|
- **Check the search, not just its result.** A proof ends with a search certificate: `searched(Call, Answers)` lists each call's answers and `derived(Pattern, Facts)` each consulted relation. The checker expands each call one level against the program, so a wrong table shows up as a disagreement.
|
|
482
482
|
- **Say what was taken on trust.** Anything the certificate cannot settle becomes an obligation, and evidence in the proof can still refute it (C6).
|
|
483
|
-
- **Certify the original questions.** Supported, closed listings establish the original calls, and that the claims are all their answers, when no rule they depend on can observe bindings or evaluation order. A mode analysis checks this: primitives such as arithmetic run with their inputs bound, negations with their variables bound, and `once` and `findall` bind nothing other goals use. Where it does not apply, as for tests of whether a variable is bound, the checker replays each derived fact's recorded firing in source order instead. A proof within these bounds can be `checked` with no obligation, even under `--strict-proof`. Collections and first answers over derived facts, whose order a listing cannot show,
|
|
483
|
+
- **Certify the original questions.** Supported, closed listings establish the original calls, and that the claims are all their answers, when no rule they depend on can observe bindings or evaluation order. A mode analysis checks this: primitives such as arithmetic run with their inputs bound, negations with their variables bound, and `once` and `findall` bind nothing other goals use. Where it does not apply, as for tests of whether a variable is bound, the checker replays each derived fact's recorded firing in source order instead. A proof within these bounds can be `checked` with no obligation, even under `--strict-proof`. Rules generated by templates are checked through their instances. Collections and first answers over derived facts, whose order a listing cannot show, and `restricted` rules with new witnesses keep an obligation.
|
|
484
484
|
|
|
485
485
|
## Checking the translation
|
|
486
486
|
|
package/SPEC.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
```text
|
|
4
4
|
Title: The eyemind Rule Language and Proof Format
|
|
5
|
-
Version: eyemind 0.5.
|
|
5
|
+
Version: eyemind 0.5.24
|
|
6
6
|
```
|
|
7
7
|
|
|
8
8
|
This document specifies the syntax and meaning of eyemind programs and data
|
|
@@ -2040,6 +2040,18 @@ clause order. Search each rule's body in its place, answering inner calls
|
|
|
2040
2040
|
as above. Each table MUST equal its expansion: the same number of answers,
|
|
2041
2041
|
each identical up to variable renaming to the answer in the same position.
|
|
2042
2042
|
|
|
2043
|
+
A backward rule appended by a template ([Section 6.2](#62-inline-rule-templates))
|
|
2044
|
+
answers through its instances. A rule whose enclosing generators are not
|
|
2045
|
+
all in the program has none. Otherwise, search the generator's part of its
|
|
2046
|
+
body first, with none of the call's bindings, and take its solutions in
|
|
2047
|
+
order, skipping a solution whose captured values are identical to an
|
|
2048
|
+
earlier one's. For each, unify the call with the head and search the
|
|
2049
|
+
template's part of the body. This is the order in which the run made the
|
|
2050
|
+
instances only when the generator's search consults no table and no
|
|
2051
|
+
listing, and its generators have no guard and introduce no witnesses;
|
|
2052
|
+
otherwise the search is unsettled. Captured values that are not ground
|
|
2053
|
+
also leave it unsettled.
|
|
2054
|
+
|
|
2043
2055
|
The boundary **rests on** every table and listing its search consults,
|
|
2044
2056
|
including those consulted transitively by table expansions and listing
|
|
2045
2057
|
closure checks. No table it rests on may depend on itself through the
|
|
@@ -2072,10 +2084,14 @@ requires:
|
|
|
2072
2084
|
closure check uses a table whose answers rest on a forward listing.
|
|
2073
2085
|
This format checks support and closure of derived facts, but cannot
|
|
2074
2086
|
establish their publication order for order-sensitive operations.
|
|
2075
|
-
- The search reaches
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2087
|
+
- The search reaches no source inspection.
|
|
2088
|
+
- No consulted listing's relation is concluded by a forward rule within a
|
|
2089
|
+
template's scope ([Section 6.2](#62-inline-rule-templates)) that
|
|
2090
|
+
introduces witnesses, or whose generators have a guard or introduce
|
|
2091
|
+
witnesses. A rule appended by a template fires once for each instance, so
|
|
2092
|
+
closure searches its whole body, generator's part first. A rule whose
|
|
2093
|
+
enclosing generators are not all in the program never fires, and closure
|
|
2094
|
+
skips it.
|
|
2079
2095
|
|
|
2080
2096
|
For example, the saved
|
|
2081
2097
|
[Nixon diamond proof](https://eyereasoner.github.io/eyemind/examples/proof/nixon-diamond.js)
|
|
@@ -2255,8 +2271,10 @@ this analysis.
|
|
|
2255
2271
|
|
|
2256
2272
|
**Replayed listings.** A listing the mode analysis does not support still
|
|
2257
2273
|
supports C10 when every fact of every consulted listing **replays**. A fact
|
|
2258
|
-
replays when its step cites a forward rule
|
|
2259
|
-
|
|
2274
|
+
replays when its step cites a forward rule that is not restricted, does
|
|
2275
|
+
not introduce witnesses within a template's scope, and, if appended by a
|
|
2276
|
+
template, has all its enclosing generators in the program, none with a
|
|
2277
|
+
guard or witnesses; and when a search of that rule's body in
|
|
2260
2278
|
source order, starting with no bindings, solves each body goal as the
|
|
2261
2279
|
step's corresponding use records:
|
|
2262
2280
|
|
|
@@ -2271,11 +2289,14 @@ step's corresponding use records:
|
|
|
2271
2289
|
with the use.
|
|
2272
2290
|
- `call/1` and a disjunction replay the goals their `'control'` step uses,
|
|
2273
2291
|
for a disjunction from the side those uses form.
|
|
2274
|
-
- A call to an ordinary relation follows the use's step
|
|
2292
|
+
- A call to an ordinary relation follows the use's step, whose rule MUST
|
|
2293
|
+
meet the conditions above other than direction. A forward rule's
|
|
2275
2294
|
conclusion MUST itself replay, and is then unified with the goal. A
|
|
2276
2295
|
source fact, renamed apart, is unified with the goal. A backward rule,
|
|
2277
2296
|
renamed apart, has its head unified with the goal and its body replayed
|
|
2278
|
-
against its step's uses.
|
|
2297
|
+
against its step's uses. For a backward rule appended by a template, the
|
|
2298
|
+
generator's part of the body replays first, before the head meets the
|
|
2299
|
+
goal, and the template's part after. A use with no step is unified with a source fact
|
|
2279
2300
|
of the relation, renamed apart. A replay that meets the same use under
|
|
2280
2301
|
the same call again does not replay.
|
|
2281
2302
|
- After each goal, the goal MUST still unify with its use, since a step
|
package/package.json
CHANGED
package/src/closure.js
CHANGED
|
@@ -43,6 +43,16 @@ function instanceOf(term, pattern) {
|
|
|
43
43
|
return unify(pattern, term, env) && variant(copyResolved(term, env)) === variant(term);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
// Whether the generators of a rule appended by a template fire as ordinary
|
|
47
|
+
// rules: no restricted guard, whose firings depend on the order of rule
|
|
48
|
+
// applications, and no witnesses, which the derived rule would share.
|
|
49
|
+
export function plainGenerators(program, clause) {
|
|
50
|
+
return clause.scopeIds.every((id) => {
|
|
51
|
+
const generator = program.byId.get(id);
|
|
52
|
+
return !generator || (generator.guard === null && !generator.witnessNames.length);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
46
56
|
// The name and arity of every relation a forward rule concludes.
|
|
47
57
|
export function forwardKeys(program) {
|
|
48
58
|
const keys = new Set();
|
|
@@ -239,14 +249,46 @@ export class Settler {
|
|
|
239
249
|
const clauses = this.program.hasTemplates ? this.program.groups.get(goalKey) || []
|
|
240
250
|
: this.program.candidates(call, env, goalKey);
|
|
241
251
|
for (const clause of clauses) {
|
|
242
|
-
|
|
243
|
-
|
|
252
|
+
if (clause.parentId !== null) {
|
|
253
|
+
yield* this.instances(clause, call, env, reliance);
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
244
256
|
const [head, body] = freshClause(clause, `clause${++this.serial}`);
|
|
245
257
|
if (unify(call, head, env)) yield* this.solveAll(body, 0, env, reliance);
|
|
246
258
|
env.undo(mark);
|
|
247
259
|
}
|
|
248
260
|
}
|
|
249
261
|
|
|
262
|
+
// A backward rule appended by a template answers through its instances:
|
|
263
|
+
// one for each solution of its generator's body with captures not met
|
|
264
|
+
// before, in the order the generator found them, each searching only the
|
|
265
|
+
// template's body. The generator ran with none of the caller's bindings,
|
|
266
|
+
// so its body is solved before the head meets the call. Its order is the
|
|
267
|
+
// order of the run only when it consults no derived facts or tables.
|
|
268
|
+
* instances(clause, call, env, reliance) {
|
|
269
|
+
// Without its generator in the program, a rule has no instances.
|
|
270
|
+
if (!clause.scopeIds.every((id) => this.program.byId.has(id))) return;
|
|
271
|
+
if (!plainGenerators(this.program, clause)) throw new Unsettled();
|
|
272
|
+
const mark = env.mark();
|
|
273
|
+
const [head, body, names] = freshClause(clause, `clause${++this.serial}`);
|
|
274
|
+
const captures = listFromItems(clause.captures.map((name) => names.get(name) ?? new Var(name)));
|
|
275
|
+
const generator = new Reliance();
|
|
276
|
+
const seen = new Set();
|
|
277
|
+
for (const _ of this.solveAll(body.slice(0, clause.prefixLength), 0, env, generator)) { // eslint-disable-line no-unused-vars
|
|
278
|
+
if (generator.tables.size || generator.listings.size) throw new Unsettled();
|
|
279
|
+
const values = copyResolved(captures, env);
|
|
280
|
+
if (!isGround(values)) throw new Unsettled();
|
|
281
|
+
const id = identity(values);
|
|
282
|
+
if (seen.has(id)) continue;
|
|
283
|
+
seen.add(id);
|
|
284
|
+
const inner = env.mark();
|
|
285
|
+
if (unify(call, head, env)) yield* this.solveAll(body.slice(clause.prefixLength), 0, env, reliance);
|
|
286
|
+
env.undo(inner);
|
|
287
|
+
}
|
|
288
|
+
if (generator.tables.size || generator.listings.size) throw new Unsettled();
|
|
289
|
+
env.undo(mark);
|
|
290
|
+
}
|
|
291
|
+
|
|
250
292
|
* solveAll(goals, index, env, reliance) {
|
|
251
293
|
if (index === goals.length) {
|
|
252
294
|
yield;
|
|
@@ -325,7 +367,14 @@ export class Settler {
|
|
|
325
367
|
}
|
|
326
368
|
for (const rule of this.program.forward) {
|
|
327
369
|
if (!rule.plainHeads.some((head) => isCallable(head) && key(head) === goalKey)) continue;
|
|
328
|
-
|
|
370
|
+
// Without its generator in the program, an appended rule never fires.
|
|
371
|
+
if (!rule.scopeIds.every((id) => this.program.byId.has(id))) continue;
|
|
372
|
+
if (!plainGenerators(this.program, rule)) throw new Unsettled();
|
|
373
|
+
// A rule appended by a template fires once for each instance, so as a
|
|
374
|
+
// rule over facts it is its full body. Witnesses that depend on a
|
|
375
|
+
// captured context are not recomputed here.
|
|
376
|
+
if ((rule.parentId === null && rule.captures !== null) ||
|
|
377
|
+
((rule.parentId !== null || rule.templates.length) && rule.witnessNames.length)) throw new Unsettled();
|
|
329
378
|
const missing = this.closes(rule, goalKey, listed, entry.reliance);
|
|
330
379
|
if (missing !== null) {
|
|
331
380
|
entry.failure = `derived facts of ${goalKey} leave out ${text(missing)}, which clause ${rule.id} derives`;
|
package/src/fidelity.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// each claim is an answer, and each answer is claimed. Unlike logical steps,
|
|
3
3
|
// these searches start before a final substitution.
|
|
4
4
|
import { PRIMITIVE_KEYS, primitive } from './builtins.js';
|
|
5
|
-
import { Settler } from './closure.js';
|
|
5
|
+
import { Settler, plainGenerators } from './closure.js';
|
|
6
6
|
import { freshClause, text, variant } from './common.js';
|
|
7
7
|
import { goalTerm } from './goals.js';
|
|
8
8
|
import { INSPECTION_KEYS } from './inspection.js';
|
|
@@ -226,8 +226,12 @@ export function replayed(program, settler, listingKeys, stepOf) {
|
|
|
226
226
|
const active = new Set();
|
|
227
227
|
let serial = 0;
|
|
228
228
|
const fresh = (term) => freshTerm(term, `replay${++serial}`);
|
|
229
|
-
|
|
230
|
-
|
|
229
|
+
// A rule appended by a template replays as its full body, generator first.
|
|
230
|
+
// Witnesses that depend on a captured context are not recomputed here.
|
|
231
|
+
const supportedRule = (clause) => clause && clause.guard === null &&
|
|
232
|
+
clause.scopeIds.every((id) => program.byId.has(id)) && plainGenerators(program, clause) &&
|
|
233
|
+
(clause.parentId !== null || clause.captures === null) &&
|
|
234
|
+
!((clause.parentId !== null || clause.templates.length) && clause.witnessNames.length);
|
|
231
235
|
function compatible(goal, use, env) {
|
|
232
236
|
const mark = env.mark();
|
|
233
237
|
const agrees = unify(goal, fresh(use), env);
|
|
@@ -292,7 +296,11 @@ export function replayed(program, settler, listingKeys, stepOf) {
|
|
|
292
296
|
const call = `${text(use)} ${text(copyResolved(goal, env))}`;
|
|
293
297
|
if (active.has(call)) return false;
|
|
294
298
|
active.add(call);
|
|
295
|
-
|
|
299
|
+
// A generator ran before any caller: its premises replay before the head
|
|
300
|
+
// meets the call.
|
|
301
|
+
const prefix = clause.prefixLength;
|
|
302
|
+
const solved = step.uses.length === body.length && all(body.slice(0, prefix), step.uses.slice(0, prefix), env) &&
|
|
303
|
+
unify(goal, head, env) && all(body.slice(prefix), step.uses.slice(prefix), env) && compatible(goal, use, env);
|
|
296
304
|
active.delete(call);
|
|
297
305
|
return solved;
|
|
298
306
|
}
|
package/src/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// The release this checkout is; ./release keeps it in step with package.json.
|
|
2
|
-
export const VERSION = '0.5.
|
|
2
|
+
export const VERSION = '0.5.24';
|