gdp-wired 0.48.0 → 0.50.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 +6 -2
- package/dist/core/bmc.js +10 -7
- package/dist/core/candidate-seeds.d.ts +25 -0
- package/dist/core/candidate-seeds.js +90 -0
- package/dist/core/check.js +7 -2
- package/dist/core/cli.js +3 -0
- 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.d.ts +1 -0
- package/dist/core/count-support.js +26 -4
- 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/counted-candidate-seeds.d.ts +12 -0
- package/dist/core/counted-candidate-seeds.js +31 -0
- package/dist/core/counts.d.ts +37 -13
- package/dist/core/counts.js +999 -129
- 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 +32 -2
- package/dist/core/dsl.js +202 -64
- 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 +53 -10
- package/dist/core/field-laws.d.ts +3 -1
- package/dist/core/field-laws.js +159 -3
- 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 +49 -33
- package/dist/core/kind.js +2 -1
- package/dist/core/lemma-cuts.js +11 -10
- package/dist/core/lift-cli.d.ts +11 -0
- package/dist/core/lift-cli.js +113 -0
- 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/proof-output.d.ts +53 -0
- package/dist/core/proof-output.js +38 -0
- 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 +80 -17
- 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/function-instances.d.ts +45 -0
- package/dist/kernel/function-instances.js +460 -0
- package/dist/kernel/kernel.d.ts +47 -1
- package/dist/kernel/kernel.js +417 -68
- package/dist/kernel/prove.d.ts +61 -6
- package/dist/kernel/prove.js +625 -205
- 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/axiom-audit.d.ts +11 -0
- package/dist/lean-kernel/axiom-audit.js +50 -0
- package/dist/lean-kernel/emit.d.ts +34 -3
- package/dist/lean-kernel/emit.js +215 -28
- 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/legacy-family-order.d.ts +1 -0
- package/dist/lean-kernel/legacy-family-order.js +26 -0
- package/dist/lean-kernel/library.js +25 -3
- package/dist/lean-kernel/lift/counted-source-data.d.ts +7 -0
- package/dist/lean-kernel/lift/counted-source-data.js +78 -0
- package/dist/lean-kernel/lift/index.d.ts +82 -0
- package/dist/lean-kernel/lift/index.js +116 -0
- package/dist/lean-kernel/lift/project.d.ts +4 -0
- package/dist/lean-kernel/lift/project.js +15 -0
- package/dist/lean-kernel/lift/proof-capture.d.ts +104 -0
- package/dist/lean-kernel/lift/proof-capture.js +216 -0
- package/dist/lean-kernel/lift/proof-codec.d.ts +28 -0
- package/dist/lean-kernel/lift/proof-codec.js +299 -0
- package/dist/lean-kernel/lift/proof-counted-source.d.ts +16 -0
- package/dist/lean-kernel/lift/proof-counted-source.js +68 -0
- package/dist/lean-kernel/lift/proof-frontier.d.ts +19 -0
- package/dist/lean-kernel/lift/proof-frontier.js +153 -0
- package/dist/lean-kernel/lift/proof-graph.d.ts +17 -0
- package/dist/lean-kernel/lift/proof-graph.js +130 -0
- package/dist/lean-kernel/lift/proof-parts.d.ts +29 -0
- package/dist/lean-kernel/lift/proof-parts.js +131 -0
- package/dist/lean-kernel/lift/proof-prelude.d.ts +2 -0
- package/dist/lean-kernel/lift/proof-prelude.js +38 -0
- package/dist/lean-kernel/lift/proof-witness.d.ts +30 -0
- package/dist/lean-kernel/lift/proof-witness.js +283 -0
- package/dist/lean-kernel/lift/shape.d.ts +5 -0
- package/dist/lean-kernel/lift/shape.js +57 -0
- package/dist/lean-kernel/lift/source-projection.d.ts +16 -0
- package/dist/lean-kernel/lift/source-projection.js +81 -0
- package/dist/lean-kernel/lift/source.d.ts +23 -0
- package/dist/lean-kernel/lift/source.js +111 -0
- package/dist/lean-kernel/lift/witness-alpha.d.ts +9 -0
- package/dist/lean-kernel/lift/witness-alpha.js +31 -0
- package/dist/lean-kernel/lift-legacy.d.ts +58 -0
- package/dist/lean-kernel/lift-legacy.js +84 -0
- package/dist/lean-kernel/lift-names.d.ts +22 -0
- package/dist/lean-kernel/lift-names.js +36 -0
- package/dist/lean-kernel/lift-simulation/index.d.ts +29 -0
- package/dist/lean-kernel/lift-simulation/index.js +352 -0
- package/dist/lean-kernel/lift-simulation/shape.d.ts +41 -0
- package/dist/lean-kernel/lift-simulation/shape.js +173 -0
- package/dist/lean-kernel/lift-special/index.d.ts +36 -0
- package/dist/lean-kernel/lift-special/index.js +241 -0
- package/dist/lean-kernel/lift-special/structural.d.ts +25 -0
- package/dist/lean-kernel/lift-special/structural.js +126 -0
- package/dist/lean-kernel/lift-typed/index.d.ts +35 -0
- package/dist/lean-kernel/lift-typed/index.js +256 -0
- package/dist/lean-kernel/lift-typed/roles.d.ts +17 -0
- package/dist/lean-kernel/lift-typed/roles.js +170 -0
- package/dist/lean-kernel/lift-typed/shape.d.ts +1 -0
- package/dist/lean-kernel/lift-typed/shape.js +12 -0
- package/dist/lean-kernel/lift.d.ts +30 -0
- package/dist/lean-kernel/lift.js +97 -0
- package/package.json +5 -1
package/dist/core/quorum-laws.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
// Untrusted quorum candidates read from a stored row, a majority assumption, and
|
|
2
2
|
// an action's quantified guard. No protocol vocabulary or facts live here.
|
|
3
|
-
import { all, any, atMost, get, ite, less, n, not, plus, same, times, walk, x } from "./machine.js";
|
|
3
|
+
import { all, any, atMost, get, ite, less, n, not, plus, same, times, tuple, 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];
|
|
@@ -37,13 +43,15 @@ function rowOf(m, name) {
|
|
|
37
43
|
if (cell?.op !== 'get' || !(cell.map in (m.maps ?? {})))
|
|
38
44
|
return undefined;
|
|
39
45
|
const k = cell.key;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
const packedRow = k.op === 'add' && k.a.op === 'mul' && k.a.k > 1 && k.a.a.op === 'var' && k.b.op === 'var' && k.b.name === d.key ? { input: k.a.a.name, base: k.a.k } : undefined;
|
|
47
|
+
const sorts = m.relations?.[cell.map];
|
|
48
|
+
const tupleRow = k.op === 'tup' && k.a.op === 'var' && k.b.op === 'var' && k.b.name === d.key && sorts?.length === 2 && sorts[0] === sorts[1] ? { input: k.a.name, base: 0 } : undefined;
|
|
49
|
+
const row = packedRow ?? tupleRow;
|
|
50
|
+
if (!row || !m.inputs.includes(row.input) || [d.j, ...m.inputs].some(v => vars(d.below).has(v)))
|
|
43
51
|
return undefined;
|
|
44
|
-
return { name, map: cell.map,
|
|
52
|
+
return { name, map: cell.map, ...row, below: d.below, key: d.key, body };
|
|
45
53
|
}
|
|
46
|
-
export function quorumLaws(m) {
|
|
54
|
+
export function quorumLaws(m, provenance = env.GDP_COUNT_LIFTED === '1') {
|
|
47
55
|
const counts = {}, laws = [];
|
|
48
56
|
if (!m.assume || !m.counts || !m.inputMaps?.length)
|
|
49
57
|
return { counts, laws };
|
|
@@ -74,21 +82,51 @@ export function quorumLaws(m) {
|
|
|
74
82
|
for (const { row, sets } of rows.values()) {
|
|
75
83
|
const rowBody = substC(row.body, sub({ [row.input]: x(j), [row.key]: x(key) }));
|
|
76
84
|
const domain = (v) => less(x(v), row.below);
|
|
77
|
-
const registry = new Map();
|
|
85
|
+
const registry = new Map(), pairCounts = new Set();
|
|
86
|
+
// A count map accepts a plain key only. Quantify a single paired natural
|
|
87
|
+
// and project its components in the law; count reads use that key directly.
|
|
88
|
+
const pairLaw = (law) => {
|
|
89
|
+
if (row.base)
|
|
90
|
+
return law;
|
|
91
|
+
const first = { op: 'proj', k: 0, a: x(a) }, second = { op: 'proj', k: 1, a: x(a) };
|
|
92
|
+
const project = substC(law.holds, sub({ [a]: first, [b]: second })), expected = tuple([first, second]);
|
|
93
|
+
let unsupported = false;
|
|
94
|
+
const plain = (t) => {
|
|
95
|
+
if (Array.isArray(t))
|
|
96
|
+
return t.map(plain);
|
|
97
|
+
if (!t || typeof t !== 'object')
|
|
98
|
+
return t;
|
|
99
|
+
const o = t;
|
|
100
|
+
if (o.op === 'get' && pairCounts.has(o.map)) {
|
|
101
|
+
if (!eq(o.key, expected)) {
|
|
102
|
+
unsupported = true;
|
|
103
|
+
return o;
|
|
104
|
+
}
|
|
105
|
+
return { ...o, key: x(a) };
|
|
106
|
+
}
|
|
107
|
+
return Object.fromEntries(Object.entries(o).map(([k, v]) => [k, plain(v)]));
|
|
108
|
+
};
|
|
109
|
+
const keys = law.keys?.filter(k => k !== b), holds = plain(project);
|
|
110
|
+
return unsupported ? undefined : { ...law, ...(keys?.length ? { keys } : { keys: undefined }), holds };
|
|
111
|
+
};
|
|
78
112
|
const normal = (c) => c.op === 'and' ? text(['and', conjs(c).map(normal).sort()]) : text(c);
|
|
79
113
|
const count = (body, pair, label) => {
|
|
114
|
+
const pairKey = (a, b) => row.base ? packed(row.base, a, b) : tuple([a, b]);
|
|
80
115
|
const id = normal(body), old = registry.get(id);
|
|
81
116
|
if (old)
|
|
82
|
-
return (a, b) => get(old.name, old.pair ?
|
|
117
|
+
return (a, b) => get(old.name, old.pair ? pairKey(x(old.swap ? b : a), x(old.swap ? a : b)) : x(a));
|
|
83
118
|
const name = fresh(`${row.name}$${label}`);
|
|
84
|
-
|
|
119
|
+
const pairBody = pair && !row.base ? substC(body, sub({ [j]: { op: 'proj', k: 0, a: x(j) }, [lo]: { op: 'proj', k: 1, a: x(j) } })) : body;
|
|
120
|
+
counts[name] = { j, key, below: row.below, body: indicator(pairBody), ...(pair && row.base ? { lo, base: row.base } : {}) };
|
|
85
121
|
registry.set(id, { name, pair, swap: false });
|
|
86
|
-
if (pair)
|
|
122
|
+
if (pair)
|
|
123
|
+
pairCounts.add(name);
|
|
124
|
+
if (pair && row.base) {
|
|
87
125
|
const swapped = normal(substC(body, sub({ [j]: x(lo), [lo]: x(j) })));
|
|
88
126
|
if (!registry.has(swapped))
|
|
89
127
|
registry.set(swapped, { name, pair, swap: true });
|
|
90
128
|
}
|
|
91
|
-
return (a, b) => get(name, pair ?
|
|
129
|
+
return (a, b) => get(name, pair ? pairKey(x(a), x(b)) : x(a));
|
|
92
130
|
};
|
|
93
131
|
let size;
|
|
94
132
|
const rowSize = (a) => (size ??= count(rowBody, false, 'row'))(a);
|
|
@@ -132,7 +170,10 @@ export function quorumLaws(m) {
|
|
|
132
170
|
continue;
|
|
133
171
|
const pair = vars(lifted).has(lo), c = count(all(rowBody, ...conjs(lifted)), pair, `${flag}$${bits}`);
|
|
134
172
|
const atom = (a, b) => atMost(times(2, c(a, b)), rowSize(a));
|
|
135
|
-
|
|
173
|
+
const law = { name: `${row.name}: no quorum ${flag}/${bits}`, forall: a, ...(pair ? { keys: [b] } : {}), holds: any(not(all(domain(a), ...(pair ? [domain(b)] : []))), atom(a, b)) };
|
|
174
|
+
const proposal = pair ? pairLaw(law) : law;
|
|
175
|
+
if (proposal)
|
|
176
|
+
laws.push(proposal);
|
|
136
177
|
if (!pair)
|
|
137
178
|
noQuorums.push(a => atom(a));
|
|
138
179
|
}
|
|
@@ -155,15 +196,17 @@ export function quorumLaws(m) {
|
|
|
155
196
|
used.add(o.map); });
|
|
156
197
|
if (used.size !== 1)
|
|
157
198
|
continue;
|
|
158
|
-
const carried = [...used][0],
|
|
199
|
+
const carried = [...used][0], column = row.base ? { op: 'sub', a: x(update.each), b: times(row.base, x(row.input)) } : { op: 'proj', k: 1, a: x(update.each) };
|
|
200
|
+
const shifted = substE(d.body, sub({ [d.key]: column }));
|
|
159
201
|
let stores = false;
|
|
160
202
|
walk(update.value, o => {
|
|
161
|
-
if (o.op === 'if' && flagsIn(o.c).has(action) && eq(o.then, shifted))
|
|
203
|
+
if (o.op === 'if' && flagsIn(o.c).has(action) && eq(o.then, shifted) && (row.base || conjs(o.c).some(c => eq(c, same({ op: 'proj', k: 0, a: x(update.each) }, x(row.input))) || eq(c, same(x(row.input), { op: 'proj', k: 0, a: x(update.each) })))))
|
|
162
204
|
stores = true;
|
|
163
205
|
// Boolean maps lower an if-tree to disjunctive membership clauses.
|
|
164
206
|
if (o.op === 'and' && shifted.op === 'if') {
|
|
165
207
|
const parts = conjs(o);
|
|
166
|
-
|
|
208
|
+
const inRow = row.base || parts.some(c => eq(c, same({ op: 'proj', k: 0, a: x(update.each) }, x(row.input))) || eq(c, same(x(row.input), { op: 'proj', k: 0, a: x(update.each) })));
|
|
209
|
+
if (inRow && parts.some(c => c.op === 'flag' && c.name === action) && parts.some(c => eq(c, shifted.c)))
|
|
167
210
|
stores = true;
|
|
168
211
|
}
|
|
169
212
|
});
|
|
@@ -220,8 +263,28 @@ export function quorumLaws(m) {
|
|
|
220
263
|
if (leaks)
|
|
221
264
|
continue;
|
|
222
265
|
const base = [not(all(domain(a), domain(b), ...constraints)), lifted];
|
|
223
|
-
const add = (suffix, extra) => {
|
|
224
|
-
laws.
|
|
266
|
+
const add = (suffix, extra) => {
|
|
267
|
+
if (laws.length >= 32)
|
|
268
|
+
return;
|
|
269
|
+
const law = { name: `${row.name}: stored guard ${action}/${set}${suffix}`, forall: a, keys: [b, ...free.map((_, i) => i ? w : u)], holds: any(...base, ...extra) };
|
|
270
|
+
// Metadata builds charged AST nodes too; it must be a no-op while the route is off.
|
|
271
|
+
if (provenance && row.base) {
|
|
272
|
+
const rowRead = rowSize(a), twins = [...mapped].flatMap(([request, value]) => {
|
|
273
|
+
if (!contains(comparison, { op: 'get', map: request, key: n(0) }))
|
|
274
|
+
return [];
|
|
275
|
+
const read = value(a, b);
|
|
276
|
+
return read.op === 'get' ? [{ request, row: read.map, key: text(read.key) }] : [];
|
|
277
|
+
});
|
|
278
|
+
const used = new Set();
|
|
279
|
+
walk(law.holds, node => { if (node.op === 'get')
|
|
280
|
+
used.add(node.map); });
|
|
281
|
+
if (rowRead.op === 'get')
|
|
282
|
+
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)]] : []; })) });
|
|
283
|
+
}
|
|
284
|
+
const proposal = pairLaw(law);
|
|
285
|
+
if (proposal)
|
|
286
|
+
laws.push(proposal);
|
|
287
|
+
};
|
|
225
288
|
add('', []);
|
|
226
289
|
for (const [i, atom] of noQuorums.entries())
|
|
227
290
|
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;
|