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,299 @@
|
|
|
1
|
+
// Untrusted sampling optimization. A class is used only AFTER one member has
|
|
2
|
+
// produced a state. Refusals are never generalized; the original request order,
|
|
3
|
+
// logical trial allowance and first successful witness remain unchanged.
|
|
4
|
+
import { hasFinite, walk } from "./machine.js";
|
|
5
|
+
import { startWork } from "./work-admission.js";
|
|
6
|
+
import { completeWorkProfile } from "./work-profile.js";
|
|
7
|
+
import { checkWall } from "./wall.js";
|
|
8
|
+
class UnsupportedQuotient extends Error {
|
|
9
|
+
}
|
|
10
|
+
export function requestQuotient(m, requests) {
|
|
11
|
+
if (hasFinite(m))
|
|
12
|
+
return undefined; // arbitrary finite-body reads need an exact quotient proof
|
|
13
|
+
if (requests.length < 2 || Object.keys(m.fns ?? {}).length || m.history || m.leasts || Object.keys(m.sums ?? {}).length)
|
|
14
|
+
return undefined;
|
|
15
|
+
const names = [...m.inputs, ...m.inputMaps ?? []], inputs = new Set(m.inputs), maps = new Set(m.inputMaps ?? []);
|
|
16
|
+
// Ambiguous namespaces and non-topological flags use the unmodified sampler.
|
|
17
|
+
if (new Set(names).size !== names.length || names.some(n => n.startsWith('?') || m.params.includes(n) || Object.hasOwn(m.state, n)) || [...maps].some(n => Object.hasOwn(m.maps ?? {}, n) || Object.hasOwn(m.counts ?? {}, n)))
|
|
18
|
+
return undefined;
|
|
19
|
+
let work = 0;
|
|
20
|
+
const tick = () => {
|
|
21
|
+
if (completeWorkProfile.enabled) {
|
|
22
|
+
// Polling every 256 visits remains a wall-cancellation optimization, not
|
|
23
|
+
// permission to debit past an inherited raw-work endpoint.
|
|
24
|
+
startWork('ticks', 1, 'request quotient');
|
|
25
|
+
}
|
|
26
|
+
if ((++work & 255) === 0)
|
|
27
|
+
checkWall('request quotient');
|
|
28
|
+
};
|
|
29
|
+
const flags = m.step.flags ?? {}, known = new Set(), tags = new Map();
|
|
30
|
+
let supported = true;
|
|
31
|
+
walk([m.step, m.counts], o => {
|
|
32
|
+
tick();
|
|
33
|
+
if (o.op === 'var' && String(o.name).startsWith('?'))
|
|
34
|
+
supported = false;
|
|
35
|
+
if (o.op === 'all' && [o.key, ...o.keys ?? []].some(name => String(name).startsWith('?')))
|
|
36
|
+
supported = false;
|
|
37
|
+
});
|
|
38
|
+
for (const count of Object.values(m.counts ?? {}))
|
|
39
|
+
walk(count, o => { tick(); if (o.op === 'flag')
|
|
40
|
+
supported = false; });
|
|
41
|
+
if (Object.values(m.step.maps ?? {}).some(w => 'each' in w && w.each.startsWith('?')))
|
|
42
|
+
supported = false;
|
|
43
|
+
for (const [name, c] of Object.entries(flags)) {
|
|
44
|
+
walk(c, o => { tick(); if (o.op === 'flag' && !known.has(String(o.name)))
|
|
45
|
+
supported = false; });
|
|
46
|
+
known.add(name);
|
|
47
|
+
}
|
|
48
|
+
if (!supported)
|
|
49
|
+
return undefined;
|
|
50
|
+
walk(m.step, o => {
|
|
51
|
+
tick();
|
|
52
|
+
if (o.op !== '=')
|
|
53
|
+
return;
|
|
54
|
+
const a = o.a, b = o.b, v = a.op === 'var' ? a : b, k = a.op === 'var' ? b : a;
|
|
55
|
+
if (v.op === 'var' && k.op === 'const' && inputs.has(v.name) && Number.isSafeInteger(k.value)) {
|
|
56
|
+
let values = tags.get(v.name);
|
|
57
|
+
if (!values)
|
|
58
|
+
tags.set(v.name, (values = new Set()));
|
|
59
|
+
values.add(k.value);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const selector = [...tags].filter(([, values]) => values.size > 1).sort((a, b) => b[1].size - a[1].size || m.inputs.indexOf(a[0]) - m.inputs.indexOf(b[0]))[0]?.[0];
|
|
63
|
+
const empty = new Set(), reads = new Map();
|
|
64
|
+
const number = (e, fixed, bound) => {
|
|
65
|
+
tick();
|
|
66
|
+
let out;
|
|
67
|
+
switch (e.op) {
|
|
68
|
+
case 'const':
|
|
69
|
+
out = e.value;
|
|
70
|
+
break;
|
|
71
|
+
case 'var':
|
|
72
|
+
out = bound.has(e.name) ? undefined : fixed[e.name];
|
|
73
|
+
break;
|
|
74
|
+
case 'if': {
|
|
75
|
+
const c = boolean(e.c, fixed, bound, new Set());
|
|
76
|
+
return c === undefined ? undefined : number(c ? e.then : e.else, fixed, bound);
|
|
77
|
+
}
|
|
78
|
+
case 'get':
|
|
79
|
+
case 'tup':
|
|
80
|
+
case 'proj': return undefined;
|
|
81
|
+
case 'mul': {
|
|
82
|
+
const a = number(e.a, fixed, bound);
|
|
83
|
+
out = a === undefined ? undefined : e.k * a;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
case 'add':
|
|
87
|
+
case 'sub':
|
|
88
|
+
case 'min':
|
|
89
|
+
case 'max':
|
|
90
|
+
case 'prod': {
|
|
91
|
+
const a = number(e.a, fixed, bound), b = number(e.b, fixed, bound);
|
|
92
|
+
if (a === undefined || b === undefined)
|
|
93
|
+
return undefined;
|
|
94
|
+
out = e.op === 'add' ? a + b : e.op === 'sub' ? Math.max(0, a - b) : e.op === 'min' ? Math.min(a, b) : e.op === 'max' ? Math.max(a, b) : a * b;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return out !== undefined && Number.isSafeInteger(out) && out >= 0 ? out : undefined;
|
|
98
|
+
};
|
|
99
|
+
const boolean = (c, fixed, bound, visiting) => {
|
|
100
|
+
tick();
|
|
101
|
+
switch (c.op) {
|
|
102
|
+
case 'flag': {
|
|
103
|
+
if (visiting.has(c.name) || !flags[c.name])
|
|
104
|
+
throw new UnsupportedQuotient('flag');
|
|
105
|
+
const next = new Set(visiting);
|
|
106
|
+
next.add(c.name);
|
|
107
|
+
return boolean(flags[c.name], fixed, empty, next);
|
|
108
|
+
}
|
|
109
|
+
case 'all': return undefined;
|
|
110
|
+
case 'not': {
|
|
111
|
+
const a = boolean(c.x, fixed, bound, visiting);
|
|
112
|
+
return a === undefined ? undefined : !a;
|
|
113
|
+
}
|
|
114
|
+
case 'and':
|
|
115
|
+
case 'or': {
|
|
116
|
+
let unknown = false;
|
|
117
|
+
for (const x of c.xs) {
|
|
118
|
+
const a = boolean(x, fixed, bound, visiting);
|
|
119
|
+
if (a === (c.op === 'or'))
|
|
120
|
+
return a;
|
|
121
|
+
if (a === undefined)
|
|
122
|
+
unknown = true;
|
|
123
|
+
}
|
|
124
|
+
return unknown ? undefined : c.op === 'and';
|
|
125
|
+
}
|
|
126
|
+
case '=':
|
|
127
|
+
case '<':
|
|
128
|
+
case '<=': {
|
|
129
|
+
const a = number(c.a, fixed, bound), b = number(c.b, fixed, bound);
|
|
130
|
+
return a === undefined || b === undefined ? undefined : c.op === '=' ? a === b : c.op === '<' ? a < b : a <= b;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
const projection = (value) => {
|
|
135
|
+
const cached = reads.get(value);
|
|
136
|
+
if (cached)
|
|
137
|
+
return cached;
|
|
138
|
+
const fixed = selector ? { [selector]: value } : {}, out = new Set(), visiting = new Set();
|
|
139
|
+
const expr = (e, bound) => {
|
|
140
|
+
tick();
|
|
141
|
+
switch (e.op) {
|
|
142
|
+
case 'const': return;
|
|
143
|
+
case 'var':
|
|
144
|
+
if (!bound.has(e.name) && inputs.has(e.name) && !Object.hasOwn(fixed, e.name))
|
|
145
|
+
out.add(e.name);
|
|
146
|
+
return;
|
|
147
|
+
case 'if': {
|
|
148
|
+
const c = boolean(e.c, fixed, bound, new Set());
|
|
149
|
+
if (c !== undefined) {
|
|
150
|
+
expr(c ? e.then : e.else, bound);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
cond(e.c, bound);
|
|
154
|
+
expr(e.then, bound);
|
|
155
|
+
expr(e.else, bound);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
case 'get': {
|
|
159
|
+
expr(e.key, bound);
|
|
160
|
+
if (maps.has(e.map))
|
|
161
|
+
out.add(e.map);
|
|
162
|
+
const count = m.counts?.[e.map];
|
|
163
|
+
// A derived count has memoized, not complete, enumerable support in
|
|
164
|
+
// the runtime. Never quotient its reads under a quantified/bulk binder.
|
|
165
|
+
if (count && bound.size)
|
|
166
|
+
throw new UnsupportedQuotient('count under binder');
|
|
167
|
+
if (count) {
|
|
168
|
+
const tag = 'count:' + e.map;
|
|
169
|
+
if (visiting.has(tag))
|
|
170
|
+
throw new UnsupportedQuotient('count cycle');
|
|
171
|
+
visiting.add(tag);
|
|
172
|
+
const inner = new Set([count.j, count.key, ...count.lo ? [count.lo] : []]);
|
|
173
|
+
expr(count.below, new Set([count.j, ...count.lo ? [count.lo] : []]));
|
|
174
|
+
expr(count.body, inner);
|
|
175
|
+
visiting.delete(tag);
|
|
176
|
+
}
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
case 'mul':
|
|
180
|
+
case 'proj':
|
|
181
|
+
expr(e.a, bound);
|
|
182
|
+
return;
|
|
183
|
+
case 'add':
|
|
184
|
+
case 'sub':
|
|
185
|
+
case 'min':
|
|
186
|
+
case 'max':
|
|
187
|
+
case 'prod':
|
|
188
|
+
case 'tup':
|
|
189
|
+
expr(e.a, bound);
|
|
190
|
+
expr(e.b, bound);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
const cond = (c, bound) => {
|
|
194
|
+
tick();
|
|
195
|
+
if (boolean(c, fixed, bound, new Set()) !== undefined)
|
|
196
|
+
return;
|
|
197
|
+
switch (c.op) {
|
|
198
|
+
case 'flag': {
|
|
199
|
+
const tag = 'flag:' + c.name;
|
|
200
|
+
if (visiting.has(tag) || !flags[c.name])
|
|
201
|
+
throw new UnsupportedQuotient('flag');
|
|
202
|
+
visiting.add(tag);
|
|
203
|
+
cond(flags[c.name], empty);
|
|
204
|
+
visiting.delete(tag);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
case 'all':
|
|
208
|
+
// For one plain key, any past-the-support key has the same observations:
|
|
209
|
+
// every bound-key read is a map's default (opaque/count maps are excluded).
|
|
210
|
+
// Keep the conservative full support for cross-key quantifiers.
|
|
211
|
+
if (c.keys?.length)
|
|
212
|
+
for (const name of maps)
|
|
213
|
+
out.add(name);
|
|
214
|
+
cond(c.c, new Set([...bound, c.key, ...c.keys ?? []]));
|
|
215
|
+
return;
|
|
216
|
+
case 'not':
|
|
217
|
+
cond(c.x, bound);
|
|
218
|
+
return;
|
|
219
|
+
case 'and':
|
|
220
|
+
case 'or':
|
|
221
|
+
for (const x of c.xs)
|
|
222
|
+
cond(x, bound);
|
|
223
|
+
return;
|
|
224
|
+
case '=':
|
|
225
|
+
case '<':
|
|
226
|
+
case '<=':
|
|
227
|
+
expr(c.a, bound);
|
|
228
|
+
expr(c.b, bound);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
for (const e of Object.values(m.step.state ?? {}))
|
|
232
|
+
expr(e, empty);
|
|
233
|
+
for (const w of Object.values(m.step.maps ?? {})) {
|
|
234
|
+
if ('each' in w)
|
|
235
|
+
expr(w.value, new Set([w.each]));
|
|
236
|
+
else {
|
|
237
|
+
expr(w.key, empty);
|
|
238
|
+
expr(w.value, empty);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// The slice tag is part of the class even if the selected arm is a no-op.
|
|
242
|
+
const ordered = names.filter(name => out.has(name));
|
|
243
|
+
reads.set(value, ordered);
|
|
244
|
+
return ordered;
|
|
245
|
+
};
|
|
246
|
+
const tokens = new WeakMap();
|
|
247
|
+
const mapToken = (value) => {
|
|
248
|
+
if (!(value instanceof Map))
|
|
249
|
+
throw new UnsupportedQuotient('non-map request');
|
|
250
|
+
const cached = tokens.get(value);
|
|
251
|
+
if (cached !== undefined)
|
|
252
|
+
return cached;
|
|
253
|
+
const entries = [...value];
|
|
254
|
+
for (const [k, v] of entries) {
|
|
255
|
+
tick();
|
|
256
|
+
if (!Number.isSafeInteger(k) || k < 0 || !Number.isSafeInteger(v) || v < 0)
|
|
257
|
+
throw new UnsupportedQuotient('non-natural request map');
|
|
258
|
+
}
|
|
259
|
+
entries.sort((a, b) => a[0] - b[0]);
|
|
260
|
+
const token = JSON.stringify(entries);
|
|
261
|
+
tokens.set(value, token);
|
|
262
|
+
return token;
|
|
263
|
+
};
|
|
264
|
+
try {
|
|
265
|
+
const ids = new Map(), classes = new Uint32Array(requests.length);
|
|
266
|
+
for (let i = 0; i < requests.length; i++) {
|
|
267
|
+
tick();
|
|
268
|
+
const request = requests[i], value = selector ? request[selector] : undefined;
|
|
269
|
+
if (selector && (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 0))
|
|
270
|
+
return undefined;
|
|
271
|
+
const fields = projection(value), parts = [value];
|
|
272
|
+
for (const name of fields) {
|
|
273
|
+
tick();
|
|
274
|
+
const v = request[name];
|
|
275
|
+
if (maps.has(name))
|
|
276
|
+
parts.push(mapToken(v));
|
|
277
|
+
else {
|
|
278
|
+
if (typeof v !== 'number' || !Number.isSafeInteger(v) || v < 0)
|
|
279
|
+
return undefined;
|
|
280
|
+
parts.push(v);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
const key = JSON.stringify(parts);
|
|
284
|
+
let id = ids.get(key);
|
|
285
|
+
if (id === undefined) {
|
|
286
|
+
id = ids.size;
|
|
287
|
+
ids.set(key, id);
|
|
288
|
+
}
|
|
289
|
+
classes[i] = id;
|
|
290
|
+
}
|
|
291
|
+
checkWall('request quotient complete');
|
|
292
|
+
return ids.size < requests.length ? { classes, count: ids.size, selector, reads } : undefined;
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
if (error instanceof UnsupportedQuotient)
|
|
296
|
+
return undefined;
|
|
297
|
+
throw error;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type C, type Law, type Machine } from './machine.js';
|
|
2
|
+
export type RowAgreementShape = {
|
|
3
|
+
map: string;
|
|
4
|
+
width: number;
|
|
5
|
+
left: string;
|
|
6
|
+
right: string;
|
|
7
|
+
column: string;
|
|
8
|
+
fields: string[];
|
|
9
|
+
markers: {
|
|
10
|
+
map: string;
|
|
11
|
+
value: number;
|
|
12
|
+
}[];
|
|
13
|
+
guard: C;
|
|
14
|
+
};
|
|
15
|
+
export declare function discoverRowAgreement(m: Machine, law: Law): RowAgreementShape | undefined;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// A proposal selector only. Matching syntax proves no invariant and adds no premise.
|
|
2
|
+
import { walkOnce } from "./machine.js";
|
|
3
|
+
const atoms = (c) => c.op === 'and' ? c.xs.flatMap(atoms) : [c];
|
|
4
|
+
const variable = (e, name) => e.op === 'var' && e.name === name;
|
|
5
|
+
function packed(e, row, column) {
|
|
6
|
+
if (e.op !== 'add')
|
|
7
|
+
return;
|
|
8
|
+
const [a, b] = e.a.op === 'mul' ? [e.a, e.b] : [e.b, e.a];
|
|
9
|
+
if (a.op === 'mul' && variable(a.a, row) && variable(b, column) && Number.isSafeInteger(a.k) && a.k > 0)
|
|
10
|
+
return a.k;
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
export function discoverRowAgreement(m, law) {
|
|
14
|
+
if (!law.forall || law.keys?.length !== 2 || law.holds.op !== 'or' || law.holds.xs.length !== 2)
|
|
15
|
+
return;
|
|
16
|
+
const [left, right, column] = [law.forall, law.keys[0], law.keys[1]];
|
|
17
|
+
if (new Set([left, right, column]).size !== 3)
|
|
18
|
+
return;
|
|
19
|
+
const negated = law.holds.xs.find(c => c.op === 'not'), conclusion = law.holds.xs.find(c => c.op === '=');
|
|
20
|
+
if (negated?.op !== 'not' || conclusion?.op !== '=' || conclusion.a.op !== 'get' || conclusion.b.op !== 'get')
|
|
21
|
+
return;
|
|
22
|
+
const a = conclusion.a, b = conclusion.b, width = packed(a.key, left, column);
|
|
23
|
+
if (!width || packed(b.key, right, column) !== width || a.map !== b.map || !(a.map in (m.maps ?? {})) || m.counts?.[a.map])
|
|
24
|
+
return;
|
|
25
|
+
const fields = new Set(), marked = new Map();
|
|
26
|
+
for (const c of atoms(negated.x)) {
|
|
27
|
+
if (c.op !== '=')
|
|
28
|
+
continue;
|
|
29
|
+
const [x, y] = c.a.op === 'get' ? [c.a, c.b] : [c.b, c.a];
|
|
30
|
+
if (x.op !== 'get')
|
|
31
|
+
continue;
|
|
32
|
+
if (y.op === 'get' && x.map === y.map && (variable(x.key, left) && variable(y.key, right) || variable(x.key, right) && variable(y.key, left)))
|
|
33
|
+
fields.add(x.map);
|
|
34
|
+
if (y.op === 'const' && Number.isSafeInteger(y.value) && (variable(x.key, left) || variable(x.key, right))) {
|
|
35
|
+
const byRow = marked.get(x.map) ?? new Map();
|
|
36
|
+
byRow.set(x.key.op === 'var' ? x.key.name : '', y.value);
|
|
37
|
+
marked.set(x.map, byRow);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (!fields.size || [...fields].some(f => m.counts?.[f] || !(f in (m.maps ?? {}))))
|
|
41
|
+
return;
|
|
42
|
+
const markers = [...marked].flatMap(([map, rows]) => rows.has(left) && rows.get(left) === rows.get(right) ? [{ map, value: rows.get(left) }] : []);
|
|
43
|
+
let supported = true;
|
|
44
|
+
walkOnce(negated.x, (node) => { if (node.op === 'get' && !fields.has(node.map) && !markers.some(marker => marker.map === node.map))
|
|
45
|
+
supported = false; });
|
|
46
|
+
if (!supported)
|
|
47
|
+
return;
|
|
48
|
+
// A versioned row's fields move with a row copy. This deliberately excludes
|
|
49
|
+
// lookalike pairs containing a field updated only by an unrelated action.
|
|
50
|
+
const rowFlags = new Set();
|
|
51
|
+
walkOnce(m.step.maps?.[a.map], (node) => { if (node.op === 'flag')
|
|
52
|
+
rowFlags.add(node.name); });
|
|
53
|
+
let shared = rowFlags;
|
|
54
|
+
for (const field of fields) {
|
|
55
|
+
const copied = new Set();
|
|
56
|
+
walkOnce(m.step.maps?.[field], (node) => {
|
|
57
|
+
if (node.op !== 'if' || node.then.op !== 'get' || node.then.map !== field || node.then.key.op !== 'var' || !m.inputs.includes(node.then.key.name))
|
|
58
|
+
return;
|
|
59
|
+
for (const c of atoms(node.c))
|
|
60
|
+
if (c.op === 'flag')
|
|
61
|
+
copied.add(c.name);
|
|
62
|
+
});
|
|
63
|
+
shared = new Set([...shared].filter(flag => copied.has(flag)));
|
|
64
|
+
}
|
|
65
|
+
if (!shared.size)
|
|
66
|
+
return;
|
|
67
|
+
return { map: a.map, width, left, right, column, fields: [...fields].sort(), markers: markers.sort((a, b) => a.map.localeCompare(b.map)), guard: negated.x };
|
|
68
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type ProxySearchState = {
|
|
2
|
+
rate: number;
|
|
3
|
+
model: boolean;
|
|
4
|
+
deadline: number;
|
|
5
|
+
deadlineEpr: number;
|
|
6
|
+
workCap: number;
|
|
7
|
+
wallEnd: number;
|
|
8
|
+
};
|
|
9
|
+
export declare const proxySearchState: () => ProxySearchState | undefined;
|
|
10
|
+
export declare const inProxySearch: () => boolean;
|
|
11
|
+
export declare function projectedSearchWork(): number;
|
|
12
|
+
export declare function withPlainSearchPolicy<T>(hasCounts: boolean, run: () => T): T;
|
|
13
|
+
export declare function withPublicSearchPolicy<T>(hasCounts: boolean, run: () => T): T;
|
|
14
|
+
export declare function canUseCountedProxy(): boolean;
|
|
15
|
+
export declare function withCountedSearchPolicy<T>(rejecting: boolean, run: () => T): T;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Search policy is not work accounting. The projection is a new deterministic
|
|
2
|
+
// heuristic, not a replay of the legacy clock (whose charges and wall differed).
|
|
3
|
+
import { completeWorkProfile } from "./work-profile.js";
|
|
4
|
+
import { workLedger } from "./work-admission.js";
|
|
5
|
+
import { legacyWeights } from "./work-kinds.js";
|
|
6
|
+
let policy;
|
|
7
|
+
export const proxySearchState = () => policy?.kind === 'proxy' ? policy.state : undefined;
|
|
8
|
+
export const inProxySearch = () => policy?.kind === 'proxy';
|
|
9
|
+
// No extra counter, weight, charge, grant, lease or root. Preserve declared order.
|
|
10
|
+
export function projectedSearchWork() {
|
|
11
|
+
let n = 0;
|
|
12
|
+
for (const [key, weight] of legacyWeights)
|
|
13
|
+
n += weight * Number(workLedger.counter(key));
|
|
14
|
+
return n;
|
|
15
|
+
}
|
|
16
|
+
// Public proveRule owns the selection, using its existing actual-machine test.
|
|
17
|
+
// A native parent locks its entire call tree, including nested plain public calls.
|
|
18
|
+
// A native public child of a proxy temporarily suspends it; proxy state is separate
|
|
19
|
+
// from all legacy/native control state and resumes only after that child exits.
|
|
20
|
+
export function withPlainSearchPolicy(hasCounts, run) {
|
|
21
|
+
if (!completeWorkProfile.enabled || !workLedger.inBudget() || policy?.kind === 'native'
|
|
22
|
+
|| policy?.kind === 'proxy' && !hasCounts)
|
|
23
|
+
return run();
|
|
24
|
+
const previous = policy;
|
|
25
|
+
policy = hasCounts ? { kind: 'native', locked: true } : { kind: 'proxy', state: {
|
|
26
|
+
rate: 0, model: false, deadline: Infinity, deadlineEpr: 0, workCap: Infinity, wallEnd: Infinity,
|
|
27
|
+
} };
|
|
28
|
+
try {
|
|
29
|
+
return run();
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
policy = previous;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// A public counted call defers its policy choice until searchCounted knows the
|
|
36
|
+
// branch. Explicit native scopes and rejecting ancestors remain locked.
|
|
37
|
+
export function withPublicSearchPolicy(hasCounts, run) {
|
|
38
|
+
if (!hasCounts)
|
|
39
|
+
return withPlainSearchPolicy(false, run);
|
|
40
|
+
if (!completeWorkProfile.enabled || !workLedger.inBudget() || policy?.kind === 'native' && policy.locked !== false)
|
|
41
|
+
return run();
|
|
42
|
+
const previous = policy;
|
|
43
|
+
policy = { kind: 'native', locked: false };
|
|
44
|
+
try {
|
|
45
|
+
return run();
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
policy = previous;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export function canUseCountedProxy() {
|
|
52
|
+
return completeWorkProfile.enabled && workLedger.inBudget() && !(policy?.kind === 'native' && policy.locked !== false);
|
|
53
|
+
}
|
|
54
|
+
// Only the counted branch selector may relax an unresolved native policy.
|
|
55
|
+
export function withCountedSearchPolicy(rejecting, run) {
|
|
56
|
+
if (!completeWorkProfile.enabled || !workLedger.inBudget() || policy?.kind === 'native' && policy.locked !== false)
|
|
57
|
+
return run();
|
|
58
|
+
if (!rejecting && policy?.kind === 'proxy')
|
|
59
|
+
return run();
|
|
60
|
+
const previous = policy;
|
|
61
|
+
policy = rejecting ? { kind: 'native', locked: true } : { kind: 'proxy', state: { rate: 0, model: false, deadline: Infinity, deadlineEpr: 0, workCap: Infinity, wallEnd: Infinity } };
|
|
62
|
+
try {
|
|
63
|
+
return run();
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
policy = previous;
|
|
67
|
+
}
|
|
68
|
+
}
|
package/dist/core/solver.d.ts
CHANGED
|
@@ -87,7 +87,7 @@ export declare const costs: {
|
|
|
87
87
|
goalNodes: number;
|
|
88
88
|
translateRows: number;
|
|
89
89
|
};
|
|
90
|
-
export declare function solve(constraints: Constraint[], maxRows?: number, integral?: boolean): Verdict;
|
|
90
|
+
export declare function solve(constraints: Constraint[], maxRows?: number, integral?: boolean, more?: () => boolean): Verdict;
|
|
91
91
|
export declare const ratioRow: (T: Float64Array[], basis: number[], enter: number, cols: number, eps: number) => [number, number];
|
|
92
92
|
export declare function pivot(T: Float64Array[], z: Float64Array | undefined, basis: number[], leave: number, enter: number, cols: number): void;
|
|
93
93
|
export declare function refuteFast(constraints: Constraint[], maxRows?: number, integral?: boolean): Verdict | undefined;
|
package/dist/core/solver.js
CHANGED
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
// row is strict), so the answer is refuted or sat, the witness exact (`rational`), the derivation one check.ts takes
|
|
12
12
|
// with no cut: the integers are this with the cut rule, and a strict row over them is lin + 1 <= 0.
|
|
13
13
|
import { Q0, Q1, q, qadd, qcmp, qdiv, qneg, qnum, qrow, qsub } from "./q.js";
|
|
14
|
+
import { startWork, workCounterView } from "./work-admission.js";
|
|
15
|
+
import { completeWorkProfile } from "./work-profile.js";
|
|
14
16
|
// The process's environment (the switches and traces the searches read), empty where there is none.
|
|
15
17
|
export const env = globalThis.process?.env ?? {};
|
|
16
18
|
export const v = (name) => ({ [name]: 1 });
|
|
@@ -104,12 +106,19 @@ export const canon = (l) => JSON.stringify(Object.keys(l).sort().map(x => [x, l[
|
|
|
104
106
|
// The rows the solver has read and made, which a counted search reads as its clock (kernel/prove.ts's `counted`).
|
|
105
107
|
export const work = { n: 0 };
|
|
106
108
|
// What the searches did, by kind, beside work.n (research/query reads them: the cost of each query's parts).
|
|
107
|
-
export const costs = { solves: 0, solveRows: 0, fm: 0, fpivots: 0, fcells: 0, cdclNodes: 0, cdclRows: 0, scan: 0, pivots: 0, pivotRows: 0, plainNodes: 0, plainRows: 0,
|
|
108
|
-
values: 0, copies: 0, edges: 0, unitRows: 0, unfoldRows: 0, goalNodes: 0, translateRows: 0 }
|
|
109
|
-
|
|
109
|
+
export const costs = workCounterView({ solves: 0, solveRows: 0, fm: 0, fpivots: 0, fcells: 0, cdclNodes: 0, cdclRows: 0, scan: 0, pivots: 0, pivotRows: 0, plainNodes: 0, plainRows: 0,
|
|
110
|
+
values: 0, copies: 0, edges: 0, unitRows: 0, unfoldRows: 0, goalNodes: 0, translateRows: 0 }, { fm: 'fm', fcells: 'fcells', cdclNodes: 'cdclNodes', scan: 'scan', pivotRows: 'pivotRows', plainRows: 'plainRows',
|
|
111
|
+
values: 'values', copies: 'copies', edges: 'edges', unitRows: 'unitRows', unfoldRows: 'unfoldRows', goalNodes: 'goalNodes', translateRows: 'translateRows' });
|
|
112
|
+
// `more` is opt-in. Normal callers retain the exact charge/order path; bounded
|
|
113
|
+
// callers may stop before an elimination round or between generated rows.
|
|
114
|
+
export function solve(constraints, maxRows = 20_000, integral = true, more) {
|
|
115
|
+
if (more && !more())
|
|
116
|
+
return { kind: 'unknown' };
|
|
110
117
|
work.n += constraints.length;
|
|
111
118
|
costs.solves++;
|
|
112
119
|
costs.solveRows += constraints.length;
|
|
120
|
+
if (more && !more())
|
|
121
|
+
return { kind: 'unknown' };
|
|
113
122
|
const steps = [];
|
|
114
123
|
const lins = [], stricts = [];
|
|
115
124
|
const push = (step, lin, strict = false) => (steps.push(step), lins.push(lin), stricts.push(strict), lins.length - 1);
|
|
@@ -154,6 +163,8 @@ export function solve(constraints, maxRows = 20_000, integral = true) {
|
|
|
154
163
|
const keys = [], negKeys = [];
|
|
155
164
|
const key = (r) => (keys[r] ??= keyOf(lins[r])), negKey = (r) => (negKeys[r] ??= keyOf(scale(lins[r], -1)));
|
|
156
165
|
for (let changed = true; changed && contradiction() === undefined;) {
|
|
166
|
+
if (more && !more())
|
|
167
|
+
return { kind: 'unknown' };
|
|
157
168
|
changed = false;
|
|
158
169
|
const byKey = new Map(rows.map(r => [key(r), r]));
|
|
159
170
|
for (const r of rows) {
|
|
@@ -201,6 +212,8 @@ export function solve(constraints, maxRows = 20_000, integral = true) {
|
|
|
201
212
|
return sig;
|
|
202
213
|
};
|
|
203
214
|
for (let found = contradiction(); found === undefined; found = contradiction()) {
|
|
215
|
+
if (more && !more())
|
|
216
|
+
return { kind: 'unknown' };
|
|
204
217
|
// Each variable's rows by sign, in one pass (variables in the order they first appear).
|
|
205
218
|
const index = new Map();
|
|
206
219
|
for (const r of rows)
|
|
@@ -233,13 +246,25 @@ export function solve(constraints, maxRows = 20_000, integral = true) {
|
|
|
233
246
|
break;
|
|
234
247
|
if (choice.pos.length * choice.neg.length > 5 * maxRows)
|
|
235
248
|
return { kind: 'unknown' };
|
|
236
|
-
|
|
237
|
-
|
|
249
|
+
if (!more) {
|
|
250
|
+
work.n += choice.pos.length * choice.neg.length;
|
|
251
|
+
if (!completeWorkProfile.enabled)
|
|
252
|
+
costs.fm += choice.pos.length * choice.neg.length;
|
|
253
|
+
}
|
|
238
254
|
exact &&= choice.isExact;
|
|
239
255
|
eliminated.push({ x: choice.x, rows: [...choice.pos, ...choice.neg] });
|
|
240
256
|
const next = rows.filter(r => (lins[r][choice.x] ?? 0) === 0);
|
|
241
257
|
for (const p of choice.pos)
|
|
242
258
|
for (const n of choice.neg) {
|
|
259
|
+
if (more && !more())
|
|
260
|
+
return { kind: 'unknown' };
|
|
261
|
+
if (completeWorkProfile.enabled)
|
|
262
|
+
startWork('fm', 1, 'Fourier-Motzkin pair');
|
|
263
|
+
if (more) {
|
|
264
|
+
work.n++;
|
|
265
|
+
if (!completeWorkProfile.enabled)
|
|
266
|
+
costs.fm++;
|
|
267
|
+
}
|
|
243
268
|
const a = lins[p][choice.x], b = -lins[n][choice.x];
|
|
244
269
|
const combined = pushExact({ kind: 'combine', a: p, b: n, ma: b / gcd(a, b), mb: a / gcd(a, b) }, add(scale(lins[p], b / gcd(a, b)), scale(lins[n], a / gcd(a, b))), stricts[p] || stricts[n]);
|
|
245
270
|
next.push(tighten(combined));
|
|
@@ -259,6 +284,8 @@ export function solve(constraints, maxRows = 20_000, integral = true) {
|
|
|
259
284
|
if (rows.length > maxRows || inexact)
|
|
260
285
|
return { kind: 'unknown' };
|
|
261
286
|
}
|
|
287
|
+
if (more && !more())
|
|
288
|
+
return { kind: 'unknown' };
|
|
262
289
|
const found = contradiction();
|
|
263
290
|
if (found !== undefined)
|
|
264
291
|
return inexact ? { kind: 'unknown' } : { kind: 'refuted', steps: prune(steps, found) };
|
|
@@ -426,8 +453,15 @@ export function refuteFast(constraints, maxRows = 2_000, integral = true) {
|
|
|
426
453
|
const eps = 1e-9;
|
|
427
454
|
for (let iter = 0; iter < 50 * (R + m); iter++) {
|
|
428
455
|
work.n += 1 + ((R * cols) >> 8);
|
|
456
|
+
if (completeWorkProfile.enabled) {
|
|
457
|
+
const cells = R * cols;
|
|
458
|
+
if (!Number.isSafeInteger(cells) || cells < 0)
|
|
459
|
+
throw new RangeError('unsafe float tableau size');
|
|
460
|
+
startWork('fcells', Math.floor(cells / 256), 'float tableau iteration');
|
|
461
|
+
}
|
|
429
462
|
costs.fpivots++;
|
|
430
|
-
|
|
463
|
+
if (!completeWorkProfile.enabled)
|
|
464
|
+
costs.fcells += (R * cols) >> 8;
|
|
431
465
|
// Bland's rule: the first column with a negative reduced cost enters (no cycling on degenerate systems).
|
|
432
466
|
let enter = -1;
|
|
433
467
|
for (let j = 0; j < cols; j++)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const stepWorkProfile: Readonly<{
|
|
2
|
+
id: "core-steps-v0";
|
|
3
|
+
enabled: boolean;
|
|
4
|
+
provisional: true;
|
|
5
|
+
}>;
|
|
6
|
+
export declare const provisionalStepWeights: Readonly<{
|
|
7
|
+
astNodes: 1;
|
|
8
|
+
evals: 1;
|
|
9
|
+
cubeTests: 1;
|
|
10
|
+
ticks: 1;
|
|
11
|
+
}>;
|
|
12
|
+
export declare function stepWork(): number;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// An opt-in research profile, not a calibration. D2 owns the eventual weights
|
|
2
|
+
// and W. Freeze the flag once: changing process.env during a proof must not
|
|
3
|
+
// remove already-counted work or change its unit definition.
|
|
4
|
+
import { coreMeter } from "./meter.js";
|
|
5
|
+
import { completeWorkProfile } from "./work-profile.js";
|
|
6
|
+
const environment = globalThis.process?.env;
|
|
7
|
+
export const stepWorkProfile = Object.freeze({ id: 'core-steps-v0', enabled: environment?.GDP_WORK_STEPS === '1' || completeWorkProfile.enabled, provisional: true });
|
|
8
|
+
export const provisionalStepWeights = Object.freeze({ astNodes: 1, evals: 1, cubeTests: 1, ticks: 1 });
|
|
9
|
+
export function stepWork() {
|
|
10
|
+
if (!stepWorkProfile.enabled || completeWorkProfile.enabled)
|
|
11
|
+
return 0;
|
|
12
|
+
return coreMeter.astNodes * provisionalStepWeights.astNodes + coreMeter.evals * provisionalStepWeights.evals
|
|
13
|
+
+ coreMeter.cubeTests * provisionalStepWeights.cubeTests + coreMeter.ticks * provisionalStepWeights.ticks;
|
|
14
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Law, type Machine } from './machine.js';
|
|
2
|
+
import { type Instances } from '../kernel/kernel.js';
|
|
3
|
+
export declare function strategyLawKey(law: Law): string;
|
|
4
|
+
export declare function strategyPremiseSelector(machine: Machine, family: readonly Law[], rejected: readonly Law[]): Readonly<{
|
|
5
|
+
find(predicate: (law: Law) => boolean): Law | undefined;
|
|
6
|
+
assertInstances: (instances: Instances) => void;
|
|
7
|
+
run<T>(instances: Instances, attempt: (laws: readonly Law[], instances: Instances) => T): T;
|
|
8
|
+
}>;
|