eyemind 0.5.26 → 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/SPEC.md +1 -1
- package/package.json +1 -1
- package/src/closure.js +2 -2
- package/src/common.js +54 -8
- package/src/fidelity.js +2 -2
- package/src/native-proof.js +8 -1
- package/src/version.js +1 -1
package/SPEC.md
CHANGED
package/package.json
CHANGED
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,
|
|
@@ -352,7 +352,7 @@ export class Settler {
|
|
|
352
352
|
for (const _ of this.expand(call, env, entry.reliance)) found.push(copyResolved(call, env)); // eslint-disable-line no-unused-vars
|
|
353
353
|
const listed = entry.answers;
|
|
354
354
|
let i = 0;
|
|
355
|
-
while (i < found.length && i < listed.length &&
|
|
355
|
+
while (i < found.length && i < listed.length && sameVariant(found[i], listed[i], this.operational)) i++;
|
|
356
356
|
if (i < found.length && i < listed.length) {
|
|
357
357
|
entry.failure = `the search of ${text(entry.call)} answers ${text(found[i])} where its table lists ${text(listed[i])}`;
|
|
358
358
|
} else if (i < found.length) {
|
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
|
-
//
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
|
243
|
+
return out.join('\u0001');
|
|
198
244
|
}
|
package/src/fidelity.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { PRIMITIVE_KEYS, primitive } from './builtins.js';
|
|
5
5
|
import { Settler, plainGenerators } from './closure.js';
|
|
6
6
|
import { stepIdOf } from './proof.js';
|
|
7
|
-
import { freshClause, text, variant } from './common.js';
|
|
7
|
+
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 {
|
|
@@ -385,7 +385,7 @@ export function checkCalls(program, claims, goals, certificate, steps, spellings
|
|
|
385
385
|
let detail = null;
|
|
386
386
|
if (matching.some(({ status }) => status === 'failed')) detail = 'the original call has an invalid search certificate';
|
|
387
387
|
else if (!matching.some(({ status, answers }) => status === 'settled' &&
|
|
388
|
-
answers.some((answer) =>
|
|
388
|
+
answers.some((answer) => sameVariant(answer, claim)))) {
|
|
389
389
|
if (matching.length && matching.every(({ status }) => status === 'settled')) {
|
|
390
390
|
detail = 'the original call does not return this answer';
|
|
391
391
|
} else {
|
package/src/native-proof.js
CHANGED
|
@@ -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))
|
|
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/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.27';
|