gdp-wired 0.26.0 → 0.28.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/dist/core/accel.d.ts +24 -0
- package/dist/core/accel.js +557 -207
- package/dist/core/bmc.d.ts +4 -1
- package/dist/core/bmc.js +18 -15
- package/dist/core/cycles.d.ts +2 -0
- package/dist/core/cycles.js +1 -1
- package/dist/core/cyclic.js +17 -10
- package/dist/core/data.d.ts +1 -0
- package/dist/core/data.js +73 -18
- package/dist/core/discover.js +64 -25
- package/dist/core/dsl.js +108 -18
- package/dist/core/extract-check.d.ts +52 -2
- package/dist/core/extract-check.js +155 -104
- package/dist/core/extract-read.d.ts +25 -0
- package/dist/core/extract-read.js +55 -14
- package/dist/core/extract-shapes.js +94 -18
- package/dist/core/extract-xstate.js +16 -3
- package/dist/core/extract.d.ts +1 -0
- package/dist/core/extract.js +16 -8
- package/dist/core/fresh.d.ts +9 -0
- package/dist/core/fresh.js +91 -0
- package/dist/core/infer.d.ts +1 -0
- package/dist/core/infer.js +64 -46
- package/dist/core/live.d.ts +15 -0
- package/dist/core/live.js +317 -0
- package/dist/core/machine.js +0 -1
- package/dist/core/nonterm.d.ts +3 -1
- package/dist/core/nonterm.js +103 -25
- package/dist/core/solver.d.ts +21 -0
- package/dist/core/solver.js +8 -0
- package/dist/core/translate.js +69 -19
- package/dist/kernel/cdcl.js +212 -78
- package/dist/kernel/kernel.d.ts +17 -1
- package/dist/kernel/kernel.js +158 -2
- package/dist/kernel/prove.d.ts +30 -4
- package/dist/kernel/prove.js +119 -25
- package/dist/kernel/reader.d.ts +74 -5
- package/dist/kernel/reader.js +531 -75
- package/dist/kernel/simplex.d.ts +26 -1
- package/dist/kernel/simplex.js +148 -14
- package/dist/lean-kernel/emit.d.ts +15 -3
- package/dist/lean-kernel/emit.js +144 -12
- package/dist/lean-kernel/library.js +1 -1
- package/package.json +2 -2
package/dist/core/nonterm.js
CHANGED
|
@@ -20,12 +20,14 @@
|
|
|
20
20
|
// among these sets: their bounds and differences grow along the run.
|
|
21
21
|
// - Accelerated cycles, between the runs and the policies (core/accel.ts): a set from a cycle of the loop's relation,
|
|
22
22
|
// the cycle's n-fold run read in closed form (an atom's differences along it), and a stem from a reached state or a
|
|
23
|
-
// run with its loops accelerated, checked as the rest are.
|
|
23
|
+
// run with its loops accelerated, checked as the rest are. A large closure goal (a program of many locations, whose
|
|
24
|
+
// body reads every rule) is closed by the set's parts (`cases`): each part's goal at its location, the location
|
|
25
|
+
// substituted and the constants folded, which leaves only that location's rules (kernel.ts's checkRecurCases).
|
|
24
26
|
import { n as K, same as eq, seeded, walkOnce, x as V } from "./machine.js";
|
|
25
|
-
import { checkRecur, loopMachine, recurGoal, substC, trueC } from "../kernel/kernel.js";
|
|
27
|
+
import { caseGoals, checkRecur, checkRecurCases, coverGoal, loopMachine, recurGoal, substC, trueC } from "../kernel/kernel.js";
|
|
26
28
|
import { clock, counted, grow, realModels } from "../kernel/prove.js";
|
|
27
29
|
import { work } from "./solver.js";
|
|
28
|
-
import { accelerated, stemsTo } from "./accel.js";
|
|
30
|
+
import { accelerated, relationBuilt, stemsTo } from "./accel.js";
|
|
29
31
|
import { findBoundedRun } from "./bmc.js";
|
|
30
32
|
const T = trueC, F = { op: '<', a: K(0), b: K(0) };
|
|
31
33
|
export const isT = (c) => c.op === '<=' && c.a.op === 'const' && c.b.op === 'const' && c.a.value <= c.b.value;
|
|
@@ -107,6 +109,9 @@ const GOAL_MAX = 300_000;
|
|
|
107
109
|
// 11 s; tqli: 720,729 written out, proven in 22 s).
|
|
108
110
|
export const dagSize = (x) => { let n = 0; walkOnce(x, () => { n++; }); return n; };
|
|
109
111
|
const ACCEL_DAG_MAX = 1_500_000;
|
|
112
|
+
// (a goal past this many distinct terms is closed by cases, where `cases` asks for it: pgarch's sets, 537,164, each
|
|
113
|
+
// location's case under 300)
|
|
114
|
+
const CASES_FROM = 20_000;
|
|
110
115
|
// --- running the loop ---------------------------------------------------------------------------------------------------
|
|
111
116
|
class Overflow extends Error {
|
|
112
117
|
}
|
|
@@ -362,9 +367,10 @@ function search(l, opts) {
|
|
|
362
367
|
// 1. Random runs: the states they reach, each with its stem; a lasso on the way is tried at once.
|
|
363
368
|
const visits = [], bounds = [1, 2, 4, 8, 16, 64];
|
|
364
369
|
try {
|
|
365
|
-
// (a fifth of the time, at most 1.5 s, unless only lassos are asked for; at most 4,000 states kept, then
|
|
366
|
-
// run's last)
|
|
367
|
-
|
|
370
|
+
// (a fifth of the time, at most 1.5 s, a run too, unless only lassos are asked for; at most 4,000 states kept, then
|
|
371
|
+
// only a run's last)
|
|
372
|
+
const runsUntil = opts.lassos ? until : Math.min(t0 + (until - t0) * 0.2, t0 + 1500);
|
|
373
|
+
while (now() < runsUntil) {
|
|
368
374
|
const bound = bounds[stats.runs++ % bounds.length], ps = drawParams(bound);
|
|
369
375
|
if (!ps)
|
|
370
376
|
continue;
|
|
@@ -372,7 +378,7 @@ function search(l, opts) {
|
|
|
372
378
|
const stem = [], seen = new Map(), trail = [], run = { n: 0 };
|
|
373
379
|
if (visits.length < 4000)
|
|
374
380
|
visits.push({ params: ps, trail: stem, at: 0, st, run });
|
|
375
|
-
for (let n = 0; n < 3000 && now() <
|
|
381
|
+
for (let n = 0; n < 3000 && now() < runsUntil; n++) {
|
|
376
382
|
const key = keyOf(st), back = seen.get(key);
|
|
377
383
|
if (back !== undefined) {
|
|
378
384
|
const cycle = trail.slice(back).map((s, j) => ({ st: s, input: stem[back + j] }));
|
|
@@ -417,23 +423,48 @@ function search(l, opts) {
|
|
|
417
423
|
if (v.run && (ends.get(v.run)?.at ?? -1) < v.at)
|
|
418
424
|
ends.set(v.run, v);
|
|
419
425
|
const runs = [...ends.values()].sort((a, b) => b.at - a.at).slice(0, 20).map(v => ({ params: v.params, inputs: stemOf(v) }));
|
|
420
|
-
// A set's closure (`budget`: when it stops), then, where no stem is known,
|
|
421
|
-
// k-step goal's model, the set's complement as the law it breaks), then the
|
|
422
|
-
// where the closure ran out of time.
|
|
426
|
+
// A set's closure (`budget`: when it stops), then, where no stem is known, the accelerated runs' search deeper and a
|
|
427
|
+
// bounded run (core/bmc.ts: the kernel's k-step goal's model, the set's complement as the law it breaks), then the
|
|
428
|
+
// kernel's check of each stem; `late` where the closure ran out of time.
|
|
423
429
|
const attempt = (a, goal, stems, cut, budget) => {
|
|
424
430
|
// (a model of the CDCL search whose products don't multiply out goes on to the plain search, which multiplies rows)
|
|
425
431
|
const was = realModels.on;
|
|
426
432
|
realModels.on = true;
|
|
427
|
-
|
|
433
|
+
// (a large goal by its cases, where the set's parts are at locations: each part's goal its location substituted
|
|
434
|
+
// and its constants folded, which leaves the rules at that location, and the cover)
|
|
435
|
+
const byCases = opts.cases && a.cases && dagSize(goal.hyps) > CASES_FROM ? a.cases : undefined;
|
|
436
|
+
let closed, late = false;
|
|
428
437
|
try {
|
|
429
|
-
|
|
438
|
+
for (const g of byCases ? [coverGoal({ set: a.set, cases: byCases }), ...caseGoals(l, a, byCases)] : [goal]) {
|
|
439
|
+
const out = grow(g, new Map(), { nodes: 0, until: budget });
|
|
440
|
+
if (!('tree' in out)) {
|
|
441
|
+
late = out.stuck === 'unknown' && out.why !== undefined;
|
|
442
|
+
closed = undefined;
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
if (!byCases)
|
|
446
|
+
closed = { tree: out.tree };
|
|
447
|
+
else if (!closed)
|
|
448
|
+
closed = { cover: out.tree, cases: [] };
|
|
449
|
+
else if ('cases' in closed)
|
|
450
|
+
closed.cases.push({ ...byCases[closed.cases.length], tree: out.tree });
|
|
451
|
+
}
|
|
430
452
|
}
|
|
431
453
|
finally {
|
|
432
454
|
realModels.on = was;
|
|
433
455
|
}
|
|
434
|
-
if (!
|
|
435
|
-
return
|
|
456
|
+
if (!closed)
|
|
457
|
+
return late ? 'late' : undefined;
|
|
436
458
|
stats.accelClosed++;
|
|
459
|
+
// (the accelerated runs' search again, deeper: fun9's stem of 30 turns)
|
|
460
|
+
if (!stems.length && now() < until)
|
|
461
|
+
for (const t of stemsTo(l, a.targets, { start, turn }, { now, until: Math.min(until, now() + 1000), deepen: true })) {
|
|
462
|
+
const c = cut(t);
|
|
463
|
+
if (c) {
|
|
464
|
+
stems.push(c);
|
|
465
|
+
break;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
437
468
|
if (!stems.length && now() < until) {
|
|
438
469
|
const left = Math.min(until - now(), 2000);
|
|
439
470
|
const run = findBoundedRun(m, [{ name: 'outside the set', holds: { op: 'not', x: a.set } }], { ms: left, depth: 24, ...(opts.counted ? {} : { wall: performance.now() + left }) });
|
|
@@ -442,7 +473,21 @@ function search(l, opts) {
|
|
|
442
473
|
stems.push(c);
|
|
443
474
|
}
|
|
444
475
|
for (const t of stems) {
|
|
445
|
-
const
|
|
476
|
+
const base = { start: params(t.params), stem: asStem(t.stem), set: a.set, wit: a.wit };
|
|
477
|
+
if ('cases' in closed) {
|
|
478
|
+
const cases = { ...base, ...closed };
|
|
479
|
+
let ok = false;
|
|
480
|
+
try {
|
|
481
|
+
ok = checkRecurCases(l, cases);
|
|
482
|
+
}
|
|
483
|
+
catch {
|
|
484
|
+
ok = false;
|
|
485
|
+
}
|
|
486
|
+
if (ok)
|
|
487
|
+
return done({ proven: true, checked: true, cases, by: 'accelerated' });
|
|
488
|
+
continue;
|
|
489
|
+
}
|
|
490
|
+
const recur = { ...base, tree: closed.tree };
|
|
446
491
|
let ok = false;
|
|
447
492
|
try {
|
|
448
493
|
ok = checkRecur(l, recur);
|
|
@@ -458,12 +503,21 @@ function search(l, opts) {
|
|
|
458
503
|
// (sets with a small goal that the accelerated runs' search, run to its end, doesn't reach: after the rest, their
|
|
459
504
|
// closures and bounded runs, in the time the search has left)
|
|
460
505
|
const later = [];
|
|
506
|
+
let deepened = 0;
|
|
461
507
|
const again = [];
|
|
462
|
-
|
|
508
|
+
// (the search for the next candidate has its own time: a closure tried on a set a stem reaches doesn't count
|
|
509
|
+
// against it, up to `extend`; so a set whose closure runs out of time leaves the time to look for a smaller one)
|
|
510
|
+
// (a large loop's relation takes seconds to build, once: the search for candidates starts when it is built, up to
|
|
511
|
+
// 10 s later; pgarch's 203 locations, 4 s to build its loop and 13 s its relation on a laptop)
|
|
512
|
+
const built = now();
|
|
513
|
+
relationBuilt(l);
|
|
514
|
+
let genUntil = accelUntil + Math.min(10_000, now() - built);
|
|
515
|
+
for (const a of accelerated(l, { now, get until() { return genUntil; }, runs, io: { start, turn } })) {
|
|
463
516
|
stats.accel++;
|
|
464
517
|
const goal = recurGoal(l, a);
|
|
465
518
|
stats.goalSize = Math.max(stats.goalSize, goalSize(goal.hyps));
|
|
466
|
-
|
|
519
|
+
// (past the cap a goal is closed only by its cases, each at one location)
|
|
520
|
+
if (dagSize(goal.hyps) > ACCEL_DAG_MAX && !(opts.cases && a.cases))
|
|
467
521
|
continue;
|
|
468
522
|
const inSet = cC(a.set);
|
|
469
523
|
// A stem into the set, cut where it first enters it (every turn allowed): from a state a random run reached (the
|
|
@@ -488,8 +542,19 @@ function search(l, opts) {
|
|
|
488
542
|
for (const v of visits)
|
|
489
543
|
if ((!best || v.at < best.at) && inSet(v.st))
|
|
490
544
|
best = v;
|
|
491
|
-
if (best)
|
|
492
|
-
stems.push({ params: best.params, stem: stemOf(best) });
|
|
545
|
+
if (best) {
|
|
546
|
+
stems.push(cut({ params: best.params, stem: stemOf(best) }) ?? { params: best.params, stem: stemOf(best) });
|
|
547
|
+
// (a run's stem past 64 turns, which Lean replays turn by turn over the whole loop: a shorter one of the
|
|
548
|
+
// accelerated runs' search first, where it finds one within 500 ms)
|
|
549
|
+
if (stems[0].stem.length > 64)
|
|
550
|
+
for (const t of stemsTo(l, a.targets, { start, turn }, { now, until: Math.min(longUntil, now() + 500) })) {
|
|
551
|
+
const c = cut(t);
|
|
552
|
+
if (c && c.stem.length < stems[0].stem.length) {
|
|
553
|
+
stems.unshift(c);
|
|
554
|
+
break;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
493
558
|
else {
|
|
494
559
|
// (a set's stem has time of its own, past the stage's if need be, within the search's)
|
|
495
560
|
let n = 0;
|
|
@@ -502,6 +567,15 @@ function search(l, opts) {
|
|
|
502
567
|
if (++n >= 4)
|
|
503
568
|
break;
|
|
504
569
|
}
|
|
570
|
+
// (a set that search, run to its end, doesn't reach: again deeper, at most 500 ms, for the first four)
|
|
571
|
+
if (!stems.length && report.exhausted && deepened++ < 4)
|
|
572
|
+
for (const t of stemsTo(l, a.targets, { start, turn }, { now, until: Math.min(longUntil, now() + 500), deepen: true })) {
|
|
573
|
+
const c = cut(t);
|
|
574
|
+
if (c) {
|
|
575
|
+
stems.push(c);
|
|
576
|
+
break;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
505
579
|
}
|
|
506
580
|
// (a set the accelerated runs' search, run to its end, doesn't reach is left: the time goes to sets a run
|
|
507
581
|
// reaches; a small one is tried after them)
|
|
@@ -512,10 +586,13 @@ function search(l, opts) {
|
|
|
512
586
|
}
|
|
513
587
|
// (a set with a stem is likely: its closure may take most of what is left, past the stage's share; one without,
|
|
514
588
|
// the stage's share and at most 4 s)
|
|
589
|
+
const tried = now();
|
|
515
590
|
const v = attempt(a, goal, stems, cut, stems.length ? Math.min(until, now() + Math.max(4000, (until - now()) * 0.6)) : Math.min(accelUntil, now() + 4000));
|
|
516
591
|
if (v && v !== 'late')
|
|
517
592
|
return v;
|
|
518
|
-
if (
|
|
593
|
+
if (stems.length)
|
|
594
|
+
genUntil = Math.max(genUntil, Math.min(longUntil - 1000, genUntil + now() - tried));
|
|
595
|
+
if (v === 'late' && stems.length && longUntil > until)
|
|
519
596
|
again.push({ a, goal, stems, cut });
|
|
520
597
|
}
|
|
521
598
|
// (the small sets no stem reaches: a closure and a bounded run each, in what is left of the search's time)
|
|
@@ -526,13 +603,14 @@ function search(l, opts) {
|
|
|
526
603
|
if (v && v !== 'late')
|
|
527
604
|
return v;
|
|
528
605
|
}
|
|
529
|
-
// (a set with a stem whose closure ran out of time: again, with the time `extend` gives,
|
|
530
|
-
//
|
|
531
|
-
again.
|
|
532
|
-
for (const [k, { a, goal, stems, cut }] of
|
|
606
|
+
// (a set with a stem whose closure ran out of time: again, with the time `extend` gives, the smaller goal first,
|
|
607
|
+
// each its share of what is left by its goal's size, the closure's work growing with it)
|
|
608
|
+
const sized = again.map(x => ({ ...x, size: dagSize(x.goal.hyps) })).sort((x, y) => x.size - y.size).slice(0, 6);
|
|
609
|
+
for (const [k, { a, goal, stems, cut, size }] of sized.entries()) {
|
|
533
610
|
if (now() >= longUntil - 1000)
|
|
534
611
|
break;
|
|
535
|
-
const
|
|
612
|
+
const share = size / sized.slice(k).reduce((s, x) => s + x.size, 0);
|
|
613
|
+
const v = attempt(a, goal, stems, cut, Math.min(longUntil, now() + Math.max(2000, (longUntil - now()) * 0.9 * share)));
|
|
536
614
|
if (v && v !== 'late')
|
|
537
615
|
return v;
|
|
538
616
|
}
|
package/dist/core/solver.d.ts
CHANGED
|
@@ -66,6 +66,27 @@ export declare const canon: (l: Lin) => string;
|
|
|
66
66
|
export declare const work: {
|
|
67
67
|
n: number;
|
|
68
68
|
};
|
|
69
|
+
export declare const costs: {
|
|
70
|
+
solves: number;
|
|
71
|
+
solveRows: number;
|
|
72
|
+
fm: number;
|
|
73
|
+
fpivots: number;
|
|
74
|
+
fcells: number;
|
|
75
|
+
cdclNodes: number;
|
|
76
|
+
cdclRows: number;
|
|
77
|
+
scan: number;
|
|
78
|
+
pivots: number;
|
|
79
|
+
pivotRows: number;
|
|
80
|
+
plainNodes: number;
|
|
81
|
+
plainRows: number;
|
|
82
|
+
values: number;
|
|
83
|
+
copies: number;
|
|
84
|
+
edges: number;
|
|
85
|
+
unitRows: number;
|
|
86
|
+
unfoldRows: number;
|
|
87
|
+
goalNodes: number;
|
|
88
|
+
translateRows: number;
|
|
89
|
+
};
|
|
69
90
|
export declare function solve(constraints: Constraint[], maxRows?: number, integral?: boolean): Verdict;
|
|
70
91
|
export declare const ratioRow: (T: Float64Array[], basis: number[], enter: number, cols: number, eps: number) => [number, number];
|
|
71
92
|
export declare function pivot(T: Float64Array[], z: Float64Array | undefined, basis: number[], leave: number, enter: number, cols: number): void;
|
package/dist/core/solver.js
CHANGED
|
@@ -100,8 +100,13 @@ export const canon = (l) => JSON.stringify(Object.keys(l).sort().map(x => [x, l[
|
|
|
100
100
|
// five times as many before merging them, it gives up with `unknown`.
|
|
101
101
|
// The rows the solver has read and made, which a counted search reads as its clock (kernel/prove.ts's `counted`).
|
|
102
102
|
export const work = { n: 0 };
|
|
103
|
+
// What the searches did, by kind, beside work.n (research/query reads them: the cost of each query's parts).
|
|
104
|
+
export const costs = { solves: 0, solveRows: 0, fm: 0, fpivots: 0, fcells: 0, cdclNodes: 0, cdclRows: 0, scan: 0, pivots: 0, pivotRows: 0, plainNodes: 0, plainRows: 0,
|
|
105
|
+
values: 0, copies: 0, edges: 0, unitRows: 0, unfoldRows: 0, goalNodes: 0, translateRows: 0 };
|
|
103
106
|
export function solve(constraints, maxRows = 20_000, integral = true) {
|
|
104
107
|
work.n += constraints.length;
|
|
108
|
+
costs.solves++;
|
|
109
|
+
costs.solveRows += constraints.length;
|
|
105
110
|
const steps = [];
|
|
106
111
|
const lins = [], stricts = [];
|
|
107
112
|
const push = (step, lin, strict = false) => (steps.push(step), lins.push(lin), stricts.push(strict), lins.length - 1);
|
|
@@ -226,6 +231,7 @@ export function solve(constraints, maxRows = 20_000, integral = true) {
|
|
|
226
231
|
if (choice.pos.length * choice.neg.length > 5 * maxRows)
|
|
227
232
|
return { kind: 'unknown' };
|
|
228
233
|
work.n += choice.pos.length * choice.neg.length;
|
|
234
|
+
costs.fm += choice.pos.length * choice.neg.length;
|
|
229
235
|
exact &&= choice.isExact;
|
|
230
236
|
eliminated.push({ x: choice.x, rows: [...choice.pos, ...choice.neg] });
|
|
231
237
|
const next = rows.filter(r => (lins[r][choice.x] ?? 0) === 0);
|
|
@@ -417,6 +423,8 @@ export function refuteFast(constraints, maxRows = 2_000, integral = true) {
|
|
|
417
423
|
const eps = 1e-9;
|
|
418
424
|
for (let iter = 0; iter < 50 * (R + m); iter++) {
|
|
419
425
|
work.n += 1 + ((R * cols) >> 8);
|
|
426
|
+
costs.fpivots++;
|
|
427
|
+
costs.fcells += (R * cols) >> 8;
|
|
420
428
|
// Bland's rule: the first column with a negative reduced cost enters (no cycling on degenerate systems).
|
|
421
429
|
let enter = -1;
|
|
422
430
|
for (let j = 0; j < cols; j++)
|
package/dist/core/translate.js
CHANGED
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
// keys over Ω the node's path doesn't yet compare) is grown again on the node's goal at its path (`regrown`); a split the
|
|
11
11
|
// node's path already decides is followed, not made again.
|
|
12
12
|
import { walk } from "./machine.js";
|
|
13
|
-
import { add, env, refuteFast, scale, solve } from "./solver.js";
|
|
13
|
+
import { add, costs, env, refuteFast, scale, solve } from "./solver.js";
|
|
14
14
|
import { checkRefutation } from "./check.js";
|
|
15
|
-
import { canon, canonFlip, columnTerm, factorsOf, isCell, isMonomial, leafConstraintsReusing, linear, substE, truth, withProducts } from "../kernel/kernel.js";
|
|
16
|
-
import { cellProducts, clock, grow, parseKey } from "../kernel/prove.js";
|
|
17
|
-
import { times } from "../kernel/reader.js";
|
|
15
|
+
import { canon, canonFlip, columnTerm, factorsOf, isCell, isMonomial, leafConstraints, leafConstraintsReusing, linear, substE, truth, withProducts } from "../kernel/kernel.js";
|
|
16
|
+
import { cellProducts, clock, grow, leafRowsOf, parseKey } from "../kernel/prove.js";
|
|
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).
|
|
@@ -89,6 +89,45 @@ const known = (lin, wp) => {
|
|
|
89
89
|
const b = wp.get(canonFlip(lin));
|
|
90
90
|
return b ? !b.holds : undefined;
|
|
91
91
|
};
|
|
92
|
+
const trailed = new WeakMap();
|
|
93
|
+
function rowsAt(g, wp) {
|
|
94
|
+
// (a path with an atom about a term column, a cut's, read by kernel.ts: the reader's columns aren't kept for those)
|
|
95
|
+
for (const a of wp.values())
|
|
96
|
+
for (const key in a.lin)
|
|
97
|
+
if (key.startsWith('⟦'))
|
|
98
|
+
return leafConstraintsReusing(g, wp);
|
|
99
|
+
let t = trailed.get(g);
|
|
100
|
+
if (!t) {
|
|
101
|
+
const stack = [], on = new Map(), stamps = [];
|
|
102
|
+
t = { stack, on, stamps, n: 0, reader: new Reader(g, { get: name => on.get(name), stamp: at => stamps[at], size: () => stack.length, lin: at => stack[at] }) };
|
|
103
|
+
trailed.set(g, t);
|
|
104
|
+
}
|
|
105
|
+
const s = t, ps = [...wp];
|
|
106
|
+
let k = 0;
|
|
107
|
+
while (k < s.stack.length && k < ps.length && s.stack[k].name === ps[k][0] && s.stack[k].holds === ps[k][1].holds)
|
|
108
|
+
k++;
|
|
109
|
+
while (s.stack.length > k) {
|
|
110
|
+
const name = s.stack.pop().name;
|
|
111
|
+
s.on.delete(name);
|
|
112
|
+
s.reader.touch(name);
|
|
113
|
+
}
|
|
114
|
+
for (const [name, a] of ps.slice(k)) {
|
|
115
|
+
s.on.set(name, { val: a.holds, at: s.stack.length });
|
|
116
|
+
s.stamps[s.stack.length] = ++s.n;
|
|
117
|
+
s.stack.push({ name, lin: a.lin, holds: a.holds });
|
|
118
|
+
s.reader.touch(name);
|
|
119
|
+
}
|
|
120
|
+
s.reader.begin();
|
|
121
|
+
const rows = s.reader.leafRows();
|
|
122
|
+
if (env.GDP_CDCL_VERIFY === '1') {
|
|
123
|
+
const kr = leafConstraints(g, wp);
|
|
124
|
+
if (kr.length !== rows.length || kr.some((r, j) => canon(r.lin) !== canon(rows[j].lin))) {
|
|
125
|
+
const j = kr.findIndex((r, j2) => canon(r.lin) !== canon(rows[j2]?.lin ?? {}));
|
|
126
|
+
throw new Error(`reader.ts's rows differ from kernel.ts's at a translated leaf of ${g.name}: ${kr.length} vs ${rows.length}, at ${j}: ${JSON.stringify(kr[j])} vs ${JSON.stringify(rows[j]?.lin)}; path ${JSON.stringify([...wp].map(([key, a]) => [key, a.holds]))}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return rows;
|
|
130
|
+
}
|
|
92
131
|
// The node's goal grown at a path (cell products on, as every cyclic goal is), within the deadline.
|
|
93
132
|
function regrow(whole, wp, until) {
|
|
94
133
|
const was = cellProducts.on;
|
|
@@ -132,18 +171,29 @@ export function translate(part, whole, tree, ren0, st, until, pp = new Map(), wp
|
|
|
132
171
|
const no = yes && translate(part, whole, tree.no, ren0, st, until, new Map(pp).set(id, { lin: tree.split, holds: false }), new Map(wp).set(wid, { lin: wl, holds: false }), swaps);
|
|
133
172
|
return yes && no ? { split: wl, yes, no } : undefined;
|
|
134
173
|
}
|
|
135
|
-
|
|
174
|
+
// (past its budget, no translation: each leaf reads the two goals' rows whole, counted, so a large tree's stops there)
|
|
175
|
+
if (clock() > until)
|
|
176
|
+
return undefined;
|
|
177
|
+
// (the usual leaf's rows as its search kept them, where it did: kernel/prove.ts's leafRowsOf; else read again)
|
|
178
|
+
const kept = !tree.products && !tree.squares ? leafRowsOf.get(tree) : undefined;
|
|
179
|
+
const rp = kept ? undefined : leafConstraintsReusing(part, pp), rw = rowsAt(whole, wp), at = new Map();
|
|
180
|
+
const np = kept ? kept.n : rp.length, linP = (i) => (kept ? kept.at.get(i).lin : rp[i].lin);
|
|
181
|
+
const pairP = (i) => { if (kept) {
|
|
182
|
+
const s = kept.at.get(i)?.src;
|
|
183
|
+
return Array.isArray(s) ? s : undefined;
|
|
184
|
+
} const s = rp[i].src; return s && 'pair' in s ? s.pair : undefined; };
|
|
185
|
+
costs.translateRows += (rp?.length ?? 0) + rw.length;
|
|
136
186
|
rw.forEach((r, i) => { const key = canon(r.lin); if (!at.has(key))
|
|
137
187
|
at.set(key, i); });
|
|
138
188
|
// Two cells the usual path proves equal (a row of the leaf's from their pair) are cells over time here, at keys
|
|
139
189
|
// (t − 1) + a·Ω and (t − 1) + b·Ω: the path has a = b, and the keys' difference (a − b)·Ω is split (each other side
|
|
140
190
|
// refuted by (a − b)·Ω = 0, the product of a − b <= 0 or b − a <= 0 with Ω >= 0), the leaf then read again.
|
|
141
|
-
const usedRows = [...tree.leaf.flatMap(x => (x.kind === 'input' ? [x.index] : [])), ...(tree.products ?? []).flat()].filter(i => i <
|
|
191
|
+
const usedRows = [...tree.leaf.flatMap(x => (x.kind === 'input' ? [x.index] : [])), ...(tree.products ?? []).flat()].filter(i => i < np);
|
|
142
192
|
for (const i of usedRows) {
|
|
143
|
-
const
|
|
144
|
-
if (!
|
|
193
|
+
const pair = pairP(i);
|
|
194
|
+
if (!pair)
|
|
145
195
|
continue;
|
|
146
|
-
const a = ren({ [
|
|
196
|
+
const a = ren({ [pair[0]]: 1 }, wp), b = ren({ [pair[1]]: 1 }, wp), [ca] = Object.keys(a ?? {}), [cb] = Object.keys(b ?? {});
|
|
147
197
|
if (!ca || !cb || !isCell(ca) || !isCell(cb))
|
|
148
198
|
continue;
|
|
149
199
|
const d = add(keyOf(ca), scale(keyOf(cb), -1)), q0 = {};
|
|
@@ -167,8 +217,8 @@ export function translate(part, whole, tree, ren0, st, until, pp = new Map(), wp
|
|
|
167
217
|
}
|
|
168
218
|
}
|
|
169
219
|
st.leaves++;
|
|
170
|
-
const map = (i) => { if (i >=
|
|
171
|
-
return i -
|
|
220
|
+
const map = (i) => { if (i >= np)
|
|
221
|
+
return i - np + rw.length; const l = ren(linP(i), wp); return l && at.get(canon(l)); };
|
|
172
222
|
const leaf = [], products = [], squares = (tree.squares ?? []).map(s => ren(s, wp));
|
|
173
223
|
let ok = squares.every(Boolean);
|
|
174
224
|
for (const s of ok ? tree.leaf : []) {
|
|
@@ -194,8 +244,8 @@ export function translate(part, whole, tree, ren0, st, until, pp = new Map(), wp
|
|
|
194
244
|
if (ok && checkRefutation(withProducts(rw, products, squares), leaf))
|
|
195
245
|
return { leaf, ...(tree.products ? { products } : {}), ...(tree.squares ? { squares: squares } : {}) };
|
|
196
246
|
if (debugOn()) {
|
|
197
|
-
const missing = tree.leaf.flatMap(s => (s.kind === 'input' && s.index <
|
|
198
|
-
console.error(`[leaf] ${whole.name}: ${ok ? 'rows found, refutation refused' : `${missing.length} rows missing`}${missing.slice(0, 3).map(i => `; ${JSON.stringify(
|
|
247
|
+
const missing = tree.leaf.flatMap(s => (s.kind === 'input' && s.index < np && map(s.index) === undefined ? [s.index] : []));
|
|
248
|
+
console.error(`[leaf] ${whole.name}: ${ok ? 'rows found, refutation refused' : `${missing.length} rows missing`}${missing.slice(0, 3).map(i => `; ${JSON.stringify(linP(i))} as ${JSON.stringify(ren(linP(i), wp) ?? 'no form')}`).join('')}`);
|
|
199
249
|
}
|
|
200
250
|
return close(whole, wp, st, until);
|
|
201
251
|
}
|
|
@@ -229,7 +279,7 @@ export function readsFirst(whole, reads, ren, inner, st, until, wp = new Map(),
|
|
|
229
279
|
// 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
|
|
230
280
|
// that row and Ω >= 0.
|
|
231
281
|
function apart(whole, wp, l, q, st, until) {
|
|
232
|
-
const rows =
|
|
282
|
+
const rows = rowsAt(whole, wp), find = (x) => { const c = canon(x); return rows.findIndex(r => canon(r.lin) === c); };
|
|
233
283
|
const iq = find(q), io = find({ [omega]: -1 }), ia = find(add({ 1: 1 }, scale(l, -1)));
|
|
234
284
|
if (iq >= 0 && io >= 0 && ia >= 0) {
|
|
235
285
|
const leaf = [{ kind: 'input', index: ia }, { kind: 'input', index: rows.length }, { kind: 'combine', a: 0, b: 1, ma: 1, mb: 1 }], products = [[iq, io]];
|
|
@@ -285,7 +335,7 @@ export function decide(whole, conds, inner, st, until, wp = new Map()) {
|
|
|
285
335
|
}
|
|
286
336
|
// A leaf of `g` at the path: a hypothesis false there (its row 1 <= 0), or with `solveIt` the rows refuted by the solver.
|
|
287
337
|
function leafAt(g, wp, solveIt, st) {
|
|
288
|
-
const rows =
|
|
338
|
+
const rows = rowsAt(g, wp), absurd = rows.findIndex(r => Object.keys(r.lin).every(key => key === '1') && (r.lin['1'] ?? 0) > 0);
|
|
289
339
|
if (absurd >= 0) {
|
|
290
340
|
st.leaves++;
|
|
291
341
|
return { leaf: [{ kind: 'input', index: absurd }] };
|
|
@@ -318,7 +368,7 @@ const open = (c, wp) => atomsOf(c, wp)?.find(l => known(l, wp) === undefined);
|
|
|
318
368
|
// Two reads of one function at keys the path doesn't yet prove equal or apart, keys linear (keys through a choice's
|
|
319
369
|
// column after the others: such a column is often one the path decides later).
|
|
320
370
|
function cellAtom(g, wp) {
|
|
321
|
-
const rows =
|
|
371
|
+
const rows = rowsAt(g, wp), names = [...new Set(rows.flatMap(r => Object.keys(r.lin)))].filter(isCell);
|
|
322
372
|
let later;
|
|
323
373
|
for (const [i, p] of names.entries())
|
|
324
374
|
for (const q of names.slice(i + 1)) {
|
|
@@ -351,7 +401,7 @@ const choiceOf = (e, wp) => {
|
|
|
351
401
|
return Object.keys(d).some(key => key !== '1') && known(d, wp) === undefined ? d : undefined;
|
|
352
402
|
};
|
|
353
403
|
function choiceAtom(g, wp) {
|
|
354
|
-
const rows =
|
|
404
|
+
const rows = rowsAt(g, wp);
|
|
355
405
|
for (const name of new Set(rows.flatMap(r => Object.keys(r.lin)))) {
|
|
356
406
|
const e = name.startsWith('⟦') ? columnTerm(name) : undefined;
|
|
357
407
|
const l = e && e.op === 'if' ? choiceOf(e, wp) : undefined;
|
|
@@ -387,7 +437,7 @@ function conclCells(g, wp) {
|
|
|
387
437
|
// Two cells over time at keys u + a·Ω and u + b·Ω: a = b decided first, then the keys' difference, its other side
|
|
388
438
|
// refuted by the product (`apart`).
|
|
389
439
|
function omegaPair(g, wp) {
|
|
390
|
-
const rows =
|
|
440
|
+
const rows = rowsAt(g, wp), names = [...new Set([...rows.flatMap(r => Object.keys(r.lin)), ...conclCells(g, wp)])].filter(isCell);
|
|
391
441
|
for (const [i, p] of names.entries())
|
|
392
442
|
for (const q of names.slice(i + 1)) {
|
|
393
443
|
if (p.slice(0, p.indexOf('[')) !== q.slice(0, q.indexOf('[')))
|
|
@@ -545,7 +595,7 @@ export function carry(g, nFacts, nUses, st, until) {
|
|
|
545
595
|
const y = side(yes), n = y && side(no);
|
|
546
596
|
return y && n ? { split: next, yes: y, no: n } : undefined;
|
|
547
597
|
};
|
|
548
|
-
const quick = (wp) => { const rows =
|
|
598
|
+
const quick = (wp) => { const rows = rowsAt(g, wp), v = refuteFast(rows); if (v?.kind !== 'refuted')
|
|
549
599
|
return undefined; st.leaves++; return { leaf: v.steps }; };
|
|
550
600
|
return node(new Map(), false);
|
|
551
601
|
}
|