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.
Files changed (295) hide show
  1. package/README.md +2 -2
  2. package/dist/core/bmc.js +10 -7
  3. package/dist/core/check.js +7 -2
  4. package/dist/core/count-attempt-work.d.ts +29 -0
  5. package/dist/core/count-attempt-work.js +96 -0
  6. package/dist/core/count-boolean-partition.d.ts +5 -0
  7. package/dist/core/count-boolean-partition.js +47 -0
  8. package/dist/core/count-bounded-quotient.d.ts +2 -0
  9. package/dist/core/count-bounded-quotient.js +13 -0
  10. package/dist/core/count-case-compose.d.ts +20 -0
  11. package/dist/core/count-case-compose.js +289 -0
  12. package/dist/core/count-cases.js +3 -2
  13. package/dist/core/count-cert-rename.d.ts +10 -0
  14. package/dist/core/count-cert-rename.js +69 -0
  15. package/dist/core/count-cert-transport.d.ts +10 -2
  16. package/dist/core/count-cert-transport.js +60 -9
  17. package/dist/core/count-certificate-minimize.d.ts +57 -0
  18. package/dist/core/count-certificate-minimize.js +263 -0
  19. package/dist/core/count-closed-family.d.ts +32 -0
  20. package/dist/core/count-closed-family.js +143 -0
  21. package/dist/core/count-closing-budget.d.ts +10 -0
  22. package/dist/core/count-closing-budget.js +49 -0
  23. package/dist/core/count-closing-needs.d.ts +5 -0
  24. package/dist/core/count-closing-needs.js +9 -0
  25. package/dist/core/count-component-budget.d.ts +5 -0
  26. package/dist/core/count-component-budget.js +9 -0
  27. package/dist/core/count-copy-shape.d.ts +11 -0
  28. package/dist/core/count-copy-shape.js +40 -0
  29. package/dist/core/count-disjoint-funding.d.ts +75 -0
  30. package/dist/core/count-disjoint-funding.js +284 -0
  31. package/dist/core/count-emitter-frame-pool.d.ts +23 -0
  32. package/dist/core/count-emitter-frame-pool.js +87 -0
  33. package/dist/core/count-final-step.d.ts +5 -0
  34. package/dist/core/count-final-step.js +20 -0
  35. package/dist/core/count-fixed-frame.d.ts +4 -0
  36. package/dist/core/count-fixed-frame.js +30 -0
  37. package/dist/core/count-frames.d.ts +25 -0
  38. package/dist/core/count-frames.js +118 -0
  39. package/dist/core/count-frozen-guard.d.ts +2 -0
  40. package/dist/core/count-frozen-guard.js +31 -0
  41. package/dist/core/count-generation-phase.d.ts +7 -0
  42. package/dist/core/count-generation-phase.js +33 -0
  43. package/dist/core/count-guard-composition.d.ts +12 -0
  44. package/dist/core/count-guard-composition.js +48 -0
  45. package/dist/core/count-guard-context.d.ts +11 -0
  46. package/dist/core/count-guard-context.js +50 -0
  47. package/dist/core/count-guard-facts.d.ts +50 -0
  48. package/dist/core/count-guard-facts.js +97 -0
  49. package/dist/core/count-guard-proposals.d.ts +7 -0
  50. package/dist/core/count-guard-proposals.js +106 -0
  51. package/dist/core/count-guard-shape.d.ts +18 -0
  52. package/dist/core/count-guard-shape.js +100 -0
  53. package/dist/core/count-guard-tree.d.ts +17 -0
  54. package/dist/core/count-guard-tree.js +125 -0
  55. package/dist/core/count-leader-facts.d.ts +10 -0
  56. package/dist/core/count-leader-facts.js +52 -0
  57. package/dist/core/count-leader.d.ts +10 -0
  58. package/dist/core/count-leader.js +331 -0
  59. package/dist/core/count-lemma-transport.d.ts +8 -0
  60. package/dist/core/count-lemma-transport.js +47 -0
  61. package/dist/core/count-lifted-budget.d.ts +54 -0
  62. package/dist/core/count-lifted-budget.js +97 -0
  63. package/dist/core/count-lifted-copy.d.ts +3 -0
  64. package/dist/core/count-lifted-copy.js +166 -0
  65. package/dist/core/count-lifted-increment.d.ts +3 -0
  66. package/dist/core/count-lifted-increment.js +146 -0
  67. package/dist/core/count-lifted-load.d.ts +5 -0
  68. package/dist/core/count-lifted-load.js +179 -0
  69. package/dist/core/count-lifted-prerequisite.d.ts +14 -0
  70. package/dist/core/count-lifted-prerequisite.js +53 -0
  71. package/dist/core/count-lifted-replacement.d.ts +3 -0
  72. package/dist/core/count-lifted-replacement.js +540 -0
  73. package/dist/core/count-lifted-shape.d.ts +63 -0
  74. package/dist/core/count-lifted-shape.js +115 -0
  75. package/dist/core/count-lifted-strategy.d.ts +7 -0
  76. package/dist/core/count-lifted-strategy.js +226 -0
  77. package/dist/core/count-lifted-transports.d.ts +32 -0
  78. package/dist/core/count-lifted-transports.js +293 -0
  79. package/dist/core/count-load-shape.d.ts +17 -0
  80. package/dist/core/count-load-shape.js +67 -0
  81. package/dist/core/count-minimal-view.d.ts +26 -0
  82. package/dist/core/count-minimal-view.js +46 -0
  83. package/dist/core/count-operation-observation.d.ts +9 -0
  84. package/dist/core/count-operation-observation.js +22 -0
  85. package/dist/core/count-operation-order.d.ts +5 -0
  86. package/dist/core/count-operation-order.js +4 -0
  87. package/dist/core/count-phase.d.ts +9 -0
  88. package/dist/core/count-phase.js +127 -0
  89. package/dist/core/count-premise-search.d.ts +9 -0
  90. package/dist/core/count-premise-search.js +41 -0
  91. package/dist/core/count-premise-view.d.ts +19 -0
  92. package/dist/core/count-premise-view.js +220 -0
  93. package/dist/core/count-prerequisite-components.d.ts +67 -0
  94. package/dist/core/count-prerequisite-components.js +239 -0
  95. package/dist/core/count-prerequisite-memory.d.ts +24 -0
  96. package/dist/core/count-prerequisite-memory.js +37 -0
  97. package/dist/core/count-prerequisite-plan.d.ts +12 -0
  98. package/dist/core/count-prerequisite-plan.js +88 -0
  99. package/dist/core/count-primitive-budget.d.ts +1 -0
  100. package/dist/core/count-primitive-budget.js +8 -0
  101. package/dist/core/count-project-free.d.ts +3 -0
  102. package/dist/core/count-project-free.js +24 -0
  103. package/dist/core/count-project-witness.d.ts +4 -0
  104. package/dist/core/count-project-witness.js +48 -0
  105. package/dist/core/count-proof-rescope.d.ts +14 -0
  106. package/dist/core/count-proof-rescope.js +71 -0
  107. package/dist/core/count-proof-scope.d.ts +68 -0
  108. package/dist/core/count-proof-scope.js +333 -0
  109. package/dist/core/count-prune-owned-root.d.ts +5 -0
  110. package/dist/core/count-prune-owned-root.js +27 -0
  111. package/dist/core/count-query-context.d.ts +3 -0
  112. package/dist/core/count-query-context.js +7 -0
  113. package/dist/core/count-query.d.ts +15 -0
  114. package/dist/core/count-query.js +59 -0
  115. package/dist/core/count-quorum-leaf.d.ts +9 -0
  116. package/dist/core/count-quorum-leaf.js +38 -0
  117. package/dist/core/count-reachability-budget.d.ts +1 -0
  118. package/dist/core/count-reachability-budget.js +7 -0
  119. package/dist/core/count-reachability-reconcile.d.ts +11 -0
  120. package/dist/core/count-reachability-reconcile.js +19 -0
  121. package/dist/core/count-reachability.d.ts +50 -0
  122. package/dist/core/count-reachability.js +351 -0
  123. package/dist/core/count-rebase-path.d.ts +9 -0
  124. package/dist/core/count-rebase-path.js +68 -0
  125. package/dist/core/count-recipe-context.d.ts +45 -0
  126. package/dist/core/count-recipe-context.js +71 -0
  127. package/dist/core/count-recipe-controller.d.ts +115 -0
  128. package/dist/core/count-recipe-controller.js +417 -0
  129. package/dist/core/count-recipe-graph.d.ts +36 -0
  130. package/dist/core/count-recipe-graph.js +211 -0
  131. package/dist/core/count-recovery/conditional-check-cache.js +3 -2
  132. package/dist/core/count-recovery/conditional-cuts.js +5 -4
  133. package/dist/core/count-recovery/conditional-proof.d.ts +37 -3
  134. package/dist/core/count-recovery/conditional-proof.js +72 -30
  135. package/dist/core/count-recovery/derivability-closure.js +2 -1
  136. package/dist/core/count-recovery/guard-cases.js +2 -1
  137. package/dist/core/count-recovery/reframe-tree.d.ts +2 -0
  138. package/dist/core/count-recovery/reframe-tree.js +24 -0
  139. package/dist/core/count-recovery/replay-linear-skeleton.d.ts +2 -0
  140. package/dist/core/count-recovery/replay-linear-skeleton.js +28 -0
  141. package/dist/core/count-recovery/row-cases.js +2 -1
  142. package/dist/core/count-rejection-budget.d.ts +8 -0
  143. package/dist/core/count-rejection-budget.js +15 -0
  144. package/dist/core/count-replacement.d.ts +5 -0
  145. package/dist/core/count-replacement.js +129 -0
  146. package/dist/core/count-replay-diagnostic.d.ts +21 -0
  147. package/dist/core/count-replay-diagnostic.js +49 -0
  148. package/dist/core/count-replay-skeleton.d.ts +4 -0
  149. package/dist/core/count-replay-skeleton.js +28 -0
  150. package/dist/core/count-rescope-funding.d.ts +3 -0
  151. package/dist/core/count-rescope-funding.js +17 -0
  152. package/dist/core/count-restrictions.d.ts +11 -0
  153. package/dist/core/count-restrictions.js +31 -0
  154. package/dist/core/count-retry-budget.d.ts +67 -0
  155. package/dist/core/count-retry-budget.js +114 -0
  156. package/dist/core/count-retry-round.d.ts +24 -0
  157. package/dist/core/count-retry-round.js +44 -0
  158. package/dist/core/count-row-agreement.d.ts +35 -0
  159. package/dist/core/count-row-agreement.js +270 -0
  160. package/dist/core/count-row-aliases.d.ts +3 -0
  161. package/dist/core/count-row-aliases.js +59 -0
  162. package/dist/core/count-row-composition.d.ts +6 -0
  163. package/dist/core/count-row-composition.js +55 -0
  164. package/dist/core/count-row-copy-linear.d.ts +4 -0
  165. package/dist/core/count-row-copy-linear.js +83 -0
  166. package/dist/core/count-row-copy.d.ts +4 -0
  167. package/dist/core/count-row-copy.js +94 -0
  168. package/dist/core/count-row-policy.d.ts +3 -0
  169. package/dist/core/count-row-policy.js +56 -0
  170. package/dist/core/count-row-reindex.d.ts +11 -0
  171. package/dist/core/count-row-reindex.js +126 -0
  172. package/dist/core/count-row-support.d.ts +9 -0
  173. package/dist/core/count-row-support.js +42 -0
  174. package/dist/core/count-row-symmetry.d.ts +7 -0
  175. package/dist/core/count-row-symmetry.js +100 -0
  176. package/dist/core/count-scope-hyps.d.ts +2 -0
  177. package/dist/core/count-scope-hyps.js +163 -0
  178. package/dist/core/count-scope-row-reuse.d.ts +3 -0
  179. package/dist/core/count-scope-row-reuse.js +92 -0
  180. package/dist/core/count-search-allowance.d.ts +1 -0
  181. package/dist/core/count-search-allowance.js +17 -0
  182. package/dist/core/count-stabilize-tree.d.ts +9 -0
  183. package/dist/core/count-stabilize-tree.js +35 -0
  184. package/dist/core/count-stage-trace.d.ts +8 -0
  185. package/dist/core/count-stage-trace.js +45 -0
  186. package/dist/core/count-strategies.d.ts +16 -0
  187. package/dist/core/count-strategies.js +155 -0
  188. package/dist/core/count-strategy-premises.d.ts +5 -0
  189. package/dist/core/count-strategy-premises.js +14 -0
  190. package/dist/core/count-strategy.d.ts +41 -0
  191. package/dist/core/count-strategy.js +76 -0
  192. package/dist/core/count-support.js +3 -2
  193. package/dist/core/count-tier-budget.d.ts +14 -0
  194. package/dist/core/count-tier-budget.js +64 -0
  195. package/dist/core/count-unwritten-prefix.d.ts +24 -0
  196. package/dist/core/count-unwritten-prefix.js +97 -0
  197. package/dist/core/count-write-shape.d.ts +15 -0
  198. package/dist/core/count-write-shape.js +73 -0
  199. package/dist/core/counts.d.ts +37 -13
  200. package/dist/core/counts.js +990 -127
  201. package/dist/core/cycles.js +5 -4
  202. package/dist/core/cyclic.js +11 -10
  203. package/dist/core/data.js +16 -15
  204. package/dist/core/dsl-deadline.d.ts +3 -0
  205. package/dist/core/dsl-deadline.js +27 -0
  206. package/dist/core/dsl.d.ts +9 -0
  207. package/dist/core/dsl.js +156 -51
  208. package/dist/core/evaluation-admission.d.ts +1 -0
  209. package/dist/core/evaluation-admission.js +3 -0
  210. package/dist/core/exists.d.ts +6 -1
  211. package/dist/core/exists.js +51 -9
  212. package/dist/core/field-laws.d.ts +3 -1
  213. package/dist/core/field-laws.js +140 -2
  214. package/dist/core/finite-houdini.d.ts +6 -0
  215. package/dist/core/finite-houdini.js +63 -21
  216. package/dist/core/finite-tiny.js +95 -67
  217. package/dist/core/fixtures/count-completion/paxos-decision.json +1 -0
  218. package/dist/core/fresh.js +5 -1
  219. package/dist/core/infer.js +45 -30
  220. package/dist/core/kind.js +2 -1
  221. package/dist/core/lemma-cuts.js +11 -10
  222. package/dist/core/linear-admission.d.ts +14 -0
  223. package/dist/core/linear-admission.js +151 -0
  224. package/dist/core/machine.d.ts +5 -2
  225. package/dist/core/machine.js +105 -31
  226. package/dist/core/meter.d.ts +22 -0
  227. package/dist/core/meter.js +34 -0
  228. package/dist/core/nonterm.js +4 -3
  229. package/dist/core/prover-row-budget.d.ts +3 -0
  230. package/dist/core/prover-row-budget.js +106 -0
  231. package/dist/core/quorum-laws.d.ts +21 -1
  232. package/dist/core/quorum-laws.js +27 -3
  233. package/dist/core/rationals.js +3 -2
  234. package/dist/core/rejection-discovery.d.ts +34 -0
  235. package/dist/core/rejection-discovery.js +36 -0
  236. package/dist/core/rejection-stage.d.ts +39 -0
  237. package/dist/core/rejection-stage.js +205 -0
  238. package/dist/core/request-quotient.d.ts +8 -0
  239. package/dist/core/request-quotient.js +299 -0
  240. package/dist/core/row-agreement-shape.d.ts +15 -0
  241. package/dist/core/row-agreement-shape.js +68 -0
  242. package/dist/core/runtime-wall.d.ts +2 -0
  243. package/dist/core/search-policy.d.ts +15 -0
  244. package/dist/core/search-policy.js +68 -0
  245. package/dist/core/solver.d.ts +1 -1
  246. package/dist/core/solver.js +40 -6
  247. package/dist/core/step-work.d.ts +12 -0
  248. package/dist/core/step-work.js +14 -0
  249. package/dist/core/strategy-premises.d.ts +8 -0
  250. package/dist/core/strategy-premises.js +64 -0
  251. package/dist/core/system.js +4 -3
  252. package/dist/core/table-admission.d.ts +1 -0
  253. package/dist/core/table-admission.js +3 -0
  254. package/dist/core/trace-clock.d.ts +3 -0
  255. package/dist/core/trace-clock.js +16 -0
  256. package/dist/core/transfer.js +3 -2
  257. package/dist/core/translate.js +16 -3
  258. package/dist/core/wall.d.ts +6 -1
  259. package/dist/core/wall.js +23 -9
  260. package/dist/core/watch.d.ts +1 -1
  261. package/dist/core/watch.js +13 -4
  262. package/dist/core/work-admission.d.ts +164 -0
  263. package/dist/core/work-admission.js +418 -0
  264. package/dist/core/work-amount.d.ts +21 -0
  265. package/dist/core/work-amount.js +80 -0
  266. package/dist/core/work-collections.d.ts +11 -0
  267. package/dist/core/work-collections.js +198 -0
  268. package/dist/core/work-kinds.d.ts +11 -0
  269. package/dist/core/work-kinds.js +9 -0
  270. package/dist/core/work-meter.d.ts +8 -0
  271. package/dist/core/work-meter.js +83 -0
  272. package/dist/core/work-observe.d.ts +12 -0
  273. package/dist/core/work-observe.js +39 -0
  274. package/dist/core/work-profile.d.ts +10 -0
  275. package/dist/core/work-profile.js +21 -0
  276. package/dist/core/work-refusal.d.ts +1 -0
  277. package/dist/core/work-refusal.js +6 -0
  278. package/dist/interchange/format.js +2 -0
  279. package/dist/kernel/cdcl.js +93 -40
  280. package/dist/kernel/epr.js +23 -8
  281. package/dist/kernel/kernel.d.ts +47 -1
  282. package/dist/kernel/kernel.js +417 -68
  283. package/dist/kernel/prove.d.ts +49 -3
  284. package/dist/kernel/prove.js +468 -122
  285. package/dist/kernel/prover-rows.d.ts +1 -0
  286. package/dist/kernel/prover-rows.js +12 -1
  287. package/dist/kernel/reader.d.ts +1 -1
  288. package/dist/kernel/reader.js +57 -12
  289. package/dist/kernel/simplex.js +9 -2
  290. package/dist/lean-kernel/emit.d.ts +9 -1
  291. package/dist/lean-kernel/emit.js +144 -22
  292. package/dist/lean-kernel/legacy-family-library.d.ts +1 -0
  293. package/dist/lean-kernel/legacy-family-library.js +5 -0
  294. package/dist/lean-kernel/library.js +3 -3
  295. package/package.json +1 -1
package/dist/core/dsl.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { searchNow as countedSearchNow } from "./wall.js";
1
2
  // Typed builders for machines, decisions and loops: names are declared once and come back as typed values, so a
2
3
  // misspelled name, a law that reads a request, or a step that sets an undeclared variable is a TypeScript error, and
3
4
  // the input kinds the kernel would otherwise see as hand encodings (a flag, an optional fact, a choice among values)
@@ -18,12 +19,18 @@
18
19
  import { candidates, cone, searchCounted } from "./counts.js";
19
20
  import { inheritSource, translationVerdict } from "./source-check.js";
20
21
  import { env as knobs } from "./solver.js";
21
- import { argsKey, bindDirect, directOf, machineTerms, part, tuple, carriedView, compileFunction, divName, divisor, divisorsIn, evalC, evalE, fnCall, interpret, isArithmetic, loadJs, modName, numbersOf, pairedArgs, seeded, sourceFreeFn, withArithmetic } from "./machine.js";
22
+ import { argsKey, bindDirect, directOf, machineTerms, part, tuple, carriedView, compileFunction, divName, divisor, divisorsIn, evalC, evalE, fnCall, hasFinite, interpret, isArithmetic, loadJs, modName, numbersOf, pairedArgs, seeded, sourceFreeFn, withArithmetic } from "./machine.js";
22
23
  import { allowed, keysOf, requestEnv, watch, watchWork } from "./watch.js";
23
24
  import { ghostOf, proveSome, skolemOf, someHolds, substVars, substVarsE, witnessSupport } from "./exists.js";
24
25
  import { check, mapArities, checkRecur, foldObligations, ghostedMachine, loopObligations, someOfGhostsOk, substC, sumMachine } from "../kernel/kernel.js";
25
- import { certLoop, clock, counted, factsFor, fullRate, grow, pastWall, proveLaw, proveLaws, proveLiveness, proveSetFast, proveStepLaws, usualProof, withDeadline, withWall } from "../kernel/prove.js";
26
- import { WallExpired, checkWall, searchWall } from "./wall.js";
26
+ import { certLoop, clock, counted, factsFor, fullRate, grow, pastWall, proveLaw, proveLaws, proveLiveness, proveSetFast, proveStepLaws, usualProof, withWall } from "../kernel/prove.js";
27
+ import { WallExpired, checkWall, checkWorkEndpoint, searchWall, withBudget, BudgetExpired } from "./wall.js";
28
+ import { completeWorkProfile } from "./work-profile.js";
29
+ import { workLedger } from "./work-admission.js";
30
+ import { withStageAllowance, withStageDeadline, withStageWall } from "./dsl-deadline.js";
31
+ import { withPublicSearchPolicy } from "./search-policy.js";
32
+ import { workRefusalWhy } from "./work-refusal.js";
33
+ import { workDivide, workFromNumber, workToNumber } from "./work-amount.js";
27
34
  import { certCyclic, certOn, crossCyclic, cyclicOn, foldNodes, proveCyclic, quietly, recurNodes, translatedProof, uncovered } from "./cyclic.js";
28
35
  import { discover } from "./discover.js";
29
36
  import { inferLaws, inferRates } from "./infer.js";
@@ -1059,6 +1066,41 @@ export class SeqTable {
1059
1066
  }
1060
1067
  // f at every key below n: what bookkeeping a request carries meets, row by row (where each grant went, say).
1061
1068
  export const everyBelow = (n, f) => everyKey(k => k.lt(n).implies(f(k)));
1069
+ // Explicit finite-domain opt-in. The guard, not the label, carries its semantics.
1070
+ // A size is over immutable params; the kernel validates that when it scopes the rule.
1071
+ // Unlike everyBelow's legacy breakpoint route, every/some enumerate every element.
1072
+ export function sizedSort(name, size) {
1073
+ if (!name)
1074
+ throw new Error('a sized sort needs a name');
1075
+ const below = termOf(size);
1076
+ const every = (f) => {
1077
+ const key = `k$${++boundCounter}`;
1078
+ const body = f(v(key));
1079
+ if (body.ex?.length || hasAll(body.c))
1080
+ throw new Error('a finite sort body must be unquantified in this slice');
1081
+ const c = { op: 'all', key, finite: name, c: { op: 'or', xs: [{ op: 'not', x: { op: '<', a: v(key).e, b: below } }, body.c] } };
1082
+ const n = valOf(size);
1083
+ if (n !== undefined)
1084
+ naturalConst(n);
1085
+ checkWall('finite sort enumeration');
1086
+ let ok = n === undefined ? undefined : true;
1087
+ if (n !== undefined)
1088
+ for (let k = 0; k < n; k++) {
1089
+ if ((k & 255) === 0)
1090
+ checkWall('finite sort enumeration');
1091
+ const holds = f(keyTerm(k)).ok;
1092
+ if (holds === false) {
1093
+ ok = false;
1094
+ break;
1095
+ }
1096
+ if (holds === undefined)
1097
+ ok = undefined;
1098
+ }
1099
+ return new Cond(c, ok);
1100
+ };
1101
+ return { name, size: new Term(below, valOf(size)), has: (key) => new Term(termOf(key), valOf(key)).lt(size),
1102
+ every, some: (f) => every(k => f(k).not()).not() };
1103
+ }
1062
1104
  const when_ = (c, then, otherwise) => new Term({ op: 'if', c: c.c, then: termOf(then), else: termOf(otherwise) }, c.ok === undefined ? undefined : valOf(c.ok ? then : otherwise));
1063
1105
  const isPartsWrite = (u) => typeof u === 'object' && u !== null && 'parts' in u;
1064
1106
  // The parts of a value written at a cell, by the names of the maps they go to.
@@ -1437,7 +1479,7 @@ class Hoister {
1437
1479
  const outer = bound.filter(key => namesIn(q).includes(key));
1438
1480
  if (outer.length)
1439
1481
  throw new Error(`a condition at every key reads ${outer[0]}, a key bound outside it: two keys at once are named together (everyKey((i, j) => ...))`);
1440
- const inner = perStep(q.c), keys = q.keys?.length ? { keys: q.keys } : {};
1482
+ const inner = perStep(q.c), keys = { ...(q.keys?.length ? { keys: q.keys } : {}), ...(q.finite === undefined ? {} : { finite: q.finite }) };
1441
1483
  if (!inner) {
1442
1484
  const f = name ?? `${this.prefix}${++this.n}`;
1443
1485
  this.flags[f] = { op: 'all', key: q.key, ...keys, c: q.c };
@@ -1473,6 +1515,8 @@ export function nameQuantifiers(m) {
1473
1515
  const hasForall = (c, positive = true) => c.op === 'all' ? positive || hasForall(c.c, positive) : c.op === 'not' ? hasForall(c.x, !positive) : c.op === 'and' || c.op === 'or' ? c.xs.some(y => hasForall(y, positive)) : false;
1474
1516
  const hasAll = (c) => JSON.stringify(c).includes('"op":"all"');
1475
1517
  function prenex(c, what, key) {
1518
+ if (hasFinite(c) && (what.startsWith('step law') || (c.op !== 'all' && hasForall(c))))
1519
+ throw new Error(`${what}: a finite universal is one whole law in this slice (not nested or a step law)`);
1476
1520
  let found = false;
1477
1521
  const walk = (d, positive) => {
1478
1522
  switch (d.op) {
@@ -1598,15 +1642,15 @@ export const recur = (name, def, lemmas = {}, between = {}) => {
1598
1642
  .step((env) => ({ x: env.x.plus(1), fx: def.next(env.x, env.fx, envAt(args.map(a => env[a]))) }));
1599
1643
  const laws = Object.entries(lemmas).map(([n, f]) => r.law(n, (env) => f(env.x, env.fx, envAt(args.map(a => env[a])))));
1600
1644
  // (Its machine's proof timed alone: the recurrence is compared below as its own instance.)
1601
- const t0 = performance.now();
1645
+ const t0 = countedSearchNow();
1602
1646
  usualProof.last = undefined;
1603
1647
  verdict = quietly(() => proveRule(r, laws, { search: false }));
1604
1648
  lemmaProof = usualProof.last;
1605
1649
  if (cyclicOn())
1606
- crossCyclic('recurrence', name, verdict.proven && verdict.checked, () => { const { facts, specs } = recurNodes(recurCase([])); return proveCyclic(facts, specs); }, performance.now() - t0, translatedRecur({ lemmas: lemmaProof }));
1650
+ crossCyclic('recurrence', name, verdict.proven && verdict.checked, () => { const { facts, specs } = recurNodes(recurCase([])); return proveCyclic(facts, specs); }, countedSearchNow() - t0, translatedRecur({ lemmas: lemmaProof }));
1607
1651
  // (the usual trees checked already, inside quietly: where no cyclic proof is made they are the certificate)
1608
1652
  if (certOn() && verdict.proven && verdict.checked) {
1609
- const c = certCyclic('recurrence', name, translatedRecur({ lemmas: lemmaProof }), () => { const { facts, specs } = recurNodes(recurCase([])); return proveCyclic(facts, specs); }, performance.now() - t0);
1653
+ const c = certCyclic('recurrence', name, translatedRecur({ lemmas: lemmaProof }), () => { const { facts, specs } = recurNodes(recurCase([])); return proveCyclic(facts, specs); }, countedSearchNow() - t0);
1610
1654
  if (!c.checked)
1611
1655
  uncovered('recurrence', name, c.why);
1612
1656
  }
@@ -1648,7 +1692,7 @@ export const recur = (name, def, lemmas = {}, between = {}) => {
1648
1692
  const laws = [...Object.entries(lemmas).map(([n, l]) => r.law(`${n} at y`, (env) => l(env.y, env.fy, envAt(at(env))))),
1649
1693
  ...Object.entries(between).map(([n, l]) => r.law(n, (env) => l(env.x, env.fx, env.y, env.fy, envAt(at(env)))))];
1650
1694
  usualProof.last = undefined;
1651
- const t0 = performance.now(), v = quietly(() => proveRule(r, laws, { search: false })), usualMs = performance.now() - t0, betweenProof = usualProof.last;
1695
+ const t0 = countedSearchNow(), v = quietly(() => proveRule(r, laws, { search: false })), usualMs = countedSearchNow() - t0, betweenProof = usualProof.last;
1652
1696
  if (cyclicOn())
1653
1697
  crossCyclic('recurrence, between', name, v.proven && v.checked, () => { const { facts, specs } = recurNodes(recurCase(pairs)); return proveCyclic(facts, specs); }, usualMs, betweenProof && translatedRecur({ lemmas: lemmaProof, between: betweenProof }));
1654
1698
  if (certOn() && v.proven && v.checked) {
@@ -2018,9 +2062,11 @@ export class Rule {
2018
2062
  const key = `key$${++keyCounter}`;
2019
2063
  if (out instanceof Cond) {
2020
2064
  const p = prenex(out.c, `law ${name}`, key);
2021
- return this.divides(this.someOf(name, out, p ? { name, forall: key, holds: p } : { name, holds: out.c }));
2065
+ return this.divides(this.someOf(name, out, p ? { name, forall: key, holds: p, ...(out.c.op === 'all' && out.c.finite !== undefined ? { finite: out.c.finite } : {}) } : { name, holds: out.c }));
2022
2066
  }
2023
2067
  const [k1, more] = keysFor(out), inner = out.forall(v(k1), ...more.map(v)), holds = inner.c;
2068
+ if (hasFinite(holds))
2069
+ throw new Error(`law ${name}: a finite universal is one whole law, not inside forall`);
2024
2070
  return this.divides(this.someOf(name, inner, more.length ? { name, forall: k1, keys: more, holds } : { name, forall: k1, holds: prenex(holds, `law ${name}`, k1) ?? holds }));
2025
2071
  }
2026
2072
  // A law's existentials (exists), pulled out before it: `some` its naturals, `witness` the ones given (a ghost's step
@@ -3124,12 +3170,19 @@ function refuteByRuns(r, laws, stepLaws = [], budget = refuteBudget) {
3124
3170
  const facts = (m.facts ?? []).filter(f => !isArithmetic(f.name.slice(0, f.name.indexOf(':'))));
3125
3171
  const holds = (f, params) => {
3126
3172
  const names = f.forall ? [f.forall, ...(f.keys ?? [])] : [], top = names.length > 1 ? bound : 2 * bound;
3127
- const at = (env, i) => (i === names.length ? evalC(f.holds, env, { scalars: {}, maps: {} }, m)
3128
- : Array.from({ length: top + 1 }, (_, key) => key).every(key => at({ ...env, [names[i]]: key }, i + 1)));
3173
+ const at = (env, i) => {
3174
+ checkWorkEndpoint('refutation fact bindings');
3175
+ return i === names.length ? evalC(f.holds, env, { scalars: {}, maps: {} }, m)
3176
+ : Array.from({ length: top + 1 }, (_, key) => key).every(key => at({ ...env, [names[i]]: key }, i + 1));
3177
+ };
3129
3178
  try {
3130
3179
  return at(params, 0);
3131
3180
  }
3132
- catch {
3181
+ catch (e) {
3182
+ if (e instanceof WallExpired)
3183
+ throw e;
3184
+ if (e instanceof BudgetExpired)
3185
+ checkWorkEndpoint(e.phase);
3133
3186
  return false;
3134
3187
  }
3135
3188
  };
@@ -3140,7 +3193,7 @@ function refuteByRuns(r, laws, stepLaws = [], budget = refuteBudget) {
3140
3193
  && facts.filter(readsParams).every(f => holds(f, params));
3141
3194
  const cap = watchWork.n + perTrial * budget.trials;
3142
3195
  try {
3143
- const late = () => pastWall() || budget.until !== undefined && performance.now() > budget.until;
3196
+ const late = () => { checkWorkEndpoint('refutation poll'); return pastWall() || budget.until !== undefined && countedSearchNow() > budget.until; };
3144
3197
  for (let trial = 0; trial < budget.trials && watchWork.n <= cap && !late(); trial++) {
3145
3198
  // (`mixed`: the trials in turn at bounds 1 to 4, every fourth near)
3146
3199
  const bound = budget.mixed ? 1 + trial % 4 : budget.bound, guided = guides, near = budget.mixed && trial % 4 ? undefined : budget.near;
@@ -3217,6 +3270,8 @@ function refuteByRuns(r, laws, stepLaws = [], budget = refuteBudget) {
3217
3270
  catch (e) {
3218
3271
  if (e instanceof WallExpired)
3219
3272
  throw e;
3273
+ if (e instanceof BudgetExpired)
3274
+ checkWorkEndpoint(e.phase);
3220
3275
  return undefined;
3221
3276
  }
3222
3277
  return undefined;
@@ -3228,7 +3283,47 @@ const refutedVerdict = (out) => ({ proven: false, checked: false, goal: out.goal
3228
3283
  // another instance of the same rule (a factory called twice).
3229
3284
  const noting = (r, ...xs) => { const ks = divisorsIn(xs); if (ks.size)
3230
3285
  r.dividesBy(...ks); return r; };
3286
+ function workPlan(opts) {
3287
+ const explicit = typeof opts.search === 'object' ? opts.search.work : undefined;
3288
+ const ms = typeof opts.search === 'object' ? opts.search.ms : undefined;
3289
+ if (explicit !== undefined && ms !== undefined)
3290
+ throw new RangeError('choose a work budget or a legacy ms budget, not both');
3291
+ const work = explicit ?? (completeWorkProfile.enabled ? ms === undefined ? completeWorkProfile.defaultUnits : ms * fullRate : undefined);
3292
+ if (work === undefined || opts.search === false)
3293
+ return { work, opts };
3294
+ const search = typeof opts.search === 'object' ? { ...opts.search } : {};
3295
+ delete search.work;
3296
+ // Compatibility scheduling hint only; withBudget below receives the exact
3297
+ // original amount. This display must never become the root's authority.
3298
+ search.ms = typeof work === 'number' ? work / fullRate : workToNumber(workDivide(work, workFromNumber(fullRate)));
3299
+ return { work, opts: { ...opts, search } };
3300
+ }
3301
+ function workVerdict(opts, supported, run) {
3302
+ const plan = workPlan(opts);
3303
+ // An implicit child inherits the owner's hard allowance, not a fresh default.
3304
+ // Keep workPlan's validation and scheduling hint; let the owner's refusal
3305
+ // propagate to its handler rather than becoming this child's unknown verdict.
3306
+ const implicit = typeof opts.search !== 'object' || (opts.search.work === undefined && opts.search.ms === undefined);
3307
+ if (completeWorkProfile.enabled && workLedger.inBudget() && implicit)
3308
+ return run(plan.opts);
3309
+ if (plan.work === undefined)
3310
+ return run(plan.opts);
3311
+ if (!completeWorkProfile.enabled && !supported)
3312
+ return { proven: false, checked: false, stuck: 'unknown', why: 'work mode: plain-path migration pending' };
3313
+ try {
3314
+ return withBudget(plan.work, () => run(plan.opts));
3315
+ }
3316
+ catch (error) {
3317
+ if (!(error instanceof BudgetExpired))
3318
+ throw error;
3319
+ return { proven: false, checked: false, stuck: 'unknown', why: workRefusalWhy(error) };
3320
+ }
3321
+ }
3231
3322
  export function proveRule(r, laws, opts = {}) {
3323
+ const hasCounts = !!Object.keys(r.machine.counts ?? {}).length;
3324
+ return workVerdict(opts, hasCounts, plan => withPublicSearchPolicy(hasCounts, () => proveRuleWall(r, laws, plan)));
3325
+ }
3326
+ function proveRuleWall(r, laws, opts) {
3232
3327
  const ms = typeof opts.search === 'object' ? opts.search.ms : undefined;
3233
3328
  const run = () => {
3234
3329
  try {
@@ -3251,6 +3346,7 @@ function proveRuleIn(r, laws, opts) {
3251
3346
  r = r.withSumsOf(laws);
3252
3347
  noting(r, laws);
3253
3348
  const refuted = refuteByRuns(r, laws);
3349
+ checkWorkEndpoint('refutation result');
3254
3350
  // A state the laws allow whose step breaks one, with no run to it (a wide rule's: what the kernel's step goal would end
3255
3351
  // at), is a counterexample to induction: the laws may still hold, so the search goes on from it, as from the kernel's.
3256
3352
  // (A step law broken so is refused, proveSteps below: it holds from every state the laws allow, reached or not.)
@@ -3271,11 +3367,15 @@ function proveRuleIn(r, laws, opts) {
3271
3367
  // Quantified witness preflight needs a counted allocation: a slow attempt must
3272
3368
  // not seed different memoized decisions. Other laws keep their existing budget;
3273
3369
  // inference's query rate is not calibrated for their whole-set preflight.
3274
- const out = ms === undefined ? given() : withWall(performance.now() + ms / share, () => share === 1 ? given() : counted(inferRates.work, () => withDeadline(clock() + ms / share, given)));
3275
- const v = { ...verdictOf(out), ...(out.witnesses && out.proven ? { witnesses: out.witnesses } : {}) };
3370
+ const out = ms === undefined ? given() : withStageWall(countedSearchNow() + ms / share, () => share === 1 ? given() : counted(inferRates.work, () => withStageDeadline(clock() + ms / share, given, () => undefined)), () => undefined);
3371
+ const v = out ? { ...verdictOf(out), ...(out.witnesses && out.proven ? { witnesses: out.witnesses } : {}) }
3372
+ : { proven: false, checked: false, stuck: 'unknown' };
3276
3373
  return searched(r, laws, [], v, opts);
3277
3374
  }
3278
3375
  export function proveSteps(r, laws, stepLaws, opts = {}) {
3376
+ return workVerdict(opts, false, plan => proveStepsWall(r, laws, stepLaws, plan));
3377
+ }
3378
+ function proveStepsWall(r, laws, stepLaws, opts) {
3279
3379
  const ms = typeof opts.search === 'object' ? opts.search.ms : undefined;
3280
3380
  // From any state, the caller's budget includes preflight runs and all initial
3281
3381
  // goals, not a fresh budget per goal. Keep reachable-state search unchanged.
@@ -3290,13 +3390,14 @@ export function proveSteps(r, laws, stepLaws, opts = {}) {
3290
3390
  }
3291
3391
  };
3292
3392
  const verdict = opts.from !== 'any' || ms === undefined ? run()
3293
- : withWall(performance.now() + ms, run);
3393
+ : withWall(countedSearchNow() + ms, run);
3294
3394
  return translationVerdict(r, [...laws, ...stepLaws], verdict);
3295
3395
  }
3296
3396
  function proveStepsIn(r, laws, stepLaws, opts) {
3297
3397
  r = r.withSumsOf(laws, stepLaws);
3298
3398
  noting(r, laws, stepLaws);
3299
3399
  const refuted = refuteByRuns(r, laws, stepLaws);
3400
+ checkWorkEndpoint('refutation result');
3300
3401
  // (a step law broken from a state the laws allow, with no run to it: the laws may need an invariant there, or the run
3301
3402
  // be further than these runs go; the search goes on from it, as from the kernel's)
3302
3403
  if (refuted)
@@ -3340,7 +3441,7 @@ function searched(r, laws, stepLaws, v, opts) {
3340
3441
  // The deeper runs; then runs over small values (keys that meet, small params), whose requests meet their
3341
3442
  // assumption's equalities and clocks, or near the counterexample the verdict ends at.
3342
3443
  // (the three within the search's budget again, on the wall: past it they stop, and the search starts as it would)
3343
- const ms = typeof opts.search === 'object' && opts.search.ms !== undefined ? opts.search.ms : 10_000, runsUntil = performance.now() + ms;
3444
+ const ms = typeof opts.search === 'object' && opts.search.ms !== undefined ? opts.search.ms : 10_000, runsUntil = countedSearchNow() + ms;
3344
3445
  for (const b of [deeperBudget, { ...deeperBudget, bound: 1, seed: 31, states: false }, { ...deeperBudget, trials: 1200, seed: 41, states: false, mixed: true, ...(v.witness ? { near: v.witness } : {}) }]) {
3345
3446
  const deeper = refuteByRuns(r, laws, stepLaws, { ...b, until: runsUntil });
3346
3447
  if (deeper?.run)
@@ -3357,7 +3458,7 @@ function searched(r, laws, stepLaws, v, opts) {
3357
3458
  }
3358
3459
  const until = clock() + (typeof opts.search === 'object' && opts.search.ms !== undefined ? opts.search.ms : 10_000);
3359
3460
  // (the search's end on the wall too: kernel/prove.ts's withWall, past which every goal is unknown)
3360
- return withWall(performance.now() + Math.max(0, until - clock()), () => searchedUntil(r, laws, stepLaws, v, opts, until));
3461
+ return withStageWall(countedSearchNow() + Math.max(0, until - clock()), () => searchedUntil(r, laws, stepLaws, v, opts, until), () => v);
3361
3462
  }
3362
3463
  // Two machines alike up to the names of the keys their quantified flags and writes at every key bind (the rule builds
3363
3464
  // fresh ones each time it is read): each bound name by its place of first binding.
@@ -3381,7 +3482,7 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
3381
3482
  const ghosted = stepGhosts(r.machine, stepLaws);
3382
3483
  // (with the step laws' ghosts, a wall stop too, at the budget: their goals cost the cost model more than its clock
3383
3484
  // counts, a wide rule's past twice its wall time; and the last runs always, the search's tail on the wall too)
3384
- const bounded = (ms, from, wall = !!ghosted) => counted(fullRate, () => findBoundedRun(ghosted?.machine ?? r.machine, [...laws, ...(ghosted?.laws ?? [])], { ms, from, steps: true, ...(wall ? { wall: performance.now() + ms } : {}), progress: k => { reached = k; } }), true);
3485
+ const bounded = (ms, from, wall = !!ghosted) => counted(fullRate, () => withStageAllowance(ms, () => findBoundedRun(ghosted?.machine ?? r.machine, [...laws, ...(ghosted?.laws ?? [])], { ms, from, steps: true, ...(wall ? { wall: countedSearchNow() + ms } : {}), progress: k => { reached = k; } }), () => undefined), true);
3385
3486
  const refutedBy = (b) => refutedVerdict({ goal: `${b.law} @step (a run of ${b.depth} steps from the start)`, witness: b.witness, run: { params: b.params, trace: b.trace.map(shownRequest) } });
3386
3487
  const shallow = bounded(Math.min(250, total / 40), 1);
3387
3488
  if (shallow)
@@ -3390,24 +3491,24 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
3390
3491
  // within a twentieth of the budget (at most 500 ms, counted so too).
3391
3492
  if (!any && !stepLaws.length && laws.every(l => !l.forall && !l.keys?.length && !l.some?.length)) {
3392
3493
  const ms = Math.min(500, total / 20), kinds = withKinds(r, []).filter(k => !laws.some(l => l.name === k.name));
3393
- const kd = counted(fullRate, () => proveKInduction(r.machine, kinds, conjunction(laws), { ms }), true);
3394
- if (kd.proven && kd.checked)
3494
+ const kd = counted(fullRate, () => withStageAllowance(ms, () => proveKInduction(r.machine, kinds, conjunction(laws), { ms }), () => undefined), true);
3495
+ if (kd?.proven && kd.checked)
3395
3496
  return { proven: true, checked: true, k: kd.k, assumes: { states: 'reachable', laws: [] } };
3396
3497
  }
3397
3498
  let rule = r, lemmas;
3398
3499
  const { fns, lists } = r.parts;
3399
3500
  if (lists.length || fns.some(([, d]) => recurOf(d))) {
3400
- const d = withDeadline(until, () => discover(r, laws, stepLaws, v));
3401
- if (d.verdict.proven && d.verdict.checked)
3501
+ const d = withStageDeadline(until, () => discover(r, laws, stepLaws, v), () => undefined);
3502
+ if (d?.verdict.proven && d.verdict.checked)
3402
3503
  return { ...d.verdict, found: { lemmas: d.found } };
3403
- if (Object.keys(d.found).length)
3504
+ if (d && Object.keys(d.found).length)
3404
3505
  (rule = d.rule, lemmas = d.found);
3405
3506
  }
3406
3507
  // Functions known by their facts alone (not a recurrence): lemmas about them, fitted to their values and proven from
3407
3508
  // the facts as cyclic claims, the laws proven with them as facts.
3408
3509
  if ((typeof opts.search !== 'object' || opts.search.cycles !== false) && fns.some(([, d]) => !recurOf(d)) && rule.machine.facts?.length && until - clock() > 500) {
3409
- const c = withDeadline(until, () => cycleLemmas(rule.machine, withKinds(rule, laws), stepLaws, { ms: (until - clock()) / 2 }));
3410
- if (c.proven && c.checked)
3510
+ const c = withStageDeadline(until, () => cycleLemmas(rule.machine, withKinds(rule, laws), stepLaws, { ms: (until - clock()) / 2 }), () => undefined);
3511
+ if (c?.proven && c.checked)
3411
3512
  return { proven: true, checked: true, found: { ...(lemmas ? { lemmas } : {}), facts: c.found.map(f => f.text) } };
3412
3513
  }
3413
3514
  // Laws about the ids a counter hands out (core/fresh.ts), within a tenth of what is left: the laws with them, then
@@ -3418,11 +3519,11 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
3418
3519
  let fresh = [];
3419
3520
  if (Object.keys(rule.machine.maps ?? {}).length && until - clock() - tail > 1000) {
3420
3521
  const fm = rule.machine, share = (until - clock() - tail) / 10;
3421
- fresh = withDeadline(clock() + share, () => freshLaws(fm, rule.kindLaws(), { params: (rand, bound) => rule.randomParams(rand, bound), input: (rand, bound, ps) => rule.randomInput(rand, bound, ps) }, { ms: share }));
3522
+ fresh = withStageDeadline(clock() + share, () => freshLaws(fm, rule.kindLaws(), { params: (rand, bound) => rule.randomParams(rand, bound), input: (rand, bound, ps) => rule.randomInput(rand, bound, ps) }, { ms: share }), () => []);
3422
3523
  if (fresh.length) {
3423
3524
  // (counted, as the laws' own search: the same verdict on any machine)
3424
- const given = [...withKinds(rule, laws), ...fresh.map(f => f.law)], out = counted(fullRate, () => withDeadline(clock() + share, () => (stepLaws.length ? proveStepLaws(fm, given, stepLaws) : proveLaws(fm, given))), true);
3425
- if (out.proven && out.checked)
3525
+ const given = [...withKinds(rule, laws), ...fresh.map(f => f.law)], out = counted(fullRate, () => withStageDeadline(clock() + share, () => (stepLaws.length ? proveStepLaws(fm, given, stepLaws) : proveLaws(fm, given)), () => undefined), true);
3526
+ if (out?.proven && out.checked)
3426
3527
  return { proven: true, checked: true, found: { laws: fresh, ...(lemmas ? { lemmas } : {}) }, assumes: reachableBy(fresh) };
3427
3528
  }
3428
3529
  }
@@ -3433,9 +3534,11 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
3433
3534
  if (!stepLaws.length && laws.some(l => l.some?.length) && laws.every(l => !l.some?.length || !l.forall)) {
3434
3535
  let c;
3435
3536
  try {
3436
- c = withWall(performance.now() + ms / 2, () => withDeadline(clock() + ms / 2, () => someCone(rule, laws, ms / 2)));
3537
+ c = withStageWall(countedSearchNow() + ms / 2, () => withStageDeadline(clock() + ms / 2, () => someCone(rule, laws, ms / 2), () => undefined), () => undefined);
3437
3538
  }
3438
3539
  catch (e) {
3540
+ if (e instanceof BudgetExpired)
3541
+ throw e;
3439
3542
  if (knobs.GDP_EXISTS_LOG === '1')
3440
3543
  console.error(`exists: cone failed: ${String(e.stack ?? e).slice(0, 600)}`);
3441
3544
  }
@@ -3445,7 +3548,7 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
3445
3548
  return v;
3446
3549
  }
3447
3550
  // (the search's own wall ends where the tail begins: the last bounded runs keep it)
3448
- const tailAt = () => performance.now() + Math.max(0, until - tail - clock());
3551
+ const tailAt = () => countedSearchNow() + Math.max(0, until - tail - clock());
3449
3552
  // (a law about every key with "there exists": the search over its plain form, the value at its ghost map's cell, the
3450
3553
  // ghosts' own laws beside it, on the rule with the ghosts (exists.ts's skolemOf), its verdict `back`'s; no join, whose
3451
3554
  // convex forms can't state a cell read at a key a ghost holds: the engine alone (the join's first whole-set query on
@@ -3494,15 +3597,15 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
3494
3597
  return counted(fullRate, () => {
3495
3598
  const end = clock() + budget;
3496
3599
  if (!native)
3497
- return !withDeadline(end, () => proveLaw(tm, ls, ls.indexOf(c))).proven;
3600
+ return !withStageDeadline(end, () => proveLaw(tm, ls, ls.indexOf(c)), () => undefined)?.proven;
3498
3601
  // Try local provenance before instantiating every witness. All three
3499
3602
  // attempts share the same existing support-query allocation.
3500
- if (round === 0 && withDeadline(Math.min(end, clock() + 500), () => proveSetFast(tm, [c])).proven)
3603
+ if (round === 0 && withStageDeadline(Math.min(end, clock() + 500), () => proveSetFast(tm, [c]), () => undefined)?.proven)
3501
3604
  return false;
3502
3605
  const local = witnessSupport(tm, helpers, c, Object.keys(sk.maps));
3503
- if (withDeadline(Math.min(end, clock() + 1_000), () => proveLaw(tm, local, local.indexOf(c))).proven)
3606
+ if (withStageDeadline(Math.min(end, clock() + 1_000), () => proveLaw(tm, local, local.indexOf(c)), () => undefined)?.proven)
3504
3607
  return false;
3505
- return !withDeadline(end, () => proveLaw(tm, ls, ls.indexOf(c))).proven;
3608
+ return !withStageDeadline(end, () => proveLaw(tm, ls, ls.indexOf(c)), () => undefined)?.proven;
3506
3609
  }, true);
3507
3610
  });
3508
3611
  if (clock() >= hUntil)
@@ -3513,7 +3616,7 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
3513
3616
  for (const l of native ? sought : []) {
3514
3617
  const local = witnessSupport(tm, ls, l);
3515
3618
  if (local.length < ls.length)
3516
- withDeadline(Math.min(hUntil, clock() + 3_000), () => proveLaw(tm, local, local.indexOf(l)));
3619
+ withStageDeadline(Math.min(hUntil, clock() + 3_000), () => proveLaw(tm, local, local.indexOf(l)), () => undefined);
3517
3620
  }
3518
3621
  const b = back(target, keep.map(law => ({ law })), native);
3519
3622
  if (knobs.GDP_EXISTS_LOG === '1')
@@ -3527,14 +3630,14 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
3527
3630
  keep = keep.filter(c => !drop.includes(c));
3528
3631
  }
3529
3632
  }
3530
- const inf = withWall(tailAt(), () => inferLaws(target, [...fresh.map(f => f.law), ...sought], stepLaws, { ms, ...((rule === r && !fresh.length) || sk ? { first: v } : {}), ...(sk ? { join: 0 } : {}) }));
3531
- if (!(inf.proven && inf.checked)) {
3633
+ const inf = withStageWall(tailAt(), () => inferLaws(target, [...fresh.map(f => f.law), ...sought], stepLaws, { ms, ...((rule === r && !fresh.length) || sk ? { first: v } : {}), ...(sk ? { join: 0 } : {}) }), () => undefined);
3634
+ if (!(inf?.proven && inf.checked)) {
3532
3635
  // The sum of each map the step writes (withMapSums): the search again over the rule with them, within half of what
3533
3636
  // is left (at most 20 s), where a law of cells against a total needs one (no ERC20 balance past the supply).
3534
3637
  const summed = target.withMapSums();
3535
3638
  if (summed && until - clock() - tail > 1000) {
3536
- const inf2 = withWall(tailAt(), () => inferLaws(summed, [...fresh.map(f => f.law), ...sought], stepLaws, { ms: Math.min(20_000, (until - clock() - tail) / 2) }));
3537
- if (inf2.proven && inf2.checked) {
3639
+ const inf2 = withStageWall(tailAt(), () => inferLaws(summed, [...fresh.map(f => f.law), ...sought], stepLaws, { ms: Math.min(20_000, (until - clock() - tail) / 2) }), () => undefined);
3640
+ if (inf2?.proven && inf2.checked) {
3538
3641
  const { found, stats: _s2, ...verdict } = inf2;
3539
3642
  void _s2;
3540
3643
  const b = back(summed, found);
@@ -3546,7 +3649,7 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
3546
3649
  const deep = bounded(Math.max(0, Math.min(until - clock(), ghosted && !laws.length ? 10_000 : Infinity)), Math.max(1, reached), true);
3547
3650
  if (deep)
3548
3651
  return refutedBy(deep);
3549
- return { ...v, why: [v.why, `the search found nothing that proves it in ${Math.round(inf.stats.ms)} ms`].filter(Boolean).join('; ') };
3652
+ return { ...v, why: [v.why, inf ? `the search found nothing that proves it in ${Math.round(inf.stats.ms)} ms` : 'the search reached its stage deadline'].filter(Boolean).join('; ') };
3550
3653
  }
3551
3654
  const { found, stats: _stats, ...verdict } = inf;
3552
3655
  void _stats;
@@ -3577,10 +3680,12 @@ function someCone(r, laws0, ms) {
3577
3680
  // (a cube the kernel refuses to state, one past its key rules, is never kept)
3578
3681
  const plain = (law, ls, ms2) => {
3579
3682
  try {
3580
- const o = withDeadline(Math.min(until, clock() + ms2), () => proveLaw(m, ls, ls.indexOf(law)));
3581
- return o.proven ? { proof: true } : { stuck: o.stuck };
3683
+ const o = withStageDeadline(Math.min(until, clock() + ms2), () => proveLaw(m, ls, ls.indexOf(law)), () => undefined);
3684
+ return o ? o.proven ? { proof: true } : { stuck: o.stuck } : { stuck: 'unknown' };
3582
3685
  }
3583
- catch {
3686
+ catch (e) {
3687
+ if (e instanceof BudgetExpired)
3688
+ throw e;
3584
3689
  return { stuck: '' };
3585
3690
  }
3586
3691
  };
@@ -3609,7 +3714,7 @@ function proveLeadsToIn(r, laws, l, opts) {
3609
3714
  const until = clock() + (opts.ms ?? 10_000), draws = { params: (rand, bound) => r.randomParams(rand, bound), input: (rand, bound, ps) => r.randomInput(rand, bound, ps) };
3610
3715
  // (the laws about the keys a counter hands out or a high-water mark bounds, core/fresh.ts, within a twentieth: given
3611
3716
  // to both searches, each proven again with the rank)
3612
- const share = (until - clock()) / 20, fresh = Object.keys(r.machine.maps ?? {}).length ? withDeadline(clock() + share, () => freshLaws(r.machine, r.kindLaws(), draws, { ms: share })) : [];
3717
+ const share = (until - clock()) / 20, fresh = Object.keys(r.machine.maps ?? {}).length ? withStageDeadline(clock() + share, () => freshLaws(r.machine, r.kindLaws(), draws, { ms: share }), () => []) : [];
3613
3718
  laws = [...laws, ...fresh.map(x => x.law)];
3614
3719
  let f = findLeadsTo(r.machine, withKinds(r, laws), l, { ...draws, rule: r }, { ms: until - clock() });
3615
3720
  // Where the rank fitted to the runs isn't the one: a rank of the rule's own terms (core/live.ts), in the time left.
@@ -3650,7 +3755,7 @@ export function refuteLeadsTo(r, laws, l, opts = {}) {
3650
3755
  // prover reads (the counted one inside a counted search): past it the verdict is unknown.
3651
3756
  export const proveDecision = (d, opts = {}) => {
3652
3757
  const go = () => (d.steps ? proveSteps(d.steps.rule, [], [d.steps.law], { search: false }) : goalsVerdict([d.goal]));
3653
- return translationVerdict(d.rule, [d.goal], opts.ms === undefined ? go() : withDeadline(clock() + opts.ms, go));
3758
+ return translationVerdict(d.rule, [d.goal], opts.ms === undefined ? go() : withStageDeadline(clock() + opts.ms, go, () => ({ proven: false, checked: false, stuck: 'unknown' })));
3654
3759
  };
3655
3760
  // A decision's callbacks against its condition, on random params and requests: `given` and `then` each run with every
3656
3761
  // value known, against what the interpreter evaluates of the decision built from them.
@@ -3685,15 +3790,15 @@ export function crossCheckDecision(d, opts = {}) {
3685
3790
  // usual trees, which are then its input and not checked again); where none is made, the usual trees, checked.
3686
3791
  export const proveLoop = (l, laws, opts = {}) => {
3687
3792
  if (l.hasRank) {
3688
- const t0 = performance.now(), goals = loopObligations(l.loop, laws, l.rankTerms), v = goalsVerdict(goals, !certOn());
3793
+ const t0 = countedSearchNow(), goals = loopObligations(l.loop, laws, l.rankTerms), v = goalsVerdict(goals, !certOn());
3689
3794
  if (!v.proven)
3690
3795
  return v;
3691
- const c = certLoop(l.loop, laws, l.rankTerms, v.trees, performance.now() - t0);
3796
+ const c = certLoop(l.loop, laws, l.rankTerms, v.trees, countedSearchNow() - t0);
3692
3797
  return c && !c.checked && certOn() ? { ...v, checked: goals.every(g => check(g, v.trees[g.name])) } : v;
3693
3798
  }
3694
- const t0 = performance.now(), out = findRank(l.loop, laws, opts);
3799
+ const t0 = countedSearchNow(), out = findRank(l.loop, laws, opts);
3695
3800
  if (out.proven && out.checked && out.rank && out.trees)
3696
- certLoop(l.loop, [...laws, ...(out.laws ?? [])], out.rank, out.trees, performance.now() - t0);
3801
+ certLoop(l.loop, [...laws, ...(out.laws ?? [])], out.rank, out.trees, countedSearchNow() - t0);
3697
3802
  return { proven: out.proven, checked: out.checked, ...(out.trees ? { trees: out.trees } : {}), ...(out.goal ? { goal: out.goal, stuck: out.stuck } : {}), ...(out.witness ? { witness: out.witness } : {}), ...(out.why ? { why: out.why } : {}),
3698
3803
  ...(out.found ? { found: { rank: out.found.rank, ...(out.laws?.length ? { laws: out.laws.map((law, i) => ({ law, text: out.found.laws[i] ?? law.name })) } : {}) } } : {}) };
3699
3804
  };
@@ -3821,7 +3926,7 @@ export const fold = (name) => new FoldRule({ name, params: [], inputs: [], pre:
3821
3926
  export const proveFold = (f, laws) => {
3822
3927
  // (by default the certificate a cyclic proof, core/cyclic.ts's certCyclic, the usual trees its input; where none is
3823
3928
  // made, the usual trees checked)
3824
- const all = [...(f.lemmas ?? []), ...laws], t0 = performance.now(), v = goalsVerdict(foldObligations(f.fold, all), !certOn()), usualMs = performance.now() - t0;
3929
+ const all = [...(f.lemmas ?? []), ...laws], t0 = countedSearchNow(), v = goalsVerdict(foldObligations(f.fold, all), !certOn()), usualMs = countedSearchNow() - t0;
3825
3930
  if (cyclicOn())
3826
3931
  crossCyclic('fold', f.fold.name, v.proven && v.checked, () => { const { facts, specs } = foldNodes(f.fold, all); return proveCyclic(facts, specs); }, usualMs, v.trees && (st => translatedProof(() => JSON.stringify(['fold', f.fold, all]), () => foldNodes(f.fold, all, v.trees, st), st)));
3827
3932
  if (certOn() && v.proven) {
@@ -0,0 +1 @@
1
+ export { withEvaluationAdmission } from './work-observe.js';
@@ -0,0 +1,3 @@
1
+ // Compatibility entry point. Every evaluator site now obtains its own
2
+ // exact lease; this wrapper cannot mint a second numeric credit bank.
3
+ export { withEvaluationAdmission } from "./work-observe.js";
@@ -1,4 +1,4 @@
1
- import { type C, type E, type Law, type Machine, type SomeWitness, type State } from './machine.js';
1
+ import { type C, type E, type Law, type Machine, type Request, type SomeWitness, type State } from './machine.js';
2
2
  import { type Report } from '../kernel/prove.js';
3
3
  import { type Ghosted } from '../kernel/kernel.js';
4
4
  type Env = Record<string, number>;
@@ -7,6 +7,11 @@ export declare const namesOf: (t: E | C) => string[];
7
7
  export declare function groupsOf(vars: string[]): Group[];
8
8
  export declare function substVarsE(e: E, s: Record<string, E>): E;
9
9
  export declare function substVars(c: C, s: Record<string, E>): C;
10
+ export declare function retainedSamplePath(state: State, visit: () => void): Request[] | undefined;
11
+ export declare function retainedSamples(m: Machine): readonly {
12
+ p: Env;
13
+ sts: readonly State[];
14
+ }[];
10
15
  export declare function small(m: Machine, p: Env, b: number, cap?: number, work?: number, walks?: number): State[];
11
16
  export declare function ghostOf(m: Machine, law: Law): SomeWitness | undefined;
12
17
  export declare function smallOf(m: Machine, source?: Machine): {