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
@@ -18,7 +18,12 @@
18
18
  // meet it), so it holds at the start and at every step; `assume`, about each request, holds only at a step, since no
19
19
  // request has come at the start.
20
20
  import { checkRefutation } from "../core/check.js";
21
- import { add, k, scale, sub, v } from "../core/solver.js";
21
+ import { observeCheckStep, observeTableCells } from "../core/meter.js";
22
+ import { admittedLinearSub as rowSub, admittedLinearAdd as rowAdd, admittedLinearScale as rowScale, admittedLinearCopy as rowCopy, admittedLinearVariable as rowVariable, visitLinearCells } from "../core/linear-admission.js";
23
+ import { fundedAdd as add, fundedConstant as k, fundedScale as scale, fundedSub as sub, fundedVariable as v, admittedLinearProduct, everyLinearCell } from "../core/linear-admission.js";
24
+ import { workMap, workFilter, workConcat, workStrings, workJoin, workSlice, workSetArray, workEntries, workJSON, workFlatMap, workArraySlice } from "../core/work-collections.js";
25
+ import { completeWorkProfile } from "../core/work-profile.js";
26
+ import { startWork } from "../core/work-admission.js";
22
27
  // An exhaustive switch's default: TypeScript proves it unreachable, and if it is reached anyway (a value from outside
23
28
  // the types), it fails loudly instead of returning undefined.
24
29
  export function unreachable(value) { throw new Error(`unhandled case: ${JSON.stringify(value)}`); }
@@ -32,26 +37,34 @@ export const part = (key, i, n) => { let e = key; for (let j = 0; j < i; j++)
32
37
  // (Remembered per linear form: a form is never changed once built, and the same forms are looked up at every node.)
33
38
  const canonMemo = new WeakMap(), flipMemo = new WeakMap();
34
39
  export const canon = (lin) => {
40
+ observeTableCells();
35
41
  let out = canonMemo.get(lin);
36
- if (out === undefined)
37
- canonMemo.set(lin, (out = Object.keys(lin).sort().map(key => `${key}:${lin[key]}`).join(',')));
42
+ if (out === undefined) {
43
+ const keys = [], values = new Map();
44
+ visitLinearCells(lin, (key, value) => { keys.push(key); values.set(key, value); }, 'canon:keys');
45
+ const parts = workMap(workStrings(keys, 'canon:sort'), key => { observeTableCells(key.length + 1); return `${key}:${values.get(key)}`; }, 'canon:format');
46
+ canonMemo.set(lin, (out = workJoin(parts, ',', 'canon:join')));
47
+ }
38
48
  return out;
39
49
  };
40
50
  // canon(1 − lin), the atom that decides lin <= 0 the other way, without building it.
41
51
  export const canonFlip = (lin) => {
52
+ observeTableCells();
42
53
  let out = flipMemo.get(lin);
43
54
  if (out !== undefined)
44
55
  return out;
45
- const keys = Object.keys(lin);
46
- if (!('1' in lin))
56
+ const keys = [], values = new Map();
57
+ visitLinearCells(lin, (key, value) => { keys.push(key); values.set(key, value); }, 'canonFlip:keys');
58
+ if (!values.has('1'))
47
59
  keys.push('1');
48
60
  const parts = [];
49
- for (const key of keys.sort()) {
50
- const c = key === '1' ? 1 - (lin['1'] ?? 0) : -lin[key];
61
+ for (const key of workStrings(keys, 'canonFlip:sort')) {
62
+ observeTableCells(key.length + 1);
63
+ const c = key === '1' ? 1 - (values.get('1') ?? 0) : -values.get(key);
51
64
  if (c !== 0)
52
65
  parts.push(`${key}:${c}`);
53
66
  }
54
- flipMemo.set(lin, (out = parts.join(',')));
67
+ flipMemo.set(lin, (out = workJoin(parts, ',', 'canonFlip:join')));
55
68
  return out;
56
69
  };
57
70
  export const atomOf = (lin, holds) => ({ lin: holds ? lin : add(k(1), scale(lin, -1)), label: '' });
@@ -60,8 +73,10 @@ export const atomOf = (lin, holds) => ({ lin: holds ? lin : add(k(1), scale(lin,
60
73
  // A form with a coefficient past a safe integer decides nothing: it may be a rounded difference, and its flip is
61
74
  // rounded again (1 - (2^53 + 1) reads as the safe 1 - 2^53), so an atom about another form would decide it.
62
75
  function decide(lin, path) {
76
+ observeTableCells();
63
77
  let constant = true;
64
78
  for (const key in lin) {
79
+ observeTableCells(key.length + 1);
65
80
  if (!Number.isSafeInteger(lin[key]))
66
81
  return undefined;
67
82
  if (key !== '1')
@@ -87,6 +102,7 @@ const look = (path, key) => { const out = path.get(key)?.holds; if (recording)
87
102
  const linearMemo = new WeakMap();
88
103
  const freeMemo = new WeakMap(), freeLinear = new WeakMap();
89
104
  const choiceFree = (e) => {
105
+ startWork('ticks', 1, 'kernel choiceFree');
90
106
  let out = freeMemo.get(e);
91
107
  if (out !== undefined)
92
108
  return out;
@@ -120,6 +136,7 @@ const choiceFree = (e) => {
120
136
  return out;
121
137
  };
122
138
  export function linear(e, path) {
139
+ startWork('ticks', 1, 'kernel linear');
123
140
  if (choiceFree(e)) {
124
141
  if (freeLinear.has(e))
125
142
  return freeLinear.get(e);
@@ -144,7 +161,7 @@ function linearOf(e, path) {
144
161
  const out = linearOp(e, path);
145
162
  return out && safe(out) ? out : undefined;
146
163
  }
147
- const safe = (lin) => Object.values(lin).every(c => Number.isSafeInteger(c));
164
+ const safe = (lin) => everyLinearCell(lin, (_key, c) => Number.isSafeInteger(c), 'linear safety');
148
165
  function linearOp(e, path) {
149
166
  switch (e.op) {
150
167
  case 'var': return e.name === '1' || /[*[\],:⟦⟨⟩|]/.test(e.name) ? undefined : v(e.name); // those characters build cells, monomials, term columns and tuple keys
@@ -210,7 +227,7 @@ export const plainMap = (name) => { let ok = plainMaps.get(name); if (ok === und
210
227
  function keyParts(e, path) {
211
228
  if (e.op === 'proj') {
212
229
  const ps = e.k === 0 ? undefined : keyParts(e.a, path);
213
- return ps && ps.length >= 3 ? ps.slice(1) : undefined;
230
+ return ps && ps.length >= 3 ? workArraySlice(ps, 1, 'keyParts:rest') : undefined;
214
231
  }
215
232
  if (e.op !== 'tup')
216
233
  return undefined;
@@ -232,11 +249,19 @@ function keyParts(e, path) {
232
249
  // deep term (a k-step run nests k steps) is read once, not once per lookup.
233
250
  const termIds = new Map(), termTable = [], memo = new WeakMap();
234
251
  function termId(t) {
252
+ startWork('ticks', 1, 'kernel termId');
235
253
  const had = memo.get(t);
236
254
  if (had !== undefined)
237
255
  return had;
238
- const parts = Object.entries(t).sort(([x], [y]) => (x < y ? -1 : x > y ? 1 : 0)).map(([key, val]) => (Array.isArray(val) ? `${key}=[${val.map(x => termId(x)).join(',')}]` : typeof val === 'object' && val !== null ? `${key}=#${termId(val)}` : `${key}=${JSON.stringify(val)}`));
239
- const key = parts.join(';');
256
+ const entries = workEntries(t, 'termId:members'), values = new Map(entries);
257
+ const keys = workStrings(workMap(entries, entry => entry[0], 'termId:keys'), 'termId:sort');
258
+ const parts = workMap(keys, key => {
259
+ const val = values.get(key);
260
+ if (Array.isArray(val))
261
+ return `${key}=[${workJoin(workMap(val, x => String(termId(x)), 'termId:array'), ',', 'termId:array-join')}]`;
262
+ return typeof val === 'object' && val !== null ? `${key}=#${termId(val)}` : `${key}=${workJSON(val, 'termId:scalar')}`;
263
+ }, 'termId:parts');
264
+ const key = workJoin(parts, ';', 'termId:join');
240
265
  let id = termIds.get(key);
241
266
  if (id === undefined) {
242
267
  id = termTable.length;
@@ -247,6 +272,10 @@ function termId(t) {
247
272
  return id;
248
273
  }
249
274
  export const termColumn = (e) => `⟦${termId(e)}⟧`;
275
+ // Output-only state: certificate columns contain these process-local ordinals.
276
+ // Copies protect the table; obtaining a snapshot never registers a new term.
277
+ export const snapshotKernelTermState = () => ({ terms: termTable.slice(), identities: [...termIds] });
278
+ export const snapshotKernelTermMemo = (object) => memo.get(object);
250
279
  export const columnTerm = (name) => { const m = /^⟦(\d+)⟧$/.exec(name); return m ? termTable[Number(m[1])] : undefined; };
251
280
  // Whether the path decides a choice's top (an if's condition, which side of min, max or ∸).
252
281
  export function decided(e, path) {
@@ -260,30 +289,30 @@ export function decided(e, path) {
260
289
  // The rows a term column brings: its bounds, true whichever way the choice goes (min(a, b) ≤ a and ≤ b; max(a, b) ≥ a
261
290
  // and ≥ b; a ∸ b ≥ a − b and ≤ a), and, once the path decides it, its equality to the branch taken.
262
291
  export function termRows(name, path) {
263
- const e = columnTerm(name), col = v(name), out = [];
292
+ const e = columnTerm(name), col = rowVariable(name, 1, 'termRows:column'), out = [];
264
293
  if (e.op === 'min' || e.op === 'max' || e.op === 'sub') {
265
294
  const a = linear(e.a, path), b = linear(e.b, path);
266
295
  if (a && b) {
267
296
  if (e.op === 'min')
268
- out.push(sub(col, a), sub(col, b));
297
+ out.push(rowSub(col, a, 'termRows:min-left'), rowSub(col, b, 'termRows:min-right'));
269
298
  if (e.op === 'max')
270
- out.push(sub(a, col), sub(b, col));
299
+ out.push(rowSub(a, col, 'termRows:max-left'), rowSub(b, col, 'termRows:max-right'));
271
300
  if (e.op === 'sub')
272
- out.push(sub(sub(a, b), col), sub(col, a));
301
+ out.push(rowSub(rowSub(a, b, 'termRows:subtract-inputs'), col, 'termRows:subtract-bound'), rowSub(col, a, 'termRows:subtract-upper'));
273
302
  }
274
303
  }
275
304
  // An if is one of its two naturals, so at most their sum, whichever way its condition goes (a yes/no's if(c, 1, 0)
276
305
  // is at most 1 without deciding c). Only over constant branches: over a variable one (a map's if(c, Given[k], 0)),
277
306
  // each such row is one more in every leaf and slows the solve more than it saves.
278
307
  if (e.op === 'if') {
279
- const a = linear(e.then, path), b = linear(e.else, path), constant = (l) => Object.entries(l).every(([key, c]) => key === '1' || c === 0);
308
+ const a = linear(e.then, path), b = linear(e.else, path), constant = (l) => everyLinearCell(l, (key, c) => key === '1' || c === 0, 'constant branch');
280
309
  if (a && b && constant(a) && constant(b))
281
- out.push(sub(col, add(a, b)));
310
+ out.push(rowSub(col, rowAdd(a, b, 'termRows:if-sum'), 'termRows:if-bound'));
282
311
  }
283
312
  if (decided(e, path)) {
284
313
  const r = linear(e, path);
285
314
  if (r)
286
- out.push(sub(col, r), sub(r, col));
315
+ out.push(rowSub(col, r, 'termRows:equal-left'), rowSub(r, col, 'termRows:equal-right'));
287
316
  }
288
317
  return out;
289
318
  }
@@ -295,9 +324,18 @@ export function termRows(name, path) {
295
324
  // Every coefficient, product and partial sum a safe integer, else no product: a rounded product is past 2^53, but a
296
325
  // monomial's other products could bring its sum back under it (and a square's form is the prover's, any float).
297
326
  function times(a, b) {
327
+ if (completeWorkProfile.enabled)
328
+ return admittedLinearProduct(a, b, (p, q) => {
329
+ if (p.includes('⟦') || q.includes('⟦'))
330
+ return undefined;
331
+ const fs = workStrings(workConcat(p === '1' ? [] : factorsOf(p), q === '1' ? [] : factorsOf(q), 'product:factors'), 'product:sort');
332
+ return fs.length ? workJoin(fs, '*', 'product:join') : '1';
333
+ }, 'kernel product', true);
298
334
  const out = Object.create(null);
299
- for (const [p, cp] of Object.entries(a))
300
- for (const [q, cq] of Object.entries(b)) {
335
+ for (const p in a)
336
+ for (const q in b) {
337
+ observeTableCells();
338
+ const cp = a[p], cq = b[q];
301
339
  if (p.includes('⟦') || q.includes('⟦'))
302
340
  return undefined;
303
341
  const fs = [...(p === '1' ? [] : factorsOf(p)), ...(q === '1' ? [] : factorsOf(q))].sort(), key = fs.length ? fs.join('*') : '1', c = (out[key] ?? 0) + cp * cq;
@@ -305,9 +343,11 @@ function times(a, b) {
305
343
  return undefined;
306
344
  out[key] = c;
307
345
  }
308
- for (const key in out)
346
+ for (const key in out) {
347
+ observeTableCells();
309
348
  if (out[key] === 0)
310
349
  delete out[key];
350
+ }
311
351
  return out;
312
352
  }
313
353
  // A name's factors: split at each '*' outside a cell's brackets (a cell's key may itself read a monomial).
@@ -319,13 +359,14 @@ export function factorsOf(name) {
319
359
  out = [];
320
360
  let depth = 0, start = 0;
321
361
  for (let i = 0; i <= name.length; i++) {
362
+ observeTableCells();
322
363
  const ch = name[i];
323
364
  if (ch === '[')
324
365
  depth++;
325
366
  else if (ch === ']')
326
367
  depth--;
327
368
  else if ((ch === '*' && depth === 0) || i === name.length) {
328
- out.push(name.slice(start, i));
369
+ out.push(workSlice(name, start, i, 'factor slice'));
329
370
  start = i + 1;
330
371
  }
331
372
  }
@@ -372,6 +413,7 @@ function comparisonOf(c, path) {
372
413
  // Kleene truth under the path: true, false, or undefined when open (remembered per path and condition).
373
414
  const truthMemo = new WeakMap();
374
415
  export function truth(c, path) {
416
+ startWork('ticks', 1, 'kernel truth');
375
417
  if (reuse)
376
418
  return reusing(seenOf(truthSeen, c), path, p => truthOf(c, p));
377
419
  let memo = truthMemo.get(path);
@@ -393,7 +435,7 @@ function truthOf(c, path) {
393
435
  }
394
436
  case 'and':
395
437
  case 'or': {
396
- const ts = c.xs.map(y => truth(y, path)), dominant = c.op === 'or';
438
+ const ts = workMap(c.xs, y => truth(y, path), 'truth:children'), dominant = c.op === 'or';
397
439
  return ts.includes(dominant) ? dominant : ts.every(t => t === !dominant) ? !dominant : undefined;
398
440
  }
399
441
  case '<':
@@ -435,6 +477,7 @@ export function tupleEq(c) {
435
477
  }
436
478
  // The linear facts a hypothesis gives under the path (each lin <= 0).
437
479
  export function facts(c, path, positive = true) {
480
+ startWork('ticks', 1, 'kernel facts');
438
481
  switch (c.op) {
439
482
  case 'flag': throw new Error('flags are inlined before the kernel sees them');
440
483
  case 'all': return [];
@@ -442,8 +485,8 @@ export function facts(c, path, positive = true) {
442
485
  case 'and':
443
486
  case 'or': {
444
487
  if ((c.op === 'and') === positive)
445
- return c.xs.flatMap(y => facts(y, path, positive));
446
- const open = c.xs.filter(y => truth(y, path) !== !positive);
488
+ return workFlatMap(c.xs, y => facts(y, path, positive), 'facts:conjunction');
489
+ const open = workFilter(c.xs, y => truth(y, path) !== !positive, 'facts:disjunction');
447
490
  return open.length === 0 ? [k(1)] : open.length === 1 ? facts(open[0], path, positive) : [];
448
491
  }
449
492
  case '<':
@@ -453,8 +496,8 @@ export function facts(c, path, positive = true) {
453
496
  const parts = tupleEq(c);
454
497
  if (parts) {
455
498
  if (positive)
456
- return [...facts(parts[0], path, true), ...facts(parts[1], path, true)];
457
- const open = parts.filter(y => truth(y, path) !== true);
499
+ return workConcat(facts(parts[0], path, true), facts(parts[1], path, true), 'facts:tuple');
500
+ const open = workFilter(parts, y => truth(y, path) !== true, 'facts:tuple-open');
458
501
  return open.length === 0 ? [k(1)] : open.length === 1 ? facts(open[0], path, false) : [];
459
502
  }
460
503
  const cmp = comparison(c, path);
@@ -550,40 +593,50 @@ const linearSeen = new WeakMap(), comparisonSeen = new WeakMap(), truthSeen = ne
550
593
  const seenOf = (m, k) => { let s = m.get(k); if (!s)
551
594
  m.set(k, (s = {})); return s; };
552
595
  function leafRows(goal, path, factsOf) {
553
- const rows = [...path.values()].map((a, i) => ({ ...atomOf(a.lin, a.holds), src: { atom: i } }));
596
+ const rows = [];
597
+ let atom = 0;
598
+ for (const a of path.values()) {
599
+ const lin = a.holds ? rowCopy(a.lin, 'leafRows:atom-copy') : rowAdd(rowVariable('1', 1, 'leafRows:atom-one'), rowScale(a.lin, -1, 'leafRows:atom-negate'), 'leafRows:atom-flip');
600
+ rows.push({ lin, label: '', src: { atom: atom++ } });
601
+ }
554
602
  for (const [i, h] of goal.hyps.entries())
555
603
  for (const lin of factsOf(h))
556
- rows.push({ lin, label: '', src: { fact: i } });
557
- const names = new Set(rows.flatMap(r => Object.keys(r.lin).filter(key => key !== '1')));
604
+ rows.push({ lin: rowCopy(lin, 'leafRows:fact'), label: '', src: { fact: i } });
605
+ const names = new Set();
606
+ for (const row of rows)
607
+ visitLinearCells(row.lin, key => { if (key !== '1')
608
+ names.add(key); }, 'leafRows:names');
558
609
  // Two reads of one map whose keys the path proves equal are equal.
559
- const cells = [...names].filter(isCell).map(name => ({ name, ...cellParts(name) }));
560
- for (const [i, p] of cells.entries())
561
- for (const q of cells.slice(i + 1)) {
610
+ const cells = workMap(workFilter(workSetArray(names, 'leafRows:names-copy'), isCell, 'leafRows:cell-filter'), name => ({ name, ...cellParts(name) }), 'leafRows:cell-parts');
611
+ for (let i = 0; i < cells.length; i++)
612
+ for (let j = i + 1; j < cells.length; j++) {
613
+ const p = cells[i], q = cells[j];
614
+ observeTableCells();
562
615
  if (p.map !== q.map)
563
616
  continue;
564
617
  if (!sameKey(p, q, path))
565
618
  continue;
566
- rows.push({ lin: sub(v(p.name), v(q.name)), label: '', src: { pair: [p.name, q.name] } }, { lin: sub(v(q.name), v(p.name)), label: '', src: { pair: [p.name, q.name] } });
619
+ const pRow = rowVariable(p.name, 1, 'leafRows:pair-p'), qRow = rowVariable(q.name, 1, 'leafRows:pair-q');
620
+ rows.push({ lin: rowSub(pRow, qRow, 'leafRows:pair-left'), label: '', src: { pair: [p.name, q.name] } }, { lin: rowSub(qRow, pRow, 'leafRows:pair-right'), label: '', src: { pair: [p.name, q.name] } });
567
621
  }
568
622
  // Each term column's rows, and the columns those rows bring in turn.
569
- const seen = new Set(), todo = [...names].filter(n => n.startsWith('⟦'));
623
+ const seen = new Set(), todo = workFilter(workSetArray(names, 'leafRows:todo-copy'), n => n.startsWith('⟦'), 'leafRows:todo-filter');
570
624
  while (todo.length) {
571
625
  const name = todo.pop();
572
626
  if (seen.has(name))
573
627
  continue;
574
628
  seen.add(name);
575
629
  for (const lin of termRows(name, path)) {
576
- rows.push({ lin, label: '', src: { term: name } });
577
- for (const key of Object.keys(lin))
578
- if (key !== '1') {
579
- names.add(key);
580
- if (key.startsWith('⟦') && !seen.has(key))
581
- todo.push(key);
582
- }
630
+ rows.push({ lin: rowCopy(lin, 'leafRows:term'), label: '', src: { term: name } });
631
+ visitLinearCells(lin, key => { if (key !== '1') {
632
+ names.add(key);
633
+ if (key.startsWith('⟦') && !seen.has(key))
634
+ todo.push(key);
635
+ } }, 'leafRows:term-names');
583
636
  }
584
637
  }
585
638
  for (const name of names)
586
- rows.push({ lin: { [name]: -1 }, label: '', src: { nat: name } });
639
+ rows.push({ lin: rowVariable(name, -1, 'leafRows:natural'), label: '', src: { nat: name } });
587
640
  return rows;
588
641
  }
589
642
  // A cell's map and key: M[k] a key, M[⟨k1|k2|…⟩] a tuple's parts (each a canonical text). Split at the outer level only:
@@ -591,6 +644,7 @@ function leafRows(goal, path, factsOf) {
591
644
  // (kept per name: every leaf reads its cells' keys again; a form is never changed once built)
592
645
  const cellMemo = new Map();
593
646
  export function cellParts(cell) {
647
+ observeTableCells();
594
648
  let out = cellMemo.get(cell);
595
649
  if (!out) {
596
650
  if (cellMemo.size > 200_000)
@@ -609,6 +663,7 @@ const splitOuter = (text, sep) => {
609
663
  const parts = [];
610
664
  let depth = 0, start = 0;
611
665
  for (let i = 0; i <= text.length; i++) {
666
+ observeTableCells();
612
667
  const ch = text[i];
613
668
  if (ch === '[' || ch === '⟨')
614
669
  depth++;
@@ -625,11 +680,11 @@ const splitOuter = (text, sep) => {
625
680
  const linOf = (text) => {
626
681
  const out = Object.create(null);
627
682
  for (const part of splitOuter(text, ','))
628
- if (part) {
683
+ if ((observeTableCells(part.length + 1), part)) {
629
684
  const at = part.lastIndexOf(':');
630
685
  out[part.slice(0, at)] = Number(part.slice(at + 1));
631
686
  }
632
- return out;
687
+ return completeWorkProfile.enabled ? rowCopy(out, 'linOf:output') : out;
633
688
  };
634
689
  // Two keys the path proves equal: two plain keys whose difference it decides 0 both ways, or two tuples of as many parts,
635
690
  // each pair of parts so (Lean's cellEq). A plain key and a tuple are never claimed equal.
@@ -647,15 +702,16 @@ export function withProducts(rows, pairs, squares = []) {
647
702
  const out = [...rows];
648
703
  for (const t of squares) {
649
704
  const tt = times(t, t);
650
- out.push(tt ? { lin: scale(tt, -1), label: '' } : { lin: {}, label: '' });
705
+ out.push(tt ? { lin: rowScale(tt, -1, 'withProducts:square'), label: '' } : { lin: {}, label: '' });
651
706
  }
652
707
  for (const [i, j] of pairs) {
653
708
  const p = out[i], q = out[j], pq = p && q ? times(p.lin, q.lin) : undefined;
654
- out.push(pq ? { lin: scale(pq, -1), label: '' } : { lin: {}, label: '' });
709
+ out.push(pq ? { lin: rowScale(pq, -1, 'withProducts:pair'), label: '' } : { lin: {}, label: '' });
655
710
  }
656
711
  return out;
657
712
  }
658
713
  export function check(goal, tree, path = new Map()) {
714
+ observeCheckStep();
659
715
  if ('leaf' in tree)
660
716
  return checkRefutation(withProducts(leafConstraints(goal, path), tree.products ?? [], tree.squares), tree.leaf);
661
717
  const id = canon(tree.split);
@@ -664,6 +720,303 @@ export function check(goal, tree, path = new Map()) {
664
720
  const yes = new Map(path).set(id, { lin: tree.split, holds: true }), no = new Map(path).set(id, { lin: tree.split, holds: false });
665
721
  return check(goal, tree.yes, yes) && check(goal, tree.no, no);
666
722
  }
723
+ const lemmaLin = (lin) => !!lin && typeof lin === 'object' && !Array.isArray(lin)
724
+ && (Object.getPrototypeOf(lin) === Object.prototype || Object.getPrototypeOf(lin) === null)
725
+ && Object.values(lin).every(Number.isSafeInteger);
726
+ // Lean's path is a list, so repeated atoms remain input rows, with the first deciding lookup. Keep that exact
727
+ // behavior in a Map: noncanonical duplicate keys contain no colon and cannot collide with a nonempty canon(lin).
728
+ function prependAtoms(front, path) {
729
+ const out = new Map();
730
+ let duplicate = 0;
731
+ for (const atom of [...front, ...path.values()]) {
732
+ const id = canon(atom.lin);
733
+ out.set(out.has(id) ? `@${duplicate++}` : id, atom);
734
+ }
735
+ return out;
736
+ }
737
+ // Eligibility uses only the original split path, never another cut. The returned path is for a leaf alone.
738
+ export function lemmaPath(lemmas, path) {
739
+ // Lean's dec treats all-zero variable coefficients as constant. Normalize only this
740
+ // new-condition decision boundary: preserve the original proof rows and every legacy path.
741
+ lemmas = lemmas.map(l => ({ ...l, when: l.when.map(w => Object.keys(w).every(key => key === '1' || w[key] === 0) ? k(w['1'] ?? 0) : w) }));
742
+ const active = lemmas.filter(l => l.when.every(w => decide(w, path) === true));
743
+ return active.length ? prependAtoms(active.map(l => ({ lin: l.cut, holds: true })), path) : path;
744
+ }
745
+ // checkGoalLemmas (Lean's checkGoalFrames with frames, checkGoalLemmas without): the lemma checks unchanged; each frame
746
+ // validated once by frameOk over the counted goal's counts; a leaf sees the active frames' rows in front of its lemma path.
747
+ export function checkGoalLemmas(goal, tree, lemmas = [], frames = [], counts = [], monos = [], lins = []) {
748
+ if (!Array.isArray(lemmas) || !Array.isArray(frames) || !Array.isArray(monos) || !Array.isArray(lins))
749
+ return false;
750
+ if (!lemmas.length && !frames.length && !monos.length && !lins.length)
751
+ return check(goal, tree); // Exact legacy path, including all old refusal checks.
752
+ try {
753
+ if (!Array.from(frames).every(frameShape) || !Array.from(monos).every(monoShape) || !Array.from(lins).every(linShape))
754
+ return false;
755
+ if (!frames.every(f => frameOk(counts, f)) || !monos.every(m => monoOk(counts, m)) || !lins.every(l => linOk(counts, l)))
756
+ return false;
757
+ if (!Array.from(lemmas).every(l => !!l && typeof l === 'object' && Array.isArray(l.when)
758
+ && Array.from(l.when).every(lemmaLin) && lemmaLin(l.cut) && !!l.tree && typeof l.tree === 'object'
759
+ && (l.slice === undefined || Array.isArray(l.slice) && Array.from(l.slice).every(i => Number.isSafeInteger(i) && i >= 0 && i < goal.hyps.length))))
760
+ return false;
761
+ for (const l of lemmas) {
762
+ observeCheckStep();
763
+ const hyps = l.slice === undefined ? goal.hyps : l.slice.map(i => goal.hyps[i]);
764
+ const path = prependAtoms([{ lin: l.cut, holds: false }, ...l.when.map(lin => ({ lin, holds: true }))], new Map());
765
+ if (!check({ ...goal, hyps }, l.tree, path))
766
+ return false;
767
+ }
768
+ const visit = (t, path) => {
769
+ if ('leaf' in t)
770
+ return check(goal, t, framePath(frames, lemmas, path, monos, lins));
771
+ observeCheckStep();
772
+ const id = canon(t.split);
773
+ if (path.has(id) || Object.keys(t.split).every(key => key === '1'))
774
+ return false;
775
+ return visit(t.yes, new Map(path).set(id, { lin: t.split, holds: true }))
776
+ && visit(t.no, new Map(path).set(id, { lin: t.split, holds: false }));
777
+ };
778
+ return visit(tree, new Map());
779
+ }
780
+ catch {
781
+ return false;
782
+ } // Malformed new payloads, including non-tree lemma references, are refusals.
783
+ }
784
+ const mentionsKey = (t, name) => {
785
+ switch (t.op) {
786
+ case 'var': return t.name === name;
787
+ case 'const':
788
+ case 'flag': return false;
789
+ case 'add':
790
+ case 'sub':
791
+ case 'min':
792
+ case 'max':
793
+ case 'prod':
794
+ case 'tup': return mentionsKey(t.a, name) || mentionsKey(t.b, name);
795
+ case 'mul':
796
+ case 'proj': return mentionsKey(t.a, name);
797
+ case 'if': return mentionsKey(t.c, name) || mentionsKey(t.then, name) || mentionsKey(t.else, name);
798
+ case 'get': return mentionsKey(t.key, name);
799
+ case '<':
800
+ case '<=':
801
+ case '=': return mentionsKey(t.a, name) || mentionsKey(t.b, name);
802
+ case 'and':
803
+ case 'or': return t.xs.some(x => mentionsKey(x, name));
804
+ case 'not': return mentionsKey(t.x, name);
805
+ case 'all': return mentionsKey(t.c, name);
806
+ default: return unreachable(t);
807
+ }
808
+ };
809
+ // Lean's monoE: a term that only rises with any variable (variables, constants, sums, scalings, products, minima, maxima).
810
+ const monoE = (e) => e.op === 'var' || e.op === 'const' || ((e.op === 'add' || e.op === 'min' || e.op === 'max' || e.op === 'prod') && monoE(e.a) && monoE(e.b)) || (e.op === 'mul' && monoE(e.a));
811
+ // Lean's zeroK: the key replaced by 0.
812
+ const zeroK = (e, key) => {
813
+ switch (e.op) {
814
+ case 'var': return e.name === key ? { op: 'const', value: 0 } : e;
815
+ case 'const': return e;
816
+ case 'add':
817
+ case 'sub':
818
+ case 'min':
819
+ case 'max':
820
+ case 'prod':
821
+ case 'tup': return { op: e.op, a: zeroK(e.a, key), b: zeroK(e.b, key) };
822
+ case 'mul': return { op: 'mul', k: e.k, a: zeroK(e.a, key) };
823
+ case 'proj': return { op: 'proj', k: e.k, a: zeroK(e.a, key) };
824
+ case 'get': return { op: 'get', map: e.map, key: zeroK(e.key, key) };
825
+ case 'if': return { op: 'if', c: e.c, then: zeroK(e.then, key), else: zeroK(e.else, key) };
826
+ default: return unreachable(e);
827
+ }
828
+ };
829
+ // Lean's atomK: an atom reading the key, decided for every value of the key from its key-free instance at 0 — the key
830
+ // only on the left and the left rising with it, false at 0 is false everywhere; only on the right, true at 0 is true
831
+ // everywhere.
832
+ const atomK = (op, a, b, path, key) => {
833
+ if (mentionsKey(a, key) && !mentionsKey(b, key) && monoE(a))
834
+ return truth({ op, a: zeroK(a, key), b }, path) === false ? false : undefined;
835
+ if (!mentionsKey(a, key) && mentionsKey(b, key) && monoE(b))
836
+ return truth({ op, a, b: zeroK(b, key) }, path) === true ? true : undefined;
837
+ return undefined;
838
+ };
839
+ // Lean's truthK: atoms reading no key by truth, atoms reading it by atomK, equalities through their inequalities,
840
+ // and / or / not three-valued.
841
+ export function truthK(c, path, key) {
842
+ switch (c.op) {
843
+ case 'and': {
844
+ let open = false;
845
+ for (const x of c.xs) {
846
+ const t = truthK(x, path, key);
847
+ if (t === false)
848
+ return false;
849
+ if (t === undefined)
850
+ open = true;
851
+ }
852
+ return open ? undefined : true;
853
+ }
854
+ case 'or': {
855
+ let open = false;
856
+ for (const x of c.xs) {
857
+ const t = truthK(x, path, key);
858
+ if (t === true)
859
+ return true;
860
+ if (t === undefined)
861
+ open = true;
862
+ }
863
+ return open ? undefined : false;
864
+ }
865
+ case 'not': {
866
+ const t = truthK(c.x, path, key);
867
+ return t === undefined ? undefined : !t;
868
+ }
869
+ case 'flag':
870
+ case 'all': return undefined;
871
+ case '<':
872
+ case '<=': return mentionsKey(c, key) ? atomK(c.op, c.a, c.b, path, key) : truth(c, path);
873
+ case '=': return !mentionsKey(c, key) ? truth(c, path)
874
+ : atomK('<=', c.a, c.b, path, key) === false || atomK('<=', c.b, c.a, path, key) === false ? false : undefined;
875
+ default: return unreachable(c);
876
+ }
877
+ }
878
+ // Lean's cTrue (0 ≤ 0) and cFalse (0 < 0), as the kernel's n-ary conditions: the empty conjunction and disjunction.
879
+ const cTrue = { op: 'and', xs: [] }, cFalse = { op: 'or', xs: [] };
880
+ const isTrueC = (c) => c.op === 'and' && c.xs.length === 0, isFalseC = (c) => c.op === 'or' && c.xs.length === 0;
881
+ const zeroOneIf = (e) => e.op === 'if' && e.then.op === 'const' && e.then.value === 1 && e.else.op === 'const' && e.else.value === 0 ? e.c : undefined;
882
+ // Lean's simpC: the terms inside a condition simplified; a conjunct decided true dropped, one decided false collapsing
883
+ // the conjunction, dually for a disjunction and a negation; `(if C then 1 else 0) = 1` is C and `= 0` is ¬C; an atom
884
+ // decided for every value of the key by truthK becomes cTrue or cFalse.
885
+ export function simpC(c, path, key) {
886
+ switch (c.op) {
887
+ case '<':
888
+ case '<=':
889
+ case '=': {
890
+ const a = simpE(c.a, path, key), b = simpE(c.b, path, key);
891
+ if (c.op === '=') {
892
+ const ca = zeroOneIf(a), cb = zeroOneIf(b);
893
+ if (ca && b.op === 'const' && (b.value === 1 || b.value === 0))
894
+ return b.value === 1 ? ca : notC(ca);
895
+ if (cb && a.op === 'const' && (a.value === 1 || a.value === 0))
896
+ return a.value === 1 ? cb : notC(cb);
897
+ }
898
+ const out = { op: c.op, a, b }, t = truthK(out, path, key);
899
+ return t === true ? cTrue : t === false ? cFalse : out;
900
+ }
901
+ case 'and': {
902
+ const xs = [];
903
+ for (const x of c.xs) {
904
+ const y = simpC(x, path, key);
905
+ if (isFalseC(y))
906
+ return cFalse;
907
+ if (!isTrueC(y))
908
+ xs.push(...(y.op === 'and' ? y.xs : [y]));
909
+ }
910
+ return xs.length === 1 ? xs[0] : { op: 'and', xs };
911
+ }
912
+ case 'or': {
913
+ const xs = [];
914
+ for (const x of c.xs) {
915
+ const y = simpC(x, path, key);
916
+ if (isTrueC(y))
917
+ return cTrue;
918
+ if (!isFalseC(y))
919
+ xs.push(...(y.op === 'or' ? y.xs : [y]));
920
+ }
921
+ return xs.length === 1 ? xs[0] : { op: 'or', xs };
922
+ }
923
+ case 'not': return notC(simpC(c.x, path, key));
924
+ case 'flag':
925
+ case 'all': return c;
926
+ default: return unreachable(c);
927
+ }
928
+ }
929
+ const notC = (y) => isTrueC(y) ? cFalse : isFalseC(y) ? cTrue : y.op === 'not' ? y.x : { op: 'not', x: y };
930
+ // Lean's simpE: each `if` whose condition is decided for every value of the key under the path, resolved; nothing else.
931
+ export function simpE(e, path, key) {
932
+ switch (e.op) {
933
+ case 'var':
934
+ case 'const': return e;
935
+ case 'add':
936
+ case 'sub':
937
+ case 'min':
938
+ case 'max':
939
+ case 'prod':
940
+ case 'tup': return { op: e.op, a: simpE(e.a, path, key), b: simpE(e.b, path, key) };
941
+ case 'mul': return { op: 'mul', k: e.k, a: simpE(e.a, path, key) };
942
+ case 'proj': return { op: 'proj', k: e.k, a: simpE(e.a, path, key) };
943
+ case 'get': return { op: 'get', map: e.map, key: simpE(e.key, path, key) };
944
+ case 'if': {
945
+ const t = simpE(e.then, path, key), f = simpE(e.else, path, key), c = simpC(e.c, path, key);
946
+ return isTrueC(c) ? t : isFalseC(c) ? f : { op: 'if', c, then: t, else: f };
947
+ }
948
+ default: return unreachable(e);
949
+ }
950
+ }
951
+ export const whenPath = (f) => new Map(f.when.map(w => [canon(w), { lin: w, holds: true }]));
952
+ const sameTerm = (a, b) => JSON.stringify(a) === JSON.stringify(b);
953
+ // Lean's frameOk: the two counts share their key, and under `when` their bounds and bodies are the same terms.
954
+ export function frameOk(counts, f) {
955
+ const post = counts.find(c => c.v === f.post), pre = counts.find(c => c.v === f.pre);
956
+ if (!post || !pre || post.key !== pre.key)
957
+ return false;
958
+ const path = whenPath(f);
959
+ return sameTerm(simpE(post.below, path, post.key), simpE(pre.below, path, post.key)) && sameTerm(simpE(post.body, path, post.key), simpE(pre.body, path, post.key));
960
+ }
961
+ // Lean's frameRows: post − pre ≤ 0 and pre − post ≤ 0.
962
+ export const frameRows = (f) => [{ [f.post]: 1, [f.pre]: -1 }, { [f.pre]: 1, [f.post]: -1 }];
963
+ // Lean's frameActive: eligibility from the original split path only.
964
+ export const frameActive = (f, path) => f.when.every(w => decide(w, path) === true);
965
+ // Lean's framePath: the active frames' rows in front of the lemma-cut path, both read off the original path.
966
+ export function framePath(frames, lemmas, path, monos = [], lins = []) {
967
+ const active = frames.filter(f => frameActive(f, path)), cuts = monos.filter(m => monoActive(m, path)), linear = lins.filter(l => linActive(l, path));
968
+ return prependAtoms([...linear.flatMap(l => linRows(l).map(lin => ({ lin, holds: true }))), ...cuts.flatMap(m => monoRows(m).map(lin => ({ lin, holds: true }))), ...active.flatMap(f => frameRows(f).map(lin => ({ lin, holds: true })))], lemmaPath(lemmas, path));
969
+ }
970
+ const monoHyps = (m, post, pre) => [...m.when, { op: '<', a: { op: 'var', name: post.key }, b: post.below }, { op: '<', a: pre.body, b: post.body }];
971
+ export function monoOk(counts, m) {
972
+ const post = counts.find(c => c.v === m.post), pre = counts.find(c => c.v === m.pre);
973
+ if (!post || !pre || post.key !== pre.key || !sameTerm(post.below, pre.below) || mentionsKey(post.below, post.key) || m.when.some(c => mentionsKey(c, post.key)))
974
+ return false;
975
+ return check({ name: 'per-key cut', hyps: monoHyps(m, post, pre) }, m.tree);
976
+ }
977
+ export const monoRows = (m) => [{ [m.post]: 1, [m.pre]: -1 }];
978
+ export const monoActive = (m, path) => m.when.every(c => truth(c, path) === true);
979
+ const monoShape = (m) => !!m && typeof m === 'object' && Array.isArray(m.when) && typeof m.post === 'string'
980
+ && typeof m.pre === 'string' && !!m.tree && typeof m.tree === 'object';
981
+ const linCounts = (counts, side) => {
982
+ const out = [];
983
+ let total = 0;
984
+ for (const [m, v] of side) {
985
+ const c = counts.find(k => k.v === v);
986
+ // A stricter native refusal than Lean: row accumulation must stay exact in JS.
987
+ if (!c || !Number.isSafeInteger(m) || m < 0 || m > Number.MAX_SAFE_INTEGER - total)
988
+ return undefined;
989
+ total += m;
990
+ out.push([m, c]);
991
+ }
992
+ return out;
993
+ };
994
+ const linTerm = (xs) => xs.reduceRight((rest, [m, c]) => ({ op: 'add', a: { op: 'mul', k: m, a: c.body }, b: rest }), { op: 'const', value: 0 });
995
+ const linSide = (side, sign) => {
996
+ const out = Object.create(null);
997
+ for (let i = 0; i < side.length; i++) {
998
+ startWork('tableCells', 1, 'linear cut input');
999
+ const [m, v] = side[i];
1000
+ out[v] = (out[v] ?? 0) + sign * m;
1001
+ }
1002
+ return completeWorkProfile.enabled ? rowCopy(out, 'linear cut side') : out;
1003
+ };
1004
+ export function linOk(counts, l) {
1005
+ const ps = linCounts(counts, l.pos), ns = linCounts(counts, l.neg);
1006
+ if (!ps || !ns || !ps.length && !ns.length)
1007
+ return false;
1008
+ const c0 = (ps[0] ?? ns[0])[1];
1009
+ const shape = (xs) => xs.every(([, c]) => c.key === c0.key && sameTerm(c.below, c0.below));
1010
+ if (!shape(ps) || !shape(ns) || mentionsKey(c0.below, c0.key) || l.when.some(c => mentionsKey(c, c0.key)))
1011
+ return false;
1012
+ return check({ name: 'linear cut', hyps: [...l.when, { op: '<', a: { op: 'var', name: c0.key }, b: c0.below }, { op: '<', a: linTerm(ns), b: linTerm(ps) }] }, l.tree);
1013
+ }
1014
+ export const linRows = (l) => [add(linSide(l.pos, 1), linSide(l.neg, -1))];
1015
+ export const linActive = (l, path) => l.when.every(c => truth(c, path) === true);
1016
+ const linShape = (l) => !!l && typeof l === 'object' && Array.isArray(l.when) && Array.isArray(l.pos) && Array.isArray(l.neg)
1017
+ && [...l.pos, ...l.neg].every(p => Array.isArray(p) && Number.isSafeInteger(p[0]) && p[0] >= 0 && typeof p[1] === 'string') && !!l.tree && typeof l.tree === 'object';
1018
+ const frameShape = (f) => !!f && typeof f === 'object' && Array.isArray(f.when) && Array.from(f.when).every(lemmaLin)
1019
+ && typeof f.post === 'string' && typeof f.pre === 'string';
667
1020
  // --- machines ----------------------------------------------------------------------------------------------------------
668
1021
  // Every constant and factor is a natural, so every value a machine computes is one (∸ truncates).
669
1022
  function natural(e) {
@@ -949,23 +1302,27 @@ export function scope(m, laws = []) {
949
1302
  // read only as a map's key (so every key the maps hold nothing at reads alike); a quantifier is a whole flag, nowhere
950
1303
  // else.
951
1304
  const readable = [...maps, ...carried, ...fns];
952
- const bound = (what, key, t) => {
1305
+ const bound = (what, key, t, finite = false) => {
953
1306
  plainName(what, key);
954
1307
  if ([...names, ...readable, ...flags].includes(key))
955
1308
  throw new Error(`${what}: the key ${key} is already a name of ${m.name}`);
956
1309
  // (a count map, like a function, has a value at every key, not cells a runtime can list: read at no key term)
957
- keyOnly(what, t, key, [...fns, ...counts]);
1310
+ if (!finite)
1311
+ keyOnly(what, t, key, [...fns, ...counts]);
958
1312
  };
959
1313
  inScope(`${m.name}'s start`, Object.values(m.state), m.params);
960
1314
  flags.forEach((f, i) => {
961
1315
  const c = m.step.flags[f], what = `${m.name}'s flag ${f}`;
962
1316
  // A quantified flag's body reads no flag (the twin decides quantified flags before the plain ones).
963
1317
  if (c.op === 'all') {
964
- const keys = boundOf(c), body = crossFree(c.c, keys);
1318
+ const finite = finiteBound(c), keys = boundOf(c), body = crossFree(c.c, keys);
1319
+ if (finite)
1320
+ inScope(`${what}'s finite size`, [finite], m.params);
965
1321
  distinct(what, keys);
966
1322
  for (const key of keys) {
967
- bound(what, key, body);
968
- apart(what, body, key, keys);
1323
+ bound(what, key, body, finite !== undefined);
1324
+ if (!finite)
1325
+ apart(what, body, key, keys);
969
1326
  }
970
1327
  unquantified(what, c.c);
971
1328
  inScope(what, [c.c], [...names, ...keys], readable, []);
@@ -978,6 +1335,8 @@ export function scope(m, laws = []) {
978
1335
  const arity = mapArities(m, laws);
979
1336
  for (const [map, w] of Object.entries(m.step.maps ?? {})) {
980
1337
  const what = `${m.name}'s write to ${map}`;
1338
+ if ('finite' in w)
1339
+ throw new Error(`${what}: a finite marker is only for quantifiers, not writes at every key`);
981
1340
  // At every key of a tuple-keyed map, the key is read as its parts (proj k, or the key whole at a read of the map):
982
1341
  // the runtimes compute the write at every tuple of parts, each part read as a bound key is.
983
1342
  if ('each' in w && (own(arity, map) ?? 1) > 1) {
@@ -1026,6 +1385,9 @@ export function scope(m, laws = []) {
1026
1385
  throw new Error(`${what}: further keys come with a first, each a different name`);
1027
1386
  if (law.name.startsWith('?'))
1028
1387
  throw new Error(`${what}: a name starting with ? is a flag's (its instances)`);
1388
+ const finite = finiteLawBound(law);
1389
+ if (finite)
1390
+ inScope(`${what}'s finite size`, [finite], m.params);
1029
1391
  unquantified(what, law.holds);
1030
1392
  }
1031
1393
  const keysOf = (l) => [...(l.forall ? [l.forall] : []), ...(l.keys ?? [])];
@@ -1114,6 +1476,33 @@ const tupleSides = (u) => {
1114
1476
  const as = tupleParts(u.a), bs = tupleParts(u.b);
1115
1477
  return as.length === bs.length ? as.map((a, i) => [a, bs[i]]) : undefined;
1116
1478
  };
1479
+ // A marker is a request for exact finite enumeration, never a semantic axiom.
1480
+ // The guard remains in the formula sent to closing/assumed and the Lean twin.
1481
+ // Bounded.lean proves this exact shape equivalent to enumeration, including n=0.
1482
+ export function finiteBound(q) {
1483
+ if (q.finite === undefined)
1484
+ return undefined;
1485
+ const bad = () => { throw new Error('a finite quantifier requires one key and the exact guard k < size implies body'); };
1486
+ if (typeof q.finite !== 'string' || !q.finite.length || q.keys?.length)
1487
+ return bad();
1488
+ const c = q.c;
1489
+ if (c.op !== 'or' || c.xs.length !== 2)
1490
+ return bad();
1491
+ const guard = c.xs[0];
1492
+ if (guard.op !== 'not' || guard.x.op !== '<' || guard.x.a.op !== 'var' || guard.x.a.name !== q.key)
1493
+ return bad();
1494
+ if (readsKey(guard.x.b, q.key))
1495
+ return bad();
1496
+ return guard.x.b;
1497
+ }
1498
+ // Prenexing a finite law removes its quantifier, but not its guard or runtime domain.
1499
+ export function finiteLawBound(law) {
1500
+ if (law.finite === undefined)
1501
+ return undefined;
1502
+ if (!law.forall || law.some?.length || law.ex)
1503
+ throw new Error('a finite law requires one universal key and no existential witness metadata');
1504
+ return finiteBound({ op: 'all', key: law.forall, ...(law.keys ? { keys: law.keys } : {}), c: law.holds, finite: law.finite });
1505
+ }
1117
1506
  export const keyTerm = (e, key) => e.op === 'var' ? e.name === key
1118
1507
  : e.op === 'add' ? (e.a.op === 'var' && e.a.name === key && !readsKey(e.b, key)) || (e.b.op === 'var' && e.b.name === key && !readsKey(e.a, key))
1119
1508
  : e.op === 'sub' && e.a.op === 'var' && e.a.name === key && !readsKey(e.b, key);
@@ -2006,26 +2395,35 @@ export const qdif = (a, b) => radd(rscale(b.den, a.row), rscale(-a.den, b.row));
2006
2395
  // never wrong); and its key, as `canon` writes a Lin (zero coefficients dropped: Lean's `same` compares by value).
2007
2396
  export const qLin = (r) => {
2008
2397
  const out = Object.create(null);
2009
- for (const [x, c] of r.cs) {
2398
+ const iterator = r.cs.entries(), size = r.cs.size;
2399
+ for (let i = 0; i < size; i++) {
2400
+ startWork('tableCells', 1, 'qLin input');
2401
+ const entry = iterator.next();
2402
+ if (entry.done)
2403
+ throw new Error('rational row changed during traversal');
2404
+ const [x, c] = entry.value;
2010
2405
  if (c < -(2n ** 53n) + 1n || c > 2n ** 53n - 1n)
2011
2406
  return undefined;
2012
2407
  out[x] = Number(c);
2013
2408
  }
2409
+ startWork('tableCells', 1, 'qLin constant');
2014
2410
  if (r.c !== 0n) {
2015
2411
  if (r.c < -(2n ** 53n) + 1n || r.c > 2n ** 53n - 1n)
2016
2412
  return undefined;
2017
2413
  out['1'] = Number(r.c);
2018
2414
  }
2019
- return out;
2415
+ return completeWorkProfile.enabled ? rowCopy(out, 'qLin output') : out;
2020
2416
  };
2021
2417
  const linRow = (lin) => {
2022
- if (!Object.values(lin).every(c => Number.isSafeInteger(c)))
2418
+ if (!everyLinearCell(lin, (_key, c) => Number.isSafeInteger(c), 'linRow safety'))
2023
2419
  return undefined;
2024
2420
  const cs = new Map();
2025
- for (const [x, c] of Object.entries(lin))
2026
- if (x !== '1' && c !== 0)
2027
- cs.set(x, BigInt(c));
2028
- return { cs, c: BigInt(lin['1'] ?? 0) };
2421
+ let constant = 0n;
2422
+ visitLinearCells(lin, (x, c) => { if (x === '1')
2423
+ constant = BigInt(c);
2424
+ else if (c !== 0)
2425
+ cs.set(x, BigInt(c)); }, 'linRow conversion');
2426
+ return { cs, c: constant };
2029
2427
  };
2030
2428
  const rowKey = (r) => { const lin = qLin(r); return lin && canon(lin); };
2031
2429
  export function qdec(path, r) {
@@ -2136,10 +2534,11 @@ export function qfacts(c, path, pos = true) {
2136
2534
  export function qLeafRows(goal, path) {
2137
2535
  const rows = [...[...path.values()].map(a => (a.holds ? [linRow(a.lin), false] : [rscale(-1n, linRow(a.lin)), true])),
2138
2536
  ...goal.hyps.flatMap(h => qfacts(h, path))];
2139
- return rows.flatMap(([r, strict]) => { const lin = qLin(r); return lin ? [{ lin, label: '', strict }] : []; });
2537
+ return rows.flatMap(([r, strict]) => { const lin = qLin(r); observeTableCells(lin ? Object.keys(lin).length : 0); return lin ? [{ lin, label: '', strict }] : []; });
2140
2538
  }
2141
2539
  // A split on a row the path decides already (or a constant one) is refused, as Lean's checkT refuses it.
2142
2540
  export function checkQTree(goal, tree, path = new Map()) {
2541
+ observeCheckStep();
2143
2542
  if ('leaf' in tree)
2144
2543
  return !tree.products?.length && !tree.squares?.length && checkRefutation(qLeafRows(goal, path), tree.leaf, false);
2145
2544
  const row = linRow(tree.split), lin = row && qLin(row);
@@ -2271,10 +2670,11 @@ export function countedOk(hyps, cs, is) {
2271
2670
  // (Lean's are Int).
2272
2671
  const typed = (is) => is.every(i => typeof i.wit === 'string' && Number.isSafeInteger(i.unit) && i.terms.every(([z]) => Number.isSafeInteger(z)));
2273
2672
  export function checkCounted(g, cert) {
2673
+ observeCheckStep();
2274
2674
  if (!(countedOk(g.hyps, g.counts, cert.insts) && typed(cert.insts)))
2275
2675
  return false;
2276
2676
  const goal = countedGoal(g, cert.insts);
2277
- return goal !== undefined && check(goal, cert.tree);
2677
+ return goal !== undefined && checkGoalLemmas(goal, cert.tree, cert.lemmas, cert.frames, g.counts, cert.monos, cert.lins);
2278
2678
  }
2279
2679
  // The goal a certificate's tree refutes: the goal's hypotheses, then the instances' (also what the search and the
2280
2680
  // exporter read), or none.
@@ -2404,21 +2804,23 @@ const readsTyped = (rs) => Array.isArray(rs) && rs.every(r => Array.isArray(r) &
2404
2804
  const witFreshW = (cs, is, w) => cs.every(c => c.v !== w && !readsVar(c.below, w) && !readsVar(c.body, w)) && is.every(j => !readsVar(j.below, w));
2405
2805
  const countedOkW = (cs, is) => { const ws = is.map(i => i.wit); return new Set(ws).size === ws.length && is.every(i => witFreshW(cs, is, i.wit)); };
2406
2806
  function checkCountedW(hyps, cs, cert) {
2807
+ observeCheckStep();
2407
2808
  if (!(countedOkW(cs, cert.insts) && typed(cert.insts)))
2408
2809
  return false;
2409
2810
  const hs = countHyps(cs, cert.insts);
2410
- return hs !== undefined && check({ name: 'counted', hyps: [...hyps, ...hs] }, cert.tree);
2811
+ return hs !== undefined && checkGoalLemmas({ name: 'counted', hyps: [...hyps, ...hs] }, cert.tree, cert.lemmas, cert.frames, cs, cert.monos, cert.lins);
2411
2812
  }
2412
2813
  // checkMC: each declaration's j and lo differ from its key, the reads are fresh, no read is a witness or reads one in
2413
2814
  // its key term, and checkCountedW accepts the counted goal they make (the goal's hypotheses, each read variable equal to
2414
2815
  // its cell; Lean's names the hypotheses it uses, each the goal's).
2415
2816
  export function checkMC(hyps, ds, k) {
2817
+ observeCheckStep();
2416
2818
  if (!(ds.every(d => d.j !== d.key && loOf(d) !== d.key) && picksTyped(k.picks) && readsTyped(k.reads) && Array.isArray(k.insts) && k.insts.every(i => !!i && safeTerm(i.below)) && readsOk(hyps, ds, k.reads)))
2417
2819
  return false;
2418
2820
  if (!k.reads.every(r => k.insts.every(i => i.wit !== r[0] && !readsVar(r[2], i.wit))))
2419
2821
  return false;
2420
2822
  const cs = toCounts(ds, k.reads);
2421
- return cs !== undefined && checkCountedW([...hyps, ...k.reads.map(r => readHyp(ds, r)), ...pickHyps(ds, k.reads, k.picks ?? [])], cs, { insts: k.insts, tree: k.tree });
2823
+ return cs !== undefined && checkCountedW([...hyps, ...k.reads.map(r => readHyp(ds, r)), ...pickHyps(ds, k.reads, k.picks ?? [])], cs, { insts: k.insts, tree: k.tree, lemmas: k.lemmas, frames: k.frames, monos: k.monos, lins: k.lins });
2422
2824
  }
2423
2825
  // The goal a certificate's tree refutes (what the search and the exporter read), or none.
2424
2826
  export function mcGoal(hyps, ds, k) {