eyemind 0.5.25 → 0.5.26
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/SPEC.md +23 -10
- package/package.json +1 -1
- package/src/closure.js +22 -8
- package/src/engine.js +0 -1
- package/src/fidelity.js +19 -6
- package/src/proof.js +25 -5
- package/src/version.js +1 -1
package/README.md
CHANGED
|
@@ -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`. Rules generated by templates are checked through their instances. A `findall_sorted` of ground items is certified from the set of derived facts alone. `findall` and first answers over derived facts, whose order a listing cannot show, and `restricted` rules with new witnesses keep an obligation.
|
|
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, and source rule inspection through the program's catalogue of rules. A `findall_sorted` of ground items is certified from the set of derived facts alone. `findall` 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.26
|
|
6
6
|
```
|
|
7
7
|
|
|
8
8
|
This document specifies the syntax and meaning of eyemind programs and data
|
|
@@ -2035,6 +2035,10 @@ separately checks the bindings with which the original question called it.
|
|
|
2035
2035
|
renaming. Rename each answer apart before using it.
|
|
2036
2036
|
- Answer a relation defined by source facts alone from those facts, in
|
|
2037
2037
|
clause order; it needs no table.
|
|
2038
|
+
- Answer an inspection goal from the catalogue of [Section 6.3](#63-source-rule-inspection),
|
|
2039
|
+
in source order, each rule renamed apart; it needs no table.
|
|
2040
|
+
- Use a listed derived pattern ([Section 6.3](#63-source-rule-inspection))
|
|
2041
|
+
renamed apart, as it is freshened at every use.
|
|
2038
2042
|
- Inside this search, negation treats unbound variables as anonymous.
|
|
2039
2043
|
This does not establish that a named variable was bound at the original
|
|
2040
2044
|
call; that is a C10 requirement.
|
|
@@ -2064,12 +2068,18 @@ closure checks. No table it rests on may depend on itself through the
|
|
|
2064
2068
|
tables consulted by its expansion.
|
|
2065
2069
|
|
|
2066
2070
|
**Supporting and closing listings.** Every listed fact MUST have a step,
|
|
2067
|
-
have the listing's name and arity, and be ground
|
|
2068
|
-
|
|
2069
|
-
rule
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2071
|
+
have the listing's name and arity, and be ground, unless the program
|
|
2072
|
+
inspects source rules and the fact is a derived pattern
|
|
2073
|
+
([Section 6.3](#63-source-rule-inspection)): its step is then the step of a
|
|
2074
|
+
pattern identical to it up to the renaming of its variables. Its step is
|
|
2075
|
+
subject to the other proof conditions. A listing is **closed** when, for
|
|
2076
|
+
every forward rule with a head of its relation, each solution of the body
|
|
2077
|
+
under the certificate gives head instances that are listed, a pattern up to
|
|
2078
|
+
the renaming of its variables, or are ground source facts. Bind the rule's
|
|
2079
|
+
witnesses to their specified Skolem terms when checking this closure
|
|
2080
|
+
([Section 8.2](#82-forward-evaluation-and-witnesses)). A head instance that
|
|
2081
|
+
keeps a variable no inspection or listed pattern supplied leaves the
|
|
2082
|
+
boundary unsettled: the run would have bound it to a Skolem term.
|
|
2073
2083
|
|
|
2074
2084
|
Support rules out invented facts; closure rules out omitted facts. For
|
|
2075
2085
|
example, an empty answer table is insufficient if a forward rule could
|
|
@@ -2095,7 +2105,6 @@ requires:
|
|
|
2095
2105
|
publication order for order-sensitive operations. A `findall_sorted` of
|
|
2096
2106
|
ground items depends on the solutions and how often each occurs, not on
|
|
2097
2107
|
their order.
|
|
2098
|
-
- The search reaches no source inspection.
|
|
2099
2108
|
- No consulted listing's relation is concluded by a forward rule within a
|
|
2100
2109
|
template's scope ([Section 6.2](#62-inline-rule-templates)) that
|
|
2101
2110
|
introduces witnesses, or whose generators have a guard or introduce
|
|
@@ -2142,7 +2151,7 @@ from evidence that cannot settle the boundary:
|
|
|
2142
2151
|
| A table differs from its expansion; a listed fact lacks a step or has the wrong name or arity; a listing is not closed; tables are circular; the certificate's search raises an error; or the checked search finds a solution to a negated goal. | C9 fails. |
|
|
2143
2152
|
| A needed table or listing is missing, evidence is incomplete, or a certificate limit above applies. | The boundary is not settled. |
|
|
2144
2153
|
| A collection's list disagrees with the certificate's search results. | The boundary is not settled; C6 may refute it from available evidence. |
|
|
2145
|
-
| A listing contains a nonground fact. | At the first such fact in listing order, leave the boundary unsettled rather than fail it. |
|
|
2154
|
+
| A listing contains a nonground fact, and the program inspects no source rules. | At the first such fact in listing order, leave the boundary unsettled rather than fail it. |
|
|
2146
2155
|
|
|
2147
2156
|
An incorrect table or listing is reported once, for the first boundary
|
|
2148
2157
|
resting on it. Any boundary C9 did not settle counts as trusted, including
|
|
@@ -2311,12 +2320,16 @@ step's corresponding use records:
|
|
|
2311
2320
|
goal, and the template's part after. A use with no step is unified with a source fact
|
|
2312
2321
|
of the relation, renamed apart. A replay that meets the same use under
|
|
2313
2322
|
the same call again does not replay.
|
|
2323
|
+
- An inspection follows its use's `source(N)` step: rule `N` of the
|
|
2324
|
+
catalogue, renamed apart, is unified with the goal.
|
|
2314
2325
|
- After each goal, the goal MUST still unify with its use, since a step
|
|
2315
2326
|
shows its goals after the whole solution's bindings.
|
|
2316
2327
|
|
|
2317
2328
|
Each witness is then bound to its Skolem term
|
|
2318
2329
|
([Section 8.2](#82-forward-evaluation-and-witnesses)), and the fact MUST be
|
|
2319
|
-
identical to an instance of one of the rule's heads
|
|
2330
|
+
identical to an instance of one of the rule's heads, or for a derived
|
|
2331
|
+
pattern identical up to the renaming of its variables, every one of which an
|
|
2332
|
+
inspection or a listed pattern supplied. Replay re-executes each
|
|
2320
2333
|
recorded firing, so a test of whether a variable is bound sees what a search
|
|
2321
2334
|
sees, a first answer is the search's first answer, and host math is
|
|
2322
2335
|
computed rather than accepted within a tolerance. C2 keeps the steps a
|
package/package.json
CHANGED
package/src/closure.js
CHANGED
|
@@ -43,6 +43,12 @@ function instanceOf(term, pattern) {
|
|
|
43
43
|
return unify(pattern, term, env) && variant(copyResolved(term, env)) === variant(term);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
// How a listing identifies a fact: a ground fact by identity, a derived
|
|
47
|
+
// pattern up to the renaming of its variables (Section 6.3).
|
|
48
|
+
function listedKey(fact) {
|
|
49
|
+
return isGround(fact) ? identity(fact) : `pattern ${variant(fact)}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
46
52
|
// Whether the generators of a rule appended by a template fire as ordinary
|
|
47
53
|
// rules: no restricted guard, whose firings depend on the order of rule
|
|
48
54
|
// applications, and no witnesses, which the derived rule would share.
|
|
@@ -226,7 +232,12 @@ export class Settler {
|
|
|
226
232
|
env.undo(mark);
|
|
227
233
|
}
|
|
228
234
|
} else if (INSPECTION_KEYS.has(goalKey)) {
|
|
229
|
-
|
|
235
|
+
// The catalogue of source rules, in source order, each renamed apart:
|
|
236
|
+
// its variables are scoped pattern variables (Section 6.3).
|
|
237
|
+
for (const source of this.program.inspections.get(goalKey) || []) {
|
|
238
|
+
if (unify(goal, freshTerm(source.term, `inspect${++this.serial}`), env)) yield;
|
|
239
|
+
env.undo(mark);
|
|
240
|
+
}
|
|
230
241
|
} else if (!this.derivedKeys.has(goalKey) &&
|
|
231
242
|
(this.program.groups.get(goalKey) || []).every((clause) => !clause.body.length && clause.parentId === null)) {
|
|
232
243
|
// Facts alone are scanned where they stand, with no table needed.
|
|
@@ -261,7 +272,8 @@ export class Settler {
|
|
|
261
272
|
const facts = this.listing(goalKey);
|
|
262
273
|
reliance.listings.add(goalKey);
|
|
263
274
|
for (const fact of facts) {
|
|
264
|
-
|
|
275
|
+
// A derived pattern is freshened at every use.
|
|
276
|
+
if (unify(call, isGround(fact) ? fact : freshTerm(fact, `pattern${++this.serial}`), env)) yield;
|
|
265
277
|
env.undo(mark);
|
|
266
278
|
}
|
|
267
279
|
}
|
|
@@ -375,14 +387,14 @@ export class Settler {
|
|
|
375
387
|
entry.subject = fact;
|
|
376
388
|
return entry;
|
|
377
389
|
}
|
|
378
|
-
//
|
|
379
|
-
if (!isGround(fact)) throw new Unsettled();
|
|
390
|
+
// Only a program that inspects source rules derives patterns.
|
|
391
|
+
if (!isGround(fact) && !this.program.inspectionEnabled) throw new Unsettled();
|
|
380
392
|
if (!this.source.supported(fact)) {
|
|
381
393
|
entry.failure = `derived fact without a step: ${text(fact)}`;
|
|
382
394
|
entry.subject = fact;
|
|
383
395
|
return entry;
|
|
384
396
|
}
|
|
385
|
-
listed.add(
|
|
397
|
+
listed.add(listedKey(fact));
|
|
386
398
|
}
|
|
387
399
|
for (const rule of this.program.forward) {
|
|
388
400
|
if (!rule.plainHeads.some((head) => isCallable(head) && key(head) === goalKey)) continue;
|
|
@@ -437,9 +449,11 @@ export class Settler {
|
|
|
437
449
|
}
|
|
438
450
|
for (const item of heads) {
|
|
439
451
|
const conclusion = copyResolved(item, env);
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
if (
|
|
452
|
+
// Only variables an inspection supplied stay free in a conclusion;
|
|
453
|
+
// any other would have been bound to a Skolem term.
|
|
454
|
+
if ([...variables(conclusion).keys()].some((name) => !/#(?:inspect|pattern)\d+$/.test(name))) throw new Unsettled();
|
|
455
|
+
const conclusionId = listedKey(conclusion);
|
|
456
|
+
if (!listed.has(conclusionId) && !(isGround(conclusion) && this.program.groundFactKeys.has(conclusionId))) return conclusion;
|
|
443
457
|
}
|
|
444
458
|
env.undo(mark);
|
|
445
459
|
}
|
package/src/engine.js
CHANGED
|
@@ -1132,7 +1132,6 @@ function certify(solver, boundaries, operational = false) {
|
|
|
1132
1132
|
},
|
|
1133
1133
|
facts(goalKey) {
|
|
1134
1134
|
const nodes = solver.facts.get(goalKey) || NO_NODES;
|
|
1135
|
-
if (nodes.some((node) => node.generic)) throw new Unsettled();
|
|
1136
1135
|
listed.set(goalKey, nodes);
|
|
1137
1136
|
return nodes.map((node) => node.goal);
|
|
1138
1137
|
},
|
package/src/fidelity.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// these searches start before a final substitution.
|
|
4
4
|
import { PRIMITIVE_KEYS, primitive } from './builtins.js';
|
|
5
5
|
import { Settler, plainGenerators } from './closure.js';
|
|
6
|
+
import { stepIdOf } from './proof.js';
|
|
6
7
|
import { freshClause, text, variant } from './common.js';
|
|
7
8
|
import { goalTerm } from './goals.js';
|
|
8
9
|
import { INSPECTION_KEYS } from './inspection.js';
|
|
@@ -274,7 +275,12 @@ export function replayed(program, settler, listingKeys, stepOf) {
|
|
|
274
275
|
}
|
|
275
276
|
return false;
|
|
276
277
|
}
|
|
277
|
-
if (INSPECTION_KEYS.has(goalKey))
|
|
278
|
+
if (INSPECTION_KEYS.has(goalKey)) {
|
|
279
|
+
// An inspection reads the source rule its step cites, renamed apart.
|
|
280
|
+
const step = stepOf(use);
|
|
281
|
+
const source = step && isTerm(step.by, 'source', 1) ? program.inspectedById.get(Number(step.by.args[0])) : null;
|
|
282
|
+
return Boolean(source) && unify(goal, freshTerm(source.term, `inspect${++serial}`), env) && compatible(goal, use, env);
|
|
283
|
+
}
|
|
278
284
|
const step = stepOf(use);
|
|
279
285
|
if (!step) {
|
|
280
286
|
// A use without a step is an instance of a source fact.
|
|
@@ -290,7 +296,7 @@ export function replayed(program, settler, listingKeys, stepOf) {
|
|
|
290
296
|
if (!isTerm(step.by, 'clause', 1)) return false;
|
|
291
297
|
const clause = program.byId.get(Number(step.by.args[0]));
|
|
292
298
|
if (!supportedRule(clause)) return false;
|
|
293
|
-
if (clause.forward) return fact(use) && unify(goal,
|
|
299
|
+
if (clause.forward) return fact(use) && unify(goal, freshTerm(use, `pattern${++serial}`), env);
|
|
294
300
|
const [head, body] = freshClause(clause, `replay${++serial}`);
|
|
295
301
|
if (!body.length) return unify(goal, head, env) && compatible(goal, use, env);
|
|
296
302
|
const call = `${text(use)} ${text(copyResolved(goal, env))}`;
|
|
@@ -331,8 +337,15 @@ export function replayed(program, settler, listingKeys, stepOf) {
|
|
|
331
337
|
unify(names.get(name), new Struct('skolem', [BigInt(clause.id), name, listFromItems(values)]), env);
|
|
332
338
|
}
|
|
333
339
|
}
|
|
334
|
-
|
|
335
|
-
|
|
340
|
+
// A derived pattern is identified up to the renaming of its variables,
|
|
341
|
+
// and keeps only variables an inspection supplied: the run binds any
|
|
342
|
+
// other head variable a firing leaves unbound to a Skolem term.
|
|
343
|
+
const same = isGround(goal) ? (item) => identity(item) === identity(goal) : (item) => variant(item) === variant(goal);
|
|
344
|
+
holds = holds && flattenConjunction(head).some((item) => {
|
|
345
|
+
if (!isCallable(item)) return false;
|
|
346
|
+
const conclusion = copyResolved(item, env);
|
|
347
|
+
return [...variables(conclusion).keys()].every((name) => /#(?:inspect|pattern)\d+$/.test(name)) && same(conclusion);
|
|
348
|
+
});
|
|
336
349
|
active.delete(id);
|
|
337
350
|
}
|
|
338
351
|
confirmed.set(id, holds);
|
|
@@ -351,10 +364,10 @@ export function checkCalls(program, claims, goals, certificate, steps, spellings
|
|
|
351
364
|
const settler = new Settler(program, {
|
|
352
365
|
answers: (call) => certificate.calls.get(variant(call, true)) ?? null,
|
|
353
366
|
facts: (goalKey) => certificate.listings.get(goalKey) ?? null,
|
|
354
|
-
supported: (fact) => steps.has(spellings
|
|
367
|
+
supported: (fact) => steps.has(stepIdOf(steps, spellings, fact)),
|
|
355
368
|
}, true);
|
|
356
369
|
if (claims.includes('false')) return { settler, outcomes: [], unresolved: [], covered: 0 };
|
|
357
|
-
const stepOf = (goal) => steps.get(spellings
|
|
370
|
+
const stepOf = (goal) => steps.get(stepIdOf(steps, spellings, goal));
|
|
358
371
|
// Replay runs host math exactly, so it needs no exclusion for tolerance.
|
|
359
372
|
const supported = (listings) => (!(inexact && listings.length) && positiveListings(program, listings)) ||
|
|
360
373
|
replayed(program, settler, listings, stepOf);
|
package/src/proof.js
CHANGED
|
@@ -192,12 +192,16 @@ export function renderProof(program, claims, roots, checkable = false, heading =
|
|
|
192
192
|
const spellings = new Spellings();
|
|
193
193
|
const steps = new Map();
|
|
194
194
|
const cited = new Set();
|
|
195
|
-
const walk = (starts) => {
|
|
195
|
+
const walk = (starts, listed = false) => {
|
|
196
196
|
const pending = [...starts].reverse();
|
|
197
197
|
while (pending.length) {
|
|
198
198
|
const node = pending.pop();
|
|
199
199
|
const nodeId = spellings.spell(node.goal);
|
|
200
200
|
if (steps.has(nodeId)) continue;
|
|
201
|
+
// A listed derived pattern a claim's step already shows, up to the
|
|
202
|
+
// renaming of its variables, needs no second step.
|
|
203
|
+
if (listed && !isGround(node.goal) &&
|
|
204
|
+
[...steps.values()].some((step) => !isGround(step.goal) && variant(step.goal) === variant(node.goal))) continue;
|
|
201
205
|
steps.set(nodeId, node);
|
|
202
206
|
if (isTerm(node.by, 'clause', 1) || isTerm(node.by, 'source', 1)) {
|
|
203
207
|
const id = Number(node.by.args[0]);
|
|
@@ -216,7 +220,7 @@ export function renderProof(program, claims, roots, checkable = false, heading =
|
|
|
216
220
|
// Their negations and collections need certificates too, which can list
|
|
217
221
|
// further facts: certify again until no new boundary appears.
|
|
218
222
|
for (;;) {
|
|
219
|
-
walk(certificate.listings.flatMap(([, nodes]) => nodes));
|
|
223
|
+
walk(certificate.listings.flatMap(([, nodes]) => nodes), true);
|
|
220
224
|
if (certify === null || boundariesOf().length === boundaries.length) break;
|
|
221
225
|
boundaries = boundariesOf();
|
|
222
226
|
certificate = certify(boundaries);
|
|
@@ -319,6 +323,22 @@ export function checkRendered(program, checkable, goals = null, allowTrusted = t
|
|
|
319
323
|
return check(program, claims, steps, certificate, goals, allowTrusted, new Failures(name), spellings, name);
|
|
320
324
|
}
|
|
321
325
|
|
|
326
|
+
// The step of a goal: by its spelling, or for a derived pattern up to the
|
|
327
|
+
// renaming of its variables (Section 6.3), since a listing may spell a
|
|
328
|
+
// pattern's variables differently from the step that derives it.
|
|
329
|
+
const patternSteps = new WeakMap();
|
|
330
|
+
export function stepIdOf(steps, spellings, goal) {
|
|
331
|
+
const stepId = spellings.spell(goal);
|
|
332
|
+
if (steps.has(stepId) || isGround(goal)) return stepId;
|
|
333
|
+
let index = patternSteps.get(steps);
|
|
334
|
+
if (index === undefined) {
|
|
335
|
+
index = new Map();
|
|
336
|
+
for (const [id, step] of steps) if (!isGround(step.goal) && !index.has(variant(step.goal))) index.set(variant(step.goal), id);
|
|
337
|
+
patternSteps.set(steps, index);
|
|
338
|
+
}
|
|
339
|
+
return index.get(variant(goal)) ?? stepId;
|
|
340
|
+
}
|
|
341
|
+
|
|
322
342
|
// Settle each negation and collection that is well formed by its search
|
|
323
343
|
// certificate (C9), before the steps are checked: a settled one is no
|
|
324
344
|
// obligation.
|
|
@@ -326,7 +346,7 @@ function settleBoundaries(program, steps, certificate, spellings) {
|
|
|
326
346
|
const settler = new Settler(program, {
|
|
327
347
|
answers: (call) => certificate.tables.get(variant(call)) ?? null,
|
|
328
348
|
facts: (goalKey) => certificate.listings.get(goalKey) ?? null,
|
|
329
|
-
supported: (fact) => steps.has(spellings
|
|
349
|
+
supported: (fact) => steps.has(stepIdOf(steps, spellings, fact)),
|
|
330
350
|
});
|
|
331
351
|
const outcomes = new Map();
|
|
332
352
|
for (const [stepId, step] of steps) {
|
|
@@ -1034,7 +1054,7 @@ function checkRelevance(program, claims, steps, goals, fail, spellings, settleme
|
|
|
1034
1054
|
const reach = [];
|
|
1035
1055
|
for (const claim of claims) for (const part of flattenConjunction(claim)) reach.push(spellings.spell(part));
|
|
1036
1056
|
for (const entry of settlement.calls.settler.listings.values()) {
|
|
1037
|
-
for (const fact of entry.facts) reach.push(spellings
|
|
1057
|
+
for (const fact of entry.facts) reach.push(stepIdOf(steps, spellings, fact));
|
|
1038
1058
|
}
|
|
1039
1059
|
while (reach.length) {
|
|
1040
1060
|
const stepId = reach.pop();
|
|
@@ -1047,7 +1067,7 @@ function checkRelevance(program, claims, steps, goals, fail, spellings, settleme
|
|
|
1047
1067
|
const outcome = settlement.outcomes.get(stepId);
|
|
1048
1068
|
if (outcome?.status === 'settled') {
|
|
1049
1069
|
for (const goalKey of outcome.listings) {
|
|
1050
|
-
for (const fact of settlement.settler.listings.get(goalKey).facts) reach.push(spellings
|
|
1070
|
+
for (const fact of settlement.settler.listings.get(goalKey).facts) reach.push(stepIdOf(steps, spellings, fact));
|
|
1051
1071
|
}
|
|
1052
1072
|
}
|
|
1053
1073
|
}
|
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.26';
|