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/nonterm.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { traceNow as countedTraceNow, searchNow as countedSearchNow } from "./wall.js";
|
|
1
2
|
// Runs that never end, found: the search behind `proveNeverEnds`. Untrusted, like prove.ts: what it finds is a closed
|
|
2
3
|
// recurrent set with its successor given (kernel.ts's Recur), checked by kernel.ts's checkRecur and, exported, by
|
|
3
4
|
// NonTerm.lean's never_ends_of.
|
|
@@ -304,10 +305,10 @@ export function findNeverEnds(l, opts = {}) {
|
|
|
304
305
|
return opts.counted ? counted(opts.counted, () => search(l, opts)) : search(l, opts);
|
|
305
306
|
}
|
|
306
307
|
function search(l, opts) {
|
|
307
|
-
const wall0 =
|
|
308
|
+
const wall0 = countedTraceNow(), now = clock, t0 = now(), until = t0 + (opts.ms ?? 10_000), maxTurns = opts.maxTurns ?? 400;
|
|
308
309
|
const rand = seeded(opts.seed ?? 7);
|
|
309
310
|
const stats = { runs: 0, turns: 0, policies: 0, rounds: 0, ms: 0, lassoTried: 0, goalSize: 0, accel: 0, accelClosed: 0 };
|
|
310
|
-
const done = (v) => ({ ...v, stats: { ...stats, ms: Math.round(
|
|
311
|
+
const done = (v) => ({ ...v, stats: { ...stats, ms: Math.round(countedTraceNow() - wall0) } });
|
|
311
312
|
const stateNames = Object.keys(l.state), kept = [...l.params, ...stateNames];
|
|
312
313
|
const allObs = observables(kept), inObs = observables(l.inputs);
|
|
313
314
|
// The modes: state variables compared with a constant by `=` in the loop's conditions (a translated task's pc).
|
|
@@ -508,7 +509,7 @@ function search(l, opts) {
|
|
|
508
509
|
}
|
|
509
510
|
if (!stems.length && now() < until) {
|
|
510
511
|
const left = Math.min(until - now(), 2000);
|
|
511
|
-
const run = findBoundedRun(m, [{ name: 'outside the set', holds: { op: 'not', x: a.set } }], { ms: left, depth: 24, ...(opts.counted ? {} : { wall:
|
|
512
|
+
const run = findBoundedRun(m, [{ name: 'outside the set', holds: { op: 'not', x: a.set } }], { ms: left, depth: 24, ...(opts.counted ? {} : { wall: countedSearchNow() + left }) });
|
|
512
513
|
const c = run && cut({ params: run.params, stem: run.trace.map(r => Object.fromEntries(l.inputs.map(n => [n, Number(r[n] ?? 0)]))) });
|
|
513
514
|
if (c)
|
|
514
515
|
stems.push(c);
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { observeTableCells } from "./meter.js";
|
|
2
|
+
import { admittedLinearCopy as rowCopy, admittedLinearSub as rowSub, admittedLinearScale as rowScale, admittedLinearAdd as rowAdd, admittedLinearVariable as rowVariable, visitLinearCells } from "./linear-admission.js";
|
|
3
|
+
import { checkWorkEndpoint } from "./wall.js";
|
|
4
|
+
import { withTableAdmission } from "./table-admission.js";
|
|
5
|
+
import { workFlatMap, workFilter, workMap, workSetArray } from "./work-collections.js";
|
|
6
|
+
import { canon, canonFlip, cellParts, facts, isCell, reusing, termRows, truth } from "../kernel/kernel.js";
|
|
7
|
+
const seenFacts = new WeakMap();
|
|
8
|
+
function proposedFacts(c, path, positive = true) {
|
|
9
|
+
checkWorkEndpoint('row hypothesis');
|
|
10
|
+
if (c.op === 'not')
|
|
11
|
+
return proposedFacts(c.x, path, !positive);
|
|
12
|
+
if (c.op === 'and' || c.op === 'or') {
|
|
13
|
+
if ((c.op === 'and') === positive)
|
|
14
|
+
return workFlatMap(c.xs, y => proposedFacts(y, path, positive), 'proposedFacts:conjunction');
|
|
15
|
+
const open = workFilter(c.xs, y => { checkWorkEndpoint('row disjunction'); return truth(y, path) !== !positive; }, 'proposedFacts:disjunction');
|
|
16
|
+
return open.length === 0 ? [rowVariable('1', 1, 'proposedFacts:false')] : open.length === 1 ? proposedFacts(open[0], path, positive) : [];
|
|
17
|
+
}
|
|
18
|
+
return facts(c, path, positive);
|
|
19
|
+
}
|
|
20
|
+
// Same integer-path comparison as the reference row builder, outside its
|
|
21
|
+
// private memo state. This only proposes rows; their use is checked later.
|
|
22
|
+
function decided(lin, path) {
|
|
23
|
+
checkWorkEndpoint('row key comparison');
|
|
24
|
+
observeTableCells();
|
|
25
|
+
let constant = true;
|
|
26
|
+
for (const key in lin) {
|
|
27
|
+
checkWorkEndpoint('row key coefficient');
|
|
28
|
+
observeTableCells(key.length + 1);
|
|
29
|
+
if (!Number.isSafeInteger(lin[key]))
|
|
30
|
+
return undefined;
|
|
31
|
+
if (key !== '1')
|
|
32
|
+
constant = false;
|
|
33
|
+
}
|
|
34
|
+
if (constant)
|
|
35
|
+
return (lin['1'] ?? 0) <= 0;
|
|
36
|
+
const direct = path.get(canon(lin))?.holds;
|
|
37
|
+
if (direct !== undefined)
|
|
38
|
+
return direct;
|
|
39
|
+
const flipped = path.get(canonFlip(lin))?.holds;
|
|
40
|
+
return flipped === undefined ? undefined : !flipped;
|
|
41
|
+
}
|
|
42
|
+
function sameKey(p, q, path) {
|
|
43
|
+
const zero = (a, b) => { const d = rowSub(a, b, 'row-key:subtract'); return decided(d, path) === true && decided(rowScale(d, -1, 'row-key:flip'), path) === true; };
|
|
44
|
+
if (p.key && q.key)
|
|
45
|
+
return zero(p.key, q.key);
|
|
46
|
+
return !!p.keys && !!q.keys && p.keys.length === q.keys.length && p.keys.every((a, i) => zero(a, q.keys[i]));
|
|
47
|
+
}
|
|
48
|
+
export function budgetedLeafRows(goal, path) {
|
|
49
|
+
return withTableAdmission(() => budgetedLeafRowsIn(goal, path));
|
|
50
|
+
}
|
|
51
|
+
function budgetedLeafRowsIn(goal, path) {
|
|
52
|
+
let byHyp = seenFacts.get(goal);
|
|
53
|
+
if (!byHyp)
|
|
54
|
+
seenFacts.set(goal, (byHyp = new Map()));
|
|
55
|
+
const rows = [];
|
|
56
|
+
// Own the coefficient plan and start each output before materializing it.
|
|
57
|
+
// Failed discovery/emission stays charged; no completed-row post-observer.
|
|
58
|
+
const put = (row) => { checkWorkEndpoint('row append'); rows.push({ ...row, lin: rowCopy(row.lin, 'proposedRows:copy') }); checkWorkEndpoint('row appended'); };
|
|
59
|
+
let atom = 0;
|
|
60
|
+
for (const a of path.values())
|
|
61
|
+
put({ lin: a.holds ? a.lin : rowAdd(rowVariable('1', 1, 'proposedRows:one'), rowScale(a.lin, -1, 'proposedRows:negate'), 'proposedRows:flip'), label: '', src: { atom: atom++ } });
|
|
62
|
+
for (const [i, h] of goal.hyps.entries()) {
|
|
63
|
+
checkWorkEndpoint('row hypothesis entry');
|
|
64
|
+
let seen = byHyp.get(h);
|
|
65
|
+
if (!seen)
|
|
66
|
+
byHyp.set(h, (seen = {}));
|
|
67
|
+
for (const lin of reusing(seen, path, p => proposedFacts(h, p)))
|
|
68
|
+
put({ lin, label: '', src: { fact: i } });
|
|
69
|
+
}
|
|
70
|
+
const names = new Set();
|
|
71
|
+
for (const row of rows)
|
|
72
|
+
visitLinearCells(row.lin, key => { if (key !== '1')
|
|
73
|
+
names.add(key); }, 'proposedRows:names');
|
|
74
|
+
const cells = workMap(workFilter(workSetArray(names, 'proposedRows:names-copy'), isCell, 'proposedRows:cell-filter'), name => { checkWorkEndpoint('row cell'); return { name, ...cellParts(name) }; }, 'proposedRows:cell-parts');
|
|
75
|
+
for (let i = 0; i < cells.length; i++)
|
|
76
|
+
for (let j = i + 1; j < cells.length; j++) {
|
|
77
|
+
const p = cells[i], q = cells[j];
|
|
78
|
+
checkWorkEndpoint('row cell pair');
|
|
79
|
+
observeTableCells();
|
|
80
|
+
if (p.map !== q.map || !sameKey(p, q, path))
|
|
81
|
+
continue;
|
|
82
|
+
const pr = rowVariable(p.name, 1, 'proposedRows:pair-p'), qr = rowVariable(q.name, 1, 'proposedRows:pair-q');
|
|
83
|
+
put({ lin: rowSub(pr, qr, 'proposedRows:pair-left'), label: '', src: { pair: [p.name, q.name] } });
|
|
84
|
+
put({ lin: rowSub(qr, pr, 'proposedRows:pair-right'), label: '', src: { pair: [p.name, q.name] } });
|
|
85
|
+
}
|
|
86
|
+
const seen = new Set(), todo = workFilter(workSetArray(names, 'proposedRows:todo-copy'), n => n.startsWith('⟦'), 'proposedRows:todo-filter');
|
|
87
|
+
while (todo.length) {
|
|
88
|
+
checkWorkEndpoint('row term');
|
|
89
|
+
const name = todo.pop();
|
|
90
|
+
if (seen.has(name))
|
|
91
|
+
continue;
|
|
92
|
+
seen.add(name);
|
|
93
|
+
for (const lin of termRows(name, path)) {
|
|
94
|
+
put({ lin, label: '', src: { term: name } });
|
|
95
|
+
visitLinearCells(lin, key => { if (key !== '1') {
|
|
96
|
+
names.add(key);
|
|
97
|
+
if (key.startsWith('⟦') && !seen.has(key))
|
|
98
|
+
todo.push(key);
|
|
99
|
+
} }, 'proposedRows:term-names');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
for (const name of names)
|
|
103
|
+
put({ lin: rowVariable(name, -1, 'proposedRows:natural'), label: '', src: { nat: name } });
|
|
104
|
+
checkWorkEndpoint('row completion');
|
|
105
|
+
return rows;
|
|
106
|
+
}
|
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
import { type Law, type Machine } from './machine.js';
|
|
2
|
-
export
|
|
2
|
+
export type QuorumLawProvenance = {
|
|
3
|
+
kind: 'stored-row-guard';
|
|
4
|
+
formula: string;
|
|
5
|
+
guard: string;
|
|
6
|
+
guardFormula: string;
|
|
7
|
+
membershipMap: string;
|
|
8
|
+
rowInput: string;
|
|
9
|
+
rowCount: string;
|
|
10
|
+
requestSet: string;
|
|
11
|
+
width: number;
|
|
12
|
+
halves: string[];
|
|
13
|
+
disabled: boolean;
|
|
14
|
+
twins: {
|
|
15
|
+
request: string;
|
|
16
|
+
row: string;
|
|
17
|
+
key: string;
|
|
18
|
+
}[];
|
|
19
|
+
definitions: Record<string, string>;
|
|
20
|
+
};
|
|
21
|
+
export declare function quorumLawProvenance(law: Law): Readonly<QuorumLawProvenance> | undefined;
|
|
22
|
+
export declare function quorumLaws(m: Machine, provenance?: boolean): {
|
|
3
23
|
counts: NonNullable<Machine['counts']>;
|
|
4
24
|
laws: Law[];
|
|
5
25
|
};
|
package/dist/core/quorum-laws.js
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
// an action's quantified guard. No protocol vocabulary or facts live here.
|
|
3
3
|
import { all, any, atMost, get, ite, less, n, not, plus, same, times, walk, x } from "./machine.js";
|
|
4
4
|
import { substC, substE } from "../kernel/kernel.js";
|
|
5
|
+
import { env } from "./solver.js";
|
|
6
|
+
const origins = new WeakMap();
|
|
7
|
+
export function quorumLawProvenance(law) {
|
|
8
|
+
const origin = origins.get(law);
|
|
9
|
+
return origin?.formula === JSON.stringify(law.holds) ? origin : undefined;
|
|
10
|
+
}
|
|
5
11
|
const text = (t) => JSON.stringify(t);
|
|
6
12
|
const eq = (a, b) => text(a) === text(b);
|
|
7
13
|
const conjs = (c) => c.op === 'and' ? c.xs.flatMap(conjs) : [c];
|
|
@@ -43,7 +49,7 @@ function rowOf(m, name) {
|
|
|
43
49
|
return undefined;
|
|
44
50
|
return { name, map: cell.map, input: k.a.a.name, base: k.a.k, below: d.below, key: d.key, body };
|
|
45
51
|
}
|
|
46
|
-
export function quorumLaws(m) {
|
|
52
|
+
export function quorumLaws(m, provenance = env.GDP_COUNT_LIFTED === '1') {
|
|
47
53
|
const counts = {}, laws = [];
|
|
48
54
|
if (!m.assume || !m.counts || !m.inputMaps?.length)
|
|
49
55
|
return { counts, laws };
|
|
@@ -220,8 +226,26 @@ export function quorumLaws(m) {
|
|
|
220
226
|
if (leaks)
|
|
221
227
|
continue;
|
|
222
228
|
const base = [not(all(domain(a), domain(b), ...constraints)), lifted];
|
|
223
|
-
const add = (suffix, extra) => {
|
|
224
|
-
laws.
|
|
229
|
+
const add = (suffix, extra) => {
|
|
230
|
+
if (laws.length >= 32)
|
|
231
|
+
return;
|
|
232
|
+
const law = { name: `${row.name}: stored guard ${action}/${set}${suffix}`, forall: a, keys: [b, ...free.map((_, i) => i ? w : u)], holds: any(...base, ...extra) };
|
|
233
|
+
// Metadata builds charged AST nodes too; it must be a no-op while the route is off.
|
|
234
|
+
if (provenance) {
|
|
235
|
+
const rowRead = rowSize(a), twins = [...mapped].flatMap(([request, value]) => {
|
|
236
|
+
if (!contains(comparison, { op: 'get', map: request, key: n(0) }))
|
|
237
|
+
return [];
|
|
238
|
+
const read = value(a, b);
|
|
239
|
+
return read.op === 'get' ? [{ request, row: read.map, key: text(read.key) }] : [];
|
|
240
|
+
});
|
|
241
|
+
const used = new Set();
|
|
242
|
+
walk(law.holds, node => { if (node.op === 'get')
|
|
243
|
+
used.add(node.map); });
|
|
244
|
+
if (rowRead.op === 'get')
|
|
245
|
+
origins.set(law, { kind: 'stored-row-guard', formula: text(law.holds), guard: action, guardFormula: text(guard), membershipMap: row.map, rowInput: row.input, rowCount: rowRead.map, requestSet: carried, width: row.base, halves: free.map((_, i) => i ? w : u), disabled: extra.length > 0, twins, definitions: Object.fromEntries([...used].flatMap(name => { const d = counts[name] ?? m.counts[name]; return d ? [[name, text(d)]] : []; })) });
|
|
246
|
+
}
|
|
247
|
+
laws.push(law);
|
|
248
|
+
};
|
|
225
249
|
add('', []);
|
|
226
250
|
for (const [i, atom] of noQuorums.entries())
|
|
227
251
|
add(` or disabled/${i}`, [atom(a), atom(b)]);
|
package/dist/core/rationals.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { searchNow as countedSearchNow } from "./wall.js";
|
|
1
2
|
// Rules over the rationals: params, inputs and state whose values are exact rationals (fees in fractions, tokens that
|
|
2
3
|
// refill by a fraction, ledgers in decimals), laws over them proven by linear arithmetic over ℚ, a decidable theory
|
|
3
4
|
// whose refutations are Farkas certificates. Nothing is scaled or encoded: 0.1 is 1/10, a third is 1/3, and the
|
|
@@ -233,7 +234,7 @@ function unrolled(m, d) {
|
|
|
233
234
|
}
|
|
234
235
|
// A run from the start that breaks a law, within `depth` requests: each unrolled goal decided over ℚ (exactly, so a
|
|
235
236
|
// model is a run), the run replayed by the interpreter, which must break the law too.
|
|
236
|
-
export function refuteQ(m, laws, depth = 3, until =
|
|
237
|
+
export function refuteQ(m, laws, depth = 3, until = countedSearchNow() + 2_000) {
|
|
237
238
|
const run = interpretQ(m);
|
|
238
239
|
for (let d = 0; d <= depth; d++) {
|
|
239
240
|
const { hyps, at } = unrolled(m, d);
|
|
@@ -258,7 +259,7 @@ export function refuteQ(m, laws, depth = 3, until = performance.now() + 2_000) {
|
|
|
258
259
|
}
|
|
259
260
|
// Each law by induction: its start and step goals grown by the search, the trees checked by the kernel.
|
|
260
261
|
export function proveQMachine(m, laws, opts = {}) {
|
|
261
|
-
const until =
|
|
262
|
+
const until = countedSearchNow() + (opts.ms ?? 20_000), trees = {};
|
|
262
263
|
for (const law of laws) {
|
|
263
264
|
const goals = qObligations(m, laws, law), got = {};
|
|
264
265
|
for (const which of ['start', 'step']) {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Law, type Machine, type State } from './machine.js';
|
|
2
|
+
import { type RejectionStage } from './rejection-stage.js';
|
|
3
|
+
export type RejectionPhase = {
|
|
4
|
+
kind: string;
|
|
5
|
+
used: number;
|
|
6
|
+
complete: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare function rejectionStage(source: Machine, m: Machine, caller: readonly Law[], candidates: readonly Law[], allowance: number, options?: {
|
|
9
|
+
stage?: RejectionStage;
|
|
10
|
+
phases?: RejectionPhase[];
|
|
11
|
+
}): {
|
|
12
|
+
phases: RejectionPhase[];
|
|
13
|
+
screenWork: {
|
|
14
|
+
used: number;
|
|
15
|
+
limit: number;
|
|
16
|
+
};
|
|
17
|
+
active: () => Law[];
|
|
18
|
+
addCandidates: (laws: readonly Law[]) => Law[];
|
|
19
|
+
reachable: (params0: {
|
|
20
|
+
[x: string]: number;
|
|
21
|
+
}, requests0: readonly import("./machine.ts").Request[]) => import("./rejection-stage.ts").RejectionOutcome;
|
|
22
|
+
relative: (params0: {
|
|
23
|
+
[x: string]: number;
|
|
24
|
+
}, pre0: State, request0: import("./machine.ts").Request) => import("./rejection-stage.ts").RejectionOutcome;
|
|
25
|
+
model: (law: Law, witness: Record<string, number>) => import("./rejection-stage.ts").RejectionOutcome;
|
|
26
|
+
restored: () => Law[];
|
|
27
|
+
safety: () => "weak" | "broken" | undefined;
|
|
28
|
+
within: <T>(body: () => T) => T | undefined;
|
|
29
|
+
work: () => {
|
|
30
|
+
used: number;
|
|
31
|
+
limit: number;
|
|
32
|
+
};
|
|
33
|
+
evidence: () => import("./rejection-stage.ts").RejectionEvidence[];
|
|
34
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { finiteTinyHoudini } from "./finite-houdini.js";
|
|
2
|
+
import { createRejectionStage } from "./rejection-stage.js";
|
|
3
|
+
import { checkBudget, clock, fullRate, fullWork } from "../kernel/prove.js";
|
|
4
|
+
import { countGenerationPhase } from "./count-generation-phase.js";
|
|
5
|
+
export function rejectionStage(source, m, caller, candidates, allowance, options = {}) {
|
|
6
|
+
const stage = options.stage ?? createRejectionStage(source, m, caller, candidates, allowance), phases = options.phases ?? [];
|
|
7
|
+
const until = clock() + allowance, started = fullWork(), params = Object.fromEntries(source.params.map(name => [name, 2]));
|
|
8
|
+
let complete = false, previous;
|
|
9
|
+
const dropped = new Map();
|
|
10
|
+
try {
|
|
11
|
+
const run = countGenerationPhase(until, () => {
|
|
12
|
+
finiteTinyHoudini(source, m, [...caller], stage.active().filter(law => !caller.includes(law)), [params], {
|
|
13
|
+
valueDomain: [0, 1], wallMs: Math.max(0, allowance),
|
|
14
|
+
onDrop: drop => {
|
|
15
|
+
dropped.set(drop.round, (dropped.get(drop.round) ?? 0) + 1);
|
|
16
|
+
// Every rejection still comes from one full-family source replay. Merely
|
|
17
|
+
// finding another law false in the same shared transition adds no replay.
|
|
18
|
+
if (previous?.params === drop.params && previous.pre === drop.pre && previous.request === drop.request)
|
|
19
|
+
return;
|
|
20
|
+
previous = { params: drop.params, pre: drop.pre, request: drop.request };
|
|
21
|
+
stage.relative(drop.params, drop.pre, drop.request);
|
|
22
|
+
},
|
|
23
|
+
onTiny: (round, stats) => { complete = stats.completed && !stats.timedOut && (dropped.get(round) ?? 0) === 0; },
|
|
24
|
+
onFinish: result => { if (result.timedOut)
|
|
25
|
+
complete = false; },
|
|
26
|
+
});
|
|
27
|
+
checkBudget('relative screen completion');
|
|
28
|
+
});
|
|
29
|
+
if (!run.complete)
|
|
30
|
+
complete = false;
|
|
31
|
+
}
|
|
32
|
+
finally {
|
|
33
|
+
phases.push({ kind: 'relative-two-server', used: (fullWork() - started) / fullRate, complete });
|
|
34
|
+
}
|
|
35
|
+
return { ...stage, phases, screenWork: { used: (fullWork() - started) / fullRate, limit: allowance } };
|
|
36
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type Law, type Machine, type Request, type State } from './machine.js';
|
|
2
|
+
type Params = Record<string, number>;
|
|
3
|
+
export type RejectionEvidence = {
|
|
4
|
+
kind: 'reachable';
|
|
5
|
+
law: Law;
|
|
6
|
+
params: Params;
|
|
7
|
+
requests: Request[];
|
|
8
|
+
post: State;
|
|
9
|
+
} | {
|
|
10
|
+
kind: 'relative';
|
|
11
|
+
law: Law;
|
|
12
|
+
params: Params;
|
|
13
|
+
pre: State;
|
|
14
|
+
request: Request;
|
|
15
|
+
post: State;
|
|
16
|
+
};
|
|
17
|
+
export type RejectionOutcome = {
|
|
18
|
+
status: 'ignored' | 'rejected' | 'broken' | 'weak';
|
|
19
|
+
rejected: Law[];
|
|
20
|
+
safety: Law[];
|
|
21
|
+
};
|
|
22
|
+
export declare function createRejectionStage(source: Machine, m: Machine, caller: readonly Law[], candidates: readonly Law[], allowance: number): {
|
|
23
|
+
active: () => Law[];
|
|
24
|
+
addCandidates: (laws: readonly Law[]) => Law[];
|
|
25
|
+
reachable: (params0: Params, requests0: readonly Request[]) => RejectionOutcome;
|
|
26
|
+
relative: (params0: Params, pre0: State, request0: Request) => RejectionOutcome;
|
|
27
|
+
model: (law: Law, witness: Record<string, number>) => RejectionOutcome;
|
|
28
|
+
restored: () => Law[];
|
|
29
|
+
safety: () => "weak" | "broken" | undefined;
|
|
30
|
+
within: <T>(body: () => T) => T | undefined;
|
|
31
|
+
work: () => {
|
|
32
|
+
used: number;
|
|
33
|
+
limit: number;
|
|
34
|
+
};
|
|
35
|
+
evidence: () => RejectionEvidence[];
|
|
36
|
+
};
|
|
37
|
+
export type RejectionStage = ReturnType<typeof createRejectionStage>;
|
|
38
|
+
export declare function rejectionFamily(stage: RejectionStage, initial: readonly Law[]): Law[];
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// Untrusted candidate policy. Only original-interpreter replay justifies a drop;
|
|
2
|
+
// none of this ledger is proof admission.
|
|
3
|
+
import { interpret } from "./machine.js";
|
|
4
|
+
import { finiteEvaluator } from "./finite-houdini.js";
|
|
5
|
+
import { finiteModelChecker } from "./finite-model.js";
|
|
6
|
+
import { BudgetExpired, budgetEnd, checkBudget, fullRate, fullWork, remainingWork, withBudget } from "../kernel/prove.js";
|
|
7
|
+
import { WallExpired } from "./wall.js";
|
|
8
|
+
const none = () => ({ status: 'ignored', rejected: [], safety: [] });
|
|
9
|
+
const declarations = (m) => [...(m.pre ? [{ name: 'rejection parameter precondition', holds: m.pre }] : []), ...m.facts ?? []];
|
|
10
|
+
export function createRejectionStage(source, m, caller, candidates, allowance) {
|
|
11
|
+
if (!Number.isFinite(allowance) || allowance < 0 || !Number.isFinite(allowance * fullRate))
|
|
12
|
+
throw new RangeError('rejection allowance must be finite and nonnegative');
|
|
13
|
+
const all = [...new Set([...caller, ...candidates])], protectedLaws = new Set(caller), records = new Map(), restored = new Set(), start = fullWork(), limit = allowance * fullRate;
|
|
14
|
+
let safetyStatus;
|
|
15
|
+
const evaluate = finiteEvaluator(m), sourceEvaluate = finiteEvaluator(source), facts = declarations(m), sourceFacts = declarations(source), run = interpret(source), complete = finiteModelChecker(m);
|
|
16
|
+
let charged = fullWork() - start, activeAt, exhausted = false, revision = 0;
|
|
17
|
+
let commits = [];
|
|
18
|
+
const active = () => all.filter(l => !records.has(l)), spent = () => charged + (activeAt === undefined ? 0 : fullWork() - activeAt);
|
|
19
|
+
function bounded(fallback, body) {
|
|
20
|
+
// Even an exhausted local stage must not hide cancellation of its parent.
|
|
21
|
+
checkBudget('rejection parent');
|
|
22
|
+
if (exhausted || spent() >= limit)
|
|
23
|
+
return fallback;
|
|
24
|
+
if (activeAt !== undefined) {
|
|
25
|
+
checkBudget('nested rejection entry');
|
|
26
|
+
const out = body();
|
|
27
|
+
checkBudget('nested rejection completion');
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
// A nonrestricting scope exposes the effective inherited endpoint, including
|
|
31
|
+
// withWork's otherwise private cap. This also disambiguates an exact tie:
|
|
32
|
+
// a refusal shared with the parent must propagate, not become local expiry.
|
|
33
|
+
const parentEnd = withBudget(Number.MAX_VALUE, () => budgetEnd());
|
|
34
|
+
const before = fullWork(), localEnd = (before + Math.max(0, limit - charged)) / fullRate;
|
|
35
|
+
let localRefusal = false, installedEnd;
|
|
36
|
+
activeAt = before;
|
|
37
|
+
commits = [];
|
|
38
|
+
try {
|
|
39
|
+
const out = withBudget(Math.max(0, limit - charged), () => {
|
|
40
|
+
installedEnd = budgetEnd();
|
|
41
|
+
try {
|
|
42
|
+
checkBudget('rejection evidence');
|
|
43
|
+
return body();
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
// Admission can refuse an expensive primitive BEFORE charging it. Read
|
|
47
|
+
// the actual installed endpoint and refusal marker while still inside I.
|
|
48
|
+
if (error instanceof BudgetExpired && budgetEnd() === localEnd && localEnd < parentEnd && remainingWork() === 0)
|
|
49
|
+
localRefusal = true;
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
// withBudget's completion check has succeeded. Publication itself cannot
|
|
54
|
+
// evaluate a law, replay a step, clone user data, or incur a budget charge.
|
|
55
|
+
for (const commit of commits)
|
|
56
|
+
commit();
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
checkBudget('rejection parent completion');
|
|
61
|
+
if (error instanceof BudgetExpired && (localRefusal || (installedEnd === localEnd && localEnd < parentEnd && spent() >= limit))) {
|
|
62
|
+
exhausted = true;
|
|
63
|
+
return fallback;
|
|
64
|
+
}
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
commits = [];
|
|
69
|
+
charged += fullWork() - before;
|
|
70
|
+
activeAt = undefined;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function enabled(params, pre, request) {
|
|
74
|
+
try {
|
|
75
|
+
return run.step(params, pre, request);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
if (error instanceof BudgetExpired || error instanceof WallExpired)
|
|
79
|
+
throw error;
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const declared = (params, pre) => sourceFacts.every(l => sourceEvaluate(l, params, pre) === true) && facts.every(l => evaluate(l, params, pre) === true);
|
|
84
|
+
function publish(out, evidence, version) {
|
|
85
|
+
const status = out.status;
|
|
86
|
+
commits.push(() => {
|
|
87
|
+
if (status === 'broken')
|
|
88
|
+
safetyStatus = 'broken';
|
|
89
|
+
else if (status === 'weak')
|
|
90
|
+
safetyStatus ??= 'weak';
|
|
91
|
+
// An enclosing callback may expand the family before it returns. Never
|
|
92
|
+
// publish a relative witness validated against that obsolete family.
|
|
93
|
+
for (const [law, witness] of evidence)
|
|
94
|
+
if (witness.kind === 'reachable' || version === revision)
|
|
95
|
+
records.set(law, witness);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function reachable(params0, requests0) {
|
|
99
|
+
return bounded(none(), () => {
|
|
100
|
+
const out = none(), evidence = new Map(), params = structuredClone(params0), requests = structuredClone([...requests0]);
|
|
101
|
+
let post;
|
|
102
|
+
try {
|
|
103
|
+
post = run.init(params);
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
if (error instanceof BudgetExpired || error instanceof WallExpired)
|
|
107
|
+
throw error;
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
if (!declared(params, post))
|
|
111
|
+
return out;
|
|
112
|
+
for (const request of requests) {
|
|
113
|
+
const next = enabled(params, post, request);
|
|
114
|
+
if (!next || !declared(params, next))
|
|
115
|
+
return out;
|
|
116
|
+
post = next;
|
|
117
|
+
}
|
|
118
|
+
out.safety = caller.filter(l => evaluate(l, params, post) === false);
|
|
119
|
+
if (out.safety.length)
|
|
120
|
+
out.status = 'broken';
|
|
121
|
+
else
|
|
122
|
+
for (const law of all) {
|
|
123
|
+
if (protectedLaws.has(law) || evaluate(law, params, post) !== false)
|
|
124
|
+
continue;
|
|
125
|
+
evidence.set(law, structuredClone({ kind: 'reachable', law, params, requests, post }));
|
|
126
|
+
out.rejected.push(law);
|
|
127
|
+
out.status = 'rejected';
|
|
128
|
+
}
|
|
129
|
+
publish(out, evidence, revision);
|
|
130
|
+
return out;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function relative(params0, pre0, request0) {
|
|
134
|
+
return bounded(none(), () => {
|
|
135
|
+
const out = none(), evidence = new Map(), params = structuredClone(params0), pre = structuredClone(pre0), request = structuredClone(request0), family = active(), version = revision;
|
|
136
|
+
if (!declared(params, pre) || !family.every(l => evaluate(l, params, pre) === true))
|
|
137
|
+
return out;
|
|
138
|
+
const post = enabled(params, pre, request);
|
|
139
|
+
if (!post)
|
|
140
|
+
return out;
|
|
141
|
+
out.safety = caller.filter(l => evaluate(l, params, post) === false);
|
|
142
|
+
if (out.safety.length)
|
|
143
|
+
out.status = 'weak';
|
|
144
|
+
else
|
|
145
|
+
for (const law of family) {
|
|
146
|
+
if (protectedLaws.has(law) || evaluate(law, params, post) !== false)
|
|
147
|
+
continue;
|
|
148
|
+
evidence.set(law, structuredClone({ kind: 'relative', law, params, pre, request, post }));
|
|
149
|
+
out.rejected.push(law);
|
|
150
|
+
out.status = 'rejected';
|
|
151
|
+
}
|
|
152
|
+
publish(out, evidence, version);
|
|
153
|
+
return out;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function addCandidates(laws) {
|
|
157
|
+
const added = [...new Set(laws)].filter(law => !all.includes(law));
|
|
158
|
+
if (!added.length)
|
|
159
|
+
return [];
|
|
160
|
+
all.push(...added);
|
|
161
|
+
revision++;
|
|
162
|
+
const revived = [];
|
|
163
|
+
// Restoration is monotone, not a publication transaction. On local expiry
|
|
164
|
+
// every unvalidated relative witness is removed, including cascades. Outer
|
|
165
|
+
// cancellation also restores conservatively before propagating; never roll
|
|
166
|
+
// back to evidence for a smaller, stale family.
|
|
167
|
+
try {
|
|
168
|
+
for (let changed = true; changed;) {
|
|
169
|
+
changed = false;
|
|
170
|
+
const family = active();
|
|
171
|
+
for (const [law, witness] of records) {
|
|
172
|
+
if (witness.kind === 'reachable')
|
|
173
|
+
continue;
|
|
174
|
+
const valid = bounded(false, () => declared(witness.params, witness.pre) && family.every(l => evaluate(l, witness.params, witness.pre) === true));
|
|
175
|
+
if (!valid) {
|
|
176
|
+
records.delete(law);
|
|
177
|
+
restored.add(law);
|
|
178
|
+
revived.push(law);
|
|
179
|
+
changed = true;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
for (const [law, witness] of records)
|
|
186
|
+
if (witness.kind === 'relative') {
|
|
187
|
+
records.delete(law);
|
|
188
|
+
restored.add(law);
|
|
189
|
+
}
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
return revived;
|
|
193
|
+
}
|
|
194
|
+
function model(law, witness) {
|
|
195
|
+
return bounded(none(), () => { const candidate = complete(active(), law, witness); return candidate.genuine ? relative(candidate.params, candidate.pre, candidate.request) : none(); });
|
|
196
|
+
}
|
|
197
|
+
return { active, addCandidates, reachable, relative, model, restored: () => active().filter(law => restored.has(law)), safety: () => safetyStatus, within: (body) => bounded(undefined, body), work: () => ({ used: spent() / fullRate, limit: allowance }), evidence: () => [...records.values()].map(record => structuredClone(record)) };
|
|
198
|
+
}
|
|
199
|
+
// A restored helper belongs to EVERY later proof context, not only the call
|
|
200
|
+
// which enlarged the ledger. A subsequent validated rejection may omit it.
|
|
201
|
+
export function rejectionFamily(stage, initial) {
|
|
202
|
+
stage.addCandidates(initial);
|
|
203
|
+
const requested = new Set([...initial, ...stage.restored()]);
|
|
204
|
+
return stage.active().filter(law => requested.has(law));
|
|
205
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Machine, type Request } from './machine.js';
|
|
2
|
+
export type RequestQuotient = {
|
|
3
|
+
classes: Uint32Array;
|
|
4
|
+
count: number;
|
|
5
|
+
selector?: string;
|
|
6
|
+
reads: ReadonlyMap<number | undefined, readonly string[]>;
|
|
7
|
+
};
|
|
8
|
+
export declare function requestQuotient(m: Machine, requests: readonly Request[]): RequestQuotient | undefined;
|