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
@@ -0,0 +1,534 @@
1
+ import { searchNow as countedSearchNow } from "../wall.js";
2
+ // Untrusted model-driven recovery. Scalar facts are prepared once; numeric
3
+ // countermodels select batches of pointwise facts at bounded row leaves. Every
4
+ // cut and the final tree are independently checked, without new axioms.
5
+ import { x } from "../machine.js";
6
+ import { canon, canonFlip, facts, lemmaPath, linear, substC, substE, truth } from "../../kernel/kernel.js";
7
+ import { atPoint, brokenOf, clock, pastWall, usedHyps, wallAt, withDeadline } from "../../kernel/prove.js";
8
+ import { REFUTED } from "../../kernel/cdcl.js";
9
+ import { scale, sub } from "../solver.js";
10
+ import { check, grow, modelSequence, refuteFast, rowsAt, widen } from "./ops.js";
11
+ import { fieldBounds, countBindingsAt } from "./field-bound-lemmas.js";
12
+ import { preStateCountSource } from "./pre-state-source.js";
13
+ import { booleanCore } from "./boolean-core.js";
14
+ import { foldPath } from "./fold-path.js";
15
+ import { piecesAt, walkLive } from "./live-dependencies.js";
16
+ import { liftCountProxies } from "./lift-count-proxies.js";
17
+ import { proveNaturalCases } from "./natural-cases.js";
18
+ import { proveRowCases, rowPairs } from "./row-cases.js";
19
+ import { admitConditionalCut, inlineConditionalCuts } from "./conditional-cuts.js";
20
+ import { markConditionalProof, checkConditionalProof } from "./conditional-proof.js";
21
+ import { countScalarGuards } from "./scalar-guards.js";
22
+ import { proposeWriteCountFrames } from "../count-write-frames.js";
23
+ import { countsForReads } from "../count-facts.js";
24
+ import { memberInclusions } from "./member-inclusions.js";
25
+ import { leafAllowance } from "./leaf-allowance.js";
26
+ import { emptyCountSource } from "./empty-count-source.js";
27
+ import { beginFieldAttempt, endFieldAttempt } from "./field-demand.js";
28
+ const put = (p, lin, holds) => new Map(p).set(canon(lin), { lin, holds });
29
+ const plain = (lin) => !Object.keys(lin).some(k => k.startsWith('⟦'));
30
+ const fast = (g, p) => { const q = refuteFast(rowsAt(g, p), 256); return q?.kind === 'refuted' ? { leaf: q.steps } : undefined; };
31
+ const decide = (lin, path) => path.get(canon(lin))?.holds ?? (path.has(canonFlip(lin)) ? !path.get(canonFlip(lin)).holds : undefined);
32
+ const active = (saved, path) => saved.filter(s => lemmaPath([s.lemma], path) !== path);
33
+ export function deriveCountClosure(m, ds, g, cert, root, until, trace, options = {}) {
34
+ const wanted = new Set();
35
+ walkLive(options.claim, root, (o) => {
36
+ if (o.op === 'var' && cert.reads.some(r => r[0] === o.name))
37
+ wanted.add(o.name);
38
+ if (o.op === 'get')
39
+ for (const r of cert.reads)
40
+ if (r[1] === o.map && JSON.stringify(r[2]) === JSON.stringify(o.key))
41
+ wanted.add(r[0]);
42
+ });
43
+ if (wanted.size < 2 || !cert.insts.some(q => q.unit === 0 && q.terms.length >= 3) || clock() >= until || pastWall())
44
+ return undefined;
45
+ const started = clock(), reserve = Math.min(400, (until - started) / 3), buildEnd = until - reserve;
46
+ const raw = g.hyps.slice(0, -cert.insts.length), ids = new Set(cert.reads.map(r => r[0])), maps = new Set(cert.reads.map(r => r[1])), wits = new Set(cert.insts.map(q => q.wit));
47
+ const saved = [], models = [], pins = [];
48
+ let base = new Map(root);
49
+ let leafEnd;
50
+ const alive = () => clock() < until && !pastWall(), building = () => clock() < (leafEnd ?? buildEnd) && !pastWall();
51
+ const wallEnd = () => Math.min(wallAt(), countedSearchNow() + Math.min(10000, Math.max(0, (leafEnd ?? until) - clock()) * 10));
52
+ const transport = (from, to, t, a, b) => alive() ? withDeadline(Math.min(until, leafEnd ?? until), () => widen(from, to, t, {}, a, b)) : undefined;
53
+ const sourceCache = new WeakMap();
54
+ const source = (path, witness) => {
55
+ let entry = sourceCache.get(path);
56
+ if (!entry) {
57
+ const rows = [];
58
+ for (const c of raw.flatMap(c => piecesAt(c, path))) {
59
+ let skip = false;
60
+ const owners = new Set();
61
+ walkLive(c, path, (o) => { if (o.op === 'get' && maps.has(o.map) || o.op === 'var' && ids.has(o.name))
62
+ skip = true;
63
+ else if (o.op === 'var' && wits.has(o.name))
64
+ owners.add(o.name); });
65
+ if (!skip && owners.size <= 1)
66
+ rows.push({ c, owner: owners.values().next().value });
67
+ }
68
+ entry = { rows, views: new Map() };
69
+ sourceCache.set(path, entry);
70
+ }
71
+ let view = entry.views.get(witness);
72
+ if (!view) {
73
+ view = entry.rows.filter(r => r.owner === undefined || r.owner === witness).map(r => r.c);
74
+ entry.views.set(witness, view);
75
+ }
76
+ return view;
77
+ };
78
+ const accept = (good, part, tree, from, scope, index) => {
79
+ if (!building())
80
+ return false;
81
+ const a = linear(good.a, from), b = linear(good.b, from);
82
+ if (!a || !b)
83
+ return false;
84
+ const cut = sub(a, b);
85
+ if (!plain(cut))
86
+ return false;
87
+ if (truth(good, lemmaPath(saved.map(s => s.lemma), scope)) === true)
88
+ return true;
89
+ const lemma = admitConditionalCut(g, part, tree, from, scope, cut, saved.map(s => s.lemma), wallEnd());
90
+ if (!lemma || !building())
91
+ return false;
92
+ saved.push({ lemma, good, ...(index === undefined ? {} : { index }) });
93
+ trace.push({ stage: 'closure-cut', index, when: lemma.when, cut: lemma.cut });
94
+ return true;
95
+ };
96
+ // Pin only consequences already proved from the original raw hypotheses.
97
+ // Other guards remain explicit conditions of a scalar cut, not assumptions.
98
+ const pin = (atom) => {
99
+ if (decide(atom, base) === true)
100
+ return true;
101
+ if (!plain(atom) || !building())
102
+ return false;
103
+ const noPath = put(base, atom, false), part = { name: g.name, hyps: raw }, tree = fast(part, noPath), no = tree && transport(part, g, tree, noPath, noPath);
104
+ if (!no)
105
+ return false;
106
+ pins.push({ split: atom, no });
107
+ base = put(base, atom, true);
108
+ return true;
109
+ };
110
+ // Phase A, once: plain-cell ceilings with their guard atoms in `when`.
111
+ for (const guarded of fieldBounds(m, ds, cert, { claim: options.claim, path: base })) {
112
+ if (!building())
113
+ break;
114
+ if (guarded.op !== '<=')
115
+ continue;
116
+ const condition = guarded.a.op === 'if' ? guarded.a.c : undefined;
117
+ if (condition && truth(condition, base) === false)
118
+ continue;
119
+ const conditions = condition ? facts(condition, base) : [];
120
+ conditions.forEach(pin);
121
+ let scope = new Map(base);
122
+ for (const atom of conditions)
123
+ scope = put(scope, atom, true);
124
+ if (condition && truth(condition, scope) !== true)
125
+ continue;
126
+ const good = { op: '<=', a: guarded.a.op === 'if' ? guarded.a.then : guarded.a, b: guarded.b }, a = linear(good.a, scope), b = linear(good.b, scope);
127
+ if (!a || !b || !plain(sub(a, b)) || truth(good, lemmaPath(saved.map(s => s.lemma), scope)) === true)
128
+ continue;
129
+ const before = clock(), traceStart = trace.length, noPath = put(scope, sub(a, b), false), small = { name: g.name, hyps: source(scope) }, meter = beginFieldAttempt(guarded, scope, options.fieldDemand, 'closure-scalar');
130
+ let accepted = false;
131
+ try {
132
+ const direct = fast(small, noPath);
133
+ accepted = !!direct && accept(good, small, direct, noPath, scope);
134
+ if (!accepted && options.fieldSource && building()) {
135
+ const claim = { op: 'not', x: good }, prior = preStateCountSource(g, cert, claim, scope), path = lemmaPath(saved.map(s => s.lemma), scope);
136
+ const tree = options.fieldSource(prior.goal, prior.cert, claim, path, Math.min(buildEnd, clock() + 250));
137
+ if (tree)
138
+ accepted = accept(good, prior.goal, tree, path, scope);
139
+ }
140
+ }
141
+ finally {
142
+ endFieldAttempt(meter, accepted);
143
+ }
144
+ trace.push({ stage: 'closure-scalar', plain: good, checked: accepted, ms: clock() - before, ...(!accepted ? { sourceTail: trace.slice(traceStart).slice(-8) } : {}) });
145
+ }
146
+ // Conditional source scopes are data, not arithmetic proof leaves. Minimal
147
+ // equal-row scopes come first; full order scopes cover the remaining cases.
148
+ const pairMap = new Map((options.pairs ?? []).map(pair => [JSON.stringify(pair), pair]));
149
+ for (const read of cert.reads)
150
+ if (wanted.has(read[0]) && read[1].endsWith('#'))
151
+ for (const pair of rowPairs(m, { reads: [read] }, base, options.claim))
152
+ pairMap.set(JSON.stringify(pair), pair);
153
+ const pairs = [...pairMap.values()].slice(0, 2), scopes = [], scopeByKey = new Map();
154
+ const addScope = (path) => { const key = JSON.stringify([...path].map(([id, a]) => [id, a.holds])), old = scopeByKey.get(key); if (old)
155
+ return old; scopeByKey.set(key, path); scopes.push(path); return path; };
156
+ const rowChoices = (path, pair) => {
157
+ const c = { op: '=', a: pair[0], b: pair[1] };
158
+ if (truth(c, path) !== undefined)
159
+ return [path];
160
+ const a = linear(pair[0], path), b = linear(pair[1], path);
161
+ if (!a || !b)
162
+ return [path];
163
+ const f = sub(a, b), back = scale(f, -1);
164
+ return [put(put(path, f, true), back, true), put(put(path, f, true), back, false), put(path, f, false)];
165
+ };
166
+ addScope(base);
167
+ for (const pair of pairs)
168
+ for (const scope of rowChoices(base, pair))
169
+ addScope(scope);
170
+ let complete = [base];
171
+ for (const pair of pairs)
172
+ complete = complete.flatMap(path => rowChoices(path, pair));
173
+ for (const scope of complete)
174
+ addScope(scope);
175
+ const rowScopes = [...scopes];
176
+ const postReads = new Set(cert.reads.filter(r => r[1].endsWith('#')).map(r => r[0]));
177
+ const conditional = (index) => cert.insts[index].terms.some(([, id]) => postReads.has(id));
178
+ const readMap = new Map(cert.reads.map(([id, map]) => [id, map]));
179
+ const frame = (index) => { const q = cert.insts[index]; if (q.terms.length !== 2)
180
+ return false; const [a, b] = q.terms.map(([, id]) => readMap.get(id)); return !!a && !!b && (a.endsWith('#') && a.slice(0, -1) === b || b.endsWith('#') && b.slice(0, -1) === a); };
181
+ const vector = (q) => JSON.stringify([...q.terms].sort((a, b) => a[1].localeCompare(b[1]) || a[0] - b[0]));
182
+ const memberHints = new Map(memberInclusions(m, ds, cert.reads).map(p => [vector({ wit: '', unit: 0, below: p.below, terms: [[1, p.positive], [-1, p.negative]] }), p.guards]));
183
+ const bridges = new Set(proposeWriteCountFrames(m, ds, { reads: cert.reads, insts: [] }, wanted).map(vector));
184
+ // Inclusion is cheap even when an expanded post partition is not. Rank by
185
+ // declarative membership containment only; the actual witness still proves it.
186
+ const predicates = new Map();
187
+ for (const read of cert.reads) {
188
+ const plainRead = [read[0], read[1].endsWith('#') ? read[1].slice(0, -1) : read[1], read[2]], count = countsForReads(ds, [plainRead])?.[0];
189
+ if (!count)
190
+ continue;
191
+ const body = substE(count.body, { vars: { [count.key]: x('closure$member') }, maps: {}, flags: {} });
192
+ if (body.op !== 'if' || body.then.op !== 'const' || body.then.value !== 1 || body.else.op !== 'const' || body.else.value !== 0)
193
+ continue;
194
+ const atoms = new Set(), collect = (c) => { if (c.op === 'and')
195
+ c.xs.forEach(collect);
196
+ else
197
+ atoms.add(JSON.stringify(c)); };
198
+ collect(body.c);
199
+ predicates.set(read[0], atoms);
200
+ }
201
+ const inclusion = (q) => {
202
+ if (q.unit !== 0 || q.terms.length !== 2)
203
+ return false;
204
+ const a = q.terms.find(([z]) => z === 1)?.[1], b = q.terms.find(([z]) => z === -1)?.[1];
205
+ if (!a || !b || postReads.has(a) !== postReads.has(b))
206
+ return false;
207
+ const left = predicates.get(a), right = predicates.get(b);
208
+ return !!left && !!right && [...right].every(atom => left.has(atom));
209
+ };
210
+ const rank = (index) => { const q = cert.insts[index], arity = q.terms.length; return q.unit !== 0 && arity === 1 ? -2 : inclusion(q) ? -1 : arity === 1 && wanted.has(q.terms[0][1]) ? 0 : !conditional(index) && arity === 3 ? 0 : bridges.has(vector(q)) ? 1 : !conditional(index) && arity === 5 ? 2 : frame(index) ? 3 : !conditional(index) ? 4 : arity === 3 ? 5 : arity === 2 ? 6 : 7; };
211
+ const pool = cert.insts.flatMap((q, index) => q.terms.length <= 5 ? [index] : []).sort((a, b) => rank(a) - rank(b));
212
+ const rowNames = new Set();
213
+ for (const pair of pairs)
214
+ walkLive(pair, base, (o) => { if (o.op === 'var' && !m.inputs.includes(o.name))
215
+ rowNames.add(o.name); });
216
+ const sourceRows = new Map(pool.map(index => {
217
+ const names = new Set();
218
+ for (const [, id] of cert.insts[index].terms) {
219
+ const read = cert.reads.find(r => r[0] === id);
220
+ if (read)
221
+ walkLive(read[2], base, (o) => { if (o.op === 'var' && rowNames.has(o.name))
222
+ names.add(o.name); });
223
+ }
224
+ return [index, names];
225
+ }));
226
+ const scalarAtoms = new Set(), scopeCache = new Map();
227
+ const scopesFor = (index) => {
228
+ const old = scopeCache.get(index);
229
+ if (old)
230
+ return old;
231
+ const rows = rowScopes.filter(scope => [...scope].every(([id, atom]) => base.has(id) || Object.keys(atom.lin).every(name => !rowNames.has(name) || sourceRows.get(index).has(name))));
232
+ const bridge = bridges.has(vector(cert.insts[index])), guarded = [], equalRows = rows.filter(scope => scope !== base && scope.size <= base.size + 2 && pairs.some(([a, b]) => truth({ op: '=', a, b }, scope) === true));
233
+ const distinctRows = bridge ? rows.filter(scope => { const states = pairs.map(([a, b]) => truth({ op: '=', a, b }, scope)); return states.includes(true) && states.includes(false); }) : [];
234
+ const origins = conditional(index) ? [...distinctRows, ...equalRows, base] : [base];
235
+ const preferred = memberHints.get(vector(cert.insts[index]));
236
+ const proposed = [...(preferred ? [preferred] : []), ...countScalarGuards(m, ds, cert.reads, cert.insts[index], base, { name: g.name, hyps: source(base, cert.insts[index].wit) })].slice(0, 8), equal = proposed.filter(guards => guards.every(c => c.op === '='));
237
+ const choices = bridge && equal.length ? equal.sort((a, b) => b.length - a.length) : proposed;
238
+ for (const guards of choices)
239
+ for (const origin of origins) {
240
+ let scope = new Map(origin), valid = true;
241
+ const aliases = {};
242
+ for (const [a, b] of pairs)
243
+ if (a.op === 'var' && truth({ op: '=', a, b }, origin) === true)
244
+ aliases[a.name] = b;
245
+ for (const original of guards) {
246
+ const condition = substC(original, { vars: aliases, maps: {}, flags: {} });
247
+ if (truth(condition, scope) === false) {
248
+ valid = false;
249
+ break;
250
+ }
251
+ for (const atom of facts(condition, scope)) {
252
+ if (!plain(atom)) {
253
+ valid = false;
254
+ break;
255
+ }
256
+ scalarAtoms.add(canon(atom));
257
+ scalarAtoms.add(canonFlip(atom));
258
+ scope = put(scope, atom, true);
259
+ }
260
+ if (!valid)
261
+ break;
262
+ }
263
+ if (valid)
264
+ guarded.push(addScope(scope));
265
+ }
266
+ const unique = new Set(), out = (bridge ? [base, ...rows, ...guarded] : [base, ...guarded, ...rows]).filter(scope => { const key = JSON.stringify([...scope].map(([id, a]) => [id, a.holds])); if (unique.has(key))
267
+ return false; unique.add(key); return true; });
268
+ scopeCache.set(index, out);
269
+ return out;
270
+ };
271
+ let rounds = 0, fixedPoint = false;
272
+ for (const index of pool)
273
+ scopesFor(index);
274
+ const excludedAt = new Map(), attempted = new Map();
275
+ const countBodies = new Map();
276
+ const validPoint = (part, path, point) => {
277
+ const model = { ...point };
278
+ walkLive(part.hyps, path, (o) => { if (o.op === 'var' && !Object.hasOwn(model, o.name))
279
+ model[o.name] = 0; });
280
+ for (const atom of path.values())
281
+ for (const name of Object.keys(atom.lin))
282
+ if (name !== '1' && !Object.hasOwn(model, name))
283
+ model[name] = 0;
284
+ if (!Object.values(model).every(Number.isSafeInteger) || brokenOf(part)(model).length)
285
+ return undefined;
286
+ return [...path.values()].every(a => { const n = Object.entries(a.lin).reduce((s, [k, z]) => s + z * (k === '1' ? 1 : model[k]), 0); return Number.isFinite(n) && (a.holds ? n <= 0 : n > 0); }) ? model : undefined;
287
+ };
288
+ const attempt = (index, scope, end) => {
289
+ if (!building())
290
+ return 'unknown';
291
+ scope = addScope(scope);
292
+ const version = saved.length, key = `${scopes.indexOf(scope)}:${index}`, had = attempted.get(key);
293
+ if (had?.version === version)
294
+ return had.outcome;
295
+ const inst = cert.insts[index], h = g.hyps[raw.length + index];
296
+ if (h?.op !== 'or' || h.xs[0]?.op !== '<=')
297
+ return 'unknown';
298
+ const good = { op: '<=', a: h.xs[0].a, b: h.xs[0].b }, available = active(saved, scope), path = scope, before = clock();
299
+ const meter = beginFieldAttempt(good, scope, options.fieldDemand, 'closure-count');
300
+ let emitted = false;
301
+ const aliases = {};
302
+ for (const [a, b] of pairs)
303
+ if (a.op === 'var' && truth({ op: '=', a, b }, path) === true)
304
+ aliases[a.name] = b;
305
+ const id = inst.unit === 0 && inst.terms.length === 1 && inst.terms[0][0] === 1 ? inst.terms[0][1] : undefined;
306
+ if (id && !countBodies.has(id)) {
307
+ const read = cert.reads.find(r => r[0] === id);
308
+ countBodies.set(id, read ? countsForReads(ds, [read])?.[0]?.body : undefined);
309
+ }
310
+ const body = id ? countBodies.get(id) : undefined, independent = !!body && emptyCountSource(body, aliases);
311
+ try {
312
+ const part = { name: g.name, hyps: [...(independent ? [] : source(path, inst.wit)), ...(independent ? [] : available.map(s => s.good)), h, { op: 'not', x: good }] };
313
+ const reused = models.some(m => validPoint({ ...part, hyps: part.hyps.map(c => substC(c, { vars: { [inst.wit]: x(m.witness) }, maps: {}, flags: {} })) }, path, m.model) !== undefined);
314
+ if (reused) {
315
+ attempted.set(key, { version, outcome: 'sat' });
316
+ trace.push({ stage: 'closure-source', scope: scopes.indexOf(scope), index, outcome: 'reused-model', ms: clock() - before });
317
+ return 'sat';
318
+ }
319
+ const queryLimit = Math.min(end, clock() + (inst.terms.length === 5 ? 150 : 50)), q = modelSequence(path)(part, queryLimit);
320
+ let tree = 'tree' in q ? q.tree : undefined, proofSource = part, validModel = false;
321
+ if (!tree && !('tree' in q) && q.stuck === 'sat' && q.witness) {
322
+ const model = validPoint(part, path, q.witness);
323
+ if (model) {
324
+ validModel = true;
325
+ models.push({ witness: inst.wit, model });
326
+ if (models.length > 32)
327
+ models.shift();
328
+ }
329
+ }
330
+ else if (!tree && !('tree' in q) && q.why === REFUTED && q.core?.length && q.core.length <= 8 && building()) {
331
+ const limit = Math.min(end, independent ? before + 150 : Math.max(queryLimit, clock() + 100)), small = { ...part, hyps: q.core.map(i => part.hyps[i]) }, oldPoint = atPoint.on;
332
+ atPoint.on = false;
333
+ try {
334
+ let local;
335
+ // Spend the existing 50+100 fallback envelope on the independent core,
336
+ // not unrelated field choices. No syntactic observation is a proof.
337
+ if (independent) {
338
+ const out = grow(small, path, { nodes: 0, until: limit, units: true });
339
+ if ('tree' in out)
340
+ local = out.tree;
341
+ }
342
+ if (!local && clock() < limit)
343
+ local = booleanCore(small, path, new Set([inst.wit]), limit, trace, { deferCheck: true, extended: true, scalarGuards: true, model: true });
344
+ if (!local && clock() < limit) {
345
+ const folded = foldPath(small, path), out = grow(folded.goal, path, { nodes: 0, until: Math.min(limit, clock() + 25), units: false });
346
+ local = 'tree' in out ? withDeadline(limit, () => widen(folded.goal, small, out.tree, folded.opaque, path, path)) : undefined;
347
+ }
348
+ if (local) {
349
+ tree = local;
350
+ proofSource = small;
351
+ }
352
+ }
353
+ finally {
354
+ atPoint.on = oldPoint;
355
+ }
356
+ }
357
+ const accepted = !!tree && accept(good, proofSource, tree, path, scope, index), outcome = accepted ? 'checked' : validModel ? 'sat' : 'unknown';
358
+ emitted = accepted;
359
+ attempted.set(key, { version, outcome });
360
+ trace.push({ stage: 'closure-source', scope: scopes.indexOf(scope), index, independent, core: 'tree' in q ? undefined : q.core?.length, tree: !!tree, outcome, ms: clock() - before });
361
+ return outcome;
362
+ }
363
+ finally {
364
+ endFieldAttempt(meter, emitted);
365
+ }
366
+ };
367
+ // Phase C only: use active proved facts, then decide one numeric goal per
368
+ // leaf. Natural-subtraction splitting is confined to this arithmetic phase.
369
+ const pure = (c, path) => { let other = false; walkLive(c, path, (o) => { if (o.op === 'get' || o.op === 'var' && wits.has(o.name))
370
+ other = true; }); return !other; };
371
+ const replacements = Object.fromEntries([...maps].map(map => [map, (key) => { const r = cert.reads.find(r => r[1] === map && JSON.stringify(r[2]) === JSON.stringify(key)); return r ? x(r[0]) : { op: 'get', map, key }; }]));
372
+ const flags = Object.fromEntries(Object.keys(m.step.flags ?? {}).map(name => [name, { op: 'flag', name }]));
373
+ const abstracted = raw.map(c => substC(c, { vars: {}, maps: replacements, flags }));
374
+ const finish = (scope, end, depth = 0) => {
375
+ if (!alive())
376
+ return undefined;
377
+ scope = addScope(scope);
378
+ const before = clock(), scopeKey = JSON.stringify([...scope].map(([id, a]) => [id, a.holds])), excluded = excludedAt.get(scopeKey) ?? new Set(), previousEnd = leafEnd;
379
+ excludedAt.set(scopeKey, excluded);
380
+ leafEnd = end;
381
+ const numericFor = () => ({ name: g.name, hyps: [...abstracted.flatMap(c => piecesAt(c, scope)).filter(c => pure(c, scope)), ...countBindingsAt(cert.reads, scope), ...active(saved, scope).map(s => s.good).filter(c => pure(c, scope))] });
382
+ const stop = (reason) => { trace.push({ stage: 'closure-final', mode: 'model-driven', outcome: 'unknown', reason, path: [...scope], cuts: active(saved, scope).length, ms: clock() - before, total: clock() - started }); return undefined; };
383
+ const merge = (candidate) => {
384
+ const path = new Map(scope);
385
+ for (const a of candidate.values()) {
386
+ const known = decide(a.lin, path);
387
+ if (known !== undefined && known !== a.holds)
388
+ return undefined;
389
+ path.set(canon(a.lin), a);
390
+ }
391
+ return addScope(path);
392
+ };
393
+ try {
394
+ for (let round = 0; round <= pool.length && building(); round++) {
395
+ rounds++;
396
+ const available = active(saved, scope), numeric = numericFor(), natural = proveNaturalCases(numeric, scope, end, trace, { deferCheck: true }), q = natural ? { tree: natural } : modelSequence(scope)(numeric, end);
397
+ let proof = 'tree' in q ? q.tree : undefined;
398
+ // An empty core refutes the path alone; it still needs a transported proof.
399
+ if (!proof && !('tree' in q) && q.why === REFUTED && q.core) {
400
+ const small = { ...numeric, hyps: q.core.map(i => numeric.hyps[i]) }, direct = fast(small, scope), out = direct ? undefined : grow(small, scope, { nodes: 0, until: end, units: false }), local = direct ?? (out && 'tree' in out ? out.tree : undefined);
401
+ if (local)
402
+ proof = transport(small, numeric, local, scope, scope);
403
+ }
404
+ if (proof) {
405
+ const extended = lemmaPath(available.map(s => s.lemma), scope), lifted = liftCountProxies(numeric, g, proof, cert.reads, scope, extended, e => trace.push({ stage: 'closure-transport', ...e }), { deferCheck: true });
406
+ const tree = lifted && (options.conditional ? markConditionalProof(g, lifted, available.map(s => s.lemma)) : inlineConditionalCuts(g, g, lifted, extended, scope, available.map(s => s.lemma), wallEnd(), e => trace.push({ stage: 'closure-inline', ...e })));
407
+ trace.push({ stage: 'closure-final', mode: 'model-driven', fixedPoint, hyps: numeric.hyps.length, cuts: available.length, rounds: round + 1, closedIndices: available.flatMap(s => s.index === undefined ? [] : [s.index]), outcome: tree ? 'checked' : 'untransported', ms: clock() - before, total: clock() - started });
408
+ return tree;
409
+ }
410
+ if ('tree' in q || q.stuck !== 'sat' || !q.witness)
411
+ return stop('no-numeric-model');
412
+ const point = { ...q.witness };
413
+ for (const index of pool) {
414
+ const h = g.hyps[raw.length + index];
415
+ if (h?.op === 'or' && h.xs[0]?.op === '<=')
416
+ walkLive(h.xs[0], scope, (o) => { if (o.op === 'var' && !Object.hasOwn(point, o.name))
417
+ point[o.name] = 0; });
418
+ }
419
+ const model = validPoint(numeric, scope, point);
420
+ if (!model)
421
+ return stop('invalid-numeric-model');
422
+ rowModel = point;
423
+ const violated = pool.filter(index => { const h = g.hyps[raw.length + index]; return h?.op === 'or' && h.xs[0]?.op === '<=' && brokenOf({ name: 'candidate', hyps: [h.xs[0]] })(model).length > 0; }), pending = new Set(violated.filter(i => !excluded.has(i))), startedVersion = saved.length;
424
+ if (pairs.some(([a, b]) => truth({ op: '=', a, b }, scope) === undefined)) {
425
+ rowSources = new Set(violated.flatMap(index => [...sourceRows.get(index) ?? []]));
426
+ return stop('row-demand');
427
+ }
428
+ trace.push({ stage: 'closure-model-round', round: round + 1, scope: scopes.indexOf(scope), violated, pending: [...pending], excluded: [...excluded], cuts: available.length, pool: pool.length });
429
+ if (!pending.size) {
430
+ fixedPoint = true;
431
+ return stop('no-unexcluded-violated-fact');
432
+ }
433
+ while (pending.size && building()) {
434
+ const indices = [...pending], baseGoal = numericFor(), goods = indices.map(i => g.hyps[raw.length + i].xs[0]), assumed = { ...baseGoal, hyps: [...baseGoal.hyps, ...goods] }, selection = modelSequence(scope)(assumed, end);
435
+ const core = 'tree' in selection ? [...usedHyps(assumed, selection.tree, scope)] : selection.why === REFUTED ? selection.core : undefined;
436
+ const validAssumedModel = !('tree' in selection) && selection.stuck === 'sat' && selection.witness && validPoint(assumed, scope, selection.witness);
437
+ if (!core?.length && !validAssumedModel)
438
+ return stop('no-batch-core-or-model');
439
+ // A partial violated set can leave another numeric model: its members
440
+ // are still useful cuts against the current model, not a generator gap.
441
+ const chosen = core?.length ? core.filter(i => i >= baseGoal.hyps.length).map(i => indices[i - baseGoal.hyps.length]).filter(i => i !== undefined) : indices;
442
+ trace.push({ stage: 'closure-batch-core', scope: scopes.indexOf(scope), round: round + 1, indices: chosen, core: core?.length, selector: core?.length ? 'refuted' : 'sat' });
443
+ if (!chosen.length) {
444
+ if (saved.length > startedVersion)
445
+ break;
446
+ return stop('empty-batch-core');
447
+ }
448
+ let changed = false;
449
+ for (const index of chosen) {
450
+ if (!building())
451
+ break;
452
+ pending.delete(index);
453
+ const candidates = scopesFor(index).map(merge).filter((p) => p !== undefined), hinted = memberHints.has(vector(cert.insts[index])), order = hinted ? [...candidates.filter(p => p !== scope), scope] : [scope, ...candidates], seen = new Set();
454
+ let allSat = true, proved = false;
455
+ for (const path of order) {
456
+ if (seen.has(path))
457
+ continue;
458
+ seen.add(path);
459
+ if (!building()) {
460
+ allSat = false;
461
+ break;
462
+ }
463
+ const result = attempt(index, path, end);
464
+ if (result === 'checked') {
465
+ changed = true;
466
+ proved = true;
467
+ break;
468
+ }
469
+ if (result !== 'sat')
470
+ allSat = false;
471
+ }
472
+ if (allSat && !proved)
473
+ excluded.add(index);
474
+ }
475
+ const guard = saved.slice(startedVersion).flatMap(s => s.lemma.when).find(atom => scalarAtoms.has(canon(atom)) && decide(atom, scope) === undefined);
476
+ if (guard) {
477
+ if (depth >= 8)
478
+ return stop('scalar-depth');
479
+ const yes = scalar(put(scope, guard, true), end, depth + 1), no = yes && scalar(put(scope, guard, false), end, depth + 1);
480
+ trace.push({ stage: 'closure-model-split', depth, split: guard, proposed: !!yes && !!no, ms: clock() - before });
481
+ return yes && no ? { split: guard, yes, no } : undefined;
482
+ }
483
+ if (changed)
484
+ break;
485
+ }
486
+ if (saved.length === startedVersion)
487
+ return stop(building() ? 'batch-exhausted' : 'time');
488
+ }
489
+ return stop('time');
490
+ }
491
+ finally {
492
+ leafEnd = previousEnd;
493
+ }
494
+ };
495
+ const scalar = (path, end, depth = 0) => {
496
+ if (!alive())
497
+ return undefined;
498
+ const candidates = new Map();
499
+ for (const { lemma } of saved) {
500
+ if (lemma.when.some(atom => decide(atom, path) === false))
501
+ continue;
502
+ for (const atom of lemma.when) {
503
+ const id = canon(atom);
504
+ if (!scalarAtoms.has(id) || decide(atom, path) !== undefined)
505
+ continue;
506
+ const old = candidates.get(id);
507
+ candidates.set(id, { atom, uses: (old?.uses ?? 0) + 1 });
508
+ }
509
+ }
510
+ const next = [...candidates.values()].sort((a, b) => b.uses - a.uses)[0];
511
+ if (!next || depth >= 8)
512
+ return finish(path, end, depth);
513
+ const yes = scalar(put(path, next.atom, true), end, depth + 1), no = yes && scalar(put(path, next.atom, false), end, depth + 1);
514
+ trace.push({ stage: 'closure-scalar-case', depth, split: next.atom, proposed: !!yes && !!no });
515
+ return yes && no ? { split: next.atom, yes, no } : undefined;
516
+ };
517
+ let rowModel, rowSources = new Set();
518
+ let leavesLeft = Math.max(1, complete.length);
519
+ const atLeaf = (path, end) => {
520
+ rowModel = undefined;
521
+ rowSources = new Set();
522
+ const before = clock(), remaining = Math.max(0, until - before), draw = leafAllowance(remaining, leavesLeft), stop = Math.min(end, before + draw);
523
+ trace.push({ stage: 'closure-leaf-budget', remaining, leavesLeft, draw, granted: Math.max(0, stop - before), end: stop });
524
+ return scalar(path, stop);
525
+ };
526
+ const rowTrace = (event) => { const e = event; if (e.stage === 'row-case' || e.stage === 'row-mirror')
527
+ leavesLeft = Math.max(1, leavesLeft - 1); trace.push(event); };
528
+ let tree = pairs.length ? proveRowCases(g, base, pairs, until, atLeaf, rowTrace, { deferToCaller: true, splitEqual: true, model: () => rowModel, sources: () => rowSources }) : atLeaf(base, until);
529
+ for (let i = pins.length - 1; tree && i >= 0; i--)
530
+ tree = { split: pins[i].split, yes: tree, no: pins[i].no };
531
+ const checked = !!tree && alive() && (options.conditional ? checkConditionalProof(g, tree, root) : check(g, tree, root));
532
+ trace.push({ stage: 'closure-complete', cuts: saved.length, rounds, fixedPoint, checked, total: clock() - started });
533
+ return checked ? tree : undefined;
534
+ }
@@ -0,0 +1,2 @@
1
+ import { type E } from '../machine.js';
2
+ export declare function emptyCountSource(body: E, aliases?: Record<string, E>): boolean;
@@ -0,0 +1,40 @@
1
+ export function emptyCountSource(body, aliases = {}) {
2
+ let work = 16384;
3
+ const same = (a, b, depth = 0) => {
4
+ if (--work < 0 || depth > 128)
5
+ return false;
6
+ if (a?.op === 'var' && aliases[a.name])
7
+ a = aliases[a.name];
8
+ if (b?.op === 'var' && aliases[b.name])
9
+ b = aliases[b.name];
10
+ if (a === b)
11
+ return true;
12
+ if (!a || !b || typeof a !== 'object' || typeof b !== 'object')
13
+ return false;
14
+ const keys = Object.keys(a);
15
+ return keys.length === Object.keys(b).length && keys.every(k => Object.hasOwn(b, k) && same(a[k], b[k], depth + 1));
16
+ };
17
+ const impossible = (c, depth = 0) => {
18
+ if (--work < 0 || depth > 128)
19
+ return false;
20
+ if (c.op === 'or')
21
+ return c.xs.every(x => impossible(x, depth + 1));
22
+ if (c.op !== 'and')
23
+ return false;
24
+ const xs = [], flatten = (x, d) => { if (--work < 0 || d > 128)
25
+ return; if (x.op === 'and')
26
+ x.xs.forEach(y => flatten(y, d + 1));
27
+ else
28
+ xs.push(x); };
29
+ flatten(c, depth);
30
+ return work >= 0 && (xs.some(x => x.op === 'or' && impossible(x, depth + 1)) || xs.some(x => x.op === 'not' && xs.some(y => same(x.x, y, depth + 1))));
31
+ };
32
+ const zero = (e, depth = 0) => {
33
+ if (--work < 0 || depth > 128)
34
+ return false;
35
+ if (e.op === 'const')
36
+ return e.value === 0;
37
+ return e.op === 'if' && (impossible(e.c, depth + 1) ? zero(e.else, depth + 1) : zero(e.then, depth + 1) && zero(e.else, depth + 1));
38
+ };
39
+ return zero(body);
40
+ }
@@ -0,0 +1,23 @@
1
+ import { type C, type Machine } from '../machine.js';
2
+ import { type CountCert, type CountDecl, type Goal, type Path, type Tree } from '../../kernel/kernel.js';
3
+ import { type SourceProofMemo } from './source-memo.js';
4
+ import { type FieldDemand } from './field-demand.js';
5
+ type Proposal = Pick<CountCert, 'reads' | 'insts'>;
6
+ export declare function countBindingsAt(reads: CountCert['reads'], root: Path): C[];
7
+ export declare function fieldBounds(m: Machine, ds: CountDecl[], cert: Proposal, options?: {
8
+ claim?: C;
9
+ path?: Path;
10
+ }): C[];
11
+ export declare function emptyCountCandidate(m: Machine, cert: Proposal, inst: Proposal['insts'][number]): boolean;
12
+ export declare const fieldBoundLemmas: typeof fieldBoundLemmasImpl;
13
+ declare function fieldBoundLemmasImpl(m: Machine, ds: CountDecl[], g: Goal, cert: Proposal, until: number, trace: object[], onModel?: (goal: Goal, witness: Record<string, number>) => boolean, root?: Path, options?: {
14
+ splitRows?: boolean;
15
+ deferCheck?: boolean;
16
+ fieldClaim?: C;
17
+ memo?: SourceProofMemo;
18
+ closure?: boolean;
19
+ conditional?: boolean;
20
+ fieldDemand?: FieldDemand;
21
+ onSourceModel?: (goal: Goal, witness: Record<string, number>, path: Path) => void;
22
+ }): Tree | undefined;
23
+ export {};