eyemind 0.5.30 → 0.5.32
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 +14 -96
- package/SPEC.md +34 -90
- package/package.json +1 -1
- package/src/cli.js +2 -2
- package/src/closure.js +18 -38
- package/src/engine.js +3 -4
- package/src/fidelity.js +38 -196
- package/src/formats.js +0 -12
- package/src/index.js +0 -1
- package/src/n3-parser.js +6 -9
- package/src/proof.js +5 -8
- package/src/srl.js +1 -2
- package/src/version.js +1 -1
- package/src/native-proof.js +0 -316
package/src/fidelity.js
CHANGED
|
@@ -8,8 +8,8 @@ import { freshClause, sameVariant, text, variant } from './common.js';
|
|
|
8
8
|
import { goalTerm } from './goals.js';
|
|
9
9
|
import { INSPECTION_KEYS } from './inspection.js';
|
|
10
10
|
import {
|
|
11
|
-
Env, EyemindError, Struct,
|
|
12
|
-
|
|
11
|
+
Env, EyemindError, Struct, conjunction, copyResolved, deref, flattenConjunction, freshTerm, identity, isCallable,
|
|
12
|
+
isGround, isTerm, key, listFromItems, unify, variables,
|
|
13
13
|
} from './terms.js';
|
|
14
14
|
import { Lettering, write } from './writer.js';
|
|
15
15
|
|
|
@@ -39,179 +39,6 @@ export function callQuestions(program, goals, claims) {
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
// Primitives that compute their outputs from ground inputs, in each mode an
|
|
43
|
-
// argument's positions of the inputs, then of the outputs. With its inputs
|
|
44
|
-
// ground such a call has exactly the solutions whose ground instances hold,
|
|
45
|
-
// re-decided as C5 re-decides them, so a search finds what C5 accepts.
|
|
46
|
-
// number_chars/2 re-decides by reading its characters, so only that mode.
|
|
47
|
-
const MODES = new Map([
|
|
48
|
-
['is/2', [[[1], [0]]]],
|
|
49
|
-
['compare/3', [[[1, 2], [0]]]],
|
|
50
|
-
['atom_chars/2', [[[0], [1]], [[1], [0]]]],
|
|
51
|
-
['atom_codes/2', [[[0], [1]], [[1], [0]]]],
|
|
52
|
-
['number_chars/2', [[[1], [0]]]],
|
|
53
|
-
['atom_length/2', [[[0], [1]]]],
|
|
54
|
-
['atom_lower/2', [[[0], [1]]]],
|
|
55
|
-
['atom_upper/2', [[[0], [1]]]],
|
|
56
|
-
['atom_concat/3', [[[0, 1], [2]], [[2], [0, 1]]]],
|
|
57
|
-
['regex_find/3', [[[0, 1], [2]]]],
|
|
58
|
-
['digest/3', [[[0, 1], [2]]]],
|
|
59
|
-
['term_text/2', [[[0], [1]]]],
|
|
60
|
-
['float64/4', [[[0, 1, 2], [3]]]],
|
|
61
|
-
]);
|
|
62
|
-
|
|
63
|
-
// The variables of a head's arguments that a call in mode grounds.
|
|
64
|
-
function inputs(head, mode) {
|
|
65
|
-
const names = new Set();
|
|
66
|
-
if (head instanceof Struct) {
|
|
67
|
-
head.args.forEach((arg, i) => {
|
|
68
|
-
if (mode[i] === 'g') for (const name of variables(arg).keys()) names.add(name);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
return names;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// How often each variable occurs in term, by name.
|
|
75
|
-
function occurrences(term, counts = new Map()) {
|
|
76
|
-
const pending = [term];
|
|
77
|
-
while (pending.length) {
|
|
78
|
-
const item = pending.pop();
|
|
79
|
-
if (item instanceof Struct) pending.push(...item.args);
|
|
80
|
-
else if (item instanceof Var) counts.set(item.name, (counts.get(item.name) || 0) + 1);
|
|
81
|
-
}
|
|
82
|
-
return counts;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// C9's support plus closure establishes the least ground model, and with
|
|
86
|
-
// negations the one stable model of a stratified or chain-stratified
|
|
87
|
-
// program, when a search of each rule body in source order finds exactly the
|
|
88
|
-
// ground instances that hold: then the steps that support a listed fact,
|
|
89
|
-
// re-decided on their ground instances, show a firing a search makes. That
|
|
90
|
-
// holds when no goal observes bindings: each primitive runs with its inputs
|
|
91
|
-
// ground, each negation with its named variables ground, and once/1 and
|
|
92
|
-
// findall/3 bind nothing other goals use. A backward rule is analyzed for
|
|
93
|
-
// each mode it is called in, the head arguments a call grounds being ground
|
|
94
|
-
// on entry, and must ground the rest of its head. A relation with a
|
|
95
|
-
// nonground source fact grounds nothing. Rules that observe bindings or
|
|
96
|
-
// order, templates, and restricted rules, whose guard another order of
|
|
97
|
-
// firings could decide otherwise, leave which firings occurred
|
|
98
|
-
// unestablished: refuse that promise.
|
|
99
|
-
export function positiveListings(program, listings) {
|
|
100
|
-
// Calls, by relation and mode, found to answer with nonground terms; the
|
|
101
|
-
// analysis starts again whenever it finds another, assuming fewer grounded.
|
|
102
|
-
const loose = new Set();
|
|
103
|
-
for (;;) {
|
|
104
|
-
const result = groundedListings(program, listings, loose);
|
|
105
|
-
if (result !== 'again') return result;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function groundedListings(program, listings, loose) {
|
|
110
|
-
// A listed relation and the forward rules concluding it, or a called
|
|
111
|
-
// relation and its mode: 'g' for each argument ground at the call, else 'f'.
|
|
112
|
-
const pending = listings.map((goalKey) => [goalKey, null]);
|
|
113
|
-
const seen = new Set();
|
|
114
|
-
// Whether every source fact of a relation is ground once a call in this
|
|
115
|
-
// mode has unified it: only then does the call ground its arguments.
|
|
116
|
-
const groundsFacts = (goalKey, mode) => !loose.has(`${goalKey} ${mode}`) &&
|
|
117
|
-
(program.groups.get(goalKey) || []).every((clause) => clause.body.length ||
|
|
118
|
-
[...variables(clause.head).keys()].every((name) => inputs(clause.head, mode).has(name)));
|
|
119
|
-
let outside = null;
|
|
120
|
-
// The variables of goal used elsewhere in the clause, other than in goal.
|
|
121
|
-
const shared = (goal) => {
|
|
122
|
-
const inside = occurrences(goal);
|
|
123
|
-
return [...variables(goal)].filter(([name, variable]) => !isAnonymous(variable) && outside.get(name) > inside.get(name))
|
|
124
|
-
.map(([name]) => name);
|
|
125
|
-
};
|
|
126
|
-
function bound(goal, grounded, negated = false) {
|
|
127
|
-
if (goal === 'true') return grounded;
|
|
128
|
-
if (isTerm(goal, 'and', 2) || isTerm(goal, 'or', 2)) {
|
|
129
|
-
const left = bound(goal.args[0], grounded, negated);
|
|
130
|
-
if (left === null) return null;
|
|
131
|
-
const right = bound(goal.args[1], goal.name === 'and' ? left : grounded, negated);
|
|
132
|
-
if (right === null) return null;
|
|
133
|
-
return goal.name === 'and' ? right
|
|
134
|
-
: new Set([...left].filter((name) => right.has(name)));
|
|
135
|
-
}
|
|
136
|
-
if (isTerm(goal, 'not', 1)) {
|
|
137
|
-
if (negated) return null;
|
|
138
|
-
for (const [name, variable] of variables(goal)) {
|
|
139
|
-
if (!isAnonymous(variable) && !grounded.has(name)) return null;
|
|
140
|
-
}
|
|
141
|
-
return bound(goal.args[0], grounded, true) === null ? null : grounded;
|
|
142
|
-
}
|
|
143
|
-
if (isTerm(goal, 'call', 1)) return bound(goal.args[0], grounded, negated);
|
|
144
|
-
// A first answer or a collection binds nothing it shares, so which answer
|
|
145
|
-
// came first, or which bindings a later goal makes, cannot matter.
|
|
146
|
-
if (isTerm(goal, 'once', 1)) {
|
|
147
|
-
const inner = bound(goal.args[0], grounded, negated);
|
|
148
|
-
return inner === null || shared(goal).some((name) => !grounded.has(name)) ? null : grounded;
|
|
149
|
-
}
|
|
150
|
-
if (isCollection(goal)) {
|
|
151
|
-
const inner = bound(goal.args[1], grounded, negated);
|
|
152
|
-
const collected = new Struct('-', [goal.args[0], goal.args[1]]);
|
|
153
|
-
if (inner === null || shared(collected).some((name) => !grounded.has(name))) return null;
|
|
154
|
-
const items = [...variables(goal.args[0]).keys()].every((name) => inner.has(name));
|
|
155
|
-
return items ? new Set([...grounded, ...variables(goal.args[2]).keys()]) : grounded;
|
|
156
|
-
}
|
|
157
|
-
if (!isCallable(goal)) return null;
|
|
158
|
-
const goalKey = key(goal);
|
|
159
|
-
if (INSPECTION_KEYS.has(goalKey)) return null;
|
|
160
|
-
if (PRIMITIVE_KEYS.has(goalKey)) {
|
|
161
|
-
const free = (term) => [...variables(term).keys()].filter((name) => !grounded.has(name));
|
|
162
|
-
const args = goal instanceof Struct ? goal.args : [];
|
|
163
|
-
if (args.every((arg) => !free(arg).length)) return grounded;
|
|
164
|
-
if (goalKey === 'unify/2') {
|
|
165
|
-
// Unification is pure; a ground side grounds the other.
|
|
166
|
-
const [left, right] = args;
|
|
167
|
-
if (!free(left).length || !free(right).length) return new Set([...grounded, ...variables(goal).keys()]);
|
|
168
|
-
return grounded;
|
|
169
|
-
}
|
|
170
|
-
const modes = MODES.get(goalKey) || [];
|
|
171
|
-
if (!modes.some(([inputs]) => inputs.every((i) => !free(args[i]).length))) return null;
|
|
172
|
-
return new Set([...grounded, ...variables(goal).keys()]);
|
|
173
|
-
}
|
|
174
|
-
const args = goal instanceof Struct ? goal.args : [];
|
|
175
|
-
const mode = args.map((arg) => ([...variables(arg).keys()].every((name) => grounded.has(name)) ? 'g' : 'f')).join('');
|
|
176
|
-
pending.push([goalKey, mode]);
|
|
177
|
-
return groundsFacts(goalKey, mode) ? new Set([...grounded, ...variables(goal).keys()]) : grounded;
|
|
178
|
-
}
|
|
179
|
-
while (pending.length) {
|
|
180
|
-
const [goalKey, mode] = pending.pop();
|
|
181
|
-
const clauses = [];
|
|
182
|
-
if (!seen.has(goalKey)) {
|
|
183
|
-
seen.add(goalKey);
|
|
184
|
-
clauses.push(...(program.groups.get(goalKey) || []).filter((clause) => !clause.body.length),
|
|
185
|
-
...program.forward.filter((clause) => clause.plainHeads.some((head) => isCallable(head) && key(head) === goalKey)));
|
|
186
|
-
}
|
|
187
|
-
if (mode !== null && !seen.has(`${goalKey} ${mode}`)) {
|
|
188
|
-
seen.add(`${goalKey} ${mode}`);
|
|
189
|
-
clauses.push(...(program.groups.get(goalKey) || []).filter((clause) => clause.body.length));
|
|
190
|
-
}
|
|
191
|
-
for (const clause of clauses) {
|
|
192
|
-
if (clause.parentId !== null || clause.templates.length || clause.captures !== null || clause.guard !== null) return false;
|
|
193
|
-
if (!clause.forward && !clause.body.length) continue;
|
|
194
|
-
outside = occurrences(new Struct('-', [clause.head, listFromItems(clause.body)]));
|
|
195
|
-
let grounded = clause.forward ? new Set() : inputs(clause.head, mode);
|
|
196
|
-
for (const goal of clause.body) {
|
|
197
|
-
grounded = bound(goal, grounded);
|
|
198
|
-
if (grounded === null) return false;
|
|
199
|
-
}
|
|
200
|
-
// A call in a mode whose facts stay nonground grounds nothing, so its
|
|
201
|
-
// rules need not ground their heads either.
|
|
202
|
-
if (!clause.forward && !groundsFacts(goalKey, mode)) continue;
|
|
203
|
-
const witnesses = new Set(clause.forward ? clause.witnessNames : []);
|
|
204
|
-
for (const name of variables(clause.head).keys()) {
|
|
205
|
-
if (grounded.has(name) || witnesses.has(name)) continue;
|
|
206
|
-
if (clause.forward) return false;
|
|
207
|
-
loose.add(`${goalKey} ${mode}`);
|
|
208
|
-
return 'again';
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
return true;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
42
|
// Whether each fact of these listings is the conclusion of a firing that a
|
|
216
43
|
// search makes, replaying in source order the derivation its steps record.
|
|
217
44
|
// Primitives run on the bindings of that point of the search, so a test of
|
|
@@ -234,15 +61,35 @@ export function replayed(program, settler, listingKeys, stepOf) {
|
|
|
234
61
|
(clause.parentId !== null || clause.captures === null) &&
|
|
235
62
|
!((clause.parentId !== null || clause.templates.length) && clause.witnessNames.length);
|
|
236
63
|
function compatible(goal, use, env) {
|
|
64
|
+
// Trial unification must not undo compression of existing bindings.
|
|
65
|
+
goal = copyResolved(goal, env);
|
|
237
66
|
const mark = env.mark();
|
|
238
67
|
const agrees = unify(goal, fresh(use), env);
|
|
239
68
|
env.undo(mark);
|
|
240
69
|
return agrees;
|
|
241
70
|
}
|
|
242
|
-
|
|
243
|
-
|
|
71
|
+
// Keep deep recorded derivations off the host stack.
|
|
72
|
+
function finish(start) {
|
|
73
|
+
const pending = [start];
|
|
74
|
+
let value;
|
|
75
|
+
while (pending.length) {
|
|
76
|
+
const next = pending[pending.length - 1].next(value);
|
|
77
|
+
if (next.done) {
|
|
78
|
+
value = next.value;
|
|
79
|
+
pending.pop();
|
|
80
|
+
} else {
|
|
81
|
+
pending.push(next.value);
|
|
82
|
+
value = undefined;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
function* all(goals, uses, env) {
|
|
88
|
+
if (goals.length !== uses.length) return false;
|
|
89
|
+
for (let i = 0; i < goals.length; i++) if (!(yield one(goals[i], uses[i], env))) return false;
|
|
90
|
+
return true;
|
|
244
91
|
}
|
|
245
|
-
function one(goal, use, env) {
|
|
92
|
+
function* one(goal, use, env) {
|
|
246
93
|
goal = deref(goal, env);
|
|
247
94
|
if (!isCallable(goal) || !isCallable(use)) return false;
|
|
248
95
|
const goalKey = key(goal);
|
|
@@ -256,7 +103,7 @@ export function replayed(program, settler, listingKeys, stepOf) {
|
|
|
256
103
|
const parts = flattenConjunction(use.args[i]);
|
|
257
104
|
return parts.length === used.length && parts.every((part, j) => text(part) === used[j]);
|
|
258
105
|
});
|
|
259
|
-
return side !== undefined && all(flattenConjunction(goal.args[side]), step.uses, env);
|
|
106
|
+
return side !== undefined && (yield all(flattenConjunction(goal.args[side]), step.uses, env));
|
|
260
107
|
}
|
|
261
108
|
if (['once/1', 'not/1', 'findall/3', 'findall_sorted/3'].includes(goalKey)) {
|
|
262
109
|
const outcome = settler.answers(copyResolved(goal, env));
|
|
@@ -296,22 +143,22 @@ export function replayed(program, settler, listingKeys, stepOf) {
|
|
|
296
143
|
if (!isTerm(step.by, 'clause', 1)) return false;
|
|
297
144
|
const clause = program.byId.get(Number(step.by.args[0]));
|
|
298
145
|
if (!supportedRule(clause)) return false;
|
|
299
|
-
if (clause.forward) return fact(use) && unify(goal, freshTerm(use, `pattern${++serial}`), env);
|
|
146
|
+
if (clause.forward) return (yield fact(use)) && unify(goal, freshTerm(use, `pattern${++serial}`), env);
|
|
300
147
|
const [head, body] = freshClause(clause, `replay${++serial}`);
|
|
301
148
|
if (!body.length) return unify(goal, head, env) && compatible(goal, use, env);
|
|
302
|
-
const
|
|
303
|
-
if (active.has(
|
|
304
|
-
active.add(
|
|
149
|
+
const id = text(use);
|
|
150
|
+
if (active.has(id)) return false;
|
|
151
|
+
active.add(id);
|
|
305
152
|
// A generator ran before any caller: its premises replay before the head
|
|
306
153
|
// meets the call.
|
|
307
154
|
const prefix = clause.prefixLength;
|
|
308
|
-
const solved = step.uses.length === body.length && all(body.slice(0, prefix), step.uses.slice(0, prefix), env) &&
|
|
309
|
-
unify(goal, head, env) && all(body.slice(prefix), step.uses.slice(prefix), env) && compatible(goal, use, env);
|
|
310
|
-
active.delete(
|
|
155
|
+
const solved = step.uses.length === body.length && (yield all(body.slice(0, prefix), step.uses.slice(0, prefix), env)) &&
|
|
156
|
+
unify(goal, head, env) && (yield all(body.slice(prefix), step.uses.slice(prefix), env)) && compatible(goal, use, env);
|
|
157
|
+
active.delete(id);
|
|
311
158
|
return solved;
|
|
312
159
|
}
|
|
313
160
|
// A listed fact: a firing of the forward rule its step cites.
|
|
314
|
-
function fact(goal) {
|
|
161
|
+
function* fact(goal) {
|
|
315
162
|
const id = text(goal);
|
|
316
163
|
if (confirmed.has(id)) return confirmed.get(id);
|
|
317
164
|
if (active.has(id)) return false;
|
|
@@ -322,7 +169,7 @@ export function replayed(program, settler, listingKeys, stepOf) {
|
|
|
322
169
|
active.add(id);
|
|
323
170
|
const [head, body, names] = freshClause(clause, `replay${++serial}`);
|
|
324
171
|
const env = new Env();
|
|
325
|
-
holds = all(body, step.uses, env);
|
|
172
|
+
holds = yield all(body, step.uses, env);
|
|
326
173
|
if (holds && clause.witnessNames.length) {
|
|
327
174
|
// Each witness is the Skolem term of this firing (Section 8.2).
|
|
328
175
|
const witnesses = new Set(clause.witnessNames.map((name) => names.get(name).name));
|
|
@@ -351,16 +198,14 @@ export function replayed(program, settler, listingKeys, stepOf) {
|
|
|
351
198
|
confirmed.set(id, holds);
|
|
352
199
|
return holds;
|
|
353
200
|
}
|
|
354
|
-
return listingKeys.every((goalKey) => (settler.listings.get(goalKey)?.facts || []).every(fact));
|
|
201
|
+
return listingKeys.every((goalKey) => (settler.listings.get(goalKey)?.facts || []).every((goal) => finish(fact(goal))));
|
|
355
202
|
}
|
|
356
203
|
|
|
357
204
|
// Both directions of C10: each claim is an answer of an original question,
|
|
358
205
|
// and each answer of a certified question is claimed. When the conclusions
|
|
359
206
|
// are the derived facts, a question's answers that are not derived (source
|
|
360
207
|
// facts, backward answers) are no conclusions, so only its listed facts are.
|
|
361
|
-
|
|
362
|
-
// listing for C10: its derived facts need not be what a search here finds.
|
|
363
|
-
export function checkCalls(program, claims, goals, certificate, steps, spellings, fail, allowTrusted, name, inexact = false) {
|
|
208
|
+
export function checkCalls(program, claims, goals, certificate, steps, spellings, fail, allowTrusted, name) {
|
|
364
209
|
const settler = new Settler(program, {
|
|
365
210
|
answers: (call) => certificate.calls.get(variant(call, true)) ?? null,
|
|
366
211
|
facts: (goalKey) => certificate.listings.get(goalKey) ?? null,
|
|
@@ -368,12 +213,9 @@ export function checkCalls(program, claims, goals, certificate, steps, spellings
|
|
|
368
213
|
}, true);
|
|
369
214
|
if (claims.includes('false')) return { settler, outcomes: [], unresolved: [], covered: 0 };
|
|
370
215
|
const stepOf = (goal) => steps.get(stepIdOf(steps, spellings, goal));
|
|
371
|
-
// Replay runs host math exactly, so it needs no exclusion for tolerance.
|
|
372
|
-
const supported = (listings) => (!(inexact && listings.length) && positiveListings(program, listings)) ||
|
|
373
|
-
replayed(program, settler, listings, stepOf);
|
|
374
216
|
const outcomes = callQuestions(program, goals, claims).map((question) => {
|
|
375
217
|
const outcome = settler.answers(question);
|
|
376
|
-
if (outcome.status === 'settled' && !
|
|
218
|
+
if (outcome.status === 'settled' && !replayed(program, settler, outcome.listings, stepOf)) {
|
|
377
219
|
return { question, ...outcome, status: 'unsupported' };
|
|
378
220
|
}
|
|
379
221
|
return { question, ...outcome };
|
package/src/formats.js
CHANGED
|
@@ -22,8 +22,6 @@ import { resultToN3, compileSources } from './n3.js';
|
|
|
22
22
|
import { compileSrl, srlAnswers, srlQuads } from './srl.js';
|
|
23
23
|
import { write } from './writer.js';
|
|
24
24
|
import { isRdfMessageLog, parseRdfMessages } from './messages.js';
|
|
25
|
-
import { writeNativeProof } from './native-proof.js';
|
|
26
|
-
import { checkProof } from './proof.js';
|
|
27
25
|
|
|
28
26
|
export const OUTPUT_FORMATS = ['eyemind', 'turtle', 'trig', 'n-triples', 'n-quads', 'n3'];
|
|
29
27
|
|
|
@@ -124,16 +122,6 @@ function importResolver(io) {
|
|
|
124
122
|
// eyemind's own text for a program.
|
|
125
123
|
export const defaultFormat = (kind) => ({ n3: 'n3', srl: 'turtle' })[kind] ?? 'eyemind';
|
|
126
124
|
|
|
127
|
-
// The core certificate keeps its specified JavaScript form. Native inputs
|
|
128
|
-
// expose the same evidence as N3 or SRL data at the format boundary.
|
|
129
|
-
export function writeProof(loaded, result, { goals = null } = {}) {
|
|
130
|
-
if (loaded.kind === 'js') return result.proof;
|
|
131
|
-
const document = writeNativeProof(result.proof, { format: loaded.kind, prefixes: loaded.prefixes });
|
|
132
|
-
const report = checkProof(loaded.program, document, { goals });
|
|
133
|
-
if (!report.valid) throw new EyemindError(`generated ${loaded.kind} proof failed verification: ${report.failures[0].detail}`);
|
|
134
|
-
return document;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
125
|
// The conclusions of a run in an output format; null for eyemind's own text.
|
|
138
126
|
// all also writes the given data. Throws when a conclusion is no triple.
|
|
139
127
|
export function writeConclusions(loaded, result, { format, all = false, blankNodePrefix = '' } = {}) {
|
package/src/index.js
CHANGED
|
@@ -10,7 +10,6 @@ export { readGoal } from './goals.js';
|
|
|
10
10
|
export { FloatLiteral, build, loadSources, loadText, toTerm } from './lang.js';
|
|
11
11
|
export { Program } from './program.js';
|
|
12
12
|
export { checkProof, checkReport, publicReport, strict, verdictText } from './proof.js';
|
|
13
|
-
export { readNativeProof, readProofTerms, writeNativeProof } from './native-proof.js';
|
|
14
13
|
export { readTerm, readTerms } from './reader.js';
|
|
15
14
|
export { EyemindError, Struct, Var } from './terms.js';
|
|
16
15
|
export { write } from './writer.js';
|
package/src/n3-parser.js
CHANGED
|
@@ -248,9 +248,8 @@ export const DEFAULT_PREFIXES = {
|
|
|
248
248
|
};
|
|
249
249
|
|
|
250
250
|
// Parse a document: { triples, prefixes, base }. Prefixes map names to IRIs
|
|
251
|
-
// in declaration order.
|
|
252
|
-
|
|
253
|
-
export function parseN3(src, { base = '', preserveNumericLiterals = false } = {}) {
|
|
251
|
+
// in declaration order.
|
|
252
|
+
export function parseN3(src, { base = '' } = {}) {
|
|
254
253
|
src = String(src);
|
|
255
254
|
const input = tokens(src);
|
|
256
255
|
const ahead = [];
|
|
@@ -327,7 +326,7 @@ export function parseN3(src, { base = '', preserveNumericLiterals = false } = {}
|
|
|
327
326
|
if (isP('^^')) {
|
|
328
327
|
next();
|
|
329
328
|
const dt = iriTerm();
|
|
330
|
-
return typedLiteral(text, dt.v
|
|
329
|
+
return typedLiteral(text, dt.v);
|
|
331
330
|
}
|
|
332
331
|
return { t: 'literal', v: text, dt: `${XSD}string` };
|
|
333
332
|
}
|
|
@@ -381,7 +380,7 @@ export function parseN3(src, { base = '', preserveNumericLiterals = false } = {}
|
|
|
381
380
|
if (tok.k === 'var') return { t: 'var', v: tok.v, scope: 0 };
|
|
382
381
|
if (tok.k === 'bnode') return { t: 'bnode', v: tok.v, scope: scope.id };
|
|
383
382
|
if (tok.k === 'string') return literalTail(tok.v);
|
|
384
|
-
if (tok.k === 'number') return numberTerm(tok.v
|
|
383
|
+
if (tok.k === 'number') return numberTerm(tok.v);
|
|
385
384
|
if (tok.k === 'word') {
|
|
386
385
|
if (tok.v === 'true' || tok.v === 'false') return { t: 'literal', v: tok.v, dt: `${XSD}boolean` };
|
|
387
386
|
throw fail(`unexpected word '${tok.v}'; prefixed names need a colon, as in :${tok.v}`, tok);
|
|
@@ -510,9 +509,8 @@ export function parseN3(src, { base = '', preserveNumericLiterals = false } = {}
|
|
|
510
509
|
return { triples: top.triples, prefixes, base };
|
|
511
510
|
}
|
|
512
511
|
|
|
513
|
-
function numberTerm(text
|
|
512
|
+
function numberTerm(text) {
|
|
514
513
|
if (/^[+-]?[0-9]+$/.test(text)) return { t: 'int', v: BigInt(text) };
|
|
515
|
-
if (preserve) return { t: 'literal', v: text, dt: `${XSD}${/[eE]/.test(text) ? 'double' : 'decimal'}` };
|
|
516
514
|
if (/[eE]/.test(text)) return { t: 'literal', v: String(Number(text)), dt: `${XSD}double` };
|
|
517
515
|
return { t: 'float', v: Number(text) };
|
|
518
516
|
}
|
|
@@ -522,10 +520,9 @@ const FLOAT_TYPES = new Set(['decimal']);
|
|
|
522
520
|
|
|
523
521
|
// Native numbers represent integer and decimal. Float and double retain
|
|
524
522
|
// their datatype so triple matching and log:equalTo distinguish them.
|
|
525
|
-
export function typedLiteral(text, dt
|
|
523
|
+
export function typedLiteral(text, dt) {
|
|
526
524
|
if (dt.startsWith(XSD)) {
|
|
527
525
|
const local = dt.slice(XSD.length);
|
|
528
|
-
if (preserve && ['decimal', 'float', 'double'].includes(local)) return { t: 'literal', v: text, dt };
|
|
529
526
|
if (INTEGER_TYPES.has(local) && /^[+-]?[0-9]+$/.test(text)) return { t: 'int', v: BigInt(text) };
|
|
530
527
|
if (FLOAT_TYPES.has(local) && /^[+-]?([0-9]+(\.[0-9]*)?|\.[0-9]+)([eE][+-]?[0-9]+)?$/.test(text)) return { t: 'float', v: Number(text) };
|
|
531
528
|
if ((local === 'double' || local === 'float') && Number.isFinite(Number(text)) && /^[+-]?([0-9]+(\.[0-9]*)?|\.[0-9]+)([eE][+-]?[0-9]+)?$/.test(text)) return { t: 'literal', v: String(Number(text)), dt };
|
package/src/proof.js
CHANGED
|
@@ -18,11 +18,11 @@ import { goalTerm } from './goals.js';
|
|
|
18
18
|
import { checkCalls } from './fidelity.js';
|
|
19
19
|
import { INSPECTION_KEYS, isInspection } from './inspection.js';
|
|
20
20
|
import { CONTROL_KEYS, Program } from './program.js';
|
|
21
|
-
import { readProofTerms } from './native-proof.js';
|
|
22
21
|
import {
|
|
23
22
|
Env, EyemindError, Struct, Var, conjunction, copyResolved, deref, flattenConjunction, freshTerm,
|
|
24
23
|
isCallable, isCollection, isFloat, isGround, isTerm, key, keyArity, keyName, listFromItems, properListItems, unify, variables,
|
|
25
24
|
} from './terms.js';
|
|
25
|
+
import { readTerms } from './reader.js';
|
|
26
26
|
import { Lettering, letterName, quote, write, writeNotingVariables } from './writer.js';
|
|
27
27
|
|
|
28
28
|
// Several goals or conclusions are displayed as an array, as a program
|
|
@@ -370,7 +370,7 @@ function check(program, claims, steps, certificate, goals, allowTrusted, fail, s
|
|
|
370
370
|
const provenance = new WitnessProvenance(program, steps, certificate, settlement.outcomes, spellings);
|
|
371
371
|
const tally = checkSteps(program, steps, allowTrusted, fail, spellings, name, settlement.outcomes, provenance);
|
|
372
372
|
const [confronted, closed] = checkBoundaries(program, steps, tally.boundaries, fail, settlement.outcomes, spellings);
|
|
373
|
-
settlement.calls = checkCalls(program, claims, goals, certificate, steps, spellings, fail, allowTrusted, name
|
|
373
|
+
settlement.calls = checkCalls(program, claims, goals, certificate, steps, spellings, fail, allowTrusted, name);
|
|
374
374
|
tally.trusted.push(...settlement.calls.unresolved);
|
|
375
375
|
checkRelevance(program, claims, steps, goals || [], fail, spellings, settlement, certificate);
|
|
376
376
|
checkWellFounded(steps, fail, spellings);
|
|
@@ -434,7 +434,7 @@ function readDocument(program, document, fail, spellings) {
|
|
|
434
434
|
const certificate = { tables: new Map(), calls: new Map(), listings: new Map(), order: [] };
|
|
435
435
|
const empty = new Env();
|
|
436
436
|
try {
|
|
437
|
-
for (const [term] of
|
|
437
|
+
for (const [term] of readTerms(document)) {
|
|
438
438
|
if (isTerm(term, 'searched', 2) || isTerm(term, 'derived', 2) || isTerm(term, 'called', 2)) {
|
|
439
439
|
readCertificate(term, certificate, fail, empty);
|
|
440
440
|
continue;
|
|
@@ -510,7 +510,7 @@ const CONTROL_BY = 'control';
|
|
|
510
510
|
// instance of the clause it cites, a recomputed primitive, a control composed
|
|
511
511
|
// of its uses, or a trusted boundary the later checks confront.
|
|
512
512
|
function checkSteps(program, steps, allowTrusted, fail, spellings, name, outcomes, provenance) {
|
|
513
|
-
const tally = { verified: 0, redecided: 0, composed: 0, witnessed: 0, boundaries: [], trusted: []
|
|
513
|
+
const tally = { verified: 0, redecided: 0, composed: 0, witnessed: 0, boundaries: [], trusted: [] };
|
|
514
514
|
|
|
515
515
|
function covered(goal) {
|
|
516
516
|
if (isTerm(goal, 'and', 2)) return flattenConjunction(goal).every(covered);
|
|
@@ -540,11 +540,8 @@ function checkSteps(program, steps, allowTrusted, fail, spellings, name, outcome
|
|
|
540
540
|
fail.add('C3', 'invalid builtin justification', goal);
|
|
541
541
|
continue;
|
|
542
542
|
}
|
|
543
|
-
|
|
544
|
-
if (!exact && !nearHostMath(goal)) fail.add('C5', `primitive disagrees: ${text(goal)}`, goal);
|
|
543
|
+
if (!redecides(goal)) fail.add('C5', `primitive disagrees: ${text(goal)}`, goal);
|
|
545
544
|
else tally.redecided++;
|
|
546
|
-
// Host math within its tolerance is not the result a search here finds.
|
|
547
|
-
if (!exact) tally.inexact = true;
|
|
548
545
|
} else if (isTerm(by, 'called', 1)) {
|
|
549
546
|
if (bindings.length || uses.length || !isCallable(goal) || !STATE_TESTS.has(key(goal))) {
|
|
550
547
|
fail.add('C3', 'invalid called justification', goal);
|
package/src/srl.js
CHANGED
|
@@ -41,7 +41,6 @@ import { Program, Source } from './program.js';
|
|
|
41
41
|
import { DEFAULT_GRAPH } from './rdf.js';
|
|
42
42
|
import { readTerms } from './reader.js';
|
|
43
43
|
import { Struct, Var, conjunction, identity, isGround } from './terms.js';
|
|
44
|
-
import { readProofTerms } from './native-proof.js';
|
|
45
44
|
import { write } from './writer.js';
|
|
46
45
|
|
|
47
46
|
export class SrlError extends Error {}
|
|
@@ -207,7 +206,7 @@ function executionContext(context) {
|
|
|
207
206
|
|
|
208
207
|
export function srlContextFromProof(document) {
|
|
209
208
|
try {
|
|
210
|
-
const contexts =
|
|
209
|
+
const contexts = readTerms(document).map(([term]) => term)
|
|
211
210
|
.filter((t) => t instanceof Struct && t.name === 'clause' && t.args.length === 2)
|
|
212
211
|
.map((t) => t.args[1])
|
|
213
212
|
.filter((t) => t instanceof Struct && t.name === 'fact' && t.args.length === 1)
|
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.32';
|