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,256 @@
1
+ import { boundOf, witnessesOf, substC } from "../../kernel/kernel.js";
2
+ import { retainedSMachineToLean } from "../emit.js";
3
+ import { liftProject } from "../lift/project.js";
4
+ import { sourceStructure } from "../lift/source.js";
5
+ import { proposeWitnessAlpha } from "../lift/witness-alpha.js";
6
+ import { deriveTypedRoles } from "./roles.js";
7
+ import { associativeShape } from "./shape.js";
8
+ const list = (xs) => '[' + xs.join(', ') + ']';
9
+ const equal = (a, b) => sourceStructure(a) === sourceStructure(b);
10
+ const walk = (x, f) => { if (!x || typeof x !== 'object')
11
+ return; f(x); Object.values(x).forEach(v => Array.isArray(v) ? v.forEach(y => walk(y, f)) : walk(v, f)); };
12
+ const transform = (x, r, scope) => {
13
+ if (!x || typeof x !== 'object')
14
+ return x;
15
+ if (Array.isArray(x))
16
+ return x.map(v => transform(v, r, scope));
17
+ if ((x.op === '<' || x.op === '<=') && x.b?.op === 'const' && x.b.value === r.bound) {
18
+ const p = x.a.op === 'var' ? scope[x.a.name] : x.a.op === 'get' ? r.values[x.a.map] : undefined;
19
+ if (!p)
20
+ throw Error('unclassified typed bound: ' + JSON.stringify(x.a));
21
+ return { ...x, a: transform(x.a, r, scope), b: { op: 'var', name: p } };
22
+ }
23
+ return Object.fromEntries(Object.entries(x).map(([k, v]) => [k, transform(v, r, scope)]));
24
+ };
25
+ const normalized = (m) => { const { relations: _r, name: _n, ...rest } = m; return associativeShape({ ...rest, name: 'source', maps: m.maps ?? {}, step: { ...m.step, maps: m.step.maps ?? {} } }); };
26
+ /** After caller-owned capsule/hash validation and single term restoration.
27
+ * No protocol lookup, search, old generated Lean, or schema rewriting occurs. */
28
+ export function tryTypedBoundSubstitution({ id, bundle, providedSourceAST: source, options }) {
29
+ if (!/^[A-Za-z][A-Za-z0-9_]*$/.test(id) || id.length > 80)
30
+ throw Error('unsafe typed Lean identifier');
31
+ if (source.schema !== 'gdp-lift-source/v1' || !source.laws.length)
32
+ throw Error('invalid typed source envelope');
33
+ sourceStructure(source);
34
+ for (const n of [options.maxOutputBytes, options.maxFiles, options.recursionDepth])
35
+ if (!Number.isSafeInteger(n) || n < 1)
36
+ throw Error('positive finite typed output limits required');
37
+ if (!Number.isSafeInteger(options.heartbeats) || options.heartbeats < 0)
38
+ throw Error('invalid typed heartbeat budget');
39
+ // A counted or non-parametric family is not this route. A recognized typed
40
+ // candidate is never silently delegated after encountering an unsupported mix.
41
+ if (!bundle.proof)
42
+ return null;
43
+ let probe = false;
44
+ walk(source.machine, x => { if ((x.op === '<' || x.op === '<=') && x.b?.op === 'var' && source.machine.params.includes(x.b.name))
45
+ probe = true; });
46
+ if (!probe)
47
+ return null;
48
+ if (!bundle.verdict?.proven || !bundle.verdict.checked)
49
+ throw Error('unverified typed candidate');
50
+ let node = bundle.proof;
51
+ let context;
52
+ const seen = new Set();
53
+ while (node.kind === 'derived') {
54
+ if (seen.has(node) || node.parents.length !== 1 || !node.parents[0])
55
+ throw Error('typed candidate needs a unique complete producer path');
56
+ seen.add(node);
57
+ const c = node.context;
58
+ if (c?.kind === 'skolem') {
59
+ if (context)
60
+ throw Error('mixed typed witness contexts');
61
+ context = c;
62
+ }
63
+ else if (!['projection', 'inference'].includes(c?.kind))
64
+ throw Error('unsupported typed provenance context');
65
+ node = node.parents[0];
66
+ }
67
+ if (node.kind !== 'usual')
68
+ throw Error('unsupported typed/count mixing');
69
+ const leaf = node;
70
+ for (const m of [source.machine, bundle.original.machine, leaf.machine])
71
+ if (m.history || Object.keys(m.counts ?? {}).length || Object.keys(m.sums ?? {}).length || Object.keys(m.fns ?? {}).length || m.facts?.length)
72
+ throw Error('unsupported typed machine extension');
73
+ const roles = deriveTypedRoles(source, bundle.original, leaf.machine, leaf.laws);
74
+ if (!roles)
75
+ return null;
76
+ if (!context || !context.G || !context.plains)
77
+ throw Error('typed witness context with explicit substitution required');
78
+ const gm = context.G;
79
+ if (!equal(normalized(gm.orig), normalized(context.original)))
80
+ throw Error('typed context source mismatch');
81
+ const typed = transform(leaf.machine, roles, roles.base);
82
+ // The context's source can have a different fresh quantified binder than
83
+ // its retained producer. Project the actual producer's ghost fields by the
84
+ // declared context sets; Lean rechecks this projection against the supplied
85
+ // source through alpha validity, ghost validity and operational inclusion.
86
+ const strip = (r, ghosts) => Object.fromEntries(Object.entries(r ?? {}).filter(([name]) => !Object.hasOwn(ghosts, name)));
87
+ const bare = { ...leaf.machine, state: strip(leaf.machine.state, gm.vars), maps: strip(leaf.machine.maps, gm.maps), step: { ...leaf.machine.step, state: strip(leaf.machine.step.state, gm.vars), maps: strip(leaf.machine.step.maps, gm.maps) } };
88
+ const typedOriginal = transform(bare, roles, roles.base);
89
+ // Alpha proposal only; Lean validates the actual provided machine, not this
90
+ // finite shadow or a copied public-source assertion.
91
+ const alpha = proposeWitnessAlpha(normalized(source.machine), normalized({ ...typedOriginal, params: source.machine.params }));
92
+ const publicLawIndices = [], substitutions = [];
93
+ for (let j = 0; j < source.laws.length; j++) {
94
+ const l = source.laws[j], old = bundle.original.laws[j];
95
+ if (!old || !l.some?.length || l.ex || l.stated || l.finite || l.witness)
96
+ throw Error('unsupported typed public law (explicit existential only)');
97
+ if (l.forall !== old.forall || !equal(l.keys ?? [], old.keys ?? []))
98
+ throw Error('typed universal-binder alpha requires a separate bridge');
99
+ if (!old.some || old.some.length !== l.some.length || new Set(old.some).size !== old.some.length || new Set(l.some).size !== l.some.length)
100
+ throw Error('ambiguous typed existential binder correspondence');
101
+ const q = context.plains[old.name];
102
+ if (!q || !q.sub)
103
+ throw Error('missing typed witness substitution');
104
+ const matches = leaf.laws.flatMap((f, i) => equal(f, q.plain) ? [i] : []);
105
+ if (matches.length !== 1)
106
+ throw Error('missing/ambiguous typed public family correspondence');
107
+ const i = matches[0];
108
+ publicLawIndices.push(i);
109
+ if (Object.keys(q.sub).length !== old.some.length || !old.some.every(k => Object.hasOwn(q.sub, k)))
110
+ throw Error('incomplete typed existential substitution');
111
+ const publicSub = Object.fromEntries(l.some.map((k, j) => [k, q.sub[old.some[j]]]));
112
+ substitutions.push(publicSub);
113
+ // The source differs from its captured public statement only through checked
114
+ // finite-bound substitution. Its full provided literal is emitted below.
115
+ const renamed = substC(old.holds, { vars: Object.fromEntries(old.some.map((k, j) => [k, { op: 'var', name: l.some[j] }])), maps: {}, flags: {} });
116
+ const body = transform(renamed, roles, roles.publicScopes[j]);
117
+ if (!equal(associativeShape(body), associativeShape(l.holds)))
118
+ throw Error('provided typed source law differs beyond inferred bound substitution');
119
+ }
120
+ const free = new Set([...source.machine.params, ...source.machine.inputs, ...Object.keys(source.machine.state)]);
121
+ walk([source, typed], x => { if (x.op === 'var')
122
+ free.add(x.name); });
123
+ for (const [f, q] of Object.entries(leaf.machine.step.flags ?? {}))
124
+ if (q.op === 'all') {
125
+ free.add('?' + f);
126
+ boundOf(q).forEach(k => free.add(k));
127
+ witnessesOf(f, q).forEach(k => free.add(k));
128
+ }
129
+ source.laws.forEach(l => [l.forall, ...(l.keys ?? []), ...(l.some ?? [])].forEach(k => { if (k)
130
+ free.add(k); }));
131
+ alpha?.renames.forEach(r => { free.add(r.old); free.add(r.fresh); });
132
+ alpha?.rows.forEach(r => { free.add(r.old); free.add(r.fresh); });
133
+ // The historical family interface is checker acceptance, not semantic soundness.
134
+ const raw = id + '_retained', sourceTheorems = source.laws.map((_, j) => id + '_source_law' + j + '_holds'), familyTheorem = id + '_check';
135
+ let extra = '';
136
+ const emitted = retainedSMachineToLean(raw, leaf.machine, leaf.laws, leaf.proof, { free: [...free], after: (ix, mx, lit, c) => {
137
+ const typing = (s) => `⟨${list(roles.sizes.map(ix))}, ${list(Object.entries(s).map(([v, p]) => `(${ix(v)}, ${ix(p)})`))}, ${list(Object.entries(roles.values).map(([m, p]) => `(${mx(m)}, ${ix(p)})`))}⟩`;
138
+ const renames = list((alpha?.renames ?? []).map(r => `⟨${ix('?' + r.flag)}, ${ix(r.old)}, ${ix(r.fresh)}⟩`));
139
+ const rows = list((alpha?.rows ?? []).map(r => `⟨${mx(r.map)}, ${ix(r.old)}, ${ix(r.fresh)}⟩`));
140
+ const ghostVars = Object.keys(gm.vars), ghostMaps = Object.keys(gm.maps);
141
+ function expr(e) {
142
+ switch (e.op) {
143
+ case 'var': return `.var ${ix(e.name)}`;
144
+ case 'const':
145
+ if (!Number.isSafeInteger(e.value) || e.value < 0)
146
+ throw Error('unsupported natural literal');
147
+ return `.const ${e.value}`;
148
+ case 'get': return `.get ${mx(e.map)} (${expr(e.key)})`;
149
+ case 'if': return `.ite (${c(e.c)}) (${expr(e.then)}) (${expr(e.else)})`;
150
+ case 'mul': return `.mul ${e.k} (${expr(e.a)})`;
151
+ case 'proj': return `.proj ${e.k} (${expr(e.a)})`;
152
+ case 'add':
153
+ case 'max':
154
+ case 'min':
155
+ case 'prod':
156
+ case 'sub':
157
+ case 'tup':
158
+ return `.${e.op} (${expr(e.a)}) (${expr(e.b)})`;
159
+ }
160
+ }
161
+ const ghostScalars = list(ghostVars.map(v => `(${ix(v)}, ${expr(gm.vars[v].start)}, ${expr(transform(gm.vars[v].step, roles, roles.base))})`));
162
+ const ghostStarts = list(ghostMaps.map(m => `(${mx(m)}, ${gm.maps[m].start})`));
163
+ const ghostWrites = list(ghostMaps.map(m => { const w = gm.maps[m].write; if ('each' in w)
164
+ throw Error('typed ghost row update unsupported'); return `(${mx(m)}, ${expr(w.key)}, ${expr(transform(w.value, roles, roles.base))})`; }));
165
+ const body = source.laws.map((l, j) => {
166
+ const i = publicLawIndices[j], p = id + '_public' + j, sub = substitutions[j], sigma = list(l.some.map(k => `(${ix(k)}, ${expr(sub[k])})`));
167
+ return `def ${p}_body : C := ${c(l.holds)}
168
+ def ${p}_sigma : List (Nat × E) := ${sigma}
169
+ def ${p}_strong : SEntry := ${id}_proof[${i}]'(by decide +kernel)
170
+ def ${p}_strongLiteral : C := ${c(transform(leaf.laws[i].holds, roles, roles.scopes[i]))}
171
+ def ${p}_weakLiteral : C := ${c(substC(l.holds, { vars: sub, maps: {}, flags: {} }))}
172
+ def ${p}_weak : SEntry := {${p}_strong with law := {${p}_strong.law with holds := substC ${p}_sigma ${p}_body}}
173
+ theorem ${p}_strong_eq : ${p}_strong.law.holds = ${p}_strongLiteral := by decide +kernel
174
+ theorem ${p}_weak_eq : ${p}_weak.law.holds = ${p}_weakLiteral := by rfl
175
+ theorem ${p}_implication : SourceLawImplication ${p}_strong ${p}_weak := by
176
+ apply sourceLawImplication_of_pointwise
177
+ · rfl
178
+ · rfl
179
+ · intro ρ M h
180
+ change evalC ρ M ${p}_weak.law.holds = true
181
+ rw [${p}_weak_eq]
182
+ change evalC ρ M ${p}_strong.law.holds = true at h
183
+ rw [${p}_strong_eq] at h
184
+ simpa [${p}_strongLiteral, ${p}_weakLiteral, evalC, and_assoc, or_assoc] using h
185
+ theorem ${sourceTheorems[j]} (ρ M) (hr : SReach ${id}_source_machine ρ M) :
186
+ ExHolds ${p}_body ${l.forall ? '(some ' + ix(l.forall) + ')' : 'none'} ${list(l.some.map(ix))} M ${list((l.keys ?? []).map(ix))} ρ := by
187
+ have ha : SReach ${id}_ghosts.orig ρ M := ${id}_source_machine_reach ρ M hr
188
+ have conclusion := Kern.TypedSource.ex_of_holds ${id}_ghosts ${id}_ghosts_valid ${p}_weak ${p}_sigma ${p}_body (by rfl) (by decide +kernel) (by decide +kernel) (by
189
+ intro X N hreach
190
+ exact ${p}_implication X N (${id}_laws X N (${id}_inclusion.sreach hreach) ${p}_strong (by exact List.getElem_mem (by decide +kernel)))) ρ M ha
191
+ exact conclusion
192
+ `;
193
+ }).join('\n') + (source.laws.length === 1 ? `\ntheorem ${id}_source (ρ M) (hr : SReach ${id}_source_machine ρ M) : ExHolds ${id}_public0_body ${source.laws[0].forall ? '(some ' + ix(source.laws[0].forall) + ')' : 'none'} ${list(source.laws[0].some.map(ix))} M ${list((source.laws[0].keys ?? []).map(ix))} ρ := ${sourceTheorems[0]} ρ M hr\n` : '');
194
+ extra = `def ${id}_baseTyping : Typed.Typing := ${typing(roles.base)}
195
+ def ${id}_typings : List Typed.Typing := ${list(roles.scopes.map(typing))}
196
+ def ${id}_machineOption := Typed.machine ${roles.bound} ${id}_baseTyping ${raw}_machine
197
+ def ${id}_machine : SMachine := ${id}_machineOption.getD ${raw}_machine
198
+ def ${id}_options : List (Option SEntry) := (${id}_typings.zip ${raw}_proof).map fun (p,e) => Typed.entry ${roles.bound} p (Typed.withoutStepCache (Typed.withoutInitialCache e))
199
+ def ${id}_provisional : List SEntry := (${id}_options.zip ${raw}_proof).map fun (e,old) => e.getD old
200
+ -- Cache candidates are selected only by the complete root checker, never an entry number.
201
+ def ${id}_candidates (p : Typed.Typing) (e : SEntry) : List (Option SEntry) :=
202
+ [Typed.entry ${roles.bound} p e, Typed.entry ${roles.bound} p (Typed.withoutStepCache e), Typed.entry ${roles.bound} p (Typed.withoutInitialCache e), Typed.entry ${roles.bound} p (Typed.withoutStepCache (Typed.withoutInitialCache e))]
203
+ def ${id}_choose (p : Typed.Typing) (old : SEntry) : Option SEntry :=
204
+ ((${id}_candidates p old).filterMap id).find? fun e => checkIn (sStartGoal ${id}_machine e) e.start && checkIn (sStepGoal ${id}_machine ${id}_provisional e) e.step
205
+ def ${id}_selected : List (Option SEntry) := (${id}_typings.zip ${raw}_proof).map fun (p,e) => ${id}_choose p e
206
+ def ${id}_proof : List SEntry := (${id}_selected.zip ${raw}_proof).map fun (e,old) => e.getD old
207
+ theorem ${id}_options_complete : ${id}_machineOption.isSome && ${id}_selected.all Option.isSome = true := by decide +kernel
208
+ theorem ${id}_shape_preserved : (${id}_proof.map fun e => (Typed.treeShape e.start.2.2, Typed.treeShape e.step.2.2)) = (${raw}_proof.map fun e => (Typed.treeShape e.start.2.2, Typed.treeShape e.step.2.2)) := by decide +kernel
209
+ theorem ${id}_check : checkSMachine ${id}_machine ${id}_proof = true := by decide +kernel
210
+ theorem ${id}_laws : ∀ ρ M, SReach ${id}_machine ρ M → ∀ e ∈ ${id}_proof, e.Holds ρ M := smachine_sound _ _ ${id}_check
211
+
212
+ def ${id}_source_machine : SMachine := ${lit(source.machine)}
213
+ def ${id}_renames : List QAlpha.Rename := ${renames}
214
+ def ${id}_rowRenames : List RowAlpha.Rename := ${rows}
215
+ def ${id}_alpha := RowAlpha.renameAll (QAlpha.renameAll ${id}_source_machine ${id}_renames) ${id}_rowRenames
216
+ def ${id}_ghosts : SGhostedM := ⟨${id}_alpha, ${ghostScalars}, ${ghostStarts}, ${ghostWrites}, []⟩
217
+ theorem ${id}_alpha_valid : QAlpha.validAll ${id}_source_machine ${id}_renames = true := by decide +kernel
218
+ theorem ${id}_rows_valid : RowAlpha.validAll (QAlpha.renameAll ${id}_source_machine ${id}_renames) ${id}_rowRenames = true := by decide +kernel
219
+ theorem ${id}_ghosts_valid : smghostOk ${id}_ghosts = true := by decide +kernel
220
+ theorem ${id}_source_machine_reach (ρ M) (hr : SReach ${id}_source_machine ρ M) : SReach ${id}_ghosts.orig ρ M := by
221
+ exact (RowAlpha.renameAll_equiv _ _ ${id}_rows_valid).symm.sreach_imp ((QAlpha.renameAll_equiv _ _ ${id}_alpha_valid).symm.sreach_imp hr)
222
+ def ${id}_source_machineAssume : C := ${c(source.machine.assume ?? { op: 'and', xs: [] })}
223
+ def ${id}_targetAssume : C := ${c(typed.assume ?? { op: 'and', xs: [] })}
224
+ theorem ${id}_source_machineAssume_eq : ${id}_ghosts.full.f.m.assume = ${id}_source_machineAssume := by rfl
225
+ theorem ${id}_targetAssume_eq : ${id}_machine.f.m.assume = ${id}_targetAssume := by decide +kernel
226
+ theorem ${id}_view_eq (ρ M ι κ) : sView ${id}_ghosts.full ρ M ι κ = sView ${id}_machine ρ M ι κ := by rfl
227
+ theorem ${id}_next_eq (ρ M ι κ) : sNext ${id}_ghosts.full ρ M ι κ = sNext ${id}_machine ρ M ι κ := by rfl
228
+ theorem ${id}_inclusion : SourceInclusion ${id}_ghosts.full ${id}_machine where
229
+ inputs := by rfl
230
+ carried := by rfl
231
+ initial := by rfl
232
+ startMaps := by intro M h; exact h
233
+ pre := by intro ρ M h; exact h
234
+ facts := by intro ρ M h; exact h
235
+ pfacts := by intro ρ M h; exact h
236
+ admission := by
237
+ intro ρ M ι κ h
238
+ rw [${id}_view_eq, ${id}_source_machineAssume_eq] at h
239
+ rw [${id}_targetAssume_eq]
240
+ simpa [${id}_source_machineAssume, ${id}_targetAssume, evalC, and_assoc, or_assoc] using h
241
+ next := by intro ρ M ι κ _; exact ${id}_next_eq ρ M ι κ
242
+ ${body}`;
243
+ return '';
244
+ } });
245
+ const stop = emitted.indexOf(`\ntheorem ${raw}_check :`);
246
+ if (stop < 0 || !extra)
247
+ throw Error('current complete family emitter layout changed');
248
+ const requiredTheorems = [id + '_options_complete', id + '_shape_preserved', familyTheorem, id + '_laws', id + '_alpha_valid', id + '_rows_valid', id + '_ghosts_valid', id + '_inclusion', ...source.laws.map((_, j) => id + '_public' + j + '_implication'), ...sourceTheorems, ...(source.laws.length === 1 ? [id + '_source'] : []), id + '_source_machine_reach', id + '_source_machineAssume_eq', id + '_targetAssume_eq', id + '_view_eq', id + '_next_eq', ...source.laws.flatMap((_, j) => [id + '_public' + j + '_strong_eq', id + '_public' + j + '_weak_eq']), 'Kern.TypedSource.ex_of_holds'];
249
+ const body = 'import QAlpha\nimport RowAlpha\nimport CertificateBoundSubstitution\nimport TypedSource\nopen Kern Bapa.CertificateBoundSubstitution\nset_option maxRecDepth ' + options.recursionDepth + '\nset_option maxHeartbeats ' + options.heartbeats + '\n' + emitted.slice(0, stop) + '\n' + extra + '\n' + requiredTheorems.map(t => '#print axioms ' + t).join('\n') + '\n';
250
+ const project = liftProject(body, { name: 'BapaProof' });
251
+ const modules = Object.keys(project).filter(n => n.endsWith('.lean') && n !== 'lakefile.lean').map(n => n.slice(0, -5));
252
+ project['lakefile.lean'] = 'import Lake\nopen Lake DSL\npackage typed_lift\n@[default_target]\nlean_lib TypedLift where\n roots := #[' + modules.map(m => '`' + m).join(', ') + ']\n';
253
+ if (Object.keys(project).length > options.maxFiles || Object.values(project).reduce((n, t) => n + Buffer.byteLength(t), 0) > options.maxOutputBytes)
254
+ throw Error('typed output limit exceeded');
255
+ return { project, familyTheorem, sourceTheorems, publicLawIndices, requiredTheorems, roles, status: 'EMITTED_NOT_CHECKED' };
256
+ }
@@ -0,0 +1,17 @@
1
+ import type { Law, Machine } from '../../core/machine.js';
2
+ import type { GenericLiftSource } from '../lift/source.js';
3
+ export type Roles = {
4
+ sizes: string[];
5
+ bound: number;
6
+ base: Record<string, string>;
7
+ scopes: Record<string, string>[];
8
+ publicScopes: Record<string, string>[];
9
+ values: Record<string, string>;
10
+ coordinates: Record<string, string[]>;
11
+ };
12
+ /** Parameter roles come ONLY from matching bounded source comparisons and
13
+ * coordinate/value constraints. Relations metadata and spelling are ignored. */
14
+ export declare function deriveTypedRoles(source: GenericLiftSource, original: {
15
+ machine: Machine;
16
+ laws: Law[];
17
+ }, machine: Machine, laws: Law[]): Roles | null;
@@ -0,0 +1,170 @@
1
+ import { boundOf, witnessesOf } from "../../kernel/kernel.js";
2
+ import { associativeShape } from "./shape.js";
3
+ const upper = (x) => x && (x.op === '<' || x.op === '<=');
4
+ const scan = (x, f) => { if (!x || typeof x !== 'object')
5
+ return; f(x); for (const v of Object.values(x))
6
+ if (Array.isArray(v))
7
+ v.forEach(y => scan(y, f));
8
+ else
9
+ scan(v, f); };
10
+ const tuple = (e) => e.op === 'tup' ? [e.a, ...tuple(e.b)] : [e];
11
+ /** Parameter roles come ONLY from matching bounded source comparisons and
12
+ * coordinate/value constraints. Relations metadata and spelling are ignored. */
13
+ export function deriveTypedRoles(source, original, machine, laws) {
14
+ const parameters = new Set(source.machine.params), sizes = [], bounds = new Set();
15
+ // Pair structurally corresponding comparisons, allowing alpha binder names.
16
+ const paired = (a, b) => {
17
+ if (!a || !b || typeof a !== 'object' || typeof b !== 'object')
18
+ return;
19
+ if (upper(a) && upper(b) && a.op === b.op && a.b?.op === 'var' && parameters.has(a.b.name) && b.b?.op === 'const') {
20
+ if (!sizes.includes(a.b.name))
21
+ sizes.push(a.b.name);
22
+ bounds.add(b.b.value);
23
+ }
24
+ if (Array.isArray(a) && Array.isArray(b)) {
25
+ a.forEach((x, i) => paired(x, b[i]));
26
+ return;
27
+ }
28
+ for (const k of Object.keys(a))
29
+ if (k !== 'params' && k !== 'relations')
30
+ paired(a[k], b[k]);
31
+ };
32
+ paired(associativeShape(source.machine), associativeShape(original.machine));
33
+ paired(associativeShape(source.laws), associativeShape(original.laws));
34
+ if (!sizes.length)
35
+ return null;
36
+ if (bounds.size !== 1)
37
+ throw Error('typed-bound candidate has mixed finite bounds');
38
+ const bound = [...bounds][0];
39
+ if (!Number.isSafeInteger(bound) || bound < 2)
40
+ throw Error('unsupported typed finite bound');
41
+ if (source.machine.params.some(p => !sizes.includes(p)) || original.machine.params.length)
42
+ throw Error('unsupported independent non-bound parameters in typed candidate');
43
+ const parent = new Map(), labels = new Map();
44
+ const root = (x) => { const p = parent.get(x); if (!p) {
45
+ parent.set(x, x);
46
+ return x;
47
+ } if (p === x)
48
+ return x; const r = root(p); parent.set(x, r); return r; };
49
+ const join = (a, b) => { if (!a || !b)
50
+ return; const x = root(a), y = root(b); if (x === y)
51
+ return; const p = labels.get(x), q = labels.get(y); if (p && q && p !== q)
52
+ throw Error(`ambiguous/mixed typed roles: ${p} versus ${q}`); parent.set(y, x); if (q)
53
+ labels.set(x, q); };
54
+ const seed = (x, p) => { if (!x)
55
+ throw Error('unsupported bounded expression'); const r = root(x), q = labels.get(r); if (q && q !== p)
56
+ throw Error(`ambiguous/mixed typed roles: ${q} versus ${p}`); labels.set(r, p); };
57
+ const globals = new Set([...machine.params, ...machine.inputs, ...Object.keys(machine.state)]);
58
+ const vars = new Map(), coords = new Map();
59
+ const env = (s, boundNames = []) => { const locals = new Set(boundNames); const table = new Map(); vars.set(s, table); return (n) => { const k = locals.has(n) || !globals.has(n) ? s + ':' + n : 'global:' + n; table.set(n, k); root(k); return k; }; };
60
+ const base = env('machine');
61
+ const expr = (e, v) => {
62
+ if (e.op === 'var')
63
+ return v(e.name);
64
+ if (e.op === 'get') {
65
+ keys(e.map, e.key, v);
66
+ return 'value:' + e.map;
67
+ }
68
+ if (e.op === 'if') {
69
+ condition(e.c, v);
70
+ const a = expr(e.then, v), b = expr(e.else, v);
71
+ join(a, b);
72
+ return a ?? b;
73
+ }
74
+ if ((e.op === 'add' || e.op === 'sub') && e.b.op === 'const')
75
+ return expr(e.a, v);
76
+ if (e.op === 'const')
77
+ return undefined;
78
+ throw Error('unsupported arithmetic in typed role coordinate: ' + e.op);
79
+ };
80
+ const keys = (map, key, v) => { const ks = tuple(key), old = coords.get(map); if (old !== undefined && old !== ks.length)
81
+ throw Error('mixed tuple arity: ' + map); coords.set(map, ks.length); ks.forEach((e, i) => join('key:' + map + ':' + i, expr(e, v))); };
82
+ const condition = (c, v) => {
83
+ if (c.op === 'all') {
84
+ const q = env('quantified:' + vars.size, boundOf(c));
85
+ condition(c.c, q);
86
+ return;
87
+ }
88
+ if (c.op === 'and' || c.op === 'or') {
89
+ c.xs.forEach(x => condition(x, v));
90
+ return;
91
+ }
92
+ if (c.op === 'not') {
93
+ condition(c.x, v);
94
+ return;
95
+ }
96
+ if (c.op === 'flag')
97
+ return;
98
+ const a = expr(c.a, v), b = c.b.op === 'var' && parameters.has(c.b.name) ? undefined : expr(c.b, v);
99
+ if (upper(c) && c.b.op === 'var' && sizes.includes(c.b.name))
100
+ seed(a, c.b.name);
101
+ // Equality of identifiers/witness values constrains their sort. A numeric
102
+ // literal carries no sort; it can be a valid default for any domain.
103
+ else if (c.op === '=')
104
+ join(a, b);
105
+ };
106
+ const walkMachine = (m) => {
107
+ if (m.pre)
108
+ condition(m.pre, base);
109
+ if (m.assume)
110
+ condition(m.assume, base);
111
+ Object.values(m.state).forEach(e => expr(e, base));
112
+ for (const [n, e] of Object.entries(m.step.state ?? {}))
113
+ join(base(n), expr(e, base));
114
+ for (const [n, w] of Object.entries(m.step.maps ?? {})) {
115
+ if ('each' in w)
116
+ throw Error('typed row-update mixing unsupported');
117
+ keys(n, w.key, base);
118
+ join('value:' + n, expr(w.value, base));
119
+ }
120
+ for (const [f, q] of Object.entries(m.step.flags ?? {})) {
121
+ if (q.op === 'all') {
122
+ const v = env('flag:' + f, boundOf(q));
123
+ condition(q.c, v);
124
+ witnessesOf(f, q).forEach((w, i) => join(base(w), v(boundOf(q)[i])));
125
+ }
126
+ else
127
+ condition(q, base);
128
+ }
129
+ if (m.facts?.length)
130
+ throw Error('typed facts require a separate correspondence proof');
131
+ };
132
+ walkMachine(source.machine);
133
+ walkMachine(machine);
134
+ const sourceEnvs = source.laws.map((l, i) => { const v = env('sourceLaw:' + i, [l.forall, ...(l.keys ?? []), ...(l.some ?? [])].filter((x) => !!x)); condition(l.holds, v); return v; });
135
+ const lawEnvs = laws.map((l, i) => { const v = env('law:' + i, [l.forall, ...(l.keys ?? [])].filter((x) => !!x)); condition(l.holds, v); if (l.forall)
136
+ join(v(l.forall), v(l.forall + '#')); for (const k of l.keys ?? [])
137
+ join(v(k), v(k + '#')); return v; });
138
+ // Reading/writing the same map ties every coordinate to a single domain,
139
+ // independent of bound-variable names and the order of the family entries.
140
+ const label = (x) => labels.get(root(x));
141
+ const result = (table) => Object.fromEntries([...table].flatMap(([n, x]) => label(x) ? [[n, label(x)]] : []));
142
+ const baseRoles = result(vars.get('machine'));
143
+ for (const [scope, t] of vars)
144
+ if (scope.startsWith('flag:') || scope.startsWith('quantified:'))
145
+ for (const [n, p] of Object.entries(result(t))) {
146
+ if (baseRoles[n] && baseRoles[n] !== p)
147
+ throw Error('ambiguous machine-local binder role: ' + n);
148
+ baseRoles[n] = p;
149
+ }
150
+ const scopes = laws.map((_, i) => ({ ...baseRoles, ...result(vars.get('law:' + i)) }));
151
+ const values = Object.fromEntries([...coords.keys()].flatMap(m => label('value:' + m) ? [[m, label('value:' + m)]] : []));
152
+ const coordinates = Object.fromEntries([...coords].map(([m, n]) => [m, Array.from({ length: n }, (_, i) => { const p = label('key:' + m + ':' + i); if (!p)
153
+ throw Error('unclassified tuple coordinate ' + m + ':' + i); return p; })]));
154
+ // Every old finite upper bound needs a unique role; do not silently leave a
155
+ // finite remnant in a candidate whose public statement is unbounded.
156
+ const check = (x, roles) => scan(x, c => { if (upper(c) && c.b?.op === 'const' && c.b.value === bound) {
157
+ const p = c.a.op === 'var' ? roles[c.a.name] : c.a.op === 'get' ? values[c.a.map] : undefined;
158
+ if (!p)
159
+ throw Error('unclassified retained finite-bound expression');
160
+ } });
161
+ check(machine, baseRoles);
162
+ laws.forEach((l, i) => check(l.holds, scopes[i]));
163
+ // Guard against parameters inferred only from advisory metadata/unrelated laws.
164
+ for (const p of sizes)
165
+ if (!Object.values(baseRoles).includes(p) && !scopes.some(s => Object.values(s).includes(p)))
166
+ throw Error('unused bound parameter ' + p);
167
+ void sourceEnvs;
168
+ void lawEnvs;
169
+ return { sizes, bound, base: baseRoles, scopes, publicScopes: source.laws.map((_, i) => ({ ...baseRoles, ...result(vars.get('sourceLaw:' + i)) })), values, coordinates };
170
+ }
@@ -0,0 +1 @@
1
+ export declare function associativeShape<T>(x: T): T;
@@ -0,0 +1,12 @@
1
+ // Preflight equivalence only. All generated source literals retain their exact
2
+ // original syntax, with the semantic correspondence discharged in Lean.
3
+ export function associativeShape(x) {
4
+ if (!x || typeof x !== 'object')
5
+ return x;
6
+ if (Array.isArray(x))
7
+ return x.map(associativeShape);
8
+ const out = Object.fromEntries(Object.entries(x).map(([k, v]) => [k, associativeShape(v)]));
9
+ if ((out.op === 'and' || out.op === 'or') && Array.isArray(out.xs))
10
+ out.xs = out.xs.flatMap((v) => v?.op === out.op ? v.xs : [v]);
11
+ return out;
12
+ }
@@ -0,0 +1,30 @@
1
+ import { type GenericLiftManifest, type GenericLiftOptions } from './lift/index.js';
2
+ import { type LegacyIdentity } from './lift-legacy.js';
3
+ import { type BoundInclusionOutput } from './lift-special/index.js';
4
+ import { type LiftAliases } from './lift-names.js';
5
+ export { emitGenericLift } from './lift/index.js';
6
+ export type { GenericLiftManifest, GenericLiftOptions, GenericLiftSource } from './lift/index.js';
7
+ export { auditLiftLog } from './axiom-audit.js';
8
+ export type LiftManifest = Omit<GenericLiftManifest, 'identity' | 'sourceProjection' | 'parts'> & {
9
+ capsuleSchema: 'bapa-native-certificate/v1' | 'final29-native-certificate/v1';
10
+ identity: GenericLiftManifest['identity'] | LegacyIdentity;
11
+ sourceProjection: Omit<GenericLiftManifest['sourceProjection'], 'kind'> & {
12
+ kind: GenericLiftManifest['sourceProjection']['kind'] | 'bound-inclusion' | 'typed-bound-substitution' | 'radix-simulation';
13
+ };
14
+ parts?: GenericLiftManifest['parts'] | BoundInclusionOutput['parts'];
15
+ transport?: {
16
+ kind: 'bound-inclusion' | 'typed-bound-substitution';
17
+ bound: number;
18
+ } | {
19
+ kind: 'radix-simulation';
20
+ radix: number;
21
+ layouts: {
22
+ map: string;
23
+ arity: number;
24
+ }[];
25
+ };
26
+ theoremAliases?: LiftAliases;
27
+ };
28
+ /** One fresh process, one validated input, one term restoration. Candidate
29
+ * rejection is final; a failed transport never falls back to another strategy. */
30
+ export declare function lift(capsuleDirectory: string, sourceFile: string, outputDirectory: string, options?: GenericLiftOptions): LiftManifest;
@@ -0,0 +1,97 @@
1
+ /// <reference types="node" />
2
+ // One data-only lift pipeline. Emission is not source acceptance: native Lean
3
+ // must check the emitted source correspondence and all requested axioms.
4
+ import { join } from 'node:path';
5
+ import { generateGenericLift, readLiftInput, restoreTermPrelude, writeLiftProject, defaultPartOptions } from "./lift/index.js";
6
+ import { readBoundedData, dataText, sourceStructure, sourceLeanId, sha256 } from "./lift/source.js";
7
+ import { readLegacyLiftInput } from "./lift-legacy.js";
8
+ import { tryEmitBoundInclusion } from "./lift-special/index.js";
9
+ import { tryTypedBoundSubstitution } from "./lift-typed/index.js";
10
+ import { tryRadixSimulation } from "./lift-simulation/index.js";
11
+ import { asked } from "./axiom-audit.js";
12
+ import { applyLiftTheoremNames } from "./lift-names.js";
13
+ export { emitGenericLift } from "./lift/index.js";
14
+ export { auditLiftLog } from "./axiom-audit.js";
15
+ function readInput(capsule, source, options) {
16
+ const outer = JSON.parse(dataText(readBoundedData(join(capsule, 'CAPTURE.json'), 1024 * 1024)));
17
+ if (!outer || typeof outer !== 'object' || !('schema' in outer))
18
+ throw Error('invalid capsule envelope');
19
+ if (outer.schema === 'bapa-native-certificate/v1')
20
+ return { format: 'native', ...readLiftInput(capsule, source, options) };
21
+ if (outer.schema === 'final29-native-certificate/v1')
22
+ return readLegacyLiftInput(capsule, source, options);
23
+ throw Error('unsupported capsule schema');
24
+ }
25
+ function specialManifest(input, result, options) {
26
+ const root = result.project['BapaProof.lean'];
27
+ if (typeof root !== 'string' || result.sourceTheorems.length !== input.source.laws.length || !result.sourceTheorems.length || new Set(result.sourceTheorems).size !== result.sourceTheorems.length)
28
+ throw Error('incomplete generated source theorem coverage');
29
+ const present = asked(root);
30
+ if (new Set(present).size !== present.length)
31
+ throw Error('duplicate generated root axiom request');
32
+ const requiredTheorems = [...new Set([result.familyTheorem, ...result.sourceTheorems, ...result.requiredTheorems, ...present])];
33
+ for (const name of requiredTheorems)
34
+ if (!/^[A-Za-z_][A-Za-z0-9_.']*$/.test(name))
35
+ throw Error('invalid generated theorem name');
36
+ // Imported modules do not replay #print commands from their .olean files.
37
+ // Ask in the root for every required family, source and auxiliary theorem.
38
+ result.project['BapaProof.lean'] = root + '\n' + requiredTheorems.filter(n => !present.includes(n)).map(n => '#print axioms ' + n).join('\n') + '\n';
39
+ const limits = { ...defaultPartOptions, ...options.parts }, files = Object.entries(result.project);
40
+ for (const value of [limits.maxFiles, limits.maxOutputBytes])
41
+ if (!Number.isSafeInteger(value) || value < 1)
42
+ throw Error('finite positive output limits required');
43
+ if (files.length > limits.maxFiles || files.reduce((n, [, text]) => n + Buffer.byteLength(text), 0) > limits.maxOutputBytes)
44
+ throw Error('complete project output limit exceeded');
45
+ const transport = result.kind === 'radix-simulation'
46
+ ? { kind: result.kind, radix: result.plan.radix, layouts: result.plan.layouts }
47
+ : { kind: result.kind, bound: result.kind === 'bound-inclusion' ? result.bound : result.roles.bound };
48
+ return { schema: 'gdp-lift-emission/v1', status: 'EMITTED_NOT_CHECKED', inputSha256: input.capsuleSha256, capsuleSha256: input.capsuleSha256, sourceSha256: input.sourceSha256, sourceId: input.source.id, capsuleSchema: input.manifest.schema, identity: input.manifest.identity, route: input.bundle.route,
49
+ projection: { kind: 'unqualified', reason: 'source correspondence requires the generated Lean transport' }, familyTheorem: result.familyTheorem, requiredTheorems, files: Object.fromEntries(files.map(([name, text]) => [name, sha256(text)])),
50
+ sourceProjection: { kind: result.kind, status: 'EMITTED_NOT_CHECKED', sourceTheorems: result.sourceTheorems, publicLawNames: input.source.laws.map(l => l.name), publicLawIndices: result.publicLawIndices }, ...('parts' in result ? { parts: result.parts } : {}), transport, leanVersion: '4.34.0', leanExecuted: false, allSizesProven: false, publicSourceAcceptance: 'REQUIRES_LEAN_SOURCE_PROJECTION_CHECK' };
51
+ }
52
+ function finish(input, project, manifest, output, options) {
53
+ const named = applyLiftTheoremNames(project, manifest, input.source.theorems), limits = { ...defaultPartOptions, ...options.parts };
54
+ for (const value of [limits.maxFiles, limits.maxOutputBytes])
55
+ if (!Number.isSafeInteger(value) || value < 1)
56
+ throw Error('finite positive output limits required');
57
+ if (Object.keys(project).length > limits.maxFiles || Object.values(project).reduce((n, text) => n + Buffer.byteLength(text), 0) > limits.maxOutputBytes)
58
+ throw Error('complete named project output limit exceeded');
59
+ writeLiftProject(output, project, named);
60
+ return named;
61
+ }
62
+ /** One fresh process, one validated input, one term restoration. Candidate
63
+ * rejection is final; a failed transport never falls back to another strategy. */
64
+ export function lift(capsuleDirectory, sourceFile, outputDirectory, options = {}) {
65
+ const input = readInput(capsuleDirectory, sourceFile, options);
66
+ restoreTermPrelude(input.bundle.terms, input.metadata);
67
+ if (input.format === 'native' && sourceStructure({ machine: input.source.machine, laws: input.source.laws }) === sourceStructure(input.bundle.original)) {
68
+ const generated = generateGenericLift(input, options), manifest = { ...generated.manifest, capsuleSchema: input.manifest.schema };
69
+ return finish(input, generated.project, manifest, outputDirectory, options);
70
+ }
71
+ if ('final' in input.bundle) {
72
+ const result = tryEmitBoundInclusion({ id: sourceLeanId(input.source.id), bundle: input.bundle, providedSourceAST: input.source, options: { ...defaultPartOptions, ...options.parts } });
73
+ if (result) {
74
+ const manifest = specialManifest(input, result, options);
75
+ return finish(input, result.project, manifest, outputDirectory, options);
76
+ }
77
+ }
78
+ // Route labels are validated against the retained provenance graph. They
79
+ // describe proof shapes, not protocol identities. A recognized failure is
80
+ // terminal; it is never caught and tried as a different transformation.
81
+ if ('proof' in input.bundle) {
82
+ const common = { id: sourceLeanId(input.source.id), bundle: input.bundle, providedSourceAST: input.source, options: { ...defaultPartOptions, ...options.parts } };
83
+ if (input.bundle.route === 'witness') {
84
+ const result = tryTypedBoundSubstitution(common);
85
+ if (result) {
86
+ const tagged = { ...result, kind: 'typed-bound-substitution' };
87
+ return finish(input, result.project, specialManifest(input, tagged, options), outputDirectory, options);
88
+ }
89
+ }
90
+ else {
91
+ const result = tryRadixSimulation(common);
92
+ if (result)
93
+ return finish(input, result.project, specialManifest(input, result, options), outputDirectory, options);
94
+ }
95
+ }
96
+ throw Error('unsupported source/capsule transport shape; no source acceptance');
97
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gdp-wired",
3
- "version": "0.48.0",
3
+ "version": "0.50.0",
4
4
  "description": "An automatic prover for stateful rules (budgets, caps, windows, workflows, policies): laws proven with no proof to write, checked again in Lean, counterexamples found on the GPU, the rule shipped as code",
5
5
  "keywords": [
6
6
  "verification",
@@ -48,6 +48,10 @@
48
48
  "types": "./dist/lean-kernel/emit.d.ts",
49
49
  "default": "./dist/lean-kernel/emit.js"
50
50
  },
51
+ "./lift": {
52
+ "types": "./dist/lean-kernel/lift.d.ts",
53
+ "default": "./dist/lean-kernel/lift.js"
54
+ },
51
55
  "./kernel": {
52
56
  "types": "./dist/kernel/kernel.d.ts",
53
57
  "default": "./dist/kernel/kernel.js"