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
@@ -1,14 +1,17 @@
1
1
  import { atMost, n, not, pointWrite } from "../core/machine.js";
2
2
  import { add, k, scale, sub } from "../core/solver.js";
3
- import { lemmaPath, checkCounted, checkCountedLaws, countedGoal, countedObligations, countHyps, mcGoal, postName, boundOf, caseGoals, cellParts, check, checkRecur, checkRecurCases, coverGoal, recurGoal, canon, decided, factorsOf, isCell, isMonomial, columnTerm, stateName, termColumn, truth, historyMachine, sumMachine, sumCovers, sumParts, foldObligations, kInductionStart, kInductionSteps, leafConstraints, loopLiveness, loopMachine, linear, livenessHelpful, livenessParts, livenessLevels, livenessRanks, strongly, loopObligations, trueC, obligations, progressObligations, stepLawObligations, substC, witnessesOf, withProducts } from "../kernel/kernel.js";
3
+ import { framePath, lemmaPath, checkMC, checkCounted, checkCountedLaws, checkLaws, countedGoal, countedObligations, countHyps, mcGoal, postName, boundOf, caseGoals, cellParts, check, checkRecur, checkRecurCases, coverGoal, recurGoal, canon, decided, factorsOf, isCell, isMonomial, columnTerm, stateName, termColumn, truth, historyMachine, sumMachine, sumCovers, sumParts, foldObligations, kInductionStart, kInductionSteps, leafConstraints, loopLiveness, loopMachine, linear, livenessHelpful, livenessParts, livenessLevels, livenessRanks, strongly, loopObligations, trueC, obligations, progressObligations, stepLawObligations, substC, witnessesOf, withProducts } from "../kernel/kernel.js";
4
4
  import { chooseLevels, clock, grow, minimal, proveBuilt, proveLaws, proveSetFast, proveStepLaws, withDeadline } from "../kernel/prove.js";
5
5
  import { refinement, refinementSides } from "../core/compose.js";
6
6
  import { exactNat, leanConnective, leanSurface, leanTerms } from "./lean-terms.js";
7
7
  import { descentGoal, mainGoal, premiseGoal } from "../kernel/cyclic.js";
8
8
  import { allowNode, certMs, closingInsts, reqTS, withWitness, foldNodes, certMode, quietly, uncoveredWhy, hasQuantified, kWhens, machineNodes, proveCyclic, routeOf, searchedStepNodes, skMachine, stepLawNodes, tBack, tSub } from "../core/cyclic.js";
9
9
  import { leanLibrary } from "./library.js";
10
+ import { legacyFamilyLibrary } from "./legacy-family-library.js";
11
+ import { legacyFamilyOrder } from "./legacy-family-order.js";
10
12
  import { proveKInduction } from "../core/kind.js";
11
13
  import { quantifiedRenames } from "./qalpha.js";
14
+ import { countsForReads } from "../core/count-facts.js";
12
15
  export { leanLibrary };
13
16
  // --- to Lean ------------------------------------------------------------------------------------------------------------
14
17
  const varsOf = (c) => [...JSON.stringify(c).matchAll(/"op":"var","name":"([^"]+)"/g)].map(m => m[1]);
@@ -120,7 +123,7 @@ export function encode(ex, tamper = false, dropStep = true, globalVars, globalMa
120
123
  // Each leaf with its path and rows, found once (the passes below and the tree's text read them in the same order).
121
124
  const leafList = [];
122
125
  leaves(tree, context.path ?? new Map(), (leaf, path) => {
123
- const visible = lemmaPath(context.lemmas ?? [], path);
126
+ const visible = context.frames?.length || context.monos?.length || context.lins?.length ? framePath(context.frames ?? [], context.lemmas ?? [], path, context.monos, context.lins) : lemmaPath(context.lemmas ?? [], path);
124
127
  leafList.push({ leaf, path: visible, base: leafConstraints(goal, visible) });
125
128
  });
126
129
  const reads = new Set(), hintTerms = new Set();
@@ -138,11 +141,11 @@ export function encode(ex, tamper = false, dropStep = true, globalVars, globalMa
138
141
  hintTerms.add(src.term);
139
142
  }
140
143
  }
141
- const readHyps = whole ? goal.hyps : goal.hyps.filter((_, i) => reads.has(i));
144
+ const readHyps = [...(whole ? goal.hyps : goal.hyps.filter((_, i) => reads.has(i))), ...(context.monos ?? []).flatMap(m => m.when), ...(context.lins ?? []).flatMap(l => l.when)];
142
145
  const readTerms = whole ? [] : [...hintTerms].map(name => columnTerm(name));
143
146
  // Columns: every variable of the hypotheses, then every cell any leaf uses (and the cells inside their keys),
144
147
  // shallower cells first so a key reads only earlier columns.
145
- const vars = globalVars ?? [...new Set(goal.hyps.flatMap(varsOf))];
148
+ const vars = globalVars ?? [...new Set([...goal.hyps.flatMap(varsOf), ...lemmaNames([], context.frames, context.monos, context.lins).vars])];
146
149
  const cells = new Set(), terms = new Set();
147
150
  // Monomials: every one a leaf's rows or products use, or that a product term has under the leaf's path, with the
148
151
  // cells among their factors.
@@ -228,6 +231,17 @@ export function encode(ex, tamper = false, dropStep = true, globalVars, globalMa
228
231
  addCell(key);
229
232
  }
230
233
  }
234
+ // Conditions can name columns a certificate never uses at a leaf; they still need encoding.
235
+ for (const f of context.frames ?? [])
236
+ for (const r of f.when)
237
+ for (const key of Object.keys(r)) {
238
+ if (isMonomial(key))
239
+ addMono(key);
240
+ else if (isCell(key))
241
+ addCell(key);
242
+ else if (key.startsWith('⟦'))
243
+ terms.add(key);
244
+ }
231
245
  const depth = (name) => name.split('[').length;
232
246
  // Term columns (open choices, each standing for its term's value) before the cells, whose keys may read them; a
233
247
  // monomial with a cell among its factors after the cells.
@@ -330,7 +344,7 @@ export function encode(ex, tamper = false, dropStep = true, globalVars, globalMa
330
344
  if (!src)
331
345
  return '.any';
332
346
  if ('atom' in src)
333
- return context.path || context.lemmas?.length ? '.any' : `.atom ${path.size - 1 - src.atom}`; // Lean's path has the latest decision first
347
+ return context.path || context.lemmas?.length || context.frames?.length || context.monos?.length || context.lins?.length ? '.any' : `.atom ${path.size - 1 - src.atom}`; // Lean's path has the latest decision first
334
348
  if ('fact' in src)
335
349
  return `.fact ${src.fact}`;
336
350
  const j = 'pair' in src ? pairs.indexOf([...src.pair].sort().join('\n')) : col.get('nat' in src ? src.nat : src.term) ?? -1;
@@ -368,7 +382,7 @@ theorem ${name} : ∀ env maps, ¬ ∀ c ∈ ${name}_goal.hyps, evalC env maps c
368
382
  const varsOfE = (t) => [...JSON.stringify(t).matchAll(/"op":"var","name":"([^"]+)"/g)].map(m => m[1]);
369
383
  const mapsOf = (t) => [...JSON.stringify(t).matchAll(/"op":"get","map":"([^"]+)"/g)].map(m => m[1]);
370
384
  // Extra row names may appear only in a lemma. Resolve their column dependencies with the same rules as encode.
371
- function lemmaNames(lemmas) {
385
+ function lemmaNames(lemmas, frames = [], monos = [], lins = []) {
372
386
  const vars = new Set(), maps = new Set(), seen = new Set();
373
387
  const name = (s) => {
374
388
  if (s === '1' || seen.has(s))
@@ -406,6 +420,24 @@ function lemmaNames(lemmas) {
406
420
  row(l.cut);
407
421
  tree(l.tree);
408
422
  }
423
+ for (const f of frames) {
424
+ f.when.forEach(row);
425
+ name(f.post);
426
+ name(f.pre);
427
+ }
428
+ for (const m of monos) {
429
+ m.when.flatMap(varsOf).forEach(name);
430
+ m.when.flatMap(mapsOf).forEach(v => maps.add(v));
431
+ name(m.post);
432
+ name(m.pre);
433
+ tree(m.tree);
434
+ }
435
+ for (const l of lins) {
436
+ l.when.flatMap(varsOf).forEach(name);
437
+ l.when.flatMap(mapsOf).forEach(v => maps.add(v));
438
+ [...l.pos, ...l.neg].forEach(([, v]) => name(v));
439
+ tree(l.tree);
440
+ }
409
441
  return { vars: [...vars], maps: [...maps] };
410
442
  }
411
443
  // Every independent proof uses one common table, but its own exact slice and initial path. Two passes establish
@@ -427,7 +459,7 @@ export function encodeCounted(id, goal, cert, vars, maps) {
427
459
  return { ex: { name: `${id}: lemma ${i}`, goal: { ...goal, hyps: selected }, tree: l.tree }, path };
428
460
  });
429
461
  const main = { name: id, goal, tree: cert.tree };
430
- const first = encode(main, false, true, vars, maps, false, false, { lemmas: ls });
462
+ const first = encode(main, false, true, vars, maps, false, false, { lemmas: ls, frames: cert.frames, monos: cert.monos, lins: cert.lins });
431
463
  if (!ls.length)
432
464
  return { ...first, lemmas: '[]', lemmaList: (entries) => {
433
465
  if (entries.length)
@@ -436,7 +468,7 @@ export function encodeCounted(id, goal, cert, vars, maps) {
436
468
  } };
437
469
  const initial = sources.map(s => encode(s.ex, false, true, vars, maps, false, false, { path: s.path }));
438
470
  const cols = [...new Set([first, ...initial].flatMap(e => e.cols))];
439
- const base = encode(main, false, true, vars, maps, false, false, { lemmas: ls, cols });
471
+ const base = encode(main, false, true, vars, maps, false, false, { lemmas: ls, frames: cert.frames, monos: cert.monos, lins: cert.lins, cols });
440
472
  const proofs = sources.map(s => encode(s.ex, false, true, vars, maps, false, false, { path: s.path, cols }));
441
473
  const lemmaList = (entries) => list(entries.map((l, i) => {
442
474
  const source = sources[i];
@@ -448,6 +480,71 @@ export function encodeCounted(id, goal, cert, vars, maps) {
448
480
  }));
449
481
  return { ...base, lemmas: lemmaList(ls), lemmaList };
450
482
  }
483
+ // The three cut lists of one counted certificate as Lean literals: frames over the certificate's own row encoder, per-key
484
+ // monotone and linear cuts each with the table and tree of its own auxiliary goal. One code path for the single-goal
485
+ // export (mcToLean) and the family export (cmachineToLean).
486
+ function cutLits(id, cert, decls, enc, vars, maps, c, ix) {
487
+ const frames = list((cert.frames ?? []).map(f => `⟨${list(f.when.map(enc.row))}, ${ix(f.post)}, ${ix(f.pre)}⟩`));
488
+ const counts = countsForReads(decls, cert.reads);
489
+ if (!counts)
490
+ throw new Error(`${id}: invalid count reads`);
491
+ const monos = list((cert.monos ?? []).map((m, i) => {
492
+ const post = counts.find(c => c.v === m.post), pre = counts.find(c => c.v === m.pre);
493
+ const auxiliary = { name: `${id}: per-key cut ${i}`, hyps: [...m.when,
494
+ { op: '<', a: { op: 'var', name: post.key }, b: post.below }, { op: '<', a: pre.body, b: post.body }] };
495
+ const proof = encode({ name: auxiliary.name, goal: auxiliary, tree: m.tree }, false, true, vars, maps);
496
+ return `⟨${list(m.when.map(c))}, ${ix(m.post)}, ${ix(m.pre)}, ${proof.tab}, ${proof.tree}⟩`;
497
+ }));
498
+ const lins = list((cert.lins ?? []).map((l, i) => {
499
+ const first = counts.find(c => c.v === [...l.pos, ...l.neg][0][1]);
500
+ const term = (side) => side.reduceRight((rest, [k, v]) => ({ op: 'add', a: { op: 'mul', k, a: counts.find(c => c.v === v).body }, b: rest }), { op: 'const', value: 0 });
501
+ const auxiliary = { name: `${id}: linear cut ${i}`, hyps: [...l.when,
502
+ { op: '<', a: { op: 'var', name: first.key }, b: first.below }, { op: '<', a: term(l.neg), b: term(l.pos) }] };
503
+ const proof = encode({ name: auxiliary.name, goal: auxiliary, tree: l.tree }, false, true, vars, maps);
504
+ const side = (xs) => list(xs.map(([k, v]) => `(${k}, ${ix(v)})`));
505
+ return `⟨${list(l.when.map(c))}, ${side(l.pos)}, ${side(l.neg)}, ${proof.tab}, ${proof.tree}⟩`;
506
+ }));
507
+ return { frames, monos, lins };
508
+ }
509
+ // A single counted obligation, including conditional frames. This is a conditional
510
+ // goal theorem through mcF_sound, not a claim that the source machine's INIT or
511
+ // its other operation goals have been proved.
512
+ export function mcToLean(id, hyps, decls, cert) {
513
+ if (!checkMC(hyps, decls, cert))
514
+ throw new Error(`${id}: counted certificate does not check`);
515
+ const goal = mcGoal(hyps, decls, cert);
516
+ const extra = lemmaNames(cert.lemmas ?? [], cert.frames, cert.monos, cert.lins);
517
+ const vars = [...new Set([...extra.vars, ...goal.hyps.flatMap(varsOf),
518
+ ...decls.flatMap(d => [d.j, d.lo ?? d.j, d.key, ...varsOfE(d.below), ...varsOfE(d.body)]),
519
+ ...cert.reads.flatMap(r => [r[0], ...varsOfE(r[2])]),
520
+ ...cert.insts.flatMap(i => [i.wit, ...varsOfE(i.below)]),
521
+ ...(cert.picks ?? []).flatMap(([v, ks]) => [v, ...ks.flatMap(varsOfE)])])];
522
+ const maps = [...new Set([...extra.maps, ...goal.hyps.flatMap(mapsOf), ...decls.flatMap(d => [d.map, ...mapsOf(d.below), ...mapsOf(d.body)])])];
523
+ const enc = encodeCounted(id, goal, cert, vars, maps), { e, c } = enc;
524
+ const ix = (name) => { const i = vars.indexOf(name); if (i < 0)
525
+ throw new Error(`${id}: unknown variable ${name}`); return i; };
526
+ const mx = (name) => maps.indexOf(name);
527
+ const { frames, monos, lins } = cutLits(id, cert, decls, enc, vars, maps, c, ix);
528
+ const linRef = cert.lins?.length ? `${id}_lins` : '[]';
529
+ const linDefinition = cert.lins?.length ? `def ${id}_lins : List LinCut := ${lins}\n` : '';
530
+ const monoRef = cert.monos?.length ? `${id}_monos` : '[]';
531
+ const monoDefinition = cert.monos?.length ? `def ${id}_monos : List MonoCut := ${monos}\n` : '';
532
+ return `-- Goal-local counted certificate; no whole-machine reachability claim.
533
+ def ${id}_hyps : List C := ${list(hyps.map(c))}
534
+ -- CDecl.post is unused by checkMCF/GHolds; this packet already contains PRE/POST declarations.
535
+ def ${id}_decls : List CDecl := ${list(decls.map(d => `⟨${mx(d.map)}, ${mx(d.map)}, ${ix(d.j)}, ${ix(d.key)}, ${e(d.below)}, ${e(d.body)}, ${ix(d.lo ?? d.j)}, ${d.base ?? 0}⟩`))}
536
+ def ${id}_cert : CCert := ⟨${id}_hyps,
537
+ ${list(cert.reads.map(r => `(${ix(r[0])}, ${mx(r[1])}, ${e(r[2])})`))},
538
+ ${list(cert.insts.map(i => `⟨${ix(i.wit)}, ${e(i.below)}, ${list(i.terms.map(([z, v]) => `(${int(z)}, ${ix(v)})`))}, ${int(i.unit)}⟩`))},
539
+ ${enc.tab}, ${enc.tree},
540
+ ${list((cert.picks ?? []).map(([v, ks]) => `(${ix(v)}, ${list(ks.map(e))})`))}, ${enc.lemmas}⟩
541
+ def ${id}_frames : List FrameCut := ${frames}
542
+ ${monoDefinition}${linDefinition}theorem ${id}_check : checkMCF ${id}_hyps ${id}_decls ${id}_cert ${id}_frames ${monoRef}${cert.lins?.length ? ` ${linRef}` : ''} = true := by ${checkBy}
543
+ theorem ${id} (ρ : Nat → Nat) (M : Nat → Nat → Nat) (hd : GHolds ${id}_decls ρ M)
544
+ (hH : ∀ ρw : Nat → Nat, (∀ j, (∀ i ∈ ${id}_cert.insts, i.wit ≠ j) → ρw j = ρ j) →
545
+ ∀ h ∈ ${id}_hyps, evalC ρw M h = true) : False :=
546
+ mcF_sound ${id}_hyps ${id}_decls ${id}_cert ${id}_frames ${monoRef} ${linRef} ${id}_check ρ M hd hH`;
547
+ }
451
548
  export function countedToLean(id, g, cert, tampered = []) {
452
549
  const goal = countedGoal(g, cert.insts);
453
550
  if (!goal)
@@ -479,12 +576,12 @@ example : checkCounted ${id}_goal ${instsLit(t.insts)} ${id}_tab ${id}_tree ${id
479
576
  // each certificate names the kernel's goal's hypotheses (each one Lean builds), the cells it reads, Count.lean's
480
577
  // instances and the tree. The count maps go to Lean as maps the request carries, each with its post name. `tampers`:
481
578
  // certificates kernel.ts refuses, which Lean computes to false.
482
- export function cmachineToLean(id, m, laws, proof, tampers = []) {
579
+ export function cmachineToLean(id, m, laws, proof, tampers = [], options = {}) {
483
580
  const obl = countedObligations(m, laws, proof.instances), counts = Object.entries(m.counts ?? {});
484
581
  const sm = { ...m, counts: undefined, inputMaps: [...(m.inputMaps ?? []), ...counts.map(([cn]) => cn)] };
485
582
  const named = machineNames(sm, laws, [], [], {});
486
583
  const allCerts = [proof.certs, ...tampers.map(t => t.certs)];
487
- const extra = allCerts.flatMap(cs => Object.values(cs).map(k => lemmaNames(k.lemmas ?? [])));
584
+ const extra = allCerts.flatMap(cs => Object.values(cs).map(k => lemmaNames(k.lemmas ?? [], k.frames, k.monos, k.lins)));
488
585
  const goals = obl.map(o => { const g = mcGoal(o.goal.hyps, o.decls, proof.certs[o.goal.name]); if (!g)
489
586
  throw new Error(`${id}: ${o.goal.name}: a read of no count`); return g; });
490
587
  const certVars = allCerts.flatMap(cs => Object.values(cs).flatMap(k => [...k.reads.flatMap(r => [r[0], ...varsOfE(r[2])]), ...k.insts.flatMap(i => [i.wit, ...varsOfE(i.below)]), ...(k.picks ?? []).flatMap(([v2, ks]) => [v2, ...ks.flatMap(varsOfE)])]));
@@ -496,12 +593,20 @@ export function cmachineToLean(id, m, laws, proof, tampers = []) {
496
593
  // checker alpha-renames colliding local binders; QAlpha proves its original semantics.
497
594
  const renames = quantifiedRenames(sm, laws, [...vars, ...maps]);
498
595
  vars.push(...renames.map(r => r.fresh));
596
+ for (const v of options.extraVars ?? [])
597
+ if (!vars.includes(v))
598
+ vars.push(v);
599
+ for (const map of options.extraMaps ?? [])
600
+ if (!maps.includes(map))
601
+ maps.push(map);
499
602
  const checked = renames.length ? `${id}_checkedMachine` : `${id}_machine`;
500
603
  const { e, c } = leanTerms(vars, maps, id);
501
604
  const ix = (name) => { const j = vars.indexOf(name); if (j < 0)
502
605
  throw new Error(`${id}: no variable for ${name}`); return j; };
503
606
  const mx = (name) => { const j = maps.indexOf(name); if (j < 0)
504
607
  throw new Error(`${id}: no map for ${name}`); return j; };
608
+ const decls = (ds) => list(Object.entries(ds ?? {}).map(([cn, d]) => `⟨${mx(cn)}, ${mx(postName(cn))}, ${ix(d.j)}, ${ix(d.key)}, ${e(d.below)}, ${e(d.body)}, ${ix(d.lo ?? d.j)}, ${d.base ?? 0}⟩`));
609
+ const after = options.after?.({ vars, maps, ix, mx, machine: mm => machineLit(mm, { e, c }, ix, mx), condition: c, decls }) ?? '';
505
610
  const lawIx = (name) => laws.findIndex(l => l.name === name);
506
611
  const facts = m.facts ?? [], facts1 = facts.filter(f => !f.keys?.length), factsN = facts.filter(f => f.keys?.length);
507
612
  const tuples = (keys, n2) => Array.from({ length: Math.floor(keys.length / n2) }, (_, t) => keys.slice(t * n2, t * n2 + n2));
@@ -531,12 +636,29 @@ export function cmachineToLean(id, m, laws, proof, tampers = []) {
531
636
  ${list((k.picks ?? []).map(([v2, ks]) => `(${ix(v2)}, ${list(ks.map(e))})`))},
532
637
  ${tt.lemmaList(k.lemmas ?? [])}⟩`;
533
638
  };
639
+ // A certificate's cuts, encoded against the same table as its tree (a tampered certificate keeps the cuts of the one
640
+ // it tampers with, as it keeps its table and tree). Emitted only when some certificate of this export has a cut: an
641
+ // export without cuts is the text it was before.
642
+ const hasCuts = (k) => !!(k.frames?.length || k.monos?.length || k.lins?.length);
643
+ const withAux = allCerts.some(cs => Object.values(cs).some(hasCuts));
644
+ const auxLit = (name, certs) => {
645
+ const o = obl.find(o2 => o2.goal.name === name), k = certs[name], k0 = proof.certs[name];
646
+ if (!hasCuts(k) && !hasCuts(k0))
647
+ return '⟨[], [], []⟩';
648
+ // The table is the original certificate's (as for its tree); the cuts are this certificate's own, so a tamper
649
+ // that drops or alters a cut is exported as altered and Lean computes the check without it.
650
+ const tt = encodeCounted(`${id}: ${name}`, mcGoal(o.goal.hyps, o.decls, k0), k0, vars, maps);
651
+ const cuts = cutLits(`${id}: ${name}`, { ...k0, frames: k.frames, monos: k.monos, lins: k.lins }, o.decls, tt, vars, maps, c, ix);
652
+ return `⟨${cuts.frames}, ${cuts.monos}, ${cuts.lins}⟩`;
653
+ };
534
654
  const entries = (certs) => laws.map(law => {
535
655
  const inst = proof.instances[law.name] ?? {};
536
656
  return `⟨⟨⟨${c(law.holds)}, ${law.forall ? `some ${ix(law.forall)}` : 'none'}⟩, ${ix(law.forall ? `${law.forall}#` : '#')}, ${list((law.keys ?? []).map(key => String(ix(key))))}, ${list(insts(inst))}, ${list(qinsts(inst))}, ${list(finsts(inst))}, ${list(pinsts(inst))}, ${list(pfinsts(inst))},
537
657
  ([], [], .leaf [] [] [] []), ([], [], .leaf [] [] [] [])⟩,
538
658
  ${certLit(`${law.name} @start`, certs)},
539
- ${certLit(`${law.name} @step`, certs)}⟩`;
659
+ ${certLit(`${law.name} @step`, certs)}${withAux ? `,
660
+ ${auxLit(`${law.name} @start`, certs)},
661
+ ${auxLit(`${law.name} @step`, certs)}` : ''}⟩`;
540
662
  });
541
663
  return `-- ${m.name}: ${laws.map(l => l.name).join('; ')}, with counts ${counts.map(([cn]) => cn).join(', ')}
542
664
  -- (variables ${vars.map((v2, j) => `${j} ${v2}`).join(', ')}; maps ${maps.map((v2, j) => `${j} ${v2}`).join(', ')})
@@ -545,13 +667,13 @@ def ${id}_machine : SMachine := ${machineLit(sm, { e, c }, ix, mx)}${renames.len
545
667
  def ${id}_renames : List QAlpha.Rename := ${list(renames.map(r => `⟨${ix(`?${r.flag}`)}, ${ix(r.old)}, ${ix(r.fresh)}⟩`))}
546
668
  def ${id}_checkedMachine : SMachine := QAlpha.renameAll ${id}_machine ${id}_renames` : ''}
547
669
  def ${id}_decls : List CDecl := ${list(counts.map(([cn, d]) => `⟨${mx(cn)}, ${mx(postName(cn))}, ${ix(d.j)}, ${ix(d.key)}, ${e(d.below)}, ${e(d.body)}, ${ix(d.lo ?? d.j)}, ${d.base ?? 0}⟩`))}
548
- def ${id}_proof : List CEntry := ${list(entries(proof.certs))}
549
- theorem ${id}_check : checkCMachine ${checked} ${id}_decls ${id}_proof = true := by ${checkBy}
670
+ ${withAux ? 'noncomputable ' : ''}def ${id}_proof : List ${withAux ? 'CEntryF' : 'CEntry'} := ${list(entries(proof.certs))}
671
+ theorem ${id}_check : ${withAux ? 'checkCMachineF' : 'checkCMachine'} ${checked} ${id}_decls ${id}_proof = true := by ${checkBy}
550
672
  /-- ${laws.map(l => l.name).join('; ')}: each holds in every reachable state, each count map read as the state's count. -/
551
673
  theorem ${id}_laws : ∀ ρ M, CReach ${id}_machine ${id}_decls ρ M → ∀ ce ∈ ${id}_proof, ce.e.Holds ρ (withCnt ${id}_decls ρ M) :=
552
- ${renames.length ? `QAlpha.cmachine_sound ${id}_machine ${id}_renames ${id}_decls ${id}_proof (by ${checkBy}) ${id}_check` : `cmachine_sound ${id}_machine ${id}_decls ${id}_proof ${id}_check`}${tampers.map(t => `
674
+ ${renames.length ? `QAlpha.${withAux ? 'cmachineF_sound' : 'cmachine_sound'} ${id}_machine ${id}_renames ${id}_decls ${id}_proof (by ${checkBy}) ${id}_check` : `${withAux ? 'cmachineF_sound' : 'cmachine_sound'} ${id}_machine ${id}_decls ${id}_proof ${id}_check`}${tampers.map(t => `
553
675
  -- TAMPERED: ${t.what}. Lean computes the check to false, as kernel.ts refuses it.
554
- example : checkCMachine ${checked} ${id}_decls ${list(entries(t.certs))} = false := by ${checkBy}`).join('')}`;
676
+ example : ${withAux ? 'checkCMachineF' : 'checkCMachine'} ${checked} ${id}_decls ${list(entries(t.certs))} = false := by ${checkBy}`).join('')}${after}`;
555
677
  }
556
678
  // Whole machines through Kern.machine_sound: Lean builds the goals from the machine; the trees are the kernel's.
557
679
  export function machineToLean(id, m, laws, corollary) {
@@ -947,10 +1069,15 @@ export function readable(id, laws, vars, maps, reach) {
947
1069
  throw new Error(`${id}: no variable for ${name}`); return i; };
948
1070
  const ws = ex.vars.map((_, i) => `w${i + 1}`), at = (env, vals) => `updAll ${env} [${ex.vars.map((n, i) => `(${ix(n)}, ${vals[i]})`).join(', ')}]`;
949
1071
  const P = `(${lit(ex.body)})`, key = law.forall ? ix(law.forall) : undefined;
950
- const sigma = ex.sub ? `[${ex.vars.map(n => `(${ix(n)}, ${eLit(ex.sub[n])})`).join(', ')}]` : '';
951
- const machine = ex.ghost ? `${id}_ghosted.orig` : `${id}_machine`;
1072
+ // A retained family may carry ex.ghost metadata without exporting the
1073
+ // original/ghosted pair. In that case its theorem is about this machine:
1074
+ // choose its current witness values, not a nonexistent _ghosted.orig.
1075
+ const throughGhosts = ex.ghost && reach.ghosts;
1076
+ const sub = ex.sub ?? (ex.ghost && !throughGhosts ? Object.fromEntries(ex.vars.map(n => [n, { op: 'var', name: n }])) : undefined);
1077
+ const sigma = sub ? `[${ex.vars.map(n => `(${ix(n)}, ${eLit(sub[n])})`).join(', ')}]` : '';
1078
+ const machine = throughGhosts ? `${id}_ghosted.orig` : `${id}_machine`;
952
1079
  const head = `theorem some${j} : ∀ ρ μ, SReach ${machine} ρ μ → ${key !== undefined ? '∀ k : Nat, ' : ''}∃ ${ws.join(' ')} : Nat, evalC (${at(key !== undefined ? `(upd ρ ${key} k)` : 'ρ', ws)}) μ ${P} = true`;
953
- const proof = ex.ghost
1080
+ const proof = throughGhosts
954
1081
  ? ` intro ρ μ h
955
1082
  obtain ⟨ρg, hg⟩ := some_of_ghost ${id}_ghosted ${id}_ghostOk [${ex.vars.map(ix).join(', ')}] ${P} (by ${checkBy}) (fun ρ μ h => by
956
1083
  ${haveOf(j)}
@@ -965,7 +1092,7 @@ export function readable(id, laws, vars, maps, reach) {
965
1092
  theorem law${j} ${reach.binders} (h : SReach ${machine} ρ μ) : ${statement(law)} := by
966
1093
  ${key !== undefined ? 'intro k\n ' : ''}obtain ⟨${ws.join(', ')}, hg⟩ := some${j} ρ μ h${key !== undefined ? ' k' : ''}
967
1094
  exact ⟨${ws.join(', ')}, (evalC_iff (${at(key !== undefined ? `(upd ρ ${key} k)` : 'ρ', ws)}) μ ${P}).mp hg⟩`;
968
- return `-- ${law.name}: there exists, proven ${ex.ghost ? 'through ghosts the machine carries' : 'with its witness terms in place'}
1095
+ return `-- ${law.name}: there exists, proven ${throughGhosts ? 'through ghosts the machine carries' : ex.ghost ? 'with current-machine witness values' : 'with its witness terms in place'}
969
1096
  ${head} := by
970
1097
  ${proof}
971
1098
  ${plain}`;
@@ -1080,8 +1207,11 @@ ${plain}`;
1080
1207
  return `namespace ${id}
1081
1208
  ${[...vars.filter(v => used.has(v)).map(v => `abbrev ${q(v)} : Nat := ${vars.indexOf(v)}`), ...maps.filter(mp => used.has(mp)).map(mp => `abbrev ${q(mp)} : Nat := ${maps.indexOf(mp)}`)].join('\n')}
1082
1209
  ${laws.map((law, j) => {
1083
- if (law.ex)
1210
+ if (law.ex) {
1211
+ if (reach.explicitExistentials?.has(law.name) && (law.keys?.length || (law.forall && law.ex.ghost)))
1212
+ return '-- Multi-key existential source theorem is emitted by the explicit ghost-substitution projection.';
1084
1213
  return someOf(law, j);
1214
+ }
1085
1215
  if (JSON.stringify(law.holds).includes('"op":"if"'))
1086
1216
  return `-- ${law.name}: its terms read an if, so no plain statement here (${id}_laws holds it)`;
1087
1217
  const hyps = arithBinders(law), names = arithIn(law).map(hypName);
@@ -1464,9 +1594,9 @@ theorem ${id}_some${j} : ∀ ρ M, SReach ${id}_gm.orig ρ M → ∀ v, ∃ val,
1464
1594
  throw new Error(`${id}: ${gs.law}: no such law`);
1465
1595
  const sigma = list(Object.entries(gs.sub).map(([x, t]) => `(${ix(x)}, ${e(t)})`));
1466
1596
  return `
1467
- /-- ${law.name}, read ∃: for every value of its keys, some natural for each of ${Object.keys(gs.sub).join(', ')} (at the ghosts' terms) where its body holds; no ghost read. -/
1597
+ /-- ${law.name}, read ∃: for every value of its keys, some natural for each of ${Object.keys(gs.sub).join(', ')} (at the ghosts' terms) where its body holds; no unbound ghost read. -/
1468
1598
  theorem ${id}_ex${j} : ∀ ρ M, SReach ${id}_gm.orig ρ M → ExHolds (${c(gs.body)}) ${id}_e${li}.law.key ${list(Object.keys(gs.sub).map(x => String(ix(x))))} M ${id}_e${li}.keys2 ρ :=
1469
- forall_some_of_ghostsubst ${id}_gm ${id}_gmOk ${id}_proof ${id}_check ${id}_e${li} (${memOf(li)}) ${sigma} (${c(gs.body)})
1599
+ ${gs.boundGhosts ? 'forall_some_of_ghostsubst_bound' : 'forall_some_of_ghostsubst'} ${id}_gm ${id}_gmOk ${id}_proof ${id}_check ${id}_e${li} (${memOf(li)}) ${sigma} (${c(gs.body)})
1470
1600
  (by ${checkBy}) (by ${checkBy}) (by ${checkBy})`;
1471
1601
  }).join('')}`;
1472
1602
  } });
@@ -1709,10 +1839,10 @@ def ${id}_proof : List SEntry := ${list(laws.map((_, j) => `${id}_e${j}`))}
1709
1839
  theorem ${id}_check : checkSMachine ${id}_machine ${id}_proof = true := by ${checkBy}
1710
1840
  theorem ${id}_laws : ∀ ρ M, SReach ${id}_machine ρ M → ∀ e ∈ ${id}_proof, e.Holds ρ M :=
1711
1841
  smachine_sound ${id}_machine ${id}_proof ${id}_check
1712
- ${hm ? histBlock() : readable(id, laws, vars, mapNames, { binders: '(ρ : Nat → Nat) (μ : Nat → Nat → Nat)', hyp: `SReach ${id}_machine ρ μ`, call: `${id}_laws ρ μ h`, lit: c, eLit: e })}${sm ? sumsBlock() : ''}${opts.noFacts ? '' : factsProof(id, m, mapNames, vars, opts.simp)}${opts.tamper ? `
1842
+ ${hm ? histBlock() : readable(id, laws, vars, mapNames, { binders: '(ρ : Nat → Nat) (μ : Nat → Nat → Nat)', hyp: `SReach ${id}_machine ρ μ`, call: `${id}_laws ρ μ h`, lit: c, eLit: e, ghosts: !rf && !gm && gv.length > 0, explicitExistentials: new Set((opts.ghostSubst ?? []).map(g => g.law)) })}${sm ? sumsBlock() : ''}${opts.noFacts ? '' : factsProof(id, m, mapNames, vars, opts.simp)}${opts.tamper ? `
1713
1843
  -- TAMPERED: ${opts.tamper.what}. Lean computes the check to false.
1714
1844
  def ${id}_tampered : SMachine := ${lit(opts.tamper.machine)}
1715
- example : checkSMachine ${id}_tampered ${id}_proof = false := by ${checkBy}` : ''}${records.length ? `\n\n${records.join('\n\n')}` : ''}${opts.after ? `\n\n${opts.after(ix, mx, lit)}` : ''}`;
1845
+ example : checkSMachine ${id}_tampered ${id}_proof = false := by ${checkBy}` : ''}${records.length ? `\n\n${records.join('\n\n')}` : ''}${opts.after ? `\n\n${opts.after(ix, mx, lit, c)}` : ''}`;
1716
1846
  }
1717
1847
  // --- the cyclic certificate's export (GDP_CERT=cyclic) -------------------------------------------------------------
1718
1848
  // By default, or with GDP_CERT=cyclic (core/cyclic.ts's certOn: a covered proof's certificate is its cyclic proof; or toLean's
@@ -1729,6 +1859,7 @@ example : checkSMachine ${id}_tampered ${id}_proof = false := by ${checkBy}` : '
1729
1859
  // is made with no cyclic certificate of its own (quietly): the export makes the certificate it exports from the usual
1730
1860
  // trees (cycMachineProof), and the usual export reads the trees, so a certificate made here is never read.
1731
1861
  const usualMade = new Map();
1862
+ let retainedOnly = false;
1732
1863
  // Where the usual proof fails and there are no step laws, the search's own set proof (proveSetFast: per-law instances
1733
1864
  // of each law's sort, a refutation's core widened to its goal, its trees checked by checkLaws): the laws the engine
1734
1865
  // proved that way (ring's) go to Lean from the trees that proof made, which Lean checks as any (`certReport.fast`).
@@ -1736,6 +1867,8 @@ function proveStepLawsOnce(m, laws, stepLaws) {
1736
1867
  const key = JSON.stringify([m, laws, stepLaws]), had = usualMade.get(key);
1737
1868
  if (had)
1738
1869
  return had;
1870
+ if (retainedOnly)
1871
+ throw new Error('retained-only export requested an uncaptured family; search is forbidden');
1739
1872
  // (with no step laws, the usual proof within usualMs of the cost model's clock (GDP_LEAN_USUAL_MS, 60 s): past it, the
1740
1873
  // fast one; wo's set with its ghost ran the usual proof 8 minutes and more)
1741
1874
  const fastToo = !stepLaws.length && !laws.some(l => l.some?.length);
@@ -1752,6 +1885,52 @@ function proveStepLawsOnce(m, laws, stepLaws) {
1752
1885
  }
1753
1886
  // A proof made elsewhere (core/kind.ts's k-induction search), as the one the export reads for these step laws.
1754
1887
  export const seedStepProof = (m, laws, stepLaws, r) => { usualMade.set(JSON.stringify([m, laws, stepLaws]), r); };
1888
+ // Captured-data entry points: validate and export only the supplied certificates.
1889
+ // These APIs may extend kernel term interning; use a fresh process for capsule
1890
+ // replay. Only exporter mode/cache globals are restored, not kernel term state.
1891
+ function retainedShape(id, m, laws) {
1892
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(id))
1893
+ throw new Error('invalid retained Lean identifier');
1894
+ if (Object.keys(m.fns ?? {}).length)
1895
+ throw new Error('retained function declarations require separate qualification');
1896
+ if (m.history || m.sums && Object.keys(m.sums).length)
1897
+ throw new Error('retained history/sums projection requires separate qualification');
1898
+ if (laws.some(l => l.some?.length))
1899
+ throw new Error('retained export needs the already-resolved witness family');
1900
+ }
1901
+ export function retainedCMachineToLean(id, m, laws, proof, options = {}) {
1902
+ retainedShape(id, m, laws);
1903
+ if (!checkCountedLaws(m, laws, proof))
1904
+ throw new Error('captured counted family does not check');
1905
+ const old = checkBy;
1906
+ checkBy = 'decide +kernel';
1907
+ try {
1908
+ return cmachineToLean(id, m, laws, proof, [], options);
1909
+ }
1910
+ finally {
1911
+ checkBy = old;
1912
+ }
1913
+ }
1914
+ export function retainedSMachineToLean(id, m, laws, proof, projection = {}) {
1915
+ retainedShape(id, m, laws);
1916
+ if (!checkLaws(m, laws, proof))
1917
+ throw new Error('captured usual family does not check');
1918
+ const old = checkBy, oldRetained = retainedOnly, oldCache = [...usualMade];
1919
+ try {
1920
+ usualMade.clear();
1921
+ retainedOnly = true;
1922
+ checkBy = 'decide +kernel';
1923
+ seedStepProof(m, laws, [], { proven: true, checked: true, nodes: 0, leaves: 0, proof: { laws: proof, instances: {}, perStep: {}, trees: {} } });
1924
+ return smachineToLean(id, m, laws, projection);
1925
+ }
1926
+ finally {
1927
+ usualMade.clear();
1928
+ for (const [key, value] of oldCache)
1929
+ usualMade.set(key, value);
1930
+ retainedOnly = oldRetained;
1931
+ checkBy = old;
1932
+ }
1933
+ }
1755
1934
  const envOf = () => globalThis.process?.env;
1756
1935
  export const cyclicCerts = certMode;
1757
1936
  let certsOn = false, cycTexts = 0;
@@ -2029,7 +2208,7 @@ ${cycProofText(id, p, [], vars, maps)}
2029
2208
  ${okLemmas}
2030
2209
  ${lawBlocks}
2031
2210
  ${lawsThm}
2032
- ${hm ? histBlock() : readable(id, laws, vars, maps, { binders: '(ρ : Nat → Nat) (μ : Nat → Nat → Nat)', hyp: `SReach ${id}_machine ρ μ`, call: '', lit: c, eLit: e,
2211
+ ${hm ? histBlock() : readable(id, laws, vars, maps, { binders: '(ρ : Nat → Nat) (μ : Nat → Nat → Nat)', hyp: `SReach ${id}_machine ρ μ`, call: '', lit: c, eLit: e, ghosts: !rf && gv.length > 0,
2033
2212
  have: j => `have hl : holdsOver ${id}_l${j} μ ${keys2(laws[j])} ρ := cyc_machine_holds (${id}_law${j}_holds ρ μ h)` })}${opts.noFacts ? '' : factsProof(id, m, maps, vars, opts.simp)}${records.length ? `\n\n${records.join('\n\n')}` : ''}${opts.after ? `\n\n${opts.after(ix)}` : ''}` };
2034
2213
  }
2035
2214
  // A fold from its cyclic proof (Bridge.lean's cyc_fold_sound): the fold numbered as foldToLean numbers it, each law's
@@ -2507,10 +2686,18 @@ export { rationalsToLean } from "./qlean.js";
2507
2686
  // A Lake project that builds the twin and the file: `lake build` in its folder checks every proof.
2508
2687
  export function leanProject(file, opts = {}) {
2509
2688
  const name = opts.name ?? 'Proofs';
2510
- const modules = [...Object.keys(leanLibrary).map(f => f.replace(/\.lean$/, '')), name];
2689
+ // Only generated cut-family declarations need the new family library. Merely
2690
+ // mentioning CEntryF in a comment or identifier must not change a cut-free project.
2691
+ const cutFamily = /^(?:noncomputable )?def [^\s:]+ : List CEntryF :=/m.test(file);
2692
+ const oldNames = new Set(legacyFamilyOrder);
2693
+ const modernNames = new Set(Object.keys(leanLibrary).filter(n => !oldNames.has(n)).map(n => n.slice(0, -5)));
2694
+ const modernImport = [...file.matchAll(/^\s*import\s+([^\n]+)/gm)].some(m => m[1].split(/\s+/).some(n => modernNames.has(n)));
2695
+ const current = opts.currentFamily === true || cutFamily || modernImport || file.includes('RowAlpha.') || file.includes('forall_some_of_ghostsubst_bound');
2696
+ const library = current ? leanLibrary : Object.fromEntries(legacyFamilyOrder.map(n => [n, legacyFamilyLibrary[n] ?? leanLibrary[n]]));
2697
+ const modules = [...Object.keys(library).map(f => f.replace(/\.lean$/, '')), name];
2511
2698
  return {
2512
- ...leanLibrary,
2513
- [`${name}.lean`]: file,
2699
+ ...library,
2700
+ [`${name}.lean`]: (file.includes('RowAlpha.') ? 'import RowAlpha\n' : '') + (file.includes('forall_some_of_ghostsubst_bound') ? 'import BoundGhost\n' : '') + file,
2514
2701
  'lean-toolchain': 'leanprover/lean4:v4.34.0\n',
2515
2702
  'lakefile.lean': `import Lake
2516
2703
  open Lake DSL
@@ -0,0 +1 @@
1
+ export declare const legacyFamilyLibrary: Readonly<Record<string, string>>;