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
@@ -5,9 +5,15 @@
5
5
  // Arithmetic is linear: +, −, × by a constant, min, max, if. Maps are naturals indexed by naturals, every cell starting
6
6
  // at the same value; a law about a map holds for every key x, and is proven at one arbitrary x (with the law assumed at
7
7
  // every other key the step reads).
8
- import { boundOf, crossFree, eachParts, historyMachine, tuple, keyTerm, mapArities, plainKey, scope, sumRuntime, tupleParts } from "../kernel/kernel.js";
8
+ import { boundOf, crossFree, eachParts, finiteBound, finiteLawBound, historyMachine, tuple, keyTerm, mapArities, plainKey, scope, sumRuntime, tupleParts } from "../kernel/kernel.js";
9
9
  import { add, env, eq, k, le, lt, nat, scale, show, solve, sub, v } from "./solver.js";
10
10
  import { runtimeWall } from "./runtime-wall.js";
11
+ import { traceNow } from "./trace-clock.js";
12
+ import { coreMeter } from "./meter.js";
13
+ import { observeEval } from "./work-observe.js";
14
+ import { observeAst } from "./meter.js";
15
+ import { startWork } from "./work-admission.js";
16
+ import { completeWorkProfile } from "./work-profile.js";
11
17
  // The one generator of the repo's random draws: x' = (1103515245 x + 12345) mod 2^31, exact (Math.imul). In doubles
12
18
  // the product passes 2^53 and rounds, which folds every seed into one of six short cycles (61 to 10,466 steps; 98.8% of
13
19
  // seeds into the same one). Its period is 2^31 (core/rand.test.ts). Draws are its high bits (the low ones repeat with a
@@ -28,13 +34,22 @@ export const walk = (t, f) => {
28
34
  for (const x of Object.values(o))
29
35
  walk(x, f);
30
36
  };
37
+ // Opt-in finite markers, including a law whose universal was pulled out by prenex.
38
+ // Unsupported evaluators use this to refuse rather than approximate its domain.
39
+ export const hasFinite = (value) => {
40
+ let found = false;
41
+ walk(value, o => { if (o.finite !== undefined && (o.op === 'all' || 'holds' in o))
42
+ found = true; });
43
+ return found;
44
+ };
31
45
  // Every object in a term once (arrays too), a part shared by several uses read at its first: a witness read at each of
32
46
  // its uses in a goal is one object, and a walk of the goal written out would read it at each.
33
- export const walkOnce = (t, f) => {
47
+ export const walkOnce = (t, f, before) => {
34
48
  const seen = new Set();
35
49
  const go = (x) => {
36
50
  if (!x || typeof x !== 'object' || seen.has(x))
37
51
  return;
52
+ before?.();
38
53
  seen.add(x);
39
54
  f(x);
40
55
  for (const y of Object.values(x))
@@ -91,16 +106,16 @@ export const pointWrite = (w, where) => { if ('each' in w)
91
106
  export const noQuantifier = (where) => { throw new Error(`${where} takes no quantified flag`); };
92
107
  export { unreachable, tuple, tupleParts, part } from "../kernel/kernel.js";
93
108
  // Builders.
94
- export const x = (name) => ({ op: 'var', name });
95
- export const n = (value) => ({ op: 'const', value });
96
- export const plus = (a, b) => ({ op: 'add', a, b });
97
- export const minus = (a, b) => ({ op: 'sub', a, b });
98
- export const times = (factor, a) => ({ op: 'mul', k: factor, a });
99
- export const min = (a, b) => ({ op: 'min', a, b });
100
- export const max = (a, b) => ({ op: 'max', a, b });
101
- export const prod = (a, b) => ({ op: 'prod', a, b });
102
- export const ite = (c, then, otherwise) => ({ op: 'if', c, then, else: otherwise });
103
- export const get = (map, key) => ({ op: 'get', map, key });
109
+ export const x = (name) => (observeAst(() => ({ op: 'var', name })));
110
+ export const n = (value) => (observeAst(() => ({ op: 'const', value })));
111
+ export const plus = (a, b) => (observeAst(() => ({ op: 'add', a, b })));
112
+ export const minus = (a, b) => (observeAst(() => ({ op: 'sub', a, b })));
113
+ export const times = (factor, a) => (observeAst(() => ({ op: 'mul', k: factor, a })));
114
+ export const min = (a, b) => (observeAst(() => ({ op: 'min', a, b })));
115
+ export const max = (a, b) => (observeAst(() => ({ op: 'max', a, b })));
116
+ export const prod = (a, b) => (observeAst(() => ({ op: 'prod', a, b })));
117
+ export const ite = (c, then, otherwise) => (observeAst(() => ({ op: 'if', c, then, else: otherwise })));
118
+ export const get = (map, key) => (observeAst(() => ({ op: 'get', map, key })));
104
119
  // The pairing and its inverse as the runtimes compute them, exactly (Lean's cpair and cun): tri(a + b) + b, and back.
105
120
  export const cpair = (a, b) => { const s = a + b; return exactPair(s % 2 === 0 ? (s / 2) * (s + 1) + b : s * ((s + 1) / 2) + b); };
106
121
  const exactPair = (v) => { if (!Number.isSafeInteger(v))
@@ -115,12 +130,12 @@ export const cunpair = (z) => {
115
130
  return [s - b, b];
116
131
  };
117
132
  const tri = (s) => (s % 2 === 0 ? (s / 2) * (s + 1) : s * ((s + 1) / 2));
118
- export const less = (a, b) => ({ op: '<', a, b });
119
- export const atMost = (a, b) => ({ op: '<=', a, b });
120
- export const same = (a, b) => ({ op: '=', a, b });
121
- export const all = (...xs) => ({ op: 'and', xs });
122
- export const any = (...xs) => ({ op: 'or', xs });
123
- export const not = (c) => ({ op: 'not', x: c });
133
+ export const less = (a, b) => (observeAst(() => ({ op: '<', a, b })));
134
+ export const atMost = (a, b) => (observeAst(() => ({ op: '<=', a, b })));
135
+ export const same = (a, b) => (observeAst(() => ({ op: '=', a, b })));
136
+ export const all = (...xs) => (observeAst(() => ({ op: 'and', xs })));
137
+ export const any = (...xs) => (observeAst(() => ({ op: 'or', xs })));
138
+ export const not = (c) => (observeAst(() => ({ op: 'not', x: c })));
124
139
  export const bit = (name) => any(same(x(name), n(0)), same(x(name), n(1)));
125
140
  // --- division and remainder by a constant ------------------------------------------------------------------------
126
141
  // x div k and x mod k, for a constant k >= 1, are reads of two functions of the rule, div$k and mod$k, at x. The kernel
@@ -306,6 +321,7 @@ const exact = (v) => {
306
321
  // (a value is a number: a name like constructor or toString, read through an object's prototype, is no value of it)
307
322
  const num = (x) => (typeof x === 'number' ? x : undefined);
308
323
  export function evalE(e, env, st, m) {
324
+ observeEval();
309
325
  switch (e.op) {
310
326
  case 'var': {
311
327
  const v = num(env[e.name]) ?? num(st.scalars[e.name]);
@@ -349,6 +365,7 @@ const directCall = (d) => {
349
365
  // Arithmetic inside an equation is evaluated just as in generated code; no paired key is needed for calls.
350
366
  const memo = new Map();
351
367
  const value = (e, env) => {
368
+ observeEval();
352
369
  switch (e.op) {
353
370
  case 'const': return e.value;
354
371
  case 'var': return env[e.name];
@@ -368,6 +385,7 @@ const directCall = (d) => {
368
385
  }
369
386
  };
370
387
  const condition = (c, env) => {
388
+ observeEval();
371
389
  switch (c.op) {
372
390
  case '<': return value(c.a, env) < value(c.b, env);
373
391
  case '<=': return value(c.a, env) <= value(c.b, env);
@@ -459,6 +477,7 @@ export function pairedArgs(key, n) {
459
477
  }
460
478
  const alike = (a, b) => a === b || JSON.stringify(a) === JSON.stringify(b);
461
479
  export function evalC(c, env, st, m) {
480
+ observeEval();
462
481
  switch (c.op) {
463
482
  case '<': return evalE(c.a, env, st, m) < evalE(c.b, env, st, m);
464
483
  case '<=': return evalE(c.a, env, st, m) <= evalE(c.b, env, st, m);
@@ -468,6 +487,18 @@ export function evalC(c, env, st, m) {
468
487
  case 'not': return !evalC(c.x, env, st, m);
469
488
  case 'flag': return env[`?${c.name}`] === 1;
470
489
  case 'all': {
490
+ const finite = finiteBound(c);
491
+ if (finite) {
492
+ runtimeWall.check?.('finite quantifier');
493
+ const size = naturalIn(evalE(finite, env, st, m), `size of ${c.finite}`);
494
+ for (let key = 0; key < size; key++) {
495
+ if ((key & 255) === 0)
496
+ runtimeWall.check?.('finite quantifier');
497
+ if (!evalC(c.c, { ...env, [c.key]: key }, st, m))
498
+ return false;
499
+ }
500
+ return true;
501
+ }
471
502
  const names = boundOf(c), keys = tupleKeys(c, env, st, m);
472
503
  const go = (i, at) => (i === names.length ? evalC(c.c, at, st, m) : keys.every(key => go(i + 1, { ...at, [names[i]]: key })));
473
504
  return go(0, env);
@@ -478,6 +509,11 @@ export function evalC(c, env, st, m) {
478
509
  // (a read reads the machine's functions as they are when it runs, which a table swap changes; a quantified condition and
479
510
  // a function of several arguments go through evalC and evalE). For a term read at many rows (the engine's views).
480
511
  export function compileE(e, m) {
512
+ const run = compileENode(e, m);
513
+ // A get either charges its own node or delegates it to evalE, never both.
514
+ return e.op === 'get' ? run : (env, st) => { observeEval(); return run(env, st); };
515
+ }
516
+ function compileENode(e, m) {
481
517
  switch (e.op) {
482
518
  case 'var': {
483
519
  const name = e.name;
@@ -530,6 +566,7 @@ export function compileE(e, m) {
530
566
  const fn = m.fns?.[map];
531
567
  if (fn?.call && pairedArgs(e.key, fn.arity))
532
568
  return evalE(e, env, st, m);
569
+ observeEval();
533
570
  const k = key(env, st);
534
571
  return fn ? naturalIn(fnOf(fn)(k), `${map}(${k})`) : st.maps[map].get(k) ?? st.defaults?.[map] ?? m.maps[map];
535
572
  };
@@ -537,6 +574,11 @@ export function compileE(e, m) {
537
574
  }
538
575
  }
539
576
  export function compileC(c, m) {
577
+ const run = compileCNode(c, m);
578
+ // Quantified conditions delegate the whole evaluation to the interpreter.
579
+ return c.op === 'all' ? run : (env, st) => { observeEval(); return run(env, st); };
580
+ }
581
+ function compileCNode(c, m) {
540
582
  switch (c.op) {
541
583
  case '<': {
542
584
  const a = compileE(c.a, m), b = compileE(c.b, m);
@@ -617,7 +659,7 @@ function tupleOf(w, parts) {
617
659
  tupleWrites.set(w, (byParts = new Map()));
618
660
  let t = byParts.get(parts);
619
661
  if (!t) {
620
- const e = eachParts(w, parts), body = { op: '=', a: e.value, b: { op: 'const', value: 0 } }, free = crossFree(body, e.names);
662
+ const e = eachParts(w, parts), body = observeAst(() => ({ op: '=', a: e.value, b: observeAst(() => ({ op: 'const', value: 0 })) })), free = crossFree(body, e.names);
621
663
  t = { ...e, bs: e.names.map(name => breaksOf(free, name)), crossed: JSON.stringify(free) !== JSON.stringify(body), reads: new WeakMap() };
622
664
  byParts.set(parts, t);
623
665
  }
@@ -706,13 +748,13 @@ function unchanged(t, map, env, st, m) {
706
748
  if (typeof v !== 'boolean')
707
749
  xs.push(v);
708
750
  }
709
- return xs.length === 0 ? c.op === 'and' : xs.length === 1 ? xs[0] : { op: c.op, xs };
751
+ return xs.length === 0 ? c.op === 'and' : xs.length === 1 ? xs[0] : observeAst(() => ({ op: c.op, xs }));
710
752
  }
711
753
  return c;
712
754
  };
713
755
  const term = (e) => { if (e.op !== 'if')
714
- return e; const c = cond(e.c); return c === true ? term(e.then) : c === false ? term(e.else) : { ...e, c: c }; };
715
- const v = term(t.value), own = (e) => e.op === 'get' && e.map === map && JSON.stringify(e.key) === JSON.stringify(tuple(t.names.map((name) => ({ op: 'var', name }))));
756
+ return e; const c = cond(e.c); return c === true ? term(e.then) : c === false ? term(e.else) : observeAst(() => ({ ...e, c: c })); };
757
+ const v = term(t.value), own = (e) => e.op === 'get' && e.map === map && JSON.stringify(e.key) === JSON.stringify(tuple(t.names.map((name) => (observeAst(() => ({ op: 'var', name }))))));
716
758
  if (own(v))
717
759
  return true;
718
760
  const zeroOne = () => [...(st.maps[map]?.values() ?? [])].every(x => x === 0 || x === 1) && (st.defaults?.[map] ?? m.maps[map]) <= 1;
@@ -732,7 +774,7 @@ function runnable(m) {
732
774
  export function leastsIn(m, env, st) {
733
775
  const out = {};
734
776
  for (const [name, l] of Object.entries(m.leasts ?? {})) {
735
- const keys = keysAt(st, mapsIn({ op: 'and', xs: [l.where, ...l.by.flatMap(b => [b.e, ...(b.neg ? [b.neg] : [])].map(e => ({ op: '=', a: e, b: e })))] }).filter(mp => !m.fns?.[mp])), past = keys.pop();
777
+ const keys = keysAt(st, mapsIn(observeAst(() => ({ op: 'and', xs: [l.where, ...l.by.flatMap(b => [b.e, ...(b.neg ? [b.neg] : [])].map(e => (observeAst(() => ({ op: '=', a: e, b: e })))))] }))).filter(mp => !m.fns?.[mp])), past = keys.pop();
736
778
  const at = (key) => ({ ...env, ...out, [l.key]: key });
737
779
  if (evalC(l.where, at(past), st, m))
738
780
  throw new RangeError(`${m.name}: ${name} has no least (its condition holds at every key past the cells)`);
@@ -968,7 +1010,7 @@ export function compileJs(m) { return compileJsMode(m, false); }
968
1010
  function compileJsMode(m, persistent, cells) {
969
1011
  const { h, plain, queries, carried } = runnable(m);
970
1012
  // (a condition or a write at every key over a tuple key: the interpreter decides those, part by part)
971
- const atEvery = [...Object.values(plain.step.flags ?? {}).filter(c => c.op === 'all'), ...Object.values(plain.step.maps ?? {}).filter(w => 'each' in w)];
1013
+ const atEvery = [...Object.values(plain.step.flags ?? {}).filter(c => c.op === 'all' && c.finite === undefined), ...Object.values(plain.step.maps ?? {}).filter(w => 'each' in w)];
972
1014
  const arity = mapArities(plain);
973
1015
  if (JSON.stringify(atEvery).includes('"op":"tup"') || Object.entries(plain.step.maps ?? {}).some(([map, w]) => 'each' in w && (arity[map] ?? 1) > 1))
974
1016
  throw new Error(`${m.name}: compileJs takes no tuple key at every key (interpret runs it)`);
@@ -1007,6 +1049,14 @@ function compileJsMode(m, persistent, cells) {
1007
1049
  case 'not': return `(!${cx(c.x)})`;
1008
1050
  case 'flag': return `flag${flags.indexOf(c.name)}`;
1009
1051
  case 'all': {
1052
+ const finite = finiteBound(c);
1053
+ if (finite) {
1054
+ const size = ex(finite), outer = bound;
1055
+ bound = { ...bound, [c.key]: 'fk' };
1056
+ const body = cx(c.c);
1057
+ bound = outer;
1058
+ return `(fn => { $finite(); for (let fk = 0; fk < fn; fk++) { if ((fk & 255) === 0) $finite(); if (!${body}) return false; } return true; })($n(${size}, ${id(`size of ${c.finite}`)}))`;
1059
+ }
1010
1060
  const names = boundOf(c), ks = names.map((_, i) => (i ? `k${i}` : 'k')), keys = names.length === 1 ? keysJs(c.c, c.key) : tupleJs(c), outer = bound;
1011
1061
  bound = { ...bound, ...Object.fromEntries(names.map((n, i) => [n, ks[i]])) };
1012
1062
  const body = cx(c.c);
@@ -1074,7 +1124,7 @@ function compileJsMode(m, persistent, cells) {
1074
1124
  bound = { ...bound, [l.key]: 'lk' };
1075
1125
  const where = cx(l.where), by = l.by.map(b => (b.neg ? `(${ex(b.e)} - ${ex(b.neg)})` : ex(b.e)));
1076
1126
  bound = outer;
1077
- const ms = mapsIn({ op: 'and', xs: [l.where, ...l.by.flatMap(b => [b.e, ...(b.neg ? [b.neg] : [])].map(e => ({ op: '=', a: e, b: e })))] }).filter(mp => !fns.includes(mp));
1127
+ const ms = mapsIn(observeAst(() => ({ op: 'and', xs: [l.where, ...l.by.flatMap(b => [b.e, ...(b.neg ? [b.neg] : [])].map(e => (observeAst(() => ({ op: '=', a: e, b: e })))))] }))).filter(mp => !fns.includes(mp));
1078
1128
  const better = l.by.map((b, i) => `by[${i}] !== bb[${i}] ? by[${i}] ${b.desc ? '>' : '<'} bb[${i}] : `).join('') + 'false';
1079
1129
  lines.push(`{ const ks = $keys(maps, ${JSON.stringify(ms)}), past = ks.pop(); let lk = past; if (${where}) throw new RangeError(${id(`${m.name}: ${name} has no least (its condition holds at every key past the cells)`)}); let bk, bb; for (lk of ks.sort((a, b) => a - b)) { if (!(${where})) continue; const by = [${by.join(', ')}]; if (bk === undefined || (${better})) { bk = lk; bb = by; } } env[${id(name)}] = bk ?? 0; env[${id(l.some)}] = bk === undefined ? 0 : 1; }`);
1080
1130
  }
@@ -1118,7 +1168,7 @@ function compileJsMode(m, persistent, cells) {
1118
1168
  export function fork(state) {
1119
1169
  return {scalars: {...state.scalars}, maps: Object.fromEntries(Object.entries(state.maps).map(([name, cells]) => [name, new Map(cells)])), ...(state.defaults ? {defaults: {...state.defaults}} : {})${h ? ', history: state.history.slice(state.head), head: 0, last: state.last' : ''}};
1120
1170
  }
1121
- export function step(params, state, input) {
1171
+ export function step(params, state, input${hasFinite(plain) ? ', $finite = () => { throw new Error("finite sort step requires a cancellation callback"); }' : ''}) {
1122
1172
  ${lines.join('\n ')}
1123
1173
  }
1124
1174
  `;
@@ -1133,11 +1183,24 @@ export function compileFunction(params, body) {
1133
1183
  return new Function(...params, body);
1134
1184
  }
1135
1185
  export const loadJs = (m) => loadJsMode(m, false);
1136
- const loadJsMode = (m, persistent, cells) => compileFunction([], `${compileJsMode(m, persistent, cells).replace(/^export function/gm, 'function')}\nreturn {init, fork, step${cells ? ', cells' : ''}}`)();
1186
+ const loadJsMode = (m, persistent, cells) => {
1187
+ const js = compileFunction([], `${compileJsMode(m, persistent, cells).replace(/^export function/gm, 'function')}\nreturn {init, fork, step${cells ? ', cells' : ''}}`)();
1188
+ if (hasFinite(m)) {
1189
+ // Standalone generated modules require an explicit cooperative callback.
1190
+ // The loaded runtime uses the same cancellation bridge as the interpreter.
1191
+ const step = js.step;
1192
+ js.step = (params, st, input, check = () => runtimeWall.check?.('finite quantifier')) => step(params, st, input, check);
1193
+ }
1194
+ return js;
1195
+ };
1137
1196
  // The interpreter's step (persistent: a copy of the state each) through loadJs's, several times faster, a request's counts
1138
1197
  // given to it as maps the request carries (carriedView's, each cell its sum when read); none with a history, or where the
1139
1198
  // generator refuses the machine.
1140
1199
  export function fastStep(m) {
1200
+ // Its static per-step charge cannot account for a parameter-sized loop.
1201
+ // Proof-time callers must use the interruptible, per-node interpreter instead.
1202
+ if (hasFinite(m))
1203
+ return undefined;
1141
1204
  // (the counts the step itself reads, in its guards, flags, writes or assumption: a count only a law reads is never
1142
1205
  // computed for a step; a count's body may read another count, so the closure is taken)
1143
1206
  const all = m.counts ?? {}, read = new Set();
@@ -1164,8 +1227,16 @@ export function fastStep(m) {
1164
1227
  catch {
1165
1228
  return undefined;
1166
1229
  }
1167
- const only = cs.length ? { ...m, counts: decls } : m, tick = () => runtimeWall.check?.('derived count');
1230
+ let stepEvals = 0;
1231
+ walk([m.step, m.assume ?? null, m.leasts ?? null], o => { if (typeof o.op === 'string')
1232
+ stepEvals++; });
1233
+ const only = cs.length ? { ...m, counts: decls } : m, tick = () => { if (completeWorkProfile.enabled)
1234
+ startWork('ticks', 1, 'derived count');
1235
+ else
1236
+ coreMeter.ticks += 1; runtimeWall.check?.('derived count'); };
1168
1237
  return (params, st, input) => {
1238
+ // Section 18's static expression-node charge per compiled step invocation.
1239
+ observeEval(stepEvals, true);
1169
1240
  if (!cs.length)
1170
1241
  return js.step(params, st, input);
1171
1242
  const view = compiledCells ? js.cells(params, st, input, tick) : carriedView(only, st, input, undefined, params).maps, carried = { ...input };
@@ -1250,7 +1321,7 @@ function symC(c, s, truth) {
1250
1321
  // PROVE_DEBUG=1 logs the case counts to stderr; read through globalThis so the module also loads where there is no process.
1251
1322
  const proveDebug = !!env.PROVE_DEBUG;
1252
1323
  const debug = (label, n) => { if (proveDebug)
1253
- console.error(`[prove] ${label}: ${n} (${Math.round(performance.now())} ms)`); };
1324
+ console.error(`[prove] ${label}: ${n} (${Math.round(traceNow())} ms)`); };
1254
1325
  // Drops the cases whose path is already impossible, so impossible branches don't multiply.
1255
1326
  function feasible(cases) {
1256
1327
  return cases.filter(c => {
@@ -1332,8 +1403,8 @@ export function prove(m, goal, invariants = [goal]) {
1332
1403
  // Keys first: how each key the step reads or writes compares with each focus key of the same map, decided once.
1333
1404
  const stepReads = [
1334
1405
  ...Object.values(m.step.flags ?? {}).flatMap(readsOf),
1335
- ...Object.values(m.step.state ?? {}).flatMap(e => readsOf({ op: '=', a: e, b: e })),
1336
- ...Object.entries(m.step.maps ?? {}).flatMap(([map, w]) => [...('each' in w ? [] : [{ map, key: w.key }]), ...readsOf({ op: '=', a: w.value, b: w.value })]),
1406
+ ...Object.values(m.step.state ?? {}).flatMap(e => readsOf(observeAst(() => ({ op: '=', a: e, b: e })))),
1407
+ ...Object.entries(m.step.maps ?? {}).flatMap(([map, w]) => [...('each' in w ? [] : [{ map, key: w.key }]), ...readsOf(observeAst(() => ({ op: '=', a: w.value, b: w.value })))]),
1337
1408
  ];
1338
1409
  const pairs = new Map();
1339
1410
  for (const r of stepReads) {
@@ -1411,6 +1482,9 @@ function renameKey(lin, from, to) {
1411
1482
  export function search(m, law, depth = 3, bound = 2) {
1412
1483
  const run = interpret(m);
1413
1484
  const holds = (params, st) => {
1485
+ const finite = finiteLawBound(law);
1486
+ if (finite)
1487
+ return evalC({ op: 'all', key: law.forall, c: law.holds, finite: law.finite }, params, st, m);
1414
1488
  const keys = law.forall ? [...new Set([0, ...Object.values(st.maps).flatMap(cells => [...cells.keys()])])] : [0];
1415
1489
  return keys.every(key => evalC(law.holds, { ...params, ...(law.forall ? { [law.forall]: key } : {}) }, st, m));
1416
1490
  };
@@ -0,0 +1,22 @@
1
+ export declare const coreMeter: {
2
+ tableCells: number;
3
+ checkSteps: number;
4
+ astNodes: number;
5
+ evals: number;
6
+ cubeTests: number;
7
+ ticks: number;
8
+ tinyNodes: number;
9
+ tinyTerms: number;
10
+ reachStates: number;
11
+ reachEdges: number;
12
+ reachEvals: number;
13
+ reachCompiledEvals: number;
14
+ };
15
+ export declare function observeAst<T>(build: () => T): T;
16
+ export declare function observeTableCells(count?: number): void;
17
+ export declare function observeCheckStep(): void;
18
+ export declare function observeCubeTest(): void;
19
+ export declare function observeLinearRows(rows: readonly Record<string, number>[]): void;
20
+ export declare function observeConstraintRows(rows: readonly {
21
+ lin: Record<string, number>;
22
+ }[], start?: number): void;
@@ -0,0 +1,34 @@
1
+ import { completeWorkProfile } from "./work-profile.js";
2
+ import { startWork, workCounterView } from "./work-admission.js";
3
+ // Numeric views are compatibility telemetry. In full mode only the central
4
+ // lease can update a counter while a bounded work scope is active.
5
+ export const coreMeter = workCounterView({ tableCells: 0, checkSteps: 0, astNodes: 0, evals: 0, cubeTests: 0, ticks: 0, tinyNodes: 0, tinyTerms: 0, reachStates: 0, reachEdges: 0, reachEvals: 0, reachCompiledEvals: 0 }, { tableCells: 'tableCells', checkSteps: 'checkSteps', astNodes: 'astNodes', evals: 'evals', cubeTests: 'cubeTests', ticks: 'ticks', tinyNodes: 'tinyNodes', tinyTerms: 'tinyTerms', reachStates: 'reachStates', reachEdges: 'reachEdges', reachEvals: 'reachEvals', reachCompiledEvals: 'reachCompiledEvals' });
6
+ // The factory is intentional: a post-allocation observer is too late. Child
7
+ // constructors have their own admissions; started work is never refunded.
8
+ export function observeAst(build) {
9
+ if (completeWorkProfile.enabled) {
10
+ startWork('astNodes', 1, 'AST allocation');
11
+ return build();
12
+ }
13
+ const node = build();
14
+ coreMeter.astNodes++;
15
+ return node;
16
+ }
17
+ export function observeTableCells(count = 1) { if (completeWorkProfile.enabled)
18
+ startWork('tableCells', count, 'table cells'); }
19
+ export function observeCheckStep() { if (completeWorkProfile.enabled)
20
+ startWork('checkSteps', 1, 'native check step'); }
21
+ export function observeCubeTest() { if (completeWorkProfile.enabled)
22
+ startWork('cubeTests', 1, 'cube test'); }
23
+ export function observeLinearRows(rows) {
24
+ if (completeWorkProfile.enabled)
25
+ for (const row of rows)
26
+ for (const key in row)
27
+ if (Object.hasOwn(row, key))
28
+ observeTableCells();
29
+ }
30
+ export function observeConstraintRows(rows, start = 0) {
31
+ if (completeWorkProfile.enabled)
32
+ for (let i = start; i < rows.length; i++)
33
+ observeLinearRows([rows[i].lin]);
34
+ }
@@ -1,3 +1,4 @@
1
+ import { traceNow as countedTraceNow, searchNow as countedSearchNow } from "./wall.js";
1
2
  // Runs that never end, found: the search behind `proveNeverEnds`. Untrusted, like prove.ts: what it finds is a closed
2
3
  // recurrent set with its successor given (kernel.ts's Recur), checked by kernel.ts's checkRecur and, exported, by
3
4
  // NonTerm.lean's never_ends_of.
@@ -304,10 +305,10 @@ export function findNeverEnds(l, opts = {}) {
304
305
  return opts.counted ? counted(opts.counted, () => search(l, opts)) : search(l, opts);
305
306
  }
306
307
  function search(l, opts) {
307
- const wall0 = performance.now(), now = clock, t0 = now(), until = t0 + (opts.ms ?? 10_000), maxTurns = opts.maxTurns ?? 400;
308
+ const wall0 = countedTraceNow(), now = clock, t0 = now(), until = t0 + (opts.ms ?? 10_000), maxTurns = opts.maxTurns ?? 400;
308
309
  const rand = seeded(opts.seed ?? 7);
309
310
  const stats = { runs: 0, turns: 0, policies: 0, rounds: 0, ms: 0, lassoTried: 0, goalSize: 0, accel: 0, accelClosed: 0 };
310
- const done = (v) => ({ ...v, stats: { ...stats, ms: Math.round(performance.now() - wall0) } });
311
+ const done = (v) => ({ ...v, stats: { ...stats, ms: Math.round(countedTraceNow() - wall0) } });
311
312
  const stateNames = Object.keys(l.state), kept = [...l.params, ...stateNames];
312
313
  const allObs = observables(kept), inObs = observables(l.inputs);
313
314
  // The modes: state variables compared with a constant by `=` in the loop's conditions (a translated task's pc).
@@ -508,7 +509,7 @@ function search(l, opts) {
508
509
  }
509
510
  if (!stems.length && now() < until) {
510
511
  const left = Math.min(until - now(), 2000);
511
- const run = findBoundedRun(m, [{ name: 'outside the set', holds: { op: 'not', x: a.set } }], { ms: left, depth: 24, ...(opts.counted ? {} : { wall: performance.now() + left }) });
512
+ const run = findBoundedRun(m, [{ name: 'outside the set', holds: { op: 'not', x: a.set } }], { ms: left, depth: 24, ...(opts.counted ? {} : { wall: countedSearchNow() + left }) });
512
513
  const c = run && cut({ params: run.params, stem: run.trace.map(r => Object.fromEntries(l.inputs.map(n => [n, Number(r[n] ?? 0)]))) });
513
514
  if (c)
514
515
  stems.push(c);
@@ -0,0 +1,53 @@
1
+ import type { Machine, Law } from './machine.js';
2
+ import type { Instances, Tree } from '../kernel/kernel.js';
3
+ export type ProofOutputNode = {
4
+ kind: 'counted';
5
+ machine: Machine;
6
+ laws: Law[];
7
+ proof: {
8
+ instances: Record<string, Instances>;
9
+ certs: Record<string, import('../kernel/kernel.ts').CountCert>;
10
+ };
11
+ } | {
12
+ kind: 'usual';
13
+ machine: Machine;
14
+ laws: Law[];
15
+ proof: {
16
+ instances: Record<string, Instances>;
17
+ trees: Record<string, Tree>;
18
+ };
19
+ } | {
20
+ kind: 'derived';
21
+ parents: (ProofOutputNode | undefined)[];
22
+ context: unknown;
23
+ };
24
+ export type PublicProofOutput = {
25
+ result: object;
26
+ original: {
27
+ machine: Machine;
28
+ laws: Law[];
29
+ };
30
+ proof: ProofOutputNode | undefined;
31
+ };
32
+ export declare function withPublicRule<T>(run: (outermost: boolean) => T): T;
33
+ export declare const proofOutput: {
34
+ on?: (event: PublicProofOutput) => void;
35
+ };
36
+ export declare function retainFamily<T extends {
37
+ proven: boolean;
38
+ checked: boolean;
39
+ }>(result: T, machine: Machine, laws: Law[], proof: {
40
+ instances: Record<string, Instances>;
41
+ trees: Record<string, Tree>;
42
+ } | undefined): T;
43
+ export declare function retainCounted<T extends object>(result: T, family: {
44
+ proven: boolean;
45
+ m: Machine;
46
+ laws: Law[];
47
+ proof?: {
48
+ instances: Record<string, Instances>;
49
+ certs: Record<string, import('../kernel/kernel.ts').CountCert>;
50
+ };
51
+ }): T;
52
+ export declare function retainFrom<T extends object>(result: T, parents: object[], context?: unknown): T;
53
+ export declare function publishProof<T extends object>(result: T, machine: Machine, laws: Law[]): T;
@@ -0,0 +1,38 @@
1
+ // Synchronous public rule invocations can recursively prove a Skolem family.
2
+ let publicRuleDepth = 0;
3
+ export function withPublicRule(run) {
4
+ const outermost = publicRuleDepth++ === 0;
5
+ try {
6
+ return run(outermost);
7
+ }
8
+ finally {
9
+ publicRuleDepth--;
10
+ }
11
+ }
12
+ let observer;
13
+ let records = new WeakMap();
14
+ // Every installation/clear starts a fresh custody window, even if a callback
15
+ // function is reused. Results from a previous invocation cannot be inherited.
16
+ export const proofOutput = {
17
+ get on() { return observer; },
18
+ set on(value) { records = new WeakMap(); observer = value; }
19
+ };
20
+ export function retainFamily(result, machine, laws, proof) {
21
+ if (proofOutput.on && result.proven && result.checked && proof)
22
+ records.set(result, { kind: 'usual', machine, laws, proof });
23
+ return result;
24
+ }
25
+ export function retainCounted(result, family) {
26
+ if (proofOutput.on && family.proven && family.proof)
27
+ records.set(result, { kind: 'counted', machine: family.m, laws: family.laws, proof: family.proof });
28
+ return result;
29
+ }
30
+ export function retainFrom(result, parents, context = { kind: 'projection' }) {
31
+ if (proofOutput.on)
32
+ records.set(result, { kind: 'derived', parents: parents.map(parent => records.get(parent)), context });
33
+ return result;
34
+ }
35
+ export function publishProof(result, machine, laws) {
36
+ proofOutput.on?.({ result, original: { machine, laws }, proof: records.get(result) });
37
+ return result;
38
+ }
@@ -0,0 +1,3 @@
1
+ import { type Constraint } from './solver.js';
2
+ import { type Goal, type Path } from '../kernel/kernel.js';
3
+ export declare function budgetedLeafRows(goal: Goal, path: Path): Constraint[];
@@ -0,0 +1,106 @@
1
+ import { observeTableCells } from "./meter.js";
2
+ import { admittedLinearCopy as rowCopy, admittedLinearSub as rowSub, admittedLinearScale as rowScale, admittedLinearAdd as rowAdd, admittedLinearVariable as rowVariable, visitLinearCells } from "./linear-admission.js";
3
+ import { checkWorkEndpoint } from "./wall.js";
4
+ import { withTableAdmission } from "./table-admission.js";
5
+ import { workFlatMap, workFilter, workMap, workSetArray } from "./work-collections.js";
6
+ import { canon, canonFlip, cellParts, facts, isCell, reusing, termRows, truth } from "../kernel/kernel.js";
7
+ const seenFacts = new WeakMap();
8
+ function proposedFacts(c, path, positive = true) {
9
+ checkWorkEndpoint('row hypothesis');
10
+ if (c.op === 'not')
11
+ return proposedFacts(c.x, path, !positive);
12
+ if (c.op === 'and' || c.op === 'or') {
13
+ if ((c.op === 'and') === positive)
14
+ return workFlatMap(c.xs, y => proposedFacts(y, path, positive), 'proposedFacts:conjunction');
15
+ const open = workFilter(c.xs, y => { checkWorkEndpoint('row disjunction'); return truth(y, path) !== !positive; }, 'proposedFacts:disjunction');
16
+ return open.length === 0 ? [rowVariable('1', 1, 'proposedFacts:false')] : open.length === 1 ? proposedFacts(open[0], path, positive) : [];
17
+ }
18
+ return facts(c, path, positive);
19
+ }
20
+ // Same integer-path comparison as the reference row builder, outside its
21
+ // private memo state. This only proposes rows; their use is checked later.
22
+ function decided(lin, path) {
23
+ checkWorkEndpoint('row key comparison');
24
+ observeTableCells();
25
+ let constant = true;
26
+ for (const key in lin) {
27
+ checkWorkEndpoint('row key coefficient');
28
+ observeTableCells(key.length + 1);
29
+ if (!Number.isSafeInteger(lin[key]))
30
+ return undefined;
31
+ if (key !== '1')
32
+ constant = false;
33
+ }
34
+ if (constant)
35
+ return (lin['1'] ?? 0) <= 0;
36
+ const direct = path.get(canon(lin))?.holds;
37
+ if (direct !== undefined)
38
+ return direct;
39
+ const flipped = path.get(canonFlip(lin))?.holds;
40
+ return flipped === undefined ? undefined : !flipped;
41
+ }
42
+ function sameKey(p, q, path) {
43
+ const zero = (a, b) => { const d = rowSub(a, b, 'row-key:subtract'); return decided(d, path) === true && decided(rowScale(d, -1, 'row-key:flip'), path) === true; };
44
+ if (p.key && q.key)
45
+ return zero(p.key, q.key);
46
+ return !!p.keys && !!q.keys && p.keys.length === q.keys.length && p.keys.every((a, i) => zero(a, q.keys[i]));
47
+ }
48
+ export function budgetedLeafRows(goal, path) {
49
+ return withTableAdmission(() => budgetedLeafRowsIn(goal, path));
50
+ }
51
+ function budgetedLeafRowsIn(goal, path) {
52
+ let byHyp = seenFacts.get(goal);
53
+ if (!byHyp)
54
+ seenFacts.set(goal, (byHyp = new Map()));
55
+ const rows = [];
56
+ // Own the coefficient plan and start each output before materializing it.
57
+ // Failed discovery/emission stays charged; no completed-row post-observer.
58
+ const put = (row) => { checkWorkEndpoint('row append'); rows.push({ ...row, lin: rowCopy(row.lin, 'proposedRows:copy') }); checkWorkEndpoint('row appended'); };
59
+ let atom = 0;
60
+ for (const a of path.values())
61
+ put({ lin: a.holds ? a.lin : rowAdd(rowVariable('1', 1, 'proposedRows:one'), rowScale(a.lin, -1, 'proposedRows:negate'), 'proposedRows:flip'), label: '', src: { atom: atom++ } });
62
+ for (const [i, h] of goal.hyps.entries()) {
63
+ checkWorkEndpoint('row hypothesis entry');
64
+ let seen = byHyp.get(h);
65
+ if (!seen)
66
+ byHyp.set(h, (seen = {}));
67
+ for (const lin of reusing(seen, path, p => proposedFacts(h, p)))
68
+ put({ lin, label: '', src: { fact: i } });
69
+ }
70
+ const names = new Set();
71
+ for (const row of rows)
72
+ visitLinearCells(row.lin, key => { if (key !== '1')
73
+ names.add(key); }, 'proposedRows:names');
74
+ const cells = workMap(workFilter(workSetArray(names, 'proposedRows:names-copy'), isCell, 'proposedRows:cell-filter'), name => { checkWorkEndpoint('row cell'); return { name, ...cellParts(name) }; }, 'proposedRows:cell-parts');
75
+ for (let i = 0; i < cells.length; i++)
76
+ for (let j = i + 1; j < cells.length; j++) {
77
+ const p = cells[i], q = cells[j];
78
+ checkWorkEndpoint('row cell pair');
79
+ observeTableCells();
80
+ if (p.map !== q.map || !sameKey(p, q, path))
81
+ continue;
82
+ const pr = rowVariable(p.name, 1, 'proposedRows:pair-p'), qr = rowVariable(q.name, 1, 'proposedRows:pair-q');
83
+ put({ lin: rowSub(pr, qr, 'proposedRows:pair-left'), label: '', src: { pair: [p.name, q.name] } });
84
+ put({ lin: rowSub(qr, pr, 'proposedRows:pair-right'), label: '', src: { pair: [p.name, q.name] } });
85
+ }
86
+ const seen = new Set(), todo = workFilter(workSetArray(names, 'proposedRows:todo-copy'), n => n.startsWith('⟦'), 'proposedRows:todo-filter');
87
+ while (todo.length) {
88
+ checkWorkEndpoint('row term');
89
+ const name = todo.pop();
90
+ if (seen.has(name))
91
+ continue;
92
+ seen.add(name);
93
+ for (const lin of termRows(name, path)) {
94
+ put({ lin, label: '', src: { term: name } });
95
+ visitLinearCells(lin, key => { if (key !== '1') {
96
+ names.add(key);
97
+ if (key.startsWith('⟦') && !seen.has(key))
98
+ todo.push(key);
99
+ } }, 'proposedRows:term-names');
100
+ }
101
+ }
102
+ for (const name of names)
103
+ put({ lin: rowVariable(name, -1, 'proposedRows:natural'), label: '', src: { nat: name } });
104
+ checkWorkEndpoint('row completion');
105
+ return rows;
106
+ }
@@ -1,5 +1,25 @@
1
1
  import { type Law, type Machine } from './machine.js';
2
- export declare function quorumLaws(m: Machine): {
2
+ export type QuorumLawProvenance = {
3
+ kind: 'stored-row-guard';
4
+ formula: string;
5
+ guard: string;
6
+ guardFormula: string;
7
+ membershipMap: string;
8
+ rowInput: string;
9
+ rowCount: string;
10
+ requestSet: string;
11
+ width: number;
12
+ halves: string[];
13
+ disabled: boolean;
14
+ twins: {
15
+ request: string;
16
+ row: string;
17
+ key: string;
18
+ }[];
19
+ definitions: Record<string, string>;
20
+ };
21
+ export declare function quorumLawProvenance(law: Law): Readonly<QuorumLawProvenance> | undefined;
22
+ export declare function quorumLaws(m: Machine, provenance?: boolean): {
3
23
  counts: NonNullable<Machine['counts']>;
4
24
  laws: Law[];
5
25
  };