gdp-wired 0.47.0 → 0.48.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.
Files changed (170) hide show
  1. package/README.md +15 -4
  2. package/dist/core/carry.d.ts +15 -0
  3. package/dist/core/carry.js +651 -0
  4. package/dist/core/cli.d.ts +3 -1
  5. package/dist/core/cli.js +28 -8
  6. package/dist/core/count-cases.d.ts +24 -0
  7. package/dist/core/count-cases.js +320 -0
  8. package/dist/core/count-cert-grow.d.ts +4 -0
  9. package/dist/core/count-cert-grow.js +37 -0
  10. package/dist/core/count-cert-transport.d.ts +3 -0
  11. package/dist/core/count-cert-transport.js +58 -0
  12. package/dist/core/count-completion.d.ts +9 -0
  13. package/dist/core/count-completion.js +27 -0
  14. package/dist/core/count-cubes.d.ts +8 -0
  15. package/dist/core/count-cubes.js +69 -0
  16. package/dist/core/count-demand.d.ts +37 -0
  17. package/dist/core/count-demand.js +361 -0
  18. package/dist/core/count-facts.d.ts +52 -0
  19. package/dist/core/count-facts.js +247 -0
  20. package/dist/core/count-focus-proof.d.ts +8 -0
  21. package/dist/core/count-focus-proof.js +140 -0
  22. package/dist/core/count-focused.d.ts +22 -0
  23. package/dist/core/count-focused.js +676 -0
  24. package/dist/core/count-ranges.d.ts +5 -0
  25. package/dist/core/count-ranges.js +65 -0
  26. package/dist/core/count-recovery/action-guard.d.ts +5 -0
  27. package/dist/core/count-recovery/action-guard.js +51 -0
  28. package/dist/core/count-recovery/boolean-core.d.ts +16 -0
  29. package/dist/core/count-recovery/boolean-core.js +258 -0
  30. package/dist/core/count-recovery/carried-case.d.ts +2 -0
  31. package/dist/core/count-recovery/carried-case.js +24 -0
  32. package/dist/core/count-recovery/conditional-check-cache.d.ts +23 -0
  33. package/dist/core/count-recovery/conditional-check-cache.js +130 -0
  34. package/dist/core/count-recovery/conditional-cuts.d.ts +6 -0
  35. package/dist/core/count-recovery/conditional-cuts.js +318 -0
  36. package/dist/core/count-recovery/conditional-proof.d.ts +19 -0
  37. package/dist/core/count-recovery/conditional-proof.js +306 -0
  38. package/dist/core/count-recovery/derivability-closure.d.ts +14 -0
  39. package/dist/core/count-recovery/derivability-closure.js +533 -0
  40. package/dist/core/count-recovery/empty-count-source.d.ts +2 -0
  41. package/dist/core/count-recovery/empty-count-source.js +40 -0
  42. package/dist/core/count-recovery/field-bound-lemmas.d.ts +23 -0
  43. package/dist/core/count-recovery/field-bound-lemmas.js +640 -0
  44. package/dist/core/count-recovery/field-case.d.ts +5 -0
  45. package/dist/core/count-recovery/field-case.js +89 -0
  46. package/dist/core/count-recovery/field-demand.d.ts +46 -0
  47. package/dist/core/count-recovery/field-demand.js +47 -0
  48. package/dist/core/count-recovery/field-only.d.ts +3 -0
  49. package/dist/core/count-recovery/field-only.js +18 -0
  50. package/dist/core/count-recovery/fold-path.d.ts +6 -0
  51. package/dist/core/count-recovery/fold-path.js +35 -0
  52. package/dist/core/count-recovery/frame-lemmas.d.ts +9 -0
  53. package/dist/core/count-recovery/frame-lemmas.js +120 -0
  54. package/dist/core/count-recovery/guard-cases.d.ts +12 -0
  55. package/dist/core/count-recovery/guard-cases.js +138 -0
  56. package/dist/core/count-recovery/key-closure.d.ts +14 -0
  57. package/dist/core/count-recovery/key-closure.js +62 -0
  58. package/dist/core/count-recovery/leaf-allowance.d.ts +4 -0
  59. package/dist/core/count-recovery/leaf-allowance.js +7 -0
  60. package/dist/core/count-recovery/lift-count-proxies.d.ts +6 -0
  61. package/dist/core/count-recovery/lift-count-proxies.js +175 -0
  62. package/dist/core/count-recovery/live-dependencies.d.ts +6 -0
  63. package/dist/core/count-recovery/live-dependencies.js +76 -0
  64. package/dist/core/count-recovery/member-inclusions.d.ts +11 -0
  65. package/dist/core/count-recovery/member-inclusions.js +168 -0
  66. package/dist/core/count-recovery/member-premises.d.ts +29 -0
  67. package/dist/core/count-recovery/member-premises.js +114 -0
  68. package/dist/core/count-recovery/natural-cases.d.ts +6 -0
  69. package/dist/core/count-recovery/natural-cases.js +59 -0
  70. package/dist/core/count-recovery/ops.d.ts +6 -0
  71. package/dist/core/count-recovery/ops.js +8 -0
  72. package/dist/core/count-recovery/pre-state-source.d.ts +8 -0
  73. package/dist/core/count-recovery/pre-state-source.js +18 -0
  74. package/dist/core/count-recovery/rebase-path.d.ts +9 -0
  75. package/dist/core/count-recovery/rebase-path.js +70 -0
  76. package/dist/core/count-recovery/rename-proof.d.ts +2 -0
  77. package/dist/core/count-recovery/rename-proof.js +102 -0
  78. package/dist/core/count-recovery/row-cases.d.ts +16 -0
  79. package/dist/core/count-recovery/row-cases.js +291 -0
  80. package/dist/core/count-recovery/scalar-guards.d.ts +7 -0
  81. package/dist/core/count-recovery/scalar-guards.js +291 -0
  82. package/dist/core/count-recovery/source-memo.d.ts +12 -0
  83. package/dist/core/count-recovery/source-memo.js +67 -0
  84. package/dist/core/count-select.d.ts +16 -0
  85. package/dist/core/count-select.js +24 -0
  86. package/dist/core/count-support.d.ts +598 -0
  87. package/dist/core/count-support.js +2080 -0
  88. package/dist/core/count-unions.d.ts +2 -0
  89. package/dist/core/count-unions.js +139 -0
  90. package/dist/core/count-witness-flags.d.ts +9 -0
  91. package/dist/core/count-witness-flags.js +37 -0
  92. package/dist/core/count-write-frames.d.ts +12 -0
  93. package/dist/core/count-write-frames.js +206 -0
  94. package/dist/core/counts.d.ts +20 -2
  95. package/dist/core/counts.js +807 -156
  96. package/dist/core/dsl.d.ts +50 -6
  97. package/dist/core/dsl.js +307 -65
  98. package/dist/core/effect.js +8 -1
  99. package/dist/core/exists.d.ts +1 -1
  100. package/dist/core/exists.js +80 -15
  101. package/dist/core/extract-check.d.ts +7 -1
  102. package/dist/core/extract-check.js +130 -13
  103. package/dist/core/extract-read.d.ts +22 -8
  104. package/dist/core/extract-read.js +29 -11
  105. package/dist/core/extract-shapes.js +122 -41
  106. package/dist/core/extract-standalone.js +53 -9
  107. package/dist/core/extract.js +9 -3
  108. package/dist/core/field-laws.d.ts +2 -0
  109. package/dist/core/field-laws.js +100 -0
  110. package/dist/core/finite-frontiers.d.ts +5 -0
  111. package/dist/core/finite-frontiers.js +116 -0
  112. package/dist/core/finite-houdini.d.ts +52 -0
  113. package/dist/core/finite-houdini.js +460 -0
  114. package/dist/core/finite-model.d.ts +13 -0
  115. package/dist/core/finite-model.js +68 -0
  116. package/dist/core/finite-tiny.d.ts +72 -0
  117. package/dist/core/finite-tiny.js +1052 -0
  118. package/dist/core/infer.d.ts +1 -1
  119. package/dist/core/infer.js +32 -9
  120. package/dist/core/laws.d.ts +2 -1
  121. package/dist/core/laws.js +47 -14
  122. package/dist/core/lemma-cuts.d.ts +38 -0
  123. package/dist/core/lemma-cuts.js +365 -0
  124. package/dist/core/machine.d.ts +39 -2
  125. package/dist/core/machine.js +240 -35
  126. package/dist/core/mutate.d.ts +55 -0
  127. package/dist/core/mutate.js +210 -0
  128. package/dist/core/native-domain.d.ts +6 -0
  129. package/dist/core/native-domain.js +114 -0
  130. package/dist/core/native-law.d.ts +3 -0
  131. package/dist/core/native-law.js +174 -0
  132. package/dist/core/quorum-laws.d.ts +5 -0
  133. package/dist/core/quorum-laws.js +239 -0
  134. package/dist/core/relational.js +10 -2
  135. package/dist/core/relevance.d.ts +4 -0
  136. package/dist/core/relevance.js +79 -0
  137. package/dist/core/runtime-wall.d.ts +3 -0
  138. package/dist/core/runtime-wall.js +4 -0
  139. package/dist/core/sample-step.d.ts +16 -0
  140. package/dist/core/sample-step.js +28 -0
  141. package/dist/core/source-check.d.ts +44 -0
  142. package/dist/core/source-check.js +126 -0
  143. package/dist/core/source-diagnostic.d.ts +1 -0
  144. package/dist/core/source-diagnostic.js +34 -0
  145. package/dist/core/support-budget.d.ts +2 -0
  146. package/dist/core/support-budget.js +6 -0
  147. package/dist/core/system.js +2 -0
  148. package/dist/core/wall.d.ts +6 -0
  149. package/dist/core/wall.js +23 -0
  150. package/dist/core/watch.js +4 -0
  151. package/dist/kernel/cdcl.d.ts +4 -0
  152. package/dist/kernel/cdcl.js +20 -5
  153. package/dist/kernel/kernel.d.ts +10 -0
  154. package/dist/kernel/kernel.js +56 -3
  155. package/dist/kernel/model-sequence.d.ts +2 -2
  156. package/dist/kernel/model-sequence.js +4 -3
  157. package/dist/kernel/model-values.d.ts +2 -0
  158. package/dist/kernel/model-values.js +60 -0
  159. package/dist/kernel/prove.d.ts +10 -0
  160. package/dist/kernel/prove.js +56 -8
  161. package/dist/kernel/prover-rows.d.ts +29 -0
  162. package/dist/kernel/prover-rows.js +114 -0
  163. package/dist/lean-kernel/emit.d.ts +39 -2
  164. package/dist/lean-kernel/emit.js +136 -24
  165. package/dist/lean-kernel/lean-terms.d.ts +1 -0
  166. package/dist/lean-kernel/lean-terms.js +13 -5
  167. package/dist/lean-kernel/library.js +4 -0
  168. package/dist/lean-kernel/qalpha.d.ts +7 -0
  169. package/dist/lean-kernel/qalpha.js +40 -0
  170. package/package.json +5 -1
@@ -21,6 +21,7 @@ import { substC, substE } from "../kernel/kernel.js";
21
21
  import { Cond, Term, nat, oneOf, rule } from "./dsl.js";
22
22
  import { interpret } from "./machine.js";
23
23
  import { allowed, watch } from "./watch.js";
24
+ import { inheritSource } from "./source-check.js";
24
25
  const models = new WeakMap();
25
26
  const modelled = (m, ...ms) => { models.set(m, [...(models.get(m) ?? []), ...ms]); return m; };
26
27
  // m made from `from`: the models it assumes, and the scalars it keeps shared (`sharedOf`), carried over.
@@ -544,6 +545,7 @@ export function inEnv(r, env, o = {}) {
544
545
  parts[`expiry${stores.length > 1 ? i : ''}`] = e;
545
546
  });
546
547
  const sys = system(`${machineOf(r).name} (${envText(env) || 'atomic'})`, parts, { act });
548
+ inheritSource(r, sys);
547
549
  const ms = [...modelsOf(sys), ...(env.retries ? [RETRIES] : [])];
548
550
  models.set(sys, ms);
549
551
  const locals = Object.keys(m.state).filter(s => own.includes(s)), on = same(x(act), n(0));
@@ -0,0 +1,6 @@
1
+ export declare const searchWall: (ms: number) => number;
2
+ export declare class WallExpired extends Error {
3
+ readonly phase: string;
4
+ constructor(phase: string);
5
+ }
6
+ export declare function checkWall(phase: string): void;
@@ -0,0 +1,23 @@
1
+ // Cooperative cancellation of untrusted search only. Never debits counted work,
2
+ // changes a proof rule, or turns an interrupted filter into a successful one.
3
+ import { pastWall } from "../kernel/prove.js";
4
+ import { runtimeWall } from "./runtime-wall.js";
5
+ // Leave bounded completion headroom for an in-flight synchronous operation,
6
+ // result checking and output. This shortens only wall time, never counted fuel.
7
+ // The same rule applies to every protocol and budget.
8
+ export const searchWall = (ms) => performance.now() + ms - Math.min(1000, Math.max(0, ms) / 20);
9
+ export class WallExpired extends Error {
10
+ phase;
11
+ constructor(phase) {
12
+ super(`time (${phase})`);
13
+ this.phase = phase;
14
+ this.name = 'WallExpired';
15
+ }
16
+ }
17
+ export function checkWall(phase) {
18
+ if (pastWall())
19
+ throw new WallExpired(phase);
20
+ }
21
+ // The interpreter must not import the proof engine to check its active wall:
22
+ // that would initialize cyclic proof constants before the machine constructors.
23
+ runtimeWall.check = checkWall;
@@ -9,6 +9,7 @@
9
9
  // request as input@j, and the state and maps after the last step (primed names).
10
10
  import { carriedView, evalC, evalE, numbersOf, walk } from "./machine.js";
11
11
  import { someHolds } from "./exists.js";
12
+ import { checkWall } from "./wall.js";
12
13
  export const isStepLaw = (w) => 'then' in w;
13
14
  // A request's environment: the params, its inputs and queries, and the step's flags decided (as ?name).
14
15
  export function requestEnv(m, run, params, st, input) {
@@ -129,7 +130,10 @@ export function watch(m, run, w, params, bound) {
129
130
  mapRead.add(x); });
130
131
  const turn = names.some(x => !mapRead.has(x)) ? turns(isStepLaw(w) ? w.then : w.holds, names) : undefined;
131
132
  const atKeys = (keys, env, f, st, mm) => {
133
+ let visited = 0;
132
134
  const go = (i) => {
135
+ if ((visited++ & 255) === 0)
136
+ checkWall('preflight law bindings');
133
137
  if (i === names.length) {
134
138
  watchWork.n++;
135
139
  return f(env);
@@ -24,6 +24,10 @@ export declare const cdclStats: {
24
24
  proven: number;
25
25
  conflicts: number;
26
26
  decisions: number;
27
+ setupMs: number;
28
+ propagationMs: number;
29
+ firstDecisionMs: number;
30
+ firstDecisions: number;
27
31
  solveMs: number;
28
32
  rowsMs: number;
29
33
  coreMs: number;
@@ -55,7 +55,7 @@ const keyOf = (lin) => {
55
55
  const pointLeaf = env.GDP_CDCL_POINT !== '0';
56
56
  const lpFill = Number(env.GDP_CDCL_FILL ?? 8), lpGrow = Number(env.GDP_CDCL_GROW ?? 4), lpBase = Number(env.GDP_CDCL_BASE ?? 500), lpGreedy = Number(env.GDP_CDCL_GREEDY ?? 200), useLp = env.GDP_CDCL_LP !== '0', verify = env.GDP_CDCL_VERIFY === '1';
57
57
  // Counters research/step reads (times only while `on`).
58
- export const cdclStats = { on: false, runs: 0, proven: 0, conflicts: 0, decisions: 0, solveMs: 0, rowsMs: 0, coreMs: 0, unfoldMs: 0, leaves: 0, resolved: 0, coreSize: 0, pathSize: 0, lpMisses: 0, resolved2: 0, unfoldWhy: '', orderMs: 0, boundMs: 0, openMisses: 0, lpMs: 0, lpUnknown: 0, fmCalls: 0, pivots: 0, lpRebuilds: 0, lpRows: 0, lpNnz: 0, lpVars: 0, lpLoad: 0, nodes: 0, boundRounds: 0, fmLeafMs: 0, fmOpenMs: 0, fastMs: 0, missMs: 0 };
58
+ export const cdclStats = { on: false, runs: 0, proven: 0, conflicts: 0, decisions: 0, setupMs: 0, propagationMs: 0, firstDecisionMs: 0, firstDecisions: 0, solveMs: 0, rowsMs: 0, coreMs: 0, unfoldMs: 0, leaves: 0, resolved: 0, coreSize: 0, pathSize: 0, lpMisses: 0, resolved2: 0, unfoldWhy: '', orderMs: 0, boundMs: 0, openMisses: 0, lpMs: 0, lpUnknown: 0, fmCalls: 0, pivots: 0, lpRebuilds: 0, lpRows: 0, lpNnz: 0, lpVars: 0, lpLoad: 0, nodes: 0, boundRounds: 0, fmLeafMs: 0, fmOpenMs: 0, fastMs: 0, missMs: 0 };
59
59
  // `opts.model`: only whether the goal has a model is wanted (core/bmc.ts): a refutation isn't unfolded into a tree, its
60
60
  // outcome `unknown` with `why` REFUTED; each decision's phase is the simplex's point's (phaseAtPoint; in the tree search too
61
61
  // where prove.ts's `atPoint` is on); past `opts.wall` (wall time) the search stops as past its budget.
@@ -93,7 +93,16 @@ export function cdclSession(goal, root, opts = {}) {
93
93
  // brings it down to its own; each assumption's index by name)
94
94
  // (and on each assumption's variable, `aq`, its index this run: the undo's lookup by variable, not by name)
95
95
  let aq = 0, aqOf = new Map(), aqVars = [];
96
- const st = cdclStats, timing = st.on;
96
+ const st = cdclStats, timing = st.on, setupStarted = timing ? performance.now() : 0;
97
+ let runStarted = 0, sawDecision = false;
98
+ const noteDecision = () => {
99
+ st.decisions++;
100
+ if (timing && !sawDecision) {
101
+ sawDecision = true;
102
+ st.firstDecisions++;
103
+ st.firstDecisionMs += performance.now() - runStarted;
104
+ }
105
+ };
97
106
  const t = (f, add) => { if (!timing)
98
107
  return f(); const t0 = performance.now(); try {
99
108
  return f();
@@ -797,7 +806,7 @@ export function cdclSession(goal, root, opts = {}) {
797
806
  if (!x.quiet && sx)
798
807
  phaseAtPoint(x, sx);
799
808
  levels.push(trail.length);
800
- st.decisions++;
809
+ noteDecision();
801
810
  assignVar(x, x.phase);
802
811
  return true;
803
812
  };
@@ -869,6 +878,10 @@ export function cdclSession(goal, root, opts = {}) {
869
878
  until = b.until ?? Infinity;
870
879
  wall = w;
871
880
  last = goal.hyps.length - 1;
881
+ if (timing) {
882
+ runStarted = performance.now();
883
+ sawDecision = false;
884
+ }
872
885
  restartAt = 32;
873
886
  nRestart = 0;
874
887
  sinceRestart = 0;
@@ -961,7 +974,7 @@ export function cdclSession(goal, root, opts = {}) {
961
974
  if (++budget.nodes > 200_000 || late(until) || (wall !== undefined && performance.now() > wall))
962
975
  return stuck('unknown', budget.nodes > 200_000 ? 'nodes' : 'time');
963
976
  let conflict;
964
- const ci = propagate();
977
+ const ci = t(propagate, ms => { st.propagationMs += ms; });
965
978
  let open = -1, wrong = -1;
966
979
  if (ci === undefined)
967
980
  for (; aq < assumed.length; aq++) {
@@ -1287,7 +1300,7 @@ export function cdclSession(goal, root, opts = {}) {
1287
1300
  if (!pick)
1288
1301
  return verdict?.kind === 'sat' ? stuck('sat', 'a model', { witness: verdict.witness }) : stuck('unknown', 'no split');
1289
1302
  levels.push(trail.length);
1290
- st.decisions++;
1303
+ noteDecision();
1291
1304
  assign(pick, vars.get(pick).phase);
1292
1305
  if (clausal && lpSat)
1293
1306
  free = batch;
@@ -1378,6 +1391,8 @@ export function cdclSession(goal, root, opts = {}) {
1378
1391
  // extends to (a gate its formula's value).
1379
1392
  const retire = (hyp) => { for (const ci of byHyp[hyp] ?? [])
1380
1393
  retired[ci] = true; };
1394
+ if (timing)
1395
+ st.setupMs += performance.now() - setupStarted;
1381
1396
  return { run, retire };
1382
1397
  }
1383
1398
  // The DAG as a kernel tree below `root`, walked depth first with a reader of its own (the tree's path is a stack, as
@@ -64,6 +64,14 @@ export declare function cellParts(cell: string): {
64
64
  };
65
65
  export declare function withProducts(rows: Constraint[], pairs: [number, number][], squares?: Lin[]): Constraint[];
66
66
  export declare function check(goal: Goal, tree: Tree, path?: Path): boolean;
67
+ export type LemmaCut = {
68
+ when: Lin[];
69
+ cut: Lin;
70
+ tree: Tree;
71
+ slice?: number[];
72
+ };
73
+ export declare function lemmaPath(lemmas: LemmaCut[], path: Path): Path;
74
+ export declare function checkGoalLemmas(goal: Goal, tree: Tree, lemmas?: LemmaCut[]): boolean;
67
75
  export type Subst = {
68
76
  vars: Record<string, E>;
69
77
  maps: Record<string, (key: E) => E>;
@@ -337,6 +345,7 @@ export declare function countedOk(hyps: C[], cs: Count[], is: CountInst[]): bool
337
345
  export declare function checkCounted(g: CountedGoal, cert: {
338
346
  insts: CountInst[];
339
347
  tree: Tree;
348
+ lemmas?: LemmaCut[];
340
349
  }): boolean;
341
350
  export declare function countedGoal(g: CountedGoal, insts: CountInst[]): Goal | undefined;
342
351
  export type CountDecl = {
@@ -354,6 +363,7 @@ export type CountCert = {
354
363
  insts: CountInst[];
355
364
  tree: Tree;
356
365
  picks?: [string, E[]][];
366
+ lemmas?: LemmaCut[];
357
367
  };
358
368
  export declare const postName: (map: string) => string;
359
369
  export declare const stateCounts: (m: Machine) => string[];
@@ -664,6 +664,59 @@ export function check(goal, tree, path = new Map()) {
664
664
  const yes = new Map(path).set(id, { lin: tree.split, holds: true }), no = new Map(path).set(id, { lin: tree.split, holds: false });
665
665
  return check(goal, tree.yes, yes) && check(goal, tree.no, no);
666
666
  }
667
+ const lemmaLin = (lin) => !!lin && typeof lin === 'object' && !Array.isArray(lin)
668
+ && (Object.getPrototypeOf(lin) === Object.prototype || Object.getPrototypeOf(lin) === null)
669
+ && Object.values(lin).every(Number.isSafeInteger);
670
+ // Lean's path is a list, so repeated atoms remain input rows, with the first deciding lookup. Keep that exact
671
+ // behavior in a Map: noncanonical duplicate keys contain no colon and cannot collide with a nonempty canon(lin).
672
+ function prependAtoms(front, path) {
673
+ const out = new Map();
674
+ let duplicate = 0;
675
+ for (const atom of [...front, ...path.values()]) {
676
+ const id = canon(atom.lin);
677
+ out.set(out.has(id) ? `@${duplicate++}` : id, atom);
678
+ }
679
+ return out;
680
+ }
681
+ // Eligibility uses only the original split path, never another cut. The returned path is for a leaf alone.
682
+ export function lemmaPath(lemmas, path) {
683
+ // Lean's dec treats all-zero variable coefficients as constant. Normalize only this
684
+ // new-condition decision boundary: preserve the original proof rows and every legacy path.
685
+ lemmas = lemmas.map(l => ({ ...l, when: l.when.map(w => Object.keys(w).every(key => key === '1' || w[key] === 0) ? k(w['1'] ?? 0) : w) }));
686
+ const active = lemmas.filter(l => l.when.every(w => decide(w, path) === true));
687
+ return active.length ? prependAtoms(active.map(l => ({ lin: l.cut, holds: true })), path) : path;
688
+ }
689
+ export function checkGoalLemmas(goal, tree, lemmas = []) {
690
+ if (!Array.isArray(lemmas))
691
+ return false;
692
+ if (!lemmas.length)
693
+ return check(goal, tree); // Exact legacy path, including all old refusal checks.
694
+ try {
695
+ if (!Array.from(lemmas).every(l => !!l && typeof l === 'object' && Array.isArray(l.when)
696
+ && Array.from(l.when).every(lemmaLin) && lemmaLin(l.cut) && !!l.tree && typeof l.tree === 'object'
697
+ && (l.slice === undefined || Array.isArray(l.slice) && Array.from(l.slice).every(i => Number.isSafeInteger(i) && i >= 0 && i < goal.hyps.length))))
698
+ return false;
699
+ for (const l of lemmas) {
700
+ const hyps = l.slice === undefined ? goal.hyps : l.slice.map(i => goal.hyps[i]);
701
+ const path = prependAtoms([{ lin: l.cut, holds: false }, ...l.when.map(lin => ({ lin, holds: true }))], new Map());
702
+ if (!check({ ...goal, hyps }, l.tree, path))
703
+ return false;
704
+ }
705
+ const visit = (t, path) => {
706
+ if ('leaf' in t)
707
+ return check(goal, t, lemmaPath(lemmas, path));
708
+ const id = canon(t.split);
709
+ if (path.has(id) || Object.keys(t.split).every(key => key === '1'))
710
+ return false;
711
+ return visit(t.yes, new Map(path).set(id, { lin: t.split, holds: true }))
712
+ && visit(t.no, new Map(path).set(id, { lin: t.split, holds: false }));
713
+ };
714
+ return visit(tree, new Map());
715
+ }
716
+ catch {
717
+ return false;
718
+ } // Malformed new payloads, including non-tree lemma references, are refusals.
719
+ }
667
720
  // --- machines ----------------------------------------------------------------------------------------------------------
668
721
  // Every constant and factor is a natural, so every value a machine computes is one (∸ truncates).
669
722
  function natural(e) {
@@ -2274,7 +2327,7 @@ export function checkCounted(g, cert) {
2274
2327
  if (!(countedOk(g.hyps, g.counts, cert.insts) && typed(cert.insts)))
2275
2328
  return false;
2276
2329
  const goal = countedGoal(g, cert.insts);
2277
- return goal !== undefined && check(goal, cert.tree);
2330
+ return goal !== undefined && checkGoalLemmas(goal, cert.tree, cert.lemmas);
2278
2331
  }
2279
2332
  // The goal a certificate's tree refutes: the goal's hypotheses, then the instances' (also what the search and the
2280
2333
  // exporter read), or none.
@@ -2407,7 +2460,7 @@ function checkCountedW(hyps, cs, cert) {
2407
2460
  if (!(countedOkW(cs, cert.insts) && typed(cert.insts)))
2408
2461
  return false;
2409
2462
  const hs = countHyps(cs, cert.insts);
2410
- return hs !== undefined && check({ name: 'counted', hyps: [...hyps, ...hs] }, cert.tree);
2463
+ return hs !== undefined && checkGoalLemmas({ name: 'counted', hyps: [...hyps, ...hs] }, cert.tree, cert.lemmas);
2411
2464
  }
2412
2465
  // checkMC: each declaration's j and lo differ from its key, the reads are fresh, no read is a witness or reads one in
2413
2466
  // its key term, and checkCountedW accepts the counted goal they make (the goal's hypotheses, each read variable equal to
@@ -2418,7 +2471,7 @@ export function checkMC(hyps, ds, k) {
2418
2471
  if (!k.reads.every(r => k.insts.every(i => i.wit !== r[0] && !readsVar(r[2], i.wit))))
2419
2472
  return false;
2420
2473
  const cs = toCounts(ds, k.reads);
2421
- return cs !== undefined && checkCountedW([...hyps, ...k.reads.map(r => readHyp(ds, r)), ...pickHyps(ds, k.reads, k.picks ?? [])], cs, { insts: k.insts, tree: k.tree });
2474
+ return cs !== undefined && checkCountedW([...hyps, ...k.reads.map(r => readHyp(ds, r)), ...pickHyps(ds, k.reads, k.picks ?? [])], cs, { insts: k.insts, tree: k.tree, lemmas: k.lemmas });
2422
2475
  }
2423
2476
  // The goal a certificate's tree refutes (what the search and the exporter read), or none.
2424
2477
  export function mcGoal(hyps, ds, k) {
@@ -1,3 +1,3 @@
1
- import type { Goal } from './kernel.js';
1
+ import type { Goal, Path } from './kernel.js';
2
2
  import { type Refuted } from './cdcl.js';
3
- export declare function modelSequence(): (goal: Goal, end: number) => Refuted;
3
+ export declare function modelSequence(path?: Path): (goal: Goal, end: number) => Refuted;
@@ -1,19 +1,20 @@
1
1
  import { cdclSession, growCdcl } from "./cdcl.js";
2
2
  import { wideFor } from "./prove.js";
3
- export function modelSequence() {
3
+ export function modelSequence(path = new Map()) {
4
+ const fixedPath = new Map(path);
4
5
  let session, held, texts = [];
5
6
  return (goal, end) => {
6
7
  const budget = { nodes: 0, until: end };
7
8
  if (wideFor(goal)) {
8
9
  session = undefined;
9
10
  held = undefined;
10
- return growCdcl(goal, new Map(), budget, { model: true, core: true, point: true });
11
+ return growCdcl(goal, fixedPath, budget, { model: true, core: true, point: true });
11
12
  }
12
13
  const current = goal.hyps.map(h => JSON.stringify(h)), at = new Map(current.map((h, i) => [h, i]));
13
14
  if (!held || !session || texts.some(h => !at.has(h))) {
14
15
  held = { name: goal.name, hyps: [...goal.hyps] };
15
16
  texts = [...current];
16
- session = cdclSession(held, new Map(), { model: true, core: true, point: true });
17
+ session = cdclSession(held, fixedPath, { model: true, core: true, point: true });
17
18
  }
18
19
  else {
19
20
  const old = new Set(texts);
@@ -0,0 +1,2 @@
1
+ import { type C, type E } from '../core/machine.js';
2
+ export declare function modelValueTerms(body: C, name: string, free: ReadonlySet<string>, value: (e: E) => number | undefined): E[];
@@ -0,0 +1,60 @@
1
+ // Untrusted MBQI proposals for naturals that are values, not map keys.
2
+ // A model supplies the other terms in a linear comparison. Its boundary and
3
+ // neighbours are candidate constants; only the instantiated law is assumed,
4
+ // and the ordinary kernel must still check the resulting proof.
5
+ import { walkOnce } from "../core/machine.js";
6
+ export function modelValueTerms(body, name, free, value) {
7
+ // Function arguments are keys too. Preserve their existing symbolic domain:
8
+ // replacing f(k)'s key by an equal-valued constant can lose later instances.
9
+ // Only a natural never used as a read key gets arithmetic boundary proposals.
10
+ let keyed = false;
11
+ walkOnce(body, o => {
12
+ const e = o;
13
+ if (e.op !== 'get')
14
+ return;
15
+ walkOnce(e.key, k => { const part = k; if (part.op === 'var' && part.name === name)
16
+ keyed = true; });
17
+ });
18
+ if (keyed)
19
+ return [];
20
+ const linear = (e) => {
21
+ if (e.op === 'var' && e.name === name)
22
+ return { coefficient: 1, constant: 0 };
23
+ if (e.op === 'add') {
24
+ const a = linear(e.a), b = linear(e.b);
25
+ return a && b ? { coefficient: a.coefficient + b.coefficient, constant: a.constant + b.constant } : undefined;
26
+ }
27
+ if (e.op === 'mul') {
28
+ const a = linear(e.a);
29
+ return a ? { coefficient: e.k * a.coefficient, constant: e.k * a.constant } : undefined;
30
+ }
31
+ const text = JSON.stringify(e);
32
+ if ([...free].some(n => text.includes(`"name":${JSON.stringify(n)}`)))
33
+ return undefined;
34
+ const constant = value(e);
35
+ return constant === undefined || !Number.isSafeInteger(constant) ? undefined : { coefficient: 0, constant };
36
+ };
37
+ const terms = new Set();
38
+ const visit = (c) => {
39
+ if (c.op === 'not')
40
+ return visit(c.x);
41
+ if (c.op === 'and' || c.op === 'or') {
42
+ c.xs.forEach(visit);
43
+ return;
44
+ }
45
+ if (c.op !== '=' && c.op !== '<=' && c.op !== '<')
46
+ return;
47
+ const a = linear(c.a), b = linear(c.b);
48
+ if (!a || !b)
49
+ return;
50
+ const coefficient = a.coefficient - b.coefficient, constant = b.constant - a.constant;
51
+ if (!coefficient || !Number.isSafeInteger(coefficient) || !Number.isSafeInteger(constant))
52
+ return;
53
+ const boundary = Math.floor(constant / coefficient);
54
+ for (const v of [boundary, boundary + 1, boundary - 1])
55
+ if (Number.isSafeInteger(v) && v >= 0)
56
+ terms.add(v);
57
+ };
58
+ visit(body);
59
+ return [...terms].slice(0, 16).map(value => ({ op: 'const', value }));
60
+ }
@@ -66,6 +66,10 @@ export declare function grow(goal: Goal, path?: Path, budget?: {
66
66
  until?: number;
67
67
  units?: boolean;
68
68
  }): Outcome;
69
+ export declare const treeReuseStats: {
70
+ hits: number;
71
+ kept: number;
72
+ };
69
73
  export declare function withTrees<T>(f: () => T): T;
70
74
  export declare const queryHook: {
71
75
  on?: (q: {
@@ -128,6 +132,12 @@ export declare function withModels<T>(m: Machine, laws: Law[], inst: Instances,
128
132
  inst: Instances;
129
133
  };
130
134
  export declare const relatedMost = 512, relatedBudget = 8192;
135
+ export declare function instancesFor(m: Machine, laws: Law[], build: (inst: Instances) => Goal[], opts?: {
136
+ seed?: E[];
137
+ focus?: string[];
138
+ start?: Instances;
139
+ reads?: boolean;
140
+ }): Instances;
131
141
  export declare function triggered(m: Machine, laws: Law[], inst: Instances, build: (inst: Instances) => Goal[], focus?: string[]): Instances;
132
142
  export declare const minimal: {
133
143
  on: boolean;
@@ -16,6 +16,8 @@ import { proveSome, someLaws } from "../core/exists.js";
16
16
  import { REFUTED, growCdcl } from "./cdcl.js";
17
17
  import { decide, eprMeter, pastEprCap, patternsOf, withEprCap } from "./epr.js";
18
18
  import { projected, tupleParts } from "./kernel.js";
19
+ import { modelValueTerms } from "./model-values.js";
20
+ import { proverRows } from "./prover-rows.js";
19
21
  import { assumed, atomOf, boundOf, canon, canonFlip, cellParts, columnTerm, decided, factorsOf, isCell, isMonomial, stepZone, check, checkLaws, checkStepLaws, historyMachine, plainOf, substC, substE, leafConstraints, leafConstraintsReusing, reusing, linear, livenessHelpful, livenessParts, strongly, loopMachine, obligations, plainKey, progressObligations, stepLawObligations, trueC, truth, unreachable, witnessesOf, withProducts } from "./kernel.js";
20
22
  // The atoms the path leaves open, in evaluation order: deciding any of them makes progress.
21
23
  function openE(e, path, out) {
@@ -407,8 +409,10 @@ export function grow(goal, path = new Map(), budget) {
407
409
  }
408
410
  // (a root goal grown before within `withTrees`: its tree again; a tree is the kernel's to check wherever it goes)
409
411
  const key = treeCache.on && !path.size && !budget.nodes ? treeKey(goal) : undefined, had = key === undefined ? undefined : treeCache.trees.get(key);
410
- if (had)
412
+ if (had) {
413
+ treeReuseStats.hits++;
411
414
  return { tree: had, nodes: 0 };
415
+ }
412
416
  if (key !== undefined) {
413
417
  const out = growKept(goal, path, budget);
414
418
  if ('tree' in out)
@@ -420,7 +424,8 @@ export function grow(goal, path = new Map(), budget) {
420
424
  // Trees of root goals kept by their hypotheses (and the search's modes) while `withTrees` runs: core/infer.ts proves each
421
425
  // law of a set alone (proveLaw) and then the set as a whole (proveRule), the same goals twice. At most 2,000 trees, and
422
426
  // goals of at most 4 MB written out.
423
- const treeCache = { on: 0, trees: new Map(), keep(key, tree) { if (this.trees.size >= 2000)
427
+ export const treeReuseStats = { hits: 0, kept: 0 };
428
+ const treeCache = { on: 0, trees: new Map(), keep(key, tree) { treeReuseStats.kept++; if (this.trees.size >= 2000)
424
429
  this.trees.clear(); this.trees.set(key, tree); } };
425
430
  const treeKey = (goal) => { const text = JSON.stringify(goal.hyps); return text.length > 4_000_000 ? undefined : `${cellProducts.on ? 1 : 0}${unitsNow ? 1 : 0}${text}`; };
426
431
  // GDP_TREES=0: no tree kept (each goal grown every time it is asked).
@@ -1060,7 +1065,7 @@ export function rowsAt(goal, path) {
1060
1065
  if (!rows) {
1061
1066
  if (byPath.size >= 4096)
1062
1067
  byPath.clear();
1063
- byPath.set(id, (rows = leafConstraintsReusing(goal, path)));
1068
+ byPath.set(id, (rows = env.GDP_ROWS_SHARED === '0' ? leafConstraintsReusing(goal, path) : proverRows(goal, path)));
1064
1069
  }
1065
1070
  return rows;
1066
1071
  }
@@ -1104,6 +1109,7 @@ function lift(goal, tree, from, to) {
1104
1109
  };
1105
1110
  return go(tree, from, to);
1106
1111
  }
1112
+ import { rememberProofRows } from "../core/lemma-cuts.js";
1107
1113
  // A tree for a weaker goal (some hypotheses left out, some conjuncts of one left out) made a tree for the whole: at any
1108
1114
  // path a leaf's rows are among the whole goal's (each hypothesis' facts are a hypothesis' own, the cells, terms and
1109
1115
  // naturals they read a subset), so each input is renumbered to the same row there, a square or product past the rows
@@ -1152,6 +1158,7 @@ export function widen(part, whole, tree, opaque = {}, pp = new Map(), wp = pp) {
1152
1158
  if (pastWall())
1153
1159
  return undefined;
1154
1160
  const rw = rowsAt(whole, wp), at = new Map();
1161
+ const remember = (out) => { rememberProofRows(out, whole, wp, rw); return out; };
1155
1162
  rw.forEach((r, i) => { const key = canon(r.lin); if (!at.has(key))
1156
1163
  at.set(key, i); });
1157
1164
  const map = (i) => { if (i >= rp.length)
@@ -1182,10 +1189,10 @@ export function widen(part, whole, tree, opaque = {}, pp = new Map(), wp = pp) {
1182
1189
  if (ok && names.length && !checkRefutation(withProducts(rw, products, squares), leaf))
1183
1190
  ok = false;
1184
1191
  if (ok)
1185
- return { leaf, ...(tree.products ? { products } : {}), ...(tree.squares ? { squares: squares } : {}) };
1192
+ return remember({ leaf, ...(tree.products ? { products } : {}), ...(tree.squares ? { squares: squares } : {}) });
1186
1193
  const absurd = rw.findIndex(r => Object.keys(r.lin).every(key => key === '1') && (r.lin['1'] ?? 0) > 0);
1187
1194
  if (absurd >= 0)
1188
- return { leaf: [{ kind: 'input', index: absurd }] };
1195
+ return remember({ leaf: [{ kind: 'input', index: absurd }] });
1189
1196
  const out = grow(whole, wp);
1190
1197
  return 'tree' in out ? out.tree : undefined;
1191
1198
  }
@@ -1649,8 +1656,19 @@ export function modelInstances(m, laws, inst, goal, w, most = 64, sorted = false
1649
1656
  return;
1650
1657
  const until = evals + Math.max(256, Math.floor((20_000 - evals) / Math.max(1, left--)));
1651
1658
  const have = new Set(), had = out[id] ?? [], n = names.length, sorts = sortsOf(body, names, atoms);
1659
+ const keyNames = new Set();
1660
+ eachRead(e => {
1661
+ if (fns.includes(e.map))
1662
+ return;
1663
+ const text = JSON.stringify(e.key);
1664
+ for (const name of names)
1665
+ if (text.includes(`"name":${JSON.stringify(name)}`))
1666
+ keyNames.add(name);
1667
+ }).inC(body);
1668
+ // Arithmetic-only naturals range over comparison boundaries, not map keys.
1669
+ // The model chooses constants; assumed/check still validate ordinary law instances.
1652
1670
  // (a law at one key assumed at a term of every value its sort takes already: nothing to add)
1653
- if (n === 1) {
1671
+ if (n === 1 && keyNames.has(names[0])) {
1654
1672
  const covered = new Set(had.map(valueOf));
1655
1673
  if ([...sorts[0].keys()].every(v2 => covered.has(v2)))
1656
1674
  return;
@@ -1691,7 +1709,37 @@ export function modelInstances(m, laws, inst, goal, w, most = 64, sorted = false
1691
1709
  added++;
1692
1710
  return;
1693
1711
  }
1694
- for (const [v2, e] of sorts[i])
1712
+ const domain = [...sorts[i]], seen = new Set(domain.map(([, e]) => JSON.stringify(e)));
1713
+ const add = (value, term) => {
1714
+ const key = JSON.stringify(term);
1715
+ if (!seen.has(key)) {
1716
+ seen.add(key);
1717
+ domain.push([value, term]);
1718
+ }
1719
+ };
1720
+ if (!keyNames.has(names[i])) {
1721
+ const free = new Set(names.slice(i));
1722
+ const extra = modelValueTerms(body, names[i], free, e => {
1723
+ try {
1724
+ return evalE(e, read(at), st, mm);
1725
+ }
1726
+ catch {
1727
+ return undefined;
1728
+ }
1729
+ });
1730
+ // Keep symbolic instances: their current value is not their identity.
1731
+ // Stable arithmetic witnesses must coexist with equal-valued row terms,
1732
+ // not replace them. Existing tuple/evaluation budgets still bound both.
1733
+ if (extra.length)
1734
+ for (const [v2] of sorts[i])
1735
+ add(v2, { op: 'const', value: v2 });
1736
+ for (const e of extra) {
1737
+ const v2 = valueOf(e);
1738
+ if (v2 !== undefined)
1739
+ add(v2, e);
1740
+ }
1741
+ }
1742
+ for (const [v2, e] of domain)
1695
1743
  go(i + 1, { ...at, [names[i]]: v2 }, [...terms, e]);
1696
1744
  };
1697
1745
  go(0, {}, []);
@@ -2038,7 +2086,7 @@ const arity = (m, laws, n) => {
2038
2086
  // built so far read a function at, and, where the seed doesn't cover them (no seed, positions that shift, a law about
2039
2087
  // several keys), the every-key laws and flags at every key they read a map at (a law about several keys at tuples
2040
2088
  // relating `focus`, the goals' own keys).
2041
- function instancesFor(m, laws, build, opts = {}) {
2089
+ export function instancesFor(m, laws, build, opts = {}) {
2042
2090
  const seed = opts.seed && [...new Map(opts.seed.map(e => [JSON.stringify(e), e])).values()];
2043
2091
  let inst = opts.start ?? (seed ? { ...Object.fromEntries(laws.filter(l => l.forall).map(l => [l.name, l.keys?.length ? [] : seed])), ...flagInstances(m, seed, opts.focus) } : {});
2044
2092
  const reads = opts.reads ?? (!opts.seed || shifts(m) || laws.some(l => l.keys?.length) || pairFlags(m));
@@ -0,0 +1,29 @@
1
+ import { type Constraint } from '../core/solver.js';
2
+ import { type Goal, type Path } from './kernel.js';
3
+ export declare const rowReuseStats: {
4
+ nodeHits: number;
5
+ nodeMisses: number;
6
+ goalHits: number;
7
+ rowsHits: number;
8
+ rowsBuilt: number;
9
+ rowsEvicted: number;
10
+ };
11
+ export declare class ProverRowsCache {
12
+ private maxRows;
13
+ private maxEntries;
14
+ private entries;
15
+ private kept;
16
+ constructor(maxRows: number, maxEntries?: number);
17
+ get size(): number;
18
+ get weight(): number;
19
+ get(key: string): Constraint[] | undefined;
20
+ set(key: string, value: Constraint[]): number;
21
+ }
22
+ export declare const rowReuseStorage: () => {
23
+ nodes: number;
24
+ keyChars: number;
25
+ goals: number;
26
+ rowEntries: number;
27
+ constraints: number;
28
+ };
29
+ export declare function proverRows(goal: Goal, path: Path): Constraint[];