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,97 @@
1
+ // Untrusted shared prefix for unwritten row counts. Every reusable result is
2
+ // checked after alpha-renaming; no frame is inferred merely from a row label.
3
+ import { n, not, same, walkOnce, x } from "./machine.js";
4
+ import { countCertificateRenamer } from "./count-cert-rename.js";
5
+ import { countsForReads } from "./count-facts.js";
6
+ import { linOk, substE } from "../kernel/kernel.js";
7
+ import { clock } from "../kernel/prove.js";
8
+ import { countPrimitiveUnits } from "./count-primitive-budget.js";
9
+ import { guardLinearFact } from "./count-guard-facts.js";
10
+ import { replayLinearSkeleton } from "./count-replay-skeleton.js";
11
+ // A hint, never an equality assumption: alpha-renaming can change which
12
+ // orientation a stored derivation supports. Admit the reverse only by linOk.
13
+ export function checkedReversePrefix(counts, cut) {
14
+ const candidate = { ...cut, pos: cut.neg, neg: cut.pos };
15
+ return linOk(counts, candidate) ? candidate : undefined;
16
+ }
17
+ // Unlike swapping a proof, this rebuilds every leaf for the opposite claim.
18
+ // It may only return a cut that linOk accepts under the original conditions.
19
+ export function replayReversePrefix(counts, cut, until) {
20
+ if (clock() >= until)
21
+ return;
22
+ const pos = cut.neg, neg = cut.pos, first = counts.find(c => c.v === (pos[0] ?? neg[0])?.[1]);
23
+ if (!first || [...pos, ...neg].some(([, id]) => !counts.some(c => c.v === id)))
24
+ return;
25
+ const term = (side) => side.reduceRight((rest, [k, id]) => ({ op: 'add', a: { op: 'mul', k, a: counts.find(c => c.v === id).body }, b: rest }), n(0));
26
+ const goal = { name: 'replayed opposite prefix', hyps: [...cut.when, { op: '<', a: x(first.key), b: first.below }, { op: '<', a: term(neg), b: term(pos) }] };
27
+ const tree = replayLinearSkeleton(goal, cut.tree, new Map(), until);
28
+ const candidate = tree && { ...cut, pos, neg, tree };
29
+ return candidate && clock() < until && linOk(counts, candidate) ? candidate : undefined;
30
+ }
31
+ export class UnwrittenCountPrefix {
32
+ decls;
33
+ reads;
34
+ guards;
35
+ written;
36
+ rowBound;
37
+ search;
38
+ options;
39
+ cache = new Map();
40
+ stats = { proofs: 0, hits: 0, refusals: 0 };
41
+ constructor(decls, reads, guards, written, rowBound, search = 'grow', options = {}) {
42
+ this.decls = decls;
43
+ this.reads = reads;
44
+ this.guards = guards;
45
+ this.written = written;
46
+ this.rowBound = rowBound;
47
+ this.search = search;
48
+ this.options = options;
49
+ }
50
+ prove(post, pre, rows, sign, until) {
51
+ const p = this.reads.find(r => r[0] === post), q = this.reads.find(r => r[0] === pre);
52
+ if (!p || !q || p[1] !== q[1] + '#' || JSON.stringify(p[2]) !== JSON.stringify(q[2]))
53
+ return;
54
+ const names = [...new Set(rows.flatMap(r => r.op === 'var' ? [r.name] : []))];
55
+ if (names.length !== rows.length)
56
+ return;
57
+ const fixed = new Set();
58
+ for (const c of [...this.guards, this.written, this.rowBound])
59
+ walkOnce(c, (v) => { if (v.op === 'var')
60
+ fixed.add(v.name); });
61
+ if (names.some(n => fixed.has(n)))
62
+ return;
63
+ const scope = JSON.stringify([this.decls, this.reads, this.guards, this.written, this.rowBound]);
64
+ let prefix = 'unwritten$';
65
+ while (scope.includes(prefix))
66
+ prefix = '$' + prefix;
67
+ const vars = Object.fromEntries(names.map((name, i) => [name, x(prefix + 'r' + i)])), sub = { vars, maps: {}, flags: {} };
68
+ const key = substE(p[2], sub), genericRows = names.map(n => vars[n]), when = [...this.guards, ...genericRows.flatMap(row => [{ op: '<', a: row, b: this.rowBound }, not(same(row, this.written))])];
69
+ const generic = [[prefix + 'post', p[1], key], [prefix + 'pre', q[1], key]], terms = [[sign, generic[0][0]], [-sign, generic[1][0]]];
70
+ const cacheKey = JSON.stringify([generic, when, terms]);
71
+ let cut = this.cache.get(cacheKey);
72
+ if (cut)
73
+ this.stats.hits++;
74
+ else {
75
+ this.stats.proofs++;
76
+ const fact = guardLinearFact(this.decls, generic, { name: 'unwritten count prefix', kind: 'ordinary-unwritten-count', when, terms }, Math.min(until, clock() + countPrimitiveUnits(60, this.options.leafUnits)), undefined, this.search, this.options);
77
+ if (!fact) {
78
+ this.stats.refusals++;
79
+ return;
80
+ }
81
+ cut = fact.cut;
82
+ this.cache.set(cacheKey, cut);
83
+ }
84
+ const renames = new Map(names.map((name, i) => [prefix + 'r' + i, name]));
85
+ renames.set(generic[0][0], post);
86
+ renames.set(generic[1][0], pre);
87
+ if (clock() >= until)
88
+ return;
89
+ const renamed = countCertificateRenamer(renames, until).certificate({ reads: generic, insts: [], picks: [], lins: [cut], tree: { leaf: [] } }).lins[0];
90
+ const counts = countsForReads(this.decls, this.reads);
91
+ if (!counts || !this.options.deferCheck && !linOk(counts, renamed)) {
92
+ this.stats.refusals++;
93
+ return;
94
+ }
95
+ return renamed;
96
+ }
97
+ }
@@ -0,0 +1,15 @@
1
+ import { type Machine } from './machine.js';
2
+ import { type CountGuardShape } from './count-guard-shape.js';
3
+ export type CountThresholdWrite = {
4
+ source: string;
5
+ guard: string;
6
+ increment: 0 | 1;
7
+ input: string;
8
+ inputCount: string;
9
+ committedInput?: string;
10
+ committedCount?: string;
11
+ };
12
+ export declare function discoverCountThresholdWrite(m: Machine, shape: CountGuardShape, choice: {
13
+ name: string;
14
+ value: number;
15
+ }): CountThresholdWrite | undefined;
@@ -0,0 +1,73 @@
1
+ // Untrusted structural discovery for a threshold write at its source row.
2
+ // No operation, field, law, or protocol name is built in.
3
+ import { walkOnce } from "./machine.js";
4
+ const atoms = (c) => c.op === 'and' ? c.xs.flatMap(atoms) : [c];
5
+ const fields = (value) => { const out = new Set(); walkOnce(value, (node) => { if (node.op === 'get')
6
+ out.add(node.map); }); return out; };
7
+ export function discoverCountThresholdWrite(m, shape, choice) {
8
+ const write = m.step.maps?.[shape.thresholdField];
9
+ if (!write || !('each' in write))
10
+ return;
11
+ const inputCount = (input) => Object.entries(m.counts ?? {}).filter(([, count]) => {
12
+ const maps = fields(count.body);
13
+ return !count.base && count.body.op === 'if' && count.body.then.op === 'const' && count.body.then.value === 1 && count.body.else.op === 'const' && count.body.else.value === 0 && maps.size === 1 && maps.has(input);
14
+ }).map(([name]) => name);
15
+ const candidates = [];
16
+ walkOnce(write.value, (node) => {
17
+ if (node.op !== 'if')
18
+ return;
19
+ let value = node.then, increment = 0;
20
+ if (value.op === 'add') {
21
+ const [a, b] = value.a.op === 'const' ? [value.b, value.a] : [value.a, value.b];
22
+ if (b.op !== 'const' || b.value !== 1)
23
+ return;
24
+ value = a;
25
+ increment = 1;
26
+ }
27
+ if (value.op !== 'get' || value.map !== shape.memberField || value.key.op !== 'var' || !m.inputs.includes(value.key.name))
28
+ return;
29
+ const source = value.key.name, gate = atoms(node.c);
30
+ if (!gate.some(c => c.op === '=' && ((c.a.op === 'var' && c.a.name === write.each && c.b.op === 'var' && c.b.name === source) || (c.b.op === 'var' && c.b.name === write.each && c.a.op === 'var' && c.a.name === source))))
31
+ return;
32
+ for (const c of gate) {
33
+ if (c.op !== 'flag')
34
+ continue;
35
+ const active = m.step.flags?.[c.name];
36
+ if (!active || active.op === 'all' || !atoms(active).some(a => {
37
+ if (a.op !== '=')
38
+ return false;
39
+ const [v, n] = a.a.op === 'var' ? [a.a, a.b] : [a.b, a.a];
40
+ return v.op === 'var' && v.name === choice.name && n.op === 'const' && n.value === choice.value;
41
+ }))
42
+ continue;
43
+ const direct = [...fields(active)].filter(map => m.inputMaps?.includes(map));
44
+ if (direct.length !== 1)
45
+ continue;
46
+ const input = direct[0], ownCounts = inputCount(input);
47
+ if (ownCounts.length !== 1)
48
+ continue;
49
+ const all = new Set(fields(active)), seen = new Set();
50
+ const expand = (value) => walkOnce(value, (node) => {
51
+ if (node.op !== 'flag' || seen.has(node.name))
52
+ return;
53
+ seen.add(node.name);
54
+ const flag = m.step.flags?.[node.name];
55
+ if (flag) {
56
+ for (const field of fields(flag))
57
+ all.add(field);
58
+ expand(flag);
59
+ }
60
+ });
61
+ expand(active);
62
+ const other = [...all].filter(map => map !== input && m.inputMaps?.includes(map));
63
+ if (other.length > 1)
64
+ continue;
65
+ const committedInput = other[0], committed = committedInput ? inputCount(committedInput) : [];
66
+ if (committedInput && committed.length !== 1)
67
+ continue;
68
+ candidates.push({ source, guard: c.name, increment, input, inputCount: ownCounts[0], ...(committedInput ? { committedInput, committedCount: committed[0] } : {}) });
69
+ }
70
+ });
71
+ const unique = [...new Map(candidates.map(value => [JSON.stringify(value), value])).values()];
72
+ return unique.length === 1 ? unique[0] : undefined;
73
+ }
@@ -0,0 +1,12 @@
1
+ import type { Law, Machine } from './machine.js';
2
+ import { type Counted } from './counts.js';
3
+ export type CountedSeedResult = {
4
+ status: 'checked';
5
+ closure: Counted;
6
+ kept: Law[];
7
+ dropped: Law[];
8
+ } | {
9
+ status: 'inconclusive';
10
+ reason: string;
11
+ };
12
+ export declare function proveCountedCandidateSeeds(machine: Machine, publicLaws: Law[], candidates: Law[], ms: number): CountedSeedResult;
@@ -0,0 +1,31 @@
1
+ import { admitCountedFamily } from "./counts.js";
2
+ import { searchWall } from "./wall.js";
3
+ import { checkCountedLaws } from "../kernel/kernel.js";
4
+ import { clock, counted, fullRate, withDeadline, withWall } from "../kernel/prove.js";
5
+ // The machine is the producer with conservative derived count declarations;
6
+ // the caller retains the unchanged source separately for source projection.
7
+ // Only public laws are admission targets. Every returned law is checked again
8
+ // as one family; no unverified proposal is published as a given.
9
+ export function proveCountedCandidateSeeds(machine, publicLaws, candidates, ms) {
10
+ if (!Number.isFinite(ms) || ms <= 0)
11
+ return { status: 'inconclusive', reason: 'invalid budget' };
12
+ const family = [...publicLaws, ...candidates], names = new Set(family.map(l => l.name));
13
+ if (names.size !== family.length || family.some(l => !l.name))
14
+ return { status: 'inconclusive', reason: 'duplicate or empty law name' };
15
+ try {
16
+ return withWall(searchWall(ms), () => counted(fullRate, () => {
17
+ const until = clock() + ms;
18
+ return withDeadline(until, () => {
19
+ const closure = admitCountedFamily(machine, publicLaws, family, new Set(candidates), until);
20
+ if (!closure.proven || !closure.proof)
21
+ return { status: 'inconclusive', reason: closure.why ?? 'counted family not proven' };
22
+ if (closure.m !== machine || !publicLaws.every(l => closure.laws.includes(l)) || closure.laws.some(l => !family.includes(l)) || !checkCountedLaws(closure.m, closure.laws, closure.proof))
23
+ return { status: 'inconclusive', reason: 'counted family custody or kernel check failed' };
24
+ return { status: 'checked', closure, kept: candidates.filter(l => closure.laws.includes(l)), dropped: candidates.filter(l => !closure.laws.includes(l)) };
25
+ });
26
+ }, true));
27
+ }
28
+ catch (error) {
29
+ return { status: 'inconclusive', reason: error instanceof Error ? error.message : String(error) };
30
+ }
31
+ }
@@ -1,7 +1,12 @@
1
1
  import { type C, type E, type Law, type Machine } from './machine.js';
2
- import { type CountCert, type CountInst, type Instances, type MapRead } from '../kernel/kernel.js';
2
+ import { type CountInst, type MapRead } from '../kernel/kernel.js';
3
3
  import { inferLaws } from './infer.js';
4
4
  export { attemptShare, supportBudget } from './support-budget.js';
5
+ import { type CountFamilyProof, type CountLawProof, type ScopedCountProof } from './count-proof-scope.js';
6
+ import { type LiftedWorkBudget } from './count-lifted-budget.js';
7
+ import { type CountRecipeClosingEntry } from './count-recipe-controller.js';
8
+ import { type CountTierBudget } from './count-tier-budget.js';
9
+ import { type CountClosingBudget } from './count-closing-budget.js';
5
10
  export declare const cprof: Record<string, number>;
6
11
  export declare const countsDump: {
7
12
  on?: (goal: object) => void;
@@ -25,12 +30,14 @@ export declare function certFor(goal: {
25
30
  picks: [string, E[]][];
26
31
  loose: boolean;
27
32
  };
28
- export declare function candidates(src: Parameters<typeof inferLaws>[0], m: Machine, caller: Law[], shapes: Law[], guarded: Law[], ms: number, until: number, support?: Set<Law>): Law[];
33
+ export declare function candidates(src: Parameters<typeof inferLaws>[0], m: Machine, caller: Law[], shapes: Law[], guarded: Law[], ms: number, until: number, support?: Set<Law>, publish?: (laws: Law[]) => void): Law[];
29
34
  export type Tried<P> = {
30
35
  proof: P;
31
36
  } | {
32
37
  stuck: string;
33
38
  refuted?: boolean;
39
+ expired?: boolean;
40
+ reason?: string;
34
41
  };
35
42
  export declare function withDeferredCountRecovery<P>(until: number, attempt: (defer: (recover: () => P | undefined) => void) => Tried<P>, ready?: () => boolean): Tried<P>;
36
43
  export declare function cone<P>(m: Machine, set: Law[], attempt: (law: Law, ls: Law[], ms: number) => Tried<P>, until: number, houdini?: boolean): Map<string, P>;
@@ -39,24 +46,41 @@ export declare function countSupportContext(m: Machine, caller: Law[], set: Law[
39
46
  laws: Law[];
40
47
  support: Set<Law>;
41
48
  };
42
- export declare function supportOrder(set: Law[], caller: Law[], support: Set<Law>, forModels?: boolean): Law[];
49
+ export declare function supportOrder(set: Law[], caller: Law[], support: Set<Law>, forModels?: boolean, m?: Machine): Law[];
43
50
  export type Counted = {
44
51
  proven: boolean;
45
52
  laws: Law[];
46
53
  m: Machine;
47
- proof?: {
48
- instances: Record<string, Instances>;
49
- certs: Record<string, CountCert>;
50
- };
54
+ proof?: CountFamilyProof;
51
55
  why?: string;
52
56
  };
57
+ export type CountedRecipeClosingSnapshot = Readonly<{
58
+ version: 'counted-recipe-closing/v1';
59
+ controller: CountRecipeClosingEntry<ScopedCountProof>;
60
+ m: Machine;
61
+ set: Law[];
62
+ caller: Law[];
63
+ initial: Law[];
64
+ selected: ReadonlySet<Law>;
65
+ structured: boolean;
66
+ closingBudget: CountClosingBudget | undefined;
67
+ until: number;
68
+ workAllowance: number;
69
+ scopeEnabled: boolean;
70
+ active: ReadonlySet<string>;
71
+ reachAbsent: boolean;
72
+ transportDeclined: string | undefined;
73
+ }>;
74
+ export declare const countRecipeClosingCapture: {
75
+ on?: (snapshot: CountedRecipeClosingSnapshot) => void;
76
+ };
53
77
  export declare function searchCounted(m0: Machine, caller: Law[], ms?: number): Counted;
54
- export declare function admitCountedFamily(m: Machine, caller: Law[], initial: Law[], support: Set<Law>, until: number): Counted;
55
- export declare function countedAttempts(m: Machine, caller: Law[], support: Set<Law>, until: number, structured?: boolean): {
56
- traced: (law: Law, ls: Law[], pass: 0 | 1, ms: number) => Tried<{
57
- instances: Instances;
58
- certs: Record<string, CountCert>;
59
- }>;
78
+ export declare function admitCountedFamily(m: Machine, caller: Law[], initial: Law[], support: Set<Law>, until: number, tiers?: CountTierBudget): Counted;
79
+ export declare function countedAttempts(m: Machine, caller: Law[], support: Set<Law>, until: number, structured?: boolean, focusedOrStrategies?: boolean | ReadonlySet<Law>, budgetOrWork?: CountTierBudget | number, tierBudget?: CountTierBudget, shapeFamily?: readonly Law[]): {
80
+ traced: (law: Law, ls: Law[], pass: 0 | 1, ms: number, strategyAllowed?: boolean) => Tried<CountLawProof>;
81
+ exactStrategy: (law: Law, ls: Law[], plan: LiftedWorkBudget) => import("./count-strategy.ts").CountStrategyProof | undefined;
82
+ strategyProposal: (law: Law, ls: Law[], kind: "row" | "guard") => import("./count-strategy.ts").CountStrategyProof | undefined;
83
+ countermodel: (law: Law) => Record<string, number> | undefined;
60
84
  readonly counted: boolean;
61
85
  houdini: boolean;
62
86
  };