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,270 @@
1
+ // Experimental written-row proposer. Standalone results check INIT and STEP;
2
+ // composition may request only an unchecked STEP proposal for its final check.
3
+ // The optional composition hook owns production dispatch; no trusted shortcut.
4
+ import { n, same, walkOnce, x } from "./machine.js";
5
+ import { countGuardTree } from "./count-guard-tree.js";
6
+ import { countFrameConditions, fixedCountFrameCase } from "./count-frames.js";
7
+ import { strategyLeafUntil } from "./count-strategy.js";
8
+ import { canon, check, checkMC, countedObligations, leafConstraints, mcGoal, substC, substE, truth } from "../kernel/kernel.js";
9
+ import { clock, fullRate, fullWork, pastWall, withDeadline } from "../kernel/prove.js";
10
+ import { growCdcl } from "../kernel/cdcl.js";
11
+ import { seedCountWitnessFlags } from "./count-witness-flags.js";
12
+ import { refuteFast } from "./solver.js";
13
+ import { rowSymmetryCache } from "./count-row-symmetry.js";
14
+ import { operationRefutation } from "./count-row-reindex.js";
15
+ import { countPremiseView } from "./count-premise-view.js";
16
+ import { rebasePath } from "./count-recovery/rebase-path.js";
17
+ import { countStageTrace } from "./count-stage-trace.js";
18
+ import { traceNow } from "./trace-clock.js";
19
+ // Operation tests are often already inlined, and a row equality can be an
20
+ // ancestor of the operation guard. Prune only branches decided by the fixed
21
+ // operation; proposing extra row splits is safe, omitting them loses proofs.
22
+ export function rowAgreementWrittenKeys(m, shape) {
23
+ const choice = fixedCountFrameCase(m);
24
+ if (!choice)
25
+ return [];
26
+ const path = new Map(countFrameConditions(choice).map(lin => [canon(lin), { lin, holds: true }]));
27
+ const rows = new Set(), flags = Object.create(null);
28
+ for (const [name, condition] of Object.entries(m.step.flags ?? {}))
29
+ flags[name] = condition.op === 'all' ? same(x('?' + name), n(1)) : substC(condition, { vars: {}, maps: {}, flags });
30
+ for (const map of [shape.map, ...shape.fields, ...shape.markers.map(marker => marker.map)]) {
31
+ const write = m.step.maps?.[map];
32
+ if (!write)
33
+ continue;
34
+ if (!('each' in write)) {
35
+ if (write.key.op !== 'var' || !m.inputs.includes(write.key.name))
36
+ continue;
37
+ let guarded = false, active = false;
38
+ walkOnce(substE(write.value, { vars: {}, maps: {}, flags }), (part) => {
39
+ if (part.op !== '=')
40
+ return;
41
+ const [v, value] = part.a.op === 'var' ? [part.a, part.b] : [part.b, part.a];
42
+ if (v.op !== 'var' || v.name !== choice.name || value.op !== 'const' || !choice.values.includes(value.value))
43
+ return;
44
+ guarded = true;
45
+ active ||= value.value === choice.value;
46
+ });
47
+ if (!guarded || active)
48
+ rows.add(write.key.name);
49
+ continue;
50
+ }
51
+ const visit = (value) => {
52
+ if (!value || typeof value !== 'object')
53
+ return;
54
+ const node = value;
55
+ if (node.op === 'if') {
56
+ const condition = substC(node.c, { vars: {}, maps: {}, flags }), active = truth(condition, path);
57
+ if (active !== false)
58
+ walkOnce(condition, (part) => {
59
+ if (part.op !== '=')
60
+ return;
61
+ const [v, key] = part.a.op === 'var' && part.a.name === write.each ? [part.a, part.b] : [part.b, part.a];
62
+ if (v.op === 'var' && v.name === write.each && key.op === 'var' && m.inputs.includes(key.name))
63
+ rows.add(key.name);
64
+ });
65
+ if (active !== false)
66
+ visit(node.then);
67
+ if (active !== true)
68
+ visit(node.else);
69
+ return;
70
+ }
71
+ for (const child of Array.isArray(value) ? value : Object.values(node))
72
+ visit(child);
73
+ };
74
+ visit(write.value);
75
+ }
76
+ return [...rows];
77
+ }
78
+ // An unchecked INIT proposal for a single-check composition. No STEP or supplied premise.
79
+ export function proposeRowAgreementInitial(m, family, law, until, requestFor) {
80
+ return withDeadline(until, () => {
81
+ const target = family.indexOf(law);
82
+ if (target < 0 || clock() >= until || pastWall())
83
+ return;
84
+ const packets = countedObligations(m, family, {}, target);
85
+ if (packets.length !== 2)
86
+ return;
87
+ const packet = packets[0], request = requestFor(packet.goal, packet.decls), goal = mcGoal(packet.goal.hyps, packet.decls, request);
88
+ const result = goal && growCdcl(goal, new Map(), { nodes: 0, until });
89
+ return result && 'tree' in result ? { ...request, tree: result.tree } : undefined;
90
+ });
91
+ }
92
+ export function proveRowAgreementCase(m, family, law, shape, until, requestFor, options = {}) {
93
+ return withDeadline(until, () => {
94
+ const stages = countStageTrace(options.tailTrace, 'row-case-total');
95
+ try {
96
+ stages.mark('row-case-setup', 'untrusted-assembly');
97
+ const index = family.indexOf(law);
98
+ if (index < 0 || clock() >= until || pastWall() || !law.forall || law.keys?.length !== 2)
99
+ return;
100
+ // Only operation proposals may defer. Standalone INIT/STEP behavior stays checked.
101
+ const deferChecks = options.deferToComposition === true && options.deferRowChecks === true;
102
+ const frameOnly = options.framePremisesOnly && fixedCountFrameCase(m) && !rowAgreementWrittenKeys(m, shape).length;
103
+ const a = x(law.forall + '#'), b = x(law.keys[0]), column = x(law.keys[1]), keyed = new Set();
104
+ walkOnce(m.step.maps, (node) => { if (node.op === 'get' && !m.counts?.[node.map] && node.key.op === 'var' && m.inputs.includes(node.key.name))
105
+ keyed.add(node.key.name); });
106
+ // A small proposal pool: the goal's two rows and actual request row keys.
107
+ // No count law is seeded indiscriminately, and no supplied premise is added.
108
+ const rows = [a, b, ...(options.premiseRows ?? [...keyed].slice(0, 4).map(x))], instances = Object.fromEntries(Object.entries(options.seedInstances ?? {}).map(([name, terms]) => [name, [...terms]]));
109
+ const ownRows = options.ownRows ?? rows.slice(2);
110
+ const put = (l, tuples) => {
111
+ const old = instances[l.name] ?? [], arity = 1 + (l.keys?.length ?? 0);
112
+ for (let i = 0; i < old.length; i += arity)
113
+ tuples.push(old.slice(i, i + arity));
114
+ const unique = [...new Map(tuples.map(tuple => [JSON.stringify(tuple), tuple])).values()];
115
+ instances[l.name] = unique.flat();
116
+ };
117
+ stages.mark('row-premise-instantiation', 'untrusted-assembly');
118
+ for (const l of family) {
119
+ if ((frameOnly || options.onlySeededPremises) && l !== law)
120
+ continue;
121
+ const keys = [...(l.forall ? [l.forall] : []), ...(l.keys ?? [])];
122
+ let counted = false, columnKey;
123
+ walkOnce(l.holds, (node) => {
124
+ if (node.op !== 'get')
125
+ return;
126
+ if (m.counts?.[node.map])
127
+ counted = true;
128
+ const key = node.key;
129
+ if (key.op === 'add') {
130
+ const [base, suffix] = key.a.op === 'mul' ? [key.a, key.b] : [key.b, key.a];
131
+ if (base.op === 'mul' && base.k === shape.width && suffix.op === 'var' && keys.includes(suffix.name))
132
+ columnKey = suffix.name;
133
+ }
134
+ });
135
+ if (counted || !keys.length)
136
+ continue;
137
+ if (keys.length === 1)
138
+ put(l, rows.map(row => [row]));
139
+ else if (keys.length === 2)
140
+ put(l, columnKey === keys[1] ? rows.map(row => [row, column]) : rows.flatMap(row => rows.map(other => [row, other])));
141
+ else if (l === law)
142
+ put(l, frameOnly ? [[a, b, column]] : options.sparseOwn ? [[a, b, column], ...ownRows.flatMap(row => [[row, b, column], [a, row, column]])] : rows.flatMap(row => rows.map(other => [row, other, column])));
143
+ }
144
+ if (!frameOnly)
145
+ for (const [name, flag] of Object.entries(m.step.flags ?? {}))
146
+ if (flag.op === 'all' && !flag.keys?.length)
147
+ instances['?' + name] = [...rows, column];
148
+ if (Object.values(instances).reduce((n, terms) => n + terms.length, 0) > 2048)
149
+ return;
150
+ stages.mark('row-obligation-build', 'untrusted-assembly');
151
+ let packets = countedObligations(m, family, { [law.name]: instances }, index), step = packets.at(-1);
152
+ if (!step)
153
+ return;
154
+ stages.mark('row-request-build', 'untrusted-assembly');
155
+ let request = requestFor(step.goal, step.decls);
156
+ if (options.witnessFlags)
157
+ for (let round = 0; round < 2; round++) {
158
+ stages.mark('row-witness-seed', 'untrusted-assembly', round);
159
+ const seeded = seedCountWitnessFlags(m, instances, [{ decls: step.decls, cert: request }], true);
160
+ if (seeded === instances)
161
+ break;
162
+ Object.assign(instances, seeded);
163
+ if (clock() >= until || pastWall() || Object.values(instances).reduce((n, terms) => n + terms.length, 0) > 2048)
164
+ return;
165
+ stages.mark('row-witness-obligation-build', 'untrusted-assembly', round);
166
+ packets = countedObligations(m, family, { [law.name]: instances }, index);
167
+ step = packets.at(-1);
168
+ if (!step)
169
+ return;
170
+ stages.mark('row-witness-request-build', 'untrusted-assembly', round);
171
+ request = requestFor(step.goal, step.decls);
172
+ }
173
+ stages.mark('row-mc-goal-build', 'untrusted-assembly');
174
+ const goal = mcGoal(step.goal.hyps, step.decls, request);
175
+ if (!goal)
176
+ return;
177
+ stages.mark('row-symmetry-setup', 'untrusted-assembly');
178
+ options.trace?.({ query: 'row-context', goal, request, decls: step.decls });
179
+ const mirror = options.symmetryReuse ? rowSymmetryCache(goal, request, law.forall + '#', law.keys[0], until, options.tailTrace, deferChecks) : undefined;
180
+ const close = (path) => {
181
+ if (clock() >= until || pastWall())
182
+ return;
183
+ const start = fullWork(), wall = options.tailTrace || options.observe ? traceNow() : 0, leafEnd = strategyLeafUntil(until, options);
184
+ const leafStages = countStageTrace(options.tailTrace, 'row-leaf-total');
185
+ try {
186
+ leafStages.mark('row-symmetry-get', 'untrusted-assembly');
187
+ const reused = mirror?.get(path);
188
+ leafStages.mark('row-fast-linear', 'untrusted-search');
189
+ const fast = !reused && options.fastClosure ? refuteFast(leafConstraints(goal, path)) : undefined;
190
+ let scopedTree;
191
+ if (!reused && fast?.kind !== 'refuted' && options.premiseScoped) {
192
+ const scopedEnd = Math.min(leafEnd, clock() + Math.max(0, leafEnd - clock()) * 3 / 4), seen = new Set();
193
+ for (const guardReads of [false, true]) {
194
+ const scopeStart = fullWork();
195
+ leafStages.mark('row-premise-view', 'untrusted-assembly', Number(guardReads));
196
+ const scoped = countPremiseView(goal, m, law, step.goal.hyps.at(-1), step.goal.hyps.slice(0, 2), scopedEnd, guardReads);
197
+ if (!scoped || seen.has(scoped.selected.join(',')))
198
+ continue;
199
+ seen.add(scoped.selected.join(','));
200
+ const attemptEnd = scopedEnd;
201
+ leafStages.mark('row-scoped-search', 'untrusted-search', Number(guardReads));
202
+ const result = growCdcl(scoped.goal, path, { nodes: 0, until: attemptEnd });
203
+ leafStages.mark('row-scoped-transport', 'untrusted-assembly', Number(guardReads));
204
+ const candidate = 'tree' in result ? rebasePath(scoped.goal, result.tree, path, path, until, goal) : undefined;
205
+ leafStages.mark(deferChecks ? 'row-scoped-proposal' : 'row-scoped-check', deferChecks ? 'untrusted-assembly' : 'trusted-check', Number(guardReads));
206
+ scopedTree = candidate && (deferChecks || check(goal, candidate, path)) ? candidate : undefined;
207
+ options.trace?.({ query: 'premise-scope', goal: scoped.goal, path: new Map(path), guardReads, outcome: scopedTree ? deferChecks ? 'unchecked-proposal' : 'proved' : 'tree' in result ? 'transport-rejected' : result.stuck, hyps: scoped.goal.hyps.length, fullHyps: goal.hyps.length, selected: scoped.selected, omitted: scoped.omitted, allowed: scoped.allowed, scopeUnits: (fullWork() - scopeStart) / fullRate, units: (fullWork() - start) / fullRate });
208
+ if (scopedTree)
209
+ break;
210
+ }
211
+ }
212
+ leafStages.mark('row-full-search', 'untrusted-search');
213
+ const result = reused ? { tree: reused } : fast?.kind === 'refuted' ? { tree: { leaf: fast.steps } } : scopedTree ? { tree: scopedTree } : growCdcl(goal, path, { nodes: 0, until: leafEnd });
214
+ const capped = leafEnd < until && clock() >= leafEnd;
215
+ leafStages.mark(deferChecks ? 'row-leaf-proposal' : 'row-leaf-check', deferChecks ? 'untrusted-assembly' : 'trusted-check');
216
+ const tree = 'tree' in result && (deferChecks || check(goal, result.tree, path)) && clock() < until ? result.tree : undefined;
217
+ leafStages.mark('row-symmetry-put', 'untrusted-assembly');
218
+ if (tree)
219
+ mirror?.put(path, tree);
220
+ options.observe?.({ stage: 'leaf', ...(options.symmetryReuse ? { symmetryEnabled: mirror !== undefined } : {}), method: reused ? 'symmetry' : fast?.kind === 'refuted' ? 'linear' : 'cdcl', outcome: tree ? deferChecks ? 'unchecked-proposal' : 'proved' : capped ? 'leaf-cap' : clock() >= until ? 'pool-exhausted' : 'stuck' in result ? result.stuck : 'rejected-proof', goal, path: new Map(path), hyps: goal.hyps.length, units: (fullWork() - start) / fullRate, ...(wall ? { wallMs: traceNow() - wall } : {}), ...('witness' in result ? { witness: result.witness } : {}) });
221
+ return tree;
222
+ }
223
+ finally {
224
+ leafStages.finish();
225
+ }
226
+ };
227
+ stages.mark('row-case-tree', 'untrusted-search');
228
+ const split = countGuardTree(until);
229
+ const writtenRows = rowAgreementWrittenKeys(m, shape).slice(0, 4).map(x);
230
+ const finish = (path) => options.diagonalAlias && writtenRows.some(row => truth(same(a, row), path) === true && truth(same(b, row), path) === true)
231
+ ? split.condition(same(a, b), path, close, close) : close(path);
232
+ // Written-row cases are ordinary exhaustive equality splits. Extra splits
233
+ // only cost work; they cannot establish an invariant or authorize a fact.
234
+ const choose = (i, path) => {
235
+ if (i >= writtenRows.length)
236
+ return finish(path);
237
+ const written = writtenRows[i];
238
+ return split.condition(same(a, written), path, p => split.condition(same(b, written), p, q => choose(i + 1, q), q => choose(i + 1, q)), p => split.condition(same(b, written), p, q => choose(i + 1, q), q => choose(i + 1, q)));
239
+ };
240
+ const run = (path) => options.diagonalFirst ? split.condition(same(a, b), path, close, p => choose(0, p)) : choose(0, path);
241
+ const fixed = options.operationPath ? fixedCountFrameCase(m) : undefined;
242
+ const tree = fixed ? split.rows(countFrameConditions(fixed), new Map(), run, path => operationRefutation(leafConstraints(goal, path), fixed.name)) : run(new Map());
243
+ if (!tree)
244
+ return;
245
+ stages.mark('row-case-return', 'untrusted-assembly');
246
+ const stepCert = { ...request, tree };
247
+ if (options.deferToComposition)
248
+ return { instances, certs: { [step.goal.name]: stepCert }, ...(deferChecks ? { status: 'unchecked' } : {}) };
249
+ if (!checkMC(step.goal.hyps, step.decls, stepCert))
250
+ return;
251
+ const certs = { [step.goal.name]: stepCert };
252
+ for (const initial of packets.slice(0, -1)) {
253
+ if (clock() >= until || pastWall())
254
+ return;
255
+ const base = requestFor(initial.goal, initial.decls), initialGoal = mcGoal(initial.goal.hyps, initial.decls, base);
256
+ const result = initialGoal && growCdcl(initialGoal, new Map(), { nodes: 0, until });
257
+ if (!result || !('tree' in result))
258
+ return;
259
+ const cert = { ...base, tree: result.tree };
260
+ if (!checkMC(initial.goal.hyps, initial.decls, cert))
261
+ return;
262
+ certs[initial.goal.name] = cert;
263
+ }
264
+ return clock() < until && !pastWall() ? { instances, certs } : undefined;
265
+ }
266
+ finally {
267
+ stages.finish();
268
+ }
269
+ });
270
+ }
@@ -0,0 +1,3 @@
1
+ import { type CountCert, type CountDecl } from '../kernel/kernel.js';
2
+ export declare function identicalRowCountAliases(decls: CountDecl[], reads: CountCert['reads'], rowMap: string, prefix: string, more?: () => boolean): CountCert['insts'];
3
+ export declare function restrictedRowCountAliases(decls: CountDecl[], reads: CountCert['reads'], voteMap: string, prefix: string, more?: () => boolean): CountCert['insts'];
@@ -0,0 +1,59 @@
1
+ // Untrusted equality proposals for a row count and an identical existing read.
2
+ // Both inequalities remain ordinary CountInst witnesses checked by checkMC.
3
+ import { substE } from "../kernel/kernel.js";
4
+ import { x } from "./machine.js";
5
+ import { countsForReads } from "./count-facts.js";
6
+ export function identicalRowCountAliases(decls, reads, rowMap, prefix, more = () => true) {
7
+ const counts = countsForReads(decls, reads);
8
+ if (!counts)
9
+ return [];
10
+ const rows = new Set(reads.filter(([, map]) => map === rowMap).map(([id]) => id)), pre = new Set(reads.filter(([, map]) => !map.endsWith('#')).map(([id]) => id));
11
+ const body = (c) => JSON.stringify([c.below, substE(c.body, { vars: { [c.key]: x(prefix + 'bound') }, maps: {}, flags: {} })]);
12
+ const out = [], seen = new Set();
13
+ for (const row of counts.filter(c => rows.has(c.v)))
14
+ for (const other of counts) {
15
+ if (!more() || out.length >= 8)
16
+ return out;
17
+ if (row.v === other.v || !pre.has(other.v) || body(row) !== body(other))
18
+ continue;
19
+ const pair = [row.v, other.v].sort().join('\n');
20
+ if (seen.has(pair))
21
+ continue;
22
+ seen.add(pair);
23
+ for (const [a, b] of [[row.v, other.v], [other.v, row.v]])
24
+ out.push({ wit: prefix + out.length, below: row.below, terms: [[1, a], [-1, b]], unit: 0 });
25
+ }
26
+ return out;
27
+ }
28
+ // Equality is only a proposal here. A missing restriction is NOT assumed:
29
+ // each signed difference still needs an ordinary counting witness refutation.
30
+ // This includes the election's threshold/not-newer restricted count, rather
31
+ // than trying to repair only a plain membership-row alias. Keep the nearest
32
+ // predicate slice: do not drop both the threshold and a not-newer restriction.
33
+ export function restrictedRowCountAliases(decls, reads, voteMap, prefix, more = () => true) {
34
+ const counts = countsForReads(decls, reads);
35
+ if (!counts)
36
+ return [];
37
+ const votes = new Set(reads.filter(([, map]) => map === voteMap).map(([id]) => id)), pre = new Set(reads.filter(([, map]) => !map.endsWith('#')).map(([id]) => id));
38
+ const atoms = (c) => c.op === 'and' ? c.xs.flatMap(atoms) : [c];
39
+ const body = (e) => e.op === 'if' && e.then.op === 'const' && e.then.value === 1 && e.else.op === 'const' && e.else.value === 0 ? new Set(atoms(e.c).map(c => JSON.stringify(c))) : undefined;
40
+ const normalized = (c) => body(substE(c.body, { vars: { [c.key]: x(prefix + 'bound') }, maps: {}, flags: {} }));
41
+ const out = [], seen = new Set();
42
+ for (const vote of counts.filter(c => votes.has(c.v)))
43
+ for (const other of counts) {
44
+ if (!more() || out.length >= 8)
45
+ return out;
46
+ if (vote.v === other.v || !pre.has(other.v) || JSON.stringify(vote.below) !== JSON.stringify(other.below))
47
+ continue;
48
+ const a = normalized(vote), b = normalized(other);
49
+ if (!a || !b || !b.size || a.size > b.size + 1 || ![...b].every(atom => a.has(atom)))
50
+ continue;
51
+ const pair = [vote.v, other.v].sort().join('\n');
52
+ if (seen.has(pair))
53
+ continue;
54
+ seen.add(pair);
55
+ for (const [left, right] of [[vote.v, other.v], [other.v, vote.v]])
56
+ out.push({ wit: prefix + out.length, below: vote.below, terms: [[1, left], [-1, right]], unit: 0 });
57
+ }
58
+ return out;
59
+ }
@@ -0,0 +1,6 @@
1
+ import { type Law, type Machine } from './machine.js';
2
+ import { type CountRequestBuilder, type CountStrategyProof, type CountStrategyOptions } from './count-strategy.js';
3
+ export declare function proveCountRowComposition(m: Machine, family: Law[], law: Law, until: number, requestFor: CountRequestBuilder, observe?: (event: Record<string, unknown>) => void, options?: CountStrategyOptions & {
4
+ framePremisesOnly?: boolean;
5
+ shapeFamily?: readonly Law[];
6
+ }): CountStrategyProof | undefined;
@@ -0,0 +1,55 @@
1
+ // Optional versioned-row portfolio. All cases share the caller's deadline.
2
+ // STEP cases and INIT are proposals: only the final original-goal checker accepts them.
3
+ import { all, n, same, x } from "./machine.js";
4
+ import { finiteCountChoice } from "./count-cases.js";
5
+ import { traceNow } from "./trace-clock.js";
6
+ import { traceCountStage } from "./count-stage-trace.js";
7
+ import { countCertificateSize } from "./count-certificate-minimize.js";
8
+ import { discoverCountGuardShape } from "./count-guard-shape.js";
9
+ import { discoverCountRowCopy } from "./count-copy-shape.js";
10
+ import { discoverRowAgreement } from "./row-agreement-shape.js";
11
+ import { proveRowAgreementCase, proposeRowAgreementInitial, rowAgreementWrittenKeys } from "./count-row-agreement.js";
12
+ import { classifyRowValueWrite } from "./count-row-policy.js";
13
+ import { rowCountSupport } from "./count-row-support.js";
14
+ import { composeCountOperationProofs } from "./count-case-compose.js";
15
+ import { clock, fullRate, fullWork, late, withDeadline } from "../kernel/prove.js";
16
+ export function proveCountRowComposition(m, family, law, until, requestFor, observe, options = {}) {
17
+ return withDeadline(until, () => {
18
+ if (late(until))
19
+ return;
20
+ const row = discoverRowAgreement(m, law), choice = finiteCountChoice(m);
21
+ if (!row || !choice)
22
+ return;
23
+ // Shape inventory is construction metadata only. All proof hypotheses, seed
24
+ // instances and returned citations still come from the attempted family.
25
+ const shapeFamily = options.shapeFamily ?? family;
26
+ const shapes = shapeFamily.flatMap(l => { const s = discoverCountGuardShape(m, l, shapeFamily); return s?.membershipMap === row.map ? [s] : []; });
27
+ if (!shapes.length)
28
+ return;
29
+ const planned = traceCountStage(observe, 'row-plan', 'untrusted-assembly', () => [...choice[1]].map(value => {
30
+ const machine = { ...m, assume: all(...(m.assume ? [m.assume] : []), same(x(choice[0]), n(value))) }, support = traceCountStage(observe, 'row-plan-support-' + value, 'untrusted-assembly', () => rowCountSupport(machine, family, law, row, until));
31
+ const kind = !rowAgreementWrittenKeys(machine, row).length ? 'frame' : support ? 'leader' : shapes.some(shape => discoverCountRowCopy(machine, shape, { name: choice[0], value })) ? 'copy' : classifyRowValueWrite(machine, row) ?? 'replacement';
32
+ return { value, machine, support, kind };
33
+ }));
34
+ const rank = { leader: 0, copy: 1, load: 2, replacement: 3, frame: 4 };
35
+ planned.sort((a, b) => rank[a.kind] - rank[b.kind] || a.value - b.value);
36
+ observe?.({ stage: 'plan', cases: planned.map(({ value, kind }) => ({ value, kind })) });
37
+ const cases = [];
38
+ for (const { value, machine, support, kind } of planned) {
39
+ if (late(until))
40
+ return;
41
+ const start = fullWork(), wall = traceNow();
42
+ const proof = proveRowAgreementCase(machine, family, law, row, until, support?.request ?? requestFor, { ...support?.options, leafUnits: options.leafUnits, sparseOwn: true, symmetryReuse: true, premiseScoped: kind === 'copy', operationPath: kind === 'frame' || kind === 'load' || kind === 'leader' || kind === 'copy', diagonalAlias: kind === 'copy' || kind === 'leader', framePremisesOnly: options.framePremisesOnly && kind === 'frame', deferToComposition: true, deferRowChecks: options.deferRowChecks, tailTrace: observe ? event => observe({ operation: value, kind, ...event }) : undefined, trace: observe ? event => observe({ stage: 'query', operation: value, kind, ...event }) : undefined, observe: leaf => observe?.({ stage: 'leaf', outcome: leaf.outcome, hyps: leaf.goal.hyps.length, units: leaf.units, wallMs: leaf.wallMs, operation: value, kind, method: leaf.method, ...(!['proved', 'unchecked-proposal'].includes(leaf.outcome) ? { goal: leaf.goal, path: [...leaf.path.values()] } : {}) }) });
43
+ observe?.({ stage: 'operation', value, kind, proposed: !!proof, checked: false, ...(proof?.status ? { status: proof.status } : {}), units: (fullWork() - start) / fullRate, wallMs: traceNow() - wall, remaining: until - clock(), ...(proof ? { size: countCertificateSize(proof.certs[law.name + ' @step']) } : {}) });
44
+ if (!proof)
45
+ return;
46
+ cases.push({ value, proof });
47
+ }
48
+ if (late(until))
49
+ return;
50
+ const initial = traceCountStage(observe, 'initial-proposal', 'untrusted-search', () => proposeRowAgreementInitial(m, family, law, until, requestFor));
51
+ if (!initial)
52
+ return;
53
+ return composeCountOperationProofs({ original: m, machine: m, shape: shapes[0], restrictions: [], inputCounts: {} }, family, law, cases, until, requestFor, (stage, value) => observe?.({ stage, value }), { initial, trace: observe, minimize: options.minimize, reindexFactsOnly: options.reindexFactsOnly, familyProposal: options.familyProposal });
54
+ });
55
+ }
@@ -0,0 +1,4 @@
1
+ import { type Law, type Machine } from './machine.js';
2
+ import { type CountRequestBuilder, type CountStrategyProof, type CountStrategyOptions } from './count-strategy.js';
3
+ import { type Instances } from '../kernel/kernel.js';
4
+ export declare function proveCountRowCopyLinear(m: Machine, family: Law[], law: Law, seed: Instances, until: number, requestFor: CountRequestBuilder, observe?: (stage: string, checked: boolean) => void, options?: CountStrategyOptions): CountStrategyProof | undefined;
@@ -0,0 +1,83 @@
1
+ // Pointwise, ordinary checked alternative to the global row-copy witnesses.
2
+ // A failed auxiliary proof declines; neither discovery nor a candidate is trusted.
3
+ import { all, n, not, same, x } from "./machine.js";
4
+ import { countFrameConditions, fixedCountFrameCase, ownCountLawInstance } from "./count-frames.js";
5
+ import { discoverCountGuardShape } from "./count-guard-shape.js";
6
+ import { discoverCountRowCopy } from "./count-copy-shape.js";
7
+ import { countsForReads } from "./count-facts.js";
8
+ import { countPrimitiveUnits } from "./count-primitive-budget.js";
9
+ import { guardLinearFact } from "./count-guard-facts.js";
10
+ import { countGuardTree } from "./count-guard-tree.js";
11
+ import { finishCountStrategy } from "./count-strategy.js";
12
+ import { add, k, scale, solve } from "./solver.js";
13
+ import { countedObligations, frameOk, framePath, mcGoal, truth } from "../kernel/kernel.js";
14
+ import { clock, late, rowsAt, withDeadline } from "../kernel/prove.js";
15
+ export function proveCountRowCopyLinear(m, family, law, seed, until, requestFor, observe, options = {}) {
16
+ return withDeadline(until, () => {
17
+ if (late(until) || !family.includes(law))
18
+ return;
19
+ const shape = discoverCountGuardShape(m, law, family), choice = fixedCountFrameCase(m);
20
+ if (!shape || !choice)
21
+ return;
22
+ const copy = discoverCountRowCopy(m, shape, choice), active = copy && m.step.flags?.[copy.guard];
23
+ if (!copy || !active || active.op === 'all')
24
+ return;
25
+ const from = x(copy.from), to = x(copy.to), a = x(law.forall + '#'), b = x(law.keys[0]), pairs = [[a, b], [a, from], [from, b], [from, from]], instances = { ...ownCountLawInstance(law, seed) };
26
+ const unique = new Map(), old = instances[law.name] ?? [];
27
+ for (let i = 0; i < old.length; i += 2)
28
+ unique.set(JSON.stringify(old.slice(i, i + 2)), old.slice(i, i + 2));
29
+ for (const pair of pairs)
30
+ unique.set(JSON.stringify(pair), pair);
31
+ instances[law.name] = [...unique.values()].flat();
32
+ const step = countedObligations(m, family, { [law.name]: instances }, family.indexOf(law)).at(-1);
33
+ if (!step)
34
+ return;
35
+ const base = requestFor(step.goal, step.decls), reads = base.reads, counts = countsForReads(step.decls, reads);
36
+ if (!counts)
37
+ return;
38
+ const key = (p, q) => q ? { op: 'add', a: { op: 'mul', k: shape.width, a: p }, b: q } : p;
39
+ const read = (map, key) => reads.find(r => r[1] === map && JSON.stringify(r[2]) === JSON.stringify(key))?.[0];
40
+ const postVote = read(shape.voteMap + '#', key(a, b)), postRow = read(shape.rowMap + '#', a), bound = counts.find(c => c.v === postVote)?.below;
41
+ const votes = pairs.map(([p, q]) => read(shape.voteMap, key(p, q))), rows = [a, from].map(p => read(shape.rowMap, p));
42
+ if (!postVote || !postRow || !bound || votes.some(r => !r) || rows.some(r => !r))
43
+ return;
44
+ const operation = same(x(choice.name), n(choice.value)), domain = all(...[a, b, from, to].flatMap(t => [{ op: '<', a: t, b: bound }, { op: '<', a: t, b: n(shape.width) }])), regions = [[not(same(a, to)), not(same(b, to))], [not(same(a, to)), same(b, to)], [same(a, to), not(same(b, to))], [same(a, to), same(b, to)]];
45
+ const when = [...(m.pre ? [m.pre] : []), operation, domain, active], proposals = votes.map((pre, i) => ({ name: 'copy voter inclusion ' + i, kind: 'pointwise-copy', when: [...when, ...regions[i]], terms: [[1, postVote], [-1, pre]] }));
46
+ rows.forEach((pre, i) => proposals.push({ name: 'copy row lower bound ' + i, kind: 'pointwise-copy', when: [...when, i ? same(a, to) : not(same(a, to))], terms: [[1, pre], [-1, postRow]] }));
47
+ const lins = [];
48
+ for (const proposal of proposals) {
49
+ if (late(until))
50
+ return;
51
+ const fact = guardLinearFact(step.decls, reads, proposal, Math.min(until, clock() + countPrimitiveUnits(Infinity, options.leafUnits)));
52
+ observe?.(proposal.name, !!fact);
53
+ if (!fact)
54
+ return;
55
+ lins.push(fact.cut);
56
+ }
57
+ const request = { reads, insts: [], picks: [], lins }, goal = mcGoal(step.goal.hyps, step.decls, request);
58
+ if (!goal)
59
+ return;
60
+ const frames = [], ask = (path, frame = false, stage = 'active-region') => {
61
+ if (late(until))
62
+ return;
63
+ if (frame)
64
+ for (const map of [shape.voteMap, shape.rowMap]) {
65
+ const post = read(map + '#', map === shape.rowMap ? a : key(a, b)), pre = read(map, map === shape.rowMap ? a : key(a, b));
66
+ if (!post || !pre)
67
+ return;
68
+ const cut = { post, pre, when: [...path.values()].map(t => t.holds ? t.lin : add(scale(t.lin, -1), k(1))) };
69
+ if (frameOk(counts, cut))
70
+ frames.push(cut);
71
+ }
72
+ const result = solve(rowsAt(goal, framePath(frames, [], path, [], lins)), 2000);
73
+ if (result.kind !== 'refuted')
74
+ observe?.('close:' + stage + ':' + result.kind + ':' + JSON.stringify({ frames: frames.length, activeCuts: lins.map(l => l.when.map(c => truth(c, path))), path: [...path.values()] }), false);
75
+ return result.kind === 'refuted' ? { leaf: result.steps } : undefined;
76
+ };
77
+ const split = countGuardTree(until), region = (path) => split.condition(same(a, to), path, p => split.condition(same(b, to), p, q => ask(q), q => ask(q)), p => split.condition(same(b, to), p, q => ask(q), q => ask(q)));
78
+ const body = (path) => split.rows(countFrameConditions(choice), path, p => split.condition(domain, p, q => split.condition(active, q, region, q => ask(q, true, 'inactive')), q => ask(q, false, 'outside-domain')), q => ask(q, false, 'outside-operation'));
79
+ const tree = m.pre ? split.condition(m.pre, new Map(), body, p => ask(p, false, 'outside-precondition')) : body(new Map());
80
+ observe?.('whole-step-tree', !!tree);
81
+ return tree ? finishCountStrategy(m, family, law, instances, shape.voteMap, { ...request, frames, tree }, until, requestFor, undefined, options) : undefined;
82
+ });
83
+ }
@@ -0,0 +1,4 @@
1
+ import { type Law, type Machine } from './machine.js';
2
+ import { type CountRequestBuilder, type CountStrategyProof, type CountStrategyOptions } from './count-strategy.js';
3
+ import { type Instances } from '../kernel/kernel.js';
4
+ export declare function proveCountRowCopy(m: Machine, family: Law[], law: Law, seed: Instances, until: number, requestFor: CountRequestBuilder, options?: CountStrategyOptions): CountStrategyProof | undefined;
@@ -0,0 +1,94 @@
1
+ // Optional structural row-copy proof. Selection and slicing are untrusted;
2
+ // every leaf is transported back and checked on the complete count goal.
3
+ import { x, n, same, atMost, walkOnce } from "./machine.js";
4
+ import { countsForReads } from "./count-facts.js";
5
+ import { countPrimitiveUnits } from "./count-primitive-budget.js";
6
+ import { countFrameConditions, fixedCountFrameCase, ownCountLawInstance } from "./count-frames.js";
7
+ import { discoverCountGuardShape } from "./count-guard-shape.js";
8
+ import { discoverCountRowCopy } from "./count-copy-shape.js";
9
+ import { countGuardTree } from "./count-guard-tree.js";
10
+ import { finishCountStrategy, strategyLeafUntil } from "./count-strategy.js";
11
+ import { add, k, scale, solve } from "./solver.js";
12
+ import { countedObligations, frameOk, framePath, mcGoal } from "../kernel/kernel.js";
13
+ import { growCdcl } from "../kernel/cdcl.js";
14
+ import { clock, pastWall, rowsAt, withDeadline } from "../kernel/prove.js";
15
+ import { rebasePath } from "./count-recovery/rebase-path.js";
16
+ export function proveCountRowCopy(m, family, law, seed, until, requestFor, options = {}) {
17
+ return withDeadline(until, () => {
18
+ if (clock() >= until || pastWall() || !family.includes(law))
19
+ return;
20
+ const shape = discoverCountGuardShape(m, law, family), choice = fixedCountFrameCase(m);
21
+ if (!shape || !choice)
22
+ return;
23
+ const copy = discoverCountRowCopy(m, shape, choice);
24
+ if (!copy)
25
+ return;
26
+ const from = x(copy.from), to = x(copy.to), a = x(law.forall + '#'), b = x(law.keys[0]);
27
+ const pairs = [[a, b], [a, from], [from, b], [from, from]], instances = { ...ownCountLawInstance(law, seed) };
28
+ const old = instances[law.name] ?? [], unique = new Map();
29
+ for (let i = 0; i < old.length; i += 2)
30
+ unique.set(JSON.stringify(old.slice(i, i + 2)), old.slice(i, i + 2));
31
+ for (const pair of pairs)
32
+ unique.set(JSON.stringify(pair), pair);
33
+ instances[law.name] = [...unique.values()].flat();
34
+ const step = countedObligations(m, family, { [law.name]: instances }, family.indexOf(law)).at(-1);
35
+ if (!step)
36
+ return;
37
+ const base = requestFor(step.goal, step.decls), reads = base.reads, counts = countsForReads(step.decls, reads);
38
+ if (!counts)
39
+ return;
40
+ const { voteMap, rowMap, width } = shape, key = (p, q) => q ? { op: 'add', a: { op: 'mul', k: width, a: p }, b: q } : p;
41
+ const read = (map, key) => reads.find(r => r[1] === map && JSON.stringify(r[2]) === JSON.stringify(key))?.[0];
42
+ const postVote = read(voteMap + '#', key(a, b)), postRow = read(rowMap + '#', a), bound = counts.find(c => c.v === postVote)?.below;
43
+ const voteReads = pairs.map(([p, q]) => read(voteMap, key(p, q))), rowReads = [a, from].map(p => read(rowMap, p));
44
+ if (!postVote || !postRow || !bound || voteReads.some(r => !r) || rowReads.some(r => !r))
45
+ return;
46
+ const scope = JSON.stringify([m, family, seed, reads]), names = [];
47
+ for (let i = 0; names.length < 6; i++) {
48
+ const name = `rowCopy$${i}`;
49
+ if (!scope.includes(JSON.stringify(name)))
50
+ names.push(name);
51
+ }
52
+ const voters = voteReads.map((r, i) => ({ wit: names[i], below: bound, terms: [[1, postVote], [-1, r]], unit: 0 }));
53
+ const rows = rowReads.map((r, i) => ({ wit: names[4 + i], below: bound, terms: [[1, r], [-1, postRow]], unit: 0 }));
54
+ const request = { reads, insts: [...voters, ...rows], picks: [] }, goal = mcGoal(step.goal.hyps, step.decls, request);
55
+ if (!goal)
56
+ return;
57
+ const frames = [], active = m.step.flags?.[copy.guard];
58
+ if (!active || active.op === 'all')
59
+ return;
60
+ const ask = (path, index, frame = false) => {
61
+ if (clock() >= until || pastWall())
62
+ return;
63
+ if (frame)
64
+ for (const map of [voteMap, rowMap]) {
65
+ const post = read(map + '#', map === rowMap ? a : key(a, b)), pre = read(map, map === rowMap ? a : key(a, b));
66
+ if (!post || !pre)
67
+ return;
68
+ const cut = { post, pre, when: [...path.values()].map(t => t.holds ? t.lin : add(scale(t.lin, -1), k(1))) };
69
+ if (frameOk(counts, cut))
70
+ frames.push(cut);
71
+ }
72
+ const p = framePath(frames, [], path), selected = reads.find(r => r[0] === voters[index].terms[1][1]);
73
+ const hyps = step.goal.hyps.filter(h => { let unrelated = false; walkOnce(h, (z) => { if (z.op === 'get' && z.map === voteMap && JSON.stringify(z.key) !== JSON.stringify(selected[2]))
74
+ unrelated = true; }); return !unrelated; });
75
+ const view = mcGoal(hyps, step.decls, { ...request, insts: [voters[index], rows[index >= 2 ? 1 : 0]] });
76
+ if (!view)
77
+ return;
78
+ const direct = solve(rowsAt(goal, p), 1000);
79
+ // Intermediate trees are proposals. finishCountStrategy checks the whole
80
+ // original-goal certificate once; do not repeat that work at every leaf.
81
+ if (direct.kind === 'refuted')
82
+ return { leaf: direct.steps };
83
+ const result = growCdcl(view, p, { nodes: 0, until: Math.min(strategyLeafUntil(until, options), clock() + countPrimitiveUnits(1000, options.leafUnits)) });
84
+ const lifted = 'tree' in result ? rebasePath(view, result.tree, p, p, Math.min(strategyLeafUntil(until, options), clock() + countPrimitiveUnits(500, options.leafUnits)), goal) : undefined;
85
+ return lifted;
86
+ };
87
+ const split = countGuardTree(until);
88
+ const domain = { op: 'and', xs: [a, b, from, to].flatMap(t => [{ op: '<', a: t, b: bound }, { op: '<', a: t, b: n(width) }]) };
89
+ const regions = (p) => split.condition(same(a, to), p, q => split.condition(same(b, to), q, r => ask(r, 3), r => ask(r, 2)), q => split.condition(same(b, to), q, r => ask(r, 1), r => ask(r, 0)));
90
+ const copies = (p) => split.condition(atMost(to, from), p, regions, regions);
91
+ const tree = split.rows(countFrameConditions(choice), new Map(), p => split.condition(domain, p, q => split.condition(active, q, copies, q => ask(q, 0, true)), q => ask(q, 0)), p => ask(p, 0));
92
+ return tree ? finishCountStrategy(m, family, law, instances, voteMap, { ...request, frames, tree }, until, requestFor, undefined, options) : undefined;
93
+ });
94
+ }
@@ -0,0 +1,3 @@
1
+ import { type Machine } from './machine.js';
2
+ import { type RowAgreementShape } from './row-agreement-shape.js';
3
+ export declare function classifyRowValueWrite(m: Machine, row: Pick<RowAgreementShape, 'map' | 'fields'>): 'load' | 'replacement' | undefined;