gdp-wired 0.48.0 → 0.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (361) hide show
  1. package/README.md +6 -2
  2. package/dist/core/bmc.js +10 -7
  3. package/dist/core/candidate-seeds.d.ts +25 -0
  4. package/dist/core/candidate-seeds.js +90 -0
  5. package/dist/core/check.js +7 -2
  6. package/dist/core/cli.js +3 -0
  7. package/dist/core/count-attempt-work.d.ts +29 -0
  8. package/dist/core/count-attempt-work.js +96 -0
  9. package/dist/core/count-boolean-partition.d.ts +5 -0
  10. package/dist/core/count-boolean-partition.js +47 -0
  11. package/dist/core/count-bounded-quotient.d.ts +2 -0
  12. package/dist/core/count-bounded-quotient.js +13 -0
  13. package/dist/core/count-case-compose.d.ts +20 -0
  14. package/dist/core/count-case-compose.js +289 -0
  15. package/dist/core/count-cases.js +3 -2
  16. package/dist/core/count-cert-rename.d.ts +10 -0
  17. package/dist/core/count-cert-rename.js +69 -0
  18. package/dist/core/count-cert-transport.d.ts +10 -2
  19. package/dist/core/count-cert-transport.js +60 -9
  20. package/dist/core/count-certificate-minimize.d.ts +57 -0
  21. package/dist/core/count-certificate-minimize.js +263 -0
  22. package/dist/core/count-closed-family.d.ts +32 -0
  23. package/dist/core/count-closed-family.js +143 -0
  24. package/dist/core/count-closing-budget.d.ts +10 -0
  25. package/dist/core/count-closing-budget.js +49 -0
  26. package/dist/core/count-closing-needs.d.ts +5 -0
  27. package/dist/core/count-closing-needs.js +9 -0
  28. package/dist/core/count-component-budget.d.ts +5 -0
  29. package/dist/core/count-component-budget.js +9 -0
  30. package/dist/core/count-copy-shape.d.ts +11 -0
  31. package/dist/core/count-copy-shape.js +40 -0
  32. package/dist/core/count-disjoint-funding.d.ts +75 -0
  33. package/dist/core/count-disjoint-funding.js +284 -0
  34. package/dist/core/count-emitter-frame-pool.d.ts +23 -0
  35. package/dist/core/count-emitter-frame-pool.js +87 -0
  36. package/dist/core/count-final-step.d.ts +5 -0
  37. package/dist/core/count-final-step.js +20 -0
  38. package/dist/core/count-fixed-frame.d.ts +4 -0
  39. package/dist/core/count-fixed-frame.js +30 -0
  40. package/dist/core/count-frames.d.ts +25 -0
  41. package/dist/core/count-frames.js +118 -0
  42. package/dist/core/count-frozen-guard.d.ts +2 -0
  43. package/dist/core/count-frozen-guard.js +31 -0
  44. package/dist/core/count-generation-phase.d.ts +7 -0
  45. package/dist/core/count-generation-phase.js +33 -0
  46. package/dist/core/count-guard-composition.d.ts +12 -0
  47. package/dist/core/count-guard-composition.js +48 -0
  48. package/dist/core/count-guard-context.d.ts +11 -0
  49. package/dist/core/count-guard-context.js +50 -0
  50. package/dist/core/count-guard-facts.d.ts +50 -0
  51. package/dist/core/count-guard-facts.js +97 -0
  52. package/dist/core/count-guard-proposals.d.ts +7 -0
  53. package/dist/core/count-guard-proposals.js +106 -0
  54. package/dist/core/count-guard-shape.d.ts +18 -0
  55. package/dist/core/count-guard-shape.js +100 -0
  56. package/dist/core/count-guard-tree.d.ts +17 -0
  57. package/dist/core/count-guard-tree.js +125 -0
  58. package/dist/core/count-leader-facts.d.ts +10 -0
  59. package/dist/core/count-leader-facts.js +52 -0
  60. package/dist/core/count-leader.d.ts +10 -0
  61. package/dist/core/count-leader.js +331 -0
  62. package/dist/core/count-lemma-transport.d.ts +8 -0
  63. package/dist/core/count-lemma-transport.js +47 -0
  64. package/dist/core/count-lifted-budget.d.ts +54 -0
  65. package/dist/core/count-lifted-budget.js +97 -0
  66. package/dist/core/count-lifted-copy.d.ts +3 -0
  67. package/dist/core/count-lifted-copy.js +166 -0
  68. package/dist/core/count-lifted-increment.d.ts +3 -0
  69. package/dist/core/count-lifted-increment.js +146 -0
  70. package/dist/core/count-lifted-load.d.ts +5 -0
  71. package/dist/core/count-lifted-load.js +179 -0
  72. package/dist/core/count-lifted-prerequisite.d.ts +14 -0
  73. package/dist/core/count-lifted-prerequisite.js +53 -0
  74. package/dist/core/count-lifted-replacement.d.ts +3 -0
  75. package/dist/core/count-lifted-replacement.js +540 -0
  76. package/dist/core/count-lifted-shape.d.ts +63 -0
  77. package/dist/core/count-lifted-shape.js +115 -0
  78. package/dist/core/count-lifted-strategy.d.ts +7 -0
  79. package/dist/core/count-lifted-strategy.js +226 -0
  80. package/dist/core/count-lifted-transports.d.ts +32 -0
  81. package/dist/core/count-lifted-transports.js +293 -0
  82. package/dist/core/count-load-shape.d.ts +17 -0
  83. package/dist/core/count-load-shape.js +67 -0
  84. package/dist/core/count-minimal-view.d.ts +26 -0
  85. package/dist/core/count-minimal-view.js +46 -0
  86. package/dist/core/count-operation-observation.d.ts +9 -0
  87. package/dist/core/count-operation-observation.js +22 -0
  88. package/dist/core/count-operation-order.d.ts +5 -0
  89. package/dist/core/count-operation-order.js +4 -0
  90. package/dist/core/count-phase.d.ts +9 -0
  91. package/dist/core/count-phase.js +127 -0
  92. package/dist/core/count-premise-search.d.ts +9 -0
  93. package/dist/core/count-premise-search.js +41 -0
  94. package/dist/core/count-premise-view.d.ts +19 -0
  95. package/dist/core/count-premise-view.js +220 -0
  96. package/dist/core/count-prerequisite-components.d.ts +67 -0
  97. package/dist/core/count-prerequisite-components.js +239 -0
  98. package/dist/core/count-prerequisite-memory.d.ts +24 -0
  99. package/dist/core/count-prerequisite-memory.js +37 -0
  100. package/dist/core/count-prerequisite-plan.d.ts +12 -0
  101. package/dist/core/count-prerequisite-plan.js +88 -0
  102. package/dist/core/count-primitive-budget.d.ts +1 -0
  103. package/dist/core/count-primitive-budget.js +8 -0
  104. package/dist/core/count-project-free.d.ts +3 -0
  105. package/dist/core/count-project-free.js +24 -0
  106. package/dist/core/count-project-witness.d.ts +4 -0
  107. package/dist/core/count-project-witness.js +48 -0
  108. package/dist/core/count-proof-rescope.d.ts +14 -0
  109. package/dist/core/count-proof-rescope.js +71 -0
  110. package/dist/core/count-proof-scope.d.ts +68 -0
  111. package/dist/core/count-proof-scope.js +333 -0
  112. package/dist/core/count-prune-owned-root.d.ts +5 -0
  113. package/dist/core/count-prune-owned-root.js +27 -0
  114. package/dist/core/count-query-context.d.ts +3 -0
  115. package/dist/core/count-query-context.js +7 -0
  116. package/dist/core/count-query.d.ts +15 -0
  117. package/dist/core/count-query.js +59 -0
  118. package/dist/core/count-quorum-leaf.d.ts +9 -0
  119. package/dist/core/count-quorum-leaf.js +38 -0
  120. package/dist/core/count-reachability-budget.d.ts +1 -0
  121. package/dist/core/count-reachability-budget.js +7 -0
  122. package/dist/core/count-reachability-reconcile.d.ts +11 -0
  123. package/dist/core/count-reachability-reconcile.js +19 -0
  124. package/dist/core/count-reachability.d.ts +50 -0
  125. package/dist/core/count-reachability.js +351 -0
  126. package/dist/core/count-rebase-path.d.ts +9 -0
  127. package/dist/core/count-rebase-path.js +68 -0
  128. package/dist/core/count-recipe-context.d.ts +45 -0
  129. package/dist/core/count-recipe-context.js +71 -0
  130. package/dist/core/count-recipe-controller.d.ts +115 -0
  131. package/dist/core/count-recipe-controller.js +417 -0
  132. package/dist/core/count-recipe-graph.d.ts +36 -0
  133. package/dist/core/count-recipe-graph.js +211 -0
  134. package/dist/core/count-recovery/conditional-check-cache.js +3 -2
  135. package/dist/core/count-recovery/conditional-cuts.js +5 -4
  136. package/dist/core/count-recovery/conditional-proof.d.ts +37 -3
  137. package/dist/core/count-recovery/conditional-proof.js +72 -30
  138. package/dist/core/count-recovery/derivability-closure.js +2 -1
  139. package/dist/core/count-recovery/guard-cases.js +2 -1
  140. package/dist/core/count-recovery/reframe-tree.d.ts +2 -0
  141. package/dist/core/count-recovery/reframe-tree.js +24 -0
  142. package/dist/core/count-recovery/replay-linear-skeleton.d.ts +2 -0
  143. package/dist/core/count-recovery/replay-linear-skeleton.js +28 -0
  144. package/dist/core/count-recovery/row-cases.js +2 -1
  145. package/dist/core/count-rejection-budget.d.ts +8 -0
  146. package/dist/core/count-rejection-budget.js +15 -0
  147. package/dist/core/count-replacement.d.ts +5 -0
  148. package/dist/core/count-replacement.js +129 -0
  149. package/dist/core/count-replay-diagnostic.d.ts +21 -0
  150. package/dist/core/count-replay-diagnostic.js +49 -0
  151. package/dist/core/count-replay-skeleton.d.ts +4 -0
  152. package/dist/core/count-replay-skeleton.js +28 -0
  153. package/dist/core/count-rescope-funding.d.ts +3 -0
  154. package/dist/core/count-rescope-funding.js +17 -0
  155. package/dist/core/count-restrictions.d.ts +11 -0
  156. package/dist/core/count-restrictions.js +31 -0
  157. package/dist/core/count-retry-budget.d.ts +67 -0
  158. package/dist/core/count-retry-budget.js +114 -0
  159. package/dist/core/count-retry-round.d.ts +24 -0
  160. package/dist/core/count-retry-round.js +44 -0
  161. package/dist/core/count-row-agreement.d.ts +35 -0
  162. package/dist/core/count-row-agreement.js +270 -0
  163. package/dist/core/count-row-aliases.d.ts +3 -0
  164. package/dist/core/count-row-aliases.js +59 -0
  165. package/dist/core/count-row-composition.d.ts +6 -0
  166. package/dist/core/count-row-composition.js +55 -0
  167. package/dist/core/count-row-copy-linear.d.ts +4 -0
  168. package/dist/core/count-row-copy-linear.js +83 -0
  169. package/dist/core/count-row-copy.d.ts +4 -0
  170. package/dist/core/count-row-copy.js +94 -0
  171. package/dist/core/count-row-policy.d.ts +3 -0
  172. package/dist/core/count-row-policy.js +56 -0
  173. package/dist/core/count-row-reindex.d.ts +11 -0
  174. package/dist/core/count-row-reindex.js +126 -0
  175. package/dist/core/count-row-support.d.ts +9 -0
  176. package/dist/core/count-row-support.js +42 -0
  177. package/dist/core/count-row-symmetry.d.ts +7 -0
  178. package/dist/core/count-row-symmetry.js +100 -0
  179. package/dist/core/count-scope-hyps.d.ts +2 -0
  180. package/dist/core/count-scope-hyps.js +163 -0
  181. package/dist/core/count-scope-row-reuse.d.ts +3 -0
  182. package/dist/core/count-scope-row-reuse.js +92 -0
  183. package/dist/core/count-search-allowance.d.ts +1 -0
  184. package/dist/core/count-search-allowance.js +17 -0
  185. package/dist/core/count-stabilize-tree.d.ts +9 -0
  186. package/dist/core/count-stabilize-tree.js +35 -0
  187. package/dist/core/count-stage-trace.d.ts +8 -0
  188. package/dist/core/count-stage-trace.js +45 -0
  189. package/dist/core/count-strategies.d.ts +16 -0
  190. package/dist/core/count-strategies.js +155 -0
  191. package/dist/core/count-strategy-premises.d.ts +5 -0
  192. package/dist/core/count-strategy-premises.js +14 -0
  193. package/dist/core/count-strategy.d.ts +41 -0
  194. package/dist/core/count-strategy.js +76 -0
  195. package/dist/core/count-support.d.ts +1 -0
  196. package/dist/core/count-support.js +26 -4
  197. package/dist/core/count-tier-budget.d.ts +14 -0
  198. package/dist/core/count-tier-budget.js +64 -0
  199. package/dist/core/count-unwritten-prefix.d.ts +24 -0
  200. package/dist/core/count-unwritten-prefix.js +97 -0
  201. package/dist/core/count-write-shape.d.ts +15 -0
  202. package/dist/core/count-write-shape.js +73 -0
  203. package/dist/core/counted-candidate-seeds.d.ts +12 -0
  204. package/dist/core/counted-candidate-seeds.js +31 -0
  205. package/dist/core/counts.d.ts +37 -13
  206. package/dist/core/counts.js +999 -129
  207. package/dist/core/cycles.js +5 -4
  208. package/dist/core/cyclic.js +11 -10
  209. package/dist/core/data.js +16 -15
  210. package/dist/core/dsl-deadline.d.ts +3 -0
  211. package/dist/core/dsl-deadline.js +27 -0
  212. package/dist/core/dsl.d.ts +32 -2
  213. package/dist/core/dsl.js +202 -64
  214. package/dist/core/evaluation-admission.d.ts +1 -0
  215. package/dist/core/evaluation-admission.js +3 -0
  216. package/dist/core/exists.d.ts +6 -1
  217. package/dist/core/exists.js +53 -10
  218. package/dist/core/field-laws.d.ts +3 -1
  219. package/dist/core/field-laws.js +159 -3
  220. package/dist/core/finite-houdini.d.ts +6 -0
  221. package/dist/core/finite-houdini.js +63 -21
  222. package/dist/core/finite-tiny.js +95 -67
  223. package/dist/core/fixtures/count-completion/paxos-decision.json +1 -0
  224. package/dist/core/fresh.js +5 -1
  225. package/dist/core/infer.js +49 -33
  226. package/dist/core/kind.js +2 -1
  227. package/dist/core/lemma-cuts.js +11 -10
  228. package/dist/core/lift-cli.d.ts +11 -0
  229. package/dist/core/lift-cli.js +113 -0
  230. package/dist/core/linear-admission.d.ts +14 -0
  231. package/dist/core/linear-admission.js +151 -0
  232. package/dist/core/machine.d.ts +5 -2
  233. package/dist/core/machine.js +105 -31
  234. package/dist/core/meter.d.ts +22 -0
  235. package/dist/core/meter.js +34 -0
  236. package/dist/core/nonterm.js +4 -3
  237. package/dist/core/proof-output.d.ts +53 -0
  238. package/dist/core/proof-output.js +38 -0
  239. package/dist/core/prover-row-budget.d.ts +3 -0
  240. package/dist/core/prover-row-budget.js +106 -0
  241. package/dist/core/quorum-laws.d.ts +21 -1
  242. package/dist/core/quorum-laws.js +80 -17
  243. package/dist/core/rationals.js +3 -2
  244. package/dist/core/rejection-discovery.d.ts +34 -0
  245. package/dist/core/rejection-discovery.js +36 -0
  246. package/dist/core/rejection-stage.d.ts +39 -0
  247. package/dist/core/rejection-stage.js +205 -0
  248. package/dist/core/request-quotient.d.ts +8 -0
  249. package/dist/core/request-quotient.js +299 -0
  250. package/dist/core/row-agreement-shape.d.ts +15 -0
  251. package/dist/core/row-agreement-shape.js +68 -0
  252. package/dist/core/runtime-wall.d.ts +2 -0
  253. package/dist/core/search-policy.d.ts +15 -0
  254. package/dist/core/search-policy.js +68 -0
  255. package/dist/core/solver.d.ts +1 -1
  256. package/dist/core/solver.js +40 -6
  257. package/dist/core/step-work.d.ts +12 -0
  258. package/dist/core/step-work.js +14 -0
  259. package/dist/core/strategy-premises.d.ts +8 -0
  260. package/dist/core/strategy-premises.js +64 -0
  261. package/dist/core/system.js +4 -3
  262. package/dist/core/table-admission.d.ts +1 -0
  263. package/dist/core/table-admission.js +3 -0
  264. package/dist/core/trace-clock.d.ts +3 -0
  265. package/dist/core/trace-clock.js +16 -0
  266. package/dist/core/transfer.js +3 -2
  267. package/dist/core/translate.js +16 -3
  268. package/dist/core/wall.d.ts +6 -1
  269. package/dist/core/wall.js +23 -9
  270. package/dist/core/watch.d.ts +1 -1
  271. package/dist/core/watch.js +13 -4
  272. package/dist/core/work-admission.d.ts +164 -0
  273. package/dist/core/work-admission.js +418 -0
  274. package/dist/core/work-amount.d.ts +21 -0
  275. package/dist/core/work-amount.js +80 -0
  276. package/dist/core/work-collections.d.ts +11 -0
  277. package/dist/core/work-collections.js +198 -0
  278. package/dist/core/work-kinds.d.ts +11 -0
  279. package/dist/core/work-kinds.js +9 -0
  280. package/dist/core/work-meter.d.ts +8 -0
  281. package/dist/core/work-meter.js +83 -0
  282. package/dist/core/work-observe.d.ts +12 -0
  283. package/dist/core/work-observe.js +39 -0
  284. package/dist/core/work-profile.d.ts +10 -0
  285. package/dist/core/work-profile.js +21 -0
  286. package/dist/core/work-refusal.d.ts +1 -0
  287. package/dist/core/work-refusal.js +6 -0
  288. package/dist/interchange/format.js +2 -0
  289. package/dist/kernel/cdcl.js +93 -40
  290. package/dist/kernel/epr.js +23 -8
  291. package/dist/kernel/function-instances.d.ts +45 -0
  292. package/dist/kernel/function-instances.js +460 -0
  293. package/dist/kernel/kernel.d.ts +47 -1
  294. package/dist/kernel/kernel.js +417 -68
  295. package/dist/kernel/prove.d.ts +61 -6
  296. package/dist/kernel/prove.js +625 -205
  297. package/dist/kernel/prover-rows.d.ts +1 -0
  298. package/dist/kernel/prover-rows.js +12 -1
  299. package/dist/kernel/reader.d.ts +1 -1
  300. package/dist/kernel/reader.js +57 -12
  301. package/dist/kernel/simplex.js +9 -2
  302. package/dist/lean-kernel/axiom-audit.d.ts +11 -0
  303. package/dist/lean-kernel/axiom-audit.js +50 -0
  304. package/dist/lean-kernel/emit.d.ts +34 -3
  305. package/dist/lean-kernel/emit.js +215 -28
  306. package/dist/lean-kernel/legacy-family-library.d.ts +1 -0
  307. package/dist/lean-kernel/legacy-family-library.js +5 -0
  308. package/dist/lean-kernel/legacy-family-order.d.ts +1 -0
  309. package/dist/lean-kernel/legacy-family-order.js +26 -0
  310. package/dist/lean-kernel/library.js +25 -3
  311. package/dist/lean-kernel/lift/counted-source-data.d.ts +7 -0
  312. package/dist/lean-kernel/lift/counted-source-data.js +78 -0
  313. package/dist/lean-kernel/lift/index.d.ts +82 -0
  314. package/dist/lean-kernel/lift/index.js +116 -0
  315. package/dist/lean-kernel/lift/project.d.ts +4 -0
  316. package/dist/lean-kernel/lift/project.js +15 -0
  317. package/dist/lean-kernel/lift/proof-capture.d.ts +104 -0
  318. package/dist/lean-kernel/lift/proof-capture.js +216 -0
  319. package/dist/lean-kernel/lift/proof-codec.d.ts +28 -0
  320. package/dist/lean-kernel/lift/proof-codec.js +299 -0
  321. package/dist/lean-kernel/lift/proof-counted-source.d.ts +16 -0
  322. package/dist/lean-kernel/lift/proof-counted-source.js +68 -0
  323. package/dist/lean-kernel/lift/proof-frontier.d.ts +19 -0
  324. package/dist/lean-kernel/lift/proof-frontier.js +153 -0
  325. package/dist/lean-kernel/lift/proof-graph.d.ts +17 -0
  326. package/dist/lean-kernel/lift/proof-graph.js +130 -0
  327. package/dist/lean-kernel/lift/proof-parts.d.ts +29 -0
  328. package/dist/lean-kernel/lift/proof-parts.js +131 -0
  329. package/dist/lean-kernel/lift/proof-prelude.d.ts +2 -0
  330. package/dist/lean-kernel/lift/proof-prelude.js +38 -0
  331. package/dist/lean-kernel/lift/proof-witness.d.ts +30 -0
  332. package/dist/lean-kernel/lift/proof-witness.js +283 -0
  333. package/dist/lean-kernel/lift/shape.d.ts +5 -0
  334. package/dist/lean-kernel/lift/shape.js +57 -0
  335. package/dist/lean-kernel/lift/source-projection.d.ts +16 -0
  336. package/dist/lean-kernel/lift/source-projection.js +81 -0
  337. package/dist/lean-kernel/lift/source.d.ts +23 -0
  338. package/dist/lean-kernel/lift/source.js +111 -0
  339. package/dist/lean-kernel/lift/witness-alpha.d.ts +9 -0
  340. package/dist/lean-kernel/lift/witness-alpha.js +31 -0
  341. package/dist/lean-kernel/lift-legacy.d.ts +58 -0
  342. package/dist/lean-kernel/lift-legacy.js +84 -0
  343. package/dist/lean-kernel/lift-names.d.ts +22 -0
  344. package/dist/lean-kernel/lift-names.js +36 -0
  345. package/dist/lean-kernel/lift-simulation/index.d.ts +29 -0
  346. package/dist/lean-kernel/lift-simulation/index.js +352 -0
  347. package/dist/lean-kernel/lift-simulation/shape.d.ts +41 -0
  348. package/dist/lean-kernel/lift-simulation/shape.js +173 -0
  349. package/dist/lean-kernel/lift-special/index.d.ts +36 -0
  350. package/dist/lean-kernel/lift-special/index.js +241 -0
  351. package/dist/lean-kernel/lift-special/structural.d.ts +25 -0
  352. package/dist/lean-kernel/lift-special/structural.js +126 -0
  353. package/dist/lean-kernel/lift-typed/index.d.ts +35 -0
  354. package/dist/lean-kernel/lift-typed/index.js +256 -0
  355. package/dist/lean-kernel/lift-typed/roles.d.ts +17 -0
  356. package/dist/lean-kernel/lift-typed/roles.js +170 -0
  357. package/dist/lean-kernel/lift-typed/shape.d.ts +1 -0
  358. package/dist/lean-kernel/lift-typed/shape.js +12 -0
  359. package/dist/lean-kernel/lift.d.ts +30 -0
  360. package/dist/lean-kernel/lift.js +97 -0
  361. package/package.json +5 -1
@@ -0,0 +1,33 @@
1
+ // Optional generation phase. Legacy callers run exactly the original body.
2
+ import { BudgetExpired, budgetEnd, checkBudget, clock, fullRate, withBudget, withDeadline, withinDeadline } from "../kernel/prove.js";
3
+ import { inProxySearch } from "./search-policy.js";
4
+ import { withSearchAllowance } from "./count-search-allowance.js";
5
+ export function countGenerationPhase(until, run) {
6
+ checkBudget('generation parent entry');
7
+ const remaining = until - clock();
8
+ if (remaining <= 0)
9
+ return { complete: false };
10
+ // A proxy allowance has no owned ledger endpoint: never catch a hard refusal.
11
+ if (inProxySearch())
12
+ return withSearchAllowance(until, () => ({ complete: true, value: run() }));
13
+ // Capture the inherited endpoint while a nonrestricting budget exposes bare
14
+ // withWork caps too. Equality is parent expiry, never a local partial result.
15
+ const parentEnd = withBudget(Number.MAX_VALUE, () => withinDeadline(budgetEnd()));
16
+ let installedEnd;
17
+ try {
18
+ return withBudget(remaining * fullRate, () => {
19
+ installedEnd = withinDeadline(budgetEnd());
20
+ return withDeadline(until, () => ({ complete: true, value: run() }));
21
+ });
22
+ }
23
+ catch (error) {
24
+ if (!(error instanceof BudgetExpired))
25
+ throw error;
26
+ // A bare withWork cap has no sticky parent budget after child unwind.
27
+ // Only an endpoint strictly inside the captured parent can expire locally.
28
+ checkBudget('generation parent completion');
29
+ if (installedEnd === undefined || installedEnd >= parentEnd)
30
+ throw error;
31
+ return { complete: false };
32
+ }
33
+ }
@@ -0,0 +1,12 @@
1
+ import { type Law } from './machine.js';
2
+ import { type GuardCountContext } from './count-guard-context.js';
3
+ import { type CountRequestBuilder, type CountStrategyProof, type CountStrategyOptions } from './count-strategy.js';
4
+ import { type FixedOperationProof } from './count-case-compose.js';
5
+ export declare function proveFixedCountOperations(context: GuardCountContext, family: Law[], law: Law, until: number, requestFor: CountRequestBuilder, observe?: (event: Record<string, unknown>) => void, options?: CountStrategyOptions & {
6
+ caseOrder?: 'original' | 'cost';
7
+ }): FixedOperationProof[] | undefined;
8
+ export declare function proveCountGuardComposition(context: GuardCountContext, family: Law[], law: Law, until: number, requestFor: CountRequestBuilder, observe?: (event: Record<string, unknown>) => void, options?: CountStrategyOptions & {
9
+ checkEachCase?: boolean;
10
+ caseOrder?: 'original' | 'cost';
11
+ reindexMode?: 'offset' | 'exact';
12
+ }): CountStrategyProof | undefined;
@@ -0,0 +1,48 @@
1
+ // Optional whole-operation strategy. The caller owns one shared allowance;
2
+ // discovery selects a proposer, never a trusted fact or a protocol name.
3
+ import { all, n, same, x } from "./machine.js";
4
+ import { finiteCountChoice } from "./count-cases.js";
5
+ import { countPrimitiveUnits } from "./count-primitive-budget.js";
6
+ import { traceNow } from "./trace-clock.js";
7
+ import { orderCountOperations } from "./count-operation-order.js";
8
+ import { discoverCountRowCopy } from "./count-copy-shape.js";
9
+ import { discoverCountThresholdWrite } from "./count-write-shape.js";
10
+ import { proveFixedCountPhase } from "./count-phase.js";
11
+ import { proveFixedCountFrame } from "./count-fixed-frame.js";
12
+ import { proveCountRowCopy } from "./count-row-copy.js";
13
+ import { proveCountRowCopyLinear } from "./count-row-copy-linear.js";
14
+ import { proveCountReplacement } from "./count-replacement.js";
15
+ import { proveCountLeader } from "./count-leader.js";
16
+ import { composeCountOperationProofs } from "./count-case-compose.js";
17
+ import { clock, fullRate, fullWork, late, withDeadline } from "../kernel/prove.js";
18
+ export function proveFixedCountOperations(context, family, law, until, requestFor, observe, options = {}) {
19
+ return withDeadline(until, () => {
20
+ const choice = finiteCountChoice(context.machine);
21
+ if (!choice || late(until))
22
+ return;
23
+ const [name, values] = choice, cases = [];
24
+ const planned = [...values].map(value => {
25
+ const branch = { name, value }, write = discoverCountThresholdWrite(context.original, context.shape, branch), copy = discoverCountRowCopy(context.original, context.shape, branch);
26
+ const kind = copy ? 'copy' : write?.increment === 1 ? 'leader' : write?.increment === 0 ? 'replacement' : 'phase';
27
+ return { value, kind };
28
+ });
29
+ for (const { value, kind } of orderCountOperations(planned, options.caseOrder)) {
30
+ if (late(until))
31
+ return;
32
+ const machine = { ...context.machine, assume: all(...(context.machine.assume ? [context.machine.assume] : []), same(x(name), n(value))) }, selected = { ...context, machine }, wallStart = traceNow();
33
+ const start = fullWork(), caseOptions = { ...options, trace: (event) => observe?.({ stage: 'query', value, kind, ...event }) };
34
+ const proof = kind === 'copy' ? proveCountRowCopyLinear(machine, family, law, {}, Math.min(until, clock() + countPrimitiveUnits(1000, Infinity)), requestFor, undefined, caseOptions) ?? proveCountRowCopy(machine, family, law, {}, until, requestFor, caseOptions) : kind === 'leader' ? proveCountLeader(selected, family, law, {}, until, requestFor, undefined, caseOptions) : kind === 'replacement' ? proveCountReplacement(selected, family, law, {}, until, requestFor, undefined, caseOptions) : proveFixedCountFrame(machine, family, law, {}, until, requestFor, caseOptions) ?? proveFixedCountPhase(machine, family, law, {}, until, requestFor, undefined, caseOptions);
35
+ observe?.({ stage: 'operation', value, kind, proposed: !!proof, checked: !!proof && !options.deferToComposition, units: (fullWork() - start) / fullRate, wallMs: traceNow() - wallStart, remaining: until - clock(), ...(proof ? { premises: Object.keys(proof.instances).filter(name => family.some(law => law.name === name)) } : {}) });
36
+ if (!proof)
37
+ return;
38
+ cases.push({ value, proof });
39
+ }
40
+ return cases;
41
+ });
42
+ }
43
+ export function proveCountGuardComposition(context, family, law, until, requestFor, observe, options = {}) {
44
+ return withDeadline(until, () => {
45
+ const cases = proveFixedCountOperations(context, family, law, until, requestFor, observe, { ...options, deferToComposition: !options.checkEachCase });
46
+ return cases && composeCountOperationProofs(context, family, law, cases, until, requestFor, (stage, value) => observe?.({ stage, value }), { reindexMode: options.reindexMode, trace: observe, minimize: options.minimize, reindexFactsOnly: options.reindexFactsOnly, familyProposal: options.familyProposal });
47
+ });
48
+ }
@@ -0,0 +1,11 @@
1
+ import { type Law, type Machine } from './machine.js';
2
+ import { type CountGuardShape } from './count-guard-shape.js';
3
+ import { type Restriction } from './count-restrictions.js';
4
+ export type GuardCountContext = {
5
+ original: Machine;
6
+ machine: Machine;
7
+ shape: CountGuardShape;
8
+ restrictions: Restriction[];
9
+ inputCounts: Record<string, string>;
10
+ };
11
+ export declare function prepareGuardCountContext(original: Machine, law: Law, family: readonly Law[]): GuardCountContext | undefined;
@@ -0,0 +1,50 @@
1
+ // One conservative definition extension, shared by every operation case.
2
+ // This prepares syntax only; no discovered relationship becomes an assumption.
3
+ import { walkOnce } from "./machine.js";
4
+ import { discoverCountGuardShape } from "./count-guard-shape.js";
5
+ import { restrictedCounts } from "./count-restrictions.js";
6
+ export function prepareGuardCountContext(original, law, family) {
7
+ const shape = discoverCountGuardShape(original, law, family);
8
+ if (!shape)
9
+ return;
10
+ const inputCounts = {}, selected = [shape.voteMap, shape.rowMap];
11
+ for (const input of original.inputMaps ?? []) {
12
+ const found = Object.entries(original.counts ?? {}).filter(([, d]) => {
13
+ if (d.base || d.body.op !== 'if' || d.body.then.op !== 'const' || d.body.then.value !== 1 || d.body.else.op !== 'const' || d.body.else.value !== 0)
14
+ return false;
15
+ const fields = new Set();
16
+ walkOnce(d.body, (node) => { if (node.op === 'get')
17
+ fields.add(node.map); });
18
+ return fields.size === 1 && fields.has(input);
19
+ });
20
+ if (found.length !== 1)
21
+ return;
22
+ inputCounts[input] = found[0][0];
23
+ selected.push(found[0][0]);
24
+ }
25
+ if (selected.length * (original.inputMaps?.length ?? 0) > 128)
26
+ return;
27
+ const reserved = new Set([...original.params, ...original.inputs, ...Object.keys(original.fns ?? {}), ...Object.keys(original.step.flags ?? {})]);
28
+ for (const base of selected)
29
+ for (const input of original.inputMaps ?? []) {
30
+ const name = `${base}$restricted$${input}`;
31
+ if (reserved.has(name) || reserved.has(name + '$not'))
32
+ return;
33
+ }
34
+ try {
35
+ // Reuse only exact definitions installed at the admission boundary. A name
36
+ // collision is never permission to replace a user count or add a premise.
37
+ const planned = new Set(selected.flatMap(base => (original.inputMaps ?? []).flatMap(input => [`${base}$restricted$${input}`, `${base}$restricted$${input}$not`])));
38
+ const source = { ...original, counts: Object.fromEntries(Object.entries(original.counts ?? {}).filter(([name]) => !planned.has(name))) };
39
+ const extended = restrictedCounts(source, selected, 128, shape.memberKey);
40
+ for (const name of planned)
41
+ if (original.counts?.[name] && JSON.stringify(original.counts[name]) !== JSON.stringify(extended.machine.counts?.[name]))
42
+ return;
43
+ const added = Object.keys(extended.machine.counts ?? {}).some(name => !original.counts?.[name]);
44
+ const machine = added ? { ...original, counts: { ...original.counts, ...extended.machine.counts } } : original;
45
+ return { original, machine, shape, restrictions: extended.entries, inputCounts };
46
+ }
47
+ catch {
48
+ return;
49
+ }
50
+ }
@@ -0,0 +1,50 @@
1
+ import { type C, type E } from './machine.js';
2
+ import { type CountCert, type CountDecl, type Goal, type LinCut, type MapRead, type Tree } from '../kernel/kernel.js';
3
+ export type GuardCountProposal = {
4
+ name: string;
5
+ kind: string;
6
+ when: C[];
7
+ terms: [number, string][];
8
+ };
9
+ export type CheckedGuardCountFact = {
10
+ proposal: GuardCountProposal;
11
+ claim: C;
12
+ goal: Goal;
13
+ cert: CountCert;
14
+ };
15
+ export type CheckedGuardLinearFact = {
16
+ proposal: GuardCountProposal;
17
+ goal: Goal;
18
+ cut: LinCut;
19
+ status?: 'unchecked';
20
+ };
21
+ export type GuardCountTrace = {
22
+ outcome: string;
23
+ encoded?: Goal;
24
+ witness?: Record<string, number>;
25
+ broken?: unknown;
26
+ searchEnd?: number;
27
+ minimal?: {
28
+ kind: string;
29
+ fallback: boolean;
30
+ units: number;
31
+ fallbackUnits: number;
32
+ };
33
+ };
34
+ export type GuardBodyProposal = {
35
+ name: string;
36
+ kind: 'excluded-body-frame';
37
+ when: C[];
38
+ pre: E;
39
+ post: E;
40
+ };
41
+ export type CheckedGuardBodyFact = {
42
+ proposal: GuardBodyProposal;
43
+ goal: Goal;
44
+ tree: Tree;
45
+ };
46
+ export declare function guardCountFact(premises: C[], decls: CountDecl[], reads: MapRead[], proposal: GuardCountProposal, wit: string, until: number, observe?: (trace: GuardCountTrace) => void): CheckedGuardCountFact | undefined;
47
+ export declare function guardLinearFact(decls: CountDecl[], reads: MapRead[], proposal: GuardCountProposal, until: number, observe?: (trace: GuardCountTrace) => void, search?: 'grow' | 'cdcl', options?: {
48
+ deferCheck?: boolean;
49
+ }): CheckedGuardLinearFact | undefined;
50
+ export declare function guardBodyFact(proposal: GuardBodyProposal, until: number): CheckedGuardBodyFact | undefined;
@@ -0,0 +1,97 @@
1
+ // Generic ordinary guard-restricted count facts for optional proof strategies.
2
+ // Every result is an ordinary checkMC/check proof under its explicitly recorded
3
+ // conditions; a proposal is never added to the original goal as an axiom.
4
+ import { atMost, get, n, not, same, walkOnce } from "./machine.js";
5
+ import { countsForReads } from "./count-facts.js";
6
+ import { check, checkMC, linOk, mcGoal } from "../kernel/kernel.js";
7
+ import { brokenOf, clock, grow, pastWall } from "../kernel/prove.js";
8
+ import { growCdcl } from "../kernel/cdcl.js";
9
+ import { minimalViewFirst } from "./count-minimal-view.js";
10
+ import { projectCountFree } from "./count-project-free.js";
11
+ const mentions = (t, key) => { let found = false; walkOnce(t, (v) => { if (v.op === 'var' && v.name === key)
12
+ found = true; }); return found; };
13
+ export function guardCountFact(premises, decls, reads, proposal, wit, until, observe) {
14
+ if (pastWall() || clock() >= until || !proposal.terms.length || proposal.when.some(c => mentions(c, wit)))
15
+ return;
16
+ const counts = countsForReads(decls, reads), terms = proposal.terms;
17
+ if (!counts || new Set(terms.map(t => t[1])).size !== terms.length)
18
+ return;
19
+ const first = counts.find(c => c.v === terms[0][1]);
20
+ if (!first)
21
+ return;
22
+ let positive = n(0), negative = n(0);
23
+ for (const [coefficient, name] of terms) {
24
+ if (!Number.isSafeInteger(coefficient) || !coefficient)
25
+ return;
26
+ const read = reads.find(r => r[0] === name), count = counts.find(c => c.v === name);
27
+ if (!read || !count || JSON.stringify(count.below) !== JSON.stringify(first.below))
28
+ return;
29
+ const value = { op: 'mul', k: Math.abs(coefficient), a: get(read[1], read[2]) };
30
+ if (coefficient > 0)
31
+ positive = { op: 'add', a: positive, b: value };
32
+ else
33
+ negative = { op: 'add', a: negative, b: value };
34
+ }
35
+ const claim = atMost(positive, negative), goal = { name: proposal.name, hyps: [...premises, ...proposal.when, not(claim)] };
36
+ const request = { reads, insts: [{ wit, below: first.below, terms, unit: 0 }], picks: [] }, encoded = mcGoal(goal.hyps, decls, request);
37
+ if (!encoded) {
38
+ observe?.({ outcome: 'invalid-encoding' });
39
+ return;
40
+ }
41
+ const result = grow(encoded, new Map(), { nodes: 0, until });
42
+ if (!('tree' in result)) {
43
+ const witness = 'witness' in result ? result.witness : undefined, broken = witness ? brokenOf(encoded)(witness) : undefined;
44
+ if (witness && broken?.length)
45
+ throw Error('invalid auxiliary witness');
46
+ observe?.({ outcome: result.stuck, encoded, witness, broken });
47
+ return;
48
+ }
49
+ const cert = { ...request, tree: result.tree }, checked = checkMC(goal.hyps, decls, cert);
50
+ observe?.({ outcome: checked ? 'proof' : 'rejected-proof', encoded });
51
+ return checked ? { proposal, claim, goal, cert } : undefined;
52
+ }
53
+ export function guardLinearFact(decls, reads, proposal, until, observe, search = 'grow', options = {}) {
54
+ if (pastWall() || clock() >= until || !proposal.terms.length)
55
+ return;
56
+ const counts = countsForReads(decls, reads);
57
+ if (!counts)
58
+ return;
59
+ const pos = [], neg = [];
60
+ for (const [coefficient, name] of proposal.terms) {
61
+ if (!Number.isSafeInteger(coefficient) || !coefficient || !counts.some(c => c.v === name))
62
+ return;
63
+ if (coefficient > 0)
64
+ pos.push([coefficient, name]);
65
+ else
66
+ neg.push([-coefficient, name]);
67
+ }
68
+ const first = counts.find(c => c.v === proposal.terms[0][1]);
69
+ if (counts.filter(c => proposal.terms.some(t => t[1] === c.v)).some(c => c.key !== first.key || JSON.stringify(c.below) !== JSON.stringify(first.below)))
70
+ return;
71
+ const term = (side) => side.reduceRight((rest, [k, name]) => ({ op: 'add', a: { op: 'mul', k, a: counts.find(c => c.v === name).body }, b: rest }), n(0));
72
+ const goal = { name: proposal.name, hyps: [...proposal.when, { op: '<', a: { op: 'var', name: first.key }, b: first.below }, { op: '<', a: term(neg), b: term(pos) }] };
73
+ const policy = minimalViewFirst(goal, { ...goal, hyps: projectCountFree(goal.hyps, new Map(), new Set()) }, new Map(), until, search === 'cdcl' ? growCdcl : grow, new Map(), options);
74
+ const result = policy ? (policy.tree ? { tree: policy.tree, nodes: 0 } : { stuck: policy.kind === 'sat' ? 'sat' : 'unknown', path: new Map(), witness: policy.witness, why: policy.kind }) : search === 'cdcl' ? growCdcl(goal, new Map(), { nodes: 0, until }) : grow(goal, new Map(), { nodes: 0, until });
75
+ const searchEnd = clock();
76
+ if (searchEnd >= until) {
77
+ observe?.({ outcome: 'deadline', encoded: goal, searchEnd });
78
+ return;
79
+ }
80
+ if (!('tree' in result)) {
81
+ const witness = 'witness' in result ? result.witness : undefined, broken = witness ? brokenOf(goal)(witness) : undefined;
82
+ if (witness && broken?.length)
83
+ throw Error('invalid linear auxiliary witness');
84
+ observe?.({ outcome: result.stuck, encoded: goal, witness, broken, searchEnd, ...(policy ? { minimal: { kind: policy.minimalKind, fallback: policy.fallback, units: policy.minimalUnits, fallbackUnits: policy.fallbackUnits } } : {}) });
85
+ return;
86
+ }
87
+ const cut = { when: proposal.when, pos, neg, tree: result.tree }, checked = options.deferCheck || linOk(counts, cut);
88
+ observe?.({ outcome: checked ? (options.deferCheck ? 'proposal' : 'proof') : 'rejected-proof', encoded: goal, searchEnd, ...(policy ? { minimal: { kind: policy.minimalKind, fallback: policy.fallback, units: policy.minimalUnits, fallbackUnits: policy.fallbackUnits } } : {}) });
89
+ return checked ? { proposal, goal, cut, ...(options.deferCheck ? { status: 'unchecked' } : {}) } : undefined;
90
+ }
91
+ export function guardBodyFact(proposal, until) {
92
+ if (pastWall() || clock() >= until)
93
+ return;
94
+ const goal = { name: proposal.name, hyps: [...proposal.when, not(same(proposal.pre, proposal.post))] };
95
+ const result = grow(goal, new Map(), { nodes: 0, until });
96
+ return 'tree' in result && check(goal, result.tree) ? { proposal, goal, tree: result.tree } : undefined;
97
+ }
@@ -0,0 +1,7 @@
1
+ import { type C } from './machine.js';
2
+ import { type Count, type CountDecl, type MapRead, type Path } from '../kernel/kernel.js';
3
+ import type { GuardBodyProposal, GuardCountProposal } from './count-guard-facts.js';
4
+ export declare function guardRegionProposals(rawCounts: Count[], reads: MapRead[], decls: CountDecl[], inputMaps: readonly string[], operation: C, path?: Path): {
5
+ counts: GuardCountProposal[];
6
+ bodies: GuardBodyProposal[];
7
+ };
@@ -0,0 +1,106 @@
1
+ // Structural proposals only: existing count declarations, no protocol names,
2
+ // operation values, trusted facts, or synthesized count declarations.
3
+ import { all, atMost, n, not, same, walkOnce, x } from "./machine.js";
4
+ import { simpE } from "../kernel/kernel.js";
5
+ const text = (t) => JSON.stringify(t);
6
+ const has = (t, p) => { let yes = false; walkOnce(t, (v) => { if (p(v))
7
+ yes = true; }); return yes; };
8
+ const keyed = (t, key) => has(t, v => v.op === 'var' && v.name === key);
9
+ const atoms = (c) => c.op === 'and' ? c.xs.flatMap(atoms) : [c];
10
+ function negativeMap(c, map, negative = false) {
11
+ if (c.op === 'not')
12
+ return negativeMap(c.x, map, !negative);
13
+ if (c.op === 'and' || c.op === 'or')
14
+ return c.xs.some(v => negativeMap(v, map, negative));
15
+ return negative && has(c, v => v.op === 'get' && v.map === map);
16
+ }
17
+ function rowOf(read, decl) {
18
+ const e = read[2];
19
+ return decl.base ? e.op === 'add' && e.a.op === 'mul' && e.a.k === decl.base ? e.a.a : undefined : e;
20
+ }
21
+ export function guardRegionProposals(rawCounts, reads, decls, inputMaps, operation, path = new Map()) {
22
+ // Simplification guides discovery only. Returned body goals retain original expressions.
23
+ const counts = rawCounts.map(c => ({ ...c, body: simpE(c.body, path, c.key) }));
24
+ const out = [], bodies = [], seen = new Set();
25
+ const add = (proposal) => {
26
+ const when = [...proposal.when];
27
+ // A packed read is tied to its certificate label only while its low part is in range.
28
+ for (const [, name] of proposal.terms) {
29
+ const r = reads.find(r => r[0] === name), d = r && decls.find(d => d.map === r[1]);
30
+ if (!r || !d)
31
+ return;
32
+ if (d.base) {
33
+ const key = r[2];
34
+ if (key.op !== 'add' || key.a.op !== 'mul' || key.a.k !== d.base)
35
+ return;
36
+ const bound = { op: '<', a: key.b, b: n(d.base) };
37
+ if (!when.some(c => text(c) === text(bound)))
38
+ when.push(bound);
39
+ }
40
+ }
41
+ const p = { ...proposal, when }, id = text([p.when, p.terms]);
42
+ if (!seen.has(id)) {
43
+ seen.add(id);
44
+ out.push(p);
45
+ }
46
+ };
47
+ for (const post of counts) {
48
+ const read = reads.find(r => r[0] === post.v), decl = read && decls.find(d => d.map === read[1]);
49
+ if (!read || !decl || !read[1].endsWith('#'))
50
+ continue;
51
+ const preRead = reads.find(r => r[1] === read[1].slice(0, -1) && text(r[2]) === text(read[2])), pre = preRead && counts.find(c => c.v === preRead[0]), row = rowOf(read, decl);
52
+ if (!pre || !row)
53
+ continue;
54
+ // A row which is unchanged is still a checked count fact, not a name test.
55
+ if (text(pre.body) === text(post.body))
56
+ for (const sign of [1, -1])
57
+ add({ name: `unchanged ${post.v} ${sign}`, kind: 'row-frame', when: [operation], terms: [[sign, post.v], [-sign, pre.v]] });
58
+ const comparisons = [];
59
+ walkOnce(post.body, (v) => { if (v.op === '<' && keyed(v.a, post.key) && !keyed(v.b, post.key))
60
+ comparisons.push(v); });
61
+ for (const comparison of comparisons) {
62
+ const updates = [];
63
+ walkOnce(comparison.a, (v) => { if (v.op === 'if' && !keyed(v.then, post.key) && v.else?.op === 'get' && keyed(v.else.key, post.key))
64
+ updates.push(v); });
65
+ for (const update of updates) {
66
+ const parts = atoms(update.c), guard = parts.find(c => keyed(c, post.key) && has(c, v => v.op === 'get' && inputMaps.includes(v.map))), active = parts.filter(c => !keyed(c, post.key));
67
+ if (!guard || update.else.op !== 'get')
68
+ continue;
69
+ const raisedMap = update.else.map, sources = [];
70
+ walkOnce(update.then, (v) => { if (v.op === 'get' && v.map === raisedMap && !keyed(v.key, post.key))
71
+ sources.push(v.key); });
72
+ const source = sources[0];
73
+ if (!source)
74
+ continue;
75
+ const guardMap = inputMaps.find(map => has(guard, v => v.op === 'get' && v.map === map));
76
+ if (!guardMap)
77
+ continue;
78
+ const preComparisons = [];
79
+ walkOnce(pre.body, (v) => { if (v.op === '<' && has(v.a, z => z.op === 'get' && z.map === raisedMap && keyed(z.key, pre.key)) && !keyed(v.b, pre.key))
80
+ preComparisons.push(v); });
81
+ for (const restricted of counts) {
82
+ const rr = reads.find(r => r[0] === restricted.v);
83
+ if (!rr || rr[1].endsWith('#') || restricted.body.op !== 'if' || !has(restricted.body, v => v.op === 'get' && v.map === guardMap))
84
+ continue;
85
+ const rd = decls.find(d => d.map === rr[1]), restrictedRow = rd && rowOf(rr, rd);
86
+ // A global/input count has no row parameter. Do not pretend its read key identifies a row.
87
+ if (!rd || !restrictedRow || !has(rd.body, v => v.op === 'var' && (v.name === rd.j || v.name === (rd.lo ?? rd.j))))
88
+ continue;
89
+ if (negativeMap(restricted.body.c, guardMap))
90
+ add({ name: `guard complement ${post.v} <= ${restricted.v}`, kind: 'guard-complement-upper', when: [operation, all(...active), same(row, restrictedRow), atMost(comparison.b, update.then)], terms: [[1, post.v], [-1, restricted.v]] });
91
+ else
92
+ for (const bound of preComparisons)
93
+ add({ name: `guard intersection ${restricted.v} <= ${pre.v}`, kind: 'guard-intersection-lower', when: [operation, all(...active), same(row, restrictedRow), atMost(update.then, bound.b)], terms: [[1, restricted.v], [-1, pre.v]] });
94
+ }
95
+ // On the complement of the member guard and away from every changed
96
+ // key-free field read, both per-member predicates must be identical.
97
+ const exclusions = [operation, { op: '<', a: x(post.key), b: post.below }, not(guard), not(same(x(post.key), source))];
98
+ walkOnce(pre.body, (v) => { if (v.op === 'get' && !keyed(v.key, pre.key))
99
+ exclusions.push(not(same(v.key, source))); });
100
+ const unique = [...new Map(exclusions.map(c => [text(c), c])).values()];
101
+ bodies.push({ name: `guard-excluded body ${post.v}`, kind: 'excluded-body-frame', when: unique, pre: rawCounts.find(c => c.v === pre.v).body, post: rawCounts.find(c => c.v === post.v).body });
102
+ }
103
+ }
104
+ }
105
+ return { counts: out, bodies };
106
+ }
@@ -0,0 +1,18 @@
1
+ import { type Law, type Machine } from './machine.js';
2
+ export type CountGuardShape = {
3
+ voteMap: string;
4
+ rowMap: string;
5
+ memberField: string;
6
+ thresholdField: string;
7
+ memberKey: string;
8
+ rowKey: string;
9
+ otherKey: string;
10
+ width: number;
11
+ membershipMap: string;
12
+ phase?: {
13
+ name: string;
14
+ laws: Law[];
15
+ };
16
+ weakerLaw?: Law;
17
+ };
18
+ export declare function discoverCountGuardShape(m: Machine, law: Law, family: readonly Law[]): CountGuardShape | undefined;
@@ -0,0 +1,100 @@
1
+ // Untrusted structural discovery for optional guarded-count strategies.
2
+ // A match supplies names and existing laws, never a premise or a verdict.
3
+ import { n, walkOnce, x } from "./machine.js";
4
+ import { substC } from "../kernel/kernel.js";
5
+ const json = (value) => JSON.stringify(value);
6
+ const atoms = (c) => c.op === 'and' ? c.xs.flatMap(atoms) : [c];
7
+ const indicator = (d) => d.body.op === 'if' && json(d.body.then) === json(n(1)) && json(d.body.else) === json(n(0));
8
+ export function discoverCountGuardShape(m, law, family) {
9
+ if (!law.forall || law.keys?.length !== 1)
10
+ return;
11
+ let voteMap, rowMap;
12
+ walkOnce(law.holds, (node) => {
13
+ if (node.op !== '<=' || node.a.op !== 'mul' || node.a.k !== 2 || node.a.a.op !== 'get' || node.b.op !== 'get')
14
+ return;
15
+ const vote = m.counts?.[node.a.a.map], row = m.counts?.[node.b.map];
16
+ if (!vote?.base || !row || row.base || !indicator(vote) || !indicator(row) || json(vote.below) !== json(row.below))
17
+ return;
18
+ const packed = node.a.a.key;
19
+ if (packed.op !== 'add' || packed.a.op !== 'mul' || packed.a.k !== vote.base || json(packed.a.a) !== json(x(law.forall)) || json(packed.b) !== json(x(law.keys[0])) || json(node.b.key) !== json(x(law.forall)))
20
+ return;
21
+ const membership = substC(row.body.c, { vars: { [row.j]: x(vote.j), [row.key]: x(vote.key) }, maps: {}, flags: {} });
22
+ if (!atoms(vote.body.c).some(c => json(c) === json(membership)))
23
+ return;
24
+ voteMap = node.a.a.map;
25
+ rowMap = node.b.map;
26
+ });
27
+ if (!voteMap || !rowMap)
28
+ return;
29
+ const vote = m.counts[voteMap];
30
+ if (!indicator(vote))
31
+ return;
32
+ const comparisons = atoms(vote.body.c);
33
+ const threshold = comparisons.find(c => c.op === '<' && c.a.op === 'get' && c.b.op === 'get' && json(c.a.key) === json(x(vote.key)) && json(c.b.key) === json(x(vote.lo ?? vote.j)));
34
+ if (!threshold || threshold.op !== '<' || threshold.a.op !== 'get' || threshold.b.op !== 'get' || !(threshold.a.map in (m.maps ?? {})) || !(threshold.b.map in (m.maps ?? {})))
35
+ return;
36
+ const thresholdField = threshold.b.map, phaseNames = new Set(), phaseLaws = [];
37
+ for (const candidate of family) {
38
+ if (!candidate.forall || candidate.keys?.length)
39
+ continue;
40
+ const fields = new Set(), variables = new Set();
41
+ walkOnce(candidate.holds, (node) => { if (node.op === 'get')
42
+ fields.add(node.map); if (node.op === 'var')
43
+ variables.add(node.name); });
44
+ const phases = Object.keys(m.state).filter(name => variables.has(name));
45
+ if (fields.size && [...fields].every(name => name === thresholdField) && phases.length) {
46
+ phases.forEach(name => phaseNames.add(name));
47
+ phaseLaws.push(candidate);
48
+ }
49
+ }
50
+ // Several existing zero-phase laws can hold (e.g. before selection and
51
+ // before activation). Prefer only a unique phase named by every non-frame
52
+ // threshold-write guard. This remains a proposal: all resulting proofs check.
53
+ if (phaseNames.size > 1) {
54
+ const write = m.step.maps?.[thresholdField], gates = [];
55
+ if (write && 'each' in write)
56
+ walkOnce(write.value, (node) => {
57
+ if (node.op !== 'if' || node.then.op === 'if' || node.then.op === 'get' && node.then.map === thresholdField && node.then.key.op === 'var' && node.then.key.name === write.each)
58
+ return;
59
+ const names = new Set(), seen = new Set();
60
+ const scan = (value) => walkOnce(value, (part) => {
61
+ if (part.op === 'var' && phaseNames.has(part.name))
62
+ names.add(part.name);
63
+ if (part.op === 'flag' && !seen.has(part.name)) {
64
+ seen.add(part.name);
65
+ const flag = m.step.flags?.[part.name];
66
+ if (flag)
67
+ scan(flag.op === 'all' ? flag.c : flag);
68
+ }
69
+ });
70
+ scan(node.c);
71
+ gates.push(names);
72
+ });
73
+ const common = gates.length ? [...phaseNames].filter(name => gates.every(gate => gate.has(name))) : [];
74
+ if (common.length === 1) {
75
+ phaseNames.clear();
76
+ phaseNames.add(common[0]);
77
+ }
78
+ }
79
+ const serialized = new Set(comparisons.map(json));
80
+ const weakerLaw = family.find(candidate => {
81
+ if (!candidate.forall || candidate.keys?.length !== 1)
82
+ return false;
83
+ let found = false;
84
+ walkOnce(candidate.holds, (node) => {
85
+ const count = node.op === 'get' && m.counts?.[node.map];
86
+ if (count && node.map !== voteMap && count.base && indicator(count) && atoms(count.body.c).length < comparisons.length && atoms(count.body.c).every(c => serialized.has(json(c))))
87
+ found = true;
88
+ });
89
+ return found;
90
+ });
91
+ const row = m.counts[rowMap];
92
+ const membershipMaps = new Set();
93
+ if (indicator(row))
94
+ walkOnce(row.body.c, (node) => { if (node.op === 'get')
95
+ membershipMaps.add(node.map); });
96
+ if (membershipMaps.size !== 1)
97
+ return;
98
+ return { membershipMap: [...membershipMaps][0], voteMap, rowMap, memberField: threshold.a.map, thresholdField, memberKey: vote.key, rowKey: vote.j, otherKey: vote.lo ?? vote.j, width: vote.base, ...(phaseNames.size === 1 ? { phase: { name: [...phaseNames][0], laws: phaseLaws.filter(law => { let found = false; walkOnce(law.holds, (node) => { if (node.op === 'var' && phaseNames.has(node.name))
99
+ found = true; }); return found; }) } } : {}), ...(weakerLaw ? { weakerLaw } : {}) };
100
+ }
@@ -0,0 +1,17 @@
1
+ import { type C } from './machine.js';
2
+ import { type Lin } from './solver.js';
3
+ import { type Path, type Tree } from '../kernel/kernel.js';
4
+ type Branch = (path: Path) => Tree | undefined;
5
+ export type HoistRow = {
6
+ row: Lin;
7
+ reject: Branch;
8
+ name?: string;
9
+ };
10
+ export declare function countGuardTree(until: number, options?: {
11
+ yesFirst?: boolean;
12
+ }): {
13
+ rows: (conditions: Lin[], path: Path, yes: Branch, no: Branch) => Tree | undefined;
14
+ condition: (c: C, path: Path, yes: Branch, no: Branch) => Tree | undefined;
15
+ hoist: (queries: readonly HoistRow[], cases: readonly C[], path: Path, yes: Branch, trace?: (event: Record<string, unknown>) => void) => Tree | undefined;
16
+ };
17
+ export {};