gdp-wired 0.47.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 (420) hide show
  1. package/README.md +17 -6
  2. package/dist/core/bmc.js +10 -7
  3. package/dist/core/carry.d.ts +15 -0
  4. package/dist/core/carry.js +651 -0
  5. package/dist/core/check.js +7 -2
  6. package/dist/core/cli.d.ts +3 -1
  7. package/dist/core/cli.js +28 -8
  8. package/dist/core/count-attempt-work.d.ts +29 -0
  9. package/dist/core/count-attempt-work.js +96 -0
  10. package/dist/core/count-boolean-partition.d.ts +5 -0
  11. package/dist/core/count-boolean-partition.js +47 -0
  12. package/dist/core/count-bounded-quotient.d.ts +2 -0
  13. package/dist/core/count-bounded-quotient.js +13 -0
  14. package/dist/core/count-case-compose.d.ts +20 -0
  15. package/dist/core/count-case-compose.js +289 -0
  16. package/dist/core/count-cases.d.ts +24 -0
  17. package/dist/core/count-cases.js +321 -0
  18. package/dist/core/count-cert-grow.d.ts +4 -0
  19. package/dist/core/count-cert-grow.js +37 -0
  20. package/dist/core/count-cert-rename.d.ts +10 -0
  21. package/dist/core/count-cert-rename.js +69 -0
  22. package/dist/core/count-cert-transport.d.ts +11 -0
  23. package/dist/core/count-cert-transport.js +109 -0
  24. package/dist/core/count-certificate-minimize.d.ts +57 -0
  25. package/dist/core/count-certificate-minimize.js +263 -0
  26. package/dist/core/count-closed-family.d.ts +32 -0
  27. package/dist/core/count-closed-family.js +143 -0
  28. package/dist/core/count-closing-budget.d.ts +10 -0
  29. package/dist/core/count-closing-budget.js +49 -0
  30. package/dist/core/count-closing-needs.d.ts +5 -0
  31. package/dist/core/count-closing-needs.js +9 -0
  32. package/dist/core/count-completion.d.ts +9 -0
  33. package/dist/core/count-completion.js +27 -0
  34. package/dist/core/count-component-budget.d.ts +5 -0
  35. package/dist/core/count-component-budget.js +9 -0
  36. package/dist/core/count-copy-shape.d.ts +11 -0
  37. package/dist/core/count-copy-shape.js +40 -0
  38. package/dist/core/count-cubes.d.ts +8 -0
  39. package/dist/core/count-cubes.js +69 -0
  40. package/dist/core/count-demand.d.ts +37 -0
  41. package/dist/core/count-demand.js +361 -0
  42. package/dist/core/count-disjoint-funding.d.ts +75 -0
  43. package/dist/core/count-disjoint-funding.js +284 -0
  44. package/dist/core/count-emitter-frame-pool.d.ts +23 -0
  45. package/dist/core/count-emitter-frame-pool.js +87 -0
  46. package/dist/core/count-facts.d.ts +52 -0
  47. package/dist/core/count-facts.js +247 -0
  48. package/dist/core/count-final-step.d.ts +5 -0
  49. package/dist/core/count-final-step.js +20 -0
  50. package/dist/core/count-fixed-frame.d.ts +4 -0
  51. package/dist/core/count-fixed-frame.js +30 -0
  52. package/dist/core/count-focus-proof.d.ts +8 -0
  53. package/dist/core/count-focus-proof.js +140 -0
  54. package/dist/core/count-focused.d.ts +22 -0
  55. package/dist/core/count-focused.js +676 -0
  56. package/dist/core/count-frames.d.ts +25 -0
  57. package/dist/core/count-frames.js +118 -0
  58. package/dist/core/count-frozen-guard.d.ts +2 -0
  59. package/dist/core/count-frozen-guard.js +31 -0
  60. package/dist/core/count-generation-phase.d.ts +7 -0
  61. package/dist/core/count-generation-phase.js +33 -0
  62. package/dist/core/count-guard-composition.d.ts +12 -0
  63. package/dist/core/count-guard-composition.js +48 -0
  64. package/dist/core/count-guard-context.d.ts +11 -0
  65. package/dist/core/count-guard-context.js +50 -0
  66. package/dist/core/count-guard-facts.d.ts +50 -0
  67. package/dist/core/count-guard-facts.js +97 -0
  68. package/dist/core/count-guard-proposals.d.ts +7 -0
  69. package/dist/core/count-guard-proposals.js +106 -0
  70. package/dist/core/count-guard-shape.d.ts +18 -0
  71. package/dist/core/count-guard-shape.js +100 -0
  72. package/dist/core/count-guard-tree.d.ts +17 -0
  73. package/dist/core/count-guard-tree.js +125 -0
  74. package/dist/core/count-leader-facts.d.ts +10 -0
  75. package/dist/core/count-leader-facts.js +52 -0
  76. package/dist/core/count-leader.d.ts +10 -0
  77. package/dist/core/count-leader.js +331 -0
  78. package/dist/core/count-lemma-transport.d.ts +8 -0
  79. package/dist/core/count-lemma-transport.js +47 -0
  80. package/dist/core/count-lifted-budget.d.ts +54 -0
  81. package/dist/core/count-lifted-budget.js +97 -0
  82. package/dist/core/count-lifted-copy.d.ts +3 -0
  83. package/dist/core/count-lifted-copy.js +166 -0
  84. package/dist/core/count-lifted-increment.d.ts +3 -0
  85. package/dist/core/count-lifted-increment.js +146 -0
  86. package/dist/core/count-lifted-load.d.ts +5 -0
  87. package/dist/core/count-lifted-load.js +179 -0
  88. package/dist/core/count-lifted-prerequisite.d.ts +14 -0
  89. package/dist/core/count-lifted-prerequisite.js +53 -0
  90. package/dist/core/count-lifted-replacement.d.ts +3 -0
  91. package/dist/core/count-lifted-replacement.js +540 -0
  92. package/dist/core/count-lifted-shape.d.ts +63 -0
  93. package/dist/core/count-lifted-shape.js +115 -0
  94. package/dist/core/count-lifted-strategy.d.ts +7 -0
  95. package/dist/core/count-lifted-strategy.js +226 -0
  96. package/dist/core/count-lifted-transports.d.ts +32 -0
  97. package/dist/core/count-lifted-transports.js +293 -0
  98. package/dist/core/count-load-shape.d.ts +17 -0
  99. package/dist/core/count-load-shape.js +67 -0
  100. package/dist/core/count-minimal-view.d.ts +26 -0
  101. package/dist/core/count-minimal-view.js +46 -0
  102. package/dist/core/count-operation-observation.d.ts +9 -0
  103. package/dist/core/count-operation-observation.js +22 -0
  104. package/dist/core/count-operation-order.d.ts +5 -0
  105. package/dist/core/count-operation-order.js +4 -0
  106. package/dist/core/count-phase.d.ts +9 -0
  107. package/dist/core/count-phase.js +127 -0
  108. package/dist/core/count-premise-search.d.ts +9 -0
  109. package/dist/core/count-premise-search.js +41 -0
  110. package/dist/core/count-premise-view.d.ts +19 -0
  111. package/dist/core/count-premise-view.js +220 -0
  112. package/dist/core/count-prerequisite-components.d.ts +67 -0
  113. package/dist/core/count-prerequisite-components.js +239 -0
  114. package/dist/core/count-prerequisite-memory.d.ts +24 -0
  115. package/dist/core/count-prerequisite-memory.js +37 -0
  116. package/dist/core/count-prerequisite-plan.d.ts +12 -0
  117. package/dist/core/count-prerequisite-plan.js +88 -0
  118. package/dist/core/count-primitive-budget.d.ts +1 -0
  119. package/dist/core/count-primitive-budget.js +8 -0
  120. package/dist/core/count-project-free.d.ts +3 -0
  121. package/dist/core/count-project-free.js +24 -0
  122. package/dist/core/count-project-witness.d.ts +4 -0
  123. package/dist/core/count-project-witness.js +48 -0
  124. package/dist/core/count-proof-rescope.d.ts +14 -0
  125. package/dist/core/count-proof-rescope.js +71 -0
  126. package/dist/core/count-proof-scope.d.ts +68 -0
  127. package/dist/core/count-proof-scope.js +333 -0
  128. package/dist/core/count-prune-owned-root.d.ts +5 -0
  129. package/dist/core/count-prune-owned-root.js +27 -0
  130. package/dist/core/count-query-context.d.ts +3 -0
  131. package/dist/core/count-query-context.js +7 -0
  132. package/dist/core/count-query.d.ts +15 -0
  133. package/dist/core/count-query.js +59 -0
  134. package/dist/core/count-quorum-leaf.d.ts +9 -0
  135. package/dist/core/count-quorum-leaf.js +38 -0
  136. package/dist/core/count-ranges.d.ts +5 -0
  137. package/dist/core/count-ranges.js +65 -0
  138. package/dist/core/count-reachability-budget.d.ts +1 -0
  139. package/dist/core/count-reachability-budget.js +7 -0
  140. package/dist/core/count-reachability-reconcile.d.ts +11 -0
  141. package/dist/core/count-reachability-reconcile.js +19 -0
  142. package/dist/core/count-reachability.d.ts +50 -0
  143. package/dist/core/count-reachability.js +351 -0
  144. package/dist/core/count-rebase-path.d.ts +9 -0
  145. package/dist/core/count-rebase-path.js +68 -0
  146. package/dist/core/count-recipe-context.d.ts +45 -0
  147. package/dist/core/count-recipe-context.js +71 -0
  148. package/dist/core/count-recipe-controller.d.ts +115 -0
  149. package/dist/core/count-recipe-controller.js +417 -0
  150. package/dist/core/count-recipe-graph.d.ts +36 -0
  151. package/dist/core/count-recipe-graph.js +211 -0
  152. package/dist/core/count-recovery/action-guard.d.ts +5 -0
  153. package/dist/core/count-recovery/action-guard.js +51 -0
  154. package/dist/core/count-recovery/boolean-core.d.ts +16 -0
  155. package/dist/core/count-recovery/boolean-core.js +258 -0
  156. package/dist/core/count-recovery/carried-case.d.ts +2 -0
  157. package/dist/core/count-recovery/carried-case.js +24 -0
  158. package/dist/core/count-recovery/conditional-check-cache.d.ts +23 -0
  159. package/dist/core/count-recovery/conditional-check-cache.js +131 -0
  160. package/dist/core/count-recovery/conditional-cuts.d.ts +6 -0
  161. package/dist/core/count-recovery/conditional-cuts.js +319 -0
  162. package/dist/core/count-recovery/conditional-proof.d.ts +53 -0
  163. package/dist/core/count-recovery/conditional-proof.js +348 -0
  164. package/dist/core/count-recovery/derivability-closure.d.ts +14 -0
  165. package/dist/core/count-recovery/derivability-closure.js +534 -0
  166. package/dist/core/count-recovery/empty-count-source.d.ts +2 -0
  167. package/dist/core/count-recovery/empty-count-source.js +40 -0
  168. package/dist/core/count-recovery/field-bound-lemmas.d.ts +23 -0
  169. package/dist/core/count-recovery/field-bound-lemmas.js +640 -0
  170. package/dist/core/count-recovery/field-case.d.ts +5 -0
  171. package/dist/core/count-recovery/field-case.js +89 -0
  172. package/dist/core/count-recovery/field-demand.d.ts +46 -0
  173. package/dist/core/count-recovery/field-demand.js +47 -0
  174. package/dist/core/count-recovery/field-only.d.ts +3 -0
  175. package/dist/core/count-recovery/field-only.js +18 -0
  176. package/dist/core/count-recovery/fold-path.d.ts +6 -0
  177. package/dist/core/count-recovery/fold-path.js +35 -0
  178. package/dist/core/count-recovery/frame-lemmas.d.ts +9 -0
  179. package/dist/core/count-recovery/frame-lemmas.js +120 -0
  180. package/dist/core/count-recovery/guard-cases.d.ts +12 -0
  181. package/dist/core/count-recovery/guard-cases.js +139 -0
  182. package/dist/core/count-recovery/key-closure.d.ts +14 -0
  183. package/dist/core/count-recovery/key-closure.js +62 -0
  184. package/dist/core/count-recovery/leaf-allowance.d.ts +4 -0
  185. package/dist/core/count-recovery/leaf-allowance.js +7 -0
  186. package/dist/core/count-recovery/lift-count-proxies.d.ts +6 -0
  187. package/dist/core/count-recovery/lift-count-proxies.js +175 -0
  188. package/dist/core/count-recovery/live-dependencies.d.ts +6 -0
  189. package/dist/core/count-recovery/live-dependencies.js +76 -0
  190. package/dist/core/count-recovery/member-inclusions.d.ts +11 -0
  191. package/dist/core/count-recovery/member-inclusions.js +168 -0
  192. package/dist/core/count-recovery/member-premises.d.ts +29 -0
  193. package/dist/core/count-recovery/member-premises.js +114 -0
  194. package/dist/core/count-recovery/natural-cases.d.ts +6 -0
  195. package/dist/core/count-recovery/natural-cases.js +59 -0
  196. package/dist/core/count-recovery/ops.d.ts +6 -0
  197. package/dist/core/count-recovery/ops.js +8 -0
  198. package/dist/core/count-recovery/pre-state-source.d.ts +8 -0
  199. package/dist/core/count-recovery/pre-state-source.js +18 -0
  200. package/dist/core/count-recovery/rebase-path.d.ts +9 -0
  201. package/dist/core/count-recovery/rebase-path.js +70 -0
  202. package/dist/core/count-recovery/reframe-tree.d.ts +2 -0
  203. package/dist/core/count-recovery/reframe-tree.js +24 -0
  204. package/dist/core/count-recovery/rename-proof.d.ts +2 -0
  205. package/dist/core/count-recovery/rename-proof.js +102 -0
  206. package/dist/core/count-recovery/replay-linear-skeleton.d.ts +2 -0
  207. package/dist/core/count-recovery/replay-linear-skeleton.js +28 -0
  208. package/dist/core/count-recovery/row-cases.d.ts +16 -0
  209. package/dist/core/count-recovery/row-cases.js +292 -0
  210. package/dist/core/count-recovery/scalar-guards.d.ts +7 -0
  211. package/dist/core/count-recovery/scalar-guards.js +291 -0
  212. package/dist/core/count-recovery/source-memo.d.ts +12 -0
  213. package/dist/core/count-recovery/source-memo.js +67 -0
  214. package/dist/core/count-rejection-budget.d.ts +8 -0
  215. package/dist/core/count-rejection-budget.js +15 -0
  216. package/dist/core/count-replacement.d.ts +5 -0
  217. package/dist/core/count-replacement.js +129 -0
  218. package/dist/core/count-replay-diagnostic.d.ts +21 -0
  219. package/dist/core/count-replay-diagnostic.js +49 -0
  220. package/dist/core/count-replay-skeleton.d.ts +4 -0
  221. package/dist/core/count-replay-skeleton.js +28 -0
  222. package/dist/core/count-rescope-funding.d.ts +3 -0
  223. package/dist/core/count-rescope-funding.js +17 -0
  224. package/dist/core/count-restrictions.d.ts +11 -0
  225. package/dist/core/count-restrictions.js +31 -0
  226. package/dist/core/count-retry-budget.d.ts +67 -0
  227. package/dist/core/count-retry-budget.js +114 -0
  228. package/dist/core/count-retry-round.d.ts +24 -0
  229. package/dist/core/count-retry-round.js +44 -0
  230. package/dist/core/count-row-agreement.d.ts +35 -0
  231. package/dist/core/count-row-agreement.js +270 -0
  232. package/dist/core/count-row-aliases.d.ts +3 -0
  233. package/dist/core/count-row-aliases.js +59 -0
  234. package/dist/core/count-row-composition.d.ts +6 -0
  235. package/dist/core/count-row-composition.js +55 -0
  236. package/dist/core/count-row-copy-linear.d.ts +4 -0
  237. package/dist/core/count-row-copy-linear.js +83 -0
  238. package/dist/core/count-row-copy.d.ts +4 -0
  239. package/dist/core/count-row-copy.js +94 -0
  240. package/dist/core/count-row-policy.d.ts +3 -0
  241. package/dist/core/count-row-policy.js +56 -0
  242. package/dist/core/count-row-reindex.d.ts +11 -0
  243. package/dist/core/count-row-reindex.js +126 -0
  244. package/dist/core/count-row-support.d.ts +9 -0
  245. package/dist/core/count-row-support.js +42 -0
  246. package/dist/core/count-row-symmetry.d.ts +7 -0
  247. package/dist/core/count-row-symmetry.js +100 -0
  248. package/dist/core/count-scope-hyps.d.ts +2 -0
  249. package/dist/core/count-scope-hyps.js +163 -0
  250. package/dist/core/count-scope-row-reuse.d.ts +3 -0
  251. package/dist/core/count-scope-row-reuse.js +92 -0
  252. package/dist/core/count-search-allowance.d.ts +1 -0
  253. package/dist/core/count-search-allowance.js +17 -0
  254. package/dist/core/count-select.d.ts +16 -0
  255. package/dist/core/count-select.js +24 -0
  256. package/dist/core/count-stabilize-tree.d.ts +9 -0
  257. package/dist/core/count-stabilize-tree.js +35 -0
  258. package/dist/core/count-stage-trace.d.ts +8 -0
  259. package/dist/core/count-stage-trace.js +45 -0
  260. package/dist/core/count-strategies.d.ts +16 -0
  261. package/dist/core/count-strategies.js +155 -0
  262. package/dist/core/count-strategy-premises.d.ts +5 -0
  263. package/dist/core/count-strategy-premises.js +14 -0
  264. package/dist/core/count-strategy.d.ts +41 -0
  265. package/dist/core/count-strategy.js +76 -0
  266. package/dist/core/count-support.d.ts +598 -0
  267. package/dist/core/count-support.js +2081 -0
  268. package/dist/core/count-tier-budget.d.ts +14 -0
  269. package/dist/core/count-tier-budget.js +64 -0
  270. package/dist/core/count-unions.d.ts +2 -0
  271. package/dist/core/count-unions.js +139 -0
  272. package/dist/core/count-unwritten-prefix.d.ts +24 -0
  273. package/dist/core/count-unwritten-prefix.js +97 -0
  274. package/dist/core/count-witness-flags.d.ts +9 -0
  275. package/dist/core/count-witness-flags.js +37 -0
  276. package/dist/core/count-write-frames.d.ts +12 -0
  277. package/dist/core/count-write-frames.js +206 -0
  278. package/dist/core/count-write-shape.d.ts +15 -0
  279. package/dist/core/count-write-shape.js +73 -0
  280. package/dist/core/counts.d.ts +49 -7
  281. package/dist/core/counts.js +1679 -165
  282. package/dist/core/cycles.js +5 -4
  283. package/dist/core/cyclic.js +11 -10
  284. package/dist/core/data.js +16 -15
  285. package/dist/core/dsl-deadline.d.ts +3 -0
  286. package/dist/core/dsl-deadline.js +27 -0
  287. package/dist/core/dsl.d.ts +59 -6
  288. package/dist/core/dsl.js +459 -112
  289. package/dist/core/effect.js +8 -1
  290. package/dist/core/evaluation-admission.d.ts +1 -0
  291. package/dist/core/evaluation-admission.js +3 -0
  292. package/dist/core/exists.d.ts +7 -2
  293. package/dist/core/exists.js +131 -24
  294. package/dist/core/extract-check.d.ts +7 -1
  295. package/dist/core/extract-check.js +130 -13
  296. package/dist/core/extract-read.d.ts +22 -8
  297. package/dist/core/extract-read.js +29 -11
  298. package/dist/core/extract-shapes.js +122 -41
  299. package/dist/core/extract-standalone.js +53 -9
  300. package/dist/core/extract.js +9 -3
  301. package/dist/core/field-laws.d.ts +4 -0
  302. package/dist/core/field-laws.js +238 -0
  303. package/dist/core/finite-frontiers.d.ts +5 -0
  304. package/dist/core/finite-frontiers.js +116 -0
  305. package/dist/core/finite-houdini.d.ts +58 -0
  306. package/dist/core/finite-houdini.js +502 -0
  307. package/dist/core/finite-model.d.ts +13 -0
  308. package/dist/core/finite-model.js +68 -0
  309. package/dist/core/finite-tiny.d.ts +72 -0
  310. package/dist/core/finite-tiny.js +1080 -0
  311. package/dist/core/fixtures/count-completion/paxos-decision.json +1 -0
  312. package/dist/core/fresh.js +5 -1
  313. package/dist/core/infer.d.ts +1 -1
  314. package/dist/core/infer.js +76 -38
  315. package/dist/core/kind.js +2 -1
  316. package/dist/core/laws.d.ts +2 -1
  317. package/dist/core/laws.js +47 -14
  318. package/dist/core/lemma-cuts.d.ts +38 -0
  319. package/dist/core/lemma-cuts.js +366 -0
  320. package/dist/core/linear-admission.d.ts +14 -0
  321. package/dist/core/linear-admission.js +151 -0
  322. package/dist/core/machine.d.ts +44 -4
  323. package/dist/core/machine.js +342 -63
  324. package/dist/core/meter.d.ts +22 -0
  325. package/dist/core/meter.js +34 -0
  326. package/dist/core/mutate.d.ts +55 -0
  327. package/dist/core/mutate.js +210 -0
  328. package/dist/core/native-domain.d.ts +6 -0
  329. package/dist/core/native-domain.js +114 -0
  330. package/dist/core/native-law.d.ts +3 -0
  331. package/dist/core/native-law.js +174 -0
  332. package/dist/core/nonterm.js +4 -3
  333. package/dist/core/prover-row-budget.d.ts +3 -0
  334. package/dist/core/prover-row-budget.js +106 -0
  335. package/dist/core/quorum-laws.d.ts +25 -0
  336. package/dist/core/quorum-laws.js +263 -0
  337. package/dist/core/rationals.js +3 -2
  338. package/dist/core/rejection-discovery.d.ts +34 -0
  339. package/dist/core/rejection-discovery.js +36 -0
  340. package/dist/core/rejection-stage.d.ts +39 -0
  341. package/dist/core/rejection-stage.js +205 -0
  342. package/dist/core/relational.js +10 -2
  343. package/dist/core/relevance.d.ts +4 -0
  344. package/dist/core/relevance.js +79 -0
  345. package/dist/core/request-quotient.d.ts +8 -0
  346. package/dist/core/request-quotient.js +299 -0
  347. package/dist/core/row-agreement-shape.d.ts +15 -0
  348. package/dist/core/row-agreement-shape.js +68 -0
  349. package/dist/core/runtime-wall.d.ts +5 -0
  350. package/dist/core/runtime-wall.js +4 -0
  351. package/dist/core/sample-step.d.ts +16 -0
  352. package/dist/core/sample-step.js +28 -0
  353. package/dist/core/search-policy.d.ts +15 -0
  354. package/dist/core/search-policy.js +68 -0
  355. package/dist/core/solver.d.ts +1 -1
  356. package/dist/core/solver.js +40 -6
  357. package/dist/core/source-check.d.ts +44 -0
  358. package/dist/core/source-check.js +126 -0
  359. package/dist/core/source-diagnostic.d.ts +1 -0
  360. package/dist/core/source-diagnostic.js +34 -0
  361. package/dist/core/step-work.d.ts +12 -0
  362. package/dist/core/step-work.js +14 -0
  363. package/dist/core/strategy-premises.d.ts +8 -0
  364. package/dist/core/strategy-premises.js +64 -0
  365. package/dist/core/support-budget.d.ts +2 -0
  366. package/dist/core/support-budget.js +6 -0
  367. package/dist/core/system.js +6 -3
  368. package/dist/core/table-admission.d.ts +1 -0
  369. package/dist/core/table-admission.js +3 -0
  370. package/dist/core/trace-clock.d.ts +3 -0
  371. package/dist/core/trace-clock.js +16 -0
  372. package/dist/core/transfer.js +3 -2
  373. package/dist/core/translate.js +16 -3
  374. package/dist/core/wall.d.ts +11 -0
  375. package/dist/core/wall.js +37 -0
  376. package/dist/core/watch.d.ts +1 -1
  377. package/dist/core/watch.js +15 -2
  378. package/dist/core/work-admission.d.ts +164 -0
  379. package/dist/core/work-admission.js +418 -0
  380. package/dist/core/work-amount.d.ts +21 -0
  381. package/dist/core/work-amount.js +80 -0
  382. package/dist/core/work-collections.d.ts +11 -0
  383. package/dist/core/work-collections.js +198 -0
  384. package/dist/core/work-kinds.d.ts +11 -0
  385. package/dist/core/work-kinds.js +9 -0
  386. package/dist/core/work-meter.d.ts +8 -0
  387. package/dist/core/work-meter.js +83 -0
  388. package/dist/core/work-observe.d.ts +12 -0
  389. package/dist/core/work-observe.js +39 -0
  390. package/dist/core/work-profile.d.ts +10 -0
  391. package/dist/core/work-profile.js +21 -0
  392. package/dist/core/work-refusal.d.ts +1 -0
  393. package/dist/core/work-refusal.js +6 -0
  394. package/dist/interchange/format.js +2 -0
  395. package/dist/kernel/cdcl.d.ts +4 -0
  396. package/dist/kernel/cdcl.js +109 -41
  397. package/dist/kernel/epr.js +23 -8
  398. package/dist/kernel/kernel.d.ts +56 -0
  399. package/dist/kernel/kernel.js +466 -64
  400. package/dist/kernel/model-sequence.d.ts +2 -2
  401. package/dist/kernel/model-sequence.js +4 -3
  402. package/dist/kernel/model-values.d.ts +2 -0
  403. package/dist/kernel/model-values.js +60 -0
  404. package/dist/kernel/prove.d.ts +59 -3
  405. package/dist/kernel/prove.js +524 -130
  406. package/dist/kernel/prover-rows.d.ts +30 -0
  407. package/dist/kernel/prover-rows.js +125 -0
  408. package/dist/kernel/reader.d.ts +1 -1
  409. package/dist/kernel/reader.js +57 -12
  410. package/dist/kernel/simplex.js +9 -2
  411. package/dist/lean-kernel/emit.d.ts +47 -2
  412. package/dist/lean-kernel/emit.js +270 -36
  413. package/dist/lean-kernel/lean-terms.d.ts +1 -0
  414. package/dist/lean-kernel/lean-terms.js +13 -5
  415. package/dist/lean-kernel/legacy-family-library.d.ts +1 -0
  416. package/dist/lean-kernel/legacy-family-library.js +5 -0
  417. package/dist/lean-kernel/library.js +4 -0
  418. package/dist/lean-kernel/qalpha.d.ts +7 -0
  419. package/dist/lean-kernel/qalpha.js +40 -0
  420. package/package.json +5 -1
@@ -5,8 +5,15 @@
5
5
  // Arithmetic is linear: +, −, × by a constant, min, max, if. Maps are naturals indexed by naturals, every cell starting
6
6
  // at the same value; a law about a map holds for every key x, and is proven at one arbitrary x (with the law assumed at
7
7
  // every other key the step reads).
8
- import { boundOf, crossFree, eachParts, historyMachine, tuple, keyTerm, mapArities, plainKey, scope, sumRuntime, tupleParts } from "../kernel/kernel.js";
8
+ import { boundOf, crossFree, eachParts, finiteBound, finiteLawBound, historyMachine, tuple, keyTerm, mapArities, plainKey, scope, sumRuntime, tupleParts } from "../kernel/kernel.js";
9
9
  import { add, env, eq, k, le, lt, nat, scale, show, solve, sub, v } from "./solver.js";
10
+ import { runtimeWall } from "./runtime-wall.js";
11
+ import { traceNow } from "./trace-clock.js";
12
+ import { coreMeter } from "./meter.js";
13
+ import { observeEval } from "./work-observe.js";
14
+ import { observeAst } from "./meter.js";
15
+ import { startWork } from "./work-admission.js";
16
+ import { completeWorkProfile } from "./work-profile.js";
10
17
  // The one generator of the repo's random draws: x' = (1103515245 x + 12345) mod 2^31, exact (Math.imul). In doubles
11
18
  // the product passes 2^53 and rounds, which folds every seed into one of six short cycles (61 to 10,466 steps; 98.8% of
12
19
  // seeds into the same one). Its period is 2^31 (core/rand.test.ts). Draws are its high bits (the low ones repeat with a
@@ -27,13 +34,22 @@ export const walk = (t, f) => {
27
34
  for (const x of Object.values(o))
28
35
  walk(x, f);
29
36
  };
37
+ // Opt-in finite markers, including a law whose universal was pulled out by prenex.
38
+ // Unsupported evaluators use this to refuse rather than approximate its domain.
39
+ export const hasFinite = (value) => {
40
+ let found = false;
41
+ walk(value, o => { if (o.finite !== undefined && (o.op === 'all' || 'holds' in o))
42
+ found = true; });
43
+ return found;
44
+ };
30
45
  // Every object in a term once (arrays too), a part shared by several uses read at its first: a witness read at each of
31
46
  // its uses in a goal is one object, and a walk of the goal written out would read it at each.
32
- export const walkOnce = (t, f) => {
47
+ export const walkOnce = (t, f, before) => {
33
48
  const seen = new Set();
34
49
  const go = (x) => {
35
50
  if (!x || typeof x !== 'object' || seen.has(x))
36
51
  return;
52
+ before?.();
37
53
  seen.add(x);
38
54
  f(x);
39
55
  for (const y of Object.values(x))
@@ -41,6 +57,47 @@ export const walkOnce = (t, f) => {
41
57
  };
42
58
  go(t);
43
59
  };
60
+ const directBody = (d) => {
61
+ switch (d.kind) {
62
+ case 'div':
63
+ case 'mod': return { kind: d.kind, divisor: d.divisor };
64
+ case 'const': return { kind: d.kind, value: d.value };
65
+ case 'recur': return { kind: d.kind, name: d.name, args: d.args, zero: d.zero, next: d.next, uses: d.uses };
66
+ }
67
+ };
68
+ // Only runtime semantics belong in the snapshot, never Lean definitions or recurrence proof receipts.
69
+ const directDescriptor = (d) => d.kind !== 'recur' ? directBody(d) : {
70
+ ...directBody(d), uses: Object.fromEntries(Object.entries(d.uses).map(([name, fn]) => [name, {
71
+ js: fn.js, arity: fn.arity ?? 1, call: fn.call, direct: fn.direct && directDescriptor(fn.direct),
72
+ }])),
73
+ };
74
+ // Bind a library implementation to the exact source it replaces. Keep the association in JSON too: a WeakMap alone
75
+ // cannot recognize a serialized machine. Overridden source/arity/call is custom code, never the old implementation.
76
+ // This is a consistency check on trusted library metadata, not provenance or validation of arbitrary input.
77
+ export const bindDirect = (fn, direct) => ({ ...directBody(direct), source: { js: fn.js, arity: fn.arity ?? 1, ...(fn.call === undefined ? {} : { call: fn.call }), descriptor: JSON.stringify(directDescriptor(direct)) } });
78
+ export const directOf = (fn) => {
79
+ const d = fn.direct, s = d?.source;
80
+ if (!d || !s || s.js !== fn.js || s.arity !== (fn.arity ?? 1) || s.call !== fn.call)
81
+ return undefined;
82
+ try {
83
+ if (s.descriptor !== JSON.stringify(directDescriptor(d)))
84
+ return undefined;
85
+ switch (d.kind) {
86
+ case 'div':
87
+ case 'mod': return Number.isSafeInteger(d.divisor) && d.divisor >= 1 ? d : undefined;
88
+ case 'const': return Number.isSafeInteger(d.value) && d.value >= 0 ? d : undefined;
89
+ case 'recur': return Array.isArray(d.args) && d.args.length + 1 === s.arity ? d : undefined;
90
+ default: return undefined;
91
+ }
92
+ }
93
+ catch {
94
+ return undefined;
95
+ } // Malformed/cyclic metadata is not a source-free implementation.
96
+ };
97
+ export const sourceFreeFn = (fn) => {
98
+ const d = directOf(fn);
99
+ return !!d && (d.kind !== 'recur' || Object.values(d.uses).every(sourceFreeFn));
100
+ };
44
101
  // A write at one key, for the parts that take no write at every key (the symbolic prover, the GPU synthesizers, the
45
102
  // hand-written shader, the first Lean export): they refuse one by name.
46
103
  export const pointWrite = (w, where) => { if ('each' in w)
@@ -49,16 +106,16 @@ export const pointWrite = (w, where) => { if ('each' in w)
49
106
  export const noQuantifier = (where) => { throw new Error(`${where} takes no quantified flag`); };
50
107
  export { unreachable, tuple, tupleParts, part } from "../kernel/kernel.js";
51
108
  // Builders.
52
- export const x = (name) => ({ op: 'var', name });
53
- export const n = (value) => ({ op: 'const', value });
54
- export const plus = (a, b) => ({ op: 'add', a, b });
55
- export const minus = (a, b) => ({ op: 'sub', a, b });
56
- export const times = (factor, a) => ({ op: 'mul', k: factor, a });
57
- export const min = (a, b) => ({ op: 'min', a, b });
58
- export const max = (a, b) => ({ op: 'max', a, b });
59
- export const prod = (a, b) => ({ op: 'prod', a, b });
60
- export const ite = (c, then, otherwise) => ({ op: 'if', c, then, else: otherwise });
61
- export const get = (map, key) => ({ op: 'get', map, key });
109
+ export const x = (name) => (observeAst(() => ({ op: 'var', name })));
110
+ export const n = (value) => (observeAst(() => ({ op: 'const', value })));
111
+ export const plus = (a, b) => (observeAst(() => ({ op: 'add', a, b })));
112
+ export const minus = (a, b) => (observeAst(() => ({ op: 'sub', a, b })));
113
+ export const times = (factor, a) => (observeAst(() => ({ op: 'mul', k: factor, a })));
114
+ export const min = (a, b) => (observeAst(() => ({ op: 'min', a, b })));
115
+ export const max = (a, b) => (observeAst(() => ({ op: 'max', a, b })));
116
+ export const prod = (a, b) => (observeAst(() => ({ op: 'prod', a, b })));
117
+ export const ite = (c, then, otherwise) => (observeAst(() => ({ op: 'if', c, then, else: otherwise })));
118
+ export const get = (map, key) => (observeAst(() => ({ op: 'get', map, key })));
62
119
  // The pairing and its inverse as the runtimes compute them, exactly (Lean's cpair and cun): tri(a + b) + b, and back.
63
120
  export const cpair = (a, b) => { const s = a + b; return exactPair(s % 2 === 0 ? (s / 2) * (s + 1) + b : s * ((s + 1) / 2) + b); };
64
121
  const exactPair = (v) => { if (!Number.isSafeInteger(v))
@@ -73,12 +130,12 @@ export const cunpair = (z) => {
73
130
  return [s - b, b];
74
131
  };
75
132
  const tri = (s) => (s % 2 === 0 ? (s / 2) * (s + 1) : s * ((s + 1) / 2));
76
- export const less = (a, b) => ({ op: '<', a, b });
77
- export const atMost = (a, b) => ({ op: '<=', a, b });
78
- export const same = (a, b) => ({ op: '=', a, b });
79
- export const all = (...xs) => ({ op: 'and', xs });
80
- export const any = (...xs) => ({ op: 'or', xs });
81
- export const not = (c) => ({ op: 'not', x: c });
133
+ export const less = (a, b) => (observeAst(() => ({ op: '<', a, b })));
134
+ export const atMost = (a, b) => (observeAst(() => ({ op: '<=', a, b })));
135
+ export const same = (a, b) => (observeAst(() => ({ op: '=', a, b })));
136
+ export const all = (...xs) => (observeAst(() => ({ op: 'and', xs })));
137
+ export const any = (...xs) => (observeAst(() => ({ op: 'or', xs })));
138
+ export const not = (c) => (observeAst(() => ({ op: 'not', x: c })));
82
139
  export const bit = (name) => any(same(x(name), n(0)), same(x(name), n(1)));
83
140
  // --- division and remainder by a constant ------------------------------------------------------------------------
84
141
  // x div k and x mod k, for a constant k >= 1, are reads of two functions of the rule, div$k and mod$k, at x. The kernel
@@ -107,8 +164,9 @@ export function arithmetic(ks) {
107
164
  const fns = {}, facts = [];
108
165
  for (const k of [...new Set(ks)].sort((a, b) => a - b)) {
109
166
  const d = divName(k), r = modName(k), key = `x$${r}`, at = (map) => get(map, x(key));
110
- fns[d] = { js: `x => Math.floor(x / ${k})`, lean: `fun x => x / ${k}` };
111
- fns[r] = { js: `x => x % ${k}`, lean: `fun x => x % ${k}` };
167
+ const quotient = { js: `x => Math.floor(x / ${k})`, lean: `fun x => x / ${k}` }, remainder = { js: `x => x % ${k}`, lean: `fun x => x % ${k}` };
168
+ fns[d] = { ...quotient, direct: bindDirect(quotient, { kind: 'div', divisor: k }) };
169
+ fns[r] = { ...remainder, direct: bindDirect(remainder, { kind: 'mod', divisor: k }) };
112
170
  facts.push({ name: `${r}: x = ${k}·(x div ${k}) + x mod ${k}`, forall: key, holds: same(x(key), plus(times(k, at(d)), at(r))) }, { name: `${r}: x mod ${k} < ${k}`, forall: key, holds: less(at(r), n(k)) });
113
171
  }
114
172
  return { fns, facts };
@@ -263,6 +321,7 @@ const exact = (v) => {
263
321
  // (a value is a number: a name like constructor or toString, read through an object's prototype, is no value of it)
264
322
  const num = (x) => (typeof x === 'number' ? x : undefined);
265
323
  export function evalE(e, env, st, m) {
324
+ observeEval();
266
325
  switch (e.op) {
267
326
  case 'var': {
268
327
  const v = num(env[e.name]) ?? num(st.scalars[e.name]);
@@ -293,22 +352,105 @@ export function evalE(e, env, st, m) {
293
352
  }
294
353
  // A function's value at a key (the GPU search tabulates functions with it).
295
354
  export const fnValue = (fn, key) => naturalIn(fnOf(fn)(key), `a function at ${key}`);
296
- // A function's JavaScript, compiled once.
355
+ // Call a helper on its arguments, without computing their potentially enormous paired key.
356
+ export const fnCall = (fn, args) => naturalIn(callOf(fn)(...args), 'a function call');
357
+ const directCall = (d) => {
358
+ if (d.kind === 'div')
359
+ return x => Math.floor(x / d.divisor);
360
+ if (d.kind === 'mod')
361
+ return x => x % d.divisor;
362
+ if (d.kind === 'const')
363
+ return () => d.value;
364
+ // Match recurJs: check each completed step, memoize by the fixed arguments, restart for a smaller x.
365
+ // Arithmetic inside an equation is evaluated just as in generated code; no paired key is needed for calls.
366
+ const memo = new Map();
367
+ const value = (e, env) => {
368
+ observeEval();
369
+ switch (e.op) {
370
+ case 'const': return e.value;
371
+ case 'var': return env[e.name];
372
+ case 'add': return value(e.a, env) + value(e.b, env);
373
+ case 'sub': return Math.max(0, value(e.a, env) - value(e.b, env));
374
+ case 'mul': return e.k * value(e.a, env);
375
+ case 'prod': return value(e.a, env) * value(e.b, env);
376
+ case 'min': return Math.min(value(e.a, env), value(e.b, env));
377
+ case 'max': return Math.max(value(e.a, env), value(e.b, env));
378
+ case 'if': return condition(e.c, env) ? value(e.then, env) : value(e.else, env);
379
+ case 'get': {
380
+ const fn = d.uses[e.map], args = pairedArgs(e.key, fn.arity ?? 1);
381
+ return args ? callOf(fn)(...args.map(a => value(a, env))) : fnOf(fn)(value(e.key, env));
382
+ }
383
+ case 'tup':
384
+ case 'proj': throw new Error('a recurrence takes no tuple key');
385
+ }
386
+ };
387
+ const condition = (c, env) => {
388
+ observeEval();
389
+ switch (c.op) {
390
+ case '<': return value(c.a, env) < value(c.b, env);
391
+ case '<=': return value(c.a, env) <= value(c.b, env);
392
+ case '=': return value(c.a, env) === value(c.b, env);
393
+ case 'and': return c.xs.every(c => condition(c, env));
394
+ case 'or': return c.xs.some(c => condition(c, env));
395
+ case 'not': return !condition(c.x, env);
396
+ case 'flag':
397
+ case 'all': throw new Error('a recurrence takes no flag or quantifier');
398
+ }
399
+ };
400
+ return (x, ...args) => {
401
+ const key = args.join(), env = Object.fromEntries(d.args.map((a, i) => [a, args[i]]));
402
+ let at = memo.get(key);
403
+ if (!at || at[0] > x)
404
+ at = [0, value(d.zero, env)];
405
+ let prev = at[1];
406
+ for (let i = at[0]; i < x; i++) {
407
+ prev = value(d.next, { ...env, x: i, prev });
408
+ if (!Number.isSafeInteger(prev))
409
+ throw new RangeError(`${d.name} passes the safe integers`);
410
+ }
411
+ if (memo.size > 4096)
412
+ memo.clear();
413
+ memo.set(key, [x, prev]);
414
+ return prev;
415
+ };
416
+ };
417
+ const currentFn = (fn, cached) => cached && cached.js === fn.js && cached.arity === fn.arity && cached.call === fn.call && cached.direct === directOf(fn) ? cached.value : undefined;
418
+ const cacheFn = (fn, value) => ({ js: fn.js, arity: fn.arity, call: fn.call, direct: directOf(fn), value });
297
419
  const compiledFns = new WeakMap();
298
420
  const fnOf = (fn) => {
299
- let f = compiledFns.get(fn);
421
+ let f = currentFn(fn, compiledFns.get(fn));
300
422
  if (!f) {
301
- f = compileFunction(['k'], `return (${fn.js})(k)`);
302
- compiledFns.set(fn, f);
423
+ if (directOf(fn)) {
424
+ const call = callOf(fn), arity = fn.arity ?? 1;
425
+ f = key => {
426
+ const args = [];
427
+ let z = key;
428
+ for (let i = 1; i < arity; i++) {
429
+ let s = Math.floor(Math.sqrt(z));
430
+ while (s * s > z)
431
+ s--;
432
+ while ((s + 1) * (s + 1) <= z)
433
+ s++;
434
+ const q = z - s * s;
435
+ args.unshift(q);
436
+ z = s - q;
437
+ }
438
+ return call(z, ...args);
439
+ };
440
+ }
441
+ else
442
+ f = compileFunction(['k'], `return (${fn.js})(k)`);
443
+ compiledFns.set(fn, cacheFn(fn, f));
303
444
  }
304
445
  return f;
305
446
  };
306
447
  const compiledCalls = new WeakMap();
307
448
  const callOf = (fn) => {
308
- let f = compiledCalls.get(fn);
449
+ let f = currentFn(fn, compiledCalls.get(fn));
309
450
  if (!f) {
310
- f = compileFunction([], `return (${fn.call})`)();
311
- compiledCalls.set(fn, f);
451
+ const direct = directOf(fn);
452
+ f = direct ? directCall(direct) : compileFunction([], `return (${fn.call ?? fn.js})`)();
453
+ compiledCalls.set(fn, cacheFn(fn, f));
312
454
  }
313
455
  return f;
314
456
  };
@@ -335,6 +477,7 @@ export function pairedArgs(key, n) {
335
477
  }
336
478
  const alike = (a, b) => a === b || JSON.stringify(a) === JSON.stringify(b);
337
479
  export function evalC(c, env, st, m) {
480
+ observeEval();
338
481
  switch (c.op) {
339
482
  case '<': return evalE(c.a, env, st, m) < evalE(c.b, env, st, m);
340
483
  case '<=': return evalE(c.a, env, st, m) <= evalE(c.b, env, st, m);
@@ -344,6 +487,18 @@ export function evalC(c, env, st, m) {
344
487
  case 'not': return !evalC(c.x, env, st, m);
345
488
  case 'flag': return env[`?${c.name}`] === 1;
346
489
  case 'all': {
490
+ const finite = finiteBound(c);
491
+ if (finite) {
492
+ runtimeWall.check?.('finite quantifier');
493
+ const size = naturalIn(evalE(finite, env, st, m), `size of ${c.finite}`);
494
+ for (let key = 0; key < size; key++) {
495
+ if ((key & 255) === 0)
496
+ runtimeWall.check?.('finite quantifier');
497
+ if (!evalC(c.c, { ...env, [c.key]: key }, st, m))
498
+ return false;
499
+ }
500
+ return true;
501
+ }
347
502
  const names = boundOf(c), keys = tupleKeys(c, env, st, m);
348
503
  const go = (i, at) => (i === names.length ? evalC(c.c, at, st, m) : keys.every(key => go(i + 1, { ...at, [names[i]]: key })));
349
504
  return go(0, env);
@@ -354,6 +509,11 @@ export function evalC(c, env, st, m) {
354
509
  // (a read reads the machine's functions as they are when it runs, which a table swap changes; a quantified condition and
355
510
  // a function of several arguments go through evalC and evalE). For a term read at many rows (the engine's views).
356
511
  export function compileE(e, m) {
512
+ const run = compileENode(e, m);
513
+ // A get either charges its own node or delegates it to evalE, never both.
514
+ return e.op === 'get' ? run : (env, st) => { observeEval(); return run(env, st); };
515
+ }
516
+ function compileENode(e, m) {
357
517
  switch (e.op) {
358
518
  case 'var': {
359
519
  const name = e.name;
@@ -406,6 +566,7 @@ export function compileE(e, m) {
406
566
  const fn = m.fns?.[map];
407
567
  if (fn?.call && pairedArgs(e.key, fn.arity))
408
568
  return evalE(e, env, st, m);
569
+ observeEval();
409
570
  const k = key(env, st);
410
571
  return fn ? naturalIn(fnOf(fn)(k), `${map}(${k})`) : st.maps[map].get(k) ?? st.defaults?.[map] ?? m.maps[map];
411
572
  };
@@ -413,6 +574,11 @@ export function compileE(e, m) {
413
574
  }
414
575
  }
415
576
  export function compileC(c, m) {
577
+ const run = compileCNode(c, m);
578
+ // Quantified conditions delegate the whole evaluation to the interpreter.
579
+ return c.op === 'all' ? run : (env, st) => { observeEval(); return run(env, st); };
580
+ }
581
+ function compileCNode(c, m) {
416
582
  switch (c.op) {
417
583
  case '<': {
418
584
  const a = compileE(c.a, m), b = compileE(c.b, m);
@@ -450,14 +616,15 @@ export function compileC(c, m) {
450
616
  // same value, which need not be the default), and past it the value is the new default.
451
617
  function writeEvery(w, env, st, m, parts = 1, map) {
452
618
  if (parts > 1) {
453
- const t = eachParts(w, parts), same = map !== undefined && unchanged(t, map, env, st, m);
619
+ const t = tupleOf(w, parts), same = map !== undefined && unchanged(t, map, env, st, m);
454
620
  return same ? { cells: new Map(st.maps[map]), default: st.defaults && Object.hasOwn(st.defaults, map) ? st.defaults[map] : m.maps[map] } : writeEveryTuple(t, env, st, m);
455
621
  }
456
622
  if (!plainKey(w.value, w.each)) {
457
623
  const ks = breakKeys(breaksOf(w.value, w.each), env, st, m), top = ks.at(-1);
458
624
  // (each breakpoint on its own, and each stretch between two at one key of it: no read moves and no comparison turns
459
625
  // inside one, so it holds one value; most stretches hold the default, and a stretch that doesn't is filled)
460
- const at = (key) => evalE(w.value, { ...env, [w.each]: key }, st, m);
626
+ // (one environment for every key, the key written into it: evalE reads its environment and never keeps it)
627
+ const env1 = { ...env }, at = (key) => { env1[w.each] = key; return evalE(w.value, env1, st, m); };
461
628
  const fallback = at(top), cells = new Map();
462
629
  for (let i = 0; i + 1 < ks.length; i++) {
463
630
  const key = ks[i], v = at(key);
@@ -475,28 +642,42 @@ function writeEvery(w, env, st, m, parts = 1, map) {
475
642
  }
476
643
  return { cells, default: fallback };
477
644
  }
478
- const keys = keysAt(st, mapsIn(w.value)), past = keys.at(-1);
479
- const fallback = evalE(w.value, { ...env, [w.each]: past }, st, m), cells = new Map();
645
+ const keys = keysAt(st, mapsIn(w.value)), past = keys.at(-1), env1 = { ...env, [w.each]: past };
646
+ const fallback = evalE(w.value, env1, st, m), cells = new Map();
480
647
  for (const key of keys.slice(0, -1)) {
481
- const v = evalE(w.value, { ...env, [w.each]: key }, st, m);
648
+ env1[w.each] = key;
649
+ const v = evalE(w.value, env1, st, m);
482
650
  if (v !== fallback)
483
651
  cells.set(key, v);
484
652
  }
485
653
  return { cells, default: fallback };
486
654
  }
655
+ const tupleWrites = new WeakMap();
656
+ function tupleOf(w, parts) {
657
+ let byParts = tupleWrites.get(w);
658
+ if (!byParts)
659
+ tupleWrites.set(w, (byParts = new Map()));
660
+ let t = byParts.get(parts);
661
+ if (!t) {
662
+ const e = eachParts(w, parts), body = observeAst(() => ({ op: '=', a: e.value, b: observeAst(() => ({ op: 'const', value: 0 })) })), free = crossFree(body, e.names);
663
+ t = { ...e, bs: e.names.map(name => breaksOf(free, name)), crossed: JSON.stringify(free) !== JSON.stringify(body), reads: new WeakMap() };
664
+ byParts.set(parts, t);
665
+ }
666
+ return t;
667
+ }
487
668
  // A write at every tuple of a map of n parts, read at its parts (kernel.ts's eachParts): each part's breakpoints together
488
669
  // (as a condition at every tuple of keys reads them), every tuple of them, and each stretch between two breakpoints at
489
670
  // one key of it. Past the last breakpoint in any part the value must be the new default (a value other than it along an
490
671
  // unbounded stretch is cells without end), and a stretch filled in two parts or more at once must read no comparison
491
672
  // between the parts (the value along it then depends on more than the stretch).
492
673
  function writeEveryTuple(t, env, st, m) {
493
- const n = t.names.length, body = { op: '=', a: t.value, b: { op: 'const', value: 0 } }, free = crossFree(body, t.names);
494
- const bs = t.names.map(name => breaksOf(free, name));
495
- const crossed = JSON.stringify(free) !== JSON.stringify(body);
674
+ const n = t.names.length, { bs, crossed } = t;
496
675
  // (parts compared with no other part: each on its own breakpoints; else all of them together, n keys after each)
497
676
  const merged = crossed ? spread(breakKeys({ reads: bs.flatMap(b => b.reads), cmps: bs.flatMap(b => b.cmps) }, env, st, m), n) : undefined;
498
677
  const kss = bs.map(b => merged ?? breakKeys(b, env, st, m));
499
- const at = (xs) => evalE(t.value, { ...env, ...Object.fromEntries(t.names.map((name, i) => [name, xs[i]])) }, st, m);
678
+ // (one environment for every tuple, the parts written into it: evalE reads its environment and never keeps it)
679
+ const env1 = { ...env }, at = (xs) => { for (let i = 0; i < n; i++)
680
+ env1[t.names[i]] = xs[i]; return evalE(t.value, env1, st, m); };
500
681
  const fallback = at(kss.map(ks => ks.at(-1))), cells = new Map();
501
682
  // (each key of a part's keys, and after each the stretch up to the next, at its first key: [key, end) with end the
502
683
  // next; the last key stands for every key past it)
@@ -546,7 +727,9 @@ const tupleKey = (xs) => xs.slice(0, -1).reduceRight((b, a) => cpair(a, b), xs.a
546
727
  // decided at the request (the flags, the inputs, the state), is the map's own cell at the tuple of the parts, as read
547
728
  // (M[k]) or as a member (if(1 <= M[k], 1, 0) where every cell is 0 or 1 already). Then no tuple need be visited.
548
729
  function unchanged(t, map, env, st, m) {
549
- const names = new Set(t.names), reads = (u) => JSON.stringify(u).match(/"name":"([^"]+)"/g)?.some(x => names.has(x.slice(8, -1))) ?? false;
730
+ // (whether a condition reads a part is a fact of the term within its write, read once per term)
731
+ const names = new Set(t.names), reads = (u) => { let r = t.reads.get(u); if (r === undefined)
732
+ t.reads.set(u, (r = JSON.stringify(u).match(/"name":"([^"]+)"/g)?.some(x => names.has(x.slice(8, -1))) ?? false)); return r; };
550
733
  const cond = (c) => {
551
734
  if (!reads(c)) {
552
735
  try {
@@ -565,13 +748,13 @@ function unchanged(t, map, env, st, m) {
565
748
  if (typeof v !== 'boolean')
566
749
  xs.push(v);
567
750
  }
568
- return xs.length === 0 ? c.op === 'and' : xs.length === 1 ? xs[0] : { op: c.op, xs };
751
+ return xs.length === 0 ? c.op === 'and' : xs.length === 1 ? xs[0] : observeAst(() => ({ op: c.op, xs }));
569
752
  }
570
753
  return c;
571
754
  };
572
755
  const term = (e) => { if (e.op !== 'if')
573
- return e; const c = cond(e.c); return c === true ? term(e.then) : c === false ? term(e.else) : { ...e, c: c }; };
574
- const v = term(t.value), own = (e) => e.op === 'get' && e.map === map && JSON.stringify(e.key) === JSON.stringify(tuple(t.names.map((name) => ({ op: 'var', name }))));
756
+ return e; const c = cond(e.c); return c === true ? term(e.then) : c === false ? term(e.else) : observeAst(() => ({ ...e, c: c })); };
757
+ const v = term(t.value), own = (e) => e.op === 'get' && e.map === map && JSON.stringify(e.key) === JSON.stringify(tuple(t.names.map((name) => (observeAst(() => ({ op: 'var', name }))))));
575
758
  if (own(v))
576
759
  return true;
577
760
  const zeroOne = () => [...(st.maps[map]?.values() ?? [])].every(x => x === 0 || x === 1) && (st.defaults?.[map] ?? m.maps[map]) <= 1;
@@ -591,7 +774,7 @@ function runnable(m) {
591
774
  export function leastsIn(m, env, st) {
592
775
  const out = {};
593
776
  for (const [name, l] of Object.entries(m.leasts ?? {})) {
594
- const keys = keysAt(st, mapsIn({ op: 'and', xs: [l.where, ...l.by.flatMap(b => [b.e, ...(b.neg ? [b.neg] : [])].map(e => ({ op: '=', a: e, b: e })))] }).filter(mp => !m.fns?.[mp])), past = keys.pop();
777
+ const keys = keysAt(st, mapsIn(observeAst(() => ({ op: 'and', xs: [l.where, ...l.by.flatMap(b => [b.e, ...(b.neg ? [b.neg] : [])].map(e => (observeAst(() => ({ op: '=', a: e, b: e })))))] }))).filter(mp => !m.fns?.[mp])), past = keys.pop();
595
778
  const at = (key) => ({ ...env, ...out, [l.key]: key });
596
779
  if (evalC(l.where, at(past), st, m))
597
780
  throw new RangeError(`${m.name}: ${name} has no least (its condition holds at every key past the cells)`);
@@ -625,7 +808,7 @@ class CountCells extends Map {
625
808
  super.set(x, v);
626
809
  } return v; }
627
810
  }
628
- export function carriedView(m, st, input, rename = map => map, params) {
811
+ export function carriedView(m, st, input, rename = map => map, params, checkpoint) {
629
812
  const counts = Object.entries(m.counts ?? {});
630
813
  if (!m.inputMaps?.length && !counts.length)
631
814
  return st;
@@ -649,8 +832,13 @@ export function carriedView(m, st, input, rename = map => map, params) {
649
832
  maps[rename(c)] = new CountCells(x => {
650
833
  const e1 = d.base ? { ...env0, [d.j]: Math.floor(x / d.base), [d.lo]: x % d.base } : { ...env0, [d.j]: x }, n = evalE(d.below, e1, view, m);
651
834
  let sum = 0;
652
- for (let k = 0; k < n; k++)
835
+ for (let k = 0; k < n; k++) {
836
+ if ((k & 255) === 0) {
837
+ runtimeWall.check?.('derived count');
838
+ checkpoint?.();
839
+ }
653
840
  sum = exact(sum + evalE(d.body, { ...e1, [d.key]: k }, view, m));
841
+ }
654
842
  return sum;
655
843
  });
656
844
  defaults[rename(c)] = 0;
@@ -664,7 +852,7 @@ export const numbersOf = (input) => Object.fromEntries(Object.entries(input).fil
664
852
  // it (a caller that may send one checks first, as gdp-wired/gdp's gate does).
665
853
  const refused = (m) => `${m.name}: the request fails the rule's assumption, so no proof covers the step it would take`;
666
854
  // The interpreter: persistent (a step leaves the state it was given as it was), so searches can branch from any state.
667
- export function interpret(m) {
855
+ export function interpret(m, checkpoint) {
668
856
  const { h, plain, carried } = runnable(m), arity = mapArities(plain);
669
857
  const args = (params, input) => {
670
858
  const env = {};
@@ -675,7 +863,7 @@ export function interpret(m) {
675
863
  env[i] = naturalIn(input[i], `input ${i}`);
676
864
  return env;
677
865
  };
678
- const viewed = (st, input, params) => carriedView(m, st, input, undefined, params);
866
+ const viewed = (st, input, params) => carriedView(m, st, input, undefined, params, checkpoint);
679
867
  // The records a request's queries read: with pruning, those not yet spent at its order.
680
868
  const live = (env, st) => {
681
869
  const records = st.history;
@@ -767,14 +955,24 @@ const RUNTIME = [
767
955
  ['$p', `function $p(a, b) { const s = a + b, v = (s % 2 === 0 ? (s / 2) * (s + 1) : s * ((s + 1) / 2)) + b; if (!Number.isSafeInteger(v)) throw new RangeError('a tuple key passed 2^53 - 1, past which the proofs over the naturals no longer describe the run'); return v; }`],
768
956
  ['$u', `function $u(z) { const tri = t => (t % 2 === 0 ? (t / 2) * (t + 1) : t * ((t + 1) / 2)); let s = Math.floor((Math.sqrt(8 * z + 1) - 1) / 2); while (s > 0 && tri(s) > z) s--; while (tri(s + 1) <= z) s++; const b = z - tri(s); return [s - b, b]; }`],
769
957
  ['$m', `function $m(v, what) { if (!(v instanceof Map)) throw new RangeError(what + ' must be a Map of naturals'); for (const [key, x] of v) { $n(key, 'a key of ' + what); $n(x, 'a cell of ' + what); } return v; }`],
770
- ['$keys', `function $keys(maps, names) { const keys = new Set(); let past = 0; for (const c of Object.values(maps)) for (const key of c.keys()) past = Math.max(past, key + 1); for (const n of names) for (const key of maps[n].keys()) keys.add(key); return [...keys, past]; }`],
771
- ['$breaks', `function $breaks(maps, reads, cmps) { const p = new Set([0]); for (const [n, d, minus] of reads) { for (const s of maps[n].keys()) { if (minus) p.add(s + d); else if (s >= d) p.add(s - d); } if (minus) p.add(d); } for (const [v, d, minus] of cmps) { if (minus) { p.add(v + d); p.add(d); } else if (v >= d) p.add(v - d); } const keys = new Set(); for (const q of p) for (let i = -1; i <= 2; i++) if (q + i >= 0) keys.add(q + i); const sorted = [...keys].sort((a, b) => a - b); sorted.push(sorted[sorted.length - 1] + 1); return sorted; }`],
958
+ // ($unique: the naturals of `vals` (each at most `top`) sorted and made unique. A dense range is marked in a reused
959
+ // stamp buffer and read back in key order, no sort and no Set per step; a sparse one falls back to a Set and a sort.
960
+ // The stamp never reaches 2^32 − 1: at that count the buffer is zeroed and the stamps restart at 1, so a stale mark
961
+ // can never equal a live stamp; a grown buffer starts at 0 likewise.)
962
+ ['$unique', `function $unique(vals, top) { if (top > 4 * vals.length + 64 || top > 1048576) return [...new Set(vals)].sort((a, b) => a - b); let buf = $unique.buf; if (!buf || buf.length <= top) { buf = new Uint32Array(Math.max(top + 1, buf ? 2 * buf.length : 256)); $unique.buf = buf; $unique.stamp = 0; } let s = $unique.stamp + 1; if (s >= 0xFFFFFFFF) { buf.fill(0); s = 1; } $unique.stamp = s; for (let i = 0; i < vals.length; i++) buf[vals[i]] = s; const out = []; for (let i = 0; i <= top; i++) if (buf[i] === s) out.push(i); return out; }`],
963
+ ['$keys', `function $keys(maps, names) { const keys = []; let past = 0; for (const n of Object.keys(maps)) for (const key of maps[n].keys()) if (key + 1 > past) past = key + 1; for (const n of names) for (const key of maps[n].keys()) keys.push(key); const out = $unique(keys, past); out.push(past); return out; }`],
964
+ // ($breaks: every breakpoint q of the reads and comparisons and its neighbours q − 1 .. q + 2, sorted and unique, then one
965
+ // past the last. A dense set is marked straight into $unique's stamp buffer (no array of the neighbours and no second
966
+ // pass); a sparse one goes through $unique's Set path. Both give the same list.)
967
+ ['$breaks', `function $breaks(maps, reads, cmps) { const p = [0]; let top = 0; for (const [n, d, minus] of reads) { for (const s of maps[n].keys()) { const q = minus ? s + d : s - d; if (q >= 0) { p.push(q); if (q > top) top = q; } } if (minus) { p.push(d); if (d > top) top = d; } } for (const [v, d, minus] of cmps) { if (minus) { p.push(v + d); p.push(d); if (v + d > top) top = v + d; } else if (v >= d) { p.push(v - d); if (v - d > top) top = v - d; } } const t2 = top + 2; if (t2 > 16 * p.length + 64 || t2 > 1048576) { const vals = []; for (let j = 0; j < p.length; j++) { const q = p[j]; for (let i = -1; i <= 2; i++) if (q + i >= 0) vals.push(q + i); } const out = $unique(vals, t2); out.push(out[out.length - 1] + 1); return out; } let buf = $unique.buf; if (!buf || buf.length <= t2) { buf = new Uint32Array(Math.max(t2 + 1, buf ? 2 * buf.length : 256)); $unique.buf = buf; $unique.stamp = 0; } let s = $unique.stamp + 1; if (s >= 0xFFFFFFFF) { buf.fill(0); s = 1; } $unique.stamp = s; for (let j = 0; j < p.length; j++) { const q = p[j]; for (let i = q > 0 ? q - 1 : 0; i <= q + 2; i++) buf[i] = s; } const out = []; for (let i = 0; i <= t2; i++) if (buf[i] === s) out.push(i); out.push(out[out.length - 1] + 1); return out; }`],
772
968
  // A condition at every two keys that holds wherever x(k) differs from y(k1): only the pairs whose values match are read.
773
969
  ['$join', `function $join(ks, x, y, f) { const by = new Map(); for (const k1 of ks) { const v = y(k1), l = by.get(v); if (l) l.push(k1); else by.set(v, [k1]); } return ks.every(k => { const l = by.get(x(k)); return l === undefined || l.every(k1 => f(k, k1)); }); }`],
774
- ['$spread', `function $spread(keys, n) { const out = new Set(); for (const k of keys) for (let i = 0; i < n; i++) out.add(k + i); return [...out].sort((a, b) => a - b); }`],
970
+ ['$spread', `function $spread(keys, n) { const vals = []; let top = 0; for (const k of keys) for (let i = 0; i < n; i++) { vals.push(k + i); if (k + i > top) top = k + i; } return $unique(vals, top); }`],
775
971
  // (the interpreter's writeEvery: each breakpoint, and each stretch between two at one key of it, filled only where it
776
972
  // holds other than the value past the last)
777
973
  ['$dense', `function $dense(keys, f) { const top = keys[keys.length - 1], d = f(top), cells = new Map(); for (let i = 0; i + 1 < keys.length; i++) { const key = keys[i], v = f(key); if (v !== d) cells.set(key, v); if (keys[i + 1] > key + 1) { const u = f(key + 1); if (u !== d) { if (keys[i + 1] - key > 1000000) throw new RangeError('a write at every key fills a stretch of more than a million keys (' + (key + 1) + ' to ' + (keys[i + 1] - 1) + ')'); for (let k2 = key + 1; k2 < keys[i + 1]; k2++) cells.set(k2, u); } } } return {cells, d}; }`],
974
+ // (a request's count map in the generated code: each cell its sum, computed when first read, as carriedView's CountCells)
975
+ ['$cells', `class $cells extends Map { constructor(at) { super(); this.at = at; } get(x) { let v = super.get(x); if (v === undefined) { v = this.at(x); super.set(x, v); } return v; } }`],
778
976
  ['$every', `function $every(keys, f) { const past = keys[keys.length - 1], d = f(past), cells = new Map(); for (let i = 0; i < keys.length - 1; i++) { const v = f(keys[i]); if (v !== d) cells.set(keys[i], v); } return {cells, d}; }`],
779
977
  ];
780
978
  function runtimeFor(code) {
@@ -809,10 +1007,10 @@ function joinOf(c, k, k1) {
809
1007
  export function compileJs(m) { return compileJsMode(m, false); }
810
1008
  // fastStep keeps the input state persistent. Its fork can wait until every
811
1009
  // precondition and right-hand side has been evaluated, just before the writes.
812
- function compileJsMode(m, persistent) {
1010
+ function compileJsMode(m, persistent, cells) {
813
1011
  const { h, plain, queries, carried } = runnable(m);
814
1012
  // (a condition or a write at every key over a tuple key: the interpreter decides those, part by part)
815
- const atEvery = [...Object.values(plain.step.flags ?? {}).filter(c => c.op === 'all'), ...Object.values(plain.step.maps ?? {}).filter(w => 'each' in w)];
1013
+ const atEvery = [...Object.values(plain.step.flags ?? {}).filter(c => c.op === 'all' && c.finite === undefined), ...Object.values(plain.step.maps ?? {}).filter(w => 'each' in w)];
816
1014
  const arity = mapArities(plain);
817
1015
  if (JSON.stringify(atEvery).includes('"op":"tup"') || Object.entries(plain.step.maps ?? {}).some(([map, w]) => 'each' in w && (arity[map] ?? 1) > 1))
818
1016
  throw new Error(`${m.name}: compileJs takes no tuple key at every key (interpret runs it)`);
@@ -851,6 +1049,14 @@ function compileJsMode(m, persistent) {
851
1049
  case 'not': return `(!${cx(c.x)})`;
852
1050
  case 'flag': return `flag${flags.indexOf(c.name)}`;
853
1051
  case 'all': {
1052
+ const finite = finiteBound(c);
1053
+ if (finite) {
1054
+ const size = ex(finite), outer = bound;
1055
+ bound = { ...bound, [c.key]: 'fk' };
1056
+ const body = cx(c.c);
1057
+ bound = outer;
1058
+ return `(fn => { $finite(); for (let fk = 0; fk < fn; fk++) { if ((fk & 255) === 0) $finite(); if (!${body}) return false; } return true; })($n(${size}, ${id(`size of ${c.finite}`)}))`;
1059
+ }
854
1060
  const names = boundOf(c), ks = names.map((_, i) => (i ? `k${i}` : 'k')), keys = names.length === 1 ? keysJs(c.c, c.key) : tupleJs(c), outer = bound;
855
1061
  bound = { ...bound, ...Object.fromEntries(names.map((n, i) => [n, ks[i]])) };
856
1062
  const body = cx(c.c);
@@ -889,7 +1095,17 @@ function compileJsMode(m, persistent) {
889
1095
  const parts = names.map(n => breaksOf(body, n));
890
1096
  return `$spread(${breaksJs({ reads: parts.flatMap(b => b.reads), cmps: parts.flatMap(b => b.cmps) })}, ${names.length})`;
891
1097
  };
892
- const every = (w) => { const keys = keysJs(w.value, w.each), dense = !plainKey(w.value, w.each), outer = bound; bound = { [w.each]: 'k' }; const body = ex(w.value); bound = outer; return `${dense ? '$dense' : '$every'}(${keys}, k => ${body})`; };
1098
+ const every = (w, shared) => { const dense = !plainKey(w.value, w.each), keys = shared ?? keysJs(w.value, w.each), outer = bound; bound = { [w.each]: 'k' }; const body = ex(w.value); bound = outer; return `${dense ? '$dense' : '$every'}(${keys}, k => ${body})`; };
1099
+ // Writes at every key with the same breakpoints (the same reads and comparisons) share one list per step, computed once
1100
+ // instead of once per write; a write with breakpoints of its own keeps its own list, since $dense evaluates a write's
1101
+ // value at every key of the list it is given, and a list holding another write's breakpoints would cost it those.
1102
+ const denseWrites = Object.entries(plain.step.maps ?? {}).filter((e) => 'each' in e[1] && !plainKey(e[1].value, e[1].each));
1103
+ const breaksText = new Map(denseWrites.map(([name, w]) => [name, JSON.stringify(breaksOf(w.value, w.each))]));
1104
+ const sharedBreaks = new Map();
1105
+ for (const [text, count] of [...breaksText.values()].reduce((acc, text) => acc.set(text, (acc.get(text) ?? 0) + 1), new Map()))
1106
+ if (count > 1)
1107
+ sharedBreaks.set(text, `bk${sharedBreaks.size}`);
1108
+ const sharedOf = (name) => sharedBreaks.get(breaksText.get(name) ?? '');
893
1109
  const writes = Object.entries(plain.step.maps ?? {});
894
1110
  const env = (input) => `{${[...m.params.map(p => `${id(p)}: $n(params[${id(p)}], ${id(`param ${p}`)})`), ...(input ? carried.map(i => `${id(i)}: $n(input[${id(i)}], ${id(`input ${i}`)})`) : [])].join(', ')}}`;
895
1111
  // Reads go through `maps` (with the maps the request carries); writes go to the state's own.
@@ -908,13 +1124,13 @@ function compileJsMode(m, persistent) {
908
1124
  bound = { ...bound, [l.key]: 'lk' };
909
1125
  const where = cx(l.where), by = l.by.map(b => (b.neg ? `(${ex(b.e)} - ${ex(b.neg)})` : ex(b.e)));
910
1126
  bound = outer;
911
- const ms = mapsIn({ op: 'and', xs: [l.where, ...l.by.flatMap(b => [b.e, ...(b.neg ? [b.neg] : [])].map(e => ({ op: '=', a: e, b: e })))] }).filter(mp => !fns.includes(mp));
1127
+ const ms = mapsIn(observeAst(() => ({ op: 'and', xs: [l.where, ...l.by.flatMap(b => [b.e, ...(b.neg ? [b.neg] : [])].map(e => (observeAst(() => ({ op: '=', a: e, b: e })))))] }))).filter(mp => !fns.includes(mp));
912
1128
  const better = l.by.map((b, i) => `by[${i}] !== bb[${i}] ? by[${i}] ${b.desc ? '>' : '<'} bb[${i}] : `).join('') + 'false';
913
1129
  lines.push(`{ const ks = $keys(maps, ${JSON.stringify(ms)}), past = ks.pop(); let lk = past; if (${where}) throw new RangeError(${id(`${m.name}: ${name} has no least (its condition holds at every key past the cells)`)}); let bk, bb; for (lk of ks.sort((a, b) => a - b)) { if (!(${where})) continue; const by = [${by.join(', ')}]; if (bk === undefined || (${better})) { bk = lk; bb = by; } } env[${id(name)}] = bk ?? 0; env[${id(l.some)}] = bk === undefined ? 0 : 1; }`);
914
1130
  }
915
1131
  lines.push(...flags.map((name, i) => `const flag${i} = ${cx(plain.step.flags[name])};`),
916
1132
  // The rule's own assumption, as `allowed` (core/watch.ts) reads it (a history's machine assumes more: its relations).
917
- ...(m.assume ? [`if (!${cx(m.assume)}) throw new RangeError(${id(refused(m))});`] : []), `const scalars = {...s, ${Object.entries(plain.step.state ?? {}).map(([name, e]) => `${id(name)}: ${ex(e)}`).join(', ')}};`, ...writes.map(([, w], i) => ('each' in w ? `const write${i} = ${every(w)};` : `const key${i} = ${ex(w.key)}, value${i} = ${ex(w.value)};`)));
1133
+ ...(m.assume ? [`if (!${cx(m.assume)}) throw new RangeError(${id(refused(m))});`] : []), `const scalars = {...s, ${Object.entries(plain.step.state ?? {}).map(([name, e]) => `${id(name)}: ${ex(e)}`).join(', ')}};`, ...[...sharedBreaks].map(([text, bk]) => `const ${bk} = ${breaksJs(JSON.parse(text))};`), ...writes.map(([name, w], i) => ('each' in w ? `const write${i} = ${every(w, sharedOf(name))};` : `const key${i} = ${ex(w.key)}, value${i} = ${ex(w.value)};`)));
918
1134
  if (h)
919
1135
  lines.push(`const keep = ${cx(h.keep)};`);
920
1136
  if (persistent)
@@ -927,14 +1143,32 @@ function compileJsMode(m, persistent) {
927
1143
  else
928
1144
  lines.push('return Object.keys(dft).length ? {scalars, maps: state.maps, defaults: dft} : {scalars, maps: state.maps};');
929
1145
  const fnDefs = fns.map((name, i) => `const fn${i} = (${m.fns[name].js});\n${m.fns[name].call ? `const fnc${i} = (${m.fns[name].call});\n` : ''}`).join('');
930
- const code = `export function init(params) {
1146
+ // The request's counts (carriedView's CountCells, compiled): the view's maps (the state's, the maps the request carries as
1147
+ // given — the step validates them before any write, so a bad one still ends in its RangeError —,
1148
+ // then each count as a $cells whose cell at x is the sum of its body over the keys below its bound, read through the same
1149
+ // view, so a count's body may read another count), as the step reads them through `input`.
1150
+ const cellsCode = cells ? `export function cells(params, state, input, tick) {
1151
+ const env = ${env(true)}, s = state.scalars, dft = {...state.defaults}, maps = {...state.maps${cells.inputMaps.map(mp => `, ${id(mp)}: input[${id(mp)}]`).join('')}};
1152
+ ${Object.entries(cells.decls).map(([c, d]) => {
1153
+ const outer = bound;
1154
+ bound = { ...bound, [d.j]: 'cj', ...(d.base ? { [d.lo]: 'clo' } : {}) };
1155
+ const below = ex(d.below);
1156
+ bound = { ...bound, [d.key]: 'ck' };
1157
+ const body = ex(d.body);
1158
+ bound = outer;
1159
+ return `maps[${id(c)}] = new $cells(x => { const cj = ${d.base ? `Math.floor(x / ${d.base}), clo = x % ${d.base}` : 'x'}; const n = ${below}; let sum = 0; for (let ck = 0; ck < n; ck++) { if ((ck & 255) === 0) tick(); sum = $x(sum + ${body}); } return sum; });`;
1160
+ }).join('\n ')}
1161
+ return maps;
1162
+ }
1163
+ ` : '';
1164
+ const code = `${cellsCode}export function init(params) {
931
1165
  const env = ${env(false)}, s = {};
932
1166
  return {scalars: {${Object.entries(plain.state).map(([name, e]) => `${id(name)}: ${ex(e)}`).join(', ')}}, maps: {${Object.keys(plain.maps ?? {}).map(name => `${id(name)}: new Map()`).join(', ')}}${h ? ', history: [], head: 0' : ''}};
933
1167
  }
934
1168
  export function fork(state) {
935
1169
  return {scalars: {...state.scalars}, maps: Object.fromEntries(Object.entries(state.maps).map(([name, cells]) => [name, new Map(cells)])), ...(state.defaults ? {defaults: {...state.defaults}} : {})${h ? ', history: state.history.slice(state.head), head: 0, last: state.last' : ''}};
936
1170
  }
937
- export function step(params, state, input) {
1171
+ export function step(params, state, input${hasFinite(plain) ? ', $finite = () => { throw new Error("finite sort step requires a cancellation callback"); }' : ''}) {
938
1172
  ${lines.join('\n ')}
939
1173
  }
940
1174
  `;
@@ -949,24 +1183,66 @@ export function compileFunction(params, body) {
949
1183
  return new Function(...params, body);
950
1184
  }
951
1185
  export const loadJs = (m) => loadJsMode(m, false);
952
- const loadJsMode = (m, persistent) => compileFunction([], `${compileJsMode(m, persistent).replace(/^export function/gm, 'function')}\nreturn {init, fork, step}`)();
1186
+ const loadJsMode = (m, persistent, cells) => {
1187
+ const js = compileFunction([], `${compileJsMode(m, persistent, cells).replace(/^export function/gm, 'function')}\nreturn {init, fork, step${cells ? ', cells' : ''}}`)();
1188
+ if (hasFinite(m)) {
1189
+ // Standalone generated modules require an explicit cooperative callback.
1190
+ // The loaded runtime uses the same cancellation bridge as the interpreter.
1191
+ const step = js.step;
1192
+ js.step = (params, st, input, check = () => runtimeWall.check?.('finite quantifier')) => step(params, st, input, check);
1193
+ }
1194
+ return js;
1195
+ };
953
1196
  // The interpreter's step (persistent: a copy of the state each) through loadJs's, several times faster, a request's counts
954
1197
  // given to it as maps the request carries (carriedView's, each cell its sum when read); none with a history, or where the
955
1198
  // generator refuses the machine.
956
1199
  export function fastStep(m) {
957
- const cs = Object.keys(m.counts ?? {});
1200
+ // Its static per-step charge cannot account for a parameter-sized loop.
1201
+ // Proof-time callers must use the interruptible, per-node interpreter instead.
1202
+ if (hasFinite(m))
1203
+ return undefined;
1204
+ // (the counts the step itself reads, in its guards, flags, writes or assumption: a count only a law reads is never
1205
+ // computed for a step; a count's body may read another count, so the closure is taken)
1206
+ const all = m.counts ?? {}, read = new Set();
1207
+ walk([m.step, m.assume ?? null, m.pre ?? null], o => { if (o.op === 'get' && o.map in all)
1208
+ read.add(o.map); });
1209
+ for (let grew = true; grew;) {
1210
+ grew = false;
1211
+ for (const c of [...read])
1212
+ walk([all[c].below, all[c].body], o => { if (o.op === 'get' && o.map in all && !read.has(o.map)) {
1213
+ read.add(o.map);
1214
+ grew = true;
1215
+ } });
1216
+ }
1217
+ const cs = Object.keys(all).filter(c => read.has(c));
958
1218
  let js;
1219
+ const decls = Object.fromEntries(cs.map(c => [c, all[c]]));
1220
+ // (the counts compiled with the step, unless the machine has least keys, whose names the step alone computes)
1221
+ const compiledCells = cs.length && !Object.keys(m.leasts ?? {}).length;
959
1222
  try {
960
1223
  if (m.history)
961
1224
  return undefined;
962
- js = loadJsMode({ ...m, counts: undefined, inputMaps: [...m.inputMaps ?? [], ...cs] }, true);
1225
+ js = loadJsMode({ ...m, counts: undefined, inputMaps: [...m.inputMaps ?? [], ...cs] }, true, compiledCells ? { decls, inputMaps: m.inputMaps ?? [] } : undefined);
963
1226
  }
964
1227
  catch {
965
1228
  return undefined;
966
1229
  }
1230
+ let stepEvals = 0;
1231
+ walk([m.step, m.assume ?? null, m.leasts ?? null], o => { if (typeof o.op === 'string')
1232
+ stepEvals++; });
1233
+ const only = cs.length ? { ...m, counts: decls } : m, tick = () => { if (completeWorkProfile.enabled)
1234
+ startWork('ticks', 1, 'derived count');
1235
+ else
1236
+ coreMeter.ticks += 1; runtimeWall.check?.('derived count'); };
967
1237
  return (params, st, input) => {
968
- const view = cs.length ? carriedView(m, st, input, undefined, params).maps : {};
969
- return js.step(params, st, cs.length ? { ...input, ...Object.fromEntries(cs.map(c => [c, view[c]])) } : input);
1238
+ // Section 18's static expression-node charge per compiled step invocation.
1239
+ observeEval(stepEvals, true);
1240
+ if (!cs.length)
1241
+ return js.step(params, st, input);
1242
+ const view = compiledCells ? js.cells(params, st, input, tick) : carriedView(only, st, input, undefined, params).maps, carried = { ...input };
1243
+ for (const c of cs)
1244
+ carried[c] = view[c];
1245
+ return js.step(params, st, carried);
970
1246
  };
971
1247
  }
972
1248
  const cross = (as, f) => as.flatMap(a => f(a.value).map(b => ({ path: [...a.path, ...b.path], value: b.value })));
@@ -1045,7 +1321,7 @@ function symC(c, s, truth) {
1045
1321
  // PROVE_DEBUG=1 logs the case counts to stderr; read through globalThis so the module also loads where there is no process.
1046
1322
  const proveDebug = !!env.PROVE_DEBUG;
1047
1323
  const debug = (label, n) => { if (proveDebug)
1048
- console.error(`[prove] ${label}: ${n} (${Math.round(performance.now())} ms)`); };
1324
+ console.error(`[prove] ${label}: ${n} (${Math.round(traceNow())} ms)`); };
1049
1325
  // Drops the cases whose path is already impossible, so impossible branches don't multiply.
1050
1326
  function feasible(cases) {
1051
1327
  return cases.filter(c => {
@@ -1127,8 +1403,8 @@ export function prove(m, goal, invariants = [goal]) {
1127
1403
  // Keys first: how each key the step reads or writes compares with each focus key of the same map, decided once.
1128
1404
  const stepReads = [
1129
1405
  ...Object.values(m.step.flags ?? {}).flatMap(readsOf),
1130
- ...Object.values(m.step.state ?? {}).flatMap(e => readsOf({ op: '=', a: e, b: e })),
1131
- ...Object.entries(m.step.maps ?? {}).flatMap(([map, w]) => [...('each' in w ? [] : [{ map, key: w.key }]), ...readsOf({ op: '=', a: w.value, b: w.value })]),
1406
+ ...Object.values(m.step.state ?? {}).flatMap(e => readsOf(observeAst(() => ({ op: '=', a: e, b: e })))),
1407
+ ...Object.entries(m.step.maps ?? {}).flatMap(([map, w]) => [...('each' in w ? [] : [{ map, key: w.key }]), ...readsOf(observeAst(() => ({ op: '=', a: w.value, b: w.value })))]),
1132
1408
  ];
1133
1409
  const pairs = new Map();
1134
1410
  for (const r of stepReads) {
@@ -1206,6 +1482,9 @@ function renameKey(lin, from, to) {
1206
1482
  export function search(m, law, depth = 3, bound = 2) {
1207
1483
  const run = interpret(m);
1208
1484
  const holds = (params, st) => {
1485
+ const finite = finiteLawBound(law);
1486
+ if (finite)
1487
+ return evalC({ op: 'all', key: law.forall, c: law.holds, finite: law.finite }, params, st, m);
1209
1488
  const keys = law.forall ? [...new Set([0, ...Object.values(st.maps).flatMap(cells => [...cells.keys()])])] : [0];
1210
1489
  return keys.every(key => evalC(law.holds, { ...params, ...(law.forall ? { [law.forall]: key } : {}) }, st, m));
1211
1490
  };