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
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Scheduling hints only. Every selected strategy must still prove its result.
|
|
2
|
+
import { n, same, walkOnce, x } from "./machine.js";
|
|
3
|
+
import { countFrameConditions, fixedCountFrameCase } from "./count-frames.js";
|
|
4
|
+
import { canon, cellParts, isCell, linear, substC, truth } from "../kernel/kernel.js";
|
|
5
|
+
export function classifyRowValueWrite(m, row) {
|
|
6
|
+
const choice = fixedCountFrameCase(m);
|
|
7
|
+
if (!choice)
|
|
8
|
+
return;
|
|
9
|
+
const path = new Map(countFrameConditions(choice).map(lin => [canon(lin), { lin, holds: true }]));
|
|
10
|
+
// A scheduling-only evaluation: the checked proof still receives the original machine.
|
|
11
|
+
const vars = { [choice.name]: n(choice.value) }, flags = Object.create(null);
|
|
12
|
+
for (const [name, c] of Object.entries(m.step.flags ?? {}))
|
|
13
|
+
flags[name] = c.op === 'all' ? same(x('?' + name), n(1)) : substC(c, { vars, maps: {}, flags });
|
|
14
|
+
const foreignRead = (value) => {
|
|
15
|
+
let loaded = false;
|
|
16
|
+
walkOnce(value, (node) => { if (node.op === 'get' && node.map !== row.map && Object.hasOwn(m.maps ?? {}, node.map))
|
|
17
|
+
loaded = true; });
|
|
18
|
+
return loaded;
|
|
19
|
+
};
|
|
20
|
+
// Boolean maps compile data selection into the condition of a 1/0 indicator.
|
|
21
|
+
// Ignore decided Boolean branches before looking for a data-source read.
|
|
22
|
+
const unresolvedRead = (c, match) => {
|
|
23
|
+
if (truth(c, path) !== undefined)
|
|
24
|
+
return false;
|
|
25
|
+
if (c.op === 'and' || c.op === 'or')
|
|
26
|
+
return c.xs.some(child => unresolvedRead(child, match));
|
|
27
|
+
if (c.op === 'not')
|
|
28
|
+
return unresolvedRead(c.x, match);
|
|
29
|
+
return match(c);
|
|
30
|
+
};
|
|
31
|
+
const active = (e, predicate, indicatorReads = false, indicatorMatch = foreignRead) => {
|
|
32
|
+
if (e.op !== 'if')
|
|
33
|
+
return predicate(e);
|
|
34
|
+
const condition = substC(e.c, { vars, maps: {}, flags }), known = truth(condition, path);
|
|
35
|
+
const indicator = e.then.op === 'const' && e.else.op === 'const' && e.then.value !== e.else.value && [0, 1].includes(e.then.value) && [0, 1].includes(e.else.value);
|
|
36
|
+
return indicatorReads && indicator && unresolvedRead(condition, indicatorMatch) || known !== false && active(e.then, predicate, indicatorReads, indicatorMatch) || known !== true && active(e.else, predicate, indicatorReads, indicatorMatch);
|
|
37
|
+
};
|
|
38
|
+
for (const field of row.fields) {
|
|
39
|
+
const write = m.step.maps?.[field];
|
|
40
|
+
if (!write || !('each' in write))
|
|
41
|
+
continue;
|
|
42
|
+
if (active(write.value, e => {
|
|
43
|
+
const value = linear(e, path), terms = value && Object.entries(value).filter(([name, k]) => name !== '1' && k !== 0);
|
|
44
|
+
return !!value && value['1'] === 1 && terms?.length === 1 && terms[0][1] === 1 && isCell(terms[0][0]) && cellParts(terms[0][0]).map === field;
|
|
45
|
+
}))
|
|
46
|
+
return 'replacement';
|
|
47
|
+
}
|
|
48
|
+
const write = m.step.maps?.[row.map];
|
|
49
|
+
if (!write)
|
|
50
|
+
return;
|
|
51
|
+
const carriedRead = (value) => { let carried = false; walkOnce(value, (node) => { if (node.op === 'get' && m.inputMaps?.includes(node.map))
|
|
52
|
+
carried = true; }); return carried; };
|
|
53
|
+
if (active(write.value, carriedRead, true, carriedRead))
|
|
54
|
+
return 'replacement';
|
|
55
|
+
return active(write.value, foreignRead, true) ? 'load' : undefined;
|
|
56
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Goal, type Tree } from '../kernel/kernel.js';
|
|
2
|
+
import { type Constraint } from './solver.js';
|
|
3
|
+
export type CountReindexStats = {
|
|
4
|
+
hits: number;
|
|
5
|
+
layouts: number;
|
|
6
|
+
};
|
|
7
|
+
export declare function countRowReindexer(target: Goal, options?: {
|
|
8
|
+
offsets?: boolean;
|
|
9
|
+
stats?: CountReindexStats;
|
|
10
|
+
}): (source: Goal, before: Constraint[], after: Constraint[]) => (i: number) => number | undefined;
|
|
11
|
+
export declare function operationRefutation(rows: Constraint[], operation: string): Tree | undefined;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// Untrusted row transport. Exact mode checks every chosen linear form. Offset
|
|
2
|
+
// mode lazily caches demanded indices per source/layout and verifies each reused
|
|
3
|
+
// row against its current form. The enclosing complete checker still owns acceptance.
|
|
4
|
+
import { canon } from "../kernel/kernel.js";
|
|
5
|
+
export function countRowReindexer(target, options = {}) {
|
|
6
|
+
const layouts = new WeakMap();
|
|
7
|
+
const ids = new WeakMap(), hypotheses = new Map(), sources = new WeakMap();
|
|
8
|
+
const groups = new WeakMap(), all = new WeakMap();
|
|
9
|
+
const id = (row) => { let key = ids.get(row); if (key === undefined) {
|
|
10
|
+
key = canon(row);
|
|
11
|
+
ids.set(row, key);
|
|
12
|
+
} return key; };
|
|
13
|
+
for (const [i, h] of target.hyps.entries()) {
|
|
14
|
+
const key = JSON.stringify(h);
|
|
15
|
+
if (!hypotheses.has(key))
|
|
16
|
+
hypotheses.set(key, i);
|
|
17
|
+
}
|
|
18
|
+
const tag = (row, remap) => {
|
|
19
|
+
const source = row.src;
|
|
20
|
+
if (!source)
|
|
21
|
+
return;
|
|
22
|
+
if ('fact' in source) {
|
|
23
|
+
const i = remap ? remap.get(source.fact) : source.fact;
|
|
24
|
+
return i === undefined ? undefined : 'f:' + i;
|
|
25
|
+
}
|
|
26
|
+
if ('atom' in source)
|
|
27
|
+
return 'a';
|
|
28
|
+
if ('nat' in source)
|
|
29
|
+
return 'n:' + source.nat;
|
|
30
|
+
if ('term' in source)
|
|
31
|
+
return 't:' + source.term;
|
|
32
|
+
return 'p:' + JSON.stringify(source.pair);
|
|
33
|
+
};
|
|
34
|
+
return (source, before, after) => {
|
|
35
|
+
let remap = sources.get(source);
|
|
36
|
+
if (!remap) {
|
|
37
|
+
remap = new Map();
|
|
38
|
+
for (const [i, h] of source.hyps.entries()) {
|
|
39
|
+
const found = hypotheses.get(JSON.stringify(h));
|
|
40
|
+
if (found !== undefined)
|
|
41
|
+
remap.set(i, found);
|
|
42
|
+
}
|
|
43
|
+
sources.set(source, remap);
|
|
44
|
+
}
|
|
45
|
+
const key = options.offsets ? JSON.stringify([before.map(r => tag(r, remap) ?? null), after.map(r => tag(r) ?? null)]) : undefined;
|
|
46
|
+
let cache = layouts.get(source);
|
|
47
|
+
const cached = key === undefined ? undefined : cache?.get(key);
|
|
48
|
+
if (cached && options.stats)
|
|
49
|
+
options.stats.hits++;
|
|
50
|
+
const exact = (i) => {
|
|
51
|
+
if (!Number.isSafeInteger(i) || i < 0)
|
|
52
|
+
return;
|
|
53
|
+
if (i >= before.length)
|
|
54
|
+
return i - before.length + after.length; // appended product rows
|
|
55
|
+
let byTag = groups.get(after);
|
|
56
|
+
if (!byTag) {
|
|
57
|
+
byTag = new Map();
|
|
58
|
+
after.forEach((row, index) => { const name = tag(row); if (name !== undefined) {
|
|
59
|
+
const list = byTag.get(name) ?? [];
|
|
60
|
+
list.push(index);
|
|
61
|
+
byTag.set(name, list);
|
|
62
|
+
} });
|
|
63
|
+
groups.set(after, byTag);
|
|
64
|
+
}
|
|
65
|
+
const row = before[i], key = id(row.lin), origin = tag(row, remap);
|
|
66
|
+
for (const j of origin === undefined ? [] : byTag.get(origin) ?? [])
|
|
67
|
+
if (id(after[j].lin) === key)
|
|
68
|
+
return j;
|
|
69
|
+
// A changed assumption can yield the same row through a path atom or a
|
|
70
|
+
// different hypothesis. This fallback is still exact, with no solver.
|
|
71
|
+
let fallback = all.get(after);
|
|
72
|
+
if (!fallback) {
|
|
73
|
+
fallback = new Map();
|
|
74
|
+
after.forEach((r, j) => { const k = id(r.lin); if (!fallback.has(k))
|
|
75
|
+
fallback.set(k, j); });
|
|
76
|
+
all.set(after, fallback);
|
|
77
|
+
}
|
|
78
|
+
return fallback.get(key);
|
|
79
|
+
};
|
|
80
|
+
if (key === undefined)
|
|
81
|
+
return exact;
|
|
82
|
+
const indices = cached ?? [];
|
|
83
|
+
if (!cached) {
|
|
84
|
+
if (!cache) {
|
|
85
|
+
cache = new Map();
|
|
86
|
+
layouts.set(source, cache);
|
|
87
|
+
}
|
|
88
|
+
if (cache.size >= 64)
|
|
89
|
+
cache.delete(cache.keys().next().value);
|
|
90
|
+
cache.set(key, indices);
|
|
91
|
+
if (options.stats)
|
|
92
|
+
options.stats.layouts++;
|
|
93
|
+
}
|
|
94
|
+
return (i) => {
|
|
95
|
+
if (!Number.isSafeInteger(i) || i < 0)
|
|
96
|
+
return;
|
|
97
|
+
if (i >= before.length)
|
|
98
|
+
return i - before.length + after.length;
|
|
99
|
+
const previous = indices[i];
|
|
100
|
+
if (previous !== undefined && after[previous] && id(before[i].lin) === id(after[previous].lin))
|
|
101
|
+
return previous;
|
|
102
|
+
return indices[i] = exact(i);
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
// The missing operation branches are contradictory interval bounds. Emit
|
|
107
|
+
// their two-input linear derivation directly; decline any other shape.
|
|
108
|
+
export function operationRefutation(rows, operation) {
|
|
109
|
+
let upper, lower;
|
|
110
|
+
for (const [index, row] of rows.entries()) {
|
|
111
|
+
const names = Object.keys(row.lin).filter(name => name !== '1' && row.lin[name] !== 0), constant = row.lin['1'] ?? 0;
|
|
112
|
+
if (!Number.isSafeInteger(constant))
|
|
113
|
+
continue;
|
|
114
|
+
if (!names.length && constant > 0)
|
|
115
|
+
return { leaf: [{ kind: 'input', index }] };
|
|
116
|
+
if (names.length !== 1 || names[0] !== operation)
|
|
117
|
+
continue;
|
|
118
|
+
if (row.lin[operation] === 1 && (!upper || constant > upper.constant))
|
|
119
|
+
upper = { index, constant };
|
|
120
|
+
if (row.lin[operation] === -1 && (!lower || constant > lower.constant))
|
|
121
|
+
lower = { index, constant };
|
|
122
|
+
}
|
|
123
|
+
if (upper && lower && upper.constant + lower.constant > 0)
|
|
124
|
+
return { leaf: [{ kind: 'input', index: upper.index }, { kind: 'input', index: lower.index }, { kind: 'combine', a: 0, b: 1, ma: 1, mb: 1 }] };
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Law, type Machine } from './machine.js';
|
|
2
|
+
import { type RowAgreementShape } from './row-agreement-shape.js';
|
|
3
|
+
import { type RowAgreementOptions } from './count-row-agreement.js';
|
|
4
|
+
import { type CountRequestBuilder } from './count-strategy.js';
|
|
5
|
+
export declare function rowCountSupport(m: Machine, family: Law[], target: Law, row: RowAgreementShape, until: number): {
|
|
6
|
+
options: RowAgreementOptions;
|
|
7
|
+
request: CountRequestBuilder;
|
|
8
|
+
report: unknown;
|
|
9
|
+
} | undefined;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// An untrusted strategy request: instantiate an existing PRE count law,
|
|
2
|
+
// then propose ordinary inclusion witnesses. No scalar guard is asserted.
|
|
3
|
+
import { x } from "./machine.js";
|
|
4
|
+
import { fixedCountFrameCase } from "./count-frames.js";
|
|
5
|
+
import { discoverCountGuardShape } from "./count-guard-shape.js";
|
|
6
|
+
import { discoverCountThresholdWrite } from "./count-write-shape.js";
|
|
7
|
+
import { memberInclusions } from "./count-recovery/member-inclusions.js";
|
|
8
|
+
import { certFor } from "./counts.js";
|
|
9
|
+
import { clock } from "../kernel/prove.js";
|
|
10
|
+
import { identicalRowCountAliases, restrictedRowCountAliases } from "./count-row-aliases.js";
|
|
11
|
+
export function rowCountSupport(m, family, target, row, until) {
|
|
12
|
+
const choice = fixedCountFrameCase(m);
|
|
13
|
+
if (!choice || !target.forall || target.keys?.length !== 2)
|
|
14
|
+
return;
|
|
15
|
+
const matches = family.flatMap(law => {
|
|
16
|
+
const shape = discoverCountGuardShape(m, law, family);
|
|
17
|
+
if (!shape || shape.membershipMap !== row.map || !row.fields.includes(shape.thresholdField))
|
|
18
|
+
return [];
|
|
19
|
+
const write = discoverCountThresholdWrite(m, shape, choice);
|
|
20
|
+
return write?.increment === 1 ? [{ law, shape, write }] : [];
|
|
21
|
+
});
|
|
22
|
+
// Prefer the most restricted vote predicate, never its weaker base law.
|
|
23
|
+
// The election witness must prove every restriction; unrelated roots decline.
|
|
24
|
+
const roots = matches.filter(match => !matches.some(other => other.shape.weakerLaw === match.law));
|
|
25
|
+
if (roots.length !== 1)
|
|
26
|
+
return;
|
|
27
|
+
const { law, shape, write } = roots[0], report = { law: law.name, shape, write, inclusionCounts: [], aliasCounts: [] };
|
|
28
|
+
const seedInstances = { [law.name]: [x(write.source), x(target.forall + '#'), x(write.source), x(target.keys[0])] };
|
|
29
|
+
const scope = JSON.stringify([m, family]);
|
|
30
|
+
let prefix = 'rowCountWitness$';
|
|
31
|
+
while (scope.includes(prefix))
|
|
32
|
+
prefix += '$';
|
|
33
|
+
const request = (goal, decls) => {
|
|
34
|
+
const base = certFor(goal, decls, false, 0, () => clock() < until);
|
|
35
|
+
const inclusions = memberInclusions(m, decls, base.reads, () => clock() < until).filter(p => p.carried === write.input && base.reads.some(r => r[0] === p.negative && r[1] === shape.voteMap)).slice(0, 8);
|
|
36
|
+
const aliases = [...restrictedRowCountAliases(decls, base.reads, shape.voteMap, prefix + 'voteAlias$', () => clock() < until), ...identicalRowCountAliases(decls, base.reads, shape.rowMap, prefix + 'alias$', () => clock() < until)];
|
|
37
|
+
report.inclusionCounts.push(inclusions.length);
|
|
38
|
+
report.aliasCounts.push(aliases.length);
|
|
39
|
+
return { ...base, insts: [...inclusions.map((p, i) => ({ wit: prefix + i, below: p.below, terms: [[1, p.positive], [-1, p.negative]], unit: 0 })), ...aliases] };
|
|
40
|
+
};
|
|
41
|
+
return { options: { seedInstances, witnessFlags: true }, request, report };
|
|
42
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type CountCert, type Goal, type Path, type Tree } from '../kernel/kernel.js';
|
|
2
|
+
import { type CountStageObserver } from './count-stage-trace.js';
|
|
3
|
+
export declare function rowSymmetryNames(request: Pick<CountCert, 'reads' | 'insts'>, a: string, b: string, until: number): Map<string, string> | undefined;
|
|
4
|
+
export declare function rowSymmetryCache(goal: Goal, request: Pick<CountCert, 'reads' | 'insts'>, a: string, b: string, until: number, observe?: CountStageObserver, deferCheck?: boolean): {
|
|
5
|
+
put(path: Path, tree: Tree): void;
|
|
6
|
+
get(path: Path): Tree | undefined;
|
|
7
|
+
} | undefined;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// Experimental, untrusted row-symmetry proposals. No goal is weakened: all
|
|
2
|
+
// input rows are matched exactly after renaming and the result is checked.
|
|
3
|
+
import { canon, check, leafConstraints } from "../kernel/kernel.js";
|
|
4
|
+
import { late } from "../kernel/prove.js";
|
|
5
|
+
import { countCertificateRenamer } from "./count-cert-rename.js";
|
|
6
|
+
import { countRowReindexer } from "./count-row-reindex.js";
|
|
7
|
+
import { traceCountStage } from "./count-stage-trace.js";
|
|
8
|
+
export function rowSymmetryNames(request, a, b, until) {
|
|
9
|
+
if (a === b || late(until))
|
|
10
|
+
return;
|
|
11
|
+
const names = new Map([[a, b], [b, a]]), variables = countCertificateRenamer(names, until);
|
|
12
|
+
const add = (before, after) => {
|
|
13
|
+
if (names.has(before) && names.get(before) !== after)
|
|
14
|
+
return false;
|
|
15
|
+
names.set(before, after);
|
|
16
|
+
return true;
|
|
17
|
+
};
|
|
18
|
+
for (const [id, map, key] of request.reads) {
|
|
19
|
+
const target = JSON.stringify(variables.expression(key)), matches = request.reads.filter(([, m, k]) => m === map && JSON.stringify(k) === target);
|
|
20
|
+
if (matches.length !== 1 || !add(id, matches[0][0]))
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const reads = countCertificateRenamer(names, until);
|
|
24
|
+
const signature = (i, rename) => {
|
|
25
|
+
const terms = new Map();
|
|
26
|
+
for (const [k, id] of i.terms) {
|
|
27
|
+
const target = rename ? names.get(id) ?? id : id;
|
|
28
|
+
terms.set(target, (terms.get(target) ?? 0) + k);
|
|
29
|
+
}
|
|
30
|
+
return JSON.stringify([i.unit, rename ? reads.expression(i.below) : i.below, [...terms].filter(([, k]) => k !== 0).sort(([a], [b]) => a.localeCompare(b))]);
|
|
31
|
+
};
|
|
32
|
+
for (const i of request.insts) {
|
|
33
|
+
const target = signature(i, true), matches = request.insts.filter(other => signature(other, false) === target);
|
|
34
|
+
if (matches.length !== 1 || !add(i.wit, matches[0].wit))
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
for (const [before, after] of names)
|
|
38
|
+
if (names.get(after) !== before)
|
|
39
|
+
return;
|
|
40
|
+
return names;
|
|
41
|
+
}
|
|
42
|
+
export function rowSymmetryCache(goal, request, a, b, until, observe, deferCheck = false) {
|
|
43
|
+
const names = rowSymmetryNames(request, a, b, until);
|
|
44
|
+
if (!names)
|
|
45
|
+
return;
|
|
46
|
+
const rename = countCertificateRenamer(names, until), reindex = countRowReindexer(goal);
|
|
47
|
+
const saved = new Map();
|
|
48
|
+
const key = (path) => JSON.stringify([...path.values()].map(({ lin, holds }) => [canon(lin), holds]).sort(([a], [b]) => String(a).localeCompare(String(b))));
|
|
49
|
+
const extend = (path, lin, holds) => new Map([...path, [canon(lin), { lin, holds }]]);
|
|
50
|
+
const transport = (source, before, after) => {
|
|
51
|
+
if (late(until))
|
|
52
|
+
return;
|
|
53
|
+
if ('split' in source) {
|
|
54
|
+
const split = rename.row(source.split), yes = transport(source.yes, extend(before, source.split, true), extend(after, split, true));
|
|
55
|
+
if (!yes)
|
|
56
|
+
return;
|
|
57
|
+
const no = transport(source.no, extend(before, source.split, false), extend(after, split, false));
|
|
58
|
+
return no ? { split, yes, no } : undefined;
|
|
59
|
+
}
|
|
60
|
+
const old = leafConstraints(goal, before).map(row => ({ ...row, lin: rename.row(row.lin) })), target = leafConstraints(goal, after), index = reindex(goal, old, target);
|
|
61
|
+
const leaf = [], products = [];
|
|
62
|
+
for (const step of source.leaf) {
|
|
63
|
+
if (step.kind !== 'input')
|
|
64
|
+
leaf.push({ ...step });
|
|
65
|
+
else {
|
|
66
|
+
const next = index(step.index);
|
|
67
|
+
if (next === undefined)
|
|
68
|
+
return;
|
|
69
|
+
leaf.push({ ...step, index: next });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
for (const [a, b] of source.products ?? []) {
|
|
73
|
+
const left = index(a), right = index(b);
|
|
74
|
+
if (left === undefined || right === undefined)
|
|
75
|
+
return;
|
|
76
|
+
products.push([left, right]);
|
|
77
|
+
}
|
|
78
|
+
return { leaf, ...(source.products ? { products } : {}), ...(source.squares ? { squares: source.squares.map(rename.row) } : {}) };
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
// Default get rechecks. Deferred trees are UNCHECKED construction inputs;
|
|
82
|
+
// only the enclosing original-goal check and family gate can accept them.
|
|
83
|
+
put(path, tree) { if (saved.size >= 32)
|
|
84
|
+
saved.delete(saved.keys().next().value); saved.set(key(path), { path: new Map(path), tree }); },
|
|
85
|
+
get(path) {
|
|
86
|
+
if (late(until))
|
|
87
|
+
return;
|
|
88
|
+
try {
|
|
89
|
+
const swapped = new Map([...path.values()].map(({ lin, holds }) => { const row = rename.row(lin); return [canon(row), { lin: row, holds }]; })), source = saved.get(key(swapped));
|
|
90
|
+
if (!source)
|
|
91
|
+
return;
|
|
92
|
+
const tree = traceCountStage(observe, 'row-symmetry-transport', 'untrusted-assembly', () => transport(source.tree, source.path, path));
|
|
93
|
+
return tree && (deferCheck || traceCountStage(observe, 'row-symmetry-check', 'trusted-check', () => check(goal, tree, path))) ? tree : undefined;
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// Untrusted scope metadata, never a checker or a transport-success receipt.
|
|
2
|
+
// Preserve every legacy reference and retain root hypotheses supplying names
|
|
3
|
+
// to used native pair, term and naturality rows, including term-closure chains.
|
|
4
|
+
import { canon, framePath, leafConstraints } from "../kernel/kernel.js";
|
|
5
|
+
import { countedCertificateHyps } from "./count-cert-transport.js";
|
|
6
|
+
import { leafRowsOf, cachedRowsAt } from "../kernel/prove.js";
|
|
7
|
+
import { reuseNativeScopeRows } from "./count-scope-row-reuse.js";
|
|
8
|
+
import { visitLinearCells } from "./linear-admission.js";
|
|
9
|
+
import { startWork } from "./work-admission.js";
|
|
10
|
+
import { checkWall } from "./wall.js";
|
|
11
|
+
const tick = (site) => { checkWall('counted scope row premises'); startWork('ticks', 1, site); };
|
|
12
|
+
function branch(path, split, holds) {
|
|
13
|
+
const out = new Map();
|
|
14
|
+
for (const [key, value] of path) {
|
|
15
|
+
tick('pair-scope:path-copy');
|
|
16
|
+
out.set(key, value);
|
|
17
|
+
}
|
|
18
|
+
tick('pair-scope:path-branch');
|
|
19
|
+
out.set(canon(split), { lin: split, holds });
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
export function countedScopeHyps(goal, cert) {
|
|
23
|
+
tick('pair-scope:entry');
|
|
24
|
+
const legacy = countedCertificateHyps(goal, cert);
|
|
25
|
+
if (!legacy)
|
|
26
|
+
return undefined;
|
|
27
|
+
const found = new Set();
|
|
28
|
+
for (const index of legacy) {
|
|
29
|
+
tick('pair-scope:legacy-reference');
|
|
30
|
+
found.add(index);
|
|
31
|
+
}
|
|
32
|
+
const active = new WeakSet();
|
|
33
|
+
const leaf = (tree, path) => {
|
|
34
|
+
// Reconstruct the actual native prefix; all cut kinds affect row indices.
|
|
35
|
+
const actual = framePath(cert.frames ?? [], cert.lemmas ?? [], path, cert.monos ?? [], cert.lins ?? []);
|
|
36
|
+
// Legacy usedHyps either used sparse leaf metadata, or already built this
|
|
37
|
+
// exact table through rowsAt. Reuse only the latter, inside this capture;
|
|
38
|
+
// retain the native work pass and never inject rows into a checker/cache.
|
|
39
|
+
const sparse = !tree.products && !tree.squares && leafRowsOf.has(tree);
|
|
40
|
+
const cached = sparse ? undefined : cachedRowsAt(goal, actual);
|
|
41
|
+
const rows = cached ? reuseNativeScopeRows(goal, actual, cached) : leafConstraints(goal, actual);
|
|
42
|
+
const roots = new Map(), parents = new Map();
|
|
43
|
+
// name -> introducing term. Walking these edges backwards lazily computes
|
|
44
|
+
// the same union of root owners as forward propagation to a fixed point.
|
|
45
|
+
for (let i = 0; i < rows.length; i++) {
|
|
46
|
+
tick('row-scope:source-row');
|
|
47
|
+
const row = rows[i], src = row.src;
|
|
48
|
+
if (!src)
|
|
49
|
+
return false;
|
|
50
|
+
if ('atom' in src || 'fact' in src) {
|
|
51
|
+
if ('fact' in src && (!Number.isSafeInteger(src.fact) || src.fact < 0 || src.fact >= goal.hyps.length))
|
|
52
|
+
return false;
|
|
53
|
+
visitLinearCells(row.lin, name => {
|
|
54
|
+
tick('row-scope:root-name');
|
|
55
|
+
if (name === '1')
|
|
56
|
+
return;
|
|
57
|
+
// Presence includes stored zero entries, exactly like native names.
|
|
58
|
+
let owners = roots.get(name);
|
|
59
|
+
if (!owners)
|
|
60
|
+
roots.set(name, (owners = new Set()));
|
|
61
|
+
if ('fact' in src)
|
|
62
|
+
owners.add(src.fact); // Path/cut atoms invent no fact owner.
|
|
63
|
+
}, 'row-scope:root-cells');
|
|
64
|
+
}
|
|
65
|
+
else if ('term' in src) {
|
|
66
|
+
visitLinearCells(row.lin, name => {
|
|
67
|
+
tick('row-scope:introduced-name');
|
|
68
|
+
if (name === '1')
|
|
69
|
+
return;
|
|
70
|
+
let origins = parents.get(name);
|
|
71
|
+
if (!origins)
|
|
72
|
+
parents.set(name, (origins = new Set()));
|
|
73
|
+
origins.add(src.term);
|
|
74
|
+
}, 'row-scope:term-cells');
|
|
75
|
+
}
|
|
76
|
+
else if (!('pair' in src || 'nat' in src))
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
const todo = [], seen = new Set(), names = [], seenNames = new Set();
|
|
80
|
+
const n = rows.length, squares = tree.squares?.length ?? 0, products = tree.products ?? [];
|
|
81
|
+
for (let i = 0; i < tree.leaf.length; i++) {
|
|
82
|
+
tick('pair-scope:input-step');
|
|
83
|
+
const step = tree.leaf[i];
|
|
84
|
+
if (step.kind === 'input')
|
|
85
|
+
todo.push(step.index);
|
|
86
|
+
}
|
|
87
|
+
// The transporter reindexes all explicit products, even unread ones.
|
|
88
|
+
for (let i = 0; i < products.length; i++) {
|
|
89
|
+
tick('pair-scope:product-operands');
|
|
90
|
+
const pair = products[i];
|
|
91
|
+
todo.push(pair[0], pair[1]);
|
|
92
|
+
}
|
|
93
|
+
while (todo.length) {
|
|
94
|
+
tick('pair-scope:referenced-row');
|
|
95
|
+
const index = todo.pop();
|
|
96
|
+
if (!Number.isSafeInteger(index) || index < 0 || index >= n + squares + products.length)
|
|
97
|
+
return false;
|
|
98
|
+
if (seen.has(index))
|
|
99
|
+
continue;
|
|
100
|
+
seen.add(index);
|
|
101
|
+
if (index < n) {
|
|
102
|
+
const src = rows[index].src;
|
|
103
|
+
if ('fact' in src)
|
|
104
|
+
found.add(src.fact);
|
|
105
|
+
else if ('pair' in src) {
|
|
106
|
+
for (const cell of src.pair) {
|
|
107
|
+
tick('pair-scope:pair-cell');
|
|
108
|
+
if (!roots.has(cell))
|
|
109
|
+
return false;
|
|
110
|
+
names.push(cell);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else if ('term' in src)
|
|
114
|
+
names.push(src.term);
|
|
115
|
+
else if ('nat' in src)
|
|
116
|
+
names.push(src.nat);
|
|
117
|
+
else if (!('atom' in src))
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
else if (index >= n + squares) {
|
|
121
|
+
const pair = products[index - n - squares];
|
|
122
|
+
if (!pair || !Number.isSafeInteger(pair[0]) || !Number.isSafeInteger(pair[1]) || pair[0] < 0 || pair[1] < 0 || pair[0] >= index || pair[1] >= index)
|
|
123
|
+
return false;
|
|
124
|
+
todo.push(pair[0], pair[1]);
|
|
125
|
+
}
|
|
126
|
+
// A square is supplied by the certificate itself, not by hypothesis names.
|
|
127
|
+
// Products inherit their operands, including nested products and squares.
|
|
128
|
+
}
|
|
129
|
+
while (names.length) {
|
|
130
|
+
tick('row-scope:dependency-name');
|
|
131
|
+
const name = names.pop();
|
|
132
|
+
if (seenNames.has(name))
|
|
133
|
+
continue;
|
|
134
|
+
seenNames.add(name);
|
|
135
|
+
if (!roots.has(name) && !parents.has(name))
|
|
136
|
+
return false;
|
|
137
|
+
for (const owner of roots.get(name) ?? []) {
|
|
138
|
+
tick('row-scope:root-owner');
|
|
139
|
+
found.add(owner);
|
|
140
|
+
}
|
|
141
|
+
// Follow the generating term even when its name cancelled out of the used
|
|
142
|
+
// row. src.term, not a scan of only that row's coefficients, supplies it.
|
|
143
|
+
for (const origin of parents.get(name) ?? []) {
|
|
144
|
+
tick('row-scope:term-origin');
|
|
145
|
+
names.push(origin);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return true;
|
|
149
|
+
};
|
|
150
|
+
const visit = (tree, path) => {
|
|
151
|
+
tick('pair-scope:tree');
|
|
152
|
+
if (!tree || typeof tree !== 'object' || active.has(tree))
|
|
153
|
+
return false;
|
|
154
|
+
active.add(tree);
|
|
155
|
+
try {
|
|
156
|
+
return 'leaf' in tree ? leaf(tree, path) : visit(tree.yes, branch(path, tree.split, true)) && visit(tree.no, branch(path, tree.split, false));
|
|
157
|
+
}
|
|
158
|
+
finally {
|
|
159
|
+
active.delete(tree);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
return visit(cert.tree, new Map()) ? found : undefined;
|
|
163
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { canon, canonFlip, cellParts, facts, isCell, termRows } from "../kernel/kernel.js";
|
|
2
|
+
import { observeTableCells } from "./meter.js";
|
|
3
|
+
import { admittedLinearCopy as rowCopy, admittedLinearAdd as rowAdd, admittedLinearScale as rowScale, admittedLinearSub as rowSub, admittedLinearVariable as rowVariable, visitLinearCells, fundedSub as sub, fundedScale as scale } from "./linear-admission.js";
|
|
4
|
+
import { workFilter, workMap, workSetArray } from "./work-collections.js";
|
|
5
|
+
// Keep the native sameKey/decide operations (including funded sub/scale and
|
|
6
|
+
// short-circuiting), not the differently metered proposer implementation.
|
|
7
|
+
function decide(lin, path) {
|
|
8
|
+
observeTableCells();
|
|
9
|
+
let constant = true;
|
|
10
|
+
for (const key in lin) {
|
|
11
|
+
observeTableCells(key.length + 1);
|
|
12
|
+
if (!Number.isSafeInteger(lin[key]))
|
|
13
|
+
return undefined;
|
|
14
|
+
if (key !== '1')
|
|
15
|
+
constant = false;
|
|
16
|
+
}
|
|
17
|
+
if (constant)
|
|
18
|
+
return (lin['1'] ?? 0) <= 0;
|
|
19
|
+
const direct = path.get(canon(lin))?.holds;
|
|
20
|
+
if (direct !== undefined)
|
|
21
|
+
return direct;
|
|
22
|
+
const flipped = path.get(canonFlip(lin))?.holds;
|
|
23
|
+
return flipped === undefined ? undefined : !flipped;
|
|
24
|
+
}
|
|
25
|
+
function sameKey(p, q, path) {
|
|
26
|
+
const zero = (a, b) => { const d = sub(a, b); return decide(d, path) === true && decide(scale(d, -1), path) === true; };
|
|
27
|
+
if (p.key && q.key)
|
|
28
|
+
return zero(p.key, q.key);
|
|
29
|
+
return !!p.keys && !!q.keys && p.keys.length === q.keys.length && p.keys.every((a, i) => zero(a, q.keys[i]));
|
|
30
|
+
}
|
|
31
|
+
// The work-only counterpart of kernel leafRows(..., h => facts(h,path)). Only
|
|
32
|
+
// atom/fact rows must coexist to discover names. Generated pair/term/nat rows
|
|
33
|
+
// still perform every original funded coefficient operation at its original
|
|
34
|
+
// position; their output is discarded immediately instead of being appended.
|
|
35
|
+
// This intentionally saves storage, NOT quadratic arithmetic/counting work.
|
|
36
|
+
export function reuseNativeScopeRows(goal, path, rows) {
|
|
37
|
+
const initial = [];
|
|
38
|
+
let atom = 0, count = 0;
|
|
39
|
+
for (const a of path.values()) {
|
|
40
|
+
const lin = a.holds ? rowCopy(a.lin, 'leafRows:atom-copy') : rowAdd(rowVariable('1', 1, 'leafRows:atom-one'), rowScale(a.lin, -1, 'leafRows:atom-negate'), 'leafRows:atom-flip');
|
|
41
|
+
initial.push({ lin, label: '', src: { atom: atom++ } });
|
|
42
|
+
count++;
|
|
43
|
+
}
|
|
44
|
+
for (const [i, h] of goal.hyps.entries())
|
|
45
|
+
for (const lin of facts(h, path)) {
|
|
46
|
+
initial.push({ lin: rowCopy(lin, 'leafRows:fact'), label: '', src: { fact: i } });
|
|
47
|
+
count++;
|
|
48
|
+
}
|
|
49
|
+
const names = new Set();
|
|
50
|
+
for (const row of initial)
|
|
51
|
+
visitLinearCells(row.lin, key => { if (key !== '1')
|
|
52
|
+
names.add(key); }, 'leafRows:names');
|
|
53
|
+
const cells = workMap(workFilter(workSetArray(names, 'leafRows:names-copy'), isCell, 'leafRows:cell-filter'), name => ({ name, ...cellParts(name) }), 'leafRows:cell-parts');
|
|
54
|
+
for (let i = 0; i < cells.length; i++)
|
|
55
|
+
for (let j = i + 1; j < cells.length; j++) {
|
|
56
|
+
const p = cells[i], q = cells[j];
|
|
57
|
+
observeTableCells();
|
|
58
|
+
if (p.map !== q.map)
|
|
59
|
+
continue;
|
|
60
|
+
if (!sameKey(p, q, path))
|
|
61
|
+
continue;
|
|
62
|
+
const pRow = rowVariable(p.name, 1, 'leafRows:pair-p'), qRow = rowVariable(q.name, 1, 'leafRows:pair-q');
|
|
63
|
+
rowSub(pRow, qRow, 'leafRows:pair-left');
|
|
64
|
+
rowSub(qRow, pRow, 'leafRows:pair-right');
|
|
65
|
+
count += 2;
|
|
66
|
+
}
|
|
67
|
+
const seen = new Set(), todo = workFilter(workSetArray(names, 'leafRows:todo-copy'), n => n.startsWith('⟦'), 'leafRows:todo-filter');
|
|
68
|
+
while (todo.length) {
|
|
69
|
+
const name = todo.pop();
|
|
70
|
+
if (seen.has(name))
|
|
71
|
+
continue;
|
|
72
|
+
seen.add(name);
|
|
73
|
+
for (const lin of termRows(name, path)) {
|
|
74
|
+
rowCopy(lin, 'leafRows:term');
|
|
75
|
+
count++;
|
|
76
|
+
visitLinearCells(lin, key => { if (key !== '1') {
|
|
77
|
+
names.add(key);
|
|
78
|
+
if (key.startsWith('⟦') && !seen.has(key))
|
|
79
|
+
todo.push(key);
|
|
80
|
+
} }, 'leafRows:term-names');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
for (const name of names) {
|
|
84
|
+
rowVariable(name, -1, 'leafRows:natural');
|
|
85
|
+
count++;
|
|
86
|
+
}
|
|
87
|
+
// Never use a partial/mismatched proposal to infer suppliers. This comparison
|
|
88
|
+
// is intrinsic metadata, not a traversal or a certificate-acceptance shortcut.
|
|
89
|
+
if (count !== rows.length)
|
|
90
|
+
throw new Error('capture native/proposer row-count mismatch');
|
|
91
|
+
return rows;
|
|
92
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function withSearchAllowance<T>(until: number, run: () => T, onNativeRefusal?: (error: unknown) => T): T;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Clock-derived search allowances are policy, not public native work quotas.
|
|
2
|
+
import { clock, fullRate, withBudget, withDeadline } from "../kernel/prove.js";
|
|
3
|
+
import { inProxySearch } from "./search-policy.js";
|
|
4
|
+
export function withSearchAllowance(until, run, onNativeRefusal) {
|
|
5
|
+
// No local ledger endpoint exists here. An authentic enclosing refusal must
|
|
6
|
+
// bypass every catch written to consume a native local-quota expiration.
|
|
7
|
+
if (inProxySearch())
|
|
8
|
+
return withDeadline(until, run);
|
|
9
|
+
try {
|
|
10
|
+
return withBudget(Math.max(0, until - clock()) * fullRate, run);
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
if (!onNativeRefusal)
|
|
14
|
+
throw error;
|
|
15
|
+
return onNativeRefusal(error);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type FrameCut, type Goal, type LinCut, type LemmaCut, type Path, type Tree } from '../kernel/kernel.js';
|
|
2
|
+
export declare function stabilizeGuardedTree(goal: Goal, tree: Tree, frames: FrameCut[], lins: LinCut[], roots: ReadonlyMap<Tree, Path>, until: number, options?: {
|
|
3
|
+
deferCheck?: boolean;
|
|
4
|
+
lemmas?: LemmaCut[];
|
|
5
|
+
}): {
|
|
6
|
+
tree?: Tree;
|
|
7
|
+
rebased: number;
|
|
8
|
+
failed: boolean;
|
|
9
|
+
};
|