eyemind 0.5.25 → 0.5.27

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 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.25
5
+ Version: eyemind 0.5.27
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. Its step is subject to the
2068
- other proof conditions. A listing is **closed** when, for every forward
2069
- rule with a head of its relation, each solution of the body under the
2070
- certificate gives head instances that are listed or are ground source
2071
- facts. Bind the rule's witnesses to their specified Skolem terms when
2072
- checking this closure ([Section 8.2](#82-forward-evaluation-and-witnesses)).
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. Replay re-executes each
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyemind",
3
- "version": "0.5.25",
3
+ "version": "0.5.27",
4
4
  "description": "A dependency-free JavaScript rule language with forward and backward reasoning and checkable proofs.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/closure.js CHANGED
@@ -16,7 +16,7 @@
16
16
  // a once/1 whose answers rest on a listing stays an obligation, and so does a
17
17
  // boundary whose search reaches rule templates or inspection.
18
18
  import { PRIMITIVE_KEYS, primitive } from './builtins.js';
19
- import { freshClause, text, variant } from './common.js';
19
+ import { freshClause, sameVariant, text, variant } from './common.js';
20
20
  import { INSPECTION_KEYS } from './inspection.js';
21
21
  import {
22
22
  Env, EyemindError, Struct, Var, copyResolved, deref, flattenConjunction, freshTerm, identity, isCallable, isGround, isTerm, key,
@@ -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
- throw new Unsettled();
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
- if (unify(call, fact, env)) yield;
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
  }
@@ -340,7 +352,7 @@ export class Settler {
340
352
  for (const _ of this.expand(call, env, entry.reliance)) found.push(copyResolved(call, env)); // eslint-disable-line no-unused-vars
341
353
  const listed = entry.answers;
342
354
  let i = 0;
343
- while (i < found.length && i < listed.length && this.variant(found[i]) === this.variant(listed[i])) i++;
355
+ while (i < found.length && i < listed.length && sameVariant(found[i], listed[i], this.operational)) i++;
344
356
  if (i < found.length && i < listed.length) {
345
357
  entry.failure = `the search of ${text(entry.call)} answers ${text(found[i])} where its table lists ${text(listed[i])}`;
346
358
  } else if (i < found.length) {
@@ -375,14 +387,14 @@ export class Settler {
375
387
  entry.subject = fact;
376
388
  return entry;
377
389
  }
378
- // A pattern an inspection derived is not a fact closure can compare.
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(identity(fact));
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
- if (!isGround(conclusion)) throw new Unsettled();
441
- const conclusionId = identity(conclusion);
442
- if (!listed.has(conclusionId) && !this.program.groundFactKeys.has(conclusionId)) return conclusion;
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/common.js CHANGED
@@ -183,16 +183,62 @@ function build(term, values, fresh) {
183
183
  return new Struct(term.name, term.args.map((arg) => build(arg, values, fresh)));
184
184
  }
185
185
 
186
- // A key that preserves sharing while forgetting variable names.
186
+ // Whether two terms are variants of each other, as their variant keys would
187
+ // say, compared directly: one consistent renaming in each direction.
188
+ export function sameVariant(left, right, anonymous = false) {
189
+ const forward = new Map();
190
+ const backward = new Map();
191
+ const pending = [left, right];
192
+ while (pending.length) {
193
+ const b = pending.pop();
194
+ const a = pending.pop();
195
+ if (a instanceof Var || b instanceof Var) {
196
+ if (!(a instanceof Var && b instanceof Var)) return false;
197
+ if (anonymous && isAnonymous(a) !== isAnonymous(b)) return false;
198
+ const mapped = forward.get(a.name);
199
+ if (mapped === undefined) {
200
+ if (backward.has(b.name)) return false;
201
+ forward.set(a.name, b.name);
202
+ backward.set(b.name, a.name);
203
+ } else if (mapped !== b.name) {
204
+ return false;
205
+ }
206
+ } else if (a instanceof Struct || b instanceof Struct) {
207
+ if (!(a instanceof Struct && b instanceof Struct) || a.name !== b.name || a.args.length !== b.args.length) return false;
208
+ for (let i = a.args.length - 1; i >= 0; i--) pending.push(a.args[i], b.args[i]);
209
+ } else if (typeof a !== typeof b || !Object.is(a, b)) {
210
+ return false;
211
+ }
212
+ }
213
+ return true;
214
+ }
215
+
216
+ // A key that preserves sharing while forgetting variable names: variables
217
+ // are numbered in order of first occurrence, anonymous ones apart when asked.
218
+ // It encodes the term as identity does, without writing canonical text.
187
219
  export function variant(term, anonymous = false) {
188
220
  const names = new Map();
189
- function visit(t) {
190
- if (t instanceof Var) {
191
- if (!names.has(t.name)) names.set(t.name, new Var(`${anonymous && isAnonymous(t) ? '_' : 'V'}${names.size}`));
192
- return names.get(t.name);
221
+ const out = [];
222
+ const pending = [term];
223
+ while (pending.length) {
224
+ const item = pending.pop();
225
+ if (item instanceof Var) {
226
+ let name = names.get(item.name);
227
+ if (name === undefined) {
228
+ name = `${anonymous && isAnonymous(item) ? '_' : 'V'}${names.size}`;
229
+ names.set(item.name, name);
230
+ }
231
+ out.push('\u0000v', name);
232
+ } else if (item instanceof Struct) {
233
+ out.push('\u0000c', String(item.name.length), item.name, String(item.args.length));
234
+ for (let i = item.args.length - 1; i >= 0; i--) pending.push(item.args[i]);
235
+ } else if (typeof item === 'string') {
236
+ out.push('\u0000a', String(item.length), item);
237
+ } else if (typeof item === 'bigint') {
238
+ out.push('\u0000i', String(item));
239
+ } else {
240
+ out.push('\u0000f', Object.is(item, -0) ? '-0' : String(item));
193
241
  }
194
- if (t instanceof Struct) return new Struct(t.name, t.args.map(visit));
195
- return t;
196
242
  }
197
- return text(visit(term));
243
+ return out.join('\u0001');
198
244
  }
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,7 +3,8 @@
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 { freshClause, text, variant } from './common.js';
6
+ import { stepIdOf } from './proof.js';
7
+ import { freshClause, sameVariant, text, variant } from './common.js';
7
8
  import { goalTerm } from './goals.js';
8
9
  import { INSPECTION_KEYS } from './inspection.js';
9
10
  import {
@@ -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)) return false;
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, fresh(use), env);
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
- holds = holds && flattenConjunction(head).some((item) => isCallable(item) &&
335
- identity(copyResolved(item, env)) === identity(goal));
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.spell(fact)),
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.spell(goal));
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);
@@ -372,7 +385,7 @@ export function checkCalls(program, claims, goals, certificate, steps, spellings
372
385
  let detail = null;
373
386
  if (matching.some(({ status }) => status === 'failed')) detail = 'the original call has an invalid search certificate';
374
387
  else if (!matching.some(({ status, answers }) => status === 'settled' &&
375
- answers.some((answer) => variant(answer) === variant(claim)))) {
388
+ answers.some((answer) => sameVariant(answer, claim)))) {
376
389
  if (matching.length && matching.every(({ status }) => status === 'settled')) {
377
390
  detail = 'the original call does not return this answer';
378
391
  } else {
@@ -284,7 +284,14 @@ export function readNativeProof(document) {
284
284
  }
285
285
  }
286
286
 
287
+ // The command line reads an SRL proof's execution context before checking
288
+ // the same document, so the last native document read is kept.
289
+ let lastNative = null;
290
+
287
291
  export function readProofTerms(document) {
288
- if (/^\s*(?:#|@|PREFIX\b|BASE\b|DATA\b|<|_:)/i.test(document)) return readNativeProof(document).map((term) => [term, 0]);
292
+ if (/^\s*(?:#|@|PREFIX\b|BASE\b|DATA\b|<|_:)/i.test(document)) {
293
+ if (lastNative?.document !== document) lastNative = { document, terms: readNativeProof(document) };
294
+ return lastNative.terms.map((term) => [term, 0]);
295
+ }
289
296
  return readTerms(document);
290
297
  }
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.spell(fact)),
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.spell(fact));
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.spell(fact));
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.25';
2
+ export const VERSION = '0.5.27';