gdp-wired 0.48.0 → 0.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/core/bmc.js +10 -7
- package/dist/core/check.js +7 -2
- package/dist/core/count-attempt-work.d.ts +29 -0
- package/dist/core/count-attempt-work.js +96 -0
- package/dist/core/count-boolean-partition.d.ts +5 -0
- package/dist/core/count-boolean-partition.js +47 -0
- package/dist/core/count-bounded-quotient.d.ts +2 -0
- package/dist/core/count-bounded-quotient.js +13 -0
- package/dist/core/count-case-compose.d.ts +20 -0
- package/dist/core/count-case-compose.js +289 -0
- package/dist/core/count-cases.js +3 -2
- package/dist/core/count-cert-rename.d.ts +10 -0
- package/dist/core/count-cert-rename.js +69 -0
- package/dist/core/count-cert-transport.d.ts +10 -2
- package/dist/core/count-cert-transport.js +60 -9
- package/dist/core/count-certificate-minimize.d.ts +57 -0
- package/dist/core/count-certificate-minimize.js +263 -0
- package/dist/core/count-closed-family.d.ts +32 -0
- package/dist/core/count-closed-family.js +143 -0
- package/dist/core/count-closing-budget.d.ts +10 -0
- package/dist/core/count-closing-budget.js +49 -0
- package/dist/core/count-closing-needs.d.ts +5 -0
- package/dist/core/count-closing-needs.js +9 -0
- package/dist/core/count-component-budget.d.ts +5 -0
- package/dist/core/count-component-budget.js +9 -0
- package/dist/core/count-copy-shape.d.ts +11 -0
- package/dist/core/count-copy-shape.js +40 -0
- package/dist/core/count-disjoint-funding.d.ts +75 -0
- package/dist/core/count-disjoint-funding.js +284 -0
- package/dist/core/count-emitter-frame-pool.d.ts +23 -0
- package/dist/core/count-emitter-frame-pool.js +87 -0
- package/dist/core/count-final-step.d.ts +5 -0
- package/dist/core/count-final-step.js +20 -0
- package/dist/core/count-fixed-frame.d.ts +4 -0
- package/dist/core/count-fixed-frame.js +30 -0
- package/dist/core/count-frames.d.ts +25 -0
- package/dist/core/count-frames.js +118 -0
- package/dist/core/count-frozen-guard.d.ts +2 -0
- package/dist/core/count-frozen-guard.js +31 -0
- package/dist/core/count-generation-phase.d.ts +7 -0
- package/dist/core/count-generation-phase.js +33 -0
- package/dist/core/count-guard-composition.d.ts +12 -0
- package/dist/core/count-guard-composition.js +48 -0
- package/dist/core/count-guard-context.d.ts +11 -0
- package/dist/core/count-guard-context.js +50 -0
- package/dist/core/count-guard-facts.d.ts +50 -0
- package/dist/core/count-guard-facts.js +97 -0
- package/dist/core/count-guard-proposals.d.ts +7 -0
- package/dist/core/count-guard-proposals.js +106 -0
- package/dist/core/count-guard-shape.d.ts +18 -0
- package/dist/core/count-guard-shape.js +100 -0
- package/dist/core/count-guard-tree.d.ts +17 -0
- package/dist/core/count-guard-tree.js +125 -0
- package/dist/core/count-leader-facts.d.ts +10 -0
- package/dist/core/count-leader-facts.js +52 -0
- package/dist/core/count-leader.d.ts +10 -0
- package/dist/core/count-leader.js +331 -0
- package/dist/core/count-lemma-transport.d.ts +8 -0
- package/dist/core/count-lemma-transport.js +47 -0
- package/dist/core/count-lifted-budget.d.ts +54 -0
- package/dist/core/count-lifted-budget.js +97 -0
- package/dist/core/count-lifted-copy.d.ts +3 -0
- package/dist/core/count-lifted-copy.js +166 -0
- package/dist/core/count-lifted-increment.d.ts +3 -0
- package/dist/core/count-lifted-increment.js +146 -0
- package/dist/core/count-lifted-load.d.ts +5 -0
- package/dist/core/count-lifted-load.js +179 -0
- package/dist/core/count-lifted-prerequisite.d.ts +14 -0
- package/dist/core/count-lifted-prerequisite.js +53 -0
- package/dist/core/count-lifted-replacement.d.ts +3 -0
- package/dist/core/count-lifted-replacement.js +540 -0
- package/dist/core/count-lifted-shape.d.ts +63 -0
- package/dist/core/count-lifted-shape.js +115 -0
- package/dist/core/count-lifted-strategy.d.ts +7 -0
- package/dist/core/count-lifted-strategy.js +226 -0
- package/dist/core/count-lifted-transports.d.ts +32 -0
- package/dist/core/count-lifted-transports.js +293 -0
- package/dist/core/count-load-shape.d.ts +17 -0
- package/dist/core/count-load-shape.js +67 -0
- package/dist/core/count-minimal-view.d.ts +26 -0
- package/dist/core/count-minimal-view.js +46 -0
- package/dist/core/count-operation-observation.d.ts +9 -0
- package/dist/core/count-operation-observation.js +22 -0
- package/dist/core/count-operation-order.d.ts +5 -0
- package/dist/core/count-operation-order.js +4 -0
- package/dist/core/count-phase.d.ts +9 -0
- package/dist/core/count-phase.js +127 -0
- package/dist/core/count-premise-search.d.ts +9 -0
- package/dist/core/count-premise-search.js +41 -0
- package/dist/core/count-premise-view.d.ts +19 -0
- package/dist/core/count-premise-view.js +220 -0
- package/dist/core/count-prerequisite-components.d.ts +67 -0
- package/dist/core/count-prerequisite-components.js +239 -0
- package/dist/core/count-prerequisite-memory.d.ts +24 -0
- package/dist/core/count-prerequisite-memory.js +37 -0
- package/dist/core/count-prerequisite-plan.d.ts +12 -0
- package/dist/core/count-prerequisite-plan.js +88 -0
- package/dist/core/count-primitive-budget.d.ts +1 -0
- package/dist/core/count-primitive-budget.js +8 -0
- package/dist/core/count-project-free.d.ts +3 -0
- package/dist/core/count-project-free.js +24 -0
- package/dist/core/count-project-witness.d.ts +4 -0
- package/dist/core/count-project-witness.js +48 -0
- package/dist/core/count-proof-rescope.d.ts +14 -0
- package/dist/core/count-proof-rescope.js +71 -0
- package/dist/core/count-proof-scope.d.ts +68 -0
- package/dist/core/count-proof-scope.js +333 -0
- package/dist/core/count-prune-owned-root.d.ts +5 -0
- package/dist/core/count-prune-owned-root.js +27 -0
- package/dist/core/count-query-context.d.ts +3 -0
- package/dist/core/count-query-context.js +7 -0
- package/dist/core/count-query.d.ts +15 -0
- package/dist/core/count-query.js +59 -0
- package/dist/core/count-quorum-leaf.d.ts +9 -0
- package/dist/core/count-quorum-leaf.js +38 -0
- package/dist/core/count-reachability-budget.d.ts +1 -0
- package/dist/core/count-reachability-budget.js +7 -0
- package/dist/core/count-reachability-reconcile.d.ts +11 -0
- package/dist/core/count-reachability-reconcile.js +19 -0
- package/dist/core/count-reachability.d.ts +50 -0
- package/dist/core/count-reachability.js +351 -0
- package/dist/core/count-rebase-path.d.ts +9 -0
- package/dist/core/count-rebase-path.js +68 -0
- package/dist/core/count-recipe-context.d.ts +45 -0
- package/dist/core/count-recipe-context.js +71 -0
- package/dist/core/count-recipe-controller.d.ts +115 -0
- package/dist/core/count-recipe-controller.js +417 -0
- package/dist/core/count-recipe-graph.d.ts +36 -0
- package/dist/core/count-recipe-graph.js +211 -0
- package/dist/core/count-recovery/conditional-check-cache.js +3 -2
- package/dist/core/count-recovery/conditional-cuts.js +5 -4
- package/dist/core/count-recovery/conditional-proof.d.ts +37 -3
- package/dist/core/count-recovery/conditional-proof.js +72 -30
- package/dist/core/count-recovery/derivability-closure.js +2 -1
- package/dist/core/count-recovery/guard-cases.js +2 -1
- package/dist/core/count-recovery/reframe-tree.d.ts +2 -0
- package/dist/core/count-recovery/reframe-tree.js +24 -0
- package/dist/core/count-recovery/replay-linear-skeleton.d.ts +2 -0
- package/dist/core/count-recovery/replay-linear-skeleton.js +28 -0
- package/dist/core/count-recovery/row-cases.js +2 -1
- package/dist/core/count-rejection-budget.d.ts +8 -0
- package/dist/core/count-rejection-budget.js +15 -0
- package/dist/core/count-replacement.d.ts +5 -0
- package/dist/core/count-replacement.js +129 -0
- package/dist/core/count-replay-diagnostic.d.ts +21 -0
- package/dist/core/count-replay-diagnostic.js +49 -0
- package/dist/core/count-replay-skeleton.d.ts +4 -0
- package/dist/core/count-replay-skeleton.js +28 -0
- package/dist/core/count-rescope-funding.d.ts +3 -0
- package/dist/core/count-rescope-funding.js +17 -0
- package/dist/core/count-restrictions.d.ts +11 -0
- package/dist/core/count-restrictions.js +31 -0
- package/dist/core/count-retry-budget.d.ts +67 -0
- package/dist/core/count-retry-budget.js +114 -0
- package/dist/core/count-retry-round.d.ts +24 -0
- package/dist/core/count-retry-round.js +44 -0
- package/dist/core/count-row-agreement.d.ts +35 -0
- package/dist/core/count-row-agreement.js +270 -0
- package/dist/core/count-row-aliases.d.ts +3 -0
- package/dist/core/count-row-aliases.js +59 -0
- package/dist/core/count-row-composition.d.ts +6 -0
- package/dist/core/count-row-composition.js +55 -0
- package/dist/core/count-row-copy-linear.d.ts +4 -0
- package/dist/core/count-row-copy-linear.js +83 -0
- package/dist/core/count-row-copy.d.ts +4 -0
- package/dist/core/count-row-copy.js +94 -0
- package/dist/core/count-row-policy.d.ts +3 -0
- package/dist/core/count-row-policy.js +56 -0
- package/dist/core/count-row-reindex.d.ts +11 -0
- package/dist/core/count-row-reindex.js +126 -0
- package/dist/core/count-row-support.d.ts +9 -0
- package/dist/core/count-row-support.js +42 -0
- package/dist/core/count-row-symmetry.d.ts +7 -0
- package/dist/core/count-row-symmetry.js +100 -0
- package/dist/core/count-scope-hyps.d.ts +2 -0
- package/dist/core/count-scope-hyps.js +163 -0
- package/dist/core/count-scope-row-reuse.d.ts +3 -0
- package/dist/core/count-scope-row-reuse.js +92 -0
- package/dist/core/count-search-allowance.d.ts +1 -0
- package/dist/core/count-search-allowance.js +17 -0
- package/dist/core/count-stabilize-tree.d.ts +9 -0
- package/dist/core/count-stabilize-tree.js +35 -0
- package/dist/core/count-stage-trace.d.ts +8 -0
- package/dist/core/count-stage-trace.js +45 -0
- package/dist/core/count-strategies.d.ts +16 -0
- package/dist/core/count-strategies.js +155 -0
- package/dist/core/count-strategy-premises.d.ts +5 -0
- package/dist/core/count-strategy-premises.js +14 -0
- package/dist/core/count-strategy.d.ts +41 -0
- package/dist/core/count-strategy.js +76 -0
- package/dist/core/count-support.js +3 -2
- package/dist/core/count-tier-budget.d.ts +14 -0
- package/dist/core/count-tier-budget.js +64 -0
- package/dist/core/count-unwritten-prefix.d.ts +24 -0
- package/dist/core/count-unwritten-prefix.js +97 -0
- package/dist/core/count-write-shape.d.ts +15 -0
- package/dist/core/count-write-shape.js +73 -0
- package/dist/core/counts.d.ts +37 -13
- package/dist/core/counts.js +990 -127
- package/dist/core/cycles.js +5 -4
- package/dist/core/cyclic.js +11 -10
- package/dist/core/data.js +16 -15
- package/dist/core/dsl-deadline.d.ts +3 -0
- package/dist/core/dsl-deadline.js +27 -0
- package/dist/core/dsl.d.ts +9 -0
- package/dist/core/dsl.js +156 -51
- package/dist/core/evaluation-admission.d.ts +1 -0
- package/dist/core/evaluation-admission.js +3 -0
- package/dist/core/exists.d.ts +6 -1
- package/dist/core/exists.js +51 -9
- package/dist/core/field-laws.d.ts +3 -1
- package/dist/core/field-laws.js +140 -2
- package/dist/core/finite-houdini.d.ts +6 -0
- package/dist/core/finite-houdini.js +63 -21
- package/dist/core/finite-tiny.js +95 -67
- package/dist/core/fixtures/count-completion/paxos-decision.json +1 -0
- package/dist/core/fresh.js +5 -1
- package/dist/core/infer.js +45 -30
- package/dist/core/kind.js +2 -1
- package/dist/core/lemma-cuts.js +11 -10
- package/dist/core/linear-admission.d.ts +14 -0
- package/dist/core/linear-admission.js +151 -0
- package/dist/core/machine.d.ts +5 -2
- package/dist/core/machine.js +105 -31
- package/dist/core/meter.d.ts +22 -0
- package/dist/core/meter.js +34 -0
- package/dist/core/nonterm.js +4 -3
- package/dist/core/prover-row-budget.d.ts +3 -0
- package/dist/core/prover-row-budget.js +106 -0
- package/dist/core/quorum-laws.d.ts +21 -1
- package/dist/core/quorum-laws.js +27 -3
- package/dist/core/rationals.js +3 -2
- package/dist/core/rejection-discovery.d.ts +34 -0
- package/dist/core/rejection-discovery.js +36 -0
- package/dist/core/rejection-stage.d.ts +39 -0
- package/dist/core/rejection-stage.js +205 -0
- package/dist/core/request-quotient.d.ts +8 -0
- package/dist/core/request-quotient.js +299 -0
- package/dist/core/row-agreement-shape.d.ts +15 -0
- package/dist/core/row-agreement-shape.js +68 -0
- package/dist/core/runtime-wall.d.ts +2 -0
- package/dist/core/search-policy.d.ts +15 -0
- package/dist/core/search-policy.js +68 -0
- package/dist/core/solver.d.ts +1 -1
- package/dist/core/solver.js +40 -6
- package/dist/core/step-work.d.ts +12 -0
- package/dist/core/step-work.js +14 -0
- package/dist/core/strategy-premises.d.ts +8 -0
- package/dist/core/strategy-premises.js +64 -0
- package/dist/core/system.js +4 -3
- package/dist/core/table-admission.d.ts +1 -0
- package/dist/core/table-admission.js +3 -0
- package/dist/core/trace-clock.d.ts +3 -0
- package/dist/core/trace-clock.js +16 -0
- package/dist/core/transfer.js +3 -2
- package/dist/core/translate.js +16 -3
- package/dist/core/wall.d.ts +6 -1
- package/dist/core/wall.js +23 -9
- package/dist/core/watch.d.ts +1 -1
- package/dist/core/watch.js +13 -4
- package/dist/core/work-admission.d.ts +164 -0
- package/dist/core/work-admission.js +418 -0
- package/dist/core/work-amount.d.ts +21 -0
- package/dist/core/work-amount.js +80 -0
- package/dist/core/work-collections.d.ts +11 -0
- package/dist/core/work-collections.js +198 -0
- package/dist/core/work-kinds.d.ts +11 -0
- package/dist/core/work-kinds.js +9 -0
- package/dist/core/work-meter.d.ts +8 -0
- package/dist/core/work-meter.js +83 -0
- package/dist/core/work-observe.d.ts +12 -0
- package/dist/core/work-observe.js +39 -0
- package/dist/core/work-profile.d.ts +10 -0
- package/dist/core/work-profile.js +21 -0
- package/dist/core/work-refusal.d.ts +1 -0
- package/dist/core/work-refusal.js +6 -0
- package/dist/interchange/format.js +2 -0
- package/dist/kernel/cdcl.js +93 -40
- package/dist/kernel/epr.js +23 -8
- package/dist/kernel/kernel.d.ts +47 -1
- package/dist/kernel/kernel.js +417 -68
- package/dist/kernel/prove.d.ts +49 -3
- package/dist/kernel/prove.js +468 -122
- package/dist/kernel/prover-rows.d.ts +1 -0
- package/dist/kernel/prover-rows.js +12 -1
- package/dist/kernel/reader.d.ts +1 -1
- package/dist/kernel/reader.js +57 -12
- package/dist/kernel/simplex.js +9 -2
- package/dist/lean-kernel/emit.d.ts +9 -1
- package/dist/lean-kernel/emit.js +144 -22
- package/dist/lean-kernel/legacy-family-library.d.ts +1 -0
- package/dist/lean-kernel/legacy-family-library.js +5 -0
- package/dist/lean-kernel/library.js +3 -3
- package/package.json +1 -1
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { liftedLeafUntil, withLiftedLeaf } from "./count-lifted-budget.js";
|
|
2
|
+
import { FrameFactPool } from "./count-emitter-frame-pool.js";
|
|
3
|
+
// A row-copy STEP proposal from discovered source/target roles and the lifted
|
|
4
|
+
// law's own tuples. All transports are ordinary checked per-key linear facts.
|
|
5
|
+
import { atMost, n, not, same, walkOnce, x } from "./machine.js";
|
|
6
|
+
import { check, checkMC, countedObligations, frameOk, framePath, mcGoal, substE } from "../kernel/kernel.js";
|
|
7
|
+
import { deferIntermediateCountChecks } from "./count-strategy.js";
|
|
8
|
+
import { discoverLiftedCountGuard } from "./count-lifted-shape.js";
|
|
9
|
+
import { discoverCountRowCopy } from "./count-copy-shape.js";
|
|
10
|
+
import { proposeLiftedTransports } from "./count-lifted-transports.js";
|
|
11
|
+
import { countsForReads } from "./count-facts.js";
|
|
12
|
+
import { countFrameConditions, fixedCountFrameCase, ownCountLawInstance } from "./count-frames.js";
|
|
13
|
+
import { fullRate, fullWork, late, rowsAt, withDeadline } from "../kernel/prove.js";
|
|
14
|
+
import { growCdcl } from "../kernel/cdcl.js";
|
|
15
|
+
import { add, k, scale, solve } from "./solver.js";
|
|
16
|
+
import { countGuardTree } from "./count-guard-tree.js";
|
|
17
|
+
import { inlineFrozenGuard } from "./count-frozen-guard.js";
|
|
18
|
+
import { guardLinearFact } from "./count-guard-facts.js";
|
|
19
|
+
import { rebasePath } from "./count-rebase-path.js";
|
|
20
|
+
import { replayLinearSkeleton } from "./count-replay-skeleton.js";
|
|
21
|
+
import { stabilizeGuardedTree } from "./count-stabilize-tree.js";
|
|
22
|
+
const json = (value) => JSON.stringify(value);
|
|
23
|
+
export function proveLiftedCountCopy(m, family, law, until, requestFor, observe, options = {}) {
|
|
24
|
+
if (!family.includes(law))
|
|
25
|
+
return;
|
|
26
|
+
return withDeadline(until, () => {
|
|
27
|
+
const deferred = deferIntermediateCountChecks(options), accepts = (...args) => deferred || check(...args);
|
|
28
|
+
const shape = discoverLiftedCountGuard(m, law, family), choice = fixedCountFrameCase(m), copy = shape && choice && discoverCountRowCopy(m, shape.countShape, choice);
|
|
29
|
+
if (!shape || !choice || !copy || !m.pre || late(until))
|
|
30
|
+
return;
|
|
31
|
+
const stopped = {}, decline = (reason) => { observe?.({ stage: 'copy-decline', reason }); throw stopped; };
|
|
32
|
+
let framePool;
|
|
33
|
+
try {
|
|
34
|
+
const from = x(copy.from), to = x(copy.to), a = x(law.forall + '#'), b = x(law.keys[0]), transportRegions = proposeLiftedTransports(m, family, law, choice.value);
|
|
35
|
+
if (transportRegions?.length !== 4)
|
|
36
|
+
return decline('transport-plan');
|
|
37
|
+
const tuples = transportRegions[0].tuples, instances = ownCountLawInstance(law, {});
|
|
38
|
+
instances[law.name] = tuples.flat();
|
|
39
|
+
const packet = (terms) => countedObligations(m, family, { [law.name]: { [law.name]: terms } }, family.indexOf(law)).at(-1);
|
|
40
|
+
const step = packet(instances[law.name]), reads = requestFor(step.goal, step.decls).reads, counts = countsForReads(step.decls, reads);
|
|
41
|
+
if (!counts)
|
|
42
|
+
return decline('counts');
|
|
43
|
+
const targetMaps = new Set(shape.countMaps), postReads = reads.filter(read => read[1].endsWith('#') && targetMaps.has(read[1].slice(0, -1)));
|
|
44
|
+
const read = (map, key) => reads.find(r => r[1] === map && json(r[2]) === json(key))?.[0] ?? decline('missing-copy-read');
|
|
45
|
+
const bound = m.counts?.[shape.origin.rowCount]?.below;
|
|
46
|
+
if (!bound)
|
|
47
|
+
return decline('bound');
|
|
48
|
+
let prefix = 'rowCopy$';
|
|
49
|
+
const scope = json([m, family, reads]);
|
|
50
|
+
while (scope.includes(prefix))
|
|
51
|
+
prefix = '$' + prefix;
|
|
52
|
+
const caseInsts = transportRegions.map((region, i) => postReads.flatMap(([post, map, key], j) => {
|
|
53
|
+
const vars = Object.fromEntries([law.forall + '#', ...law.keys].map((name, index) => [name, region.activeTuple[index]])), targetKey = substE(key, { vars, maps: {}, flags: {} });
|
|
54
|
+
const relation = region.relations.find(relation => relation.post[1] === map && json(relation.post[2]) === json(key) && relation.target?.[1] === map.slice(0, -1) && json(relation.target[2]) === json(targetKey));
|
|
55
|
+
if (!relation?.target || relation.kind === 'zero')
|
|
56
|
+
return decline('unmatched-copy-transport');
|
|
57
|
+
const pre = read(relation.target[1], relation.target[2]), forward = { wit: prefix + i + '$' + j, below: bound, terms: [[1, post], [-1, pre]], unit: 0 };
|
|
58
|
+
return relation.kind === 'equality' ? [forward, { ...forward, wit: forward.wit + '$reverse', terms: [[1, pre], [-1, post]] }] : [forward];
|
|
59
|
+
}));
|
|
60
|
+
observe?.({ stage: 'copy-match', regions: transportRegions.length, tuples: tuples.length, relations: caseInsts.map(group => group.length) });
|
|
61
|
+
const unique = new Map();
|
|
62
|
+
for (const group of caseInsts)
|
|
63
|
+
for (let i = 0; i < group.length; i++) {
|
|
64
|
+
const inst = group[i], key = json(inst.terms), old = unique.get(key);
|
|
65
|
+
if (old)
|
|
66
|
+
group[i] = old;
|
|
67
|
+
else
|
|
68
|
+
unique.set(key, inst);
|
|
69
|
+
}
|
|
70
|
+
const request = { reads, insts: [], picks: [] }, goal = mcGoal(step.goal.hyps, step.decls, request);
|
|
71
|
+
if (!goal)
|
|
72
|
+
return decline('encoding');
|
|
73
|
+
const countMaps = new Set(step.decls.map(decl => decl.map)), scalarHyps = step.goal.hyps.filter(hyp => { let counted = false; walkOnce(hyp, (node) => { if (node.op === 'get' && countMaps.has(node.map))
|
|
74
|
+
counted = true; }); return !counted; }), caseHyps = tuples.map(tuple => packet(tuple).goal.hyps);
|
|
75
|
+
const frames = [], lins = [], facts = new Map(), linearCases = new Set(), composed = new Map(), roots = new Map();
|
|
76
|
+
const active = inlineFrozenGuard(m.step.flags ?? {}, copy.guard), domain = { op: 'and', xs: [a, b, from, to].flatMap(row => [{ op: '<', a: row, b: bound }, { op: '<', a: row, b: n(shape.origin.width) }]) };
|
|
77
|
+
const ask = (path, index, frame = false, stage = 'case') => {
|
|
78
|
+
if (late(until))
|
|
79
|
+
return;
|
|
80
|
+
if (frame)
|
|
81
|
+
for (const [post, map, key] of postReads) {
|
|
82
|
+
const cut = { post, pre: read(map.slice(0, -1), key), when: [...path.values()].map(atom => atom.holds ? atom.lin : add(scale(atom.lin, -1), k(1))) };
|
|
83
|
+
if (options.emitterFramePool) {
|
|
84
|
+
(framePool ??= new FrameFactPool(counts, frames, until)).offer(cut);
|
|
85
|
+
}
|
|
86
|
+
else if (frameOk(counts, cut))
|
|
87
|
+
frames.push(cut);
|
|
88
|
+
}
|
|
89
|
+
const root = framePath(frames, [], path, [], lins), view = mcGoal(stage === 'fact' ? scalarHyps : caseHyps[index], step.decls, request), before = fullWork(), remember = (tree) => { roots.set(tree, new Map(root)); return tree; };
|
|
90
|
+
return withLiftedLeaf(until, options, 500, 'leaf:copy:' + stage + ':' + index, deadline => {
|
|
91
|
+
if (!view)
|
|
92
|
+
return;
|
|
93
|
+
const cached = composed.get(index);
|
|
94
|
+
if (cached && stage === 'linear-composed') {
|
|
95
|
+
const end = options.leafWork ? deadline : liftedLeafUntil(deadline, options, 25), tree = rebasePath(goal, cached.tree, cached.path, root, end, goal) ?? replayLinearSkeleton(goal, cached.tree, root, end, { deferCheck: deferred });
|
|
96
|
+
if (tree && accepts(goal, tree, root)) {
|
|
97
|
+
observe?.({ stage, index, reused: true, units: (fullWork() - before) / fullRate });
|
|
98
|
+
return remember(tree);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const direct = solve(rowsAt(view, root), 1000);
|
|
102
|
+
if (direct.kind === 'refuted') {
|
|
103
|
+
const tree = rebasePath(view, { leaf: direct.steps }, root, root, deadline, goal);
|
|
104
|
+
if (tree && !late(until))
|
|
105
|
+
return remember(tree);
|
|
106
|
+
}
|
|
107
|
+
const result = growCdcl(view, root, { nodes: 0, until: deadline }), tree = 'tree' in result ? rebasePath(view, result.tree, root, root, deadline, goal) : undefined;
|
|
108
|
+
observe?.({ stage, index, checked: !!tree, units: (fullWork() - before) / fullRate, ...(!('tree' in result) ? { outcome: result.stuck, witness: result.witness } : {}) });
|
|
109
|
+
if (!tree || late(until))
|
|
110
|
+
return;
|
|
111
|
+
if (stage === 'linear-composed' && accepts(goal, tree, root))
|
|
112
|
+
composed.set(index, { tree, path: root });
|
|
113
|
+
return remember(tree);
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
const transport = (path, index) => {
|
|
117
|
+
if (!linearCases.has(index)) {
|
|
118
|
+
for (const inst of caseInsts[index]) {
|
|
119
|
+
const dependencies = new Set();
|
|
120
|
+
for (const [, id] of inst.terms) {
|
|
121
|
+
const count = reads.find(read => read[0] === id);
|
|
122
|
+
if (count[1].endsWith('#'))
|
|
123
|
+
walkOnce(count[2], (node) => { if (node.op === 'var')
|
|
124
|
+
dependencies.add(node.name); });
|
|
125
|
+
}
|
|
126
|
+
const when = [m.pre, domain, active];
|
|
127
|
+
if (dependencies.has(law.forall + '#'))
|
|
128
|
+
when.push(index >= 2 ? same(a, to) : not(same(a, to)));
|
|
129
|
+
if (dependencies.has(law.keys[0]))
|
|
130
|
+
when.push(index % 2 ? same(b, to) : not(same(b, to)));
|
|
131
|
+
const key = json([inst.terms, when]);
|
|
132
|
+
if (facts.has(key))
|
|
133
|
+
continue;
|
|
134
|
+
const before = fullWork(), fact = withLiftedLeaf(until, options, 100, 'leaf:copy:transport:' + index, end => guardLinearFact(step.decls, reads, { name: 'row copy transport', kind: 'ordinary-copy', when, terms: inst.terms }, end, event => { if (event.outcome !== 'proof' && event.outcome !== 'proposal')
|
|
135
|
+
observe?.({ stage: 'copy-transport-failure', index, witness: event.witness, outcome: event.outcome }); }, 'grow', { deferCheck: deferred }));
|
|
136
|
+
observe?.({ stage: 'copy-transport', index, constructed: !!fact, checked: !!fact && fact.status !== 'unchecked', deferred: fact?.status === 'unchecked', units: (fullWork() - before) / fullRate });
|
|
137
|
+
if (!fact)
|
|
138
|
+
return;
|
|
139
|
+
facts.set(key, fact.cut);
|
|
140
|
+
lins.push(fact.cut);
|
|
141
|
+
}
|
|
142
|
+
linearCases.add(index);
|
|
143
|
+
}
|
|
144
|
+
return ask(path, index, false, 'linear-composed');
|
|
145
|
+
};
|
|
146
|
+
const split = countGuardTree(until), regions = (path) => split.condition(same(a, to), path, p => split.condition(same(b, to), p, q => transport(q, 3), q => transport(q, 2)), p => split.condition(same(b, to), p, q => transport(q, 1), q => transport(q, 0)));
|
|
147
|
+
const copies = (path) => split.condition(atMost(to, from), path, regions, regions);
|
|
148
|
+
const run = (path) => split.rows(countFrameConditions(choice), path, p => split.condition(domain, p, q => split.condition(active, q, copies, q => ask(q, 0, true)), q => ask(q, 0)), p => ask(p, 0));
|
|
149
|
+
const tree = split.condition(m.pre, new Map(), run, path => ask(path, 0, false, 'outside-pre'));
|
|
150
|
+
if (!tree)
|
|
151
|
+
return decline('tree');
|
|
152
|
+
const stable = stabilizeGuardedTree(goal, tree, frames, lins, roots, until, { deferCheck: deferred });
|
|
153
|
+
if (!stable.tree || late(until))
|
|
154
|
+
return decline('stabilization');
|
|
155
|
+
if (framePool)
|
|
156
|
+
observe?.({ stage: 'emitter-frame-pool', emitter: 'copy', ...framePool.stats() });
|
|
157
|
+
const cert = { ...request, frames, lins, tree: stable.tree };
|
|
158
|
+
return (options.deferToComposition || checkMC(step.goal.hyps, step.decls, cert)) && !late(until) ? { instances, certs: { [step.goal.name]: cert }, ...(deferred ? { status: 'unchecked' } : {}) } : undefined;
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
if (error === stopped)
|
|
162
|
+
return;
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type Law, type Machine } from './machine.js';
|
|
2
|
+
import { type CountRequestBuilder, type CountStrategyOptions, type CountStrategyProof } from './count-strategy.js';
|
|
3
|
+
export declare function proveLiftedCountIncrement(m: Machine, family: Law[], law: Law, until: number, requestFor: CountRequestBuilder, observe?: (event: Record<string, unknown>) => void, options?: CountStrategyOptions): CountStrategyProof | undefined;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { withLiftedLeaf } from "./count-lifted-budget.js";
|
|
2
|
+
import { FrameFactPool } from "./count-emitter-frame-pool.js";
|
|
3
|
+
// Conditional threshold-increment STEP proposal. Role discovery and the
|
|
4
|
+
// family's no-quorum premise select witnesses; only the native checker accepts.
|
|
5
|
+
import { all, atMost, get, less, n, plus, times, walkOnce, x } from "./machine.js";
|
|
6
|
+
import { checkMC, countedObligations, frameOk, framePath, mcGoal } from "../kernel/kernel.js";
|
|
7
|
+
import { deferIntermediateCountChecks } from "./count-strategy.js";
|
|
8
|
+
import { discoverLiftedCountGuard, discoverLiftedCountOperation } from "./count-lifted-shape.js";
|
|
9
|
+
import { discoverCountGuardShape } from "./count-guard-shape.js";
|
|
10
|
+
import { discoverLiftedCountPrerequisites } from "./count-lifted-prerequisite.js";
|
|
11
|
+
import { countFrameConditions, fixedCountFrameCase, ownCountLawInstance } from "./count-frames.js";
|
|
12
|
+
import { countsForReads } from "./count-facts.js";
|
|
13
|
+
import { matchLiftedCountBodies } from "./count-lifted-transports.js";
|
|
14
|
+
import { fullRate, fullWork, late, withDeadline } from "../kernel/prove.js";
|
|
15
|
+
import { growCdcl } from "../kernel/cdcl.js";
|
|
16
|
+
import { add, k, scale } from "./solver.js";
|
|
17
|
+
import { countGuardTree } from "./count-guard-tree.js";
|
|
18
|
+
import { inlineFrozenGuard } from "./count-frozen-guard.js";
|
|
19
|
+
import { minimalTransportView, minimalViewFirst } from "./count-minimal-view.js";
|
|
20
|
+
import { copyQueryContext } from "./count-query-context.js";
|
|
21
|
+
import { stabilizeGuardedTree } from "./count-stabilize-tree.js";
|
|
22
|
+
const json = (value) => JSON.stringify(value);
|
|
23
|
+
export function proveLiftedCountIncrement(m, family, law, until, requestFor, observe, options = {}) {
|
|
24
|
+
if (!family.includes(law))
|
|
25
|
+
return;
|
|
26
|
+
return withDeadline(until, () => {
|
|
27
|
+
const deferred = deferIntermediateCountChecks(options);
|
|
28
|
+
const shape = discoverLiftedCountGuard(m, law, family), choice = fixedCountFrameCase(m), operation = shape && choice && discoverLiftedCountOperation(m, shape, choice.value);
|
|
29
|
+
if (!shape || !choice || operation?.kind !== 'threshold-increment' || !('write' in operation) || !m.pre || late(until)) {
|
|
30
|
+
observe?.({ stage: 'increment-decline', reason: 'shape-or-operation' });
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const write = operation.write;
|
|
34
|
+
if (write.increment !== 1) {
|
|
35
|
+
observe?.({ stage: 'increment-decline', reason: 'nonincrement-write' });
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const stopped = {}, decline = (reason) => { observe?.({ stage: 'increment-decline', reason }); throw stopped; };
|
|
39
|
+
let framePool;
|
|
40
|
+
try {
|
|
41
|
+
const lower = discoverLiftedCountPrerequisites(m, law, family).flatMap(prerequisite => {
|
|
42
|
+
const found = discoverCountGuardShape(m, prerequisite.law, family);
|
|
43
|
+
if (!found || found.rowMap !== shape.origin.rowCount || found.memberField !== shape.countShape.memberField || found.thresholdField !== shape.countShape.thresholdField)
|
|
44
|
+
return [];
|
|
45
|
+
return [{ law: prerequisite.law, shape: found }];
|
|
46
|
+
});
|
|
47
|
+
if (lower.length !== 1)
|
|
48
|
+
return decline('no-unique-guarded-vote-premise');
|
|
49
|
+
const premise = lower[0], twins = new Set(shape.origin.twins.map(twin => twin.row)), votes = shape.countMaps.filter(map => map !== shape.origin.rowCount && !twins.has(map));
|
|
50
|
+
if (votes.length !== 1)
|
|
51
|
+
return decline('disabled-count');
|
|
52
|
+
const vote = votes[0], a = x(law.forall + '#'), b = x(law.keys[0]), actor = x(write.source), rowMap = shape.origin.rowCount;
|
|
53
|
+
let prefix = 'increment$';
|
|
54
|
+
const scope = json([m, family]);
|
|
55
|
+
while (scope.includes(prefix))
|
|
56
|
+
prefix = '$' + prefix;
|
|
57
|
+
const labels = Array.from({ length: 7 }, (_, index) => prefix + 'w' + index), instances = ownCountLawInstance(law, { [premise.law.name]: [actor, a, actor, b] });
|
|
58
|
+
const ownFlags = options.slicedLemmas ? (() => {
|
|
59
|
+
const ownFlags = new Set(), flagQueue = [write.guard];
|
|
60
|
+
walkOnce([m.pre, m.assume], (node) => { if (node.op === 'flag')
|
|
61
|
+
flagQueue.push(node.name); });
|
|
62
|
+
while (flagQueue.length) {
|
|
63
|
+
const name = flagQueue.pop();
|
|
64
|
+
if (ownFlags.has(name))
|
|
65
|
+
continue;
|
|
66
|
+
ownFlags.add(name);
|
|
67
|
+
walkOnce(m.step.flags?.[name], (node) => { if (node.op === 'flag')
|
|
68
|
+
flagQueue.push(node.name); });
|
|
69
|
+
}
|
|
70
|
+
observe?.({ stage: 'own-operation-flags', names: [...ownFlags].filter(name => m.step.flags?.[name]?.op === 'all').sort() });
|
|
71
|
+
return ownFlags;
|
|
72
|
+
})() : undefined;
|
|
73
|
+
for (const [name, flag] of Object.entries(m.step.flags ?? {}))
|
|
74
|
+
if (flag.op === 'all' && (!ownFlags || ownFlags.has(name)))
|
|
75
|
+
instances['?' + name] = labels.map(x);
|
|
76
|
+
const step = countedObligations(m, family, { [law.name]: instances }, family.indexOf(law)).at(-1), reads = [...requestFor(step.goal, step.decls).reads];
|
|
77
|
+
const bind = (map, key) => { const old = reads.find(read => read[1] === map && json(read[2]) === json(key)); if (old)
|
|
78
|
+
return old[0]; const id = prefix + 'r' + reads.length; reads.push([id, map, key]); return id; };
|
|
79
|
+
const pair = (left, right) => plus(times(shape.origin.width, left), right);
|
|
80
|
+
const row = countsForReads(step.decls, [[prefix + 'row', rowMap, actor]])?.[0], used = new Set();
|
|
81
|
+
walkOnce([m.pre, m.assume, m.step.flags?.[write.guard]], (node) => { if (node.op === 'get')
|
|
82
|
+
used.add(node.map); });
|
|
83
|
+
const aliases = Object.entries(m.counts ?? {}).filter(([map, definition]) => !definition.base && used.has(map)).flatMap(([map]) => { const count = countsForReads(step.decls, [[prefix + 'alias', map, n(0)]])?.[0]; return row && count && matchLiftedCountBodies(row, count) ? [map] : []; });
|
|
84
|
+
if (aliases.length !== 1)
|
|
85
|
+
return decline('no-unique-actor-row-count');
|
|
86
|
+
const S = bind(write.inputCount, n(0)), X = bind(aliases[0], n(0)), R = bind(rowMap, actor), V = bind(vote, actor), TA = bind(premise.shape.voteMap, pair(actor, a)), TB = bind(premise.shape.voteMap, pair(actor, b));
|
|
87
|
+
const beforeA = bind(vote, a), beforeB = bind(vote, b), afterA = bind(vote + '#', a), afterB = bind(vote + '#', b), counts = countsForReads(step.decls, reads), bound = counts?.find(count => count.v === S)?.below;
|
|
88
|
+
if (!counts || !bound)
|
|
89
|
+
return decline('count-reads');
|
|
90
|
+
const vectors = [[[1, X], [-1, R]], [[1, R], [-1, X]], [[1, S], [-1, V]], [[1, S], [-1, TA]], [[1, S], [-1, TB]], [[1, afterA], [-1, beforeA]], [[1, afterB], [-1, beforeB]]];
|
|
91
|
+
const insts = vectors.map((terms, index) => ({ wit: labels[index], below: bound, terms, unit: 0 })), request = { reads, insts, picks: [] }, goal = mcGoal(step.goal.hyps, step.decls, request);
|
|
92
|
+
if (!goal)
|
|
93
|
+
return decline('encoding');
|
|
94
|
+
const frames = [], roots = new Map();
|
|
95
|
+
observe?.({ stage: 'increment-premise', premise: premise.law.name, rowAlias: aliases[0], instances: insts.length });
|
|
96
|
+
const ask = (path, stage, index) => {
|
|
97
|
+
if (late(until))
|
|
98
|
+
return;
|
|
99
|
+
const root = framePath(frames, [], path), started = fullWork();
|
|
100
|
+
return withLiftedLeaf(until, options, 500, 'leaf:increment:' + stage + (index === undefined ? '' : ':' + index), end => {
|
|
101
|
+
const minimal = index === undefined ? { goal: mcGoal(copyQueryContext(step.goal.hyps, root, counts, insts, []), step.decls, { reads, insts: [], picks: [] }), path: root } : minimalTransportView(step.goal.hyps, step.decls, reads, insts, [insts[index]], root);
|
|
102
|
+
if (!minimal?.goal)
|
|
103
|
+
return;
|
|
104
|
+
const result = minimalViewFirst(goal, minimal.goal, root, end, growCdcl, minimal.path, { deferCheck: deferred }), tree = result.tree;
|
|
105
|
+
observe?.({ stage, index, checked: !!tree, hyps: minimal.goal.hyps.length, leafCap: late(end), units: (fullWork() - started) / fullRate, minimal: result.minimalKind, fullFallback: result.fallback, minimalUnits: result.minimalUnits, fallbackUnits: result.fallbackUnits, ...(result.witness ? { witness: result.witness } : {}) });
|
|
106
|
+
if (!tree || late(end))
|
|
107
|
+
return;
|
|
108
|
+
roots.set(tree, new Map(root));
|
|
109
|
+
return tree;
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
const frame = (path, every = false) => { for (const read of reads.filter(read => read[1].endsWith('#') && (every || read[1] !== vote + '#'))) {
|
|
113
|
+
const before = reads.find(old => old[1] === read[1].slice(0, -1) && json(old[2]) === json(read[2]));
|
|
114
|
+
if (!before)
|
|
115
|
+
continue;
|
|
116
|
+
const cut = { post: read[0], pre: before[0], when: [...path.values()].map(atom => atom.holds ? atom.lin : add(scale(atom.lin, -1), k(1))) };
|
|
117
|
+
if (options.emitterFramePool) {
|
|
118
|
+
(framePool ??= new FrameFactPool(counts, frames, until)).offer(cut);
|
|
119
|
+
}
|
|
120
|
+
else if (frameOk(counts, cut))
|
|
121
|
+
frames.push(cut);
|
|
122
|
+
} };
|
|
123
|
+
const split = countGuardTree(until, { yesFirst: true }), factRow = (index) => add(...insts[index].terms.map(([coefficient, id]) => ({ [id]: coefficient })));
|
|
124
|
+
const fact = (index, path, next) => split.rows([factRow(index)], path, next, branch => ask(branch, 'count-fact', index));
|
|
125
|
+
const finish = (path) => split.condition({ op: '=', a, b: actor }, path, left => fact(2, left, p => split.condition({ op: '=', a: b, b: actor }, p, q => ask(q, 'both-actor'), q => fact(6, q, r => ask(r, 'left-actor')))), left => fact(5, left, p => split.condition({ op: '=', a: b, b: actor }, p, q => fact(2, q, r => ask(r, 'right-actor')), q => fact(6, q, r => ask(r, 'neither-actor')))));
|
|
126
|
+
const term = (row, index, path, next) => split.condition(atMost(get(shape.countShape.thresholdField, row), get(shape.countShape.memberField, actor)), path, next, branch => fact(index, branch, p => ask(p, 'term-contradiction')));
|
|
127
|
+
const domain = all(...[a, b, actor].flatMap(row => [less(row, bound), less(row, n(shape.origin.width))])), active = inlineFrozenGuard(m.step.flags ?? {}, write.guard);
|
|
128
|
+
const run = (path) => split.rows(countFrameConditions(choice), path, p => split.condition(domain, p, q => { frame(q); return split.condition(active, q, r => fact(0, r, s => fact(1, s, t => term(a, 3, t, u => term(b, 4, u, finish)))), r => { frame(r, true); return ask(r, 'inactive'); }); }, q => ask(q, 'outside-domain')), p => ask(p, 'outside-operation'));
|
|
129
|
+
const tree = split.condition(m.pre, new Map(), run, path => ask(path, 'outside-pre'));
|
|
130
|
+
if (!tree)
|
|
131
|
+
return decline('tree');
|
|
132
|
+
const stable = stabilizeGuardedTree(goal, tree, frames, [], roots, until, { deferCheck: deferred });
|
|
133
|
+
if (!stable.tree || late(until))
|
|
134
|
+
return decline('stabilization');
|
|
135
|
+
if (framePool)
|
|
136
|
+
observe?.({ stage: 'emitter-frame-pool', emitter: 'increment', ...framePool.stats() });
|
|
137
|
+
const cert = { ...request, frames, tree: stable.tree };
|
|
138
|
+
return (options.deferToComposition || checkMC(step.goal.hyps, step.decls, cert)) && !late(until) ? { instances, certs: { [step.goal.name]: cert }, ...(deferred ? { status: 'unchecked' } : {}) } : undefined;
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
if (error === stopped)
|
|
142
|
+
return;
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Law, type Machine } from './machine.js';
|
|
2
|
+
import { type CountRequestBuilder, type CountStrategyProof, type CountStrategyOptions } from './count-strategy.js';
|
|
3
|
+
import { type Goal, type Path, type Tree } from '../kernel/kernel.js';
|
|
4
|
+
export declare function rebaseLiftedLoadCandidate(view: Goal, tree: Tree, root: Path, until: number, goal: Goal, options?: CountStrategyOptions): Tree | undefined;
|
|
5
|
+
export declare function proveLiftedCountLoad(m: Machine, family: Law[], law: Law, until: number, requestFor: CountRequestBuilder, observe?: (event: Record<string, unknown>) => void, options?: CountStrategyOptions): CountStrategyProof | undefined;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { liftedLeafUntil, withLiftedLeaf } from "./count-lifted-budget.js";
|
|
2
|
+
import { FrameFactPool } from "./count-emitter-frame-pool.js";
|
|
3
|
+
// Generic marked-load STEP proposer. Every premise comes from structural
|
|
4
|
+
// discovery in the caller's family; no saved certificate or named law is used.
|
|
5
|
+
import { all, atMost, get, n, not, same, x } from "./machine.js";
|
|
6
|
+
import { countsForReads } from "./count-facts.js";
|
|
7
|
+
import { ownCountLawInstance, fixedCountFrameCase } from "./count-frames.js";
|
|
8
|
+
import { deferIntermediateCountChecks } from "./count-strategy.js";
|
|
9
|
+
import { discoverLiftedCountGuard } from "./count-lifted-shape.js";
|
|
10
|
+
import { discoverCountRowLoad } from "./count-load-shape.js";
|
|
11
|
+
import { proposeLiftedTransports } from "./count-lifted-transports.js";
|
|
12
|
+
import { canon, check, checkMC, countedObligations, frameOk, framePath, linear, mcGoal } from "../kernel/kernel.js";
|
|
13
|
+
import { add, env, k, scale, solve, sub } from "./solver.js";
|
|
14
|
+
import { growCdcl } from "../kernel/cdcl.js";
|
|
15
|
+
import { fullRate, fullWork, late, rowsAt, withDeadline } from "../kernel/prove.js";
|
|
16
|
+
import { countGuardTree } from "./count-guard-tree.js";
|
|
17
|
+
import { inlineFrozenGuard } from "./count-frozen-guard.js";
|
|
18
|
+
import { rebasePath } from "./count-rebase-path.js";
|
|
19
|
+
import { replayLinearSkeleton } from "./count-replay-skeleton.js";
|
|
20
|
+
import { checkedReversePrefix, UnwrittenCountPrefix } from "./count-unwritten-prefix.js";
|
|
21
|
+
import { copyQueryContext } from "./count-query-context.js";
|
|
22
|
+
import { stabilizeGuardedTree } from "./count-stabilize-tree.js";
|
|
23
|
+
const json = (value) => JSON.stringify(value);
|
|
24
|
+
// Untrusted minimal-to-full transport. The independent opt-in is default off;
|
|
25
|
+
// C2 and general deferral alone retain the pre-G1 checked replay call.
|
|
26
|
+
export function rebaseLiftedLoadCandidate(view, tree, root, until, goal, options = {}) {
|
|
27
|
+
return rebasePath(view, tree, root, root, until, goal) ?? (env.GDP_COUNT_G1_OWNED_DEFER === '1'
|
|
28
|
+
? replayLinearSkeleton(goal, tree, root, until, { deferCheck: deferIntermediateCountChecks(options) })
|
|
29
|
+
: replayLinearSkeleton(goal, tree, root, until));
|
|
30
|
+
}
|
|
31
|
+
export function proveLiftedCountLoad(m, family, law, until, requestFor, observe, options = {}) {
|
|
32
|
+
if (!family.includes(law))
|
|
33
|
+
return;
|
|
34
|
+
return withDeadline(until, () => {
|
|
35
|
+
const deferred = deferIntermediateCountChecks(options), accepts = (...args) => deferred || check(...args);
|
|
36
|
+
const shape = discoverLiftedCountGuard(m, law, family), choice = fixedCountFrameCase(m), load = shape && choice && discoverCountRowLoad(m, shape, family, choice);
|
|
37
|
+
if (!shape || !choice || !load || !m.pre || late(until))
|
|
38
|
+
return;
|
|
39
|
+
const stopped = {}, decline = (reason) => { observe?.({ stage: 'load-decline', reason }); throw stopped; };
|
|
40
|
+
let framePool;
|
|
41
|
+
try {
|
|
42
|
+
const a = x(law.forall + '#'), b = x(law.keys[0]), written = x(load.written), endpoints = [a, b, written];
|
|
43
|
+
const instances = ownCountLawInstance(law, {});
|
|
44
|
+
for (const premise of load.phaseLaws)
|
|
45
|
+
instances[premise.name] = endpoints;
|
|
46
|
+
const packet = () => countedObligations(m, family, { [law.name]: instances }, family.indexOf(law)).at(-1);
|
|
47
|
+
const bootstrap = packet(), reads = requestFor(bootstrap.goal, bootstrap.decls).reads, maps = new Set(shape.countMaps), post = reads.filter(read => read[1].endsWith('#') && maps.has(read[1].slice(0, -1)));
|
|
48
|
+
const rowName = shape.origin.rowCount, twins = new Set(shape.origin.twins.map(t => t.row)), disabled = shape.countMaps.filter(map => map !== rowName && !twins.has(map));
|
|
49
|
+
if (disabled.length !== 1)
|
|
50
|
+
return decline('disabled-count');
|
|
51
|
+
const voteName = disabled[0], transport = proposeLiftedTransports(m, family, law, choice.value);
|
|
52
|
+
const loaded = transport?.filter(region => region.name === 'load-both' || region.name.endsWith('-marked')), neither = transport?.find(region => region.name === 'load-neither');
|
|
53
|
+
if (!loaded?.length || !neither)
|
|
54
|
+
return decline('transport-plan');
|
|
55
|
+
const key = (read) => json(read.post.slice(1));
|
|
56
|
+
const zeros = loaded[0].relations.filter(relation => relation.kind === 'zero' && twins.has(relation.post[1].slice(0, -1)) && loaded.every(region => region.relations.some(other => other.kind === 'zero' && key(other) === key(relation))));
|
|
57
|
+
const subsets = neither.relations.filter(relation => relation.kind === 'upper' && relation.post[1] === voteName + '#' && relation.target?.[1] === rowName + '#' && json(relation.post[2]) === json(relation.target[2]));
|
|
58
|
+
if (!zeros.length || subsets.length !== 2)
|
|
59
|
+
return decline('transport-coverage');
|
|
60
|
+
observe?.({ stage: 'load-match', zeroRelations: zeros.length, subsetRelations: subsets.length, regions: transport.length });
|
|
61
|
+
const find = (map, key) => reads.find(read => read[1] === map && json(read[2]) === json(key))?.[0] ?? decline('missing-count-read');
|
|
62
|
+
const counts0 = countsForReads(bootstrap.decls, reads), bound = counts0?.find(count => count.v === find(rowName + '#', a))?.below;
|
|
63
|
+
if (!bound)
|
|
64
|
+
return decline('row-bound');
|
|
65
|
+
let prefixName = 'markedLoad$';
|
|
66
|
+
const scope = json([m, family, reads]);
|
|
67
|
+
while (scope.includes(prefixName))
|
|
68
|
+
prefixName = '$' + prefixName;
|
|
69
|
+
const insts = [], loadWitnesses = [];
|
|
70
|
+
const put = (terms, isLoad = false) => { const wit = prefixName + insts.length; insts.push({ wit, below: bound, terms, unit: 0 }); if (isLoad)
|
|
71
|
+
loadWitnesses.push(wit); };
|
|
72
|
+
for (const relation of subsets)
|
|
73
|
+
put([[1, find(relation.post[1], relation.post[2])], [-1, find(relation.target[1], relation.target[2])]]);
|
|
74
|
+
for (const relation of zeros)
|
|
75
|
+
put([[1, find(relation.post[1], relation.post[2])]], true);
|
|
76
|
+
instances[load.law.name] = loadWitnesses.flatMap(wit => [a, x(wit), b, x(wit)]);
|
|
77
|
+
const step = packet(), again = requestFor(step.goal, step.decls);
|
|
78
|
+
if (json(reads) !== json(again.reads))
|
|
79
|
+
return decline('read-layout-drift');
|
|
80
|
+
const request = { reads, insts, picks: [] }, goal = mcGoal(step.goal.hyps, step.decls, request), counts = countsForReads(step.decls, reads);
|
|
81
|
+
if (!goal || !counts)
|
|
82
|
+
return decline('encoding');
|
|
83
|
+
const frames = [], lins = [], prefix = new UnwrittenCountPrefix(step.decls, reads, [same(x(choice.name), n(choice.value)), m.pre], written, bound, 'cdcl', { leafUnits: options.leafUnits });
|
|
84
|
+
const prefixFact = (postId, preId, rows, sign) => {
|
|
85
|
+
if (late(until))
|
|
86
|
+
return;
|
|
87
|
+
const positive = sign === 1 ? postId : preId, negative = sign === 1 ? preId : postId, opposite = lins.find(cut => cut.pos.length === 1 && cut.neg.length === 1 && cut.pos[0][0] === 1 && cut.neg[0][0] === 1 && cut.pos[0][1] === negative && cut.neg[0][1] === positive);
|
|
88
|
+
const run = (end) => opposite && checkedReversePrefix(counts, opposite) || prefix.prove(postId, preId, rows, sign, end);
|
|
89
|
+
return options.leafWork ? withLiftedLeaf(until, options, 60, 'leaf:load:prefix', run) : run(until);
|
|
90
|
+
};
|
|
91
|
+
for (const endpoint of [a, b])
|
|
92
|
+
for (const sign of [1, -1]) {
|
|
93
|
+
const cut = prefixFact(find(rowName + '#', endpoint), find(rowName, endpoint), [endpoint], sign);
|
|
94
|
+
if (cut)
|
|
95
|
+
lins.push(cut);
|
|
96
|
+
}
|
|
97
|
+
for (const endpoint of [a, b]) {
|
|
98
|
+
const cut = prefixFact(find(voteName + '#', endpoint), find(voteName, endpoint), [endpoint], 1);
|
|
99
|
+
if (cut)
|
|
100
|
+
lins.push(cut);
|
|
101
|
+
}
|
|
102
|
+
const reused = new Map(), roots = new Map();
|
|
103
|
+
const ask = (path, stage, frame = false) => {
|
|
104
|
+
if (late(until))
|
|
105
|
+
return;
|
|
106
|
+
if (stage === 'neither-written')
|
|
107
|
+
for (const [postId, map, key] of post) {
|
|
108
|
+
if (map === rowName + '#')
|
|
109
|
+
continue;
|
|
110
|
+
const rows = key.op === 'add' && key.a.op === 'mul' ? [key.a.a, key.b] : [key];
|
|
111
|
+
for (const sign of map === voteName + '#' ? [1] : [1, -1]) {
|
|
112
|
+
const cut = prefixFact(postId, find(map.slice(0, -1), key), rows, sign);
|
|
113
|
+
if (cut && !lins.some(old => json(old) === json(cut)))
|
|
114
|
+
lins.push(cut);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (frame)
|
|
118
|
+
for (const [postId, map, key] of post) {
|
|
119
|
+
const pre = reads.find(read => read[1] === map.slice(0, -1) && json(read[2]) === json(key));
|
|
120
|
+
if (pre) {
|
|
121
|
+
const cut = { post: postId, pre: pre[0], when: [...path.values()].map(atom => atom.holds ? atom.lin : add(scale(atom.lin, -1), k(1))) };
|
|
122
|
+
if (options.emitterFramePool) {
|
|
123
|
+
(framePool ??= new FrameFactPool(counts, frames, until)).offer(cut);
|
|
124
|
+
}
|
|
125
|
+
else if (frameOk(counts, cut))
|
|
126
|
+
frames.push(cut);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const root = framePath(frames, [], path, [], lins), before = fullWork(), remember = (tree) => { roots.set(tree, new Map(root)); return tree; };
|
|
130
|
+
return withLiftedLeaf(until, options, 500, 'leaf:load:' + stage, deadline => {
|
|
131
|
+
const direct = solve(rowsAt(goal, root), 500);
|
|
132
|
+
if (direct.kind === 'refuted')
|
|
133
|
+
return remember({ leaf: direct.steps });
|
|
134
|
+
const cached = reused.get(stage);
|
|
135
|
+
if (cached) {
|
|
136
|
+
const end = options.leafWork ? deadline : liftedLeafUntil(deadline, options, 25), tree = rebasePath(cached.goal, cached.tree, cached.path, root, end, goal) ?? replayLinearSkeleton(goal, cached.tree, root, end, { deferCheck: deferred });
|
|
137
|
+
if (tree && accepts(goal, tree, root))
|
|
138
|
+
return remember(tree);
|
|
139
|
+
}
|
|
140
|
+
const selected = stage === 'both-written' || stage.endsWith('-loaded') ? insts.filter(inst => inst.terms.length === 1) : stage.endsWith('-empty') ? insts.filter(inst => inst.terms.length === 2 && inst.terms[0][1] === find(voteName + '#', stage.startsWith('a-written') ? b : a)) : [];
|
|
141
|
+
let searchRoot = root;
|
|
142
|
+
if (stage.endsWith('-loaded')) {
|
|
143
|
+
const other = stage.startsWith('a-written') ? b : a, order = sub(linear(other, path), linear(written, path)), drop = new Set([canon(order), canon(scale(order, -1))]);
|
|
144
|
+
searchRoot = framePath(frames, [], new Map([...path].filter(([, atom]) => !drop.has(canon(atom.lin)))), [], lins);
|
|
145
|
+
}
|
|
146
|
+
const hyps = copyQueryContext(step.goal.hyps, searchRoot, counts, insts, selected), view = mcGoal(hyps, step.decls, { ...request, insts: selected });
|
|
147
|
+
if (!view)
|
|
148
|
+
return;
|
|
149
|
+
const result = growCdcl(view, searchRoot, { nodes: 0, until: deadline }), candidate = 'tree' in result ? rebaseLiftedLoadCandidate(view, result.tree, searchRoot, deadline, goal, options) : undefined;
|
|
150
|
+
const general = candidate && accepts(goal, candidate, searchRoot) ? candidate : undefined, lift = general && (searchRoot === root ? general : rebasePath(goal, general, searchRoot, root, deadline, goal) ?? replayLinearSkeleton(goal, general, root, deadline, { deferCheck: deferred }));
|
|
151
|
+
observe?.({ stage, checked: !!lift, units: (fullWork() - before) / fullRate, ...(!('tree' in result) ? { outcome: result.stuck, witness: result.witness } : {}) });
|
|
152
|
+
if (general && !reused.has(stage))
|
|
153
|
+
reused.set(stage, { tree: general, path: searchRoot, goal });
|
|
154
|
+
return lift && accepts(goal, lift, root) && !late(until) ? remember(lift) : undefined;
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
const split = countGuardTree(until, { yesFirst: true }), marked = (row, path, stage) => split.condition(atMost(n(load.marker.value), get(load.marker.map, row)), path, p => ask(p, stage + '-loaded'), p => ask(p, stage + '-empty', true));
|
|
158
|
+
const regions = (path) => split.condition(same(a, written), path, p => split.condition(same(b, written), p, q => ask(q, 'both-written'), q => marked(b, q, 'a-written')), p => split.condition(same(b, written), p, q => marked(a, q, 'b-written'), q => ask(q, 'neither-written', true)));
|
|
159
|
+
const domain = all(m.pre, ...endpoints.flatMap(row => [{ op: '<', a: row, b: bound }, atMost(row, n(shape.origin.width - 1))])), active = inlineFrozenGuard(m.step.flags ?? {}, load.guard);
|
|
160
|
+
const inactive = (path) => split.condition(all(...choice.values.filter(value => value !== choice.value).map(value => not(same(x(choice.name), n(value))))), path, p => ask(p, 'inactive', true), p => ask(p, 'inactive-operation-contradiction'));
|
|
161
|
+
const tree = split.condition(domain, new Map(), path => split.condition(active, path, regions, inactive), path => ask(path, 'outside-domain'));
|
|
162
|
+
if (!tree)
|
|
163
|
+
return decline('tree');
|
|
164
|
+
const stable = stabilizeGuardedTree(goal, tree, frames, lins, roots, until, { deferCheck: deferred });
|
|
165
|
+
observe?.({ stage: 'load-stabilize', completed: !!stable.tree, rebased: stable.rebased, failed: stable.failed, phasePremises: load.phaseLaws.length });
|
|
166
|
+
if (!stable.tree || late(until))
|
|
167
|
+
return;
|
|
168
|
+
if (framePool)
|
|
169
|
+
observe?.({ stage: 'emitter-frame-pool', emitter: 'load', ...framePool.stats() });
|
|
170
|
+
const cert = { ...request, frames, lins, tree: stable.tree };
|
|
171
|
+
return (options.deferToComposition || checkMC(step.goal.hyps, step.decls, cert)) && !late(until) ? { instances, certs: { [step.goal.name]: cert }, ...(deferred ? { status: 'unchecked' } : {}) } : undefined;
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
if (error === stopped)
|
|
175
|
+
return;
|
|
176
|
+
throw error;
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type C, type Law, type Machine } from './machine.js';
|
|
2
|
+
import { type Count } from '../kernel/kernel.js';
|
|
3
|
+
export type LiftedCountPrerequisite = {
|
|
4
|
+
law: Law;
|
|
5
|
+
disabledMap: string;
|
|
6
|
+
voteMap: string;
|
|
7
|
+
kind: 'diagonal' | 'threshold-factor';
|
|
8
|
+
disabled: Count;
|
|
9
|
+
votes: Count;
|
|
10
|
+
threshold?: C;
|
|
11
|
+
bodyNodes: number;
|
|
12
|
+
};
|
|
13
|
+
export declare function liftedCountBodySize(value: unknown): number;
|
|
14
|
+
export declare function discoverLiftedCountPrerequisites(m: Machine, law: Law, family: readonly Law[]): LiftedCountPrerequisite[];
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Untrusted F15 scheduling proposal. A factor match supplies an existing law,
|
|
2
|
+
// never a count inequality, a proof, or permission to bypass native checking.
|
|
3
|
+
import { all, get, ite, less, n, plus, times, x } from "./machine.js";
|
|
4
|
+
import { countsForReads } from "./count-facts.js";
|
|
5
|
+
import { discoverCountGuardShape } from "./count-guard-shape.js";
|
|
6
|
+
import { discoverLiftedCountGuard } from "./count-lifted-shape.js";
|
|
7
|
+
import { matchLiftedCountBodies } from "./count-lifted-transports.js";
|
|
8
|
+
import { substE } from "../kernel/kernel.js";
|
|
9
|
+
const json = (value) => JSON.stringify(value);
|
|
10
|
+
export function liftedCountBodySize(value) {
|
|
11
|
+
if (!value || typeof value !== 'object')
|
|
12
|
+
return 0;
|
|
13
|
+
if (Array.isArray(value))
|
|
14
|
+
return value.reduce((sum, child) => sum + liftedCountBodySize(child), 0);
|
|
15
|
+
return ('op' in value ? 1 : 0) + Object.values(value).reduce((sum, child) => sum + liftedCountBodySize(child), 0);
|
|
16
|
+
}
|
|
17
|
+
const atoms = (c) => c.op === 'and' ? c.xs.flatMap(atoms) : [c];
|
|
18
|
+
export function discoverLiftedCountPrerequisites(m, law, family) {
|
|
19
|
+
const shape = discoverLiftedCountGuard(m, law, family);
|
|
20
|
+
if (!shape || !law.forall)
|
|
21
|
+
return [];
|
|
22
|
+
const twins = new Set(shape.origin.twins.map(twin => twin.row)), disabledMaps = shape.countMaps.filter(map => map !== shape.origin.rowCount && !twins.has(map));
|
|
23
|
+
if (disabledMaps.length !== 1)
|
|
24
|
+
return [];
|
|
25
|
+
const disabledMap = disabledMaps[0], row = x(law.forall), decls = Object.entries(m.counts ?? {}).map(([map, definition]) => ({ ...definition, map }));
|
|
26
|
+
const raw = countsForReads(decls, [['disabled', disabledMap, row]])?.[0];
|
|
27
|
+
if (!raw)
|
|
28
|
+
return [];
|
|
29
|
+
let member = 'prerequisite$member';
|
|
30
|
+
const scope = json([m, law]);
|
|
31
|
+
while (scope.includes(member))
|
|
32
|
+
member = '$' + member;
|
|
33
|
+
const canonical = (count) => ({ ...count, key: member, body: substE(count.body, { vars: { [count.key]: x(member) }, maps: {}, flags: {} }) });
|
|
34
|
+
const disabled = canonical(raw), bodyNodes = liftedCountBodySize(raw.body);
|
|
35
|
+
return family.flatMap(candidate => {
|
|
36
|
+
const guard = discoverCountGuardShape(m, candidate, family);
|
|
37
|
+
if (!guard || guard.rowMap !== shape.origin.rowCount || guard.width !== shape.origin.width)
|
|
38
|
+
return [];
|
|
39
|
+
const rawVotes = countsForReads(decls, [['votes', guard.voteMap, plus(times(guard.width, row), row)]])?.[0];
|
|
40
|
+
if (!rawVotes)
|
|
41
|
+
return [];
|
|
42
|
+
const votes = canonical(rawVotes), base = { law: candidate, disabledMap, voteMap: guard.voteMap, disabled, votes, bodyNodes };
|
|
43
|
+
if (matchLiftedCountBodies(disabled, votes))
|
|
44
|
+
return [{ ...base, kind: 'diagonal' }];
|
|
45
|
+
if (votes.body.op !== 'if' || json(votes.body.then) !== json(n(1)) || json(votes.body.else) !== json(n(0)))
|
|
46
|
+
return [];
|
|
47
|
+
const threshold = less(get(guard.memberField, x(member)), get(guard.thresholdField, row)), parts = atoms(votes.body.c);
|
|
48
|
+
if (parts.filter(part => json(part) === json(threshold)).length !== 1)
|
|
49
|
+
return [];
|
|
50
|
+
const residual = { ...votes, body: ite(all(...parts.filter(part => json(part) !== json(threshold))), n(1), n(0)) };
|
|
51
|
+
return matchLiftedCountBodies(disabled, residual) ? [{ ...base, kind: 'threshold-factor', threshold }] : [];
|
|
52
|
+
});
|
|
53
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type Law, type Machine } from './machine.js';
|
|
2
|
+
import { type CountRequestBuilder, type CountStrategyOptions, type CountStrategyProof } from './count-strategy.js';
|
|
3
|
+
export declare function proveLiftedCountReplacement(m: Machine, family: Law[], law: Law, until: number, requestFor: CountRequestBuilder, observe?: (event: Record<string, unknown>) => void, options?: CountStrategyOptions): CountStrategyProof | undefined;
|