gdp-wired 0.44.0 → 0.46.0
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 +58 -7
- package/dist/core/bitsets.d.ts +2 -0
- package/dist/core/bitsets.js +23 -0
- package/dist/core/bmc.js +6 -2
- package/dist/core/c/reader.d.ts +9 -1
- package/dist/core/c/reader.js +445 -38
- package/dist/core/calendar.d.ts +29 -0
- package/dist/core/calendar.js +82 -0
- package/dist/core/check.js +3 -2
- package/dist/core/cli.d.ts +4 -0
- package/dist/core/cli.js +335 -39
- package/dist/core/compose.js +3 -1
- package/dist/core/counts.d.ts +5 -2
- package/dist/core/counts.js +335 -88
- package/dist/core/cycles.js +8 -1
- package/dist/core/cyclic.d.ts +1 -0
- package/dist/core/cyclic.js +13 -7
- package/dist/core/data-synth.d.ts +3 -0
- package/dist/core/data-synth.js +252 -0
- package/dist/core/data.d.ts +8 -2
- package/dist/core/data.js +1113 -172
- package/dist/core/discover.js +3 -1
- package/dist/core/draft.d.ts +19 -0
- package/dist/core/draft.js +53 -0
- package/dist/core/dsl.d.ts +39 -3
- package/dist/core/dsl.js +250 -31
- package/dist/core/effect-prims.js +2 -2
- package/dist/core/effect.d.ts +1 -4
- package/dist/core/effect.js +1 -15
- package/dist/core/ex/reader.exs +17 -1
- package/dist/core/exists.d.ts +16 -1
- package/dist/core/exists.js +447 -50
- package/dist/core/extract-c.d.ts +2 -0
- package/dist/core/extract-c.js +185 -31
- package/dist/core/extract-check.d.ts +7 -0
- package/dist/core/extract-check.js +115 -3
- package/dist/core/extract-ex.js +3 -3
- package/dist/core/extract-go-check.d.ts +1 -1
- package/dist/core/extract-go-check.js +21 -13
- package/dist/core/extract-go.d.ts +1 -0
- package/dist/core/extract-go.js +58 -9
- package/dist/core/extract-ir.d.ts +1 -0
- package/dist/core/extract-ir.js +15 -0
- package/dist/core/extract-jvm.d.ts +1 -1
- package/dist/core/extract-jvm.js +65 -14
- package/dist/core/extract-orm.d.ts +12 -0
- package/dist/core/extract-orm.js +244 -0
- package/dist/core/extract-print.js +23 -1
- package/dist/core/extract-py.d.ts +1 -0
- package/dist/core/extract-py.js +4 -4
- package/dist/core/extract-rb.js +3 -3
- package/dist/core/extract-read.d.ts +25 -0
- package/dist/core/extract-read.js +60 -5
- package/dist/core/extract-rs.js +22 -20
- package/dist/core/extract-shapes.js +22 -0
- package/dist/core/extract-sol.d.ts +10 -1
- package/dist/core/extract-sol.js +89 -30
- package/dist/core/extract-step.d.ts +201 -4
- package/dist/core/extract-step.js +1514 -111
- package/dist/core/extract-swift.js +24 -13
- package/dist/core/extract.d.ts +9 -0
- package/dist/core/extract.js +88 -7
- package/dist/core/fiber-run.d.ts +5 -0
- package/dist/core/fiber-run.js +18 -0
- package/dist/core/fresh.d.ts +2 -2
- package/dist/core/fresh.js +7 -3
- package/dist/core/go/reader.go +7 -1
- package/dist/core/infer.d.ts +4 -1
- package/dist/core/infer.js +1020 -246
- package/dist/core/jvm/JavaReader.java +33 -8
- package/dist/core/jvm/Jvm.java +20 -1
- package/dist/core/jvm/KtReader.java +59 -6
- package/dist/core/laws.d.ts +10 -3
- package/dist/core/laws.js +193 -14
- package/dist/core/machine.d.ts +16 -3
- package/dist/core/machine.js +212 -28
- package/dist/core/nonterm.js +14 -1
- package/dist/core/orm/harness.js +61 -0
- package/dist/core/orm-fixtures/schema.prisma +5 -0
- package/dist/core/py/harness.py +260 -21
- package/dist/core/py/reader.py +278 -39
- package/dist/core/rb/reader.rb +52 -5
- package/dist/core/reader-fixtures/README.md +28 -0
- package/dist/core/reader-fixtures/c-693042.cpp +8 -0
- package/dist/core/reader-fixtures/go-685506.go +14 -0
- package/dist/core/reader-fixtures/jvm-724362.kt +8 -0
- package/dist/core/reader-fixtures/jvm-737430.kt +7 -0
- package/dist/core/reader-fixtures/jvm-765282.kt +3 -0
- package/dist/core/reader-fixtures/swift-735726.swift +15 -0
- package/dist/core/reader-fixtures/swift-735990.swift +15 -0
- package/dist/core/reader-fixtures/swift-739158.swift +4 -0
- package/dist/core/reader-fixtures/swift-744834.swift +15 -0
- package/dist/core/reader-fixtures/swift-746946.swift +31 -0
- package/dist/core/reader-fixtures/typescript-673062.ts.txt +2 -0
- package/dist/core/relation.d.ts +1 -1
- package/dist/core/relation.js +29 -2
- package/dist/core/relational.js +4 -2
- package/dist/core/rs/src/main.rs +18 -2
- package/dist/core/sample-cache.d.ts +8 -0
- package/dist/core/sample-cache.js +46 -0
- package/dist/core/security.d.ts +38 -0
- package/dist/core/security.js +88 -0
- package/dist/core/sol/harness.py +63 -7
- package/dist/core/sol-concrete.d.ts +23 -0
- package/dist/core/sol-concrete.js +195 -0
- package/dist/core/solver.js +8 -5
- package/dist/core/swift/Sources/gdp-swiftreader/main.swift +50 -7
- package/dist/core/system.d.ts +62 -1
- package/dist/core/system.js +263 -4
- package/dist/core/transfer.js +39 -9
- package/dist/core/translate.js +39 -10
- package/dist/core/watch.js +51 -6
- package/dist/interchange/check.js +10 -10
- package/dist/interchange/format.d.ts +4 -0
- package/dist/interchange/format.js +24 -6
- package/dist/kernel/cdcl.d.ts +5 -0
- package/dist/kernel/cdcl.js +88 -10
- package/dist/kernel/epr.js +141 -29
- package/dist/kernel/kernel.d.ts +31 -1
- package/dist/kernel/kernel.js +391 -101
- package/dist/kernel/model-sequence.d.ts +3 -0
- package/dist/kernel/model-sequence.js +34 -0
- package/dist/kernel/prove.d.ts +30 -1
- package/dist/kernel/prove.js +481 -71
- package/dist/kernel/reader.d.ts +3 -0
- package/dist/kernel/reader.js +101 -14
- package/dist/kernel/share.d.ts +1 -0
- package/dist/kernel/share.js +27 -0
- package/dist/lean-kernel/emit.d.ts +9 -3
- package/dist/lean-kernel/emit.js +200 -66
- package/dist/lean-kernel/lean-terms.js +5 -0
- package/dist/lean-kernel/library.js +10 -10
- package/package.json +7 -2
package/dist/core/system.js
CHANGED
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
import { all, any, atMost, get, ite, n, not, plus, same, x } from "./machine.js";
|
|
20
20
|
import { substC, substE } from "../kernel/kernel.js";
|
|
21
21
|
import { Cond, Term, nat, oneOf, rule } from "./dsl.js";
|
|
22
|
+
import { interpret } from "./machine.js";
|
|
23
|
+
import { allowed, watch } from "./watch.js";
|
|
22
24
|
const models = new WeakMap();
|
|
23
25
|
const modelled = (m, ...ms) => { models.set(m, [...(models.get(m) ?? []), ...ms]); return m; };
|
|
24
26
|
// m made from `from`: the models it assumes, and the scalars it keeps shared (`sharedOf`), carried over.
|
|
@@ -198,7 +200,7 @@ function writesWhen(v, cell) {
|
|
|
198
200
|
return xs.length ? any(...xs) : false;
|
|
199
201
|
}
|
|
200
202
|
// m's one step (a request's) as a transaction of several: `pc$` 0 begins it (the request's inputs kept as in$<input>),
|
|
201
|
-
// then the reads (read committed: each store read site at its own step, inner ones first, as rd$<i
|
|
203
|
+
// then the reads (read committed: each store read site at its own step, inner ones first, as rd$<i>, a record's parts at one key one step; snapshot: all at
|
|
202
204
|
// the begin), then the commit, which computes m's step from what was read and writes it (snapshot: unless a cell it
|
|
203
205
|
// writes moved since the begin, aborted$ then 1), then done. m's scalars are the request's own (a result, a flag); its
|
|
204
206
|
// maps are the stores. 'atomic' is m itself. Each step reads only its own process's state and the stores, so
|
|
@@ -278,7 +280,7 @@ export function isolation(m, level) {
|
|
|
278
280
|
return ite(sigmaC(e.c), sigma(e.then), sigma(e.else));
|
|
279
281
|
if (e.op === 'const')
|
|
280
282
|
return e;
|
|
281
|
-
if (e.op === 'mul')
|
|
283
|
+
if (e.op === 'mul' || e.op === 'proj')
|
|
282
284
|
return { ...e, a: sigma(e.a) };
|
|
283
285
|
return { ...e, a: sigma(e.a), b: sigma(e.b) };
|
|
284
286
|
};
|
|
@@ -291,7 +293,9 @@ export function isolation(m, level) {
|
|
|
291
293
|
return c;
|
|
292
294
|
return { ...c, a: sigma(c.a), b: sigma(c.b) };
|
|
293
295
|
};
|
|
294
|
-
|
|
296
|
+
// (a record's parts at one key are one read: one GET returns the record)
|
|
297
|
+
const groupOf = (st) => `${st.map.replace(/\.[^.]*$/, '')}|${JSON.stringify(st.key)}`, groups = [...new Set(sites.map(groupOf))], gi = (j) => groups.indexOf(groupOf(sites[j]));
|
|
298
|
+
const r = groups.length, snap = level === 'snapshot';
|
|
295
299
|
const commit = snap ? 1 : r + 1, done = commit + 1;
|
|
296
300
|
const at = (k) => same(x('pc$'), n(k));
|
|
297
301
|
const valid = snap ? all(...pointWrites.map(w => { const on = writesWhen(w.value, get(w.map, w.key)); const cell = get(w.map, sigma(w.key)), was = sigma(get(w.map, w.key)); return on === false ? same(n(0), n(0)) : any(...(on === true ? [] : [not(sigmaC(on))]), same(cell, was)); })) : undefined;
|
|
@@ -300,7 +304,7 @@ export function isolation(m, level) {
|
|
|
300
304
|
const state = {
|
|
301
305
|
'pc$': ite(at(0), n(snap || !r ? commit : 1), ite(at(commit), n(done), reads)),
|
|
302
306
|
...Object.fromEntries(m.inputs.map(i => [inp(i), ite(at(0), x(i), x(inp(i)))])),
|
|
303
|
-
...Object.fromEntries(sites.map((s, j) => [rd(j), ite(at(snap ? 0 : j + 1), snap ? s.e : get(s.map, sigma(s.key)), x(rd(j)))])),
|
|
307
|
+
...Object.fromEntries(sites.map((s, j) => [rd(j), ite(at(snap ? 0 : gi(j) + 1), snap ? s.e : get(s.map, sigma(s.key)), x(rd(j)))])),
|
|
304
308
|
...mapValues(m.step.state, (e, s) => ite(commits, sigma(e), x(s))),
|
|
305
309
|
...(snap ? { 'aborted$': ite(at(commit), valid.op === 'and' && !valid.xs.length ? n(0) : ite(valid, n(0), n(1)), x('aborted$')) } : {}),
|
|
306
310
|
};
|
|
@@ -318,8 +322,11 @@ export function isolation(m, level) {
|
|
|
318
322
|
...(m.assume ? { assume: any(not(at(0)), m.assume) } : {}),
|
|
319
323
|
...(m.pre ? { pre: m.pre } : {}),
|
|
320
324
|
};
|
|
325
|
+
readsOf.set(out, groups.map(g => g.slice(0, g.indexOf('|'))));
|
|
321
326
|
return from(out, m, ISOLATION[level]);
|
|
322
327
|
}
|
|
328
|
+
// The stores a transaction reads, one per read step (read committed's; snapshot's are all at its begin).
|
|
329
|
+
export const readsOf = new WeakMap();
|
|
323
330
|
export const DELIVERY = {
|
|
324
331
|
'exactly-once': { name: 'exactly-once delivery', assumes: 'a message is taken by one handler step, once, and the take commits with the handler\'s writes (a transactional consume, an inbox row in the same transaction)',
|
|
325
332
|
checked: 'a transactional consume (Kafka transactions, an inbox row in the handler\'s transaction)' },
|
|
@@ -433,3 +440,255 @@ export function expires(cells, at, opts = {}) {
|
|
|
433
440
|
sharedOf.set(m, [now]);
|
|
434
441
|
return modelled(m, TTL);
|
|
435
442
|
}
|
|
443
|
+
const WORDS = [
|
|
444
|
+
[/^(atomic|serializable|lua|one step|locked|for update)$/, e => { e.isolation = 'atomic'; }],
|
|
445
|
+
[/^read committed$/, e => { e.isolation = 'read committed'; }],
|
|
446
|
+
[/^(snapshot|repeatable read)$/, e => { e.isolation = 'snapshot'; }],
|
|
447
|
+
[/^(keys expire|expiry|ttl|eviction|keys evicted)$/, e => { e.expiry = true; }],
|
|
448
|
+
[/^(retries|retried|at-least-once|at least once|redelivery|duplicates)$/, e => { e.retries = true; }],
|
|
449
|
+
[/^(an object per call|objects apart|a process per call|one object per call)$/, e => { e.apart = true; }],
|
|
450
|
+
];
|
|
451
|
+
export function envOf(text) {
|
|
452
|
+
const e = {};
|
|
453
|
+
for (const w of (Array.isArray(text) ? text : [text]).flatMap(t => t.split(/\s*[,;]\s*|\s+and\s+/)).map(w => w.trim().replace(/\s+/g, ' ')).filter(Boolean)) {
|
|
454
|
+
// (a call's flow: its methods in order, `acquire then release`)
|
|
455
|
+
if (/^[\w.]+( then [\w.]+)+$/.test(w)) {
|
|
456
|
+
e.flow = w.split(' then ');
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
459
|
+
const f = WORDS.find(([re]) => re.test(w.toLowerCase()));
|
|
460
|
+
if (!f)
|
|
461
|
+
throw new Error(`env: ${JSON.stringify(w)} is not an environment gdp-wired models (atomic, read committed, snapshot, keys expire, retries, a flow: <method> then <method>)`);
|
|
462
|
+
f[1](e);
|
|
463
|
+
}
|
|
464
|
+
return e;
|
|
465
|
+
}
|
|
466
|
+
export const envText = (e) => [e.isolation, e.expiry && 'keys expire', e.retries && 'retries', e.apart && 'an object per call', e.flow?.join(' then ')].filter(Boolean).join(', ');
|
|
467
|
+
export function inEnv(r, env, o = {}) {
|
|
468
|
+
let m = machineOf(r);
|
|
469
|
+
const level = env.isolation ?? 'atomic', split = level !== 'atomic', flow = env.flow, lifted = split || !!flow, P = 'calls', act = 'act$', id = 'p$';
|
|
470
|
+
const stores = o.stores ?? [], own = [...(o.own ?? [])], hk = {};
|
|
471
|
+
if (flow) {
|
|
472
|
+
const k = flow.length;
|
|
473
|
+
const is = (f) => {
|
|
474
|
+
if (!o.method) {
|
|
475
|
+
if (k > 1)
|
|
476
|
+
throw new Error(`a flow of ${k} methods, and the rule has one`);
|
|
477
|
+
return same(n(0), n(0));
|
|
478
|
+
}
|
|
479
|
+
const i = o.method.values.indexOf(f);
|
|
480
|
+
if (i < 0)
|
|
481
|
+
throw new Error(`${f} is no method of ${m.name} (${o.method.values.join(', ')})`);
|
|
482
|
+
return same(x(o.method.name), n(i));
|
|
483
|
+
};
|
|
484
|
+
// (a method done: not failed, and where its result says whether it did it, that result true)
|
|
485
|
+
const failedOk = o.failed && m.step.state?.[o.failed] ? [same(m.step.state[o.failed], n(0))] : [];
|
|
486
|
+
const oks = (o.oks ?? []).filter(r => flow.includes(r.method) && m.step.state?.[r.rule]).map(r => any(not(is(r.method)), not(same(m.step.state[r.rule], n(0)))));
|
|
487
|
+
const done = failedOk.length || oks.length ? all(...failedOk, ...oks) : undefined, stage = x('stage$');
|
|
488
|
+
for (const [map, w] of Object.entries(m.step.maps ?? {}))
|
|
489
|
+
if ('key' in w)
|
|
490
|
+
hk[map] = `hk$${map}`;
|
|
491
|
+
m = { ...m, state: { ...m.state, 'stage$': n(0), 'held$': n(0), ...Object.fromEntries(Object.values(hk).map(h => [h, n(0)])) },
|
|
492
|
+
step: { ...m.step, state: { ...m.step.state,
|
|
493
|
+
'stage$': done ? ite(done, plus(stage, n(1)), n(k)) : plus(stage, n(1)),
|
|
494
|
+
'held$': ite(all(is(flow[0]), ...(done ? [done] : [])), n(1), ite(is(flow[k - 1]), n(0), x('held$'))),
|
|
495
|
+
...Object.fromEntries(Object.entries(hk).map(([map, h]) => [h, ite(is(flow[0]), m.step.maps[map].key, x(h))])) } },
|
|
496
|
+
assume: all(...(m.assume ? [m.assume] : []), atMost(plus(stage, n(1)), n(k)), any(...flow.map((f, j) => all(same(stage, n(j)), is(f))))) };
|
|
497
|
+
// (an argument of one name, kept from the first method of the flow that takes it, its later methods given the same)
|
|
498
|
+
const named = new Map();
|
|
499
|
+
for (const a of o.args ?? [])
|
|
500
|
+
if (flow.includes(a.method) && m.inputs.includes(a.rule))
|
|
501
|
+
named.set(a.code, [...(named.get(a.code) ?? []), a]);
|
|
502
|
+
const keeps = [];
|
|
503
|
+
for (const [code, as] of named) {
|
|
504
|
+
const sorted = [...as].sort((a, b) => flow.indexOf(a.method) - flow.indexOf(b.method)), first = sorted[0], kept = `arg$${code}`;
|
|
505
|
+
if (sorted.length < 2 || kept in m.state)
|
|
506
|
+
continue;
|
|
507
|
+
keeps.push(kept);
|
|
508
|
+
m = { ...m, state: { ...m.state, [kept]: n(0) }, step: { ...m.step, state: { ...m.step.state, [kept]: ite(is(first.method), x(first.rule), x(kept)) } },
|
|
509
|
+
assume: all(m.assume, ...sorted.slice(1).map(a => any(not(is(a.method)), same(x(a.rule), x(kept))))) };
|
|
510
|
+
}
|
|
511
|
+
own.push('stage$', 'held$', ...Object.values(hk), ...keeps);
|
|
512
|
+
// (atomic: the calls holding each key, counted in the step that takes or gives it up, so the law is about every key)
|
|
513
|
+
const rk = Object.values(m.step.maps ?? {}).find((w) => 'key' in w)?.key;
|
|
514
|
+
if (!split && rk) {
|
|
515
|
+
const d = get('done$', rk), took = all(is(flow[0]), ...(done ? [done] : [])), gave = k > 1 ? all(is(flow[k - 1]), same(x('held$'), n(1))) : same(n(0), n(1));
|
|
516
|
+
m = { ...m, maps: { ...m.maps, 'done$': 0 }, step: { ...m.step, maps: { ...m.step.maps, 'done$': { key: rk, value: ite(took, plus(d, n(1)), ite(gave, { op: 'sub', a: d, b: n(1) }, d)) } } } };
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
// (an object per call: the fields its methods write are the call's own, those it only reads the object's as made)
|
|
520
|
+
if (env.apart)
|
|
521
|
+
own.push(...Object.keys(m.state).filter(s => !own.includes(s) && m.step.state?.[s] && JSON.stringify(m.step.state[s]) !== JSON.stringify(x(s))));
|
|
522
|
+
// (a field a call writes is read where the call commits, not where the code reads it: refused at a split level)
|
|
523
|
+
const fields = Object.keys(m.state).filter(s => !own.includes(s)), written = fields.filter(s => m.step.state?.[s] && JSON.stringify(m.step.state[s]) !== JSON.stringify(x(s)));
|
|
524
|
+
if (split && written.length)
|
|
525
|
+
throw new Error(`a call writes the object's ${written.join(', ')}, which it reads at its commit only here: not modelled at ${level}`);
|
|
526
|
+
const h = isolation(m, level);
|
|
527
|
+
const commit = split ? (level === 'snapshot' ? 1 : readsOf.get(h).length + 1) : undefined;
|
|
528
|
+
// (a flow's call begins its next method after a commit)
|
|
529
|
+
if (flow && split)
|
|
530
|
+
h.step.state['pc$'] = ite(same(x('pc$'), n(commit)), n(0), h.step.state['pc$']);
|
|
531
|
+
const parts = { [P]: lifted ? { rule: h, id, shared: fields } : h };
|
|
532
|
+
if (env.expiry)
|
|
533
|
+
stores.forEach((cells, i) => {
|
|
534
|
+
const e = expiry(Object.fromEntries(cells.map(c => [c, m.maps[c]])), 'key$'), mine = cells.filter(c => hk[c]);
|
|
535
|
+
// (a lease runs out: the calls holding by the key expired hold no longer; a call's done work, a flow of one method, stays done)
|
|
536
|
+
if (mine.length && flow.length > 1) {
|
|
537
|
+
e.maps = { ...e.maps, 'held$': 0, ...Object.fromEntries(mine.map(c => [hk[c], 0])) };
|
|
538
|
+
e.step.maps['held$'] = { each: 'q$', value: ite(any(...mine.map(c => same(get(hk[c], x('q$')), x('key$')))), n(0), get('held$', x('q$'))) };
|
|
539
|
+
if ('done$' in (m.maps ?? {})) {
|
|
540
|
+
e.maps['done$'] = 0;
|
|
541
|
+
e.step.maps['done$'] = { key: x('key$'), value: n(0) };
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
parts[`expiry${stores.length > 1 ? i : ''}`] = e;
|
|
545
|
+
});
|
|
546
|
+
const sys = system(`${machineOf(r).name} (${envText(env) || 'atomic'})`, parts, { act });
|
|
547
|
+
const ms = [...modelsOf(sys), ...(env.retries ? [RETRIES] : [])];
|
|
548
|
+
models.set(sys, ms);
|
|
549
|
+
const locals = Object.keys(m.state).filter(s => own.includes(s)), on = same(x(act), n(0));
|
|
550
|
+
const flags = () => Object.fromEntries(Object.keys(m.step.flags ?? {}).map(g => [g, { op: 'flag', name: `${P}$${g}` }]));
|
|
551
|
+
// (a call's own: its locals at its process `at`, before and after; its request as the call kept it)
|
|
552
|
+
const mine = (at, before) => {
|
|
553
|
+
const vs = [...locals.flatMap((s) => [[s, get(s, at)], [`${s}'`, get(`${s}'`, at)]]), ...(before && split ? m.inputs.map((i) => [i, get(`in$${i}`, at)]) : [])];
|
|
554
|
+
return { vars: lifted ? Object.fromEntries(vs) : {}, maps: {}, flags: flags() };
|
|
555
|
+
};
|
|
556
|
+
const law = (l) => {
|
|
557
|
+
if (!lifted || !locals.some(s => JSON.stringify(l.holds).includes(`"name":"${s}"`)))
|
|
558
|
+
return l;
|
|
559
|
+
const k = 'p$k', holds = substC(l.holds, mine(x(k), false));
|
|
560
|
+
return l.forall ? { ...l, holds, keys: [...(l.keys ?? []), k] } : { ...l, holds, forall: k };
|
|
561
|
+
};
|
|
562
|
+
const step = (s) => {
|
|
563
|
+
if ((s.steps ?? 1) !== 1)
|
|
564
|
+
throw new Error(`env: a law of ${s.steps} steps is not lifted to every call at once`);
|
|
565
|
+
const sub = mine(x(id), true), whens = s.when === undefined ? [] : Array.isArray(s.when) ? s.when : [s.when];
|
|
566
|
+
const then = substC(s.then, sub);
|
|
567
|
+
return { ...s, then: level === 'snapshot' ? any(same(get("aborted$'", x(id)), n(1)), then) : then,
|
|
568
|
+
when: all(on, ...(split ? [same(get('pc$', x(id)), n(commit))] : []), ...whens.map(w => substC(w, sub))) };
|
|
569
|
+
};
|
|
570
|
+
const between = (name, a, b) => {
|
|
571
|
+
if (!flow || flow[0] !== a || flow.at(-1) !== b)
|
|
572
|
+
throw new Error(`between ${a} and ${b}: the call's flow is ${flow ? flow.join(' then ') : 'not stated'} (env: ${a} then ${b})`);
|
|
573
|
+
if (!split && 'done$' in (m.maps ?? {}))
|
|
574
|
+
return { name, holds: atMost(get('done$', x('k$d')), n(1)), forall: 'k$d' };
|
|
575
|
+
const held = (p) => same(get('held$', x(p)), n(1));
|
|
576
|
+
// (per lock: two calls holding by different keys hold different things)
|
|
577
|
+
return { name, holds: any(not(held('p$a')), not(held('p$b')), same(x('p$a'), x('p$b')), ...Object.values(hk).map(k => not(same(get(k, x('p$a')), get(k, x('p$b')))))), forall: 'p$a', keys: ['p$b'] };
|
|
578
|
+
};
|
|
579
|
+
return { rule: sys, models: ms, reads: split && level !== 'snapshot' ? readsOf.get(h) : [], part: P, act, ...(lifted ? { id } : {}), ...(split ? { commit } : {}), level, ...(flow ? { flow } : {}), ...(o.method ? { method: o.method.name, methods: o.method.values.length } : {}), law, step, between };
|
|
580
|
+
}
|
|
581
|
+
// A run that breaks a law, shortened: steps dropped one at a time while the rest still breaks it (replayed on the
|
|
582
|
+
// interpreter, each request allowed where it is taken, the law read as the search reads it), cut at the first break.
|
|
583
|
+
export function shrinkRun(r, w, run) {
|
|
584
|
+
const m = machineOf(r), rt = interpret(m), params = run.params;
|
|
585
|
+
const bound = 2 + Math.max(0, ...[...Object.values(params), ...run.trace.flatMap(q => Object.values(q))].filter((v) => typeof v === 'number'));
|
|
586
|
+
// (the length of the prefix that breaks it, or 0)
|
|
587
|
+
const breaks = (trace) => {
|
|
588
|
+
try {
|
|
589
|
+
const on = watch(m, rt, w, params, bound);
|
|
590
|
+
let st = rt.init(params);
|
|
591
|
+
if (!on.start(st))
|
|
592
|
+
return 0;
|
|
593
|
+
for (const [i, q] of trace.entries()) {
|
|
594
|
+
if (!allowed(m, rt, params, st, q))
|
|
595
|
+
return 0;
|
|
596
|
+
const nx = rt.step(params, st, q);
|
|
597
|
+
if (!on.step(st, q, nx))
|
|
598
|
+
return i + 1;
|
|
599
|
+
st = nx;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
catch {
|
|
603
|
+
return 0;
|
|
604
|
+
}
|
|
605
|
+
return 0;
|
|
606
|
+
};
|
|
607
|
+
let trace = run.trace, at = breaks(trace);
|
|
608
|
+
if (!at)
|
|
609
|
+
return run;
|
|
610
|
+
trace = trace.slice(0, at);
|
|
611
|
+
for (let changed = true; changed;) {
|
|
612
|
+
changed = false;
|
|
613
|
+
for (let i = 0; i < trace.length; i++) {
|
|
614
|
+
const t = [...trace.slice(0, i), ...trace.slice(i + 1)], b = breaks(t);
|
|
615
|
+
if (b) {
|
|
616
|
+
trace = t.slice(0, b);
|
|
617
|
+
changed = true;
|
|
618
|
+
i--;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
return { ...run, trace };
|
|
623
|
+
}
|
|
624
|
+
// Contention: runs of a system where every call passes one request, so the calls contend for one key; only which
|
|
625
|
+
// part steps, which of three calls, its method and the expiring key vary, searched breadth first (states seen once) to
|
|
626
|
+
// a depth, for each of a few requests drawn. A run found breaks the law on the interpreter, as the search's do. (The
|
|
627
|
+
// search's own runs draw each request apart: three calls on one lock are rare among them.)
|
|
628
|
+
export function contend(e, w, opts = {}) {
|
|
629
|
+
const m = e.rule.machine, rt = interpret(m), bound = opts.bound ?? 2, until = performance.now() + (opts.ms ?? 3000), calls = opts.calls ?? 3;
|
|
630
|
+
let seed = opts.seed ?? 7;
|
|
631
|
+
const rand = (k) => { seed = (seed * 1103515245 + 12345) & 0x7fffffff; return seed % k; };
|
|
632
|
+
const free = new Set([e.act, ...(e.id ? [e.id] : []), ...(e.method ? [e.method] : []), 'key$']);
|
|
633
|
+
const acts = (e.rule.parts?.inputs.find(([i]) => i === e.act)?.[1].values ?? ['calls']).length;
|
|
634
|
+
const choices = [];
|
|
635
|
+
for (let a = 0; a < acts; a++) {
|
|
636
|
+
if (a > 0) {
|
|
637
|
+
for (let k = 0; k <= bound; k++)
|
|
638
|
+
choices.push({ [e.act]: a, 'key$': k });
|
|
639
|
+
continue;
|
|
640
|
+
}
|
|
641
|
+
for (let p = 1; p <= (e.id ? calls : 1); p++)
|
|
642
|
+
for (let mt = 0; mt < (e.method ? e.methods ?? 1 : 1); mt++)
|
|
643
|
+
choices.push({ [e.act]: 0, ...(e.id ? { [e.id]: p } : {}), ...(e.method ? { [e.method]: mt } : {}) });
|
|
644
|
+
}
|
|
645
|
+
const key = (st) => JSON.stringify([st.scalars, Object.entries(st.maps).map(([k, v]) => [k, [...v].filter(([, x]) => x !== 0).sort((a, b) => a[0] - b[0])])]);
|
|
646
|
+
for (let b = 0, tried = 0; b < (opts.bases ?? 12) && tried < 400 && performance.now() < until; tried++) {
|
|
647
|
+
const params = Object.fromEntries(m.params.map(p => [p, rand(bound + 1)]));
|
|
648
|
+
// (the request's values from 0 and 1: two arguments a flow keeps equal, two strings of one length, agree often)
|
|
649
|
+
const base = Object.fromEntries(m.inputs.filter(i => !free.has(i)).map(i => [i, rand(2)]));
|
|
650
|
+
let st0;
|
|
651
|
+
try {
|
|
652
|
+
st0 = rt.init(params);
|
|
653
|
+
}
|
|
654
|
+
catch {
|
|
655
|
+
continue;
|
|
656
|
+
}
|
|
657
|
+
const req = (c) => ({ ...base, ...Object.fromEntries(m.inputs.filter(i => !(i in base)).map(i => [i, 0])), ...c });
|
|
658
|
+
if (!choices.some(c => { try {
|
|
659
|
+
return allowed(m, rt, params, st0, req(c));
|
|
660
|
+
}
|
|
661
|
+
catch {
|
|
662
|
+
return false;
|
|
663
|
+
} }))
|
|
664
|
+
continue;
|
|
665
|
+
b++;
|
|
666
|
+
const seen = new Set([key(st0)]);
|
|
667
|
+
let frontier = [{ st: st0, trace: [] }];
|
|
668
|
+
for (let d = 0; d < (opts.depth ?? 7) && frontier.length && performance.now() < until; d++) {
|
|
669
|
+
const next = [];
|
|
670
|
+
for (const { st, trace } of frontier)
|
|
671
|
+
for (const c of choices) {
|
|
672
|
+
const q = req(c);
|
|
673
|
+
let nx;
|
|
674
|
+
try {
|
|
675
|
+
if (!allowed(m, rt, params, st, q))
|
|
676
|
+
continue;
|
|
677
|
+
nx = rt.step(params, st, q);
|
|
678
|
+
}
|
|
679
|
+
catch {
|
|
680
|
+
continue;
|
|
681
|
+
}
|
|
682
|
+
if (!watch(m, rt, w, params, bound + 2).step(st, q, nx))
|
|
683
|
+
return { params, trace: [...trace, q] };
|
|
684
|
+
const k = key(nx);
|
|
685
|
+
if (seen.has(k) || seen.size > 200_000)
|
|
686
|
+
continue;
|
|
687
|
+
seen.add(k);
|
|
688
|
+
next.push({ st: nx, trace: [...trace, q] });
|
|
689
|
+
}
|
|
690
|
+
frontier = next;
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
return undefined;
|
|
694
|
+
}
|
package/dist/core/transfer.js
CHANGED
|
@@ -123,7 +123,7 @@ function isBridge(y, f, op) {
|
|
|
123
123
|
const callsOf = (t) => { const out = []; walk(t, o => { if (o.op === 'call')
|
|
124
124
|
out.push(o.fn); }); return out; };
|
|
125
125
|
export function transferPlan(l) {
|
|
126
|
-
const p = programOf([l]), bridges = new Map();
|
|
126
|
+
const p = programOf([l], [], false), bridges = new Map();
|
|
127
127
|
for (const f of p.fns) {
|
|
128
128
|
const op = builtinOf(f);
|
|
129
129
|
if (op && !isBridge(l.holds, f, op))
|
|
@@ -225,6 +225,7 @@ function rewriter(bridges, copies, unfold, ren = new Map()) {
|
|
|
225
225
|
const valueOf = (s, x) => (s === 'nat' ? new Nat(x) : s === 'bool' ? new Bool(x.op === 'bool' ? x.c : { op: 'holds', x }) : s === 'int' ? new Integer(x) : new Val(s, x));
|
|
226
226
|
// The copies made, by function and bridges (a law proven again reads the same copies).
|
|
227
227
|
const made = new WeakMap();
|
|
228
|
+
const refused = new Set();
|
|
228
229
|
const freshName = (base) => { let n = base; for (let i = 2; fnNamed(n); i++)
|
|
229
230
|
n = `${base}${i}`; return n; };
|
|
230
231
|
// The law through the bridges `bridged`: the copies (made once), the law said with them, the bridge and copy laws, and
|
|
@@ -232,7 +233,7 @@ const freshName = (base) => { let n = base; for (let i = 2; fnNamed(n); i++)
|
|
|
232
233
|
function build(l, bridged, unfold) {
|
|
233
234
|
// Copied: a function that calls a bridged one, or (unfolding) one that isn't recursive, or a copied one; a function
|
|
234
235
|
// that isn't recursive is unfolded where it is called instead.
|
|
235
|
-
const p0 = programOf([l]), reach = new Set(), unfolded = (n) => unfold && !taken(fnOf(n));
|
|
236
|
+
const p0 = programOf([l], [], false), reach = new Set(), unfolded = (n) => unfold && !taken(fnOf(n));
|
|
236
237
|
for (let changed = true; changed;) {
|
|
237
238
|
changed = false;
|
|
238
239
|
for (const f of p0.fns)
|
|
@@ -246,6 +247,8 @@ function build(l, bridged, unfold) {
|
|
|
246
247
|
const key = `${unfold}|${[...bridged].map(([f, op]) => `${f}:${op.name}`).sort().join(',')}`, copies = new Map();
|
|
247
248
|
for (const n of reach) {
|
|
248
249
|
const f = fnOf(n), had = made.get(f)?.get(key);
|
|
250
|
+
if (had && refused.has(had))
|
|
251
|
+
return undefined;
|
|
249
252
|
if (had && fnNamed(had))
|
|
250
253
|
copies.set(n, had);
|
|
251
254
|
}
|
|
@@ -274,6 +277,20 @@ function build(l, bridged, unfold) {
|
|
|
274
277
|
}
|
|
275
278
|
define(name, Object.fromEntries(f.params.map(q => [q.name, q.sort])), f.ret, () => valueOf(f.ret, body));
|
|
276
279
|
}
|
|
280
|
+
// (a copy whose recursion isn't taken where the original's is, a well-founded call left nested in the match of an
|
|
281
|
+
// unfolded definition, bmerge's in stitch's: no copies of these)
|
|
282
|
+
for (const n of reach) {
|
|
283
|
+
const name = copies.get(n);
|
|
284
|
+
try {
|
|
285
|
+
void fnOf(name).ring;
|
|
286
|
+
}
|
|
287
|
+
catch (e) {
|
|
288
|
+
if (!/not structural recursion/.test(e.message))
|
|
289
|
+
throw e;
|
|
290
|
+
refused.add(name);
|
|
291
|
+
return undefined;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
277
294
|
let holds;
|
|
278
295
|
try {
|
|
279
296
|
holds = rewriter(bridged, copies, unfold).ry(l.holds);
|
|
@@ -290,7 +307,7 @@ function build(l, bridged, unfold) {
|
|
|
290
307
|
return undefined;
|
|
291
308
|
const v = (name) => ({ op: 'var', name });
|
|
292
309
|
// Only the copies the law said through them reaches (each with those its copy calls).
|
|
293
|
-
const p1 = programOf([lstar]), back = new Map([...copies].map(([a, b]) => [b, a]));
|
|
310
|
+
const p1 = programOf([lstar], [], false), back = new Map([...copies].map(([a, b]) => [b, a]));
|
|
294
311
|
const bridges = [...bridged].map(([f, op]) => {
|
|
295
312
|
const fn = fnOf(f), vs = fn.params.map(q => q.name);
|
|
296
313
|
return { fn, op, law: { name: `${f} is ${op.name}`, vars: fn.params.map(q => ({ name: q.name, sort: q.sort })), holds: { op: '=', a: { op: 'call', fn: f, args: vs.map(v) }, b: op.x(vs.map(v)) }, params: [] } };
|
|
@@ -299,7 +316,7 @@ function build(l, bridged, unfold) {
|
|
|
299
316
|
const fn = fnOf(back.get(c.name)), vs = fn.params.map(q => q.name), params = [...new Set(fn.paramFns)];
|
|
300
317
|
return { fn, law: { name: `${fn.name} is ${c.name}`, vars: fn.params.map(q => ({ name: q.name, sort: q.sort })), holds: { op: '=', a: { op: 'call', fn: fn.name, args: vs.map(v) }, b: { op: 'call', fn: c.name, args: vs.map(v) } }, params } };
|
|
301
318
|
});
|
|
302
|
-
const p = programOf([l, lstar, ...bridges.map(b => b.law), ...equivs.map(e => e.law)]);
|
|
319
|
+
const p = programOf([l, lstar, ...bridges.map(b => b.law), ...equivs.map(e => e.law)], [], false);
|
|
303
320
|
return { p, lstar, bridges, equivs, copies, unfolded: unfold };
|
|
304
321
|
}
|
|
305
322
|
// --- the proof ---------------------------------------------------------------------------------------------------------
|
|
@@ -328,15 +345,24 @@ export function proveThrough(l, plan, opts, until) {
|
|
|
328
345
|
if (!b)
|
|
329
346
|
return undefined;
|
|
330
347
|
// One chain of nodes: each bridge (by the search), each copy's law (its node made, or by the search), in order.
|
|
331
|
-
|
|
348
|
+
let fs = factsOf(b.p);
|
|
349
|
+
const chain = [], nodes = [], nodeOf = new Map();
|
|
350
|
+
// Search may invent ordinary observer definitions. Its facts append to the context's,
|
|
351
|
+
// preserving the indices of the chain; carry that vocabulary into the final verification.
|
|
352
|
+
const extend = (r) => { if (r.out && r.facts && r.verdict.program) {
|
|
353
|
+
fs = r.facts;
|
|
354
|
+
b.p = r.verdict.program;
|
|
355
|
+
} };
|
|
332
356
|
const add = (pr) => { chain.push(pr); nodes.splice(0, nodes.length, ...pr.nodes); nodeOf.set(pr.law.name, nodes.findIndex(n => n.name === pr.spec.name)); };
|
|
333
357
|
const ctx = () => ({ p: b.p, fs, base: [...chain], level: chain.length ? top(chain.at(-1)) : 0 });
|
|
334
358
|
const lost = [];
|
|
335
359
|
for (const x of b.bridges) {
|
|
336
360
|
const r = searchIn(x.law, opts, Math.min(until, clock() + 6000 * (opts.patience ?? 1)), ctx());
|
|
337
361
|
tried += r.verdict.tried;
|
|
338
|
-
if (r.out)
|
|
362
|
+
if (r.out) {
|
|
363
|
+
extend(r);
|
|
339
364
|
add(r.out);
|
|
365
|
+
}
|
|
340
366
|
else
|
|
341
367
|
lost.push(x.fn.name);
|
|
342
368
|
}
|
|
@@ -358,6 +384,7 @@ export function proveThrough(l, plan, opts, until) {
|
|
|
358
384
|
tried += r.verdict.tried;
|
|
359
385
|
if (!r.out)
|
|
360
386
|
return undefined;
|
|
387
|
+
extend(r);
|
|
361
388
|
add(r.out);
|
|
362
389
|
}
|
|
363
390
|
// (through the bridges and unfolded: half the time left, the other half through the unfolding alone, the functions
|
|
@@ -371,6 +398,7 @@ export function proveThrough(l, plan, opts, until) {
|
|
|
371
398
|
}
|
|
372
399
|
if (!r.out)
|
|
373
400
|
return { ...r.verdict, proven: false, checked: false, law: l.name, counterexample: undefined, tried };
|
|
401
|
+
extend(r);
|
|
374
402
|
// The nodes: the chain's, then the law's said through them, then the law's own.
|
|
375
403
|
const specs = [...nodes], names = new Set(specs.map(n => n.name)), off = specs.length;
|
|
376
404
|
for (const n of r.out.nodes) {
|
|
@@ -388,7 +416,7 @@ export function proveThrough(l, plan, opts, until) {
|
|
|
388
416
|
const v = verify(fs, specs, Math.max(until, clock() + 3000));
|
|
389
417
|
if (!v.proven || !v.checked)
|
|
390
418
|
return undefined;
|
|
391
|
-
const through = [...b.bridges.map(x => `${x.fn.name} is ${x.op.name}`), ...b.equivs.map(x => x.law.name), ...(b.unfolded ? [`unfolded: ${programOf([l]).fns.filter(f => !taken(f)).map(f => f.name).join(', ')}`] : [])];
|
|
419
|
+
const through = [...b.bridges.map(x => `${x.fn.name} is ${x.op.name}`), ...b.equivs.map(x => x.law.name), ...(b.unfolded ? [`unfolded: ${programOf([l], [], false).fns.filter(f => !taken(f)).map(f => f.name).join(', ')}`] : [])];
|
|
392
420
|
return { law: l.name, proven: true, checked: true, proof: v, lemmas: [...b.bridges.map(x => x.law.name), ...b.equivs.map(x => x.law.name), ...r.verdict.lemmas], scheme: `${r.verdict.scheme ?? 'no induction'}, through the law ${b.lstar.name}`, tried, program: b.p, node: specs.length - 1, ms: Math.round(performance.now() - t0), through };
|
|
393
421
|
}
|
|
394
422
|
}
|
|
@@ -455,11 +483,13 @@ function walker(b, fs, nodeOf, own) {
|
|
|
455
483
|
case 'sub':
|
|
456
484
|
case 'min':
|
|
457
485
|
case 'max':
|
|
458
|
-
case 'prod':
|
|
486
|
+
case 'prod':
|
|
487
|
+
case 'tup': {
|
|
459
488
|
const o = c;
|
|
460
489
|
return walkE(a.a, o.a) && walkE(a.b, o.b);
|
|
461
490
|
}
|
|
462
|
-
case 'mul':
|
|
491
|
+
case 'mul':
|
|
492
|
+
case 'proj': {
|
|
463
493
|
const o = c;
|
|
464
494
|
return a.k === o.k && walkE(a.a, o.a);
|
|
465
495
|
}
|
package/dist/core/translate.js
CHANGED
|
@@ -13,12 +13,20 @@ import { walk } from "./machine.js";
|
|
|
13
13
|
import { add, costs, env, refuteFast, scale, solve } from "./solver.js";
|
|
14
14
|
import { checkRefutation } from "./check.js";
|
|
15
15
|
import { canon, canonFlip, columnTerm, factorsOf, isCell, isMonomial, leafConstraints, leafConstraintsReusing, linear, substE, truth, withProducts } from "../kernel/kernel.js";
|
|
16
|
-
import { cellProducts,
|
|
16
|
+
import { cellProducts, grow, late, leafRowsOf, parseKey, withinDeadline } from "../kernel/prove.js";
|
|
17
17
|
import { Reader, times } from "../kernel/reader.js";
|
|
18
18
|
const omega = 'O$';
|
|
19
19
|
const debugOn = () => !!env.GDP_CYCLIC_DEBUG;
|
|
20
20
|
// A cell's key, from its name (`M[key]`, the key's canonical text, whose names may be cells themselves).
|
|
21
|
-
const keyOf = (cell) =>
|
|
21
|
+
const keyOf = (cell) => {
|
|
22
|
+
const text = cell.slice(cell.indexOf('[') + 1, -1);
|
|
23
|
+
// The time encoding below is scalar. A tuple cell is not a linear key: parsing its
|
|
24
|
+
// separators as coefficients made NaN rows, on which elimination's gcd never ends.
|
|
25
|
+
if (text.startsWith('⟨'))
|
|
26
|
+
return undefined;
|
|
27
|
+
const key = parseKey(text);
|
|
28
|
+
return Object.values(key).every(Number.isFinite) ? key : undefined;
|
|
29
|
+
};
|
|
22
30
|
export function renamer(r) {
|
|
23
31
|
const terms = new Map(), memo = new WeakMap(), cells = r.cells ?? {};
|
|
24
32
|
const col = (name, wp) => {
|
|
@@ -51,7 +59,7 @@ export function renamer(r) {
|
|
|
51
59
|
return out;
|
|
52
60
|
}
|
|
53
61
|
if (isCell(name)) {
|
|
54
|
-
const map = name.slice(0, name.indexOf('[')),
|
|
62
|
+
const map = name.slice(0, name.indexOf('[')), original = keyOf(name), key = original && lin(original, wp);
|
|
55
63
|
if (!key)
|
|
56
64
|
return undefined;
|
|
57
65
|
const to = cells[map];
|
|
@@ -148,12 +156,14 @@ function regrow(whole, wp, until) {
|
|
|
148
156
|
export function translate(part, whole, tree, ren0, st, until0, pp = new Map(), wp = new Map(), swaps = []) {
|
|
149
157
|
// (within the deadline it runs in too: a certificate's translation, core/cyclic.ts's translateMs)
|
|
150
158
|
const until = withinDeadline(until0);
|
|
159
|
+
if (late(until))
|
|
160
|
+
return undefined;
|
|
151
161
|
const ren = swaps.length ? (lin, p) => {
|
|
152
162
|
const out = {};
|
|
153
163
|
for (const key in lin) {
|
|
154
164
|
let to = key;
|
|
155
165
|
if (isCell(key)) {
|
|
156
|
-
const
|
|
166
|
+
const k = keyOf(key), sw = k && swaps.find(x => x[0] === canon(k));
|
|
157
167
|
if (sw)
|
|
158
168
|
to = `${key.slice(0, key.indexOf('['))}[${sw[1]}]`;
|
|
159
169
|
}
|
|
@@ -174,7 +184,7 @@ export function translate(part, whole, tree, ren0, st, until0, pp = new Map(), w
|
|
|
174
184
|
return yes && no ? { split: wl, yes, no } : undefined;
|
|
175
185
|
}
|
|
176
186
|
// (past its budget, no translation: each leaf reads the two goals' rows whole, counted, so a large tree's stops there)
|
|
177
|
-
if (
|
|
187
|
+
if (late(until))
|
|
178
188
|
return undefined;
|
|
179
189
|
// (the usual leaf's rows as its search kept them, where it did: kernel/prove.ts's leafRowsOf; else read again)
|
|
180
190
|
const kept = !tree.products && !tree.squares ? leafRowsOf.get(tree) : undefined;
|
|
@@ -198,7 +208,10 @@ export function translate(part, whole, tree, ren0, st, until0, pp = new Map(), w
|
|
|
198
208
|
const a = ren({ [pair[0]]: 1 }, wp), b = ren({ [pair[1]]: 1 }, wp), [ca] = Object.keys(a ?? {}), [cb] = Object.keys(b ?? {});
|
|
199
209
|
if (!ca || !cb || !isCell(ca) || !isCell(cb))
|
|
200
210
|
continue;
|
|
201
|
-
const
|
|
211
|
+
const ak = keyOf(ca), bk = keyOf(cb);
|
|
212
|
+
if (!ak || !bk)
|
|
213
|
+
continue;
|
|
214
|
+
const d = add(ak, scale(bk, -1)), q0 = {};
|
|
202
215
|
if (!Object.keys(d).length || Object.keys(d).some(key => key === '1' || !factorsOf(key).includes(omega)))
|
|
203
216
|
continue;
|
|
204
217
|
for (const key of Object.keys(d)) {
|
|
@@ -252,6 +265,8 @@ export function translate(part, whole, tree, ren0, st, until0, pp = new Map(), w
|
|
|
252
265
|
return close(whole, wp, st, until);
|
|
253
266
|
}
|
|
254
267
|
export function readsFirst(whole, reads, ren, inner, st, until, wp = new Map(), swaps = []) {
|
|
268
|
+
if (late(withinDeadline(until)))
|
|
269
|
+
return undefined;
|
|
255
270
|
if (!reads.length)
|
|
256
271
|
return inner(wp, swaps);
|
|
257
272
|
const [r, ...rest] = reads, ku = linear(r.k, new Map()), wu = linear(r.w, new Map()), kl = ku && ren(ku, wp), wl = wu && ren(wu, wp);
|
|
@@ -281,6 +296,8 @@ export function readsFirst(whole, reads, ren, inner, st, until, wp = new Map(),
|
|
|
281
296
|
// A path where l >= 1 (two cells' keys apart by l = q·Ω) while q <= 0 is a row: refuted by q·Ω <= 0, the product of
|
|
282
297
|
// that row and Ω >= 0.
|
|
283
298
|
function apart(whole, wp, l, q, st, until) {
|
|
299
|
+
if (late(withinDeadline(until)))
|
|
300
|
+
return undefined;
|
|
284
301
|
const rows = rowsAt(whole, wp), find = (x) => { const c = canon(x); return rows.findIndex(r => canon(r.lin) === c); };
|
|
285
302
|
const iq = find(q), io = find({ [omega]: -1 }), ia = find(add({ 1: 1 }, scale(l, -1)));
|
|
286
303
|
if (iq >= 0 && io >= 0 && ia >= 0) {
|
|
@@ -317,6 +334,8 @@ function atomsOf(c, wp) {
|
|
|
317
334
|
// A tree for `whole` that first decides each condition true (a guard, the antecedent of a use's implication), each
|
|
318
335
|
// other side grown on the goal (the node's hypotheses refute it), then `inner` at the path where all hold.
|
|
319
336
|
export function decide(whole, conds, inner, st, until, wp = new Map()) {
|
|
337
|
+
if (late(withinDeadline(until)))
|
|
338
|
+
return undefined;
|
|
320
339
|
for (const [i, c] of conds.entries()) {
|
|
321
340
|
if (truth(c, wp) === true)
|
|
322
341
|
continue;
|
|
@@ -376,7 +395,10 @@ function cellAtom(g, wp) {
|
|
|
376
395
|
for (const q of names.slice(i + 1)) {
|
|
377
396
|
if (p.slice(0, p.indexOf('[')) !== q.slice(0, q.indexOf('[')))
|
|
378
397
|
continue;
|
|
379
|
-
const
|
|
398
|
+
const pk = keyOf(p), qk = keyOf(q);
|
|
399
|
+
if (!pk || !qk)
|
|
400
|
+
continue;
|
|
401
|
+
const d = add(pk, scale(qk, -1));
|
|
380
402
|
if (Object.keys(d).some(key => key !== '1' && isMonomial(key)))
|
|
381
403
|
continue;
|
|
382
404
|
const column = Object.keys(d).some(key => key.includes('⟦'));
|
|
@@ -444,7 +466,10 @@ function omegaPair(g, wp) {
|
|
|
444
466
|
for (const q of names.slice(i + 1)) {
|
|
445
467
|
if (p.slice(0, p.indexOf('[')) !== q.slice(0, q.indexOf('[')))
|
|
446
468
|
continue;
|
|
447
|
-
const
|
|
469
|
+
const pk = keyOf(p), qk = keyOf(q);
|
|
470
|
+
if (!pk || !qk)
|
|
471
|
+
continue;
|
|
472
|
+
const d = add(pk, scale(qk, -1)), q0 = {};
|
|
448
473
|
if (!Object.keys(d).length || Object.keys(d).some(key => key === '1' || !factorsOf(key).includes(omega)))
|
|
449
474
|
continue;
|
|
450
475
|
for (const key of Object.keys(d)) {
|
|
@@ -471,11 +496,13 @@ function omegaPair(g, wp) {
|
|
|
471
496
|
// A case of `g` closed: refuted by its rows, else an open choice, two reads of a function or two cells over time split
|
|
472
497
|
// (each then equal), else the goal grown at the path.
|
|
473
498
|
export function close(g, wp, st, until) {
|
|
499
|
+
if (late(withinDeadline(until)))
|
|
500
|
+
return undefined;
|
|
474
501
|
const l = leafAt(g, wp, true, st);
|
|
475
502
|
if (l)
|
|
476
503
|
return l;
|
|
477
504
|
const pick = choiceAtom(g, wp) ?? cellAtom(g, wp), om = pick ? undefined : omegaPair(g, wp), next = pick ?? om?.l;
|
|
478
|
-
if (next &&
|
|
505
|
+
if (next && !late(withinDeadline(until))) {
|
|
479
506
|
st.splits++;
|
|
480
507
|
const id = canon(next), y = close(g, new Map(wp).set(id, { lin: next, holds: true }), st, until);
|
|
481
508
|
const no = new Map(wp).set(id, { lin: next, holds: false }), n = y && (om?.q ? apart(g, no, next, om.q, st, until) : close(g, no, st, until));
|
|
@@ -496,6 +523,8 @@ export function close(g, wp, st, until) {
|
|
|
496
523
|
// `nUses`: the uses' hypotheses, just before the conclusion refuted (mainGoal's order).
|
|
497
524
|
export function carry(g, nFacts, nUses, st, until0) {
|
|
498
525
|
const until = withinDeadline(until0);
|
|
526
|
+
if (late(until))
|
|
527
|
+
return undefined;
|
|
499
528
|
const last = g.hyps.length - 1, uses = g.hyps.slice(last - nUses, last), facts = g.hyps.slice(last - nUses - nFacts, last - nUses);
|
|
500
529
|
const law = g.hyps[last].x;
|
|
501
530
|
const parts = uses.map(u => (u.op === 'or' && u.xs.length === 2 && u.xs[0].op === 'not' ? { guard: u.xs[0].x, concl: u.xs[1] } : { guard: undefined, concl: u }));
|
|
@@ -541,7 +570,7 @@ export function carry(g, nFacts, nUses, st, until0) {
|
|
|
541
570
|
};
|
|
542
571
|
const leafOf = (wp, solveIt) => leafAt(g, wp, solveIt, st), final = (wp) => close(g, wp, st, until);
|
|
543
572
|
const node = (wp, guardsDone) => {
|
|
544
|
-
if (
|
|
573
|
+
if (late(until))
|
|
545
574
|
return undefined;
|
|
546
575
|
// A hypothesis false at the path: the law at t holds there, or a law it is carried from (its guard true) fails.
|
|
547
576
|
if (truth(law, wp) === true || parts.some(p => (p.guard === undefined || truth(p.guard, wp) === true) && truth(p.concl, wp) === false))
|