gdp-wired 0.48.0 → 0.50.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 (361) hide show
  1. package/README.md +6 -2
  2. package/dist/core/bmc.js +10 -7
  3. package/dist/core/candidate-seeds.d.ts +25 -0
  4. package/dist/core/candidate-seeds.js +90 -0
  5. package/dist/core/check.js +7 -2
  6. package/dist/core/cli.js +3 -0
  7. package/dist/core/count-attempt-work.d.ts +29 -0
  8. package/dist/core/count-attempt-work.js +96 -0
  9. package/dist/core/count-boolean-partition.d.ts +5 -0
  10. package/dist/core/count-boolean-partition.js +47 -0
  11. package/dist/core/count-bounded-quotient.d.ts +2 -0
  12. package/dist/core/count-bounded-quotient.js +13 -0
  13. package/dist/core/count-case-compose.d.ts +20 -0
  14. package/dist/core/count-case-compose.js +289 -0
  15. package/dist/core/count-cases.js +3 -2
  16. package/dist/core/count-cert-rename.d.ts +10 -0
  17. package/dist/core/count-cert-rename.js +69 -0
  18. package/dist/core/count-cert-transport.d.ts +10 -2
  19. package/dist/core/count-cert-transport.js +60 -9
  20. package/dist/core/count-certificate-minimize.d.ts +57 -0
  21. package/dist/core/count-certificate-minimize.js +263 -0
  22. package/dist/core/count-closed-family.d.ts +32 -0
  23. package/dist/core/count-closed-family.js +143 -0
  24. package/dist/core/count-closing-budget.d.ts +10 -0
  25. package/dist/core/count-closing-budget.js +49 -0
  26. package/dist/core/count-closing-needs.d.ts +5 -0
  27. package/dist/core/count-closing-needs.js +9 -0
  28. package/dist/core/count-component-budget.d.ts +5 -0
  29. package/dist/core/count-component-budget.js +9 -0
  30. package/dist/core/count-copy-shape.d.ts +11 -0
  31. package/dist/core/count-copy-shape.js +40 -0
  32. package/dist/core/count-disjoint-funding.d.ts +75 -0
  33. package/dist/core/count-disjoint-funding.js +284 -0
  34. package/dist/core/count-emitter-frame-pool.d.ts +23 -0
  35. package/dist/core/count-emitter-frame-pool.js +87 -0
  36. package/dist/core/count-final-step.d.ts +5 -0
  37. package/dist/core/count-final-step.js +20 -0
  38. package/dist/core/count-fixed-frame.d.ts +4 -0
  39. package/dist/core/count-fixed-frame.js +30 -0
  40. package/dist/core/count-frames.d.ts +25 -0
  41. package/dist/core/count-frames.js +118 -0
  42. package/dist/core/count-frozen-guard.d.ts +2 -0
  43. package/dist/core/count-frozen-guard.js +31 -0
  44. package/dist/core/count-generation-phase.d.ts +7 -0
  45. package/dist/core/count-generation-phase.js +33 -0
  46. package/dist/core/count-guard-composition.d.ts +12 -0
  47. package/dist/core/count-guard-composition.js +48 -0
  48. package/dist/core/count-guard-context.d.ts +11 -0
  49. package/dist/core/count-guard-context.js +50 -0
  50. package/dist/core/count-guard-facts.d.ts +50 -0
  51. package/dist/core/count-guard-facts.js +97 -0
  52. package/dist/core/count-guard-proposals.d.ts +7 -0
  53. package/dist/core/count-guard-proposals.js +106 -0
  54. package/dist/core/count-guard-shape.d.ts +18 -0
  55. package/dist/core/count-guard-shape.js +100 -0
  56. package/dist/core/count-guard-tree.d.ts +17 -0
  57. package/dist/core/count-guard-tree.js +125 -0
  58. package/dist/core/count-leader-facts.d.ts +10 -0
  59. package/dist/core/count-leader-facts.js +52 -0
  60. package/dist/core/count-leader.d.ts +10 -0
  61. package/dist/core/count-leader.js +331 -0
  62. package/dist/core/count-lemma-transport.d.ts +8 -0
  63. package/dist/core/count-lemma-transport.js +47 -0
  64. package/dist/core/count-lifted-budget.d.ts +54 -0
  65. package/dist/core/count-lifted-budget.js +97 -0
  66. package/dist/core/count-lifted-copy.d.ts +3 -0
  67. package/dist/core/count-lifted-copy.js +166 -0
  68. package/dist/core/count-lifted-increment.d.ts +3 -0
  69. package/dist/core/count-lifted-increment.js +146 -0
  70. package/dist/core/count-lifted-load.d.ts +5 -0
  71. package/dist/core/count-lifted-load.js +179 -0
  72. package/dist/core/count-lifted-prerequisite.d.ts +14 -0
  73. package/dist/core/count-lifted-prerequisite.js +53 -0
  74. package/dist/core/count-lifted-replacement.d.ts +3 -0
  75. package/dist/core/count-lifted-replacement.js +540 -0
  76. package/dist/core/count-lifted-shape.d.ts +63 -0
  77. package/dist/core/count-lifted-shape.js +115 -0
  78. package/dist/core/count-lifted-strategy.d.ts +7 -0
  79. package/dist/core/count-lifted-strategy.js +226 -0
  80. package/dist/core/count-lifted-transports.d.ts +32 -0
  81. package/dist/core/count-lifted-transports.js +293 -0
  82. package/dist/core/count-load-shape.d.ts +17 -0
  83. package/dist/core/count-load-shape.js +67 -0
  84. package/dist/core/count-minimal-view.d.ts +26 -0
  85. package/dist/core/count-minimal-view.js +46 -0
  86. package/dist/core/count-operation-observation.d.ts +9 -0
  87. package/dist/core/count-operation-observation.js +22 -0
  88. package/dist/core/count-operation-order.d.ts +5 -0
  89. package/dist/core/count-operation-order.js +4 -0
  90. package/dist/core/count-phase.d.ts +9 -0
  91. package/dist/core/count-phase.js +127 -0
  92. package/dist/core/count-premise-search.d.ts +9 -0
  93. package/dist/core/count-premise-search.js +41 -0
  94. package/dist/core/count-premise-view.d.ts +19 -0
  95. package/dist/core/count-premise-view.js +220 -0
  96. package/dist/core/count-prerequisite-components.d.ts +67 -0
  97. package/dist/core/count-prerequisite-components.js +239 -0
  98. package/dist/core/count-prerequisite-memory.d.ts +24 -0
  99. package/dist/core/count-prerequisite-memory.js +37 -0
  100. package/dist/core/count-prerequisite-plan.d.ts +12 -0
  101. package/dist/core/count-prerequisite-plan.js +88 -0
  102. package/dist/core/count-primitive-budget.d.ts +1 -0
  103. package/dist/core/count-primitive-budget.js +8 -0
  104. package/dist/core/count-project-free.d.ts +3 -0
  105. package/dist/core/count-project-free.js +24 -0
  106. package/dist/core/count-project-witness.d.ts +4 -0
  107. package/dist/core/count-project-witness.js +48 -0
  108. package/dist/core/count-proof-rescope.d.ts +14 -0
  109. package/dist/core/count-proof-rescope.js +71 -0
  110. package/dist/core/count-proof-scope.d.ts +68 -0
  111. package/dist/core/count-proof-scope.js +333 -0
  112. package/dist/core/count-prune-owned-root.d.ts +5 -0
  113. package/dist/core/count-prune-owned-root.js +27 -0
  114. package/dist/core/count-query-context.d.ts +3 -0
  115. package/dist/core/count-query-context.js +7 -0
  116. package/dist/core/count-query.d.ts +15 -0
  117. package/dist/core/count-query.js +59 -0
  118. package/dist/core/count-quorum-leaf.d.ts +9 -0
  119. package/dist/core/count-quorum-leaf.js +38 -0
  120. package/dist/core/count-reachability-budget.d.ts +1 -0
  121. package/dist/core/count-reachability-budget.js +7 -0
  122. package/dist/core/count-reachability-reconcile.d.ts +11 -0
  123. package/dist/core/count-reachability-reconcile.js +19 -0
  124. package/dist/core/count-reachability.d.ts +50 -0
  125. package/dist/core/count-reachability.js +351 -0
  126. package/dist/core/count-rebase-path.d.ts +9 -0
  127. package/dist/core/count-rebase-path.js +68 -0
  128. package/dist/core/count-recipe-context.d.ts +45 -0
  129. package/dist/core/count-recipe-context.js +71 -0
  130. package/dist/core/count-recipe-controller.d.ts +115 -0
  131. package/dist/core/count-recipe-controller.js +417 -0
  132. package/dist/core/count-recipe-graph.d.ts +36 -0
  133. package/dist/core/count-recipe-graph.js +211 -0
  134. package/dist/core/count-recovery/conditional-check-cache.js +3 -2
  135. package/dist/core/count-recovery/conditional-cuts.js +5 -4
  136. package/dist/core/count-recovery/conditional-proof.d.ts +37 -3
  137. package/dist/core/count-recovery/conditional-proof.js +72 -30
  138. package/dist/core/count-recovery/derivability-closure.js +2 -1
  139. package/dist/core/count-recovery/guard-cases.js +2 -1
  140. package/dist/core/count-recovery/reframe-tree.d.ts +2 -0
  141. package/dist/core/count-recovery/reframe-tree.js +24 -0
  142. package/dist/core/count-recovery/replay-linear-skeleton.d.ts +2 -0
  143. package/dist/core/count-recovery/replay-linear-skeleton.js +28 -0
  144. package/dist/core/count-recovery/row-cases.js +2 -1
  145. package/dist/core/count-rejection-budget.d.ts +8 -0
  146. package/dist/core/count-rejection-budget.js +15 -0
  147. package/dist/core/count-replacement.d.ts +5 -0
  148. package/dist/core/count-replacement.js +129 -0
  149. package/dist/core/count-replay-diagnostic.d.ts +21 -0
  150. package/dist/core/count-replay-diagnostic.js +49 -0
  151. package/dist/core/count-replay-skeleton.d.ts +4 -0
  152. package/dist/core/count-replay-skeleton.js +28 -0
  153. package/dist/core/count-rescope-funding.d.ts +3 -0
  154. package/dist/core/count-rescope-funding.js +17 -0
  155. package/dist/core/count-restrictions.d.ts +11 -0
  156. package/dist/core/count-restrictions.js +31 -0
  157. package/dist/core/count-retry-budget.d.ts +67 -0
  158. package/dist/core/count-retry-budget.js +114 -0
  159. package/dist/core/count-retry-round.d.ts +24 -0
  160. package/dist/core/count-retry-round.js +44 -0
  161. package/dist/core/count-row-agreement.d.ts +35 -0
  162. package/dist/core/count-row-agreement.js +270 -0
  163. package/dist/core/count-row-aliases.d.ts +3 -0
  164. package/dist/core/count-row-aliases.js +59 -0
  165. package/dist/core/count-row-composition.d.ts +6 -0
  166. package/dist/core/count-row-composition.js +55 -0
  167. package/dist/core/count-row-copy-linear.d.ts +4 -0
  168. package/dist/core/count-row-copy-linear.js +83 -0
  169. package/dist/core/count-row-copy.d.ts +4 -0
  170. package/dist/core/count-row-copy.js +94 -0
  171. package/dist/core/count-row-policy.d.ts +3 -0
  172. package/dist/core/count-row-policy.js +56 -0
  173. package/dist/core/count-row-reindex.d.ts +11 -0
  174. package/dist/core/count-row-reindex.js +126 -0
  175. package/dist/core/count-row-support.d.ts +9 -0
  176. package/dist/core/count-row-support.js +42 -0
  177. package/dist/core/count-row-symmetry.d.ts +7 -0
  178. package/dist/core/count-row-symmetry.js +100 -0
  179. package/dist/core/count-scope-hyps.d.ts +2 -0
  180. package/dist/core/count-scope-hyps.js +163 -0
  181. package/dist/core/count-scope-row-reuse.d.ts +3 -0
  182. package/dist/core/count-scope-row-reuse.js +92 -0
  183. package/dist/core/count-search-allowance.d.ts +1 -0
  184. package/dist/core/count-search-allowance.js +17 -0
  185. package/dist/core/count-stabilize-tree.d.ts +9 -0
  186. package/dist/core/count-stabilize-tree.js +35 -0
  187. package/dist/core/count-stage-trace.d.ts +8 -0
  188. package/dist/core/count-stage-trace.js +45 -0
  189. package/dist/core/count-strategies.d.ts +16 -0
  190. package/dist/core/count-strategies.js +155 -0
  191. package/dist/core/count-strategy-premises.d.ts +5 -0
  192. package/dist/core/count-strategy-premises.js +14 -0
  193. package/dist/core/count-strategy.d.ts +41 -0
  194. package/dist/core/count-strategy.js +76 -0
  195. package/dist/core/count-support.d.ts +1 -0
  196. package/dist/core/count-support.js +26 -4
  197. package/dist/core/count-tier-budget.d.ts +14 -0
  198. package/dist/core/count-tier-budget.js +64 -0
  199. package/dist/core/count-unwritten-prefix.d.ts +24 -0
  200. package/dist/core/count-unwritten-prefix.js +97 -0
  201. package/dist/core/count-write-shape.d.ts +15 -0
  202. package/dist/core/count-write-shape.js +73 -0
  203. package/dist/core/counted-candidate-seeds.d.ts +12 -0
  204. package/dist/core/counted-candidate-seeds.js +31 -0
  205. package/dist/core/counts.d.ts +37 -13
  206. package/dist/core/counts.js +999 -129
  207. package/dist/core/cycles.js +5 -4
  208. package/dist/core/cyclic.js +11 -10
  209. package/dist/core/data.js +16 -15
  210. package/dist/core/dsl-deadline.d.ts +3 -0
  211. package/dist/core/dsl-deadline.js +27 -0
  212. package/dist/core/dsl.d.ts +32 -2
  213. package/dist/core/dsl.js +202 -64
  214. package/dist/core/evaluation-admission.d.ts +1 -0
  215. package/dist/core/evaluation-admission.js +3 -0
  216. package/dist/core/exists.d.ts +6 -1
  217. package/dist/core/exists.js +53 -10
  218. package/dist/core/field-laws.d.ts +3 -1
  219. package/dist/core/field-laws.js +159 -3
  220. package/dist/core/finite-houdini.d.ts +6 -0
  221. package/dist/core/finite-houdini.js +63 -21
  222. package/dist/core/finite-tiny.js +95 -67
  223. package/dist/core/fixtures/count-completion/paxos-decision.json +1 -0
  224. package/dist/core/fresh.js +5 -1
  225. package/dist/core/infer.js +49 -33
  226. package/dist/core/kind.js +2 -1
  227. package/dist/core/lemma-cuts.js +11 -10
  228. package/dist/core/lift-cli.d.ts +11 -0
  229. package/dist/core/lift-cli.js +113 -0
  230. package/dist/core/linear-admission.d.ts +14 -0
  231. package/dist/core/linear-admission.js +151 -0
  232. package/dist/core/machine.d.ts +5 -2
  233. package/dist/core/machine.js +105 -31
  234. package/dist/core/meter.d.ts +22 -0
  235. package/dist/core/meter.js +34 -0
  236. package/dist/core/nonterm.js +4 -3
  237. package/dist/core/proof-output.d.ts +53 -0
  238. package/dist/core/proof-output.js +38 -0
  239. package/dist/core/prover-row-budget.d.ts +3 -0
  240. package/dist/core/prover-row-budget.js +106 -0
  241. package/dist/core/quorum-laws.d.ts +21 -1
  242. package/dist/core/quorum-laws.js +80 -17
  243. package/dist/core/rationals.js +3 -2
  244. package/dist/core/rejection-discovery.d.ts +34 -0
  245. package/dist/core/rejection-discovery.js +36 -0
  246. package/dist/core/rejection-stage.d.ts +39 -0
  247. package/dist/core/rejection-stage.js +205 -0
  248. package/dist/core/request-quotient.d.ts +8 -0
  249. package/dist/core/request-quotient.js +299 -0
  250. package/dist/core/row-agreement-shape.d.ts +15 -0
  251. package/dist/core/row-agreement-shape.js +68 -0
  252. package/dist/core/runtime-wall.d.ts +2 -0
  253. package/dist/core/search-policy.d.ts +15 -0
  254. package/dist/core/search-policy.js +68 -0
  255. package/dist/core/solver.d.ts +1 -1
  256. package/dist/core/solver.js +40 -6
  257. package/dist/core/step-work.d.ts +12 -0
  258. package/dist/core/step-work.js +14 -0
  259. package/dist/core/strategy-premises.d.ts +8 -0
  260. package/dist/core/strategy-premises.js +64 -0
  261. package/dist/core/system.js +4 -3
  262. package/dist/core/table-admission.d.ts +1 -0
  263. package/dist/core/table-admission.js +3 -0
  264. package/dist/core/trace-clock.d.ts +3 -0
  265. package/dist/core/trace-clock.js +16 -0
  266. package/dist/core/transfer.js +3 -2
  267. package/dist/core/translate.js +16 -3
  268. package/dist/core/wall.d.ts +6 -1
  269. package/dist/core/wall.js +23 -9
  270. package/dist/core/watch.d.ts +1 -1
  271. package/dist/core/watch.js +13 -4
  272. package/dist/core/work-admission.d.ts +164 -0
  273. package/dist/core/work-admission.js +418 -0
  274. package/dist/core/work-amount.d.ts +21 -0
  275. package/dist/core/work-amount.js +80 -0
  276. package/dist/core/work-collections.d.ts +11 -0
  277. package/dist/core/work-collections.js +198 -0
  278. package/dist/core/work-kinds.d.ts +11 -0
  279. package/dist/core/work-kinds.js +9 -0
  280. package/dist/core/work-meter.d.ts +8 -0
  281. package/dist/core/work-meter.js +83 -0
  282. package/dist/core/work-observe.d.ts +12 -0
  283. package/dist/core/work-observe.js +39 -0
  284. package/dist/core/work-profile.d.ts +10 -0
  285. package/dist/core/work-profile.js +21 -0
  286. package/dist/core/work-refusal.d.ts +1 -0
  287. package/dist/core/work-refusal.js +6 -0
  288. package/dist/interchange/format.js +2 -0
  289. package/dist/kernel/cdcl.js +93 -40
  290. package/dist/kernel/epr.js +23 -8
  291. package/dist/kernel/function-instances.d.ts +45 -0
  292. package/dist/kernel/function-instances.js +460 -0
  293. package/dist/kernel/kernel.d.ts +47 -1
  294. package/dist/kernel/kernel.js +417 -68
  295. package/dist/kernel/prove.d.ts +61 -6
  296. package/dist/kernel/prove.js +625 -205
  297. package/dist/kernel/prover-rows.d.ts +1 -0
  298. package/dist/kernel/prover-rows.js +12 -1
  299. package/dist/kernel/reader.d.ts +1 -1
  300. package/dist/kernel/reader.js +57 -12
  301. package/dist/kernel/simplex.js +9 -2
  302. package/dist/lean-kernel/axiom-audit.d.ts +11 -0
  303. package/dist/lean-kernel/axiom-audit.js +50 -0
  304. package/dist/lean-kernel/emit.d.ts +34 -3
  305. package/dist/lean-kernel/emit.js +215 -28
  306. package/dist/lean-kernel/legacy-family-library.d.ts +1 -0
  307. package/dist/lean-kernel/legacy-family-library.js +5 -0
  308. package/dist/lean-kernel/legacy-family-order.d.ts +1 -0
  309. package/dist/lean-kernel/legacy-family-order.js +26 -0
  310. package/dist/lean-kernel/library.js +25 -3
  311. package/dist/lean-kernel/lift/counted-source-data.d.ts +7 -0
  312. package/dist/lean-kernel/lift/counted-source-data.js +78 -0
  313. package/dist/lean-kernel/lift/index.d.ts +82 -0
  314. package/dist/lean-kernel/lift/index.js +116 -0
  315. package/dist/lean-kernel/lift/project.d.ts +4 -0
  316. package/dist/lean-kernel/lift/project.js +15 -0
  317. package/dist/lean-kernel/lift/proof-capture.d.ts +104 -0
  318. package/dist/lean-kernel/lift/proof-capture.js +216 -0
  319. package/dist/lean-kernel/lift/proof-codec.d.ts +28 -0
  320. package/dist/lean-kernel/lift/proof-codec.js +299 -0
  321. package/dist/lean-kernel/lift/proof-counted-source.d.ts +16 -0
  322. package/dist/lean-kernel/lift/proof-counted-source.js +68 -0
  323. package/dist/lean-kernel/lift/proof-frontier.d.ts +19 -0
  324. package/dist/lean-kernel/lift/proof-frontier.js +153 -0
  325. package/dist/lean-kernel/lift/proof-graph.d.ts +17 -0
  326. package/dist/lean-kernel/lift/proof-graph.js +130 -0
  327. package/dist/lean-kernel/lift/proof-parts.d.ts +29 -0
  328. package/dist/lean-kernel/lift/proof-parts.js +131 -0
  329. package/dist/lean-kernel/lift/proof-prelude.d.ts +2 -0
  330. package/dist/lean-kernel/lift/proof-prelude.js +38 -0
  331. package/dist/lean-kernel/lift/proof-witness.d.ts +30 -0
  332. package/dist/lean-kernel/lift/proof-witness.js +283 -0
  333. package/dist/lean-kernel/lift/shape.d.ts +5 -0
  334. package/dist/lean-kernel/lift/shape.js +57 -0
  335. package/dist/lean-kernel/lift/source-projection.d.ts +16 -0
  336. package/dist/lean-kernel/lift/source-projection.js +81 -0
  337. package/dist/lean-kernel/lift/source.d.ts +23 -0
  338. package/dist/lean-kernel/lift/source.js +111 -0
  339. package/dist/lean-kernel/lift/witness-alpha.d.ts +9 -0
  340. package/dist/lean-kernel/lift/witness-alpha.js +31 -0
  341. package/dist/lean-kernel/lift-legacy.d.ts +58 -0
  342. package/dist/lean-kernel/lift-legacy.js +84 -0
  343. package/dist/lean-kernel/lift-names.d.ts +22 -0
  344. package/dist/lean-kernel/lift-names.js +36 -0
  345. package/dist/lean-kernel/lift-simulation/index.d.ts +29 -0
  346. package/dist/lean-kernel/lift-simulation/index.js +352 -0
  347. package/dist/lean-kernel/lift-simulation/shape.d.ts +41 -0
  348. package/dist/lean-kernel/lift-simulation/shape.js +173 -0
  349. package/dist/lean-kernel/lift-special/index.d.ts +36 -0
  350. package/dist/lean-kernel/lift-special/index.js +241 -0
  351. package/dist/lean-kernel/lift-special/structural.d.ts +25 -0
  352. package/dist/lean-kernel/lift-special/structural.js +126 -0
  353. package/dist/lean-kernel/lift-typed/index.d.ts +35 -0
  354. package/dist/lean-kernel/lift-typed/index.js +256 -0
  355. package/dist/lean-kernel/lift-typed/roles.d.ts +17 -0
  356. package/dist/lean-kernel/lift-typed/roles.js +170 -0
  357. package/dist/lean-kernel/lift-typed/shape.d.ts +1 -0
  358. package/dist/lean-kernel/lift-typed/shape.js +12 -0
  359. package/dist/lean-kernel/lift.d.ts +30 -0
  360. package/dist/lean-kernel/lift.js +97 -0
  361. package/package.json +5 -1
@@ -1,3 +1,7 @@
1
+ import { retainFrom } from "./proof-output.js";
2
+ import { traceNow as countedTraceNow, BudgetExpired } from "./wall.js";
3
+ import { withReachabilityWork, reachState, reachEdge } from "./work-observe.js";
4
+ import { requestQuotient } from "./request-quotient.js";
1
5
  // There exists: a law ∃ x. P(x) (core/machine.ts's Law with `some`: x a natural, or an integer as two, x and x$neg),
2
6
  // proven through a witness. Nothing here is trusted: the kernel proves a plain law of a plain machine, and the Lean
3
7
  // export states the existential again, proven by ⟨witness, proof⟩ (lean-kernel/Ghost.lean's some_updAll).
@@ -18,7 +22,7 @@ import { carriedView, compileC, evalC, evalE, fastStep, interpret, n as k, walk,
18
22
  import { clock, proveLaw, proveLaws, withDeadline, withinDeadline } from "../kernel/prove.js";
19
23
  import { env } from "./solver.js";
20
24
  import { WallExpired, checkWall } from "./wall.js";
21
- import { ghostedMachine, ghostedOk, substC } from "../kernel/kernel.js";
25
+ import { finiteLawBound, ghostedMachine, ghostedOk, substC } from "../kernel/kernel.js";
22
26
  const add = (a, b) => (a.op === 'const' && a.value === 0 ? b : b.op === 'const' && b.value === 0 ? a : { op: 'add', a, b });
23
27
  const sum = (es) => es.reduce((acc, e) => add(acc, e), k(0));
24
28
  const sub = (a, b) => (b.op === 'const' && b.value === 0 ? a : { op: 'sub', a, b });
@@ -166,13 +170,34 @@ const atomsOf2 = (c) => (c.op === 'and' || c.op === 'or' ? c.xs.flatMap(atomsOf2
166
170
  // alike among those a few requests make: an action the BFS's levels never reach, a leader past a majority's votes, is
167
171
  // taken as often as any other. Each state's step from the state it was first reached from is kept: `pathTo`.)
168
172
  const pathTo = new WeakMap();
173
+ // Search hints only. A caller must replay this path on its original machine;
174
+ // an unrelated state with no cached parent must never be trusted as an init.
175
+ export function retainedSamplePath(state, visit) {
176
+ const requests = [], seen = new Set();
177
+ for (let at = state;;) {
178
+ visit();
179
+ if (seen.has(at))
180
+ return undefined;
181
+ seen.add(at);
182
+ const from = pathTo.get(at);
183
+ if (!from)
184
+ return requests.reverse();
185
+ requests.push(from[1]);
186
+ at = from[0];
187
+ }
188
+ }
189
+ export function retainedSamples(m) { return smalls.get(m) ?? []; }
169
190
  export function small(m, p, b, cap = 3000, work = 300_000, walks = 0) {
191
+ return withReachabilityWork(() => smallWithin(m, p, b, cap, work, walks));
192
+ }
193
+ function smallWithin(m, p, b, cap, work, walks) {
194
+ reachState();
170
195
  // (past a thousand steps, through the generated JavaScript, fastStep: the interpreter's states, as compile.test.ts holds
171
196
  // them; a small machine's few steps cost less than its compiling)
172
197
  checkWall('sample setup');
173
198
  const run = interpret(m), start = run.init(p);
174
199
  let steps = 0, fast = run.step;
175
- const step = (p2, st, r) => { if (++steps === 1000)
200
+ const step = (p2, st, r) => { reachEdge(); if (++steps === 1000)
176
201
  fast = fastStep(m) ?? run.step; return fast(p2, st, r); };
177
202
  const subsets = Array.from({ length: 1 << b }, (_, s) => new Map(Array.from({ length: b }, (_, i) => i).filter(i => (s >> i) & 1).map(i => [i, 1])));
178
203
  // (an input the assumption keeps below a few values, an action's, over all of them; the rest below b)
@@ -182,6 +207,7 @@ export function small(m, p, b, cap = 3000, work = 300_000, walks = 0) {
182
207
  reqs = reqs.flatMap(r => Array.from({ length: below(i) }, (_, x) => ({ ...r, [i]: x })));
183
208
  for (const c of m.inputMaps ?? [])
184
209
  reqs = reqs.flatMap(r => subsets.map(s => ({ ...r, [c]: s })));
210
+ const quotient = env.GDP_REQUEST_QUOTIENT === '1' ? requestQuotient(m, reqs) : undefined;
185
211
  // (a state once: by a hash of its scalars and nonzero cells, then a cell-by-cell comparison within the hash's bucket;
186
212
  // the same classes as a sorted text of the state, without a sort or a text per step)
187
213
  const scalarNames = Object.keys(start.scalars), mapNames = Object.keys(start.maps);
@@ -219,23 +245,32 @@ export function small(m, p, b, cap = 3000, work = 300_000, walks = 0) {
219
245
  }
220
246
  else
221
247
  seen.set(h, [next]);
248
+ reachState();
222
249
  all.push(next);
223
250
  pathTo.set(next, [from, r]);
224
251
  return next;
225
252
  };
226
253
  while (queue.length && all.length < cap && work > 0) {
227
- const st = queue.shift();
254
+ const st = queue.shift(), covered = quotient ? new Set() : undefined;
255
+ let requestIndex = 0;
228
256
  for (const r of reqs) {
229
257
  checkWall('sample BFS');
230
258
  if (--work < 0)
231
259
  break;
260
+ const cls = quotient?.classes[requestIndex++];
261
+ if (cls !== undefined && covered.has(cls))
262
+ continue;
232
263
  let next;
233
264
  try {
234
265
  next = step(p, st, r);
235
266
  }
236
- catch {
267
+ catch (error) {
268
+ if (error instanceof BudgetExpired)
269
+ throw error;
237
270
  continue;
238
271
  }
272
+ if (cls !== undefined)
273
+ covered.add(cls);
239
274
  const n0 = all.length;
240
275
  if (reached(next, st, r) && all.length > n0)
241
276
  queue.push(next);
@@ -259,7 +294,9 @@ export function small(m, p, b, cap = 3000, work = 300_000, walks = 0) {
259
294
  try {
260
295
  next = step(p, st, r);
261
296
  }
262
- catch {
297
+ catch (error) {
298
+ if (error instanceof BudgetExpired)
299
+ throw error;
263
300
  continue;
264
301
  }
265
302
  const kd = kindOf(st, next);
@@ -360,6 +397,10 @@ export function trueSmall(m, laws, ghosted) {
360
397
  const views = new WeakMap();
361
398
  const sampleTests = new WeakMap();
362
399
  export function holdsAt(m, law, p, st, b) {
400
+ return withReachabilityWork(() => holdsAtWithin(m, law, p, st, b));
401
+ }
402
+ function holdsAtWithin(m, law, p, st, b) {
403
+ const finite = finiteLawBound(law);
363
404
  let machineViews = views.get(m);
364
405
  if (!machineViews)
365
406
  views.set(m, (machineViews = new WeakMap()));
@@ -368,6 +409,8 @@ export function holdsAt(m, law, p, st, b) {
368
409
  const empty = Object.fromEntries((m.inputMaps ?? []).map(c => [c, new Map()]));
369
410
  machineViews.set(st, (view = carriedView(m, st, empty, undefined, p)));
370
411
  }
412
+ if (finite)
413
+ return evalC({ op: 'all', key: law.forall, c: law.holds, finite: law.finite }, p, view, m);
371
414
  let tests = sampleTests.get(m);
372
415
  if (!tests)
373
416
  sampleTests.set(m, (tests = new WeakMap()));
@@ -1233,12 +1276,12 @@ export function proveSome(m, laws, opts = {}) {
1233
1276
  firstPicks.set(key([m.step, m.assume ?? null, m.maps ?? null, p.law.holds]), pk.mode === 'map' ? { mode: 'map', at: pk.at } : { mode: 'term', at: [...pk.at] });
1234
1277
  }
1235
1278
  for (let round = 0;; round++) {
1236
- const now = current(), t0 = performance.now(), r = round === 0 && first ? { proven: false, ...first }
1279
+ const now = current(), t0 = countedTraceNow(), r = round === 0 && first ? { proven: false, ...first }
1237
1280
  // (a ghost map's goals within 2 s: a search asks them with every candidate set, and one without its supports can take
1238
1281
  // minutes; `mapMs` where the supports are the search's, found over the same map)
1239
1282
  : p.pick.mode === 'map' ? withDeadline(clock() + (opts.mapMs ?? 2_000), () => proveLaw(now.machine, now.laws, i)) : proveLaw(now.machine, now.laws, i);
1240
1283
  if (log)
1241
- console.error(`exists: pass ${pass} round ${round} "${p.law.name}" ${p.pick.mode} ${describe(p, cases).slice(0, 160)}: ${r.proven ? 'proven' : `${r.goal} ${r.stuck}`} (${Math.round(performance.now() - t0)} ms)`);
1284
+ console.error(`exists: pass ${pass} round ${round} "${p.law.name}" ${p.pick.mode} ${describe(p, cases).slice(0, 160)}: ${r.proven ? 'proven' : `${r.goal} ${r.stuck}`} (${Math.round(countedTraceNow() - t0)} ms)`);
1242
1285
  if (r.proven)
1243
1286
  return undefined;
1244
1287
  const fail = (stuck) => ({ proven: false, nodes: 0, leaves: 0, checked: false, failed: { goal: r.goal, stuck, ...(r.witness ? { witness: r.witness } : {}) } });
@@ -1321,10 +1364,10 @@ export function proveSome(m, laws, opts = {}) {
1321
1364
  return f;
1322
1365
  }
1323
1366
  for (let pass = 1;; pass++) {
1324
- const { machine, laws: plain, ghosts } = current(), t0 = performance.now();
1325
- const out = (opts.whole ?? proveLaws)(machine, plain), done = { ...out, laws: out.laws ?? plain, machine, ghosts, witnesses: Object.fromEntries([...plans.values()].map(p => [p.law.name, describe(p, cases)])) };
1367
+ const { machine, laws: plain, ghosts } = current(), t0 = countedTraceNow();
1368
+ const out = (opts.whole ?? proveLaws)(machine, plain), done = retainFrom({ ...out, laws: out.laws ?? plain, machine, ghosts, witnesses: Object.fromEntries([...plans.values()].map(p => [p.law.name, describe(p, cases)])) }, [out], { kind: 'witness', original: m, laws, machine, plain, ghosts, plans, cases });
1326
1369
  if (log)
1327
- console.error(`exists: pass ${pass} the whole set: ${out.proven ? 'proven' : `${out.failed?.goal} ${out.failed?.stuck}`} (${Math.round(performance.now() - t0)} ms)`);
1370
+ console.error(`exists: pass ${pass} the whole set: ${out.proven ? 'proven' : `${out.failed?.goal} ${out.failed?.stuck}`} (${Math.round(countedTraceNow() - t0)} ms)`);
1328
1371
  const j = out.proven || !out.failed || pass > 8 ? undefined : [...plans.keys()].find(k => out.failed.goal.startsWith(`${laws[k].name} @`));
1329
1372
  if (j === undefined)
1330
1373
  return done;
@@ -1,2 +1,4 @@
1
1
  import { type Law, type Machine } from './machine.js';
2
- export declare function fieldLaws(m: Machine, composed?: boolean): Law[];
2
+ export declare const weakensField: WeakMap<Law, Law>;
3
+ export declare function selectFieldLaws(laws: Law[], admit: (law: Law) => boolean): Law[];
4
+ export declare function fieldLaws(m: Machine, composed?: boolean, loaded?: boolean): Law[];
@@ -3,7 +3,24 @@
3
3
  // Propose their shapes, not facts: counts.ts filters on reachable samples, and the
4
4
  // ordinary counted induction/checker must prove every surviving candidate.
5
5
  import { all, any, atMost, get, less, n, not, same, times, plus, tuple, walk, x } from "./machine.js";
6
- export function fieldLaws(m, composed = true) {
6
+ // A guarded form and the stronger candidate it weakens; the guarded one is admitted only when the stronger is not.
7
+ export const weakensField = new WeakMap();
8
+ const loadFieldFamily = new WeakMap();
9
+ // Prefer the unguarded load, otherwise the first admitted singleton guard.
10
+ // Older field families retain their order and admission behavior.
11
+ export function selectFieldLaws(laws, admit) {
12
+ const kept = new Set(), selectedLoads = new Set();
13
+ return laws.filter(law => {
14
+ const stronger = weakensField.get(law), load = loadFieldFamily.get(law);
15
+ if ((stronger && kept.has(stronger)) || (load && selectedLoads.has(load)) || !admit(law))
16
+ return false;
17
+ kept.add(law);
18
+ if (load)
19
+ selectedLoads.add(load);
20
+ return true;
21
+ });
22
+ }
23
+ export function fieldLaws(m, composed = true, loaded = true) {
7
24
  const fields = new Set(), roles = new Map(), bounds = new Map();
8
25
  const maps = m.maps ?? {}, source = [m.assume, m.step.flags];
9
26
  const direct = (e) => e.op === 'get' && e.key.op === 'var' && e.map in maps;
@@ -87,14 +104,153 @@ export function fieldLaws(m, composed = true) {
87
104
  const old = rows.get(o.map);
88
105
  rows.set(o.map, old === undefined || old === key.a.k ? key.a.k : 0);
89
106
  });
107
+ // Zero is reserved for ambiguous packed strides; -1 denotes a native tuple.
108
+ for (const [map, sorts] of Object.entries(m.relations ?? {}))
109
+ if (sorts.length === 2 && sorts[0] === sorts[1])
110
+ rows.set(map, -1);
111
+ const agrees = [];
90
112
  for (const [map, base] of rows)
91
113
  if (base)
92
114
  for (let i = 0; i < fs.length; i++)
93
115
  for (let j = i + 1; j < fs.length; j++) {
94
- const f = fs[i], g = fs[j], cell = (row) => get(map, plus(times(base, row), c));
116
+ const f = fs[i], g = fs[j], cell = (row) => get(map, base === -1 ? tuple([row, c]) : plus(times(base, row), c));
95
117
  const guard = all(da, db, less(c, bound), same(get(f, a), get(f, b)), same(get(g, a), get(g, b)));
96
- out.push({ name: `fields: ${f}[a]=${f}[b] and ${g}[a]=${g}[b] -> ${map} rows agree`, forall: ka, keys: [kb, kc], holds: any(not(guard), same(cell(a), cell(b))) });
118
+ const law = { name: `fields: ${f}[a]=${f}[b] and ${g}[a]=${g}[b] -> ${map} rows agree`, forall: ka, keys: [kb, kc], holds: any(not(guard), same(cell(a), cell(b))) };
119
+ // Tuple agreement was already emitted above; use that same stronger law.
120
+ const existing = base === -1 ? out.find(l => l.name === law.name) : undefined;
121
+ if (!existing)
122
+ out.push(law);
123
+ agrees.push({ map, f, g, law: existing ?? law });
97
124
  }
125
+ if (!loaded)
126
+ return out;
127
+ const node = (t) => !!t && typeof t === 'object' && !Array.isArray(t);
128
+ const atoms = (t) => !t ? [] : t.op === 'and' ? t.xs.flatMap(atoms) : [t];
129
+ const sameTerm = (a, b) => JSON.stringify(a) === JSON.stringify(b);
130
+ const restrictCondition = (condition, flag, value) => {
131
+ if (condition.op === 'flag')
132
+ return condition.name === flag ? value : condition;
133
+ if (condition.op === 'not') {
134
+ const inner = restrictCondition(condition.x, flag, value);
135
+ return typeof inner === 'boolean' ? !inner : not(inner);
136
+ }
137
+ if (condition.op === 'and' || condition.op === 'or') {
138
+ const parts = condition.xs.map(c => restrictCondition(c, flag, value)), conjunction = condition.op === 'and';
139
+ if (parts.includes(!conjunction))
140
+ return !conjunction;
141
+ const rest = parts.filter((c) => typeof c !== 'boolean');
142
+ return !rest.length ? conjunction : rest.length === 1 ? rest[0] : conjunction ? all(...rest) : any(...rest);
143
+ }
144
+ if ((condition.op === '=' || condition.op === '<' || condition.op === '<=') && condition.a.op === 'const' && condition.b.op === 'const') {
145
+ return condition.op === '=' ? condition.a.value === condition.b.value : condition.op === '<' ? condition.a.value < condition.b.value : condition.a.value <= condition.b.value;
146
+ }
147
+ return condition;
148
+ };
149
+ const restrictValue = (value, flag, active) => {
150
+ if (value.op !== 'if')
151
+ return value;
152
+ const condition = restrictCondition(value.c, flag, active);
153
+ if (typeof condition === 'boolean')
154
+ return restrictValue(condition ? value.then : value.else, flag, active);
155
+ return { ...value, c: condition, then: restrictValue(value.then, flag, active), else: restrictValue(value.else, flag, active) };
156
+ };
157
+ const markerValue = (value, map, key, flag) => {
158
+ const active = restrictValue(value, flag, true), inactive = restrictValue(value, flag, false);
159
+ if (active.op !== 'const' || !Number.isSafeInteger(active.value) || active.value < 1)
160
+ return undefined;
161
+ const old = get(map, key), v = active.value;
162
+ if (sameTerm(inactive, old) || inactive.op === 'const' && inactive.value !== v)
163
+ return v;
164
+ // Boolean maps compile a preserved cell as if old=1 then 1 else 0.
165
+ // This cannot manufacture a marker outside the load branch.
166
+ if (inactive.op === 'if' && inactive.c.op === '=' && inactive.then.op === 'const' && inactive.then.value === v
167
+ && inactive.else.op === 'const' && inactive.else.value !== v
168
+ && (sameTerm(inactive.c, same(old, n(v))) || sameTerm(inactive.c, same(n(v), old))))
169
+ return v;
170
+ return undefined;
171
+ };
172
+ const emitted = new Map();
173
+ const add = (law) => {
174
+ const key = JSON.stringify(law.holds), old = emitted.get(key);
175
+ if (old)
176
+ return old;
177
+ emitted.set(key, law);
178
+ out.push(law);
179
+ return law;
180
+ };
181
+ for (const [map, base] of rows) {
182
+ const w = m.step.maps?.[map];
183
+ if (!base || !w || !('each' in w))
184
+ continue;
185
+ const loads = new Map();
186
+ const visit = (t, positive) => {
187
+ if (Array.isArray(t)) {
188
+ for (const u of t)
189
+ visit(u, positive);
190
+ return;
191
+ }
192
+ if (!node(t) || t.op === 'not')
193
+ return;
194
+ if (t.op === 'if') {
195
+ const branch = [...positive, ...atoms(t.c)];
196
+ visit(t.c, branch);
197
+ visit(t.then, branch);
198
+ visit(t.else, positive);
199
+ return;
200
+ }
201
+ const here = t.op === 'and' ? [...positive, ...atoms(t)] : positive;
202
+ const key = t.key, row = key?.b, input = row?.a?.name, src = t.map;
203
+ if (base === -1 && t.op === 'get' && src !== map && src in maps && !rows.has(src)) {
204
+ const first = { op: 'proj', k: 0, a: x(w.each) }, second = { op: 'proj', k: 1, a: x(w.each) };
205
+ if (sameTerm(t.key, second))
206
+ for (const input of m.inputs)
207
+ if (here.some(q => sameTerm(q, same(first, x(input))) || sameTerm(q, same(x(input), first))))
208
+ for (const q of here)
209
+ if (q.op === 'flag') {
210
+ const flag = q.name;
211
+ loads.set(`${src}:${input}:${flag}`, { src, input, flag });
212
+ }
213
+ }
214
+ if (base !== -1 && t.op === 'get' && src !== map && src in maps && !rows.has(src) && key?.op === 'sub' && key.a.op === 'var' && key.a.name === w.each
215
+ && row?.op === 'mul' && row.k === base && row.a.op === 'var' && input !== undefined && m.inputs.includes(input)
216
+ && here.some(q => sameTerm(q, atMost(times(base, x(input)), x(w.each))))
217
+ && here.some(q => sameTerm(q, less(x(w.each), plus(times(base, x(input)), n(base))))))
218
+ for (const q of here)
219
+ if (q.op === 'flag') {
220
+ const flag = q.name;
221
+ loads.set(`${src}:${input}:${flag}`, { src, input, flag });
222
+ }
223
+ for (const u of Object.values(t))
224
+ visit(u, here);
225
+ };
226
+ visit(w.value, []);
227
+ const cell = (r) => get(map, base === -1 ? tuple([r, c]) : plus(times(base, r), c));
228
+ for (const { src, input, flag } of loads.values())
229
+ for (const [mk, mw] of Object.entries(m.step.maps ?? {})) {
230
+ if ('each' in mw || mw.key.op !== 'var' || mw.key.name !== input || !(mk in maps) || rows.has(mk) || mk === src)
231
+ continue;
232
+ const v = markerValue(mw.value, mk, mw.key, flag);
233
+ if (v === undefined)
234
+ continue;
235
+ const marked = (r) => same(get(mk, r), n(v)), def = m.step.flags?.[flag];
236
+ const literals = atoms(def).filter(q => q.op === '=' && q.a.op === 'var' && q.a.name in m.state && q.b.op === 'const');
237
+ const load = (guards, label) => ({ name: `fields: ${mk}[a]=${v}${label} -> ${map} row is ${src}`, forall: ka, keys: [kc],
238
+ holds: any(not(all(da, less(c, bound), marked(a), ...guards)), same(cell(a), get(src, c))) });
239
+ const whole = add(load([], ''));
240
+ loadFieldFamily.set(whole, whole);
241
+ for (const lit of literals) {
242
+ const q = lit, weaker = load([lit], ` and ${q.a.name}=${q.b.value}`);
243
+ const choice = add(weaker);
244
+ weakensField.set(choice, whole);
245
+ loadFieldFamily.set(choice, whole);
246
+ }
247
+ for (const { f, g, law } of agrees.filter(r => r.map === map)) {
248
+ const guard = all(da, db, less(c, bound), same(get(f, a), get(f, b)), same(get(g, a), get(g, b)), marked(a), marked(b));
249
+ const weaker = { name: `fields: ${f}[a]=${f}[b] and ${g}[a]=${g}[b] and ${mk}[a]=${mk}[b]=${v} -> ${map} rows agree`, forall: ka, keys: [kb, kc], holds: any(not(guard), same(cell(a), cell(b))) };
250
+ weakensField.set(add(weaker), law);
251
+ }
252
+ }
253
+ }
98
254
  }
99
255
  return out;
100
256
  }
@@ -29,10 +29,16 @@ export type FiniteOptions = {
29
29
  seed?: number;
30
30
  targeted?: boolean;
31
31
  wallMs?: number;
32
+ workLimit?: number;
32
33
  onFinish?: (row: {
33
34
  timedOut: boolean;
34
35
  ms: number;
35
36
  dropped: number;
37
+ work?: {
38
+ used: number;
39
+ limit: number;
40
+ exhausted: boolean;
41
+ };
36
42
  }) => void;
37
43
  onDrop?: (drop: FiniteDrop) => void;
38
44
  onRound?: (row: {
@@ -1,10 +1,12 @@
1
+ import { traceNow as countedTraceNow } from "./wall.js";
1
2
  // A finite relative-CTI filter, never a proof. Unsupported evaluations are
2
3
  // unknown; only an actual enabled step from a state satisfying the WHOLE
3
4
  // current family may remove a non-caller. The checked prover sees survivors.
4
- import { carriedView, compileC, compileE, fastStep, interpret, seeded, walk } from "./machine.js";
5
- import { checkWall, searchWall, WallExpired } from "./wall.js";
5
+ import { carriedView, compileC, compileE, fastStep, hasFinite, interpret, seeded, walk } from "./machine.js";
6
+ import { checkWall, searchWall, WallExpired, BudgetExpired } from "./wall.js";
6
7
  import { boundaryState, lawFrontiers } from "./finite-frontiers.js";
7
- import { wallAt, withWall } from "../kernel/prove.js";
8
+ import { withReachabilityWork, reachState, reachEdge } from "./work-observe.js";
9
+ import { wallAt, withWall, wallDeadline } from "../kernel/prove.js";
8
10
  import { tinyFiniteCandidates, tinySeedCandidates } from "./finite-tiny.js";
9
11
  const variables = (t) => { const out = new Set(); walk(t, o => { if (o.op === 'var')
10
12
  out.add(o.name); }); return out; };
@@ -16,6 +18,7 @@ const conjuncts = (c) => c.op === 'and' ? c.xs.flatMap(conjuncts) : [c];
16
18
  export function finiteEvaluator(m, stop = () => false) {
17
19
  const checkpoint = () => { checkWall('finite derived count'); if (stop())
18
20
  throw new Error('finite evaluation stopped'); };
21
+ const finiteMachine = hasFinite(m);
19
22
  const plans = new WeakMap();
20
23
  const cache = new WeakMap();
21
24
  function plan(law) {
@@ -77,11 +80,12 @@ export function finiteEvaluator(m, stop = () => false) {
77
80
  let nested = false;
78
81
  walk(law.holds, o => { if (o.op === 'all')
79
82
  nested = true; });
80
- return { keys, cover, guards: gs, test: compileC(law.holds, m), supported: !nested && !law.some?.length && !keys.some(k => k in m.state || m.params.includes(k)) && ![...variables(law.holds)].some(k => m.inputs.includes(k) && !keys.includes(k)) };
83
+ return { keys, cover, guards: gs, test: compileC(law.holds, m), supported: !nested && !hasFinite(law) && !law.some?.length && !keys.some(k => k in m.state || m.params.includes(k)) && ![...variables(law.holds)].some(k => m.inputs.includes(k) && !keys.includes(k)) };
81
84
  }
82
- return (law, p, st) => {
85
+ return (law, p, st) => withReachabilityWork(() => {
83
86
  checkWall('finite law');
84
- if (stop())
87
+ // This specialized cover compiler has not been extended to sized domains.
88
+ if (stop() || finiteMachine)
85
89
  return undefined;
86
90
  let entry = cache.get(st);
87
91
  if (!entry || entry.params !== p) {
@@ -159,27 +163,57 @@ export function finiteEvaluator(m, stop = () => false) {
159
163
  truth = go(shape.cover);
160
164
  }
161
165
  catch (e) {
162
- if (e instanceof WallExpired)
166
+ if (e instanceof WallExpired || e instanceof BudgetExpired)
163
167
  throw e;
164
168
  truth = undefined;
165
169
  }
166
170
  entry.values.set(law, truth);
167
171
  return truth;
168
- };
172
+ });
169
173
  }
170
174
  export const finiteDump = {};
175
+ class FiniteWorkExpired extends Error {
176
+ }
171
177
  export function finiteHoudini(source, m, caller, candidates, samples, options = {}) {
172
- const start = performance.now(), end = Math.min(wallAt(), searchWall(Math.max(0, options.wallMs ?? 2_000)));
178
+ const limit = options.workLimit;
179
+ if (limit !== undefined && (!Number.isSafeInteger(limit) || limit < 0))
180
+ throw new Error('finite work limit must be a nonnegative safe integer');
181
+ const work = limit === undefined ? undefined : { used: 0, limit, exhausted: false };
182
+ const start = countedTraceNow(), end = wallDeadline(work ? wallAt() : Math.min(wallAt(), searchWall(Math.max(0, options.wallMs ?? 2_000)).end));
183
+ const tick = () => {
184
+ if (!work)
185
+ return;
186
+ checkWall('finite sampling work');
187
+ if (work.used >= work.limit) {
188
+ work.exhausted = true;
189
+ throw new FiniteWorkExpired();
190
+ }
191
+ work.used++;
192
+ };
173
193
  let survivors = candidates.slice(), timedOut = false;
174
194
  try {
175
- return withWall(end, () => finiteHoudiniWithin(source, m, caller, candidates, samples, { ...options, onDrop: drop => {
176
- survivors = survivors.filter(law => law !== drop.law);
177
- options.onDrop?.(drop);
178
- } }));
195
+ return withWall(end, () => withReachabilityWork(() => {
196
+ if (work)
197
+ checkWall('finite sampling start');
198
+ if (work?.limit === 0) {
199
+ work.exhausted = true;
200
+ return survivors;
201
+ }
202
+ return finiteHoudiniWithin(source, m, caller, candidates, samples, { ...options, onDrop: drop => {
203
+ survivors = survivors.filter(law => law !== drop.law);
204
+ options.onDrop?.(drop);
205
+ } }, tick);
206
+ }));
179
207
  }
180
208
  catch (error) {
209
+ if (error instanceof FiniteWorkExpired)
210
+ return survivors;
181
211
  if (!(error instanceof WallExpired))
182
212
  throw error;
213
+ if (work) {
214
+ timedOut = true;
215
+ throw error;
216
+ }
183
217
  // An enclosing deadline must still cancel the caller. Only expiration of
184
218
  // this local sampling allowance returns the already-certified survivors.
185
219
  checkWall('finite sampling completion');
@@ -187,7 +221,7 @@ export function finiteHoudini(source, m, caller, candidates, samples, options =
187
221
  return survivors;
188
222
  }
189
223
  finally {
190
- options.onFinish?.({ timedOut, ms: performance.now() - start, dropped: candidates.length - survivors.length });
224
+ options.onFinish?.({ timedOut, ms: countedTraceNow() - start, dropped: candidates.length - survivors.length, ...(work ? { work } : {}) });
191
225
  }
192
226
  }
193
227
  // What a law reads: its scalars and maps, a count map read as the scalars and maps of its body and bound. A law
@@ -217,10 +251,10 @@ function lawReads(m, law) {
217
251
  // independent whole-family/source-interpreter boundary as sampled Houdini.
218
252
  // It is not wired into production generation until its bounded pilot passes.
219
253
  export function finiteTinyHoudini(source, m, caller, candidates, params, options = {}) {
220
- const start = performance.now(), end = Math.min(wallAt(), searchWall(Math.max(0, options.wallMs ?? 2_000)));
254
+ const start = countedTraceNow(), end = wallDeadline(Math.min(wallAt(), searchWall(Math.max(0, options.wallMs ?? 2_000)).end));
221
255
  let survivors = candidates.slice(), timedOut = false;
222
256
  try {
223
- return withWall(end, () => {
257
+ return withWall(end, () => withReachabilityWork(() => {
224
258
  if (source.history || m.history || Object.keys(source.leasts ?? {}).length || Object.keys(m.leasts ?? {}).length || Object.keys(source.sums ?? {}).length || Object.keys(m.sums ?? {}).length)
225
259
  return survivors;
226
260
  finiteDump.onStart?.({ machine: m, caller, candidates });
@@ -234,15 +268,17 @@ export function finiteTinyHoudini(source, m, caller, candidates, params, options
234
268
  checkWall('tiny Houdini instance');
235
269
  const certify = (pre, request) => {
236
270
  checkWall('tiny Houdini certification');
271
+ reachState();
237
272
  // The screen's constraints and reported post-laws are not trusted.
238
273
  if (!family.every(law => evaluate(law, p, pre) === true))
239
274
  return false;
240
275
  let post;
241
276
  try {
277
+ reachEdge();
242
278
  post = run.step(p, pre, request);
243
279
  }
244
280
  catch (e) {
245
- if (e instanceof WallExpired)
281
+ if (e instanceof WallExpired || e instanceof BudgetExpired)
246
282
  throw e;
247
283
  return false;
248
284
  }
@@ -281,7 +317,7 @@ export function finiteTinyHoudini(source, m, caller, candidates, params, options
281
317
  return survivors;
282
318
  }
283
319
  return survivors;
284
- });
320
+ }));
285
321
  }
286
322
  catch (e) {
287
323
  if (!(e instanceof WallExpired))
@@ -291,10 +327,10 @@ export function finiteTinyHoudini(source, m, caller, candidates, params, options
291
327
  return survivors;
292
328
  }
293
329
  finally {
294
- options.onFinish?.({ timedOut, ms: performance.now() - start, dropped: candidates.length - survivors.length });
330
+ options.onFinish?.({ timedOut, ms: countedTraceNow() - start, dropped: candidates.length - survivors.length });
295
331
  }
296
332
  }
297
- function finiteHoudiniWithin(source, m, caller, candidates, samples, options) {
333
+ function finiteHoudiniWithin(source, m, caller, candidates, samples, options, tick) {
298
334
  finiteDump.onStart?.({ machine: m, caller, candidates });
299
335
  // Derived sum-state consistency is not reconstructed by this finite backend.
300
336
  if (Object.keys(m.sums ?? {}).length)
@@ -346,6 +382,8 @@ function finiteHoudiniWithin(source, m, caller, candidates, samples, options) {
346
382
  return law;
347
383
  } return undefined; };
348
384
  const visit = (p, pre) => {
385
+ reachState();
386
+ tick();
349
387
  const by = rejecting(p, pre);
350
388
  if (by) {
351
389
  rejected.push({ p, st: pre, by });
@@ -353,16 +391,18 @@ function finiteHoudiniWithin(source, m, caller, candidates, samples, options) {
353
391
  }
354
392
  const bound = Math.max(3, ...Object.values(p));
355
393
  for (let trial = 0; trial < (options.requests ?? 25); trial++) {
394
+ tick();
356
395
  checkWall('finite transitions');
357
396
  const request = Object.fromEntries(numericInputs.map(({ name, bound: b }) => [name, rng(b)]));
358
397
  for (const mp of source.inputMaps ?? [])
359
398
  request[mp] = new Map(Array.from({ length: bound }, (_, i) => [i, 1]).filter(() => rng(2)));
360
399
  let post;
361
400
  try {
401
+ reachEdge();
362
402
  post = step(p, pre, request);
363
403
  }
364
404
  catch (e) {
365
- if (e instanceof WallExpired)
405
+ if (e instanceof WallExpired || e instanceof BudgetExpired)
366
406
  throw e;
367
407
  continue;
368
408
  }
@@ -408,6 +448,7 @@ function finiteHoudiniWithin(source, m, caller, candidates, samples, options) {
408
448
  // one-sided boundary, a guard enabled, or a bounded field at its limit.
409
449
  const frontiers = options.targeted === false ? [] : alive.flatMap(law => lawFrontiers(law).map(conditions => ({ law, conditions })));
410
450
  for (let i = 0; frontiers.length && i < Math.min(requested, frontiers.length * 8); i++) {
451
+ tick();
411
452
  checkWall('finite frontiers');
412
453
  const { p, st: old } = base[rng(base.length)], { law, conditions } = frontiers[i % frontiers.length];
413
454
  const bound = Math.max(1, ...Object.values(p)), keys = Object.fromEntries([law.forall, ...law.keys ?? []].filter((k) => !!k).map(k => [k, rng(bound)]));
@@ -418,6 +459,7 @@ function finiteHoudiniWithin(source, m, caller, candidates, samples, options) {
418
459
  for (const { p, st } of base)
419
460
  visit(p, st);
420
461
  for (let tries = 0; accepted < requested && tries < Math.max(requested * 8, requested); tries++) {
462
+ tick();
421
463
  checkWall('finite neighbors');
422
464
  const { p, st: old } = base[rng(base.length)], st = { ...old, scalars: { ...old.scalars }, maps: { ...old.maps } };
423
465
  const bound = Math.max(3, ...Object.values(p));