gdp-wired 0.48.0 → 0.49.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/bmc.js +10 -7
- package/dist/core/check.js +7 -2
- package/dist/core/count-attempt-work.d.ts +29 -0
- package/dist/core/count-attempt-work.js +96 -0
- package/dist/core/count-boolean-partition.d.ts +5 -0
- package/dist/core/count-boolean-partition.js +47 -0
- package/dist/core/count-bounded-quotient.d.ts +2 -0
- package/dist/core/count-bounded-quotient.js +13 -0
- package/dist/core/count-case-compose.d.ts +20 -0
- package/dist/core/count-case-compose.js +289 -0
- package/dist/core/count-cases.js +3 -2
- package/dist/core/count-cert-rename.d.ts +10 -0
- package/dist/core/count-cert-rename.js +69 -0
- package/dist/core/count-cert-transport.d.ts +10 -2
- package/dist/core/count-cert-transport.js +60 -9
- package/dist/core/count-certificate-minimize.d.ts +57 -0
- package/dist/core/count-certificate-minimize.js +263 -0
- package/dist/core/count-closed-family.d.ts +32 -0
- package/dist/core/count-closed-family.js +143 -0
- package/dist/core/count-closing-budget.d.ts +10 -0
- package/dist/core/count-closing-budget.js +49 -0
- package/dist/core/count-closing-needs.d.ts +5 -0
- package/dist/core/count-closing-needs.js +9 -0
- package/dist/core/count-component-budget.d.ts +5 -0
- package/dist/core/count-component-budget.js +9 -0
- package/dist/core/count-copy-shape.d.ts +11 -0
- package/dist/core/count-copy-shape.js +40 -0
- package/dist/core/count-disjoint-funding.d.ts +75 -0
- package/dist/core/count-disjoint-funding.js +284 -0
- package/dist/core/count-emitter-frame-pool.d.ts +23 -0
- package/dist/core/count-emitter-frame-pool.js +87 -0
- package/dist/core/count-final-step.d.ts +5 -0
- package/dist/core/count-final-step.js +20 -0
- package/dist/core/count-fixed-frame.d.ts +4 -0
- package/dist/core/count-fixed-frame.js +30 -0
- package/dist/core/count-frames.d.ts +25 -0
- package/dist/core/count-frames.js +118 -0
- package/dist/core/count-frozen-guard.d.ts +2 -0
- package/dist/core/count-frozen-guard.js +31 -0
- package/dist/core/count-generation-phase.d.ts +7 -0
- package/dist/core/count-generation-phase.js +33 -0
- package/dist/core/count-guard-composition.d.ts +12 -0
- package/dist/core/count-guard-composition.js +48 -0
- package/dist/core/count-guard-context.d.ts +11 -0
- package/dist/core/count-guard-context.js +50 -0
- package/dist/core/count-guard-facts.d.ts +50 -0
- package/dist/core/count-guard-facts.js +97 -0
- package/dist/core/count-guard-proposals.d.ts +7 -0
- package/dist/core/count-guard-proposals.js +106 -0
- package/dist/core/count-guard-shape.d.ts +18 -0
- package/dist/core/count-guard-shape.js +100 -0
- package/dist/core/count-guard-tree.d.ts +17 -0
- package/dist/core/count-guard-tree.js +125 -0
- package/dist/core/count-leader-facts.d.ts +10 -0
- package/dist/core/count-leader-facts.js +52 -0
- package/dist/core/count-leader.d.ts +10 -0
- package/dist/core/count-leader.js +331 -0
- package/dist/core/count-lemma-transport.d.ts +8 -0
- package/dist/core/count-lemma-transport.js +47 -0
- package/dist/core/count-lifted-budget.d.ts +54 -0
- package/dist/core/count-lifted-budget.js +97 -0
- package/dist/core/count-lifted-copy.d.ts +3 -0
- package/dist/core/count-lifted-copy.js +166 -0
- package/dist/core/count-lifted-increment.d.ts +3 -0
- package/dist/core/count-lifted-increment.js +146 -0
- package/dist/core/count-lifted-load.d.ts +5 -0
- package/dist/core/count-lifted-load.js +179 -0
- package/dist/core/count-lifted-prerequisite.d.ts +14 -0
- package/dist/core/count-lifted-prerequisite.js +53 -0
- package/dist/core/count-lifted-replacement.d.ts +3 -0
- package/dist/core/count-lifted-replacement.js +540 -0
- package/dist/core/count-lifted-shape.d.ts +63 -0
- package/dist/core/count-lifted-shape.js +115 -0
- package/dist/core/count-lifted-strategy.d.ts +7 -0
- package/dist/core/count-lifted-strategy.js +226 -0
- package/dist/core/count-lifted-transports.d.ts +32 -0
- package/dist/core/count-lifted-transports.js +293 -0
- package/dist/core/count-load-shape.d.ts +17 -0
- package/dist/core/count-load-shape.js +67 -0
- package/dist/core/count-minimal-view.d.ts +26 -0
- package/dist/core/count-minimal-view.js +46 -0
- package/dist/core/count-operation-observation.d.ts +9 -0
- package/dist/core/count-operation-observation.js +22 -0
- package/dist/core/count-operation-order.d.ts +5 -0
- package/dist/core/count-operation-order.js +4 -0
- package/dist/core/count-phase.d.ts +9 -0
- package/dist/core/count-phase.js +127 -0
- package/dist/core/count-premise-search.d.ts +9 -0
- package/dist/core/count-premise-search.js +41 -0
- package/dist/core/count-premise-view.d.ts +19 -0
- package/dist/core/count-premise-view.js +220 -0
- package/dist/core/count-prerequisite-components.d.ts +67 -0
- package/dist/core/count-prerequisite-components.js +239 -0
- package/dist/core/count-prerequisite-memory.d.ts +24 -0
- package/dist/core/count-prerequisite-memory.js +37 -0
- package/dist/core/count-prerequisite-plan.d.ts +12 -0
- package/dist/core/count-prerequisite-plan.js +88 -0
- package/dist/core/count-primitive-budget.d.ts +1 -0
- package/dist/core/count-primitive-budget.js +8 -0
- package/dist/core/count-project-free.d.ts +3 -0
- package/dist/core/count-project-free.js +24 -0
- package/dist/core/count-project-witness.d.ts +4 -0
- package/dist/core/count-project-witness.js +48 -0
- package/dist/core/count-proof-rescope.d.ts +14 -0
- package/dist/core/count-proof-rescope.js +71 -0
- package/dist/core/count-proof-scope.d.ts +68 -0
- package/dist/core/count-proof-scope.js +333 -0
- package/dist/core/count-prune-owned-root.d.ts +5 -0
- package/dist/core/count-prune-owned-root.js +27 -0
- package/dist/core/count-query-context.d.ts +3 -0
- package/dist/core/count-query-context.js +7 -0
- package/dist/core/count-query.d.ts +15 -0
- package/dist/core/count-query.js +59 -0
- package/dist/core/count-quorum-leaf.d.ts +9 -0
- package/dist/core/count-quorum-leaf.js +38 -0
- package/dist/core/count-reachability-budget.d.ts +1 -0
- package/dist/core/count-reachability-budget.js +7 -0
- package/dist/core/count-reachability-reconcile.d.ts +11 -0
- package/dist/core/count-reachability-reconcile.js +19 -0
- package/dist/core/count-reachability.d.ts +50 -0
- package/dist/core/count-reachability.js +351 -0
- package/dist/core/count-rebase-path.d.ts +9 -0
- package/dist/core/count-rebase-path.js +68 -0
- package/dist/core/count-recipe-context.d.ts +45 -0
- package/dist/core/count-recipe-context.js +71 -0
- package/dist/core/count-recipe-controller.d.ts +115 -0
- package/dist/core/count-recipe-controller.js +417 -0
- package/dist/core/count-recipe-graph.d.ts +36 -0
- package/dist/core/count-recipe-graph.js +211 -0
- package/dist/core/count-recovery/conditional-check-cache.js +3 -2
- package/dist/core/count-recovery/conditional-cuts.js +5 -4
- package/dist/core/count-recovery/conditional-proof.d.ts +37 -3
- package/dist/core/count-recovery/conditional-proof.js +72 -30
- package/dist/core/count-recovery/derivability-closure.js +2 -1
- package/dist/core/count-recovery/guard-cases.js +2 -1
- package/dist/core/count-recovery/reframe-tree.d.ts +2 -0
- package/dist/core/count-recovery/reframe-tree.js +24 -0
- package/dist/core/count-recovery/replay-linear-skeleton.d.ts +2 -0
- package/dist/core/count-recovery/replay-linear-skeleton.js +28 -0
- package/dist/core/count-recovery/row-cases.js +2 -1
- package/dist/core/count-rejection-budget.d.ts +8 -0
- package/dist/core/count-rejection-budget.js +15 -0
- package/dist/core/count-replacement.d.ts +5 -0
- package/dist/core/count-replacement.js +129 -0
- package/dist/core/count-replay-diagnostic.d.ts +21 -0
- package/dist/core/count-replay-diagnostic.js +49 -0
- package/dist/core/count-replay-skeleton.d.ts +4 -0
- package/dist/core/count-replay-skeleton.js +28 -0
- package/dist/core/count-rescope-funding.d.ts +3 -0
- package/dist/core/count-rescope-funding.js +17 -0
- package/dist/core/count-restrictions.d.ts +11 -0
- package/dist/core/count-restrictions.js +31 -0
- package/dist/core/count-retry-budget.d.ts +67 -0
- package/dist/core/count-retry-budget.js +114 -0
- package/dist/core/count-retry-round.d.ts +24 -0
- package/dist/core/count-retry-round.js +44 -0
- package/dist/core/count-row-agreement.d.ts +35 -0
- package/dist/core/count-row-agreement.js +270 -0
- package/dist/core/count-row-aliases.d.ts +3 -0
- package/dist/core/count-row-aliases.js +59 -0
- package/dist/core/count-row-composition.d.ts +6 -0
- package/dist/core/count-row-composition.js +55 -0
- package/dist/core/count-row-copy-linear.d.ts +4 -0
- package/dist/core/count-row-copy-linear.js +83 -0
- package/dist/core/count-row-copy.d.ts +4 -0
- package/dist/core/count-row-copy.js +94 -0
- package/dist/core/count-row-policy.d.ts +3 -0
- package/dist/core/count-row-policy.js +56 -0
- package/dist/core/count-row-reindex.d.ts +11 -0
- package/dist/core/count-row-reindex.js +126 -0
- package/dist/core/count-row-support.d.ts +9 -0
- package/dist/core/count-row-support.js +42 -0
- package/dist/core/count-row-symmetry.d.ts +7 -0
- package/dist/core/count-row-symmetry.js +100 -0
- package/dist/core/count-scope-hyps.d.ts +2 -0
- package/dist/core/count-scope-hyps.js +163 -0
- package/dist/core/count-scope-row-reuse.d.ts +3 -0
- package/dist/core/count-scope-row-reuse.js +92 -0
- package/dist/core/count-search-allowance.d.ts +1 -0
- package/dist/core/count-search-allowance.js +17 -0
- package/dist/core/count-stabilize-tree.d.ts +9 -0
- package/dist/core/count-stabilize-tree.js +35 -0
- package/dist/core/count-stage-trace.d.ts +8 -0
- package/dist/core/count-stage-trace.js +45 -0
- package/dist/core/count-strategies.d.ts +16 -0
- package/dist/core/count-strategies.js +155 -0
- package/dist/core/count-strategy-premises.d.ts +5 -0
- package/dist/core/count-strategy-premises.js +14 -0
- package/dist/core/count-strategy.d.ts +41 -0
- package/dist/core/count-strategy.js +76 -0
- package/dist/core/count-support.js +3 -2
- package/dist/core/count-tier-budget.d.ts +14 -0
- package/dist/core/count-tier-budget.js +64 -0
- package/dist/core/count-unwritten-prefix.d.ts +24 -0
- package/dist/core/count-unwritten-prefix.js +97 -0
- package/dist/core/count-write-shape.d.ts +15 -0
- package/dist/core/count-write-shape.js +73 -0
- package/dist/core/counts.d.ts +37 -13
- package/dist/core/counts.js +990 -127
- package/dist/core/cycles.js +5 -4
- package/dist/core/cyclic.js +11 -10
- package/dist/core/data.js +16 -15
- package/dist/core/dsl-deadline.d.ts +3 -0
- package/dist/core/dsl-deadline.js +27 -0
- package/dist/core/dsl.d.ts +9 -0
- package/dist/core/dsl.js +156 -51
- package/dist/core/evaluation-admission.d.ts +1 -0
- package/dist/core/evaluation-admission.js +3 -0
- package/dist/core/exists.d.ts +6 -1
- package/dist/core/exists.js +51 -9
- package/dist/core/field-laws.d.ts +3 -1
- package/dist/core/field-laws.js +140 -2
- package/dist/core/finite-houdini.d.ts +6 -0
- package/dist/core/finite-houdini.js +63 -21
- package/dist/core/finite-tiny.js +95 -67
- package/dist/core/fixtures/count-completion/paxos-decision.json +1 -0
- package/dist/core/fresh.js +5 -1
- package/dist/core/infer.js +45 -30
- package/dist/core/kind.js +2 -1
- package/dist/core/lemma-cuts.js +11 -10
- package/dist/core/linear-admission.d.ts +14 -0
- package/dist/core/linear-admission.js +151 -0
- package/dist/core/machine.d.ts +5 -2
- package/dist/core/machine.js +105 -31
- package/dist/core/meter.d.ts +22 -0
- package/dist/core/meter.js +34 -0
- package/dist/core/nonterm.js +4 -3
- package/dist/core/prover-row-budget.d.ts +3 -0
- package/dist/core/prover-row-budget.js +106 -0
- package/dist/core/quorum-laws.d.ts +21 -1
- package/dist/core/quorum-laws.js +27 -3
- package/dist/core/rationals.js +3 -2
- package/dist/core/rejection-discovery.d.ts +34 -0
- package/dist/core/rejection-discovery.js +36 -0
- package/dist/core/rejection-stage.d.ts +39 -0
- package/dist/core/rejection-stage.js +205 -0
- package/dist/core/request-quotient.d.ts +8 -0
- package/dist/core/request-quotient.js +299 -0
- package/dist/core/row-agreement-shape.d.ts +15 -0
- package/dist/core/row-agreement-shape.js +68 -0
- package/dist/core/runtime-wall.d.ts +2 -0
- package/dist/core/search-policy.d.ts +15 -0
- package/dist/core/search-policy.js +68 -0
- package/dist/core/solver.d.ts +1 -1
- package/dist/core/solver.js +40 -6
- package/dist/core/step-work.d.ts +12 -0
- package/dist/core/step-work.js +14 -0
- package/dist/core/strategy-premises.d.ts +8 -0
- package/dist/core/strategy-premises.js +64 -0
- package/dist/core/system.js +4 -3
- package/dist/core/table-admission.d.ts +1 -0
- package/dist/core/table-admission.js +3 -0
- package/dist/core/trace-clock.d.ts +3 -0
- package/dist/core/trace-clock.js +16 -0
- package/dist/core/transfer.js +3 -2
- package/dist/core/translate.js +16 -3
- package/dist/core/wall.d.ts +6 -1
- package/dist/core/wall.js +23 -9
- package/dist/core/watch.d.ts +1 -1
- package/dist/core/watch.js +13 -4
- package/dist/core/work-admission.d.ts +164 -0
- package/dist/core/work-admission.js +418 -0
- package/dist/core/work-amount.d.ts +21 -0
- package/dist/core/work-amount.js +80 -0
- package/dist/core/work-collections.d.ts +11 -0
- package/dist/core/work-collections.js +198 -0
- package/dist/core/work-kinds.d.ts +11 -0
- package/dist/core/work-kinds.js +9 -0
- package/dist/core/work-meter.d.ts +8 -0
- package/dist/core/work-meter.js +83 -0
- package/dist/core/work-observe.d.ts +12 -0
- package/dist/core/work-observe.js +39 -0
- package/dist/core/work-profile.d.ts +10 -0
- package/dist/core/work-profile.js +21 -0
- package/dist/core/work-refusal.d.ts +1 -0
- package/dist/core/work-refusal.js +6 -0
- package/dist/interchange/format.js +2 -0
- package/dist/kernel/cdcl.js +93 -40
- package/dist/kernel/epr.js +23 -8
- package/dist/kernel/kernel.d.ts +47 -1
- package/dist/kernel/kernel.js +417 -68
- package/dist/kernel/prove.d.ts +49 -3
- package/dist/kernel/prove.js +468 -122
- package/dist/kernel/prover-rows.d.ts +1 -0
- package/dist/kernel/prover-rows.js +12 -1
- package/dist/kernel/reader.d.ts +1 -1
- package/dist/kernel/reader.js +57 -12
- package/dist/kernel/simplex.js +9 -2
- package/dist/lean-kernel/emit.d.ts +9 -1
- package/dist/lean-kernel/emit.js +144 -22
- package/dist/lean-kernel/legacy-family-library.d.ts +1 -0
- package/dist/lean-kernel/legacy-family-library.js +5 -0
- package/dist/lean-kernel/library.js +3 -3
- package/package.json +1 -1
package/dist/core/exists.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { traceNow as countedTraceNow, BudgetExpired } from "./wall.js";
|
|
2
|
+
import { withReachabilityWork, reachState, reachEdge } from "./work-observe.js";
|
|
3
|
+
import { requestQuotient } from "./request-quotient.js";
|
|
1
4
|
// There exists: a law ∃ x. P(x) (core/machine.ts's Law with `some`: x a natural, or an integer as two, x and x$neg),
|
|
2
5
|
// proven through a witness. Nothing here is trusted: the kernel proves a plain law of a plain machine, and the Lean
|
|
3
6
|
// export states the existential again, proven by ⟨witness, proof⟩ (lean-kernel/Ghost.lean's some_updAll).
|
|
@@ -18,7 +21,7 @@ import { carriedView, compileC, evalC, evalE, fastStep, interpret, n as k, walk,
|
|
|
18
21
|
import { clock, proveLaw, proveLaws, withDeadline, withinDeadline } from "../kernel/prove.js";
|
|
19
22
|
import { env } from "./solver.js";
|
|
20
23
|
import { WallExpired, checkWall } from "./wall.js";
|
|
21
|
-
import { ghostedMachine, ghostedOk, substC } from "../kernel/kernel.js";
|
|
24
|
+
import { finiteLawBound, ghostedMachine, ghostedOk, substC } from "../kernel/kernel.js";
|
|
22
25
|
const add = (a, b) => (a.op === 'const' && a.value === 0 ? b : b.op === 'const' && b.value === 0 ? a : { op: 'add', a, b });
|
|
23
26
|
const sum = (es) => es.reduce((acc, e) => add(acc, e), k(0));
|
|
24
27
|
const sub = (a, b) => (b.op === 'const' && b.value === 0 ? a : { op: 'sub', a, b });
|
|
@@ -166,13 +169,34 @@ const atomsOf2 = (c) => (c.op === 'and' || c.op === 'or' ? c.xs.flatMap(atomsOf2
|
|
|
166
169
|
// alike among those a few requests make: an action the BFS's levels never reach, a leader past a majority's votes, is
|
|
167
170
|
// taken as often as any other. Each state's step from the state it was first reached from is kept: `pathTo`.)
|
|
168
171
|
const pathTo = new WeakMap();
|
|
172
|
+
// Search hints only. A caller must replay this path on its original machine;
|
|
173
|
+
// an unrelated state with no cached parent must never be trusted as an init.
|
|
174
|
+
export function retainedSamplePath(state, visit) {
|
|
175
|
+
const requests = [], seen = new Set();
|
|
176
|
+
for (let at = state;;) {
|
|
177
|
+
visit();
|
|
178
|
+
if (seen.has(at))
|
|
179
|
+
return undefined;
|
|
180
|
+
seen.add(at);
|
|
181
|
+
const from = pathTo.get(at);
|
|
182
|
+
if (!from)
|
|
183
|
+
return requests.reverse();
|
|
184
|
+
requests.push(from[1]);
|
|
185
|
+
at = from[0];
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
export function retainedSamples(m) { return smalls.get(m) ?? []; }
|
|
169
189
|
export function small(m, p, b, cap = 3000, work = 300_000, walks = 0) {
|
|
190
|
+
return withReachabilityWork(() => smallWithin(m, p, b, cap, work, walks));
|
|
191
|
+
}
|
|
192
|
+
function smallWithin(m, p, b, cap, work, walks) {
|
|
193
|
+
reachState();
|
|
170
194
|
// (past a thousand steps, through the generated JavaScript, fastStep: the interpreter's states, as compile.test.ts holds
|
|
171
195
|
// them; a small machine's few steps cost less than its compiling)
|
|
172
196
|
checkWall('sample setup');
|
|
173
197
|
const run = interpret(m), start = run.init(p);
|
|
174
198
|
let steps = 0, fast = run.step;
|
|
175
|
-
const step = (p2, st, r) => { if (++steps === 1000)
|
|
199
|
+
const step = (p2, st, r) => { reachEdge(); if (++steps === 1000)
|
|
176
200
|
fast = fastStep(m) ?? run.step; return fast(p2, st, r); };
|
|
177
201
|
const subsets = Array.from({ length: 1 << b }, (_, s) => new Map(Array.from({ length: b }, (_, i) => i).filter(i => (s >> i) & 1).map(i => [i, 1])));
|
|
178
202
|
// (an input the assumption keeps below a few values, an action's, over all of them; the rest below b)
|
|
@@ -182,6 +206,7 @@ export function small(m, p, b, cap = 3000, work = 300_000, walks = 0) {
|
|
|
182
206
|
reqs = reqs.flatMap(r => Array.from({ length: below(i) }, (_, x) => ({ ...r, [i]: x })));
|
|
183
207
|
for (const c of m.inputMaps ?? [])
|
|
184
208
|
reqs = reqs.flatMap(r => subsets.map(s => ({ ...r, [c]: s })));
|
|
209
|
+
const quotient = env.GDP_REQUEST_QUOTIENT === '1' ? requestQuotient(m, reqs) : undefined;
|
|
185
210
|
// (a state once: by a hash of its scalars and nonzero cells, then a cell-by-cell comparison within the hash's bucket;
|
|
186
211
|
// the same classes as a sorted text of the state, without a sort or a text per step)
|
|
187
212
|
const scalarNames = Object.keys(start.scalars), mapNames = Object.keys(start.maps);
|
|
@@ -219,23 +244,32 @@ export function small(m, p, b, cap = 3000, work = 300_000, walks = 0) {
|
|
|
219
244
|
}
|
|
220
245
|
else
|
|
221
246
|
seen.set(h, [next]);
|
|
247
|
+
reachState();
|
|
222
248
|
all.push(next);
|
|
223
249
|
pathTo.set(next, [from, r]);
|
|
224
250
|
return next;
|
|
225
251
|
};
|
|
226
252
|
while (queue.length && all.length < cap && work > 0) {
|
|
227
|
-
const st = queue.shift();
|
|
253
|
+
const st = queue.shift(), covered = quotient ? new Set() : undefined;
|
|
254
|
+
let requestIndex = 0;
|
|
228
255
|
for (const r of reqs) {
|
|
229
256
|
checkWall('sample BFS');
|
|
230
257
|
if (--work < 0)
|
|
231
258
|
break;
|
|
259
|
+
const cls = quotient?.classes[requestIndex++];
|
|
260
|
+
if (cls !== undefined && covered.has(cls))
|
|
261
|
+
continue;
|
|
232
262
|
let next;
|
|
233
263
|
try {
|
|
234
264
|
next = step(p, st, r);
|
|
235
265
|
}
|
|
236
|
-
catch {
|
|
266
|
+
catch (error) {
|
|
267
|
+
if (error instanceof BudgetExpired)
|
|
268
|
+
throw error;
|
|
237
269
|
continue;
|
|
238
270
|
}
|
|
271
|
+
if (cls !== undefined)
|
|
272
|
+
covered.add(cls);
|
|
239
273
|
const n0 = all.length;
|
|
240
274
|
if (reached(next, st, r) && all.length > n0)
|
|
241
275
|
queue.push(next);
|
|
@@ -259,7 +293,9 @@ export function small(m, p, b, cap = 3000, work = 300_000, walks = 0) {
|
|
|
259
293
|
try {
|
|
260
294
|
next = step(p, st, r);
|
|
261
295
|
}
|
|
262
|
-
catch {
|
|
296
|
+
catch (error) {
|
|
297
|
+
if (error instanceof BudgetExpired)
|
|
298
|
+
throw error;
|
|
263
299
|
continue;
|
|
264
300
|
}
|
|
265
301
|
const kd = kindOf(st, next);
|
|
@@ -360,6 +396,10 @@ export function trueSmall(m, laws, ghosted) {
|
|
|
360
396
|
const views = new WeakMap();
|
|
361
397
|
const sampleTests = new WeakMap();
|
|
362
398
|
export function holdsAt(m, law, p, st, b) {
|
|
399
|
+
return withReachabilityWork(() => holdsAtWithin(m, law, p, st, b));
|
|
400
|
+
}
|
|
401
|
+
function holdsAtWithin(m, law, p, st, b) {
|
|
402
|
+
const finite = finiteLawBound(law);
|
|
363
403
|
let machineViews = views.get(m);
|
|
364
404
|
if (!machineViews)
|
|
365
405
|
views.set(m, (machineViews = new WeakMap()));
|
|
@@ -368,6 +408,8 @@ export function holdsAt(m, law, p, st, b) {
|
|
|
368
408
|
const empty = Object.fromEntries((m.inputMaps ?? []).map(c => [c, new Map()]));
|
|
369
409
|
machineViews.set(st, (view = carriedView(m, st, empty, undefined, p)));
|
|
370
410
|
}
|
|
411
|
+
if (finite)
|
|
412
|
+
return evalC({ op: 'all', key: law.forall, c: law.holds, finite: law.finite }, p, view, m);
|
|
371
413
|
let tests = sampleTests.get(m);
|
|
372
414
|
if (!tests)
|
|
373
415
|
sampleTests.set(m, (tests = new WeakMap()));
|
|
@@ -1233,12 +1275,12 @@ export function proveSome(m, laws, opts = {}) {
|
|
|
1233
1275
|
firstPicks.set(key([m.step, m.assume ?? null, m.maps ?? null, p.law.holds]), pk.mode === 'map' ? { mode: 'map', at: pk.at } : { mode: 'term', at: [...pk.at] });
|
|
1234
1276
|
}
|
|
1235
1277
|
for (let round = 0;; round++) {
|
|
1236
|
-
const now = current(), t0 =
|
|
1278
|
+
const now = current(), t0 = countedTraceNow(), r = round === 0 && first ? { proven: false, ...first }
|
|
1237
1279
|
// (a ghost map's goals within 2 s: a search asks them with every candidate set, and one without its supports can take
|
|
1238
1280
|
// minutes; `mapMs` where the supports are the search's, found over the same map)
|
|
1239
1281
|
: p.pick.mode === 'map' ? withDeadline(clock() + (opts.mapMs ?? 2_000), () => proveLaw(now.machine, now.laws, i)) : proveLaw(now.machine, now.laws, i);
|
|
1240
1282
|
if (log)
|
|
1241
|
-
console.error(`exists: pass ${pass} round ${round} "${p.law.name}" ${p.pick.mode} ${describe(p, cases).slice(0, 160)}: ${r.proven ? 'proven' : `${r.goal} ${r.stuck}`} (${Math.round(
|
|
1283
|
+
console.error(`exists: pass ${pass} round ${round} "${p.law.name}" ${p.pick.mode} ${describe(p, cases).slice(0, 160)}: ${r.proven ? 'proven' : `${r.goal} ${r.stuck}`} (${Math.round(countedTraceNow() - t0)} ms)`);
|
|
1242
1284
|
if (r.proven)
|
|
1243
1285
|
return undefined;
|
|
1244
1286
|
const fail = (stuck) => ({ proven: false, nodes: 0, leaves: 0, checked: false, failed: { goal: r.goal, stuck, ...(r.witness ? { witness: r.witness } : {}) } });
|
|
@@ -1321,10 +1363,10 @@ export function proveSome(m, laws, opts = {}) {
|
|
|
1321
1363
|
return f;
|
|
1322
1364
|
}
|
|
1323
1365
|
for (let pass = 1;; pass++) {
|
|
1324
|
-
const { machine, laws: plain, ghosts } = current(), t0 =
|
|
1366
|
+
const { machine, laws: plain, ghosts } = current(), t0 = countedTraceNow();
|
|
1325
1367
|
const out = (opts.whole ?? proveLaws)(machine, plain), done = { ...out, laws: out.laws ?? plain, machine, ghosts, witnesses: Object.fromEntries([...plans.values()].map(p => [p.law.name, describe(p, cases)])) };
|
|
1326
1368
|
if (log)
|
|
1327
|
-
console.error(`exists: pass ${pass} the whole set: ${out.proven ? 'proven' : `${out.failed?.goal} ${out.failed?.stuck}`} (${Math.round(
|
|
1369
|
+
console.error(`exists: pass ${pass} the whole set: ${out.proven ? 'proven' : `${out.failed?.goal} ${out.failed?.stuck}`} (${Math.round(countedTraceNow() - t0)} ms)`);
|
|
1328
1370
|
const j = out.proven || !out.failed || pass > 8 ? undefined : [...plans.keys()].find(k => out.failed.goal.startsWith(`${laws[k].name} @`));
|
|
1329
1371
|
if (j === undefined)
|
|
1330
1372
|
return done;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { type Law, type Machine } from './machine.js';
|
|
2
|
-
export declare
|
|
2
|
+
export declare const weakensField: WeakMap<Law, Law>;
|
|
3
|
+
export declare function selectFieldLaws(laws: Law[], admit: (law: Law) => boolean): Law[];
|
|
4
|
+
export declare function fieldLaws(m: Machine, composed?: boolean, loaded?: boolean): Law[];
|
package/dist/core/field-laws.js
CHANGED
|
@@ -3,7 +3,24 @@
|
|
|
3
3
|
// Propose their shapes, not facts: counts.ts filters on reachable samples, and the
|
|
4
4
|
// ordinary counted induction/checker must prove every surviving candidate.
|
|
5
5
|
import { all, any, atMost, get, less, n, not, same, times, plus, tuple, walk, x } from "./machine.js";
|
|
6
|
-
|
|
6
|
+
// A guarded form and the stronger candidate it weakens; the guarded one is admitted only when the stronger is not.
|
|
7
|
+
export const weakensField = new WeakMap();
|
|
8
|
+
const loadFieldFamily = new WeakMap();
|
|
9
|
+
// Prefer the unguarded load, otherwise the first admitted singleton guard.
|
|
10
|
+
// Older field families retain their order and admission behavior.
|
|
11
|
+
export function selectFieldLaws(laws, admit) {
|
|
12
|
+
const kept = new Set(), selectedLoads = new Set();
|
|
13
|
+
return laws.filter(law => {
|
|
14
|
+
const stronger = weakensField.get(law), load = loadFieldFamily.get(law);
|
|
15
|
+
if ((stronger && kept.has(stronger)) || (load && selectedLoads.has(load)) || !admit(law))
|
|
16
|
+
return false;
|
|
17
|
+
kept.add(law);
|
|
18
|
+
if (load)
|
|
19
|
+
selectedLoads.add(load);
|
|
20
|
+
return true;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export function fieldLaws(m, composed = true, loaded = true) {
|
|
7
24
|
const fields = new Set(), roles = new Map(), bounds = new Map();
|
|
8
25
|
const maps = m.maps ?? {}, source = [m.assume, m.step.flags];
|
|
9
26
|
const direct = (e) => e.op === 'get' && e.key.op === 'var' && e.map in maps;
|
|
@@ -87,14 +104,135 @@ export function fieldLaws(m, composed = true) {
|
|
|
87
104
|
const old = rows.get(o.map);
|
|
88
105
|
rows.set(o.map, old === undefined || old === key.a.k ? key.a.k : 0);
|
|
89
106
|
});
|
|
107
|
+
const agrees = [];
|
|
90
108
|
for (const [map, base] of rows)
|
|
91
109
|
if (base)
|
|
92
110
|
for (let i = 0; i < fs.length; i++)
|
|
93
111
|
for (let j = i + 1; j < fs.length; j++) {
|
|
94
112
|
const f = fs[i], g = fs[j], cell = (row) => get(map, plus(times(base, row), c));
|
|
95
113
|
const guard = all(da, db, less(c, bound), same(get(f, a), get(f, b)), same(get(g, a), get(g, b)));
|
|
96
|
-
|
|
114
|
+
const law = { name: `fields: ${f}[a]=${f}[b] and ${g}[a]=${g}[b] -> ${map} rows agree`, forall: ka, keys: [kb, kc], holds: any(not(guard), same(cell(a), cell(b))) };
|
|
115
|
+
out.push(law);
|
|
116
|
+
agrees.push({ map, f, g, law });
|
|
97
117
|
}
|
|
118
|
+
if (!loaded)
|
|
119
|
+
return out;
|
|
120
|
+
const node = (t) => !!t && typeof t === 'object' && !Array.isArray(t);
|
|
121
|
+
const atoms = (t) => !t ? [] : t.op === 'and' ? t.xs.flatMap(atoms) : [t];
|
|
122
|
+
const sameTerm = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
123
|
+
const restrictCondition = (condition, flag, value) => {
|
|
124
|
+
if (condition.op === 'flag')
|
|
125
|
+
return condition.name === flag ? value : condition;
|
|
126
|
+
if (condition.op === 'not') {
|
|
127
|
+
const inner = restrictCondition(condition.x, flag, value);
|
|
128
|
+
return typeof inner === 'boolean' ? !inner : not(inner);
|
|
129
|
+
}
|
|
130
|
+
if (condition.op === 'and' || condition.op === 'or') {
|
|
131
|
+
const parts = condition.xs.map(c => restrictCondition(c, flag, value)), conjunction = condition.op === 'and';
|
|
132
|
+
if (parts.includes(!conjunction))
|
|
133
|
+
return !conjunction;
|
|
134
|
+
const rest = parts.filter((c) => typeof c !== 'boolean');
|
|
135
|
+
return !rest.length ? conjunction : rest.length === 1 ? rest[0] : conjunction ? all(...rest) : any(...rest);
|
|
136
|
+
}
|
|
137
|
+
if ((condition.op === '=' || condition.op === '<' || condition.op === '<=') && condition.a.op === 'const' && condition.b.op === 'const') {
|
|
138
|
+
return condition.op === '=' ? condition.a.value === condition.b.value : condition.op === '<' ? condition.a.value < condition.b.value : condition.a.value <= condition.b.value;
|
|
139
|
+
}
|
|
140
|
+
return condition;
|
|
141
|
+
};
|
|
142
|
+
const restrictValue = (value, flag, active) => {
|
|
143
|
+
if (value.op !== 'if')
|
|
144
|
+
return value;
|
|
145
|
+
const condition = restrictCondition(value.c, flag, active);
|
|
146
|
+
if (typeof condition === 'boolean')
|
|
147
|
+
return restrictValue(condition ? value.then : value.else, flag, active);
|
|
148
|
+
return { ...value, c: condition, then: restrictValue(value.then, flag, active), else: restrictValue(value.else, flag, active) };
|
|
149
|
+
};
|
|
150
|
+
const markerValue = (value, map, key, flag) => {
|
|
151
|
+
const active = restrictValue(value, flag, true), inactive = restrictValue(value, flag, false);
|
|
152
|
+
if (active.op !== 'const' || !Number.isSafeInteger(active.value) || active.value < 1)
|
|
153
|
+
return undefined;
|
|
154
|
+
const old = get(map, key), v = active.value;
|
|
155
|
+
if (sameTerm(inactive, old) || inactive.op === 'const' && inactive.value !== v)
|
|
156
|
+
return v;
|
|
157
|
+
// Boolean maps compile a preserved cell as if old=1 then 1 else 0.
|
|
158
|
+
// This cannot manufacture a marker outside the load branch.
|
|
159
|
+
if (inactive.op === 'if' && inactive.c.op === '=' && inactive.then.op === 'const' && inactive.then.value === v
|
|
160
|
+
&& inactive.else.op === 'const' && inactive.else.value !== v
|
|
161
|
+
&& (sameTerm(inactive.c, same(old, n(v))) || sameTerm(inactive.c, same(n(v), old))))
|
|
162
|
+
return v;
|
|
163
|
+
return undefined;
|
|
164
|
+
};
|
|
165
|
+
const emitted = new Map();
|
|
166
|
+
const add = (law) => {
|
|
167
|
+
const key = JSON.stringify(law.holds), old = emitted.get(key);
|
|
168
|
+
if (old)
|
|
169
|
+
return old;
|
|
170
|
+
emitted.set(key, law);
|
|
171
|
+
out.push(law);
|
|
172
|
+
return law;
|
|
173
|
+
};
|
|
174
|
+
for (const [map, base] of rows) {
|
|
175
|
+
const w = m.step.maps?.[map];
|
|
176
|
+
if (!base || !w || !('each' in w))
|
|
177
|
+
continue;
|
|
178
|
+
const loads = new Map();
|
|
179
|
+
const visit = (t, positive) => {
|
|
180
|
+
if (Array.isArray(t)) {
|
|
181
|
+
for (const u of t)
|
|
182
|
+
visit(u, positive);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (!node(t) || t.op === 'not')
|
|
186
|
+
return;
|
|
187
|
+
if (t.op === 'if') {
|
|
188
|
+
const branch = [...positive, ...atoms(t.c)];
|
|
189
|
+
visit(t.c, branch);
|
|
190
|
+
visit(t.then, branch);
|
|
191
|
+
visit(t.else, positive);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const here = t.op === 'and' ? [...positive, ...atoms(t)] : positive;
|
|
195
|
+
const key = t.key, row = key?.b, input = row?.a?.name, src = t.map;
|
|
196
|
+
if (t.op === 'get' && src !== map && src in maps && !rows.has(src) && key?.op === 'sub' && key.a.op === 'var' && key.a.name === w.each
|
|
197
|
+
&& row?.op === 'mul' && row.k === base && row.a.op === 'var' && input !== undefined && m.inputs.includes(input)
|
|
198
|
+
&& here.some(q => sameTerm(q, atMost(times(base, x(input)), x(w.each))))
|
|
199
|
+
&& here.some(q => sameTerm(q, less(x(w.each), plus(times(base, x(input)), n(base))))))
|
|
200
|
+
for (const q of here)
|
|
201
|
+
if (q.op === 'flag') {
|
|
202
|
+
const flag = q.name;
|
|
203
|
+
loads.set(`${src}:${input}:${flag}`, { src, input, flag });
|
|
204
|
+
}
|
|
205
|
+
for (const u of Object.values(t))
|
|
206
|
+
visit(u, here);
|
|
207
|
+
};
|
|
208
|
+
visit(w.value, []);
|
|
209
|
+
const cell = (r) => get(map, plus(times(base, r), c));
|
|
210
|
+
for (const { src, input, flag } of loads.values())
|
|
211
|
+
for (const [mk, mw] of Object.entries(m.step.maps ?? {})) {
|
|
212
|
+
if ('each' in mw || mw.key.op !== 'var' || mw.key.name !== input || !(mk in maps) || rows.has(mk) || mk === src)
|
|
213
|
+
continue;
|
|
214
|
+
const v = markerValue(mw.value, mk, mw.key, flag);
|
|
215
|
+
if (v === undefined)
|
|
216
|
+
continue;
|
|
217
|
+
const marked = (r) => same(get(mk, r), n(v)), def = m.step.flags?.[flag];
|
|
218
|
+
const literals = atoms(def).filter(q => q.op === '=' && q.a.op === 'var' && q.a.name in m.state && q.b.op === 'const');
|
|
219
|
+
const load = (guards, label) => ({ name: `fields: ${mk}[a]=${v}${label} -> ${map} row is ${src}`, forall: ka, keys: [kc],
|
|
220
|
+
holds: any(not(all(da, less(c, bound), marked(a), ...guards)), same(cell(a), get(src, c))) });
|
|
221
|
+
const whole = add(load([], ''));
|
|
222
|
+
loadFieldFamily.set(whole, whole);
|
|
223
|
+
for (const lit of literals) {
|
|
224
|
+
const q = lit, weaker = load([lit], ` and ${q.a.name}=${q.b.value}`);
|
|
225
|
+
const choice = add(weaker);
|
|
226
|
+
weakensField.set(choice, whole);
|
|
227
|
+
loadFieldFamily.set(choice, whole);
|
|
228
|
+
}
|
|
229
|
+
for (const { f, g, law } of agrees.filter(r => r.map === map)) {
|
|
230
|
+
const guard = all(da, db, less(c, bound), same(get(f, a), get(f, b)), same(get(g, a), get(g, b)), marked(a), marked(b));
|
|
231
|
+
const weaker = { name: `fields: ${f}[a]=${f}[b] and ${g}[a]=${g}[b] and ${mk}[a]=${mk}[b]=${v} -> ${map} rows agree`, forall: ka, keys: [kb, kc], holds: any(not(guard), same(cell(a), cell(b))) };
|
|
232
|
+
weakensField.set(add(weaker), law);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
98
236
|
}
|
|
99
237
|
return out;
|
|
100
238
|
}
|
|
@@ -29,10 +29,16 @@ export type FiniteOptions = {
|
|
|
29
29
|
seed?: number;
|
|
30
30
|
targeted?: boolean;
|
|
31
31
|
wallMs?: number;
|
|
32
|
+
workLimit?: number;
|
|
32
33
|
onFinish?: (row: {
|
|
33
34
|
timedOut: boolean;
|
|
34
35
|
ms: number;
|
|
35
36
|
dropped: number;
|
|
37
|
+
work?: {
|
|
38
|
+
used: number;
|
|
39
|
+
limit: number;
|
|
40
|
+
exhausted: boolean;
|
|
41
|
+
};
|
|
36
42
|
}) => void;
|
|
37
43
|
onDrop?: (drop: FiniteDrop) => void;
|
|
38
44
|
onRound?: (row: {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { traceNow as countedTraceNow } from "./wall.js";
|
|
1
2
|
// A finite relative-CTI filter, never a proof. Unsupported evaluations are
|
|
2
3
|
// unknown; only an actual enabled step from a state satisfying the WHOLE
|
|
3
4
|
// current family may remove a non-caller. The checked prover sees survivors.
|
|
4
|
-
import { carriedView, compileC, compileE, fastStep, interpret, seeded, walk } from "./machine.js";
|
|
5
|
-
import { checkWall, searchWall, WallExpired } from "./wall.js";
|
|
5
|
+
import { carriedView, compileC, compileE, fastStep, hasFinite, interpret, seeded, walk } from "./machine.js";
|
|
6
|
+
import { checkWall, searchWall, WallExpired, BudgetExpired } from "./wall.js";
|
|
6
7
|
import { boundaryState, lawFrontiers } from "./finite-frontiers.js";
|
|
7
|
-
import {
|
|
8
|
+
import { withReachabilityWork, reachState, reachEdge } from "./work-observe.js";
|
|
9
|
+
import { wallAt, withWall, wallDeadline } from "../kernel/prove.js";
|
|
8
10
|
import { tinyFiniteCandidates, tinySeedCandidates } from "./finite-tiny.js";
|
|
9
11
|
const variables = (t) => { const out = new Set(); walk(t, o => { if (o.op === 'var')
|
|
10
12
|
out.add(o.name); }); return out; };
|
|
@@ -16,6 +18,7 @@ const conjuncts = (c) => c.op === 'and' ? c.xs.flatMap(conjuncts) : [c];
|
|
|
16
18
|
export function finiteEvaluator(m, stop = () => false) {
|
|
17
19
|
const checkpoint = () => { checkWall('finite derived count'); if (stop())
|
|
18
20
|
throw new Error('finite evaluation stopped'); };
|
|
21
|
+
const finiteMachine = hasFinite(m);
|
|
19
22
|
const plans = new WeakMap();
|
|
20
23
|
const cache = new WeakMap();
|
|
21
24
|
function plan(law) {
|
|
@@ -77,11 +80,12 @@ export function finiteEvaluator(m, stop = () => false) {
|
|
|
77
80
|
let nested = false;
|
|
78
81
|
walk(law.holds, o => { if (o.op === 'all')
|
|
79
82
|
nested = true; });
|
|
80
|
-
return { keys, cover, guards: gs, test: compileC(law.holds, m), supported: !nested && !law.some?.length && !keys.some(k => k in m.state || m.params.includes(k)) && ![...variables(law.holds)].some(k => m.inputs.includes(k) && !keys.includes(k)) };
|
|
83
|
+
return { keys, cover, guards: gs, test: compileC(law.holds, m), supported: !nested && !hasFinite(law) && !law.some?.length && !keys.some(k => k in m.state || m.params.includes(k)) && ![...variables(law.holds)].some(k => m.inputs.includes(k) && !keys.includes(k)) };
|
|
81
84
|
}
|
|
82
|
-
return (law, p, st) => {
|
|
85
|
+
return (law, p, st) => withReachabilityWork(() => {
|
|
83
86
|
checkWall('finite law');
|
|
84
|
-
|
|
87
|
+
// This specialized cover compiler has not been extended to sized domains.
|
|
88
|
+
if (stop() || finiteMachine)
|
|
85
89
|
return undefined;
|
|
86
90
|
let entry = cache.get(st);
|
|
87
91
|
if (!entry || entry.params !== p) {
|
|
@@ -159,27 +163,57 @@ export function finiteEvaluator(m, stop = () => false) {
|
|
|
159
163
|
truth = go(shape.cover);
|
|
160
164
|
}
|
|
161
165
|
catch (e) {
|
|
162
|
-
if (e instanceof WallExpired)
|
|
166
|
+
if (e instanceof WallExpired || e instanceof BudgetExpired)
|
|
163
167
|
throw e;
|
|
164
168
|
truth = undefined;
|
|
165
169
|
}
|
|
166
170
|
entry.values.set(law, truth);
|
|
167
171
|
return truth;
|
|
168
|
-
};
|
|
172
|
+
});
|
|
169
173
|
}
|
|
170
174
|
export const finiteDump = {};
|
|
175
|
+
class FiniteWorkExpired extends Error {
|
|
176
|
+
}
|
|
171
177
|
export function finiteHoudini(source, m, caller, candidates, samples, options = {}) {
|
|
172
|
-
const
|
|
178
|
+
const limit = options.workLimit;
|
|
179
|
+
if (limit !== undefined && (!Number.isSafeInteger(limit) || limit < 0))
|
|
180
|
+
throw new Error('finite work limit must be a nonnegative safe integer');
|
|
181
|
+
const work = limit === undefined ? undefined : { used: 0, limit, exhausted: false };
|
|
182
|
+
const start = countedTraceNow(), end = wallDeadline(work ? wallAt() : Math.min(wallAt(), searchWall(Math.max(0, options.wallMs ?? 2_000)).end));
|
|
183
|
+
const tick = () => {
|
|
184
|
+
if (!work)
|
|
185
|
+
return;
|
|
186
|
+
checkWall('finite sampling work');
|
|
187
|
+
if (work.used >= work.limit) {
|
|
188
|
+
work.exhausted = true;
|
|
189
|
+
throw new FiniteWorkExpired();
|
|
190
|
+
}
|
|
191
|
+
work.used++;
|
|
192
|
+
};
|
|
173
193
|
let survivors = candidates.slice(), timedOut = false;
|
|
174
194
|
try {
|
|
175
|
-
return withWall(end, () =>
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
195
|
+
return withWall(end, () => withReachabilityWork(() => {
|
|
196
|
+
if (work)
|
|
197
|
+
checkWall('finite sampling start');
|
|
198
|
+
if (work?.limit === 0) {
|
|
199
|
+
work.exhausted = true;
|
|
200
|
+
return survivors;
|
|
201
|
+
}
|
|
202
|
+
return finiteHoudiniWithin(source, m, caller, candidates, samples, { ...options, onDrop: drop => {
|
|
203
|
+
survivors = survivors.filter(law => law !== drop.law);
|
|
204
|
+
options.onDrop?.(drop);
|
|
205
|
+
} }, tick);
|
|
206
|
+
}));
|
|
179
207
|
}
|
|
180
208
|
catch (error) {
|
|
209
|
+
if (error instanceof FiniteWorkExpired)
|
|
210
|
+
return survivors;
|
|
181
211
|
if (!(error instanceof WallExpired))
|
|
182
212
|
throw error;
|
|
213
|
+
if (work) {
|
|
214
|
+
timedOut = true;
|
|
215
|
+
throw error;
|
|
216
|
+
}
|
|
183
217
|
// An enclosing deadline must still cancel the caller. Only expiration of
|
|
184
218
|
// this local sampling allowance returns the already-certified survivors.
|
|
185
219
|
checkWall('finite sampling completion');
|
|
@@ -187,7 +221,7 @@ export function finiteHoudini(source, m, caller, candidates, samples, options =
|
|
|
187
221
|
return survivors;
|
|
188
222
|
}
|
|
189
223
|
finally {
|
|
190
|
-
options.onFinish?.({ timedOut, ms:
|
|
224
|
+
options.onFinish?.({ timedOut, ms: countedTraceNow() - start, dropped: candidates.length - survivors.length, ...(work ? { work } : {}) });
|
|
191
225
|
}
|
|
192
226
|
}
|
|
193
227
|
// What a law reads: its scalars and maps, a count map read as the scalars and maps of its body and bound. A law
|
|
@@ -217,10 +251,10 @@ function lawReads(m, law) {
|
|
|
217
251
|
// independent whole-family/source-interpreter boundary as sampled Houdini.
|
|
218
252
|
// It is not wired into production generation until its bounded pilot passes.
|
|
219
253
|
export function finiteTinyHoudini(source, m, caller, candidates, params, options = {}) {
|
|
220
|
-
const start =
|
|
254
|
+
const start = countedTraceNow(), end = wallDeadline(Math.min(wallAt(), searchWall(Math.max(0, options.wallMs ?? 2_000)).end));
|
|
221
255
|
let survivors = candidates.slice(), timedOut = false;
|
|
222
256
|
try {
|
|
223
|
-
return withWall(end, () => {
|
|
257
|
+
return withWall(end, () => withReachabilityWork(() => {
|
|
224
258
|
if (source.history || m.history || Object.keys(source.leasts ?? {}).length || Object.keys(m.leasts ?? {}).length || Object.keys(source.sums ?? {}).length || Object.keys(m.sums ?? {}).length)
|
|
225
259
|
return survivors;
|
|
226
260
|
finiteDump.onStart?.({ machine: m, caller, candidates });
|
|
@@ -234,15 +268,17 @@ export function finiteTinyHoudini(source, m, caller, candidates, params, options
|
|
|
234
268
|
checkWall('tiny Houdini instance');
|
|
235
269
|
const certify = (pre, request) => {
|
|
236
270
|
checkWall('tiny Houdini certification');
|
|
271
|
+
reachState();
|
|
237
272
|
// The screen's constraints and reported post-laws are not trusted.
|
|
238
273
|
if (!family.every(law => evaluate(law, p, pre) === true))
|
|
239
274
|
return false;
|
|
240
275
|
let post;
|
|
241
276
|
try {
|
|
277
|
+
reachEdge();
|
|
242
278
|
post = run.step(p, pre, request);
|
|
243
279
|
}
|
|
244
280
|
catch (e) {
|
|
245
|
-
if (e instanceof WallExpired)
|
|
281
|
+
if (e instanceof WallExpired || e instanceof BudgetExpired)
|
|
246
282
|
throw e;
|
|
247
283
|
return false;
|
|
248
284
|
}
|
|
@@ -281,7 +317,7 @@ export function finiteTinyHoudini(source, m, caller, candidates, params, options
|
|
|
281
317
|
return survivors;
|
|
282
318
|
}
|
|
283
319
|
return survivors;
|
|
284
|
-
});
|
|
320
|
+
}));
|
|
285
321
|
}
|
|
286
322
|
catch (e) {
|
|
287
323
|
if (!(e instanceof WallExpired))
|
|
@@ -291,10 +327,10 @@ export function finiteTinyHoudini(source, m, caller, candidates, params, options
|
|
|
291
327
|
return survivors;
|
|
292
328
|
}
|
|
293
329
|
finally {
|
|
294
|
-
options.onFinish?.({ timedOut, ms:
|
|
330
|
+
options.onFinish?.({ timedOut, ms: countedTraceNow() - start, dropped: candidates.length - survivors.length });
|
|
295
331
|
}
|
|
296
332
|
}
|
|
297
|
-
function finiteHoudiniWithin(source, m, caller, candidates, samples, options) {
|
|
333
|
+
function finiteHoudiniWithin(source, m, caller, candidates, samples, options, tick) {
|
|
298
334
|
finiteDump.onStart?.({ machine: m, caller, candidates });
|
|
299
335
|
// Derived sum-state consistency is not reconstructed by this finite backend.
|
|
300
336
|
if (Object.keys(m.sums ?? {}).length)
|
|
@@ -346,6 +382,8 @@ function finiteHoudiniWithin(source, m, caller, candidates, samples, options) {
|
|
|
346
382
|
return law;
|
|
347
383
|
} return undefined; };
|
|
348
384
|
const visit = (p, pre) => {
|
|
385
|
+
reachState();
|
|
386
|
+
tick();
|
|
349
387
|
const by = rejecting(p, pre);
|
|
350
388
|
if (by) {
|
|
351
389
|
rejected.push({ p, st: pre, by });
|
|
@@ -353,16 +391,18 @@ function finiteHoudiniWithin(source, m, caller, candidates, samples, options) {
|
|
|
353
391
|
}
|
|
354
392
|
const bound = Math.max(3, ...Object.values(p));
|
|
355
393
|
for (let trial = 0; trial < (options.requests ?? 25); trial++) {
|
|
394
|
+
tick();
|
|
356
395
|
checkWall('finite transitions');
|
|
357
396
|
const request = Object.fromEntries(numericInputs.map(({ name, bound: b }) => [name, rng(b)]));
|
|
358
397
|
for (const mp of source.inputMaps ?? [])
|
|
359
398
|
request[mp] = new Map(Array.from({ length: bound }, (_, i) => [i, 1]).filter(() => rng(2)));
|
|
360
399
|
let post;
|
|
361
400
|
try {
|
|
401
|
+
reachEdge();
|
|
362
402
|
post = step(p, pre, request);
|
|
363
403
|
}
|
|
364
404
|
catch (e) {
|
|
365
|
-
if (e instanceof WallExpired)
|
|
405
|
+
if (e instanceof WallExpired || e instanceof BudgetExpired)
|
|
366
406
|
throw e;
|
|
367
407
|
continue;
|
|
368
408
|
}
|
|
@@ -408,6 +448,7 @@ function finiteHoudiniWithin(source, m, caller, candidates, samples, options) {
|
|
|
408
448
|
// one-sided boundary, a guard enabled, or a bounded field at its limit.
|
|
409
449
|
const frontiers = options.targeted === false ? [] : alive.flatMap(law => lawFrontiers(law).map(conditions => ({ law, conditions })));
|
|
410
450
|
for (let i = 0; frontiers.length && i < Math.min(requested, frontiers.length * 8); i++) {
|
|
451
|
+
tick();
|
|
411
452
|
checkWall('finite frontiers');
|
|
412
453
|
const { p, st: old } = base[rng(base.length)], { law, conditions } = frontiers[i % frontiers.length];
|
|
413
454
|
const bound = Math.max(1, ...Object.values(p)), keys = Object.fromEntries([law.forall, ...law.keys ?? []].filter((k) => !!k).map(k => [k, rng(bound)]));
|
|
@@ -418,6 +459,7 @@ function finiteHoudiniWithin(source, m, caller, candidates, samples, options) {
|
|
|
418
459
|
for (const { p, st } of base)
|
|
419
460
|
visit(p, st);
|
|
420
461
|
for (let tries = 0; accepted < requested && tries < Math.max(requested * 8, requested); tries++) {
|
|
462
|
+
tick();
|
|
421
463
|
checkWall('finite neighbors');
|
|
422
464
|
const { p, st: old } = base[rng(base.length)], st = { ...old, scalars: { ...old.scalars }, maps: { ...old.maps } };
|
|
423
465
|
const bound = Math.max(3, ...Object.values(p));
|