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,8 @@
1
+ // Direct production operations. These helpers propose ordinary trees only;
2
+ // no profiler, environment switch, or alternative checker is involved.
3
+ export { check } from "../../kernel/kernel.js";
4
+ export { grow, widen, rowsAt } from "../../kernel/prove.js";
5
+ export { modelSequence } from "../../kernel/model-sequence.js";
6
+ export { solve, refuteFast } from "../solver.js";
7
+ export const wallSpan = (_phase, run) => run();
8
+ export const wallTree = wallSpan;
@@ -0,0 +1,8 @@
1
+ import { type C } from '../machine.js';
2
+ import { type CountCert, type Goal, type Path } from '../../kernel/kernel.js';
3
+ type Proposal = Pick<CountCert, 'reads' | 'insts'>;
4
+ export declare function preStateCountSource(goal: Goal, cert: Proposal, claim: C, path: Path, extra?: C[]): {
5
+ goal: Goal;
6
+ cert: Proposal;
7
+ };
8
+ export {};
@@ -0,0 +1,18 @@
1
+ import { piecesAt, walkLive } from "./live-dependencies.js";
2
+ export function preStateCountSource(goal, cert, claim, path, extra = []) {
3
+ const post = cert.reads.filter(r => r[1].endsWith('#')), postIds = new Set(post.map(r => r[0])), postMaps = new Set(post.map(r => r[1]));
4
+ const keep = cert.insts.map((q, index) => ({ q, index })).filter(({ q }) => q.terms.every(([, id]) => !postIds.has(id))), indices = new Set(keep.map(({ index }) => index));
5
+ const discarded = new Set(cert.insts.filter((_, i) => !indices.has(i)).map(q => q.wit)), offset = goal.hyps.length - cert.insts.length;
6
+ const weaken = (c) => {
7
+ if (c.op === 'and') {
8
+ const xs = c.xs.flatMap(child => { const kept = weaken(child); return kept ? [kept] : []; });
9
+ return xs.length ? { ...c, xs } : undefined;
10
+ }
11
+ let invalid = false;
12
+ walkLive(c, path, (o) => { if (o.op === 'get' && postMaps.has(o.map) || o.op === 'var' && (postIds.has(o.name) || discarded.has(o.name)))
13
+ invalid = true; });
14
+ return invalid ? undefined : c;
15
+ };
16
+ const hyps = goal.hyps.slice(0, offset).flatMap(c => piecesAt(c, path)).flatMap(c => { const kept = weaken(c); return kept ? [kept] : []; });
17
+ return { goal: { ...goal, hyps: [...hyps, ...extra, claim, ...keep.map(({ index }) => goal.hyps[offset + index])] }, cert: { reads: cert.reads.filter(r => !postIds.has(r[0])), insts: keep.map(({ q }) => q) } };
18
+ }
@@ -0,0 +1,9 @@
1
+ import { type Goal, type Path, type Tree } from '../../kernel/kernel.js';
2
+ export declare function rebasePath(g: Goal, tree: Tree, from: Path, to: Path, until: number, target?: Goal): Tree | undefined;
3
+ export declare function pruneForcedCuts(g: Goal, tree: Tree, root: Path, cuts: {
4
+ split: Record<string, number>;
5
+ no: Tree;
6
+ }[], until: number): {
7
+ tree: Tree;
8
+ removed: number;
9
+ };
@@ -0,0 +1,70 @@
1
+ // Untrusted exact reindexing after removing path assumptions. This never
2
+ // searches and never certifies a result; the caller must check the final tree.
3
+ import { canon } from "../../kernel/kernel.js";
4
+ import { late } from "../../kernel/prove.js";
5
+ import { rowsAt, wallTree } from "./ops.js";
6
+ export function rebasePath(g, tree, from, to, until, target = g) {
7
+ return wallTree(target === g ? 'pin-pruning' : 'source-reindexing', () => {
8
+ const indices = new WeakMap();
9
+ const visit = (t, a, b) => {
10
+ if (late(until))
11
+ return undefined;
12
+ if (!('leaf' in t)) {
13
+ const id = canon(t.split), known = b.get(id)?.holds;
14
+ if (known !== undefined)
15
+ return visit(known ? t.yes : t.no, new Map(a).set(id, { lin: t.split, holds: known }), b);
16
+ const yes = visit(t.yes, new Map(a).set(id, { lin: t.split, holds: true }), new Map(b).set(id, { lin: t.split, holds: true }));
17
+ const no = yes && visit(t.no, new Map(a).set(id, { lin: t.split, holds: false }), new Map(b).set(id, { lin: t.split, holds: false }));
18
+ return yes && no ? { split: t.split, yes, no } : undefined;
19
+ }
20
+ const before = rowsAt(g, a), after = rowsAt(target, b);
21
+ let at = indices.get(after);
22
+ if (!at) {
23
+ at = new Map();
24
+ after.forEach((r, i) => { const id = canon(r.lin); if (!at.has(id))
25
+ at.set(id, i); });
26
+ indices.set(after, at);
27
+ }
28
+ const map = (i) => i < before.length ? at.get(canon(before[i].lin)) : i - before.length + after.length;
29
+ const leaf = [];
30
+ for (const step of t.leaf) {
31
+ if (step.kind !== 'input') {
32
+ leaf.push(step);
33
+ continue;
34
+ }
35
+ const index = map(step.index);
36
+ if (index === undefined)
37
+ return undefined;
38
+ leaf.push({ ...step, index });
39
+ }
40
+ const products = [];
41
+ for (const [a, b] of t.products ?? []) {
42
+ const x = map(a), y = map(b);
43
+ if (x === undefined || y === undefined)
44
+ return undefined;
45
+ products.push([x, y]);
46
+ }
47
+ return { leaf, ...(t.products ? { products } : {}), ...(t.squares ? { squares: t.squares } : {}) };
48
+ };
49
+ return visit(tree, from, to);
50
+ });
51
+ }
52
+ // Cuts are listed in the order they extended the path. Drop a cut only when
53
+ // its retained branch can be reindexed without that assumption. Rejected or
54
+ // timed-out proposals retain the original exhaustive split and its proof.
55
+ export function pruneForcedCuts(g, tree, root, cuts, until) {
56
+ const paths = [new Map(root)];
57
+ for (const cut of cuts)
58
+ paths.push(new Map(paths.at(-1)).set(canon(cut.split), { lin: cut.split, holds: true }));
59
+ let out = tree, removed = 0;
60
+ for (let i = cuts.length - 1; i >= 0; i--) {
61
+ const cut = cuts[i], shorter = rebasePath(g, out, paths[i + 1], paths[i], until);
62
+ if (shorter) {
63
+ out = shorter;
64
+ removed++;
65
+ }
66
+ else
67
+ out = { split: cut.split, yes: out, no: cut.no };
68
+ }
69
+ return { tree: out, removed };
70
+ }
@@ -0,0 +1,2 @@
1
+ import { type Goal, type Path, type Tree } from '../../kernel/kernel.js';
2
+ export declare function reframeCountTree(goal: Goal, tree: Tree, from: Path, to: Path, frame: (path: Path) => Path, until: number): Tree | undefined;
@@ -0,0 +1,24 @@
1
+ // Reindex a plain proof into a counted tree whose conditional cuts become
2
+ // active at different descendant paths. Root-only rebasing is insufficient:
3
+ // a newly active cut changes the leaf's input-row numbers.
4
+ import { canon, check } from "../../kernel/kernel.js";
5
+ import { late } from "../../kernel/prove.js";
6
+ import { rebasePath } from "./rebase-path.js";
7
+ export function reframeCountTree(goal, tree, from, to, frame, until) {
8
+ const visit = (node, source, target) => {
9
+ if (late(until))
10
+ return;
11
+ if ('leaf' in node) {
12
+ const at = frame(target), leaf = rebasePath(goal, node, source, at, until);
13
+ return leaf && check(goal, leaf, at) ? leaf : undefined;
14
+ }
15
+ const id = canon(node.split);
16
+ if (target.has(id) || Object.keys(node.split).every(name => name === '1'))
17
+ return;
18
+ const next = (path, holds) => new Map(path).set(id, { lin: node.split, holds });
19
+ const yes = visit(node.yes, next(source, true), next(target, true));
20
+ const no = yes && visit(node.no, next(source, false), next(target, false));
21
+ return yes && no ? { split: node.split, yes, no } : undefined;
22
+ };
23
+ return visit(tree, from, to);
24
+ }
@@ -0,0 +1,2 @@
1
+ import { type Goal, type Path, type Tree } from '../../kernel/kernel.js';
2
+ export declare function renameProof(goal: Goal, tree: Tree, from: Path, to: Path, names: Record<string, string>, until: number, target?: Goal, indices?: WeakMap<object, Map<string, number>>): Tree | undefined;
@@ -0,0 +1,102 @@
1
+ // Untrusted instantiation of an ordinary subtree. Rename its columns and match
2
+ // each used row at the destination; no solver, axiom, or symmetry rule is used.
3
+ // The caller must check the emitted full tree (or its enclosing certificate).
4
+ import { x } from "../machine.js";
5
+ import { add, scale } from "../solver.js";
6
+ import { times } from "../../kernel/reader.js";
7
+ import { canon, canonFlip, cellParts, columnTerm, factorsOf, isCell, linear, substE } from "../../kernel/kernel.js";
8
+ import { late, rowsAt } from "../../kernel/prove.js";
9
+ export function renameProof(goal, tree, from, to, names, until, target = goal, indices = new WeakMap()) {
10
+ const vars = Object.fromEntries(Object.entries(names).map(([a, b]) => [a, x(b)])), terms = new WeakMap();
11
+ const renamed = (e) => { let next = terms.get(e); if (!next) {
12
+ next = substE(e, { vars, maps: {}, flags: {} });
13
+ terms.set(e, next);
14
+ } return next; };
15
+ const form = (lin, path) => {
16
+ let out = {};
17
+ for (const [name, k] of Object.entries(lin)) {
18
+ const next = column(name, path);
19
+ if (!next)
20
+ return undefined;
21
+ out = add(out, scale(next, k));
22
+ }
23
+ return out;
24
+ };
25
+ const column = (name, path) => {
26
+ if (name === '1')
27
+ return { '1': 1 };
28
+ const term = columnTerm(name);
29
+ if (term)
30
+ return linear(renamed(term), path);
31
+ const factors = factorsOf(name);
32
+ if (factors.length > 1) {
33
+ let out = { '1': 1 };
34
+ for (const factor of factors) {
35
+ const next = column(factor, path), product = next && times(out, next);
36
+ if (!product)
37
+ return undefined;
38
+ out = product;
39
+ }
40
+ return out;
41
+ }
42
+ if (isCell(name)) {
43
+ const cell = cellParts(name), parts = cell.keys ?? (cell.key ? [cell.key] : []), keys = parts.map(key => form(key, path));
44
+ if (!keys.length || keys.some(key => !key))
45
+ return undefined;
46
+ const key = cell.keys ? `⟨${keys.map(key => canon(key)).join('|')}⟩` : canon(keys[0]);
47
+ return { [`${cell.map}[${key}]`]: 1 };
48
+ }
49
+ return { [Object.hasOwn(names, name) ? names[name] : name]: 1 };
50
+ };
51
+ const visit = (t, a, b) => {
52
+ if (late(until))
53
+ return undefined;
54
+ if ('split' in t) {
55
+ const split = form(t.split, b);
56
+ if (!split)
57
+ return undefined;
58
+ const old = canon(t.split), id = canon(split), known = Object.keys(split).every(k => k === '1') ? (split['1'] ?? 0) <= 0 : b.has(id) ? b.get(id).holds : b.has(canonFlip(split)) ? !b.get(canonFlip(split)).holds : undefined;
59
+ if (known !== undefined)
60
+ return visit(known ? t.yes : t.no, new Map(a).set(old, { lin: t.split, holds: known }), b);
61
+ const yes = visit(t.yes, new Map(a).set(old, { lin: t.split, holds: true }), new Map(b).set(id, { lin: split, holds: true }));
62
+ const no = yes && visit(t.no, new Map(a).set(old, { lin: t.split, holds: false }), new Map(b).set(id, { lin: split, holds: false }));
63
+ return yes && no ? { split, yes, no } : undefined;
64
+ }
65
+ const before = rowsAt(goal, a), after = rowsAt(target, b);
66
+ let at = indices.get(after);
67
+ if (!at) {
68
+ at = new Map();
69
+ after.forEach((row, i) => { const id = canon(row.lin); if (!at.has(id))
70
+ at.set(id, i); });
71
+ indices.set(after, at);
72
+ }
73
+ const index = (i) => { if (!Number.isInteger(i) || i < 0)
74
+ return undefined; if (i >= before.length)
75
+ return i - before.length + after.length; const row = form(before[i].lin, b); return row && at.get(canon(row)); };
76
+ const leaf = [], products = [], squares = [];
77
+ for (const step of t.leaf) {
78
+ if (step.kind !== 'input')
79
+ leaf.push(step);
80
+ else {
81
+ const i = index(step.index);
82
+ if (i === undefined)
83
+ return undefined;
84
+ leaf.push({ ...step, index: i });
85
+ }
86
+ }
87
+ for (const [i, j] of t.products ?? []) {
88
+ const a = index(i), b = index(j);
89
+ if (a === undefined || b === undefined)
90
+ return undefined;
91
+ products.push([a, b]);
92
+ }
93
+ for (const square of t.squares ?? []) {
94
+ const next = form(square, b);
95
+ if (!next)
96
+ return undefined;
97
+ squares.push(next);
98
+ }
99
+ return { leaf, ...(t.products ? { products } : {}), ...(t.squares ? { squares } : {}) };
100
+ };
101
+ return visit(tree, from, to);
102
+ }
@@ -0,0 +1,2 @@
1
+ import { type Goal, type Path, type Tree } from '../../kernel/kernel.js';
2
+ export declare function replayLinearSkeleton(goal: Goal, hint: Tree, root: Path, until: number): Tree | undefined;
@@ -0,0 +1,28 @@
1
+ // An untrusted proof supplies split hints only. Every replacement leaf is
2
+ // proved from the original goal/path by the ordinary linear solver/checker.
3
+ import { canon, check } from "../../kernel/kernel.js";
4
+ import { late, rowsAt } from "../../kernel/prove.js";
5
+ import { solve } from "../solver.js";
6
+ export function replayLinearSkeleton(goal, hint, root, until) {
7
+ const go = (tree, path) => {
8
+ if (late(until))
9
+ return;
10
+ if ('leaf' in tree) {
11
+ const result = solve(rowsAt(goal, path), 2000);
12
+ if (result.kind !== 'refuted')
13
+ return;
14
+ const out = { leaf: result.steps };
15
+ return check(goal, out, path) ? out : undefined;
16
+ }
17
+ const id = canon(tree.split), known = path.get(id)?.holds;
18
+ if (known !== undefined)
19
+ return go(known ? tree.yes : tree.no, path);
20
+ const yes = go(tree.yes, new Map(path).set(id, { lin: tree.split, holds: true }));
21
+ if (!yes)
22
+ return;
23
+ const no = go(tree.no, new Map(path).set(id, { lin: tree.split, holds: false }));
24
+ return no ? { split: tree.split, yes, no } : undefined;
25
+ };
26
+ const tree = go(hint, root);
27
+ return tree && check(goal, tree, root) ? tree : undefined;
28
+ }
@@ -0,0 +1,16 @@
1
+ import { type C, type E, type Machine } from '../machine.js';
2
+ import { type CountCert, type Goal, type Path, type Tree } from '../../kernel/kernel.js';
3
+ export type RowPair = readonly [E, E];
4
+ export declare function writesReadState(m: Machine, cert: Pick<CountCert, 'reads'>, path: Path, claim?: C): boolean;
5
+ export declare function demandedRowPair(pairs: RowPair[], path: Path, model: Record<string, number>, sources?: ReadonlySet<string>): RowPair | undefined;
6
+ export declare function activeWriteKey(m: Machine, root: Path): E | undefined;
7
+ export declare function activeWriteRow(m: Machine, root: Path): string | undefined;
8
+ export declare function rowPairs(m: Machine, cert: Pick<CountCert, 'reads'>, root?: Path, fieldClaim?: C): RowPair[];
9
+ export declare const proveRowCases: typeof proveRowCasesImpl;
10
+ declare function proveRowCasesImpl(g: Goal, root: Path, pairs: RowPair[], until: number, prove: (path: Path, until: number) => Tree | undefined, trace?: (e: object) => void, options?: {
11
+ deferToCaller?: boolean;
12
+ splitEqual?: boolean;
13
+ model?: () => Record<string, number> | undefined;
14
+ sources?: () => ReadonlySet<string>;
15
+ }): Tree | undefined;
16
+ export {};
@@ -0,0 +1,292 @@
1
+ import { searchNow as countedSearchNow } from "../wall.js";
2
+ // Untrusted row-equality case proposals. Every ordering branch is covered and
3
+ // every reused recipe is widened and checked at its destination path.
4
+ import { n, same, walkOnce, x } from "../machine.js";
5
+ import { canon, linear, substC, substE, truth } from "../../kernel/kernel.js";
6
+ import { clock, wallAt, withDeadline } from "../../kernel/prove.js";
7
+ import { scale, sub } from "../solver.js";
8
+ import { walkLive } from "./live-dependencies.js";
9
+ import { wallTree, widen } from "./ops.js";
10
+ import { checkConditionalProof as check, hasConditionalProof, transportConditionalProof } from "./conditional-proof.js";
11
+ import { renameProof } from "./rename-proof.js";
12
+ // A syntactic dependency test only. Unknown count declarations stay conservative;
13
+ // this selects a search strategy, never supplies a frame as a trusted fact.
14
+ export function writesReadState(m, cert, path, claim) {
15
+ const maps = new Set(), vars = new Set(), seen = new Set();
16
+ const flags = {};
17
+ for (const [name, c] of Object.entries(m.step.flags ?? {}))
18
+ flags[name] = c.op === 'all' ? same(x(`?${name}`), n(1)) : substC(c, { vars: {}, maps: {}, flags });
19
+ const visit = (value) => walkLive(value, path, (o) => {
20
+ if (o.op === 'var')
21
+ vars.add(o.name);
22
+ if (o.op === 'get')
23
+ read(o.map);
24
+ });
25
+ const read = (name) => {
26
+ name = name.endsWith('#') ? name.slice(0, -1) : name;
27
+ if (seen.has(name))
28
+ return;
29
+ seen.add(name);
30
+ const count = m.counts?.[name];
31
+ if (count) {
32
+ visit(count.below);
33
+ visit(count.body);
34
+ }
35
+ else
36
+ maps.add(name);
37
+ };
38
+ const wanted = new Set();
39
+ if (claim)
40
+ walkLive(claim, path, (o) => { for (const [id, name, key] of cert.reads)
41
+ if (o.op === 'var' && o.name === id || o.op === 'get' && o.map === name && JSON.stringify(o.key) === JSON.stringify(key))
42
+ wanted.add(id); });
43
+ for (const [id, name, key] of cert.reads)
44
+ if (!claim || wanted.has(id)) {
45
+ read(name);
46
+ visit(key);
47
+ }
48
+ visit(claim);
49
+ const identity = (value, want) => {
50
+ if (JSON.stringify(value) === JSON.stringify(want))
51
+ return true;
52
+ if (value.op !== 'if')
53
+ return false;
54
+ const t = truth(value.c, path);
55
+ return t === undefined ? identity(value.then, want) && identity(value.else, want) : identity(t ? value.then : value.else, want);
56
+ };
57
+ for (const [name, write] of Object.entries(m.step.maps ?? {}))
58
+ if (maps.has(name)) {
59
+ const key = 'each' in write ? x(write.each) : write.key;
60
+ if (!identity(substE(write.value, { vars: {}, maps: {}, flags }), { op: 'get', map: name, key }))
61
+ return true;
62
+ }
63
+ for (const [name, value] of Object.entries(m.step.state ?? {}))
64
+ if (vars.has(name) && !identity(substE(value, { vars: {}, maps: {}, flags }), x(name)))
65
+ return true;
66
+ // A packet may use a synthetic count not retained on the machine.
67
+ return [...maps].some(name => !(name in (m.maps ?? {})) && !(m.inputMaps ?? []).includes(name) && Object.keys(m.step.maps ?? {}).length > 0);
68
+ }
69
+ // Prefer a row equal in the model, then another fully assigned unresolved row.
70
+ // Missing/NaN model cells cannot choose a split. A model is a hint, not a proof.
71
+ export function demandedRowPair(pairs, path, model, sources = new Set()) {
72
+ const ranked = pairs.flatMap((pair, index) => {
73
+ if (truth({ op: '=', a: pair[0], b: pair[1] }, path) !== undefined)
74
+ return [];
75
+ const a = linear(pair[0], path), b = linear(pair[1], path);
76
+ if (!a || !b)
77
+ return [];
78
+ let value = 0;
79
+ for (const [key, k] of Object.entries(sub(a, b))) {
80
+ const v = key === '1' ? 1 : model[key];
81
+ if (!Number.isFinite(v))
82
+ return [];
83
+ value += k * v;
84
+ }
85
+ if (!Number.isFinite(value))
86
+ return [];
87
+ let relevant = false;
88
+ walkOnce(pair[0], (o) => { if (o.op === 'var' && sources.has(o.name))
89
+ relevant = true; });
90
+ return [{ pair, index, equal: value === 0, relevant }];
91
+ }).sort((a, b) => Number(b.equal && b.relevant) - Number(a.equal && a.relevant) || Number(b.relevant) - Number(a.relevant) || Number(b.equal) - Number(a.equal) || a.index - b.index);
92
+ return ranked[0]?.pair;
93
+ }
94
+ // Prefer exact scalar destinations, including constant-index initialization.
95
+ export function activeWriteKey(m, root) {
96
+ const flags = {}, found = new Map();
97
+ for (const [name, c] of Object.entries(m.step.flags ?? {}))
98
+ flags[name] = c.op === 'all' ? same(x(`?${name}`), n(1)) : substC(c, { vars: {}, maps: {}, flags });
99
+ for (const write of Object.values(m.step.maps ?? {})) {
100
+ if (!('each' in write))
101
+ continue;
102
+ walkLive(substE(write.value, { vars: {}, maps: {}, flags }), root, (o) => {
103
+ if (o.op !== 'if' || truth(o.c, root) !== undefined)
104
+ return;
105
+ walkLive(o.c, root, (c) => {
106
+ if (c.op !== '=' || truth(c, root) !== undefined)
107
+ return;
108
+ for (const [at, key] of [[c.a, c.b], [c.b, c.a]]) {
109
+ if (at.op !== 'var' || at.name !== write.each)
110
+ continue;
111
+ let scalar = true;
112
+ walkOnce(key, (e) => { if (e.op === 'get' || e.op === 'var' && e.name === write.each)
113
+ scalar = false; });
114
+ if (!scalar)
115
+ continue;
116
+ const id = JSON.stringify(key), had = found.get(id);
117
+ found.set(id, { key, rank: (had?.rank ?? 0) + 1 });
118
+ }
119
+ });
120
+ });
121
+ }
122
+ return [...found.values()].sort((a, b) => b.rank - a.rank)[0]?.key;
123
+ }
124
+ export function activeWriteRow(m, root) {
125
+ const exact = activeWriteKey(m, root);
126
+ if (exact?.op === 'var' && m.inputs.includes(exact.name))
127
+ return exact.name;
128
+ const flags = {}, inputs = new Set(m.inputs), ranks = new Map();
129
+ for (const [name, c] of Object.entries(m.step.flags ?? {}))
130
+ flags[name] = c.op === 'all' ? same(x(`?${name}`), n(1)) : substC(c, { vars: {}, maps: {}, flags });
131
+ for (const write of Object.values(m.step.maps ?? {})) {
132
+ if (!('each' in write))
133
+ continue;
134
+ const body = substE(write.value, { vars: {}, maps: {}, flags });
135
+ walkLive(body, root, (o) => {
136
+ if (o.op !== 'if' || truth(o.c, root) !== undefined)
137
+ return;
138
+ walkLive(o.c, root, (c) => {
139
+ if (!['=', '<', '<='].includes(c.op) || truth(c, root) !== undefined)
140
+ return;
141
+ let indexed = false, cell = false;
142
+ const found = new Set();
143
+ walkOnce(c, (e) => { if (e.op === 'get')
144
+ cell = true; if (e.op === 'var') {
145
+ if (e.name === write.each)
146
+ indexed = true;
147
+ if (inputs.has(e.name))
148
+ found.add(e.name);
149
+ } });
150
+ if (indexed && !cell) {
151
+ for (const name of found)
152
+ ranks.set(name, (ranks.get(name) ?? 0) + 1);
153
+ }
154
+ });
155
+ });
156
+ }
157
+ return [...ranks].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))[0]?.[0];
158
+ }
159
+ export function rowPairs(m, cert, root = new Map(), fieldClaim) {
160
+ if (!writesReadState(m, cert, root, fieldClaim))
161
+ return [];
162
+ const ranks = new Map(), inputs = new Set(m.inputs);
163
+ walkOnce(m.step.maps, (o) => { if (o.op === 'get' && o.key.op === 'var' && inputs.has(o.key.name))
164
+ ranks.set(o.key.name, (ranks.get(o.key.name) ?? 0) + 1); });
165
+ const fallback = [...ranks].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))[0]?.[0], exact = activeWriteKey(m, root), named = exact ? undefined : activeWriteRow(m, root) ?? fallback, actor = exact ?? (named ? x(named) : undefined);
166
+ if (!actor)
167
+ return [];
168
+ const names = new Set(), read = cert.reads.find(r => r[1].endsWith('#'));
169
+ if (read)
170
+ walkOnce(read[2], (o) => { if (o.op === 'var' && !inputs.has(o.name) && !m.params.includes(o.name))
171
+ names.add(o.name); });
172
+ else if (fieldClaim)
173
+ walkLive(fieldClaim, root, (o) => {
174
+ if (o.op === 'get' && o.map in (m.step.maps ?? {}) && o.key.op === 'var' && !inputs.has(o.key.name) && !m.params.includes(o.key.name))
175
+ names.add(o.key.name);
176
+ });
177
+ return [...names].slice(0, 2).map(name => [x(name), actor]);
178
+ }
179
+ export const proveRowCases = (...args) => wallTree('row-case-reconstruction', () => proveRowCasesImpl(...args));
180
+ function proveRowCasesImpl(g, root, pairs, until, prove, trace, options = {}) {
181
+ if (!pairs.length || clock() >= until)
182
+ return undefined;
183
+ const cache = new Map(), history = new Map();
184
+ const renaming = {}, pair = pairs.length === 2 ? pairs : undefined;
185
+ let mirror = !!pair;
186
+ if (pair)
187
+ for (let i = 0; i < 2; i++) {
188
+ const a = pair[0][i], b = pair[1][i];
189
+ if (JSON.stringify(a) === JSON.stringify(b))
190
+ continue;
191
+ if (a.op !== 'var' || b.op !== 'var' || renaming[a.name] && renaming[a.name] !== b.name || renaming[b.name] && renaming[b.name] !== a.name) {
192
+ mirror = false;
193
+ break;
194
+ }
195
+ renaming[a.name] = b.name;
196
+ renaming[b.name] = a.name;
197
+ }
198
+ const leaf = (path, key) => {
199
+ if (clock() >= until)
200
+ return undefined;
201
+ const begun = clock(), old = cache.get(key);
202
+ const opposite = key.split('/').reverse().join('/');
203
+ const compatible = (old) => {
204
+ const vars = Object.fromEntries(Object.entries(renaming).map(([a, b]) => [a, x(b)]));
205
+ let score = 0;
206
+ for (const [a, b] of pairs) {
207
+ const left = linear(a, old.path), right = linear(b, old.path), nextLeft = linear(substE(a, { vars, maps: {}, flags: {} }), path), nextRight = linear(substE(b, { vars, maps: {}, flags: {} }), path);
208
+ if (!left || !right || !nextLeft || !nextRight)
209
+ continue;
210
+ for (const sign of [1, -1]) {
211
+ const source = old.path.get(canon(scale(sub(left, right), sign)))?.holds, target = path.get(canon(scale(sub(nextLeft, nextRight), sign)))?.holds;
212
+ if (source !== undefined && target !== undefined)
213
+ score += source === target ? 1 : -1;
214
+ }
215
+ }
216
+ return score;
217
+ };
218
+ if (mirror && key.includes('/'))
219
+ for (const old of [...history.get(opposite) ?? []].reverse().sort((a, b) => compatible(b) - compatible(a))) {
220
+ if (compatible(old) < 3 || hasConditionalProof(old.tree))
221
+ continue;
222
+ const t = renameProof(g, old.tree, old.path, path, renaming, Math.min(until, clock() + 50));
223
+ const accepted = !!t && (options.deferToCaller || check(g, t, path));
224
+ if (accepted && t) {
225
+ trace?.({ stage: 'row-mirror', from: opposite, to: key, ms: Math.round(clock() - begun), checked: !options.deferToCaller, proposed: true, deferred: !!options.deferToCaller });
226
+ cache.set(key, { path: new Map(path), tree: t });
227
+ return t;
228
+ }
229
+ }
230
+ if (old) {
231
+ const end = Math.min(until, clock() + 50), t = hasConditionalProof(old.tree) ? transportConditionalProof(g, g, old.tree, old.path, path, Math.min(wallAt(), countedSearchNow() + Math.max(0, end - clock()) * 10)) : withDeadline(end, () => widen(g, g, old.tree, {}, old.path, path));
232
+ const accepted = !!t && (options.deferToCaller || check(g, t, path));
233
+ if (accepted && t) {
234
+ trace?.({ stage: 'row-case', key, cached: true, ms: Math.round(clock() - begun), checked: !options.deferToCaller, proposed: true, deferred: !!options.deferToCaller });
235
+ return t;
236
+ }
237
+ }
238
+ const t = prove(path, Math.min(until, clock() + 1500)), accepted = !!t && (options.deferToCaller || check(g, t, path));
239
+ trace?.({ stage: 'row-case', key, cached: false, ms: Math.round(clock() - begun), checked: !options.deferToCaller && accepted, proposed: !!t, deferred: !!options.deferToCaller });
240
+ if (!t || !accepted)
241
+ return undefined;
242
+ const entry = { path: new Map(path), tree: t };
243
+ cache.set(key, entry);
244
+ history.set(key, [...history.get(key) ?? [], entry]);
245
+ return t;
246
+ };
247
+ const split = (pair, path, yes, no) => {
248
+ const condition = { op: '=', a: pair[0], b: pair[1] }, known = truth(condition, path);
249
+ if (known !== undefined)
250
+ return known ? yes(path) : no(path);
251
+ const a = linear(pair[0], path), b = linear(pair[1], path);
252
+ if (!a || !b)
253
+ return undefined;
254
+ const diff = sub(a, b), back = scale(diff, -1);
255
+ const branch = (lin, p, on, off) => {
256
+ const id = canon(lin), had = p.get(id)?.holds;
257
+ if (had !== undefined)
258
+ return had ? on(p) : off(p);
259
+ const y = on(new Map(p).set(id, { lin, holds: true }));
260
+ if (!y)
261
+ return undefined;
262
+ const n = off(new Map(p).set(id, { lin, holds: false }));
263
+ return n ? { split: lin, yes: y, no: n } : undefined;
264
+ };
265
+ return branch(diff, path, p => branch(back, p, yes, no), no);
266
+ };
267
+ const modelAt = options.model;
268
+ if (modelAt) {
269
+ const visit = (path, _key, remaining, depth) => {
270
+ const key = pairs.map(([a, b]) => { const t = truth({ op: '=', a, b }, path); return t === undefined ? 'any' : t ? 'equal' : 'different'; }).join('/');
271
+ const direct = leaf(path, key);
272
+ if (direct)
273
+ return direct;
274
+ if (clock() >= until || depth >= pairs.length)
275
+ return undefined;
276
+ const model = modelAt(), next = model && demandedRowPair(remaining, path, model, options.sources?.());
277
+ if (!next)
278
+ return undefined;
279
+ trace?.({ stage: 'row-demand', depth, pair: next, key });
280
+ const rest = remaining.filter(pair => pair !== next);
281
+ return split(next, path, p => visit(p, `${key}/equal`, rest, depth + 1), p => visit(p, `${key}/different`, rest, depth + 1));
282
+ };
283
+ const out = visit(root, 'root', pairs, 0);
284
+ return options.deferToCaller ? out : out && check(g, out, root) ? out : undefined;
285
+ }
286
+ // Try the primary-equal case without a secondary split. Its returned proof
287
+ // must cover every secondary key. The other two logical cases are shared
288
+ // between the less-than and greater-than representations of disequality.
289
+ const out = split(pairs[0], root, p => options.splitEqual && pairs[1] ? split(pairs[1], p, q => leaf(q, 'equal/equal'), q => leaf(q, 'equal/different')) : leaf(p, 'equal'), p => pairs.length < 2 ? leaf(p, 'different') : split(pairs[1], p, q => leaf(q, 'different/equal'), q => leaf(q, 'different/different')));
290
+ // A composing caller may check this entire proposal after adding its cuts.
291
+ return options.deferToCaller ? out : out && check(g, out, root) ? out : undefined;
292
+ }
@@ -0,0 +1,7 @@
1
+ import { type C, type Machine } from '../machine.js';
2
+ import { type CountCert, type CountDecl, type CountInst, type Goal, type Path } from '../../kernel/kernel.js';
3
+ export declare function bounded(value: unknown): boolean;
4
+ /** At most eight deterministic, witness-free scalar comparison conjunctions.
5
+ * Universal equalities only suggest substitutions; nothing here asserts them,
6
+ * adds a hypothesis, mutates the path, or establishes a proof. */
7
+ export declare function countScalarGuards(m: Machine, ds: CountDecl[], reads: CountCert['reads'], inst: CountInst, root: Path, goal?: Goal): C[][];