eyemind 0.5.22 → 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 +69 -10
- package/package.json +1 -1
- package/src/closure.js +52 -3
- package/src/engine.js +21 -3
- package/src/fidelity.js +140 -5
- 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. A proof within
|
|
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)
|
|
@@ -2250,17 +2266,60 @@ whose ground instances C5 re-decides as holding. `number_chars/2` re-decides
|
|
|
2250
2266
|
a ground instance by reading its characters, so only that direction is
|
|
2251
2267
|
listed. A host-math result accepted by C5 only within its tolerance
|
|
2252
2268
|
([Section 11.8](#118-c5-re-decision)) need not be the result a search
|
|
2253
|
-
finds. A proof with such a step therefore supports no listing for C10
|
|
2269
|
+
finds. A proof with such a step therefore supports no listing for C10 by
|
|
2270
|
+
this analysis.
|
|
2271
|
+
|
|
2272
|
+
**Replayed listings.** A listing the mode analysis does not support still
|
|
2273
|
+
supports C10 when every fact of every consulted listing **replays**. A fact
|
|
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
|
|
2278
|
+
source order, starting with no bindings, solves each body goal as the
|
|
2279
|
+
step's corresponding use records:
|
|
2280
|
+
|
|
2281
|
+
- A primitive runs on the bindings of that point of the search. Its first
|
|
2282
|
+
solution under which the goal can still unify with the use is taken.
|
|
2283
|
+
`compare/3` with a nonground compared term does not replay.
|
|
2284
|
+
- `once/1`, `not/1` and `findall/3` take the answers of the goal, as it
|
|
2285
|
+
stands at that point, from the call tables and listings, as in checking
|
|
2286
|
+
the original calls. A negation with an unbound named variable does not
|
|
2287
|
+
replay, and neither does a first answer or a collection whose order rests
|
|
2288
|
+
on a listing. The first answer is taken, and the goal MUST still unify
|
|
2289
|
+
with the use.
|
|
2290
|
+
- `call/1` and a disjunction replay the goals their `'control'` step uses,
|
|
2291
|
+
for a disjunction from the side those uses form.
|
|
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
|
|
2294
|
+
conclusion MUST itself replay, and is then unified with the goal. A
|
|
2295
|
+
source fact, renamed apart, is unified with the goal. A backward rule,
|
|
2296
|
+
renamed apart, has its head unified with the goal and its body replayed
|
|
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
|
|
2300
|
+
of the relation, renamed apart. A replay that meets the same use under
|
|
2301
|
+
the same call again does not replay.
|
|
2302
|
+
- After each goal, the goal MUST still unify with its use, since a step
|
|
2303
|
+
shows its goals after the whole solution's bindings.
|
|
2304
|
+
|
|
2305
|
+
Each witness is then bound to its Skolem term
|
|
2306
|
+
([Section 8.2](#82-forward-evaluation-and-witnesses)), and the fact MUST be
|
|
2307
|
+
identical to an instance of one of the rule's heads. Replay re-executes each
|
|
2308
|
+
recorded firing, so a test of whether a variable is bound sees what a search
|
|
2309
|
+
sees, a first answer is the search's first answer, and host math is
|
|
2310
|
+
computed rather than accepted within a tolerance. C2 keeps the steps a
|
|
2311
|
+
replay follows acyclic.
|
|
2254
2312
|
|
|
2255
2313
|
Supported facts and closed listings then establish the least ground
|
|
2256
2314
|
closure and, with negations, a set of facts that is supported, closed under
|
|
2257
2315
|
the rules and consistent with each negation, every negation being decided
|
|
2258
2316
|
by the listed facts alone. A stratified or chain-stratified program has
|
|
2259
2317
|
exactly one such set ([Section 7.4](#74-negation-and-collection)), its
|
|
2260
|
-
result, so the listings are the facts the original calls consult. A
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2318
|
+
result, so the listings are the facts the original calls consult. A
|
|
2319
|
+
collection or first answer over facts that forward rules derive depends on
|
|
2320
|
+
their publication order, which this format does not establish, and a
|
|
2321
|
+
restricted rule's firings can depend on the order of rule applications:
|
|
2322
|
+
both leave call fidelity unproved.
|
|
2264
2323
|
|
|
2265
2324
|
**Deciding claims.** Every relevant call certificate MUST be valid. Each
|
|
2266
2325
|
claim MUST be identical, up to variable renaming, to an answer of at least
|
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/engine.js
CHANGED
|
@@ -3,7 +3,7 @@ import { PRIMITIVE_KEYS, STATE_TESTS, primitive } from './builtins.js';
|
|
|
3
3
|
import { Reliance, Settler, Unsettled } from './closure.js';
|
|
4
4
|
import { freshClause, matchHead, renaming, text, variant } from './common.js';
|
|
5
5
|
import { goalTerm, subgoals } from './goals.js';
|
|
6
|
-
import { callQuestions, positiveListings } from './fidelity.js';
|
|
6
|
+
import { callQuestions, positiveListings, replayed } from './fidelity.js';
|
|
7
7
|
import { INSPECTION_KEYS } from './inspection.js';
|
|
8
8
|
import { checkRendered, clauseDisplay, renderProof } from './proof.js';
|
|
9
9
|
import { CONTROL_KEYS, Program } from './program.js';
|
|
@@ -1130,7 +1130,6 @@ function certify(solver, boundaries, operational = false) {
|
|
|
1130
1130
|
}
|
|
1131
1131
|
},
|
|
1132
1132
|
facts(goalKey) {
|
|
1133
|
-
if (operational && !positiveListings(program, [goalKey])) throw new Unsettled();
|
|
1134
1133
|
const nodes = solver.facts.get(goalKey) || NO_NODES;
|
|
1135
1134
|
if (nodes.some((node) => node.generic)) throw new Unsettled();
|
|
1136
1135
|
listed.set(goalKey, nodes);
|
|
@@ -1156,9 +1155,27 @@ function certify(solver, boundaries, operational = false) {
|
|
|
1156
1155
|
}
|
|
1157
1156
|
}
|
|
1158
1157
|
}
|
|
1158
|
+
// The recorded derivation of a listed fact or one of its premises, for the
|
|
1159
|
+
// replay that supports a listing beyond the mode analysis.
|
|
1160
|
+
let recorded = null;
|
|
1161
|
+
const stepOf = (goal) => {
|
|
1162
|
+
if (recorded === null) {
|
|
1163
|
+
recorded = new Map();
|
|
1164
|
+
const pending = [...listed.values()].flat();
|
|
1165
|
+
while (pending.length) {
|
|
1166
|
+
const node = pending.pop();
|
|
1167
|
+
const goalText = text(node.goal);
|
|
1168
|
+
if (recorded.has(goalText)) continue;
|
|
1169
|
+
recorded.set(goalText, { by: node.by, uses: node.children.map((child) => child.goal) });
|
|
1170
|
+
pending.push(...node.children);
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
return recorded.get(text(goal));
|
|
1174
|
+
};
|
|
1159
1175
|
const tables = new Set();
|
|
1160
1176
|
const listings = new Set();
|
|
1161
1177
|
for (const boundary of boundaries) {
|
|
1178
|
+
recorded = null;
|
|
1162
1179
|
let outcome = null;
|
|
1163
1180
|
budget = 0;
|
|
1164
1181
|
volume = 0;
|
|
@@ -1175,7 +1192,8 @@ function certify(solver, boundaries, operational = false) {
|
|
|
1175
1192
|
}
|
|
1176
1193
|
}
|
|
1177
1194
|
}
|
|
1178
|
-
if (outcome.status === 'settled' && (!operational || positiveListings(program, outcome.listings)
|
|
1195
|
+
if (outcome.status === 'settled' && (!operational || positiveListings(program, outcome.listings) ||
|
|
1196
|
+
replayed(program, settler, outcome.listings, stepOf))) {
|
|
1179
1197
|
for (const item of outcome.tables) tables.add(item);
|
|
1180
1198
|
for (const item of outcome.listings) listings.add(item);
|
|
1181
1199
|
} else if (outcome.status === 'failed' && solver.haltCode === null) {
|
package/src/fidelity.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
// C10: answers of the original questions, checked from source call tables:
|
|
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
|
-
import { PRIMITIVE_KEYS } from './builtins.js';
|
|
5
|
-
import { Settler } from './closure.js';
|
|
6
|
-
import { text, variant } from './common.js';
|
|
4
|
+
import { PRIMITIVE_KEYS, primitive } from './builtins.js';
|
|
5
|
+
import { Settler, plainGenerators } from './closure.js';
|
|
6
|
+
import { freshClause, text, variant } from './common.js';
|
|
7
7
|
import { goalTerm } from './goals.js';
|
|
8
8
|
import { INSPECTION_KEYS } from './inspection.js';
|
|
9
9
|
import {
|
|
10
|
-
Env, Struct, Var, conjunction, copyResolved,
|
|
10
|
+
Env, EyemindError, Struct, Var, conjunction, copyResolved, deref, flattenConjunction, freshTerm, identity, isAnonymous, isCallable,
|
|
11
|
+
isGround, isTerm, key, listFromItems, unify, variables,
|
|
11
12
|
} from './terms.js';
|
|
12
13
|
import { Lettering, write } from './writer.js';
|
|
13
14
|
|
|
@@ -210,6 +211,136 @@ function groundedListings(program, listings, loose) {
|
|
|
210
211
|
return true;
|
|
211
212
|
}
|
|
212
213
|
|
|
214
|
+
// Whether each fact of these listings is the conclusion of a firing that a
|
|
215
|
+
// search makes, replaying in source order the derivation its steps record.
|
|
216
|
+
// Primitives run on the bindings of that point of the search, so a test of
|
|
217
|
+
// whether a variable is bound sees what the search saw. A relation call
|
|
218
|
+
// follows its use's own step, which C2 keeps acyclic; a listed use is
|
|
219
|
+
// replayed in turn. once/1, not/1 and findall/3 are decided by the call
|
|
220
|
+
// tables, through Settler.answers, which refuses an order resting on a
|
|
221
|
+
// listing. A use is compared with what its goal can still become, since steps
|
|
222
|
+
// show goals after the whole solution's bindings. stepOf(goal) gives the
|
|
223
|
+
// recorded justification and uses of a goal, or nothing.
|
|
224
|
+
export function replayed(program, settler, listingKeys, stepOf) {
|
|
225
|
+
const confirmed = new Map();
|
|
226
|
+
const active = new Set();
|
|
227
|
+
let serial = 0;
|
|
228
|
+
const fresh = (term) => freshTerm(term, `replay${++serial}`);
|
|
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);
|
|
235
|
+
function compatible(goal, use, env) {
|
|
236
|
+
const mark = env.mark();
|
|
237
|
+
const agrees = unify(goal, fresh(use), env);
|
|
238
|
+
env.undo(mark);
|
|
239
|
+
return agrees;
|
|
240
|
+
}
|
|
241
|
+
function all(goals, uses, env) {
|
|
242
|
+
return goals.length === uses.length && goals.every((goal, i) => one(goal, uses[i], env));
|
|
243
|
+
}
|
|
244
|
+
function one(goal, use, env) {
|
|
245
|
+
goal = deref(goal, env);
|
|
246
|
+
if (!isCallable(goal) || !isCallable(use)) return false;
|
|
247
|
+
const goalKey = key(goal);
|
|
248
|
+
if (goalKey !== key(use)) return false;
|
|
249
|
+
if (goalKey === 'call/1' || goalKey === 'or/2') {
|
|
250
|
+
const step = stepOf(use);
|
|
251
|
+
if (!step || step.by !== 'control') return false;
|
|
252
|
+
const used = step.uses.map((item) => text(item));
|
|
253
|
+
const sides = goalKey === 'call/1' ? [0] : [0, 1];
|
|
254
|
+
const side = sides.find((i) => {
|
|
255
|
+
const parts = flattenConjunction(use.args[i]);
|
|
256
|
+
return parts.length === used.length && parts.every((part, j) => text(part) === used[j]);
|
|
257
|
+
});
|
|
258
|
+
return side !== undefined && all(flattenConjunction(goal.args[side]), step.uses, env);
|
|
259
|
+
}
|
|
260
|
+
if (['once/1', 'not/1', 'findall/3'].includes(goalKey)) {
|
|
261
|
+
const outcome = settler.answers(copyResolved(goal, env));
|
|
262
|
+
if (outcome.status !== 'settled' || !outcome.answers.length) return false;
|
|
263
|
+
return unify(goal, fresh(outcome.answers[0]), env) && compatible(goal, use, env);
|
|
264
|
+
}
|
|
265
|
+
if (PRIMITIVE_KEYS.has(goalKey)) {
|
|
266
|
+
// A comparison of variables orders them by name, which renaming changes.
|
|
267
|
+
if (goalKey === 'compare/3' && (!isGround(goal.args[1], env) || !isGround(goal.args[2], env))) return false;
|
|
268
|
+
try {
|
|
269
|
+
for (const _ of primitive(goal, env)) { // eslint-disable-line no-unused-vars
|
|
270
|
+
if (compatible(goal, use, env)) return true;
|
|
271
|
+
}
|
|
272
|
+
} catch (error) {
|
|
273
|
+
if (!(error instanceof EyemindError)) throw error;
|
|
274
|
+
}
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
if (INSPECTION_KEYS.has(goalKey)) return false;
|
|
278
|
+
const step = stepOf(use);
|
|
279
|
+
if (!step) {
|
|
280
|
+
// A use without a step is an instance of a source fact.
|
|
281
|
+
for (const clause of program.groups.get(goalKey) || []) {
|
|
282
|
+
if (clause.body.length || clause.forward || clause.parentId !== null) continue;
|
|
283
|
+
const mark = env.mark();
|
|
284
|
+
const [head] = freshClause(clause, `replay${++serial}`);
|
|
285
|
+
if (unify(goal, head, env) && compatible(goal, use, env)) return true;
|
|
286
|
+
env.undo(mark);
|
|
287
|
+
}
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
if (!isTerm(step.by, 'clause', 1)) return false;
|
|
291
|
+
const clause = program.byId.get(Number(step.by.args[0]));
|
|
292
|
+
if (!supportedRule(clause)) return false;
|
|
293
|
+
if (clause.forward) return fact(use) && unify(goal, fresh(use), env);
|
|
294
|
+
const [head, body] = freshClause(clause, `replay${++serial}`);
|
|
295
|
+
if (!body.length) return unify(goal, head, env) && compatible(goal, use, env);
|
|
296
|
+
const call = `${text(use)} ${text(copyResolved(goal, env))}`;
|
|
297
|
+
if (active.has(call)) return false;
|
|
298
|
+
active.add(call);
|
|
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);
|
|
304
|
+
active.delete(call);
|
|
305
|
+
return solved;
|
|
306
|
+
}
|
|
307
|
+
// A listed fact: a firing of the forward rule its step cites.
|
|
308
|
+
function fact(goal) {
|
|
309
|
+
const id = text(goal);
|
|
310
|
+
if (confirmed.has(id)) return confirmed.get(id);
|
|
311
|
+
if (active.has(id)) return false;
|
|
312
|
+
const step = stepOf(goal);
|
|
313
|
+
const clause = step && isTerm(step.by, 'clause', 1) ? program.byId.get(Number(step.by.args[0])) : null;
|
|
314
|
+
let holds = false;
|
|
315
|
+
if (supportedRule(clause) && clause.forward) {
|
|
316
|
+
active.add(id);
|
|
317
|
+
const [head, body, names] = freshClause(clause, `replay${++serial}`);
|
|
318
|
+
const env = new Env();
|
|
319
|
+
holds = all(body, step.uses, env);
|
|
320
|
+
if (holds && clause.witnessNames.length) {
|
|
321
|
+
// Each witness is the Skolem term of this firing (Section 8.2).
|
|
322
|
+
const witnesses = new Set(clause.witnessNames.map((name) => names.get(name).name));
|
|
323
|
+
const values = [];
|
|
324
|
+
for (const variable of variables(head).values()) {
|
|
325
|
+
if (witnesses.has(variable.name)) continue;
|
|
326
|
+
const value = copyResolved(variable, env);
|
|
327
|
+
if (!isGround(value)) holds = false;
|
|
328
|
+
values.push(value);
|
|
329
|
+
}
|
|
330
|
+
for (const name of clause.witnessNames) {
|
|
331
|
+
unify(names.get(name), new Struct('skolem', [BigInt(clause.id), name, listFromItems(values)]), env);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
holds = holds && flattenConjunction(head).some((item) => isCallable(item) &&
|
|
335
|
+
identity(copyResolved(item, env)) === identity(goal));
|
|
336
|
+
active.delete(id);
|
|
337
|
+
}
|
|
338
|
+
confirmed.set(id, holds);
|
|
339
|
+
return holds;
|
|
340
|
+
}
|
|
341
|
+
return listingKeys.every((goalKey) => (settler.listings.get(goalKey)?.facts || []).every(fact));
|
|
342
|
+
}
|
|
343
|
+
|
|
213
344
|
// Both directions of C10: each claim is an answer of an original question,
|
|
214
345
|
// and each answer of a certified question is claimed. When the conclusions
|
|
215
346
|
// are the derived facts, a question's answers that are not derived (source
|
|
@@ -223,9 +354,13 @@ export function checkCalls(program, claims, goals, certificate, steps, spellings
|
|
|
223
354
|
supported: (fact) => steps.has(spellings.spell(fact)),
|
|
224
355
|
}, true);
|
|
225
356
|
if (claims.includes('false')) return { settler, outcomes: [], unresolved: [], covered: 0 };
|
|
357
|
+
const stepOf = (goal) => steps.get(spellings.spell(goal));
|
|
358
|
+
// Replay runs host math exactly, so it needs no exclusion for tolerance.
|
|
359
|
+
const supported = (listings) => (!(inexact && listings.length) && positiveListings(program, listings)) ||
|
|
360
|
+
replayed(program, settler, listings, stepOf);
|
|
226
361
|
const outcomes = callQuestions(program, goals, claims).map((question) => {
|
|
227
362
|
const outcome = settler.answers(question);
|
|
228
|
-
if (outcome.status === 'settled' &&
|
|
363
|
+
if (outcome.status === 'settled' && !supported(outcome.listings)) {
|
|
229
364
|
return { question, ...outcome, status: 'unsupported' };
|
|
230
365
|
}
|
|
231
366
|
return { question, ...outcome };
|
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';
|