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,9 @@
|
|
|
1
|
+
import { type Law } from './machine.js';
|
|
2
|
+
import { type CountPremiseContext } from './count-premise-view.js';
|
|
3
|
+
export declare function countPremiseSearch<T>(family: Law[], until: number, contexts: (until: number) => CountPremiseContext[], probe: (family: Law[], until: number) => T, accept: (context: CountPremiseContext, result: T, until: number) => T | undefined, observe?: (event: {
|
|
4
|
+
phase: 'premise-context';
|
|
5
|
+
outcome: 'proved' | 'declined' | 'expired' | 'fallback';
|
|
6
|
+
local: number;
|
|
7
|
+
whole: number;
|
|
8
|
+
guardReads?: boolean;
|
|
9
|
+
}) => void, decline?: (error: unknown) => boolean): T;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { clock, withDeadline } from "../kernel/prove.js";
|
|
2
|
+
import { isLocalCountExpiration } from "./count-tier-budget.js";
|
|
3
|
+
import { withTableAdmission } from "./table-admission.js";
|
|
4
|
+
export function countPremiseSearch(family, until, contexts, probe, accept, observe, decline = () => false) {
|
|
5
|
+
// Selection, both local searches and their transport share this allowance.
|
|
6
|
+
// The final quarter is never granted to a local search or its checker.
|
|
7
|
+
const localEnd = clock() + Math.max(0, until - clock()) * 3 / 4;
|
|
8
|
+
const seen = new Set();
|
|
9
|
+
try {
|
|
10
|
+
for (const context of withDeadline(localEnd, () => contexts(localEnd))) {
|
|
11
|
+
if (clock() >= localEnd)
|
|
12
|
+
break;
|
|
13
|
+
if (!context.laws.length || context.laws.length >= family.length || context.selected.length !== context.laws.length || context.laws.some((law, i) => family[context.selected[i]] !== law))
|
|
14
|
+
continue;
|
|
15
|
+
const key = context.selected.join(',');
|
|
16
|
+
if (seen.has(key))
|
|
17
|
+
continue;
|
|
18
|
+
seen.add(key);
|
|
19
|
+
try {
|
|
20
|
+
const result = withDeadline(localEnd, () => {
|
|
21
|
+
const proposed = withTableAdmission(() => probe(context.laws, localEnd));
|
|
22
|
+
return clock() < localEnd ? accept(context, proposed, localEnd) : undefined;
|
|
23
|
+
});
|
|
24
|
+
observe?.({ phase: 'premise-context', outcome: result !== undefined ? 'proved' : 'declined', local: context.laws.length, whole: family.length, guardReads: context.guardReads });
|
|
25
|
+
if (result !== undefined)
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
if (!isLocalCountExpiration(error, until) && !decline(error))
|
|
30
|
+
throw error;
|
|
31
|
+
observe?.({ phase: 'premise-context', outcome: decline(error) ? 'declined' : 'expired', local: context.laws.length, whole: family.length, guardReads: context.guardReads });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (!isLocalCountExpiration(error, until) && !decline(error))
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
observe?.({ phase: 'premise-context', outcome: 'fallback', local: family.length, whole: family.length });
|
|
40
|
+
return withTableAdmission(() => probe(family, until));
|
|
41
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type C, type Law, type Machine } from './machine.js';
|
|
2
|
+
import { type Goal } from '../kernel/kernel.js';
|
|
3
|
+
export type PremiseView = {
|
|
4
|
+
goal: Goal;
|
|
5
|
+
selected: number[];
|
|
6
|
+
omitted: number[];
|
|
7
|
+
allowed: string[];
|
|
8
|
+
guardReads: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function countPremiseMaps(m: Machine, law: Law, until: number, guardReads?: boolean, fixedOnly?: boolean): Set<string> | undefined;
|
|
11
|
+
export declare function countPremiseView(goal: Goal, m: Machine, law: Law, conclusion: C, globals: readonly C[], until: number, guardReads?: boolean): PremiseView | undefined;
|
|
12
|
+
export type CountPremiseContext = {
|
|
13
|
+
laws: Law[];
|
|
14
|
+
selected: number[];
|
|
15
|
+
omitted: number[];
|
|
16
|
+
allowed: string[];
|
|
17
|
+
guardReads: boolean;
|
|
18
|
+
};
|
|
19
|
+
export declare function countPremiseContext(m: Machine, family: Law[], owner: Law, until: number, guardReads?: boolean): CountPremiseContext | undefined;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
// Untrusted operation-local containment. This chooses original hypotheses,
|
|
2
|
+
// never facts: every successful tree must be transported to the complete goal.
|
|
3
|
+
import { n, walkOnce } from "./machine.js";
|
|
4
|
+
import { substC, substE, truth } from "../kernel/kernel.js";
|
|
5
|
+
import { finiteCountChoice } from "./count-cases.js";
|
|
6
|
+
// Same finite-operation recognizer as B's count-frames module, without its
|
|
7
|
+
// unrelated strategy and frame-certificate dependencies.
|
|
8
|
+
function fixedCountFrameCase(m) {
|
|
9
|
+
const choice = finiteCountChoice(m);
|
|
10
|
+
if (!choice)
|
|
11
|
+
return;
|
|
12
|
+
const [name, values] = choice, fixed = new Set();
|
|
13
|
+
const visit = (c) => {
|
|
14
|
+
if (c.op === 'and') {
|
|
15
|
+
c.xs.forEach(visit);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (c.op !== '=')
|
|
19
|
+
return;
|
|
20
|
+
const [a, b] = c.a.op === 'var' ? [c.a, c.b] : [c.b, c.a];
|
|
21
|
+
if (a.op === 'var' && a.name === name && b.op === 'const')
|
|
22
|
+
fixed.add(b.value);
|
|
23
|
+
};
|
|
24
|
+
if (m.assume)
|
|
25
|
+
visit(m.assume);
|
|
26
|
+
if (fixed.size !== 1)
|
|
27
|
+
return;
|
|
28
|
+
const value = [...fixed][0];
|
|
29
|
+
return Number.isSafeInteger(value) && value >= 0 && values.has(value) ? { name, value } : undefined;
|
|
30
|
+
}
|
|
31
|
+
import { late } from "../kernel/prove.js";
|
|
32
|
+
const base = (name) => name.replace(/#$/, '');
|
|
33
|
+
export function countPremiseMaps(m, law, until, guardReads = true, fixedOnly = true) {
|
|
34
|
+
const choice = fixedCountFrameCase(m);
|
|
35
|
+
if ((!choice && fixedOnly) || late(until))
|
|
36
|
+
return;
|
|
37
|
+
// An unspecialized family keeps both branches; it assumes no operation value.
|
|
38
|
+
const vars = choice ? { [choice.name]: n(choice.value) } : {}, flags = {}, resolving = new Set();
|
|
39
|
+
const flag = (name) => {
|
|
40
|
+
if (flags[name])
|
|
41
|
+
return flags[name];
|
|
42
|
+
const source = m.step.flags?.[name];
|
|
43
|
+
if (!source || resolving.has(name) || late(until))
|
|
44
|
+
return;
|
|
45
|
+
resolving.add(name);
|
|
46
|
+
let missing = false;
|
|
47
|
+
walkOnce(source, node => { const c = node; if (c.op === 'flag' && !flag(c.name))
|
|
48
|
+
missing = true; });
|
|
49
|
+
resolving.delete(name);
|
|
50
|
+
if (missing)
|
|
51
|
+
return;
|
|
52
|
+
return flags[name] = substC(source, { vars, flags, maps: {} });
|
|
53
|
+
};
|
|
54
|
+
for (const name of Object.keys(m.step.flags ?? {}))
|
|
55
|
+
if (!flag(name))
|
|
56
|
+
return;
|
|
57
|
+
const allowed = new Set(), targets = new Set();
|
|
58
|
+
const binarySource = (name) => {
|
|
59
|
+
const initial = m.maps?.[name], write = m.step.maps?.[name];
|
|
60
|
+
const value = (e) => e.op === 'const' ? e.value === 0 || e.value === 1 : e.op === 'if' ? value(e.then) && value(e.else) : e.op === 'get' && e.map === name;
|
|
61
|
+
return (initial === 0 || initial === 1) && !!write && value(write.value);
|
|
62
|
+
};
|
|
63
|
+
const collect = (value) => {
|
|
64
|
+
if (late(until))
|
|
65
|
+
return;
|
|
66
|
+
if (value.op === 'get') {
|
|
67
|
+
allowed.add('map:' + base(value.map));
|
|
68
|
+
collect(value.key);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (value.op === 'var') {
|
|
72
|
+
if (Object.hasOwn(m.state, value.name))
|
|
73
|
+
allowed.add('state:' + value.name);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (value.op === 'if') {
|
|
77
|
+
const known = truth(value.c, new Map());
|
|
78
|
+
if (known !== undefined) {
|
|
79
|
+
collect(known ? value.then : value.else);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (guardReads)
|
|
83
|
+
collect(value.c);
|
|
84
|
+
collect(value.then);
|
|
85
|
+
collect(value.else);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (value.op === 'and' || value.op === 'or') {
|
|
89
|
+
if (truth(value, new Map()) !== undefined)
|
|
90
|
+
return;
|
|
91
|
+
value.xs.forEach(collect);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (value.op === 'not') {
|
|
95
|
+
if (truth(value, new Map()) === undefined)
|
|
96
|
+
collect(value.x);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (value.op === 'all') {
|
|
100
|
+
collect(value.c);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if ('a' in value)
|
|
104
|
+
collect(value.a);
|
|
105
|
+
if ('b' in value)
|
|
106
|
+
collect(value.b);
|
|
107
|
+
};
|
|
108
|
+
walkOnce(law.holds, node => { const e = node; if (e.op === 'get')
|
|
109
|
+
targets.add(base(e.map)); });
|
|
110
|
+
collect(law.holds);
|
|
111
|
+
// Stored binary source data, read-only data and phase scalars used by a
|
|
112
|
+
// target update can describe inherited rows in another operation. This is
|
|
113
|
+
// only a vocabulary hint, not a range fact; request maps stay outside it.
|
|
114
|
+
for (const name of targets) {
|
|
115
|
+
const write = m.step.maps?.[name];
|
|
116
|
+
if (!write)
|
|
117
|
+
continue;
|
|
118
|
+
walkOnce(substE(write.value, { vars: {}, flags, maps: {} }), node => {
|
|
119
|
+
const value = node;
|
|
120
|
+
if (value.op === 'var' && Object.hasOwn(m.state, value.name))
|
|
121
|
+
allowed.add('state:' + value.name);
|
|
122
|
+
});
|
|
123
|
+
// Named control guards stay opaque here. Expanding them would confuse a
|
|
124
|
+
// Boolean control cell with a Boolean value copied into the target map.
|
|
125
|
+
walkOnce(write.value, node => {
|
|
126
|
+
const value = node;
|
|
127
|
+
if (value.op === 'get' && !m.inputMaps?.includes(value.map) && (binarySource(value.map) || !Object.hasOwn(m.step.maps ?? {}, value.map) && !Object.hasOwn(m.counts ?? {}, value.map)))
|
|
128
|
+
allowed.add('map:' + base(value.map));
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
// Only writes into the target's maps participate. Following writes into each
|
|
132
|
+
// newly read support map would recreate an unrestricted transitive closure.
|
|
133
|
+
for (const name of targets) {
|
|
134
|
+
const write = m.step.maps?.[name];
|
|
135
|
+
if (write)
|
|
136
|
+
collect(substE(write.value, { vars, flags, maps: {} }));
|
|
137
|
+
}
|
|
138
|
+
// A derived count is in the vocabulary only when all of its underlying
|
|
139
|
+
// reads are already in it; this is containment, never a shared-map union.
|
|
140
|
+
let changed = true;
|
|
141
|
+
while (changed && !late(until)) {
|
|
142
|
+
changed = false;
|
|
143
|
+
for (const [name, count] of Object.entries(m.counts ?? {})) {
|
|
144
|
+
if (allowed.has('map:' + name))
|
|
145
|
+
continue;
|
|
146
|
+
let contained = true;
|
|
147
|
+
walkOnce(count, node => {
|
|
148
|
+
const value = node;
|
|
149
|
+
if (value.op === 'get' && !allowed.has('map:' + base(value.map)))
|
|
150
|
+
contained = false;
|
|
151
|
+
if (value.op === 'var' && Object.hasOwn(m.state, value.name) && !allowed.has('state:' + value.name))
|
|
152
|
+
contained = false;
|
|
153
|
+
});
|
|
154
|
+
if (contained) {
|
|
155
|
+
allowed.add('map:' + name);
|
|
156
|
+
changed = true;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return late(until) ? undefined : allowed;
|
|
161
|
+
}
|
|
162
|
+
export function countPremiseView(goal, m, law, conclusion, globals, until, guardReads = true) {
|
|
163
|
+
if (late(until) || goal.hyps.length > 1024)
|
|
164
|
+
return;
|
|
165
|
+
const allowed = countPremiseMaps(m, law, until, guardReads);
|
|
166
|
+
if (!allowed)
|
|
167
|
+
return;
|
|
168
|
+
const root = JSON.stringify(conclusion), fixed = new Set(globals.map(h => JSON.stringify(h)));
|
|
169
|
+
if (!goal.hyps.some(h => JSON.stringify(h) === root))
|
|
170
|
+
return;
|
|
171
|
+
const selected = [], omitted = [];
|
|
172
|
+
for (const [index, hypothesis] of goal.hyps.entries()) {
|
|
173
|
+
if (late(until))
|
|
174
|
+
return;
|
|
175
|
+
let contained = true;
|
|
176
|
+
walkOnce(hypothesis, node => {
|
|
177
|
+
const value = node;
|
|
178
|
+
if (value.op === 'get' && !allowed.has('map:' + base(value.map)))
|
|
179
|
+
contained = false;
|
|
180
|
+
if (value.op === 'var' && Object.hasOwn(m.state, value.name) && !allowed.has('state:' + value.name))
|
|
181
|
+
contained = false;
|
|
182
|
+
});
|
|
183
|
+
const key = JSON.stringify(hypothesis);
|
|
184
|
+
if (contained || key === root || fixed.has(key))
|
|
185
|
+
selected.push(index);
|
|
186
|
+
else
|
|
187
|
+
omitted.push(index);
|
|
188
|
+
}
|
|
189
|
+
if (!omitted.length)
|
|
190
|
+
return;
|
|
191
|
+
return { goal: { name: goal.name, hyps: selected.map(i => goal.hyps[i]) }, selected, omitted, allowed: [...allowed].sort(), guardReads };
|
|
192
|
+
}
|
|
193
|
+
// Family-level search uses exactly the same all-reads containment test as the
|
|
194
|
+
// operation-local view. Without a fixed operation no substitution is made:
|
|
195
|
+
// both branches contribute vocabulary, never a guessed transition or fact.
|
|
196
|
+
export function countPremiseContext(m, family, owner, until, guardReads = true) {
|
|
197
|
+
if (!family.includes(owner) || family.length > 1024 || late(until))
|
|
198
|
+
return;
|
|
199
|
+
const allowed = countPremiseMaps(m, owner, until, guardReads, false);
|
|
200
|
+
if (!allowed)
|
|
201
|
+
return;
|
|
202
|
+
const selected = [], omitted = [];
|
|
203
|
+
for (const [index, law] of family.entries()) {
|
|
204
|
+
if (late(until))
|
|
205
|
+
return;
|
|
206
|
+
let contained = true;
|
|
207
|
+
walkOnce(law.holds, node => {
|
|
208
|
+
const value = node;
|
|
209
|
+
if (value.op === 'get' && !allowed.has('map:' + base(value.map)))
|
|
210
|
+
contained = false;
|
|
211
|
+
if (value.op === 'var' && Object.hasOwn(m.state, value.name) && !allowed.has('state:' + value.name))
|
|
212
|
+
contained = false;
|
|
213
|
+
});
|
|
214
|
+
if (law === owner || contained)
|
|
215
|
+
selected.push(index);
|
|
216
|
+
else
|
|
217
|
+
omitted.push(index);
|
|
218
|
+
}
|
|
219
|
+
return omitted.length ? { laws: selected.map(i => family[i]), selected, omitted, allowed: [...allowed].sort(), guardReads } : undefined;
|
|
220
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export type CountComponentRecipe = Readonly<{
|
|
2
|
+
id: string;
|
|
3
|
+
kind: 'ordinary' | 'strategy';
|
|
4
|
+
required?: readonly string[];
|
|
5
|
+
optional?: readonly string[];
|
|
6
|
+
}>;
|
|
7
|
+
export type CountComponentOptions = Readonly<{
|
|
8
|
+
recipes?: ReadonlyMap<string, readonly CountComponentRecipe[]>;
|
|
9
|
+
costs?: ReadonlyMap<string, number>;
|
|
10
|
+
discoveryFirst?: boolean;
|
|
11
|
+
proofGuided?: boolean;
|
|
12
|
+
discoveryContexts?: ReadonlyMap<string, string>;
|
|
13
|
+
targets?: readonly string[];
|
|
14
|
+
held?: ReadonlyMap<string, readonly string[]>;
|
|
15
|
+
discovered?: readonly string[];
|
|
16
|
+
failed?: readonly string[];
|
|
17
|
+
}>;
|
|
18
|
+
export type ComponentOutcome = Readonly<{
|
|
19
|
+
kind: 'proof';
|
|
20
|
+
citations: readonly string[];
|
|
21
|
+
}> | Readonly<{
|
|
22
|
+
kind: 'unknown';
|
|
23
|
+
reason: string;
|
|
24
|
+
}> | Readonly<{
|
|
25
|
+
kind: 'refuted' | 'refused';
|
|
26
|
+
reason?: string;
|
|
27
|
+
}>;
|
|
28
|
+
export type ComponentAttempt = Readonly<{
|
|
29
|
+
kind: 'attempt';
|
|
30
|
+
name: string;
|
|
31
|
+
component: readonly string[];
|
|
32
|
+
context: readonly string[];
|
|
33
|
+
phase: 'dissolve' | 'joint';
|
|
34
|
+
discovery: boolean;
|
|
35
|
+
purpose: 'discovery' | 'required';
|
|
36
|
+
recipe: CountComponentRecipe;
|
|
37
|
+
pass?: 0 | 1;
|
|
38
|
+
}>;
|
|
39
|
+
export type ComponentDecision = ComponentAttempt | Readonly<{
|
|
40
|
+
kind: 'ready';
|
|
41
|
+
members: readonly string[];
|
|
42
|
+
}>;
|
|
43
|
+
export declare function countPrerequisiteComponents(input: readonly string[], requirements: ReadonlyMap<string, readonly string[]>, strategies?: readonly string[], available?: readonly string[], options?: CountComponentOptions): {
|
|
44
|
+
next: () => ComponentDecision | undefined;
|
|
45
|
+
finish: (name: string, result: ComponentOutcome | readonly string[] | undefined) => {
|
|
46
|
+
held: boolean;
|
|
47
|
+
invalidated: readonly string[];
|
|
48
|
+
};
|
|
49
|
+
commit: (names: readonly string[]) => void;
|
|
50
|
+
reject: (names: readonly string[]) => readonly string[];
|
|
51
|
+
available: () => string[];
|
|
52
|
+
failed: () => string[];
|
|
53
|
+
held: () => string[];
|
|
54
|
+
unknown: () => {
|
|
55
|
+
name: string;
|
|
56
|
+
reason: string;
|
|
57
|
+
component: readonly string[];
|
|
58
|
+
citedBy: string[];
|
|
59
|
+
}[];
|
|
60
|
+
retryCount: () => {
|
|
61
|
+
[k: string]: number;
|
|
62
|
+
};
|
|
63
|
+
discovered: () => string[];
|
|
64
|
+
discoveryContexts: () => Map<string, string>;
|
|
65
|
+
required: () => string[];
|
|
66
|
+
components: () => string[][];
|
|
67
|
+
};
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
export function countPrerequisiteComponents(input, requirements, strategies = [], available = [], options = {}) {
|
|
2
|
+
const order = [...input], members = new Set(order), strategic = new Set(strategies), admitted = new Set(available), failed = new Set(options.failed ?? []), dissolved = new Set(), discovered = new Set(options.discovered ?? []);
|
|
3
|
+
const required = new Map(order.map(name => [name, [...new Set(requirements.get(name) ?? [])].filter(p => p !== name)])), actual = new Map();
|
|
4
|
+
const recipes = new Map();
|
|
5
|
+
for (const name of order) {
|
|
6
|
+
const declared = options.recipes?.get(name) ?? [{ id: strategic.has(name) ? 'strategy' : 'ordinary', kind: strategic.has(name) ? 'strategy' : 'ordinary', ...(strategic.has(name) ? { required: required.get(name) } : {}) }];
|
|
7
|
+
recipes.set(name, declared.map(recipe => Object.freeze({ ...recipe, ...(recipe.required ? { required: [...recipe.required] } : {}), ...(recipe.optional ? { optional: [...recipe.optional] } : {}) })));
|
|
8
|
+
}
|
|
9
|
+
for (const [name, premises] of options.held ?? []) {
|
|
10
|
+
if (!members.has(name) || premises.some(p => !members.has(p) || failed.has(p)))
|
|
11
|
+
throw Error('invalid remembered component');
|
|
12
|
+
actual.set(name, [...premises]);
|
|
13
|
+
}
|
|
14
|
+
const costs = new Map(order.map((name, index) => [name, options.costs?.get(name) ?? index]));
|
|
15
|
+
const retries = new Map(), requiredRuns = new Set(), discoveryContexts = new Map(options.discoveryContexts), unknown = new Map();
|
|
16
|
+
let active;
|
|
17
|
+
if (members.size !== order.length || available.some(name => !members.has(name)) || strategies.some(name => !members.has(name)) || [...costs.values()].some(value => !Number.isFinite(value)))
|
|
18
|
+
throw Error('ambiguous component family');
|
|
19
|
+
const primary = (name) => recipes.get(name)?.[0];
|
|
20
|
+
if (order.some(name => !primary(name)))
|
|
21
|
+
throw Error('component member has no recipe');
|
|
22
|
+
const uncertain = (name) => primary(name)?.required === undefined;
|
|
23
|
+
const deps = (name) => actual.get(name) ?? required.get(name) ?? [];
|
|
24
|
+
const live = () => order.filter(name => !admitted.has(name) && !failed.has(name));
|
|
25
|
+
const availableStamp = () => JSON.stringify(order.filter(name => admitted.has(name)));
|
|
26
|
+
for (const name of discovered)
|
|
27
|
+
if (!discoveryContexts.has(name))
|
|
28
|
+
discoveryContexts.set(name, availableStamp());
|
|
29
|
+
const stamp = (group, context, purpose = 'required') => JSON.stringify([group, context, order.filter(name => admitted.has(name)), purpose]);
|
|
30
|
+
function needed() {
|
|
31
|
+
const out = new Set(options.targets ?? strategies), todo = [...out];
|
|
32
|
+
for (const name of todo)
|
|
33
|
+
for (const premise of deps(name))
|
|
34
|
+
if (members.has(premise) && !out.has(premise)) {
|
|
35
|
+
out.add(premise);
|
|
36
|
+
todo.push(premise);
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
for (const name of discovered)
|
|
41
|
+
if (members.has(name) && !actual.has(name) && !failed.has(name))
|
|
42
|
+
unknown.set(name, { reason: 'parked discovery', component: [name], stamp: '' });
|
|
43
|
+
const knownStrategy = (name) => primary(name)?.kind === 'strategy' && primary(name)?.required !== undefined;
|
|
44
|
+
const ranked = (group, guided = options.proofGuided) => [...group].sort((a, b) => (guided ? Number(requiredRuns.has(a)) - Number(requiredRuns.has(b)) || Number(knownStrategy(b)) - Number(knownStrategy(a)) : 0) || costs.get(a) - costs.get(b) || order.indexOf(a) - order.indexOf(b));
|
|
45
|
+
function components() {
|
|
46
|
+
const pending = new Set(live()), index = new Map(), low = new Map(), stack = [], onStack = new Set(), out = [];
|
|
47
|
+
// Unknown ordinary requirements are possibly incoming, not known absent.
|
|
48
|
+
// Only an actual citation (or an expired required prerequisite) groups one
|
|
49
|
+
// with its user. These reverse scheduling edges never become proof premises.
|
|
50
|
+
const reverse = new Map();
|
|
51
|
+
for (const owner of pending)
|
|
52
|
+
for (const premise of deps(owner))
|
|
53
|
+
if (pending.has(premise) && uncertain(premise) && (actual.has(owner) || unknown.has(premise) && (!options.discoveryFirst || needed().has(owner)))) {
|
|
54
|
+
const users = reverse.get(premise) ?? [];
|
|
55
|
+
users.push(owner);
|
|
56
|
+
reverse.set(premise, users);
|
|
57
|
+
}
|
|
58
|
+
const edges = (name) => [...deps(name), ...reverse.get(name) ?? []];
|
|
59
|
+
let at = 0;
|
|
60
|
+
const visit = (name) => {
|
|
61
|
+
index.set(name, at);
|
|
62
|
+
low.set(name, at++);
|
|
63
|
+
stack.push(name);
|
|
64
|
+
onStack.add(name);
|
|
65
|
+
for (const premise of edges(name))
|
|
66
|
+
if (pending.has(premise)) {
|
|
67
|
+
if (!index.has(premise)) {
|
|
68
|
+
visit(premise);
|
|
69
|
+
low.set(name, Math.min(low.get(name), low.get(premise)));
|
|
70
|
+
}
|
|
71
|
+
else if (onStack.has(premise))
|
|
72
|
+
low.set(name, Math.min(low.get(name), index.get(premise)));
|
|
73
|
+
}
|
|
74
|
+
if (low.get(name) === index.get(name)) {
|
|
75
|
+
const group = [];
|
|
76
|
+
for (;;) {
|
|
77
|
+
const member = stack.pop();
|
|
78
|
+
onStack.delete(member);
|
|
79
|
+
group.push(member);
|
|
80
|
+
if (member === name)
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
out.push(order.filter(member => group.includes(member)));
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
for (const name of pending)
|
|
87
|
+
if (!index.has(name))
|
|
88
|
+
visit(name);
|
|
89
|
+
return out.sort((a, b) => costs.get(ranked(a)[0]) - costs.get(ranked(b)[0]));
|
|
90
|
+
}
|
|
91
|
+
function next() {
|
|
92
|
+
if (active)
|
|
93
|
+
return active;
|
|
94
|
+
const groups = components(), pending = new Set(live());
|
|
95
|
+
// Commit actual closed scopes before scheduling more search. This shrinks
|
|
96
|
+
// later discovery contexts without claiming native whole-family acceptance.
|
|
97
|
+
for (const group of groups) {
|
|
98
|
+
const own = new Set(group);
|
|
99
|
+
if (group.every(name => actual.has(name) && actual.get(name).every(p => admitted.has(p) || own.has(p))))
|
|
100
|
+
return { kind: 'ready', members: group };
|
|
101
|
+
}
|
|
102
|
+
if (options.discoveryFirst) {
|
|
103
|
+
const name = ranked(live(), false).find(name => !strategic.has(name) && !actual.has(name) && (!discovered.has(name) || options.proofGuided && discoveryContexts.get(name) !== availableStamp()));
|
|
104
|
+
if (name !== undefined) {
|
|
105
|
+
active = { kind: 'attempt', name, component: groups.find(group => group.includes(name)), context: order.filter(member => admitted.has(member) || member === name), phase: 'joint', discovery: true, purpose: 'discovery', recipe: primary(name) };
|
|
106
|
+
return active;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const wanted = needed();
|
|
110
|
+
const fresh = (group) => group.some(name => !actual.has(name) && !requiredRuns.has(name) && (strategic.has(name) || wanted.has(name)));
|
|
111
|
+
const strategy = (group) => group.some(name => !actual.has(name) && knownStrategy(name));
|
|
112
|
+
const scheduled = options.discoveryFirst ? [...groups].sort((a, b) => options.proofGuided
|
|
113
|
+
? Number(fresh(b)) - Number(fresh(a)) || Number(strategy(b)) - Number(strategy(a))
|
|
114
|
+
: Number(b.some(name => strategic.has(name))) - Number(a.some(name => strategic.has(name)))) : groups;
|
|
115
|
+
for (const group of scheduled) {
|
|
116
|
+
const own = new Set(group);
|
|
117
|
+
if (!options.discoveryFirst && !group.every(name => deps(name).every(p => !pending.has(p) || own.has(p))))
|
|
118
|
+
continue;
|
|
119
|
+
const sorted = ranked(group);
|
|
120
|
+
// An unknown ordinary recipe cannot justify cycle dissolution. A declared
|
|
121
|
+
// alternative must have a known required set entirely outside this group.
|
|
122
|
+
for (const name of group.length > 1 ? sorted : []) {
|
|
123
|
+
if (actual.has(name) || options.discoveryFirst && !strategic.has(name) && !wanted.has(name))
|
|
124
|
+
continue;
|
|
125
|
+
const alternative = recipes.get(name).find(recipe => recipe.id !== primary(name).id && recipe.required !== undefined && recipe.required.every(p => !own.has(p)) && !dissolved.has(JSON.stringify([name, recipe.id])));
|
|
126
|
+
if (alternative) {
|
|
127
|
+
active = { kind: 'attempt', name, component: group, context: order.filter(member => admitted.has(member) || member === name), phase: 'dissolve', discovery: false, purpose: 'required', recipe: alternative };
|
|
128
|
+
return active;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const discovery = group.length === 1 && uncertain(group[0]), potential = new Set(group);
|
|
132
|
+
for (let changed = true; changed;) {
|
|
133
|
+
changed = false;
|
|
134
|
+
for (const member of pending)
|
|
135
|
+
if (!potential.has(member) && (deps(member).some(p => potential.has(p)) || options.discoveryFirst && [...potential].some(owner => deps(owner).includes(member)))) {
|
|
136
|
+
potential.add(member);
|
|
137
|
+
changed = true;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const context = order.filter(member => admitted.has(member) || potential.has(member) || uncertain(member) && pending.has(member) || discovery && pending.has(member));
|
|
141
|
+
const currentStamp = stamp(group, context);
|
|
142
|
+
const retry = (name) => options.proofGuided && primary(name).kind === 'ordinary' && unknown.get(name)?.stamp === currentStamp && unknown.get(name)?.pass === 0;
|
|
143
|
+
const name = sorted.find(member => !actual.has(member) && (!options.discoveryFirst || strategic.has(member) || wanted.has(member)) && (unknown.get(member)?.stamp !== currentStamp || retry(member)));
|
|
144
|
+
if (name === undefined)
|
|
145
|
+
continue;
|
|
146
|
+
active = { kind: 'attempt', name, component: group, context, phase: 'joint', discovery, purpose: 'required', recipe: primary(name), ...(options.proofGuided ? { pass: retry(name) ? 1 : 0 } : {}) };
|
|
147
|
+
return active;
|
|
148
|
+
}
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
function finish(name, result) {
|
|
152
|
+
if (!active || active.name !== name)
|
|
153
|
+
throw Error('component result without matching attempt');
|
|
154
|
+
const attempt = active;
|
|
155
|
+
active = undefined;
|
|
156
|
+
const received = result === undefined ? { kind: 'refused' } : 'kind' in result ? result : { kind: 'proof', citations: result };
|
|
157
|
+
const outcome = attempt.purpose === 'discovery' && received.kind === 'refuted' ? { kind: 'unknown', reason: 'narrow-sat' } : received;
|
|
158
|
+
if (attempt.purpose === 'discovery') {
|
|
159
|
+
discovered.add(name);
|
|
160
|
+
discoveryContexts.set(name, availableStamp());
|
|
161
|
+
}
|
|
162
|
+
else
|
|
163
|
+
requiredRuns.add(name);
|
|
164
|
+
if (attempt.phase === 'dissolve')
|
|
165
|
+
dissolved.add(JSON.stringify([name, attempt.recipe.id]));
|
|
166
|
+
if (outcome.kind === 'unknown') {
|
|
167
|
+
if (attempt.phase !== 'dissolve')
|
|
168
|
+
unknown.set(name, { reason: outcome.reason, component: [...attempt.component], stamp: stamp(attempt.component, attempt.context, attempt.purpose), ...(attempt.pass === undefined ? {} : { pass: attempt.pass }) });
|
|
169
|
+
return { held: false, invalidated: [] };
|
|
170
|
+
}
|
|
171
|
+
const scope = outcome.kind === 'proof' ? [...new Set(outcome.citations)].filter(p => p !== name) : undefined;
|
|
172
|
+
const valid = scope && scope.every(p => members.has(p) && !failed.has(p) && attempt.context.includes(p));
|
|
173
|
+
if (!valid) {
|
|
174
|
+
if (attempt.phase === 'dissolve')
|
|
175
|
+
return { held: false, invalidated: [] };
|
|
176
|
+
failed.add(name);
|
|
177
|
+
actual.delete(name);
|
|
178
|
+
unknown.delete(name);
|
|
179
|
+
const invalidated = [], unavailable = new Set([name]);
|
|
180
|
+
for (let changed = true; changed;) {
|
|
181
|
+
changed = false;
|
|
182
|
+
for (const [owner, premises] of actual)
|
|
183
|
+
if (premises.some(p => unavailable.has(p))) {
|
|
184
|
+
actual.delete(owner);
|
|
185
|
+
unknown.delete(owner);
|
|
186
|
+
unavailable.add(owner);
|
|
187
|
+
invalidated.push(owner);
|
|
188
|
+
retries.set(owner, (retries.get(owner) ?? 0) + 1);
|
|
189
|
+
changed = true;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return { held: false, invalidated };
|
|
193
|
+
}
|
|
194
|
+
unknown.delete(name);
|
|
195
|
+
actual.set(name, scope);
|
|
196
|
+
return { held: true, invalidated: [] };
|
|
197
|
+
}
|
|
198
|
+
// Only the caller's validated original-reachable evidence uses this entry.
|
|
199
|
+
// Dependents lose their old scopes/commit status, not their truth: rebuild
|
|
200
|
+
// them in the reduced context rather than treating them as counterexamples.
|
|
201
|
+
function reject(names) {
|
|
202
|
+
if (names.some(name => !members.has(name)))
|
|
203
|
+
throw Error('unknown rejected member');
|
|
204
|
+
const unavailable = new Set(names), invalidated = [];
|
|
205
|
+
for (const name of names) {
|
|
206
|
+
failed.add(name);
|
|
207
|
+
actual.delete(name);
|
|
208
|
+
admitted.delete(name);
|
|
209
|
+
unknown.delete(name);
|
|
210
|
+
}
|
|
211
|
+
for (let changed = true; changed;) {
|
|
212
|
+
changed = false;
|
|
213
|
+
for (const [owner, premises] of actual)
|
|
214
|
+
if (premises.some(p => unavailable.has(p))) {
|
|
215
|
+
actual.delete(owner);
|
|
216
|
+
admitted.delete(owner);
|
|
217
|
+
unknown.delete(owner);
|
|
218
|
+
requiredRuns.delete(owner);
|
|
219
|
+
discovered.delete(owner);
|
|
220
|
+
discoveryContexts.delete(owner);
|
|
221
|
+
unavailable.add(owner);
|
|
222
|
+
invalidated.push(owner);
|
|
223
|
+
retries.set(owner, (retries.get(owner) ?? 0) + 1);
|
|
224
|
+
changed = true;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (active && (unavailable.has(active.name) || active.context.some(name => unavailable.has(name))))
|
|
228
|
+
active = undefined;
|
|
229
|
+
return invalidated;
|
|
230
|
+
}
|
|
231
|
+
function commit(names) {
|
|
232
|
+
const decision = next();
|
|
233
|
+
if (decision?.kind !== 'ready' || names.length !== decision.members.length || names.some((name, i) => name !== decision.members[i]))
|
|
234
|
+
throw Error('component not closed');
|
|
235
|
+
for (const name of names)
|
|
236
|
+
admitted.add(name);
|
|
237
|
+
}
|
|
238
|
+
return { next, finish, commit, reject, available: () => order.filter(name => admitted.has(name)), failed: () => order.filter(name => failed.has(name)), held: () => order.filter(name => actual.has(name) && !admitted.has(name)), unknown: () => order.filter(name => unknown.has(name) && !admitted.has(name) && !failed.has(name)).map(name => ({ name, reason: unknown.get(name).reason, component: unknown.get(name).component, citedBy: order.filter(owner => actual.get(owner)?.includes(name)) })), retryCount: () => Object.fromEntries(retries), discovered: () => order.filter(name => discovered.has(name)), discoveryContexts: () => new Map(discoveryContexts), required: () => order.filter(name => needed().has(name)), components };
|
|
239
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type CountRememberedScope = Readonly<{
|
|
2
|
+
owner: Readonly<{
|
|
3
|
+
name: string;
|
|
4
|
+
}>;
|
|
5
|
+
premises: readonly Readonly<{
|
|
6
|
+
name: string;
|
|
7
|
+
}>[];
|
|
8
|
+
}>;
|
|
9
|
+
export type CountPrerequisiteMemory<S extends CountRememberedScope> = {
|
|
10
|
+
machine: string;
|
|
11
|
+
family: string;
|
|
12
|
+
keys: Map<string, string>;
|
|
13
|
+
scopes: Map<string, S>;
|
|
14
|
+
committed: Set<string>;
|
|
15
|
+
discovered: Set<string>;
|
|
16
|
+
failed: Set<string>;
|
|
17
|
+
discoveryContexts?: Map<string, string>;
|
|
18
|
+
};
|
|
19
|
+
export declare function prepareCountPrerequisiteMemory<S extends CountRememberedScope>(previous: CountPrerequisiteMemory<S> | undefined, machine: unknown, laws: readonly Readonly<{
|
|
20
|
+
name: string;
|
|
21
|
+
}>[]): {
|
|
22
|
+
state: CountPrerequisiteMemory<S>;
|
|
23
|
+
invalidated: string[];
|
|
24
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export function prepareCountPrerequisiteMemory(previous, machine, laws) {
|
|
2
|
+
const machineKey = JSON.stringify(machine);
|
|
3
|
+
if (typeof machineKey !== 'string')
|
|
4
|
+
throw Error('invalid remembered machine');
|
|
5
|
+
const keys = new Map(laws.map(law => [law.name, JSON.stringify(law)])), family = JSON.stringify([...keys]);
|
|
6
|
+
if (keys.size !== laws.length)
|
|
7
|
+
throw Error('ambiguous remembered family');
|
|
8
|
+
const state = previous?.machine === machineKey ? previous : { machine: machineKey, family, keys, scopes: new Map(), committed: new Set(), discovered: new Set(), failed: new Set() };
|
|
9
|
+
const invalidated = new Set(state === previous ? [] : previous?.scopes.keys());
|
|
10
|
+
if (state === previous) {
|
|
11
|
+
for (const [name, scope] of state.scopes)
|
|
12
|
+
if (keys.get(name) !== state.keys.get(name) || [scope.owner, ...scope.premises].some(law => !keys.has(law.name) || keys.get(law.name) !== state.keys.get(law.name)))
|
|
13
|
+
invalidated.add(name);
|
|
14
|
+
for (let changed = true; changed;) {
|
|
15
|
+
changed = false;
|
|
16
|
+
for (const [name, scope] of state.scopes)
|
|
17
|
+
if (!invalidated.has(name) && scope.premises.some(law => invalidated.has(law.name))) {
|
|
18
|
+
invalidated.add(name);
|
|
19
|
+
changed = true;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
for (const name of invalidated) {
|
|
23
|
+
state.scopes.delete(name);
|
|
24
|
+
state.committed.delete(name);
|
|
25
|
+
}
|
|
26
|
+
for (const name of state.discovered)
|
|
27
|
+
if (!keys.has(name) || keys.get(name) !== state.keys.get(name)) {
|
|
28
|
+
state.discovered.delete(name);
|
|
29
|
+
state.discoveryContexts?.delete(name);
|
|
30
|
+
}
|
|
31
|
+
if (state.family !== family)
|
|
32
|
+
state.failed.clear();
|
|
33
|
+
}
|
|
34
|
+
state.keys = keys;
|
|
35
|
+
state.family = family;
|
|
36
|
+
return { state, invalidated: [...invalidated] };
|
|
37
|
+
}
|