gdp-wired 0.51.0 → 0.52.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 +2 -2
- package/dist/core/accel-refute.d.ts +53 -0
- package/dist/core/accel-refute.js +997 -0
- package/dist/core/cli.d.ts +2 -0
- package/dist/core/cli.js +8 -1
- package/dist/core/cycles.d.ts +2 -0
- package/dist/core/cycles.js +12 -9
- package/dist/core/dsl.d.ts +7 -1
- package/dist/core/dsl.js +147 -26
- package/dist/core/live-support.d.ts +5 -0
- package/dist/core/live-support.js +148 -0
- package/dist/core/live.js +194 -37
- package/dist/core/lockstep.d.ts +5 -0
- package/dist/core/lockstep.js +23 -0
- package/dist/core/ordered-pair-seeds.d.ts +2 -0
- package/dist/core/ordered-pair-seeds.js +109 -0
- package/dist/core/proof-output.d.ts +38 -1
- package/dist/core/proof-output.js +38 -0
- package/dist/core/search-termination.d.ts +4 -0
- package/dist/core/search-termination.js +1 -1
- package/dist/core/source-check.d.ts +4 -1
- package/dist/core/source-check.js +5 -2
- package/dist/core/sparse-kind-proof.d.ts +7 -0
- package/dist/core/sparse-kind-proof.js +49 -0
- package/dist/core/step-seeds.d.ts +46 -0
- package/dist/core/step-seeds.js +316 -0
- package/dist/lean-kernel/Cert.lean +222 -0
- package/dist/lean-kernel/Count.lean +1568 -0
- package/dist/lean-kernel/Ghost.lean +373 -0
- package/dist/lean-kernel/GhostMap.lean +426 -0
- package/dist/lean-kernel/Kernel.lean +2881 -0
- package/dist/lean-kernel/Live.lean +1168 -0
- package/dist/lean-kernel/Progress.lean +543 -0
- package/dist/lean-kernel/Sets.lean +1975 -0
- package/dist/lean-kernel/StepLaw.lean +128 -0
- package/dist/lean-kernel/Steps.lean +477 -0
- package/dist/lean-kernel/Sums.lean +916 -0
- package/dist/lean-kernel/emit.d.ts +4 -0
- package/dist/lean-kernel/emit.js +23 -4
- package/dist/lean-kernel/lean-aggregate/FiniteFold.lean +44 -0
- package/dist/lean-kernel/lean-aggregate/GroupedTransport.lean +308 -0
- package/dist/lean-kernel/lean-aggregate/aggregate.d.ts +13 -0
- package/dist/lean-kernel/lean-aggregate/aggregate.js +68 -0
- package/dist/lean-kernel/lean-aggregate/assets.d.ts +5 -0
- package/dist/lean-kernel/lean-aggregate/assets.js +7 -0
- package/dist/lean-kernel/lean-aggregate/audit.d.ts +3 -0
- package/dist/lean-kernel/lean-aggregate/audit.js +13 -0
- package/dist/lean-kernel/lean-aggregate/exact.d.ts +15 -0
- package/dist/lean-kernel/lean-aggregate/exact.js +51 -0
- package/dist/lean-kernel/lean-aggregate/index.d.ts +19 -0
- package/dist/lean-kernel/lean-aggregate/index.js +52 -0
- package/dist/lean-kernel/lean-aggregate/point-fold.d.ts +27 -0
- package/dist/lean-kernel/lean-aggregate/point-fold.js +79 -0
- package/dist/lean-kernel/lean-aggregate/replay-fold.d.ts +2 -0
- package/dist/lean-kernel/lean-aggregate/replay-fold.js +163 -0
- package/dist/lean-kernel/lean-aggregate/source.d.ts +2 -0
- package/dist/lean-kernel/lean-aggregate/source.js +141 -0
- package/dist/lean-kernel/lean-aggregate/weighted-flags.d.ts +2 -0
- package/dist/lean-kernel/lean-aggregate/weighted-flags.js +26 -0
- package/dist/lean-kernel/lean-aggregate/weighted-replay.d.ts +7 -0
- package/dist/lean-kernel/lean-aggregate/weighted-replay.js +53 -0
- package/dist/lean-kernel/lean-aggregate/weighted-seeded.d.ts +30 -0
- package/dist/lean-kernel/lean-aggregate/weighted-seeded.js +64 -0
- package/dist/lean-kernel/lean-aggregate/weighted.d.ts +18 -0
- package/dist/lean-kernel/lean-aggregate/weighted.js +115 -0
- package/dist/lean-kernel/lean-aggregate/worker.d.ts +10 -0
- package/dist/lean-kernel/lean-aggregate/worker.js +46 -0
- package/docs/lean-aggregate.md +29 -0
- package/package.json +6 -1
package/dist/core/cli.d.ts
CHANGED
|
@@ -51,6 +51,8 @@ type LawOut = SearchTerminationFields & Omit<TranslationFields, 'translationWitn
|
|
|
51
51
|
from?: 'any';
|
|
52
52
|
verdict: 'proven' | 'broken' | 'unknown' | 'not read';
|
|
53
53
|
run?: string[];
|
|
54
|
+
fairRing?: Verdict['fairRing'];
|
|
55
|
+
acceleratedRun?: Verdict['acceleratedRun'];
|
|
54
56
|
replayed?: string;
|
|
55
57
|
why?: string;
|
|
56
58
|
assumes?: string[];
|
package/dist/core/cli.js
CHANGED
|
@@ -787,7 +787,10 @@ function prove(x0, l, ms, proven, ctx, work = ctx?.work) {
|
|
|
787
787
|
catch (e) {
|
|
788
788
|
return { ...base, kind: 'leads to', verdict: 'unknown', why: e.message, ms: cliNow() - t0 };
|
|
789
789
|
}
|
|
790
|
-
|
|
790
|
+
const checked = v.proven && v.checked, ring = v.translation === undefined ? v.fairRing : undefined;
|
|
791
|
+
return { ...base, ...translationOf(v), ...searchOf(v), kind: 'leads to', verdict: checked ? 'proven' : 'unknown',
|
|
792
|
+
...(ring ? { fairRing: ring, why: `a model fair ring stays pending (${ring.stem.length} stem steps, ${ring.sets.length} recurring sets); native source replay unavailable` } :
|
|
793
|
+
checked ? {} : { why: whyOf(v, [v.goal, v.stuck, v.why].filter(Boolean).join('; ') || 'not proven') }), ms: cliNow() - t0 };
|
|
791
794
|
}
|
|
792
795
|
let b, two;
|
|
793
796
|
// (a law that can't be built is not read, with why: never the whole check aborted)
|
|
@@ -844,6 +847,10 @@ function prove(x0, l, ms, proven, ctx, work = ctx?.work) {
|
|
|
844
847
|
if (!v.run)
|
|
845
848
|
v = { ...v, why: `broken from a state the laws allow (from = "any"), no run from the start found reaching it` };
|
|
846
849
|
}
|
|
850
|
+
const accelerated = v.translation === undefined && v.acceleratedRun?.checked ? v.acceleratedRun : undefined;
|
|
851
|
+
if (accelerated)
|
|
852
|
+
return { ...base, ...searchOf(v), kind, verdict: 'unknown', acceleratedRun: accelerated,
|
|
853
|
+
why: `an accelerated model run of ${accelerated.totalSteps} admitted steps breaks the law; native source replay unavailable`, ms: cliNow() - t0 };
|
|
847
854
|
const brokenAt = !!(ctx?.from && !v.proven && !v.run && !searchOf(v).stopped && v.stuck === 'sat' && v.witness);
|
|
848
855
|
let verdict = v.proven && v.checked && !(ctx?.from && v.assumes) ? 'proven' : v.run || brokenAt ? 'broken' : 'unknown', replayed;
|
|
849
856
|
if (v.translation === 'unchecked')
|
package/dist/core/cycles.d.ts
CHANGED
|
@@ -115,7 +115,9 @@ export type Sampler = {
|
|
|
115
115
|
export type LeadsVerdict = {
|
|
116
116
|
proven: boolean;
|
|
117
117
|
checked: boolean;
|
|
118
|
+
evidence?: import('./proof-output.ts').LiveProofPacket;
|
|
118
119
|
rank?: E[];
|
|
120
|
+
levels?: number[];
|
|
119
121
|
laws?: Law[];
|
|
120
122
|
found?: {
|
|
121
123
|
rank: string;
|
package/dist/core/cycles.js
CHANGED
|
@@ -6,6 +6,7 @@ import { and, proveCyclic, vars as vs } from "./cyclic.js";
|
|
|
6
6
|
import { canon, env, gcd, konst, pivot, plus, ratioRow, refuteFast, solve, subst, times, vars, work } from "./solver.js";
|
|
7
7
|
import { clock, grow, proveLaws, proveLiveness, proveStepLaws, withDeadline } from "../kernel/prove.js";
|
|
8
8
|
import { inferLaws } from "./infer.js";
|
|
9
|
+
import { withStageDeadline } from "./dsl-deadline.js";
|
|
9
10
|
import { bgcd } from "./q.js";
|
|
10
11
|
import { generators, houdini, relationOf, tightBounds } from "./relation.js";
|
|
11
12
|
// --- terms ----------------------------------------------------------------------------------------------------------
|
|
@@ -1892,9 +1893,11 @@ export function findLeadsTo(m, laws, l, sample, opts = {}) {
|
|
|
1892
1893
|
const ms = until - clock();
|
|
1893
1894
|
if (ms < 200)
|
|
1894
1895
|
break;
|
|
1895
|
-
const v =
|
|
1896
|
+
const v = withStageDeadline(clock() + ms * (i === 0 && !strong.size ? 0.5 : 0.25), () => proveLiveness(m, laws, { ...l, rank }), () => undefined);
|
|
1897
|
+
if (!v)
|
|
1898
|
+
continue;
|
|
1896
1899
|
if (v.proven && v.checked)
|
|
1897
|
-
return { proven: true, checked: true, rank, laws: [], found: { rank: rankText(rank), laws: [] } };
|
|
1900
|
+
return { proven: true, checked: true, rank, levels: v.levels, laws: [], evidence: { machine: m, laws, liveness: { ...l, rank, ...(v.levels ? { levels: v.levels } : {}) }, report: v }, found: { rank: rankText(rank), laws: [] } };
|
|
1898
1901
|
tried.set(id(rank), v);
|
|
1899
1902
|
}
|
|
1900
1903
|
const samples = [[...points.values()].map(env => ({ env, calls: new Set() }))];
|
|
@@ -1906,21 +1909,21 @@ export function findLeadsTo(m, laws, l, sample, opts = {}) {
|
|
|
1906
1909
|
if (!rank)
|
|
1907
1910
|
return { proven: false, checked: false, why: noRank };
|
|
1908
1911
|
const text = rankText(rank), lv = { ...l, rank };
|
|
1909
|
-
const first = tried.get(id(rank)) ??
|
|
1910
|
-
if (first
|
|
1911
|
-
return { proven: true, checked: true, rank, laws: [], found: { rank: text, laws: [] } };
|
|
1912
|
+
const first = tried.get(id(rank)) ?? withStageDeadline(until, () => proveLiveness(m, laws, lv), () => undefined);
|
|
1913
|
+
if (first?.proven && first.checked)
|
|
1914
|
+
return { proven: true, checked: true, rank, levels: first.levels, laws: [], evidence: { machine: m, laws, liveness: { ...lv, ...(first.levels ? { levels: first.levels } : {}) }, report: first }, found: { rank: text, laws: [] } };
|
|
1912
1915
|
const ms = until - clock();
|
|
1913
1916
|
if (ms > 300) {
|
|
1914
1917
|
const { stay, cover, helps } = livenessParts(m, lv), inf = inferLaws(sample.rule ?? m, laws, [stay, cover, ...helps], { ms });
|
|
1915
1918
|
// (laws about every key too: a liveness about every key needs those of its key's cells)
|
|
1916
1919
|
const kept = inf.found.filter(f => !f.law.some?.length), more = kept.map(f => f.law);
|
|
1917
1920
|
if (inf.proven && more.length) {
|
|
1918
|
-
const again =
|
|
1919
|
-
if (again
|
|
1920
|
-
return { proven: true, checked: true, rank, laws: more, found: { rank: text, laws: kept.map(f => f.text) } };
|
|
1921
|
+
const again = withStageDeadline(until, () => proveLiveness(m, [...laws, ...more], lv), () => undefined);
|
|
1922
|
+
if (again?.proven && again.checked)
|
|
1923
|
+
return { proven: true, checked: true, rank, levels: again.levels, laws: more, evidence: { machine: m, laws: [...laws, ...more], liveness: { ...lv, ...(again.levels ? { levels: again.levels } : {}) }, report: again }, found: { rank: text, laws: kept.map(f => f.text) } };
|
|
1921
1924
|
}
|
|
1922
1925
|
}
|
|
1923
|
-
const failed = first
|
|
1926
|
+
const failed = first?.failed ? { goal: first.failed.goal, stuck: first.failed.stuck, ...(first.failed.witness ? { witness: first.failed.witness } : {}) } : {};
|
|
1924
1927
|
if (!fitted)
|
|
1925
1928
|
return { proven: false, checked: false, ...failed, why: `${noRank}; rank ${text}, which the runs allow, not proven, nor with the invariants found` };
|
|
1926
1929
|
return { proven: false, checked: false, rank, found: { rank: text, laws: [] }, ...failed, why: `rank ${text} from the runs; the kernel's goals not proven with it` };
|
package/dist/core/dsl.d.ts
CHANGED
|
@@ -5,7 +5,10 @@ import { type C, type E, type Fn, type Law, type Recurrence, type Machine, type
|
|
|
5
5
|
import { type Fold, type Ghosted, type Goal, type Liveness, type Loop, type Recur, type StepLaw, type Tree } from '../kernel/kernel.js';
|
|
6
6
|
import { type Report, type ModelRoundPolicy } from '../kernel/prove.js';
|
|
7
7
|
import { type WorkAmount } from './work-amount.js';
|
|
8
|
-
import {
|
|
8
|
+
import { type AcceleratedRun, type AcceleratedSegment, checkAcceleratedRun, findAcceleratedRefutation, formatAcceleratedSummary } from './accel-refute.js';
|
|
9
|
+
export type { AcceleratedRun, AcceleratedSegment };
|
|
10
|
+
export { checkAcceleratedRun, findAcceleratedRefutation, formatAcceleratedSummary };
|
|
11
|
+
import { findRing, type Ring } from './live.js';
|
|
9
12
|
export type TermLike = Term | number;
|
|
10
13
|
export declare const termOf: (t: TermLike) => E;
|
|
11
14
|
export type Rounding = 'halfEven' | 'halfUp' | 'halfDown' | 'halfAway';
|
|
@@ -943,6 +946,9 @@ export type Verdict = TranslationFields & import('./search-termination.ts').Sear
|
|
|
943
946
|
k?: number;
|
|
944
947
|
assumes?: Assumes;
|
|
945
948
|
rank?: E | E[];
|
|
949
|
+
levels?: number[];
|
|
950
|
+
fairRing?: Ring;
|
|
951
|
+
acceleratedRun?: AcceleratedRun;
|
|
946
952
|
};
|
|
947
953
|
export type Assumes = {
|
|
948
954
|
states: 'reachable';
|
package/dist/core/dsl.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { retainFrom, retainCounted, publishProof, withPublicRule } from "./proof-output.js";
|
|
1
|
+
import { retainFrom, retainCounted, publishProof, withPublicRule, retainStepProof, publishStepProof, retainLiveProof, publishLiveProof } from "./proof-output.js";
|
|
2
2
|
import { searchNow as countedSearchNow } from "./wall.js";
|
|
3
3
|
// Typed builders for machines, decisions and loops: names are declared once and come back as typed values, so a
|
|
4
4
|
// misspelled name, a law that reads a request, or a step that sets an undeclared variable is a TypeScript error, and
|
|
@@ -23,16 +23,20 @@ export { fixedInt, FixedWord, fixedFailure, fixedSelect } from "./fixed-integers
|
|
|
23
23
|
import { binder, copyVariable, encodeBinders, generatedVariable, guardReserved, internalName, plainDeclaration, variable } from "./dsl-binders.js";
|
|
24
24
|
import { candidates, cone, searchCounted } from "./counts.js";
|
|
25
25
|
import { proveCandidateSeeds } from "./candidate-seeds.js";
|
|
26
|
+
import { orderedPairSeed } from "./ordered-pair-seeds.js";
|
|
27
|
+
import { tryLockstepScalars } from "./lockstep.js";
|
|
26
28
|
import { proveCountedCandidateSeeds } from "./counted-candidate-seeds.js";
|
|
27
|
-
import {
|
|
29
|
+
import { stepSeedFamilies, tryStepSeed } from "./step-seeds.js";
|
|
30
|
+
import { bindSourceMachine, inheritSource, isSourceBound, translationVerdict } from "./source-check.js";
|
|
28
31
|
import { env as knobs } from "./solver.js";
|
|
29
32
|
import { argsKey, bindDirect, directOf, machineTerms, part, tuple, carriedView, compileFunction, divName, divisor, divisorsIn, evalC, evalE, fnCall, hasFinite, interpret, isArithmetic, loadJs, modName, numbersOf, pairedArgs, seeded, sourceFreeFn, withArithmetic } from "./machine.js";
|
|
30
33
|
import { allowed, keysOf, requestEnv, watch, watchWork } from "./watch.js";
|
|
31
34
|
import { ghostOf, proveSome, skolemOf, someHolds, substVars, substVarsE, witnessSupport } from "./exists.js";
|
|
32
35
|
import { check, mapArities, checkRecur, foldObligations, ghostedMachine, loopObligations, someOfGhostsOk, substC, sumMachine } from "../kernel/kernel.js";
|
|
33
36
|
import { certLoop, clock, counted, factsFor, fullRate, grow, pastWall, proveLaw, proveLaws, proveLiveness, proveSetFast, proveStepLaws, usualProof, withModelRounds, withWall } from "../kernel/prove.js";
|
|
34
|
-
import { WallExpired, checkWall, checkBudget, checkWorkEndpoint, searchWall, withBudget, BudgetExpired } from "./wall.js";
|
|
37
|
+
import { WallExpired, checkWall, checkBudget, checkWorkEndpoint, searchWall, withBudget, inBudget, BudgetExpired } from "./wall.js";
|
|
35
38
|
import { completeWorkProfile } from "./work-profile.js";
|
|
39
|
+
import { stepWorkProfile } from "./step-work.js";
|
|
36
40
|
import { workLedger } from "./work-admission.js";
|
|
37
41
|
import { withStageAllowance, withStageDeadline, withStageWall, withStageWork, remainingStageWork } from "./dsl-deadline.js";
|
|
38
42
|
import { completedSearch, searchContext, stoppedSearch } from "./search-termination.js";
|
|
@@ -44,10 +48,13 @@ import { certCyclic, certOn, crossCyclic, cyclicOn, foldNodes, proveCyclic, quie
|
|
|
44
48
|
import { discover } from "./discover.js";
|
|
45
49
|
import { inferLaws, inferRates } from "./infer.js";
|
|
46
50
|
import { findBoundedRun } from "./bmc.js";
|
|
51
|
+
import { checkAcceleratedRun, findAcceleratedRefutation, formatAcceleratedSummary } from "./accel-refute.js";
|
|
52
|
+
export { checkAcceleratedRun, findAcceleratedRefutation, formatAcceleratedSummary };
|
|
47
53
|
import { conjunction, proveKInduction } from "./kind.js";
|
|
48
54
|
import { cycleLemmas, findLeadsTo, findRank } from "./cycles.js";
|
|
49
55
|
import { findNeverEnds } from "./nonterm.js";
|
|
50
56
|
import { findRing, leadsByTerms } from "./live.js";
|
|
57
|
+
import { leadsByWriteSupports } from "./live-support.js";
|
|
51
58
|
import { freshLaws } from "./fresh.js";
|
|
52
59
|
// --- terms and conditions -------------------------------------------------------------------------------------------
|
|
53
60
|
const naturalConst = (v) => {
|
|
@@ -3457,17 +3464,17 @@ function watchdogVerdict(ms, run) {
|
|
|
3457
3464
|
export function proveRule(r, laws, opts = {}) {
|
|
3458
3465
|
return watchdogVerdict(opts.watchdogMs, () => withModelRounds(opts.modelRounds, () => withPublicRule(outermost => {
|
|
3459
3466
|
const captureMachine = r.machine, hasCounts = !!Object.keys(captureMachine.counts ?? {}).length;
|
|
3460
|
-
const result = workVerdict(opts, plan => withPublicSearchPolicy(hasCounts, () => proveRuleWall(r, laws, plan)));
|
|
3467
|
+
const result = workVerdict(opts, plan => withPublicSearchPolicy(hasCounts, () => proveRuleWall(r, laws, plan, captureMachine)));
|
|
3461
3468
|
return outermost ? publishProof(result, captureMachine, laws) : result;
|
|
3462
3469
|
})));
|
|
3463
3470
|
}
|
|
3464
|
-
function proveRuleWall(r, laws, opts) {
|
|
3471
|
+
function proveRuleWall(r, laws, opts, captureMachine) {
|
|
3465
3472
|
const ms = typeof opts.search === 'object' ? opts.search.ms : undefined;
|
|
3466
3473
|
const run = () => {
|
|
3467
3474
|
let result;
|
|
3468
3475
|
try {
|
|
3469
3476
|
checkWall('rule preflight');
|
|
3470
|
-
const out = result = proveRuleIn(r, laws, opts);
|
|
3477
|
+
const out = result = proveRuleIn(r, laws, opts, captureMachine);
|
|
3471
3478
|
if (!completedSearch(out) && !(out.stopped && out.termination))
|
|
3472
3479
|
checkWall('rule result');
|
|
3473
3480
|
return out;
|
|
@@ -3484,7 +3491,7 @@ function proveRuleWall(r, laws, opts) {
|
|
|
3484
3491
|
const result = ms === undefined ? run() : withWall(searchWall(ms), run);
|
|
3485
3492
|
return retainFrom(translationVerdict(r, laws, result), [result]);
|
|
3486
3493
|
}
|
|
3487
|
-
function proveRuleIn(r, laws, opts) {
|
|
3494
|
+
function proveRuleIn(r, laws, opts, captureMachine) {
|
|
3488
3495
|
r = r.withSumsOf(laws, opts.candidateSeeds?.laws ?? []);
|
|
3489
3496
|
noting(r, laws);
|
|
3490
3497
|
if (opts.candidateSeeds) {
|
|
@@ -3516,8 +3523,44 @@ function proveRuleIn(r, laws, opts) {
|
|
|
3516
3523
|
// A state the laws allow whose step breaks one, with no run to it (a wide rule's: what the kernel's step goal would end
|
|
3517
3524
|
// at), is a counterexample to induction: the laws may still hold, so the search goes on from it, as from the kernel's.
|
|
3518
3525
|
// (A step law broken so is refused, proveSteps below: it holds from every state the laws allow, reached or not.)
|
|
3526
|
+
if (refuted?.run)
|
|
3527
|
+
return refutedVerdict(refuted);
|
|
3528
|
+
// A narrowly matched candidate gets a bounded attempt before unrestricted
|
|
3529
|
+
// inference. A failed helper proof is not a verdict about the caller's law.
|
|
3530
|
+
const search = typeof opts.search === 'object' ? opts.search : undefined;
|
|
3531
|
+
const seedMs = search?.ms ?? 10_000;
|
|
3532
|
+
if (opts.search !== false && opts.from !== 'any' && !opts.candidateSeeds && laws.length === 1 &&
|
|
3533
|
+
!captureMachine.history && !Object.keys(captureMachine.sums ?? {}).length && !Object.keys(captureMachine.counts ?? {}).length &&
|
|
3534
|
+
!Object.keys(r.machine.sums ?? {}).length) {
|
|
3535
|
+
const law = laws[0];
|
|
3536
|
+
if (search?.work === undefined && !completeWorkProfile.enabled && seedMs > 0 && Number.isFinite(seedMs)) {
|
|
3537
|
+
const lockstep = tryLockstepScalars(captureMachine, law, withKinds(r, [law]).slice(0, -1), Math.min(seedMs / 2, 26_000));
|
|
3538
|
+
if (lockstep)
|
|
3539
|
+
return lockstep;
|
|
3540
|
+
}
|
|
3541
|
+
if (!Object.keys(captureMachine.fns ?? {}).length && law.forall && law.keys?.length === 1 &&
|
|
3542
|
+
(search?.work !== undefined || seedMs > 0 && Number.isFinite(seedMs))) {
|
|
3543
|
+
const start = countedSearchNow(), prove = () => {
|
|
3544
|
+
const seed = orderedPairSeed(captureMachine, law);
|
|
3545
|
+
if (!seed)
|
|
3546
|
+
return undefined;
|
|
3547
|
+
const out = proveLaws(captureMachine, withKinds(r, [seed, law]));
|
|
3548
|
+
if (!out.proven || !out.checked)
|
|
3549
|
+
return undefined;
|
|
3550
|
+
const found = [{ text: seed.name, law: seed }];
|
|
3551
|
+
return retainFrom({ ...verdictOf(out), found: { laws: found }, ...withAssumes(found) }, [out], { kind: 'inference', original: captureMachine, laws });
|
|
3552
|
+
};
|
|
3553
|
+
const out = search?.work === undefined
|
|
3554
|
+
? withStageWall(start + seedMs * (2 / 3), prove, () => undefined)
|
|
3555
|
+
: withStageWork(remainingStageWork(search.work, 2), prove, () => undefined);
|
|
3556
|
+
if (out)
|
|
3557
|
+
return out;
|
|
3558
|
+
if (search?.work === undefined && search?.ms === undefined && !completeWorkProfile.enabled)
|
|
3559
|
+
opts = { ...opts, search: { ...search, ms: Math.max(0, seedMs - (countedSearchNow() - start)) } };
|
|
3560
|
+
}
|
|
3561
|
+
}
|
|
3519
3562
|
if (refuted)
|
|
3520
|
-
return
|
|
3563
|
+
return searched(r, laws, [], refutedVerdict(refuted), opts);
|
|
3521
3564
|
// A rule with counts: its goals are the counted ones (core/counts.ts searches them; the kernel checks the set).
|
|
3522
3565
|
if (r.machine.counts && Object.keys(r.machine.counts).length) {
|
|
3523
3566
|
const c = searchCounted(r.machine, withKinds(r, laws), typeof opts.search === 'object' ? opts.search.ms ?? 60_000 : 60_000);
|
|
@@ -3564,7 +3607,8 @@ function proveStepsWall(r, laws, stepLaws, opts) {
|
|
|
3564
3607
|
};
|
|
3565
3608
|
const verdict = opts.from !== 'any' || ms === undefined ? run()
|
|
3566
3609
|
: withWall(countedSearchNow() + ms, run);
|
|
3567
|
-
|
|
3610
|
+
const translated = translationVerdict(r, [...laws, ...stepLaws], verdict);
|
|
3611
|
+
return publishStepProof(translated, verdict);
|
|
3568
3612
|
}
|
|
3569
3613
|
function proveStepsIn(r, laws, stepLaws, opts) {
|
|
3570
3614
|
r = r.withSumsOf(laws, stepLaws);
|
|
@@ -3573,11 +3617,48 @@ function proveStepsIn(r, laws, stepLaws, opts) {
|
|
|
3573
3617
|
checkWorkEndpoint('refutation result');
|
|
3574
3618
|
// (a step law broken from a state the laws allow, with no run to it: the laws may need an invariant there, or the run
|
|
3575
3619
|
// be further than these runs go; the search goes on from it, as from the kernel's)
|
|
3576
|
-
if (refuted)
|
|
3577
|
-
return
|
|
3578
|
-
const
|
|
3579
|
-
|
|
3580
|
-
|
|
3620
|
+
if (refuted?.run)
|
|
3621
|
+
return refutedVerdict(refuted);
|
|
3622
|
+
const m = r.machine;
|
|
3623
|
+
// A bounded search for reachable-state supports. Keep from-any proofs,
|
|
3624
|
+
// explicit work accounting and real counterexample preflight unchanged.
|
|
3625
|
+
const sl = stepLaws.length === 1 ? stepLaws[0] : undefined;
|
|
3626
|
+
const search = typeof opts.search === 'object' ? opts.search : undefined;
|
|
3627
|
+
const ms = Math.min(55_000, (search?.ms ?? 10_000) * (11 / 12));
|
|
3628
|
+
let fallback = opts;
|
|
3629
|
+
const enabled = sl && opts.search !== false && opts.from !== 'any' &&
|
|
3630
|
+
search?.work === undefined && !inBudget() && !completeWorkProfile.enabled && ms > 0 && Number.isFinite(search?.ms ?? 10_000);
|
|
3631
|
+
const trySeeds = (law) => {
|
|
3632
|
+
const started = countedSearchNow();
|
|
3633
|
+
const seeded = withStageDeadline(clock() + ms, () => {
|
|
3634
|
+
for (const seeds of stepSeedFamilies(m, law).slice(0, law.forall ? 1 : 2)) {
|
|
3635
|
+
const found = quietly(() => tryStepSeed(m, laws, r.kindLaws(), law, seeds));
|
|
3636
|
+
if (found?.checked.proven && found.checked.checked && found.checked.proof)
|
|
3637
|
+
return { ...found, seeds };
|
|
3638
|
+
}
|
|
3639
|
+
return undefined;
|
|
3640
|
+
}, () => undefined);
|
|
3641
|
+
if (seeded) {
|
|
3642
|
+
const found = seeded.seeds.map(law => ({ law, text: law.name }));
|
|
3643
|
+
return retainStepProof({ ...verdictOf(seeded.checked), found: { laws: found }, ...withAssumes(found) }, { machine: m, family: seeded.family, step: law, report: seeded.checked, ...(seeded.kindProof ? { kindProof: seeded.kindProof } : {}) });
|
|
3644
|
+
}
|
|
3645
|
+
const elapsed = Math.max(0, countedSearchNow() - started);
|
|
3646
|
+
if (elapsed >= 1)
|
|
3647
|
+
fallback = { ...opts, search: { ...search, ms: Math.max(0, (search?.ms ?? 10_000) - elapsed) } };
|
|
3648
|
+
return undefined;
|
|
3649
|
+
};
|
|
3650
|
+
// For a one-row law the sparse attempt avoids the large default instance
|
|
3651
|
+
// set entirely. The other shapes only try seeding after a non-inductive step.
|
|
3652
|
+
const sparse = enabled && sl?.forall && !laws.length ? trySeeds(sl) : undefined;
|
|
3653
|
+
if (sparse)
|
|
3654
|
+
return sparse;
|
|
3655
|
+
const v = refuted ? refutedVerdict(refuted) : verdictOf(proveStepLaws(m, withKinds(r, laws), stepLaws));
|
|
3656
|
+
if (enabled && sl && !sl.forall && v.stuck === 'sat') {
|
|
3657
|
+
const strengthened = trySeeds(sl);
|
|
3658
|
+
if (strengthened)
|
|
3659
|
+
return strengthened;
|
|
3660
|
+
}
|
|
3661
|
+
return searched(r, laws, stepLaws, v, fallback);
|
|
3581
3662
|
}
|
|
3582
3663
|
// The one-step laws as laws the bounded runs read (core/bmc.ts takes laws alone): a ghost per step law, set once a step
|
|
3583
3664
|
// it is about breaks it (`then` read with each primed name the step's update), and the law that it is never set. Only a
|
|
@@ -3625,7 +3706,7 @@ function searched(r, laws, stepLaws, v, opts) {
|
|
|
3625
3706
|
}
|
|
3626
3707
|
function searchedIn(r, laws, stepLaws, v, opts) {
|
|
3627
3708
|
const any = opts.from === 'any';
|
|
3628
|
-
if ((v.proven && v.checked) || opts.search === false || v.run || v.stuck === 'sat' && (any || !/@step|@\d+ steps/.test(v.goal ?? '')))
|
|
3709
|
+
if ((v.proven && v.checked) || opts.search === false || v.run || v.acceleratedRun?.checked || v.stuck === 'sat' && (any || !/@step|@\d+ steps/.test(v.goal ?? '')))
|
|
3629
3710
|
return v;
|
|
3630
3711
|
// The deeper runs; then runs over small values (keys that meet, small params), whose requests meet their
|
|
3631
3712
|
// assumption's equalities and clocks, or near the counterexample the verdict ends at.
|
|
@@ -3652,7 +3733,7 @@ function searchedIn(r, laws, stepLaws, v, opts) {
|
|
|
3652
3733
|
return searchedUntil(r, laws, stepLaws, v, opts, until);
|
|
3653
3734
|
return withStageWall(countedSearchNow() + Math.max(0, until - clock()), () => {
|
|
3654
3735
|
const out = searchedUntil(r, laws, stepLaws, v, opts, until);
|
|
3655
|
-
if (!(out
|
|
3736
|
+
if (!completedSearch(out))
|
|
3656
3737
|
checkWall('search result');
|
|
3657
3738
|
return out;
|
|
3658
3739
|
}, () => stoppedSearch(v, { kind: 'work-exhausted', phase: 'search stage', scope: 'stage' }));
|
|
@@ -3692,6 +3773,22 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
|
|
|
3692
3773
|
if (kd?.proven && kd.checked)
|
|
3693
3774
|
return { proven: true, checked: true, k: kd.k, assumes: { states: 'reachable', laws: [] } };
|
|
3694
3775
|
}
|
|
3776
|
+
// A compressed repeat is untrusted until the unchanged kernel proves its
|
|
3777
|
+
// admitted affine steps and exact replay checks the original failed law.
|
|
3778
|
+
// Translated source requires its own native replay; a model repeat is not it.
|
|
3779
|
+
if (!any && !stepLaws.length && !isSourceBound(r, laws) && !stepWorkProfile.enabled && !inBudget() &&
|
|
3780
|
+
laws.every(l => !l.forall && !l.keys?.length && !l.some?.length) && total > 1_000) {
|
|
3781
|
+
const ms = Math.min(1_500, total / 12), machine = r.machine;
|
|
3782
|
+
const acc = counted(fullRate, () => withStageAllowance(ms, () => findAcceleratedRefutation(machine, laws, {
|
|
3783
|
+
ms,
|
|
3784
|
+
wall: performance.now() + ms,
|
|
3785
|
+
shownRequest,
|
|
3786
|
+
randomParams: (rand, bound) => r.randomParams(rand, bound),
|
|
3787
|
+
randomInput: (rand, bound, ps) => r.randomInput(rand, bound, ps),
|
|
3788
|
+
}), () => undefined), true);
|
|
3789
|
+
if (acc?.checked && checkAcceleratedRun(machine, laws, acc))
|
|
3790
|
+
return { proven: false, checked: false, goal: `${acc.law} @accelerated (${formatAcceleratedSummary(acc)})`, stuck: 'sat', witness: acc.witness, acceleratedRun: acc };
|
|
3791
|
+
}
|
|
3695
3792
|
let rule = r, lemmas;
|
|
3696
3793
|
const { fns, lists } = r.parts;
|
|
3697
3794
|
if (lists.length || fns.some(([, d]) => recurOf(d))) {
|
|
@@ -3907,23 +4004,43 @@ const withAssumes = (found) => (found.length ? { assumes: reachableBy(found) } :
|
|
|
3907
4004
|
// The rule a keyed liveness is proven on: the rule with its key as one more param (a natural), any other rule as it is.
|
|
3908
4005
|
export const keyed = (r, l) => (l.forall ? r.params({ [l.forall]: nat }) : r);
|
|
3909
4006
|
export function proveLeadsTo(r, laws, l, opts = {}) {
|
|
3910
|
-
|
|
4007
|
+
const out = proveLeadsToIn(r, laws, l, opts, !isSourceBound(r, [...laws, l]));
|
|
4008
|
+
return publishLiveProof(translationVerdict(r, [...laws, l], out), out);
|
|
3911
4009
|
}
|
|
3912
|
-
function proveLeadsToIn(r, laws, l, opts) {
|
|
4010
|
+
function proveLeadsToIn(r, laws, l, opts, allowRing) {
|
|
3913
4011
|
r = keyed(r, l).withSumsOf(laws, l);
|
|
3914
4012
|
noting(r, laws, l);
|
|
3915
4013
|
if (laws.some(law => law.some?.length))
|
|
3916
4014
|
throw new Error(`${r.machine.name}: a law with "there exists" goes to proveRule or proveSteps; a liveness takes plain laws (the ones its proof printed, Verdict.witnesses)`);
|
|
3917
4015
|
if (Array.isArray(l.rank) && !l.rank.length) {
|
|
3918
|
-
const
|
|
4016
|
+
const ms = opts.ms ?? 10_000, until = clock() + ms;
|
|
4017
|
+
const draws = { params: (rand, bound) => r.randomParams(rand, bound), input: (rand, bound, ps) => r.randomInput(rand, bound, ps) };
|
|
4018
|
+
const m = r.machine, ringMs = Math.min(15_000, ms / 4);
|
|
4019
|
+
// History queries can keep a helpful request disabled indefinitely. Search
|
|
4020
|
+
// for a checked ring within the normal grant; never use a model ring as a
|
|
4021
|
+
// counterexample for extracted source or with unverified function facts.
|
|
4022
|
+
if (m.history && allowRing && !completeWorkProfile.enabled && ringMs > 1000 && Number.isFinite(ms)) {
|
|
4023
|
+
const found = withStageDeadline(clock() + ringMs, () => findRing(m, withKinds(r, laws), l, draws, { ms: ringMs }), () => undefined);
|
|
4024
|
+
if (found?.verdict.refuted)
|
|
4025
|
+
return { proven: false, checked: false, goal: l.name, stuck: 'sat', fairRing: found.ring };
|
|
4026
|
+
}
|
|
3919
4027
|
// (the laws about the keys a counter hands out or a high-water mark bounds, core/fresh.ts, within a twentieth: given
|
|
3920
4028
|
// to both searches, each proven again with the rank)
|
|
3921
4029
|
const share = (until - clock()) / 20, fresh = Object.keys(r.machine.maps ?? {}).length ? withStageDeadline(clock() + share, () => freshLaws(r.machine, r.kindLaws(), draws, { ms: share }), () => []) : [];
|
|
3922
4030
|
laws = [...laws, ...fresh.map(x => x.law)];
|
|
3923
|
-
|
|
4031
|
+
const ds = { ...draws, rule: r, state: (rand, bound) => Object.assign({}, ...r.kindsOfState().map(([n, kd]) => kd.random(n, rand, bound))) };
|
|
4032
|
+
// Strong fairness admits upward helpful handoffs at a fixed rank. Give guard-distance ranks a bounded first
|
|
4033
|
+
// look: the affine fit can spend the entire grant without finding a truncated distance to a guard bound.
|
|
4034
|
+
const firstMs = Math.min(15_000, (until - clock()) / 4), base = withKinds(r, laws);
|
|
4035
|
+
const early = completeWorkProfile.enabled ? undefined : withStageDeadline(Math.min(until, clock() + firstMs), () => l.fairness === 'strong' ?
|
|
4036
|
+
(firstMs > 1000 ? leadsByTerms(r.machine, base, l, ds, { ms: firstMs }) : undefined) :
|
|
4037
|
+
leadsByWriteSupports(r.machine, base, l, firstMs), () => undefined);
|
|
4038
|
+
let f = early?.proven && early.checked ? early : until > clock() ?
|
|
4039
|
+
findLeadsTo(r.machine, base, l, { ...draws, rule: r }, { ms: until - clock() }) :
|
|
4040
|
+
{ proven: false, checked: false, why: 'liveness search reached its deadline' };
|
|
3924
4041
|
// Where the rank fitted to the runs isn't the one: a rank of the rule's own terms (core/live.ts), in the time left.
|
|
3925
4042
|
if (!(f.proven && f.checked) && until - clock() > 500) {
|
|
3926
|
-
const g = leadsByTerms(r.machine, withKinds(r, laws), l,
|
|
4043
|
+
const g = leadsByTerms(r.machine, withKinds(r, laws), l, ds, { ms: until - clock() });
|
|
3927
4044
|
if (g.proven && g.checked)
|
|
3928
4045
|
f = g;
|
|
3929
4046
|
}
|
|
@@ -3942,17 +4059,21 @@ function proveLeadsToIn(r, laws, l, opts) {
|
|
|
3942
4059
|
}
|
|
3943
4060
|
}
|
|
3944
4061
|
const helpers = [...fresh, ...(f.laws ?? []).map((law, i) => ({ law, text: f.found?.laws[i] ?? law.name }))];
|
|
3945
|
-
return { proven: f.proven, checked: f.checked, ...(f.proven && f.rank ? { rank: f.rank } : {}), ...(f.goal ? { goal: f.goal, stuck: f.stuck } : {}), ...(f.witness ? { witness: f.witness } : {}), ...(f.why ? { why: f.why } : {}),
|
|
3946
|
-
...(f.found ? { found: { rank: f.found.rank, ...(helpers.length ? { laws: helpers } : {}) } } : {}), ...(f.proven ? withAssumes(helpers) : {}) };
|
|
4062
|
+
return retainLiveProof({ proven: f.proven, checked: f.checked, ...(f.proven && f.rank ? { rank: f.rank } : {}), ...(f.proven && f.levels ? { levels: f.levels } : {}), ...(f.goal ? { goal: f.goal, stuck: f.stuck } : {}), ...(f.witness ? { witness: f.witness } : {}), ...(f.why ? { why: f.why } : {}),
|
|
4063
|
+
...(f.found ? { found: { rank: f.found.rank, ...(helpers.length ? { laws: helpers } : {}) } } : {}), ...(f.proven ? withAssumes(helpers) : {}) }, 'evidence' in f ? f.evidence : undefined);
|
|
3947
4064
|
}
|
|
3948
|
-
const
|
|
3949
|
-
|
|
4065
|
+
const machine = r.machine, family = withKinds(r, laws), out = proveLiveness(machine, family, l);
|
|
4066
|
+
const liveness = out.levels ? { ...l, levels: out.levels } : l;
|
|
4067
|
+
return retainLiveProof({ ...verdictOf(out), ...(out.proven && out.checked && out.levels ? { levels: out.levels } : {}) }, { machine, laws: family, liveness, report: out });
|
|
3950
4068
|
}
|
|
3951
4069
|
// A leads-to refuted by a fair run that never gets there (core/live.ts's findRing, checked by refutedBy): a stem from
|
|
3952
4070
|
// the start, then round a ring of sets each request of which the kernel proves allowed and into the next set, fair to
|
|
3953
4071
|
// each helpful request (taken in the ring, or never allowed in a set). Undefined where none is found within `ms`.
|
|
3954
4072
|
export function refuteLeadsTo(r, laws, l, opts = {}) {
|
|
3955
|
-
|
|
4073
|
+
if (isSourceBound(r, [...laws, l]) || completeWorkProfile.enabled)
|
|
4074
|
+
return undefined;
|
|
4075
|
+
const k = keyed(r, l).withSumsOf(laws, l);
|
|
4076
|
+
noting(k, laws, l);
|
|
3956
4077
|
return findRing(k.machine, withKinds(k, laws), l, { params: (rand, bound) => k.randomParams(rand, bound), input: (rand, bound, ps) => k.randomInput(rand, bound, ps) }, opts);
|
|
3957
4078
|
}
|
|
3958
4079
|
// `ms`: the budget (the prover's own per goal, 20 s or a second a hypothesis, where none is given), on the clock the
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Law, type Machine } from './machine.js';
|
|
2
|
+
import { type Liveness } from '../kernel/kernel.js';
|
|
3
|
+
import { type LeadsVerdict } from './cycles.js';
|
|
4
|
+
export declare function helpfulWriteSupports(m: Machine, l: Liveness): Law[];
|
|
5
|
+
export declare function leadsByWriteSupports(m: Machine, laws: Law[], l: Liveness, ms: number): LeadsVerdict | undefined;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// Candidate invariants for simple helpful steps. Everything in this file is search guidance: even a syntactically
|
|
2
|
+
// matched write may take a different branch or alias a watched key. Only proveLiveness may accept the proposals.
|
|
3
|
+
import { walk } from "./machine.js";
|
|
4
|
+
import { livenessHelpful, substE, trueC } from "../kernel/kernel.js";
|
|
5
|
+
import { clock, proveLiveness, proveProgress, withDeadline } from "../kernel/prove.js";
|
|
6
|
+
import { showC } from "./cycles.js";
|
|
7
|
+
const id = (x) => JSON.stringify(x);
|
|
8
|
+
const same = (a, b) => id(a) === id(b);
|
|
9
|
+
const v = (name) => ({ op: 'var', name }), k = (value) => ({ op: 'const', value });
|
|
10
|
+
const at = (map, key) => ({ op: 'get', map, key });
|
|
11
|
+
const eq = (a, b) => ({ op: '=', a, b }), le = (a, b) => ({ op: '<=', a, b });
|
|
12
|
+
const implies = (x, y) => ({ op: 'or', xs: [{ op: 'not', x }, y] });
|
|
13
|
+
const and = (x, y) => ({ op: 'and', xs: [x, y] });
|
|
14
|
+
const conjuncts = (x) => x.op === 'and' ? x.xs.flatMap(conjuncts) : [x];
|
|
15
|
+
const addends = (x) => x.op === 'add' ? [...addends(x.a), ...addends(x.b)] : [x];
|
|
16
|
+
const outcomes = (x) => x.op === 'if' ? [...outcomes(x.then), ...outcomes(x.else)] : [x];
|
|
17
|
+
const mentions = (t, f) => {
|
|
18
|
+
let hit = false;
|
|
19
|
+
walk(t, o => { if (f(o))
|
|
20
|
+
hit = true; });
|
|
21
|
+
return hit;
|
|
22
|
+
};
|
|
23
|
+
const reads = (t, names) => mentions(t, o => o.op === 'var' && names.includes(o.name));
|
|
24
|
+
export function helpfulWriteSupports(m, l) {
|
|
25
|
+
if (m.history || m.sums && Object.keys(m.sums).length || m.inputMaps?.length || livenessHelpful(l).length !== 1)
|
|
26
|
+
return [];
|
|
27
|
+
const request = livenessHelpful(l)[0].request, stored = Object.entries(m.step.maps ?? {});
|
|
28
|
+
if (!stored.length || stored.length > 32)
|
|
29
|
+
return [];
|
|
30
|
+
const updates = Object.entries(m.step.state ?? {}), found = new Map();
|
|
31
|
+
const add = (holds) => {
|
|
32
|
+
const key = id(holds);
|
|
33
|
+
if (found.size >= 8 || found.has(key))
|
|
34
|
+
return;
|
|
35
|
+
found.set(key, { name: `liveness write support ${found.size + 1}: ${showC(holds)}`, holds });
|
|
36
|
+
};
|
|
37
|
+
// A helpful request names a key past a max/frontier. Where a scalar is either retained or written from that
|
|
38
|
+
// same request key, compare its value with the written expression at the frontier. Ordinary freshness laws about
|
|
39
|
+
// cells beyond the frontier are separately supplied by freshLaws. No clock assumption is added to the machine.
|
|
40
|
+
for (const [mark, next] of updates)
|
|
41
|
+
if (next.op === 'max') {
|
|
42
|
+
const key = same(next.a, v(mark)) ? next.b : same(next.b, v(mark)) ? next.a : undefined;
|
|
43
|
+
if (key?.op !== 'var' || !request[key.name] || !reads(request[key.name], [mark]) ||
|
|
44
|
+
!stored.some(([, w]) => 'key' in w && same(w.key, key)))
|
|
45
|
+
continue;
|
|
46
|
+
for (const [x, e] of updates)
|
|
47
|
+
if (e.op === 'if' && same(e.else, v(x)) && reads(e.then, [key.name])) {
|
|
48
|
+
if (mentions(e.then, o => o.op === 'flag' || o.op === 'get') || reads(e.then, m.inputs.filter(y => y !== key.name)))
|
|
49
|
+
continue;
|
|
50
|
+
add(le(v(x), substE(e.then, { vars: { [key.name]: v(mark) }, maps: {}, flags: {} })));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// A fixed observer is pending when its row's tag equals a constant. Follow its write selector to sibling payloads
|
|
54
|
+
// at the same write key and simple bounds on those payloads. Each projection is only a proposed reachable law.
|
|
55
|
+
for (const trigger of conjuncts(l.from))
|
|
56
|
+
if (trigger.op === '=') {
|
|
57
|
+
const tag = trigger.a.op === 'get' && trigger.b.op === 'const' ? trigger.a :
|
|
58
|
+
trigger.b.op === 'get' && trigger.a.op === 'const' ? trigger.b : undefined;
|
|
59
|
+
if (!tag || reads(tag.key, [...m.inputs, ...Object.keys(m.state)]) || mentions(tag.key, o => o.op === 'get'))
|
|
60
|
+
continue;
|
|
61
|
+
const write = m.step.maps?.[tag.map];
|
|
62
|
+
if (!write || !('key' in write) || write.value.op !== 'if' || !same(write.value.else, at(tag.map, write.key)))
|
|
63
|
+
continue;
|
|
64
|
+
const guard = write.value.c, bounds = new Map(), expanded = new Set();
|
|
65
|
+
const scan = (x) => walk(x, o => {
|
|
66
|
+
if (o.op === 'flag' && typeof o.name === 'string' && !expanded.has(o.name)) {
|
|
67
|
+
expanded.add(o.name);
|
|
68
|
+
const f = m.step.flags?.[o.name];
|
|
69
|
+
if (f)
|
|
70
|
+
scan(f);
|
|
71
|
+
}
|
|
72
|
+
if (o.op === '<=' && o.b?.op === 'var' && o.a?.op === 'add' && !reads(o.b, m.inputs)) {
|
|
73
|
+
bounds.set(id(o), { a: o.a, b: o.b });
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
scan(guard);
|
|
77
|
+
for (const [field, w] of stored) {
|
|
78
|
+
if (field === tag.map || !('key' in w) || !same(w.key, write.key) || w.value.op !== 'if')
|
|
79
|
+
continue;
|
|
80
|
+
const cells = at(field, tag.key), init = m.maps?.[field], old = at(field, w.key);
|
|
81
|
+
if (!same(w.value.else, old) || id(w.value.c) !== id(guard)) {
|
|
82
|
+
// A Boolean payload can be encoded after the row update as `if (updated predicate) then 1 else 0`.
|
|
83
|
+
// Recognize a sibling only if that predicate reads its own old bit and the row's update selector.
|
|
84
|
+
const c = w.value.c;
|
|
85
|
+
if ((init === 0 || init === 1) && same(w.value.then, k(1)) && same(w.value.else, k(0)) &&
|
|
86
|
+
mentions(c, o => o.op === 'get' && same(o, old)) && mentions(c, o => id(o) === id(guard))) {
|
|
87
|
+
add(implies(trigger, eq(cells, k(init))));
|
|
88
|
+
}
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const val = w.value.then, leaves = outcomes(val);
|
|
92
|
+
// A co-written small choice or bit; the pending state may preserve its initial value.
|
|
93
|
+
if (init !== undefined && leaves.every(x => x.op === 'const' && x.value <= 4) &&
|
|
94
|
+
leaves.some(x => same(x, k(init))))
|
|
95
|
+
add(implies(trigger, eq(cells, k(init))));
|
|
96
|
+
for (const { a, b } of bounds.values())
|
|
97
|
+
if (addends(a).some(x => same(val, x))) {
|
|
98
|
+
add(implies(trigger, le(cells, b)));
|
|
99
|
+
// A simultaneously accumulated value using the same amount may be capped by the same guard bound.
|
|
100
|
+
for (const [x, e] of updates)
|
|
101
|
+
if (!same(v(x), b) && mentions(e, o => o.op === 'add' && addends(o).some(t => same(t, val))))
|
|
102
|
+
add(le(v(x), b));
|
|
103
|
+
// With a parameter-or-request payload, zero in the watched cell may identify the zero parameter case.
|
|
104
|
+
if (leaves.some(x => x.op === 'var' && m.inputs.includes(x.name))) {
|
|
105
|
+
for (const x of leaves)
|
|
106
|
+
if (x.op === 'var' && m.params.includes(x.name))
|
|
107
|
+
add(implies(and(trigger, eq(cells, k(0))), eq(x, k(0))));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return [...found.values()];
|
|
113
|
+
}
|
|
114
|
+
// Proof proposal only. The ordinary prover checks initiation, simultaneous preservation, stay, coverage,
|
|
115
|
+
// all helpful branches and the original fairness obligations. A wrong projection costs at most this stage's grant.
|
|
116
|
+
export function leadsByWriteSupports(m, laws, l, ms) {
|
|
117
|
+
if (ms < 500 || l.fairness === 'strong')
|
|
118
|
+
return undefined;
|
|
119
|
+
const until = clock() + ms, rank = [k(0)], candidates = helpfulWriteSupports(m, l);
|
|
120
|
+
if (!candidates.length)
|
|
121
|
+
return undefined;
|
|
122
|
+
let alive = candidates.filter(c => !laws.some(law => law.name === c.name));
|
|
123
|
+
while (alive.length && clock() < until) {
|
|
124
|
+
const all = [...laws, ...alive];
|
|
125
|
+
const out = withDeadline(until, () => proveLiveness(m, all, { ...l, rank }));
|
|
126
|
+
if (out.proven && out.checked) {
|
|
127
|
+
// The legacy step proof with unnamed weak-help fields need not show enabledness. For this new route, require
|
|
128
|
+
// one checked completion in each pending state: fill the spare fields with constants (a proof witness, not a
|
|
129
|
+
// new assumption about the scheduler or what values all executions must send).
|
|
130
|
+
const h = livenessHelpful(l)[0];
|
|
131
|
+
let progress;
|
|
132
|
+
if (m.assume && m.inputs.some(i => !(i in h.request))) {
|
|
133
|
+
const request = Object.fromEntries(m.inputs.map(i => [i, h.request[i] ?? k(0)]));
|
|
134
|
+
const a = withDeadline(until, () => proveProgress(m, all, { name: `${l.name}: helpful completion is allowed`,
|
|
135
|
+
when: and(and(l.from, { op: 'not', x: l.to }), h.when), then: trueC, request }));
|
|
136
|
+
if (!a.proven || !a.checked)
|
|
137
|
+
return undefined;
|
|
138
|
+
progress = a;
|
|
139
|
+
}
|
|
140
|
+
return { proven: true, checked: true, rank, laws: alive, evidence: { machine: m, laws: all, liveness: { ...l, rank }, report: out, ...(progress ? { progress } : {}) }, found: { rank: '(0)', laws: alive.map(c => showC(c.holds)) } };
|
|
141
|
+
}
|
|
142
|
+
const drop = alive.findIndex(c => out.failed?.goal.startsWith(`${c.name} @`));
|
|
143
|
+
if (drop < 0)
|
|
144
|
+
return undefined;
|
|
145
|
+
alive = alive.filter((_, i) => i !== drop);
|
|
146
|
+
}
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|