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,540 @@
|
|
|
1
|
+
import { liftedLeafUntil, withLiftedLeaf } from "./count-lifted-budget.js";
|
|
2
|
+
import { FrameFactPool } from "./count-emitter-frame-pool.js";
|
|
3
|
+
// Generic stored-row replacement proposer. The strict path checks transports;
|
|
4
|
+
// composition-only deferral leaves acceptance to the unchanged final checker.
|
|
5
|
+
// Discovery supplies roles, never axioms.
|
|
6
|
+
import { traceNow } from "./trace-clock.js";
|
|
7
|
+
import { proveBooleanPartitionCut } from "./count-boolean-partition.js";
|
|
8
|
+
import { all, atMost, get, less, n, not, plus, same, times, walkOnce, x } from "./machine.js";
|
|
9
|
+
import { check, checkMC, countedObligations, frameOk, framePath, lemmaPath, canon, linActive, mcGoal, substC, truth } from "../kernel/kernel.js";
|
|
10
|
+
import { deferIntermediateCountChecks, deferOwnedReplacementChecks } from "./count-strategy.js";
|
|
11
|
+
import { discoverLiftedCountGuard, discoverLiftedCountOperation } from "./count-lifted-shape.js";
|
|
12
|
+
import { discoverLiftedCountPrerequisites } from "./count-lifted-prerequisite.js";
|
|
13
|
+
import { countsForReads } from "./count-facts.js";
|
|
14
|
+
import { countFrameConditions, fixedCountFrameCase, ownCountLawInstance } from "./count-frames.js";
|
|
15
|
+
import { matchLiftedCountBodies } from "./count-lifted-transports.js";
|
|
16
|
+
import { countGuardTree } from "./count-guard-tree.js";
|
|
17
|
+
import { inlineFrozenGuard } from "./count-frozen-guard.js";
|
|
18
|
+
import { clock, fullRate, fullWork, late, pastWall, rowsAt, usedHyps, withDeadline } from "../kernel/prove.js";
|
|
19
|
+
import { growCdcl } from "../kernel/cdcl.js";
|
|
20
|
+
import { add, k, scale, solve } from "./solver.js";
|
|
21
|
+
import { rebasePath } from "./count-rebase-path.js";
|
|
22
|
+
import { pruneOwnedRoot } from "./count-prune-owned-root.js";
|
|
23
|
+
import { minimalTransportView, minimalViewFirst } from "./count-minimal-view.js";
|
|
24
|
+
import { copyQueryContext } from "./count-query-context.js";
|
|
25
|
+
import { guardLinearFact } from "./count-guard-facts.js";
|
|
26
|
+
import { UnwrittenCountPrefix } from "./count-unwritten-prefix.js";
|
|
27
|
+
import { stabilizeGuardedTree } from "./count-stabilize-tree.js";
|
|
28
|
+
import { proveQuorumCountLeaf } from "./count-quorum-leaf.js";
|
|
29
|
+
const json = (value) => JSON.stringify(value);
|
|
30
|
+
export function proveLiftedCountReplacement(m, family, law, until, requestFor, observe, options = {}) {
|
|
31
|
+
if (!family.includes(law))
|
|
32
|
+
return;
|
|
33
|
+
return withDeadline(until, () => {
|
|
34
|
+
const deferred = deferIntermediateCountChecks(options), accepts = (goal, tree, path) => deferred || check(goal, tree, path);
|
|
35
|
+
const c2 = options.slicedLemmas === true;
|
|
36
|
+
const shape = discoverLiftedCountGuard(m, law, family), choice = fixedCountFrameCase(m), operation = shape && choice && discoverLiftedCountOperation(m, shape, choice.value);
|
|
37
|
+
if (!shape || !choice || operation?.kind !== 'threshold-replace' || !('write' in operation) || !operation.write || !m.pre || late(until))
|
|
38
|
+
return;
|
|
39
|
+
const write = operation.write, agreement = shape.rowAgreements[0], prerequisites = discoverLiftedCountPrerequisites(m, law, family);
|
|
40
|
+
const stopped = {}, decline = (reason) => { observe?.({ stage: 'replacement-decline', reason, remaining: until - clock(), pastWall: pastWall() }); throw stopped; };
|
|
41
|
+
let framePool;
|
|
42
|
+
try {
|
|
43
|
+
const profileStart = c2 ? fullWork() : 0;
|
|
44
|
+
const deferOwned = deferOwnedReplacementChecks(options), batchOwned = deferOwned && options.batchOwnedReplacementPruning === true;
|
|
45
|
+
const ownedStats = { seedRan: 0, seedDropped: 0, trialRan: 0, trialDropped: 0, auditRan: 0, auditDropped: 0, batchAttempts: 0 };
|
|
46
|
+
const checkOwned = (g, t, p, kind) => { const key = deferOwned ? `${kind}Dropped` : `${kind}Ran`; ownedStats[key]++; return deferOwned || check(g, t, p); };
|
|
47
|
+
const auditOwned = (g, t, p) => deferOwned ? (ownedStats.auditDropped++, undefined) : checkOwned(g, t, p, 'audit');
|
|
48
|
+
if (write.increment !== 0 || !write.committedInput || !write.committedCount || !agreement || prerequisites.length !== 1)
|
|
49
|
+
return decline('replacement-prerequisites');
|
|
50
|
+
const fields = [shape.countShape.thresholdField, ...agreement.shape.fields.filter(field => field !== shape.countShape.thresholdField)];
|
|
51
|
+
if (fields.length !== 2)
|
|
52
|
+
return decline('version-order');
|
|
53
|
+
const a = x(law.forall + '#'), b = x(law.keys[0]), actor = x(write.source), rowMap = shape.origin.rowCount, pair = (p, q) => plus(times(shape.origin.width, p), q);
|
|
54
|
+
const twins = new Set(shape.origin.twins.map(twin => twin.row)), votes = shape.countMaps.filter(map => map !== rowMap && !twins.has(map));
|
|
55
|
+
if (votes.length !== 1)
|
|
56
|
+
return decline('disabled-count');
|
|
57
|
+
const vote = votes[0], difference = shape.origin.twins[0], reverse = shape.origin.twins[1], intersection = shape.origin.twins[2];
|
|
58
|
+
if (!difference || !reverse || !intersection || difference.row !== reverse.row)
|
|
59
|
+
return decline('partition-shape');
|
|
60
|
+
const instances = ownCountLawInstance(law, { [prerequisites[0].law.name]: [actor, a, actor, b] });
|
|
61
|
+
const halfInput = (only) => {
|
|
62
|
+
const names = new Set();
|
|
63
|
+
walkOnce(m.assume, (node) => {
|
|
64
|
+
if (node.op !== '<=' || node.a.op !== 'mul' || node.a.k !== 2 || node.a.a.op !== 'var' || !m.inputs.includes(node.a.a.name))
|
|
65
|
+
return;
|
|
66
|
+
const maps = [];
|
|
67
|
+
let supported = true;
|
|
68
|
+
walkOnce(node.b, (part) => { if (part.op === 'get') {
|
|
69
|
+
maps.push(part.map);
|
|
70
|
+
if (part.key.op !== 'const' || part.key.value !== 0)
|
|
71
|
+
supported = false;
|
|
72
|
+
} });
|
|
73
|
+
if (supported && maps.length === 2 && maps.includes(only) && maps.includes(intersection.request))
|
|
74
|
+
names.add(node.a.a.name);
|
|
75
|
+
});
|
|
76
|
+
if (names.size !== 1)
|
|
77
|
+
return decline('request-half-input');
|
|
78
|
+
return x([...names][0]);
|
|
79
|
+
};
|
|
80
|
+
const sourceHalf = halfInput(difference.request), requestHalf = halfInput(reverse.request), [leftHalf, rightHalf] = law.keys.slice(1).map(x);
|
|
81
|
+
instances[law.name] = [[a, b, leftHalf, rightHalf], [actor, a, sourceHalf, leftHalf], [actor, b, sourceHalf, rightHalf], [actor, actor, sourceHalf, sourceHalf]].flat();
|
|
82
|
+
const guardFields = new Set(fields), scalarLaws = [], markerMaps = new Set(agreement.shape.markers.map(marker => marker.map)), activeStates = new Set();
|
|
83
|
+
walkOnce(m.step.flags?.[write.guard], (node) => { if (node.op === 'var' && Object.hasOwn(m.state, node.name))
|
|
84
|
+
activeStates.add(node.name); });
|
|
85
|
+
walkOnce(m.step.flags?.[write.guard], (node) => { if (node.op === 'get' && !m.counts?.[node.map])
|
|
86
|
+
guardFields.add(node.map); });
|
|
87
|
+
agreement.shape.markers.forEach(marker => guardFields.add(marker.map));
|
|
88
|
+
for (const candidate of family) {
|
|
89
|
+
if (!candidate.forall || (candidate.keys?.length ?? 0) > 1)
|
|
90
|
+
continue;
|
|
91
|
+
let valid = true, read = false, versionBound = false;
|
|
92
|
+
const seenMaps = new Set(), seenStates = new Set();
|
|
93
|
+
walkOnce(candidate.holds, (node) => { if (node.op === 'all' || node.op === 'flag')
|
|
94
|
+
valid = false; if (node.op === 'var' && Object.hasOwn(m.state, node.name))
|
|
95
|
+
seenStates.add(node.name); if (node.op === 'get') {
|
|
96
|
+
read = true;
|
|
97
|
+
seenMaps.add(node.map);
|
|
98
|
+
if (!guardFields.has(node.map))
|
|
99
|
+
valid = false;
|
|
100
|
+
} if (node.op === '<=' && node.a.op === 'get' && node.b.op === 'get' && node.a.map === fields[1] && node.b.map === fields[1])
|
|
101
|
+
versionBound = true; });
|
|
102
|
+
if (!valid || !read || candidate.keys?.length && !versionBound || !candidate.keys?.length && ([...seenMaps].some(map => !markerMaps.has(map)) || [...seenStates].some(name => !activeStates.has(name))))
|
|
103
|
+
continue;
|
|
104
|
+
scalarLaws.push(candidate);
|
|
105
|
+
instances[candidate.name] = candidate.keys?.length ? [actor, a, actor, b] : [a, b, actor];
|
|
106
|
+
}
|
|
107
|
+
const packet = () => countedObligations(m, family, { [law.name]: instances }, family.indexOf(law)).at(-1), bootstrap = packet(), reads = [...requestFor(bootstrap.goal, bootstrap.decls).reads];
|
|
108
|
+
let prefix = 'replacement$';
|
|
109
|
+
while (json([m, family, reads]).includes(prefix))
|
|
110
|
+
prefix = '$' + prefix;
|
|
111
|
+
const bind = (map, key) => { const found = reads.find(read => read[1] === map && json(read[2]) === json(key)); if (found)
|
|
112
|
+
return found[0]; const id = prefix + 'r' + reads.length; reads.push([id, map, key]); return id; };
|
|
113
|
+
const row = countsForReads(bootstrap.decls, [[prefix + 'row', rowMap, actor]])?.[0];
|
|
114
|
+
const used = new Set();
|
|
115
|
+
walkOnce([m.pre, m.assume, m.step.flags?.[write.guard]], (node) => { if (node.op === 'get')
|
|
116
|
+
used.add(node.map); });
|
|
117
|
+
const aliases = Object.entries(m.counts ?? {}).filter(([map, definition]) => !definition.base && used.has(map)).flatMap(([map]) => { const count = countsForReads(bootstrap.decls, [[prefix + 'alias', map, n(0)]])?.[0]; return row && count && matchLiftedCountBodies(row, count) ? [map] : []; });
|
|
118
|
+
if (aliases.length !== 1)
|
|
119
|
+
return decline('actor-row-alias');
|
|
120
|
+
const X = bind(aliases[0], n(0)), Y = bind(write.inputCount, n(0)), Q = bind(write.committedCount, n(0)), dx = bind(difference.request, n(0)), dy = bind(reverse.request, n(0)), mid = bind(intersection.request, n(0)), R = (p, post = false) => bind(rowMap + (post ? '#' : ''), p), V = (p, post = false) => bind(vote + (post ? '#' : ''), p), D = (p, q, post = false) => bind(difference.row + (post ? '#' : ''), pair(p, q)), H = (p, q, post = false) => bind(intersection.row + (post ? '#' : ''), pair(p, q));
|
|
121
|
+
for (const p of [a, b, actor]) {
|
|
122
|
+
R(p);
|
|
123
|
+
V(p);
|
|
124
|
+
}
|
|
125
|
+
for (const [p, q] of [[a, b], [actor, b], [a, actor], [actor, actor]]) {
|
|
126
|
+
D(p, q);
|
|
127
|
+
D(q, p);
|
|
128
|
+
H(p, q);
|
|
129
|
+
}
|
|
130
|
+
for (const p of [a, b]) {
|
|
131
|
+
R(p, true);
|
|
132
|
+
V(p, true);
|
|
133
|
+
}
|
|
134
|
+
D(a, b, true);
|
|
135
|
+
D(b, a, true);
|
|
136
|
+
H(a, b, true);
|
|
137
|
+
const counts0 = countsForReads(bootstrap.decls, reads), bound = counts0?.find(count => count.v === Y)?.below;
|
|
138
|
+
if (!bound)
|
|
139
|
+
return decline('count-bound');
|
|
140
|
+
const insts = [], put = (terms) => { const old = insts.findIndex(inst => json(inst.terms) === json(terms)); if (old >= 0)
|
|
141
|
+
return old; insts.push({ wit: prefix + 'w' + insts.length, below: bound, terms, unit: 0 }); return insts.length - 1; }, both = (terms) => [put(terms), put(terms.map(([c, id]) => [-c, id]))];
|
|
142
|
+
const plans = [true, false].map(left => {
|
|
143
|
+
const written = left ? a : b, other = left ? b : a, preOverlap = H(actor, other), preActor = D(actor, other), preOther = D(other, actor);
|
|
144
|
+
const equal = [...both([[1, R(other)], [-1, R(actor)]]), ...both([[1, D(other, written, true)], [-1, dx]])];
|
|
145
|
+
const older = c2 ? [put([[1, Q], [1, V(other)], [-1, preActor], [-1, preOther], [-1, preOverlap]]), put([[1, V(other)], [-1, preOther], [-1, preOverlap]]), put([[1, Q], [-1, preActor], [-1, preOverlap]])] : [...both([[1, X], [-1, dx], [-1, mid]]), ...both([[1, D(other, written, true)], [1, H(a, b, true)], [-1, preOther], [-1, preOverlap]]), ...both([[1, preActor], [1, preOverlap], [-1, X]]), put([[1, R(actor)], [-1, X]]), put([[1, R(other)], [-1, preOther], [-1, preOverlap]]), put([[1, D(other, written, true)], [1, H(a, b, true)], [-1, R(other, true)]]), put([[1, Q], [-1, V(actor)]]), put([[1, Q], [1, V(other)], [-1, preActor], [-1, preOther], [-1, preOverlap]]), put([[1, V(other)], [-1, preOther], [-1, preOverlap]]), put([[1, Q], [-1, preActor], [-1, preOverlap]])];
|
|
146
|
+
const newer = [put([[1, Q], [-1, bind(prerequisites[0].voteMap, pair(actor, other))]]), put([[1, R(actor)], [-1, X]])];
|
|
147
|
+
return { left, written, other, equal, older, newer, writtenRow: both([[1, R(written, true)], [-1, Y]]) };
|
|
148
|
+
});
|
|
149
|
+
const common = [...both([[1, R(actor)], [-1, X]]), ...both([[1, X], [-1, dx], [-1, mid]]), ...both([[1, Y], [-1, dy], [-1, mid]])];
|
|
150
|
+
const committedEligible = put([[1, Q], [-1, V(actor)]]);
|
|
151
|
+
const witnesses = insts.map(inst => x(inst.wit));
|
|
152
|
+
instances[agreement.law.name] = plans.flatMap(plan => plan.equal.flatMap(index => [actor, plan.other, x(insts[index].wit)]));
|
|
153
|
+
const ownFlags = c2 ? (() => {
|
|
154
|
+
const ownFlags = new Set(), flagQueue = [write.guard];
|
|
155
|
+
walkOnce([m.pre, m.assume], (node) => { if (node.op === 'flag')
|
|
156
|
+
flagQueue.push(node.name); });
|
|
157
|
+
while (flagQueue.length) {
|
|
158
|
+
const name = flagQueue.pop();
|
|
159
|
+
if (ownFlags.has(name))
|
|
160
|
+
continue;
|
|
161
|
+
ownFlags.add(name);
|
|
162
|
+
walkOnce(m.step.flags?.[name], (node) => { if (node.op === 'flag')
|
|
163
|
+
flagQueue.push(node.name); });
|
|
164
|
+
}
|
|
165
|
+
observe?.({ stage: 'own-operation-flags', names: [...ownFlags].filter(name => m.step.flags?.[name]?.op === 'all').sort() });
|
|
166
|
+
return ownFlags;
|
|
167
|
+
})() : undefined;
|
|
168
|
+
for (const [name, flag] of Object.entries(m.step.flags ?? {}))
|
|
169
|
+
if (flag.op === 'all' && (!ownFlags || ownFlags.has(name)))
|
|
170
|
+
instances['?' + name] = [a, b, actor, ...witnesses];
|
|
171
|
+
const arithmeticHyps = new Map(), step = packet(), request = { reads, insts, picks: [] }, goal = mcGoal(step.goal.hyps, step.decls, request), counts = countsForReads(step.decls, reads);
|
|
172
|
+
if (!goal || !counts)
|
|
173
|
+
return decline('encoding');
|
|
174
|
+
const active = inlineFrozenGuard(m.step.flags ?? {}, write.guard), domain = all(...[a, b, actor].flatMap(p => [less(p, bound), less(p, n(shape.origin.width))])), frames = [], lins = [], lemmas = [], roots = new Map();
|
|
175
|
+
observe?.({ stage: 'replacement-plan', transports: insts.length, reads: reads.length, scalarPremises: scalarLaws.length, rowAgreement: agreement.law.name, quorumPremise: prerequisites[0].law.name });
|
|
176
|
+
const prefixFacts = new UnwrittenCountPrefix(step.decls, reads, [same(x(choice.name), n(choice.value)), m.pre, active], actor, bound, 'cdcl', { deferCheck: deferred, leafUnits: options.leafUnits }), done = new Set();
|
|
177
|
+
const fact = (terms, when, stage) => {
|
|
178
|
+
const key = json([terms, when]);
|
|
179
|
+
if (done.has(key))
|
|
180
|
+
return true;
|
|
181
|
+
const start = fullWork(), startWall = observe ? traceNow() : 0, result = withLiftedLeaf(until, options, c2 && stage === 'partition' ? 500 : 100, 'leaf:replacement:fact:' + stage, end => c2 && stage === 'partition' ? proveBooleanPartitionCut(counts, when, terms, end, observe) : guardLinearFact(step.decls, reads, { name: 'replacement ' + stage, kind: 'ordinary-replacement-definition', when, terms }, end, event => { if (c2) {
|
|
182
|
+
if (event.outcome !== 'proof' && event.outcome !== 'proposal')
|
|
183
|
+
observe?.({ stage: 'cut-refused', kind: 'linear', label: stage, outcome: event.outcome, witness: event.witness, when, terms, counts: counts.filter(count => terms.some(([, id]) => id === count.v)) });
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
if (event.outcome !== 'proof')
|
|
187
|
+
observe?.({ stage: stage + '-failure', outcome: event.outcome, witness: event.witness });
|
|
188
|
+
} }, 'cdcl', { deferCheck: deferred }));
|
|
189
|
+
observe?.({ stage, checked: !deferred && !!result, proposed: !!result, units: (fullWork() - start) / fullRate, wallMs: traceNow() - startWall });
|
|
190
|
+
if (!result)
|
|
191
|
+
return false;
|
|
192
|
+
lins.push(result.cut);
|
|
193
|
+
done.add(key);
|
|
194
|
+
return true;
|
|
195
|
+
};
|
|
196
|
+
const prepare = (post, region) => {
|
|
197
|
+
const when = c2 ? [] : [same(x(choice.name), n(choice.value)), m.pre, domain, active, ...region];
|
|
198
|
+
for (const p of [a, b])
|
|
199
|
+
for (const sign of [1, -1])
|
|
200
|
+
if (!fact([[sign, D(p, json(p) === json(a) ? b : a, post)], [sign, H(a, b, post)], [-sign, R(p, post)]], when, 'partition'))
|
|
201
|
+
return false;
|
|
202
|
+
return true;
|
|
203
|
+
};
|
|
204
|
+
const unwritten = (p) => {
|
|
205
|
+
for (const [post, pre, sign] of [[R(p, true), R(p), 1], [R(p, true), R(p), -1], [V(p, true), V(p), 1]]) {
|
|
206
|
+
const key = json([post, pre, sign]);
|
|
207
|
+
if (done.has(key))
|
|
208
|
+
continue;
|
|
209
|
+
if (post === V(p, true) && sign === 1) {
|
|
210
|
+
if (!fact([[1, post], [-1, pre]], [same(x(choice.name), n(choice.value)), m.pre, domain, active, not(same(p, actor))], 'unwritten-disabled'))
|
|
211
|
+
return false;
|
|
212
|
+
done.add(key);
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
const start = fullWork(), startWall = observe ? traceNow() : 0, cut = options.leafWork ? withLiftedLeaf(until, options, 60, 'leaf:replacement:unwritten', end => prefixFacts.prove(post, pre, [p], sign, end)) : prefixFacts.prove(post, pre, [p], sign, until);
|
|
216
|
+
observe?.({ stage: 'unwritten-prefix', checked: !deferred && !!cut, proposed: !!cut, units: (fullWork() - start) / fullRate, wallMs: traceNow() - startWall });
|
|
217
|
+
if (!cut)
|
|
218
|
+
return false;
|
|
219
|
+
lins.push(cut);
|
|
220
|
+
done.add(key);
|
|
221
|
+
}
|
|
222
|
+
return true;
|
|
223
|
+
};
|
|
224
|
+
const remembered = new Map();
|
|
225
|
+
const ask = (path, stage, index) => {
|
|
226
|
+
let selectedLemma;
|
|
227
|
+
if (late(until))
|
|
228
|
+
return;
|
|
229
|
+
const root = framePath(frames, [], path, [], lins), start = fullWork(), startWall = observe ? traceNow() : 0, cacheKey = stage + ':' + index + ':' + truth(same(a, actor), path) + ':' + truth(same(b, actor), path);
|
|
230
|
+
return withLiftedLeaf(until, options, 500, 'leaf:replacement:' + stage + (index === undefined ? '' : ':' + index), end => {
|
|
231
|
+
if (c2 && stage === 'older-transport' && index !== undefined) {
|
|
232
|
+
const cut = add(...insts[index].terms.map(([c, id]) => ({ [id]: c }))), known = lemmas.find(l => canon(l.cut) === canon(cut) && lemmaPath([l], root).size > root.size);
|
|
233
|
+
if (known) {
|
|
234
|
+
const close = (p) => { const r = framePath(frames, lemmas, p, [], lins), out = solve(rowsAt(goal, r), 500); if (out.kind !== 'refuted')
|
|
235
|
+
return; const leaf = { leaf: out.steps }; roots.set(leaf, new Map(r)); return leaf; };
|
|
236
|
+
const main = split.rows(known.when, path, close, close);
|
|
237
|
+
observe?.({ stage: 'older-lemma-reuse', index, checked: !!main });
|
|
238
|
+
return main;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
for (const cached of remembered.get(cacheKey) ?? []) {
|
|
242
|
+
const tree = rebasePath(goal, cached.tree, cached.root, root, options.leafWork ? end : liftedLeafUntil(end, options, 25), goal);
|
|
243
|
+
if (tree && accepts(goal, tree, root)) {
|
|
244
|
+
roots.set(tree, new Map(root));
|
|
245
|
+
observe?.({ stage, index, checked: !deferred, proposed: true, reused: true, units: (fullWork() - start) / fullRate, wallMs: traceNow() - startWall });
|
|
246
|
+
return tree;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
const older = c2 && stage === 'older-transport', postIds = c2 ? new Set(reads.filter(r => r[1].endsWith('#')).map(r => r[0])) : undefined, isPost = (value) => { let out = false; walkOnce(value, (node) => { if (node.op === 'get' && node.map.endsWith('#') || node.op === 'var' && postIds.has(node.name))
|
|
250
|
+
out = true; }); return out; }, preRoot = c2 ? new Map([...root].filter(([, a]) => !Object.keys(a.lin).some(k => postIds.has(k) || k.includes('#[')))) : root, preGoal = c2 ? { ...goal, hyps: goal.hyps.filter(h => !isPost(h)) } : goal;
|
|
251
|
+
const hyps = older ? step.goal.hyps.filter(h => !isPost(h)) : arithmeticHyps.get(stage) ?? (stage.startsWith('equal-') ? arithmeticHyps.get('equal-region') : step.goal.hyps);
|
|
252
|
+
const view = index === undefined ? { goal: mcGoal(copyQueryContext(hyps, root, counts, insts, []), step.decls, { reads, insts: [], picks: [] }), path: root } : minimalTransportView(hyps, step.decls, reads, insts, [insts[index]], older ? preRoot : root);
|
|
253
|
+
if (!view?.goal)
|
|
254
|
+
return;
|
|
255
|
+
const result = stage.startsWith('older-composed') ? (() => {
|
|
256
|
+
const candidate = growCdcl(view.goal, view.path, { nodes: 0, until: end });
|
|
257
|
+
if (!('tree' in candidate)) {
|
|
258
|
+
observe?.({ stage: 'older-query-decline', outcome: candidate.stuck, why: candidate.why, query: view.goal, path: [...view.path], witness: candidate.witness });
|
|
259
|
+
return { tree: undefined, minimalKind: candidate.stuck, fallback: false, witness: candidate.witness };
|
|
260
|
+
}
|
|
261
|
+
const tree = rebasePath(view.goal, candidate.tree, view.path, root, end, goal);
|
|
262
|
+
return { tree: tree && accepts(goal, tree, root) ? tree : undefined, minimalKind: 'proof', fallback: false };
|
|
263
|
+
})() : minimalViewFirst(older ? preGoal : goal, view.goal, older ? preRoot : root, end, growCdcl, view.path, { deferCheck: deferred, deferReplayCheck: options.deferOwnedReplacementReplay === true }), tree = older && result.tree ? rebasePath(preGoal, result.tree, preRoot, root, end, goal) : result.tree;
|
|
264
|
+
observe?.({ stage, index, checked: !deferred && !!tree, proposed: !!tree, units: (fullWork() - start) / fullRate, wallMs: traceNow() - startWall, minimal: result.minimalKind, fullFallback: result.fallback, leafCap: late(end), activeLins: lins.map(cut => linActive(cut, root)), ...(result.witness ? { witness: result.witness } : {}) });
|
|
265
|
+
if (!tree || late(end))
|
|
266
|
+
return;
|
|
267
|
+
if (c2 && stage === 'older-transport' && index !== undefined) {
|
|
268
|
+
const plan = plans.find(plan => plan.older.includes(index));
|
|
269
|
+
if (!plan)
|
|
270
|
+
return;
|
|
271
|
+
if (tree) {
|
|
272
|
+
const cut = add(...insts[index].terms.map(([c, id]) => ({ [id]: c }))), postIds = new Set(reads.filter(read => read[1].endsWith('#')).map(read => read[0]));
|
|
273
|
+
const isPosition = (lin) => { const keys = Object.keys(lin).filter(key => key !== '1'); return plan.other.op === 'var' && keys.length === 2 && keys.includes(plan.other.name) && keys.includes(write.source); };
|
|
274
|
+
const isPost = (value) => { let found = false; walkOnce(value, (node) => { if (node.op === 'get' && node.map.endsWith('#') || node.op === 'var' && postIds.has(node.name))
|
|
275
|
+
found = true; }); return found; };
|
|
276
|
+
const filtered = [...root.values()].filter(atom => !isPosition(atom.lin) && canon(atom.lin) !== canon(cut));
|
|
277
|
+
const rootFor = (atoms) => { const p = new Map(); let duplicate = 0; for (const atom of [{ lin: cut, holds: false }, ...atoms]) {
|
|
278
|
+
const id = canon(atom.lin);
|
|
279
|
+
p.set(p.has(id) ? '@' + duplicate++ : id, atom);
|
|
280
|
+
} return p; };
|
|
281
|
+
const noPosition = rootFor(filtered), positionFree = rebasePath(goal, tree, root, noPosition, until, goal), preAtoms = filtered.filter(atom => !Object.keys(atom.lin).some(key => postIds.has(key) || key.includes('#['))), preRoot = rootFor(preAtoms), slice = goal.hyps.map((hyp, i) => !isPost(hyp) ? i : -1).filter(i => i >= 0), preGoal = { ...goal, hyps: slice.map(i => goal.hyps[i]) }, preTree = rebasePath(goal, tree, root, preRoot, until, preGoal);
|
|
282
|
+
if (preTree) {
|
|
283
|
+
const used = [...usedHyps(preGoal, preTree, preRoot)].sort((a, b) => a - b), smallSlice = used.map(index => slice[index]), smallGoal = { ...preGoal, hyps: used.map(index => preGoal.hyps[index]) }, nativeAtoms = preAtoms.map(atom => ({ lin: atom.holds ? atom.lin : add(scale(atom.lin, -1), k(1)), holds: true }));
|
|
284
|
+
let kept = nativeAtoms, atRoot = rootFor(kept), candidate = rebasePath(preGoal, preTree, preRoot, atRoot, until, smallGoal);
|
|
285
|
+
if (candidate && checkOwned(smallGoal, candidate, atRoot, 'seed')) {
|
|
286
|
+
if (batchOwned) {
|
|
287
|
+
const reduced = pruneOwnedRoot(kept, { tree: candidate, root: atRoot }, (short, prior) => { const nextRoot = rootFor(short), next = rebasePath(smallGoal, prior.tree, prior.root, nextRoot, until, smallGoal); return next && checkOwned(smallGoal, next, nextRoot, 'trial') ? { tree: next, root: nextRoot } : undefined; }, () => !late(until));
|
|
288
|
+
kept = reduced.kept;
|
|
289
|
+
candidate = reduced.proof.tree;
|
|
290
|
+
atRoot = reduced.proof.root;
|
|
291
|
+
ownedStats.batchAttempts += reduced.attempts;
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
for (let at = 0; at < kept.length && !late(until);) {
|
|
295
|
+
const short = kept.filter((_, i) => i !== at), nextRoot = rootFor(short), next = rebasePath(smallGoal, candidate, atRoot, nextRoot, until, smallGoal);
|
|
296
|
+
if (next && checkOwned(smallGoal, next, nextRoot, 'trial')) {
|
|
297
|
+
kept = short;
|
|
298
|
+
atRoot = nextRoot;
|
|
299
|
+
candidate = next;
|
|
300
|
+
}
|
|
301
|
+
else
|
|
302
|
+
at++;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
const lemma = { cut, when: kept.map(atom => atom.lin), slice: smallSlice, tree: candidate };
|
|
306
|
+
const key = json([lemma.cut, lemma.when, lemma.slice]);
|
|
307
|
+
selectedLemma = lemmas.find(l => json([l.cut, l.when, l.slice]) === key) ?? lemma;
|
|
308
|
+
if (selectedLemma === lemma)
|
|
309
|
+
lemmas.push(lemma);
|
|
310
|
+
observe?.({ stage: 'older-inclusion-lemma', left: plan.left, index, before: preAtoms.length, after: kept.length, hyps: smallSlice.length, nativeWhen: true, lemma });
|
|
311
|
+
}
|
|
312
|
+
else
|
|
313
|
+
observe?.({ stage: 'older-inclusion-lemma', left: plan.left, index, nativeWhen: false, before: preAtoms.length });
|
|
314
|
+
}
|
|
315
|
+
observe?.({ stage: 'older-inclusion-audit', left: plan.left, index, auditDeferred: deferOwned, positionFree: !!positionFree && auditOwned(goal, positionFree, noPosition), preOnly: !!preTree && auditOwned(preGoal, preTree, preRoot), when: preAtoms.map(atom => atom.holds ? atom.lin : add(scale(atom.lin, -1), k(1))), cut, slice, removedPositions: [...root.values()].filter(atom => isPosition(atom.lin)), removedPost: filtered.filter(atom => !preAtoms.includes(atom)) });
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (c2 && stage === 'older-transport') {
|
|
319
|
+
if (!selectedLemma)
|
|
320
|
+
return decline('older-inclusion-lemma');
|
|
321
|
+
const close = (p) => { const r = framePath(frames, lemmas, p, [], lins), out = solve(rowsAt(goal, r), 500); if (out.kind !== 'refuted') {
|
|
322
|
+
observe?.({ stage: 'older-lemma-main-open', index, when: selectedLemma.when, path: [...p], result: out });
|
|
323
|
+
return;
|
|
324
|
+
} const leaf = { leaf: out.steps }; roots.set(leaf, new Map(r)); return leaf; };
|
|
325
|
+
const main = split.rows(selectedLemma.when, path, close, close);
|
|
326
|
+
observe?.({ stage: 'older-lemma-main', index, checked: !!main, lemmas: lemmas.length });
|
|
327
|
+
return main;
|
|
328
|
+
}
|
|
329
|
+
roots.set(tree, new Map(root));
|
|
330
|
+
const previous = remembered.get(cacheKey) ?? [];
|
|
331
|
+
if (previous.length < 8)
|
|
332
|
+
remembered.set(cacheKey, [...previous, { tree, root: new Map(root) }]);
|
|
333
|
+
return tree;
|
|
334
|
+
});
|
|
335
|
+
};
|
|
336
|
+
const quick = (path) => {
|
|
337
|
+
const root = framePath(frames, [], path, [], lins), view = mcGoal(copyQueryContext(step.goal.hyps, root, counts, insts, []), step.decls, { reads, insts: [], picks: [] });
|
|
338
|
+
if (!view)
|
|
339
|
+
return;
|
|
340
|
+
const result = solve(rowsAt(view, root), 2000);
|
|
341
|
+
if (result.kind !== 'refuted')
|
|
342
|
+
return;
|
|
343
|
+
const tree = rebasePath(view, { leaf: result.steps }, root, root, until, goal);
|
|
344
|
+
if (tree && accepts(goal, tree, root)) {
|
|
345
|
+
roots.set(tree, new Map(root));
|
|
346
|
+
return tree;
|
|
347
|
+
}
|
|
348
|
+
return undefined;
|
|
349
|
+
};
|
|
350
|
+
const truncations = (condition) => { const out = [], seen = new Set(); walkOnce(condition, (node) => { if (node.op === 'sub') {
|
|
351
|
+
const guard = atMost(node.b, node.a), key = json(guard);
|
|
352
|
+
if (!seen.has(key)) {
|
|
353
|
+
seen.add(key);
|
|
354
|
+
out.push(guard);
|
|
355
|
+
}
|
|
356
|
+
} }); return out; };
|
|
357
|
+
const frame = (path) => { for (const [post, map, key] of reads.filter(read => read[1].endsWith('#'))) {
|
|
358
|
+
const pre = reads.find(read => read[1] === map.slice(0, -1) && json(read[2]) === json(key));
|
|
359
|
+
if (!pre)
|
|
360
|
+
continue;
|
|
361
|
+
const cut = { post, pre: pre[0], when: [...path.values()].map(atom => atom.holds ? atom.lin : add(scale(atom.lin, -1), k(1))) };
|
|
362
|
+
if (options.emitterFramePool) {
|
|
363
|
+
(framePool ??= new FrameFactPool(counts, frames, until)).offer(cut);
|
|
364
|
+
}
|
|
365
|
+
else if (frameOk(counts, cut))
|
|
366
|
+
frames.push(cut);
|
|
367
|
+
} return ask(path, 'inactive'); };
|
|
368
|
+
const split = countGuardTree(until, { yesFirst: true }), chain = (ids, path, stage, finish) => { const [index, ...rest] = ids; if (index === undefined)
|
|
369
|
+
return finish(path); const row = add(...insts[index].terms.map(([c, id]) => ({ [id]: c }))); return split.rows([row], path, next => chain(rest, next, stage, finish), branch => ask(branch, stage, index)); };
|
|
370
|
+
const targetTruncations = truncations(step.goal.hyps.at(-1)), compose = (path, stage, guards = targetTruncations, at = 0) => at === guards.length ? ask(path, stage) : split.condition(guards[at], path, p => compose(p, stage, guards, at + 1), p => compose(p, stage, guards, at + 1));
|
|
371
|
+
const branch = (path, left) => {
|
|
372
|
+
const plan = plans.find(plan => plan.left === left);
|
|
373
|
+
if (c2) {
|
|
374
|
+
for (const [p, q] of [[actor, plan.other], [plan.other, actor]]) {
|
|
375
|
+
for (const sign of [1, -1])
|
|
376
|
+
if (!fact([[sign, D(p, q)], [sign, H(actor, plan.other)], [-sign, R(p)]], [], 'partition'))
|
|
377
|
+
return;
|
|
378
|
+
if (!fact([[1, V(p)], [-1, R(p)]], [], 'partition'))
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
const olderStage = 'older-composed-' + (left ? 'left' : 'right'), tuple = [actor, plan.other, sourceHalf, left ? rightHalf : leftHalf];
|
|
383
|
+
if (!arithmeticHyps.has(olderStage))
|
|
384
|
+
arithmeticHyps.set(olderStage, countedObligations(m, family, { [law.name]: { [law.name]: tuple } }, family.indexOf(law)).at(-1).goal.hyps);
|
|
385
|
+
const oldLaw = substC(law.holds, { vars: Object.fromEntries([law.forall, ...law.keys].map((name, index) => [name, tuple[index]])), maps: {}, flags: {} });
|
|
386
|
+
const olderBranch = (path) => {
|
|
387
|
+
if (oldLaw.op !== 'or' || oldLaw.xs[0]?.op !== 'not')
|
|
388
|
+
return;
|
|
389
|
+
const guard = oldLaw.xs[0].x, disabled = atMost(times(2, get(vote, plan.other)), get(rowMap, plan.other));
|
|
390
|
+
const quorum = (at) => {
|
|
391
|
+
const root = framePath(frames, [], at, [], lins), needed = new Set([X, Q, V(actor), V(plan.other), R(actor), R(plan.other), D(actor, plan.other), D(plan.other, actor), H(actor, plan.other)]);
|
|
392
|
+
const minimal = mcGoal([m.pre, domain, oldLaw], step.decls, { reads: reads.filter(([id]) => needed.has(id)), insts: [], picks: [] });
|
|
393
|
+
if (!minimal)
|
|
394
|
+
return;
|
|
395
|
+
const start = fullWork(), startWall = observe ? traceNow() : 0, run = (end) => proveQuorumCountLeaf(goal, minimal, root, oldLaw, { first: Q, second: V(plan.other) }, [sourceHalf, left ? rightHalf : leftHalf], end, observe, { deferCheck: deferred, leafUnits: options.leafUnits }), tree = options.leafWork ? withLiftedLeaf(until, options, 500, 'leaf:replacement:quorum:' + olderStage, run) : run(until);
|
|
396
|
+
observe?.({ stage: olderStage, checked: !deferred && !!tree, proposed: !!tree, units: (fullWork() - start) / fullRate, wallMs: traceNow() - startWall });
|
|
397
|
+
if (tree)
|
|
398
|
+
roots.set(tree, new Map(root));
|
|
399
|
+
return tree;
|
|
400
|
+
};
|
|
401
|
+
return split.condition(disabled, path, p => c2 ? (quick(p) ?? ask(p, 'older-disabled')) : ask(p, 'older-disabled'), p => chain(plan.older, p, 'older-transport', q => split.condition(guard, q, quorum, r => c2 ? (quick(r) ?? ask(r, olderStage)) : ask(r, olderStage))));
|
|
402
|
+
};
|
|
403
|
+
if (!unwritten(plan.other) || !prepare(true, [same(plan.written, actor), not(same(plan.other, actor))]))
|
|
404
|
+
return;
|
|
405
|
+
const equal = (equalPath) => chain(plan.writtenRow, equalPath, 'written-row', writtenPath => {
|
|
406
|
+
const guards = agreement.shape.markers.map(marker => same(get(marker.map, plan.other), n(marker.value)));
|
|
407
|
+
const halves = [same(leftHalf, left ? requestHalf : sourceHalf), same(rightHalf, left ? sourceHalf : requestHalf)];
|
|
408
|
+
const inputs = (at, p) => at === activeTruncations.length ? split.condition(active, p, q => compose(q, 'equal-composed'), q => ask(q, 'equal-reactivate')) : split.condition(activeTruncations[at], p, q => inputs(at + 1, q), q => inputs(at + 1, q));
|
|
409
|
+
const specialize = (at, p) => at === halves.length ? inputs(0, p) : split.condition(halves[at], p, q => specialize(at + 1, q), q => ask(q, 'equal-half-complement'));
|
|
410
|
+
const marked = (at, p) => at === guards.length ? chain(plan.equal, p, 'equal-transport', q => specialize(0, q)) : split.condition(guards[at], p, q => marked(at + 1, q), q => ask(q, 'equal-marker'));
|
|
411
|
+
return marked(0, writtenPath);
|
|
412
|
+
});
|
|
413
|
+
const firstOther = get(fields[0], plan.other), firstActor = get(fields[0], actor), secondOther = get(fields[1], plan.other), secondActor = get(fields[1], actor);
|
|
414
|
+
return split.condition(less(firstOther, firstActor), path, olderBranch, p => split.condition(same(firstOther, firstActor), p, q => split.condition(less(secondOther, secondActor), q, olderBranch, r => split.condition(same(secondOther, secondActor), r, equal, s => ask(s, 'newer-second-field'))), q => chain(plan.newer, q, 'newer-transport', r => ask(r, 'newer-composed'))));
|
|
415
|
+
};
|
|
416
|
+
const neither = (path) => {
|
|
417
|
+
if (!unwritten(a) || !unwritten(b))
|
|
418
|
+
return;
|
|
419
|
+
for (const [p, q] of [[a, b], [b, a]])
|
|
420
|
+
for (const [post, pre] of [[D(p, q, true), D(p, q)], [H(a, b, true), H(a, b)]])
|
|
421
|
+
for (const sign of [1, -1]) {
|
|
422
|
+
const key = json([post, pre, sign]);
|
|
423
|
+
if (done.has(key))
|
|
424
|
+
continue;
|
|
425
|
+
const cut = options.leafWork ? withLiftedLeaf(until, options, 60, 'leaf:replacement:neither-prefix', end => prefixFacts.prove(post, pre, [a, b], sign, end)) : prefixFacts.prove(post, pre, [a, b], sign, until);
|
|
426
|
+
if (!cut)
|
|
427
|
+
return;
|
|
428
|
+
lins.push(cut);
|
|
429
|
+
done.add(key);
|
|
430
|
+
}
|
|
431
|
+
return ask(path, 'neither-actor');
|
|
432
|
+
};
|
|
433
|
+
const diagonal = (path) => {
|
|
434
|
+
const when = [same(x(choice.name), n(choice.value)), m.pre, domain, active, same(a, actor), same(b, actor)], terms = [[[1, D(a, b, true)]], [[1, D(b, a, true)]]];
|
|
435
|
+
for (const term of terms)
|
|
436
|
+
if (!fact(term, when, 'diagonal-definition'))
|
|
437
|
+
return;
|
|
438
|
+
return ask(path, 'both-actor');
|
|
439
|
+
};
|
|
440
|
+
const positions = (path) => quick(path) ?? split.condition(same(a, actor), path, p => split.condition(same(b, actor), p, diagonal, q => branch(q, true)), p => split.condition(same(b, actor), p, q => branch(q, false), neither));
|
|
441
|
+
const baseHyps = countedObligations(m, [law], { [law.name]: {} }, 0).at(-1).goal.hyps.slice(0, -1);
|
|
442
|
+
arithmeticHyps.set('equal-half-complement', baseHyps);
|
|
443
|
+
const equalFamily = [law, agreement.law, ...scalarLaws.filter(candidate => !candidate.keys?.length)], equalInstances = Object.fromEntries(Object.entries(instances).filter(([name]) => name !== law.name));
|
|
444
|
+
arithmeticHyps.set('equal-region', countedObligations(m, equalFamily, { [law.name]: equalInstances }, 0).at(-1).goal.hyps);
|
|
445
|
+
const negated = step.goal.hyps.at(-1), postGuard = negated?.op === 'not' && negated.x.op === 'or' ? negated.x.xs.find(part => part.op === 'not') : undefined;
|
|
446
|
+
if (postGuard?.op !== 'not')
|
|
447
|
+
return decline('post-half-domain');
|
|
448
|
+
const regions = (path) => chain([committedEligible], path, 'committed-eligible', p => split.condition(less(get(aliases[0], n(0)), times(2, get(write.committedCount, n(0)))), p, q => split.condition(postGuard.x, q, positions, r => ask(r, 'outside-target-half')), q => ask(q, 'commit-majority')));
|
|
449
|
+
const activeTruncations = truncations(active), activate = (path) => split.condition(active, path, regions, frame);
|
|
450
|
+
const run = (path) => split.rows(countFrameConditions(choice), path, p => split.condition(domain, p, q => chain(common, q, 'input-partition', activate), p => ask(p, 'outside-domain')), p => ask(p, 'outside-operation'));
|
|
451
|
+
const profileTree = c2 ? fullWork() : 0;
|
|
452
|
+
const tree = split.condition(m.pre, new Map(), run, path => ask(path, 'outside-pre'));
|
|
453
|
+
if (!tree)
|
|
454
|
+
return decline('tree');
|
|
455
|
+
let nodes = 0, leaves = 0;
|
|
456
|
+
if (c2) {
|
|
457
|
+
const regionCounts = {}, multipliers = {};
|
|
458
|
+
const region = (p) => {
|
|
459
|
+
if (truth(m.pre, p) !== true)
|
|
460
|
+
return 'outside-pre';
|
|
461
|
+
if (truth(same(x(choice.name), n(choice.value)), p) !== true)
|
|
462
|
+
return 'outside-operation';
|
|
463
|
+
if (truth(domain, p) !== true)
|
|
464
|
+
return 'outside-domain';
|
|
465
|
+
if (truth(active, p) !== true)
|
|
466
|
+
return 'inactive';
|
|
467
|
+
const ai = truth(same(a, actor), p), bi = truth(same(b, actor), p);
|
|
468
|
+
if (ai === false && bi === false)
|
|
469
|
+
return 'A';
|
|
470
|
+
if (ai === true && bi === true)
|
|
471
|
+
return 'B';
|
|
472
|
+
if (ai === bi || ai === undefined || bi === undefined)
|
|
473
|
+
return 'before-position';
|
|
474
|
+
const o = ai ? b : a, first = fields[0], second = fields[1], sameFirst = truth(same(get(first, o), get(first, actor)), p);
|
|
475
|
+
if (truth(less(get(first, o), get(first, actor)), p) === true)
|
|
476
|
+
return 'C2';
|
|
477
|
+
if (truth(less(get(first, actor), get(first, o)), p) === true)
|
|
478
|
+
return 'C3b';
|
|
479
|
+
if (sameFirst === true) {
|
|
480
|
+
if (truth(same(get(second, o), get(second, actor)), p) === true)
|
|
481
|
+
return 'C1';
|
|
482
|
+
if (truth(less(get(second, o), get(second, actor)), p) === true)
|
|
483
|
+
return 'C2';
|
|
484
|
+
if (truth(less(get(second, actor), get(second, o)), p) === true)
|
|
485
|
+
return 'C3a';
|
|
486
|
+
}
|
|
487
|
+
return 'before-version';
|
|
488
|
+
};
|
|
489
|
+
const measure = (part, p) => { nodes++; if ('leaf' in part) {
|
|
490
|
+
leaves++;
|
|
491
|
+
const name = region(p);
|
|
492
|
+
regionCounts[name] = (regionCounts[name] ?? 0) + 1;
|
|
493
|
+
return { [name]: 1 };
|
|
494
|
+
} const key = canon(part.split), yes = new Map(p), no = new Map(p); yes.set(key, { lin: part.split, holds: true }); no.set(key, { lin: part.split, holds: false }); const y = measure(part.yes, yes), n = measure(part.no, no), all = {}; for (const name of new Set([...Object.keys(y), ...Object.keys(n)])) {
|
|
495
|
+
const a = y[name] ?? 0, b = n[name] ?? 0;
|
|
496
|
+
all[name] = a + b;
|
|
497
|
+
const table = multipliers[name] ??= {};
|
|
498
|
+
const row = table[key] ??= { atom: part.split, yes: 0, no: 0, occurrences: 0, maxMin: 0, branchingOccurrences: 0 };
|
|
499
|
+
row.yes += a;
|
|
500
|
+
row.no += b;
|
|
501
|
+
row.occurrences++;
|
|
502
|
+
row.maxMin = Math.max(row.maxMin, Math.min(a, b));
|
|
503
|
+
if (a > 1 && b > 1)
|
|
504
|
+
row.branchingOccurrences++;
|
|
505
|
+
} return all; };
|
|
506
|
+
measure(tree, new Map());
|
|
507
|
+
observe?.({ stage: 'replacement-regions', regions: regionCounts, nodes, leaves });
|
|
508
|
+
observe?.({ stage: 'replacement-multipliers', regions: Object.fromEntries(['C1', 'C2', 'inactive'].map(name => [name, Object.values(multipliers[name] ?? {}).filter(row => row.yes > 1 && row.no > 1).sort((a, b) => Math.min(b.yes, b.no) - Math.min(a.yes, a.no))])) });
|
|
509
|
+
}
|
|
510
|
+
else {
|
|
511
|
+
const measure = (part) => { nodes++; if ('leaf' in part)
|
|
512
|
+
leaves++;
|
|
513
|
+
else {
|
|
514
|
+
measure(part.yes);
|
|
515
|
+
measure(part.no);
|
|
516
|
+
} };
|
|
517
|
+
measure(tree);
|
|
518
|
+
}
|
|
519
|
+
observe?.({ stage: 'replacement-tree', nodes, leaves, frames: frames.length, lins: lins.length });
|
|
520
|
+
const profileStable = c2 ? fullWork() : 0;
|
|
521
|
+
const stable = stabilizeGuardedTree(goal, tree, frames, lins, roots, until, { deferCheck: deferred, ...(c2 ? { lemmas } : {}) });
|
|
522
|
+
if (c2)
|
|
523
|
+
observe?.({ stage: 'replacement-profile', prepareUnits: (profileTree - profileStart) / fullRate, treeUnits: (profileStable - profileTree) / fullRate, stabilizeUnits: (fullWork() - profileStable) / fullRate, reads });
|
|
524
|
+
observe?.({ stage: 'replacement-stabilize', checked: !deferred && !!stable.tree, proposed: !!stable.tree, rebased: stable.rebased, failed: stable.failed });
|
|
525
|
+
if (!stable.tree || late(until))
|
|
526
|
+
return decline('stabilization');
|
|
527
|
+
if (framePool)
|
|
528
|
+
observe?.({ stage: 'emitter-frame-pool', emitter: 'replacement', ...framePool.stats() });
|
|
529
|
+
if (c2)
|
|
530
|
+
observe?.({ stage: 'replacement-owned-lemmas', deferOwned, batchOwned, ...ownedStats, retainedLemmas: lemmas.length });
|
|
531
|
+
const cert = { ...request, frames, lins, ...(c2 ? { lemmas } : {}), tree: stable.tree };
|
|
532
|
+
return (options.deferToComposition || checkMC(step.goal.hyps, step.decls, cert)) && !late(until) ? { instances, certs: { [step.goal.name]: cert }, ...(deferred ? { status: 'unchecked' } : {}) } : undefined;
|
|
533
|
+
}
|
|
534
|
+
catch (error) {
|
|
535
|
+
if (error === stopped)
|
|
536
|
+
return;
|
|
537
|
+
throw error;
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type Law, type Machine } from './machine.js';
|
|
2
|
+
import { type RowAgreementShape } from './row-agreement-shape.js';
|
|
3
|
+
import { type CountGuardShape } from './count-guard-shape.js';
|
|
4
|
+
import { type QuorumLawProvenance } from './quorum-laws.js';
|
|
5
|
+
export type LiftedCountGuardShape = {
|
|
6
|
+
origin: Readonly<QuorumLawProvenance>;
|
|
7
|
+
countShape: CountGuardShape;
|
|
8
|
+
countMaps: string[];
|
|
9
|
+
rowAgreement?: RowAgreementShape;
|
|
10
|
+
rowAgreements: {
|
|
11
|
+
law: Law;
|
|
12
|
+
shape: RowAgreementShape;
|
|
13
|
+
}[];
|
|
14
|
+
};
|
|
15
|
+
export declare function discoverLiftedCountGuard(m: Machine, law: Law, family: readonly Law[], observe?: (event: Record<string, unknown>) => void): LiftedCountGuardShape | undefined;
|
|
16
|
+
export declare function discoverLiftedCountOperation(m: Machine, shape: LiftedCountGuardShape, value: number, observe?: (event: Record<string, unknown>) => void): {
|
|
17
|
+
write?: import("./count-write-shape.ts").CountThresholdWrite | undefined;
|
|
18
|
+
kind: "threshold-replace";
|
|
19
|
+
replacement: {
|
|
20
|
+
guard: string;
|
|
21
|
+
input: string;
|
|
22
|
+
};
|
|
23
|
+
name: string;
|
|
24
|
+
value: number;
|
|
25
|
+
} | {
|
|
26
|
+
kind: "copy";
|
|
27
|
+
copy: import("./count-copy-shape.ts").CountRowCopy;
|
|
28
|
+
name: string;
|
|
29
|
+
value: number;
|
|
30
|
+
} | {
|
|
31
|
+
kind: "threshold-replace" | "threshold-increment";
|
|
32
|
+
write: import("./count-write-shape.ts").CountThresholdWrite;
|
|
33
|
+
name: string;
|
|
34
|
+
value: number;
|
|
35
|
+
} | {
|
|
36
|
+
kind: "load" | "replacement" | "frame-or-phase";
|
|
37
|
+
name: string;
|
|
38
|
+
value: number;
|
|
39
|
+
} | undefined;
|
|
40
|
+
export declare function discoverLiftedCountOperations(m: Machine, shape: LiftedCountGuardShape, observe?: (event: Record<string, unknown>) => void): ({
|
|
41
|
+
write?: import("./count-write-shape.ts").CountThresholdWrite | undefined;
|
|
42
|
+
kind: "threshold-replace";
|
|
43
|
+
replacement: {
|
|
44
|
+
guard: string;
|
|
45
|
+
input: string;
|
|
46
|
+
};
|
|
47
|
+
name: string;
|
|
48
|
+
value: number;
|
|
49
|
+
} | {
|
|
50
|
+
kind: "copy";
|
|
51
|
+
copy: import("./count-copy-shape.ts").CountRowCopy;
|
|
52
|
+
name: string;
|
|
53
|
+
value: number;
|
|
54
|
+
} | {
|
|
55
|
+
kind: "threshold-replace" | "threshold-increment";
|
|
56
|
+
write: import("./count-write-shape.ts").CountThresholdWrite;
|
|
57
|
+
name: string;
|
|
58
|
+
value: number;
|
|
59
|
+
} | {
|
|
60
|
+
kind: "load" | "replacement" | "frame-or-phase";
|
|
61
|
+
name: string;
|
|
62
|
+
value: number;
|
|
63
|
+
})[] | undefined;
|