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,418 @@
1
+ // One work bank. The counter vector and F are authoritative exact integers on
2
+ // the frozen coefficient lattice; endpoints may be arbitrary exact rationals.
3
+ import { completeWorkProfile } from "./work-profile.js";
4
+ import { legacyWeights, workKeys } from "./work-kinds.js";
5
+ import { commonWorkDenominator, compareWork, exactRaw, minWork, workAdd, workAmount, workFromNumber, workShare, workSub, workToNumber, zeroWork } from "./work-amount.js";
6
+ export class BudgetExpired extends Error {
7
+ phase;
8
+ constructor(phase) {
9
+ super(`work budget (${phase})`);
10
+ this.phase = phase;
11
+ this.name = 'BudgetExpired';
12
+ }
13
+ }
14
+ const nextEpoch = (n) => {
15
+ if (!Number.isSafeInteger(n) || n < 0 || n === Number.MAX_SAFE_INTEGER)
16
+ throw new RangeError('work epoch exhausted');
17
+ return n + 1;
18
+ };
19
+ const natural = (n) => {
20
+ if (!Number.isSafeInteger(n) || n < 0)
21
+ throw new RangeError('work count must be a nonnegative safe integer');
22
+ return BigInt(n);
23
+ };
24
+ const synchronous = (value) => {
25
+ if (value && typeof value === 'object' && 'then' in value)
26
+ throw new TypeError('work leases and scopes must be synchronous');
27
+ return value;
28
+ };
29
+ export class WorkLedger {
30
+ weights;
31
+ denominator;
32
+ units;
33
+ counters = Object.fromEntries(workKeys.map(key => [key, 0n]));
34
+ consumed = 0n;
35
+ held = 0n;
36
+ scopes = [];
37
+ leases = new Set();
38
+ observers = [];
39
+ baseline = null;
40
+ rootEpoch = 0;
41
+ scopeEpoch = 0;
42
+ counterEpoch = 0;
43
+ leaseSequence = 0;
44
+ endpointSequence = 0;
45
+ eventSequence = 0;
46
+ notifying = false;
47
+ capacityErrors = new WeakMap();
48
+ capacityBoundaries = [];
49
+ deadlineRefusalOwners = new WeakMap();
50
+ constructor(weights) {
51
+ if (Object.keys(weights).length !== workKeys.length || workKeys.some(key => !Object.hasOwn(weights, key) || !Number.isFinite(weights[key]) || weights[key] < 0))
52
+ throw new RangeError('work ledger requires the exact frozen coefficient vector');
53
+ this.weights = Object.freeze(Object.fromEntries(workKeys.map(key => [key, workFromNumber(weights[key])])));
54
+ this.denominator = commonWorkDenominator(Object.values(this.weights));
55
+ this.units = Object.freeze(Object.fromEntries(workKeys.map(key => [key, this.weights[key].num * (this.denominator / this.weights[key].den)])));
56
+ }
57
+ actual() { return workAmount(this.consumed, this.denominator); }
58
+ reserved() { return workAmount(this.held, this.denominator); }
59
+ bounded() { return this.scopes.length > 0; }
60
+ inBudget() { return this.scopes.some(scope => scope.kind === 'root'); }
61
+ check(phase) { this.checkEntry(); this.invariant(); void phase; }
62
+ checkAmount(amount, phase) {
63
+ this.checkEntry();
64
+ if (amount.den <= 0n || amount.num < 0n)
65
+ throw new RangeError('invalid work admission amount');
66
+ const left = this.available();
67
+ if (left !== null && compareWork(amount, left) > 0) {
68
+ this.emit('refuse', { site: phase });
69
+ throw this.capacityError(phase, 'check', amount);
70
+ }
71
+ }
72
+ counter(key) { return this.counters[key]; }
73
+ currentScope() {
74
+ const scope = this.scopes[this.scopes.length - 1];
75
+ return scope && Object.freeze({ id: scope.id, kind: scope.kind, end: exactRaw(scope.end) });
76
+ }
77
+ // Only this ledger can authenticate its own capacity failures. Error text,
78
+ // stale leases and exceptions from native/observer code confer no provenance.
79
+ capacityRefusal(error) {
80
+ return typeof error === 'object' && error !== null ? this.capacityErrors.get(error) : undefined;
81
+ }
82
+ // Opt-in observation only: no endpoint, allowance, counter or lease changes.
83
+ // Preserve the first genuine refusal even when a nested checker catches it.
84
+ withCapacityRefusalBoundary(run) {
85
+ const boundary = {};
86
+ this.capacityBoundaries.push(boundary);
87
+ try {
88
+ const value = synchronous(run());
89
+ if (boundary.error)
90
+ throw boundary.error;
91
+ return value;
92
+ }
93
+ catch (error) {
94
+ throw boundary.error ?? error;
95
+ }
96
+ finally {
97
+ this.capacityBoundaries.pop();
98
+ }
99
+ }
100
+ // A stage can consume only its own deadline refusal. No allowance is reset:
101
+ // the existing endpoint machinery owns admission, leases and scope cleanup.
102
+ // Remember fatal refusals separately: native code may catch a soft refusal,
103
+ // keep running, and subsequently catch a root/ancestor refusal as well.
104
+ withDeadlineRefusalBoundary(end, run, refused) {
105
+ const boundary = {};
106
+ this.capacityBoundaries.push(boundary);
107
+ try {
108
+ return this.enterEndpoint('deadline', end, () => {
109
+ const value = synchronous(run());
110
+ if (boundary.fatal ?? boundary.error)
111
+ throw boundary.fatal ?? boundary.error;
112
+ return value;
113
+ }, boundary);
114
+ }
115
+ catch (error) {
116
+ const pending = boundary.fatal ?? error;
117
+ if (typeof pending !== 'object' || pending === null || this.deadlineRefusalOwners.get(pending) !== boundary)
118
+ throw pending;
119
+ }
120
+ finally {
121
+ this.capacityBoundaries.pop();
122
+ }
123
+ // Outside both the endpoint and its guard; fallback is not free work inside
124
+ // an expired allocation and cannot hide a new refusal raised by itself.
125
+ return synchronous(refused());
126
+ }
127
+ capacityError(phase, reason, requested, entering) {
128
+ const error = new BudgetExpired(phase), active = entering ? [...this.scopes, entering] : this.scopes;
129
+ let end = null;
130
+ for (const scope of active)
131
+ end = end === null ? scope.end : minWork(end, scope.end);
132
+ const limiting = active.filter(scope => end !== null && compareWork(scope.end, end) === 0)
133
+ .map(scope => Object.freeze({ id: scope.id, kind: scope.kind, end: exactRaw(scope.end) }));
134
+ this.capacityErrors.set(error, Object.freeze({ reason, limiting: Object.freeze(limiting),
135
+ actual: exactRaw(this.actual()), reserved: exactRaw(this.reserved()),
136
+ ...(requested ? { requested: exactRaw(requested) } : {}) }));
137
+ // Classify against the live ancestry now, not the unwound catch stack.
138
+ // Descendant DEADLINE mirrors may share the owned limit. An ancestor tie,
139
+ // a root/scope/work-cap, or a stricter descendant is not ours to consume.
140
+ for (let i = this.capacityBoundaries.length - 1; i >= 0; i--) {
141
+ const boundary = this.capacityBoundaries[i], owned = boundary.deadline;
142
+ const ownerIndex = owned ? active.findIndex(scope => scope.id === owned.id) : -1;
143
+ const owns = owned && ownerIndex >= 0 && limiting.some(scope => scope.id === owned.id)
144
+ && limiting.every(scope => scope.kind === 'deadline' && active.findIndex(at => at.id === scope.id) >= ownerIndex);
145
+ boundary.error ??= error;
146
+ if (owns) {
147
+ this.deadlineRefusalOwners.set(error, boundary);
148
+ break; // An accepted local stop must not poison enclosing sticky guards.
149
+ }
150
+ if (owned)
151
+ boundary.fatal ??= error;
152
+ }
153
+ return error;
154
+ }
155
+ endpoint() {
156
+ let end = null;
157
+ for (const scope of this.scopes)
158
+ end = end === null ? scope.end : minWork(end, scope.end);
159
+ return end;
160
+ }
161
+ available() {
162
+ const end = this.endpoint();
163
+ return end === null ? null : workSub(end, workAmount(this.consumed + this.held, this.denominator));
164
+ }
165
+ vector() { return Object.freeze(Object.fromEntries(workKeys.map(key => [key, String(this.counters[key])]))); }
166
+ snapshot() {
167
+ const end = this.endpoint();
168
+ return Object.freeze({ version: 'strict-work-v1', rootEpoch: this.rootEpoch, scopeEpoch: this.scopeEpoch, counterEpoch: this.counterEpoch,
169
+ actual: exactRaw(this.actual()), reserved: exactRaw(this.reserved()), effectiveEnd: end === null ? null : exactRaw(end),
170
+ activeEndpoints: Object.freeze(this.scopes.map(scope => Object.freeze({ id: scope.id, kind: scope.kind, end: exactRaw(scope.end) }))),
171
+ weights: Object.freeze(Object.fromEntries(workKeys.map(key => [key, exactRaw(this.weights[key])]))),
172
+ rootBaseline: this.baseline, counters: this.vector() });
173
+ }
174
+ // Write-only diagnostic view; no restore/reset path or new allocation.
175
+ // Preserve private live state as data, including zero-weight lease identity.
176
+ diagnosticCheckpoint() {
177
+ return { version: 'work-diagnostic/v1', ledger: this.snapshot(),
178
+ lattice: { denominator: this.denominator, units: { ...this.units } },
179
+ raw: { consumed: this.consumed, held: this.held, counters: { ...this.counters } },
180
+ scopes: this.scopes.map(scope => ({ ...scope })), leases: [...this.leases].map(lease => ({ ...lease })),
181
+ sequences: { lease: this.leaseSequence, endpoint: this.endpointSequence, event: this.eventSequence },
182
+ observerCount: this.observers.length, observerNames: this.observers.map(observer => observer.name), notifying: this.notifying,
183
+ capacityBoundaries: this.capacityBoundaries.map(boundary => ({ ...boundary, ...(boundary.deadline ? { deadline: { ...boundary.deadline, end: { ...boundary.deadline.end } } } : {}) })) };
184
+ }
185
+ emit(kind, extra = {}) {
186
+ if (!this.observers.length)
187
+ return;
188
+ if (this.notifying)
189
+ throw new Error('work trace must not reenter the meter');
190
+ this.eventSequence = nextEpoch(this.eventSequence);
191
+ const event = Object.freeze({ ...this.snapshot(), sequence: this.eventSequence, kind, ...extra });
192
+ this.notifying = true;
193
+ try {
194
+ for (const observe of this.observers)
195
+ observe(event);
196
+ }
197
+ finally {
198
+ this.notifying = false;
199
+ }
200
+ }
201
+ checkEntry() { if (this.notifying)
202
+ throw new Error('work trace must not reenter the meter'); }
203
+ invariant() {
204
+ const end = this.endpoint();
205
+ if (this.consumed < 0n || this.held < 0n || end !== null && (this.consumed + this.held) * end.den > end.num * this.denominator)
206
+ throw new Error('work admission invariant violated');
207
+ }
208
+ invalidate(except) {
209
+ let changed = false;
210
+ for (const lease of this.leases)
211
+ if (lease !== except && lease.live) {
212
+ this.held -= lease.remaining * this.units[lease.sink];
213
+ lease.remaining = 0n;
214
+ lease.live = false;
215
+ changed = true;
216
+ }
217
+ if (changed) {
218
+ this.invariant();
219
+ this.emit('invalidate');
220
+ }
221
+ }
222
+ withTrace(observe, run) {
223
+ this.checkEntry();
224
+ this.observers.push(observe);
225
+ try {
226
+ this.emit('trace-start');
227
+ return synchronous(run());
228
+ }
229
+ finally {
230
+ try {
231
+ this.emit('trace-end');
232
+ }
233
+ finally {
234
+ this.observers.pop();
235
+ }
236
+ }
237
+ }
238
+ withEndpoint(kind, end, run) {
239
+ return this.enterEndpoint(kind, end, run);
240
+ }
241
+ enterEndpoint(kind, end, run, owner) {
242
+ this.checkEntry();
243
+ if (end.den <= 0n || end.num < 0n)
244
+ throw new RangeError('work endpoint must be nonnegative with a positive denominator');
245
+ const nextRoot = kind === 'root' ? nextEpoch(this.rootEpoch) : this.rootEpoch;
246
+ const nextScope = nextEpoch(this.scopeEpoch), nextEndpoint = nextEpoch(this.endpointSequence);
247
+ if (owner) {
248
+ // Entry can refuse before the body opens. Reserve a unique identity and
249
+ // authenticate that prospective endpoint too; never reuse it on failure.
250
+ owner.deadline = { id: nextEndpoint, kind, end: workAmount(end.num, end.den) };
251
+ this.endpointSequence = nextEndpoint;
252
+ }
253
+ this.invalidate();
254
+ if (compareWork(this.actual(), end) > 0) {
255
+ this.emit('refuse', { site: 'scope entry' });
256
+ throw this.capacityError('scope entry', 'scope-entry', undefined, owner?.deadline);
257
+ }
258
+ const priorBaseline = this.baseline;
259
+ if (kind === 'root') {
260
+ if (this.scopes.some(scope => scope.kind === 'root'))
261
+ throw new Error('cannot replace an active work root');
262
+ this.rootEpoch = nextRoot;
263
+ this.baseline = Object.freeze({ actual: exactRaw(this.actual()), counters: this.vector() });
264
+ }
265
+ this.scopeEpoch = nextScope;
266
+ this.endpointSequence = nextEndpoint;
267
+ const scope = { id: this.endpointSequence, kind, end: workAmount(end.num, end.den) };
268
+ this.scopes.push(scope);
269
+ try {
270
+ this.invariant();
271
+ this.emit('scope-enter');
272
+ return synchronous(run());
273
+ }
274
+ finally {
275
+ try {
276
+ this.invalidate();
277
+ this.emit('scope-exit');
278
+ }
279
+ finally {
280
+ this.scopes.pop();
281
+ if (kind === 'root')
282
+ this.baseline = priorBaseline;
283
+ this.scopeEpoch = nextEpoch(this.scopeEpoch);
284
+ this.invariant();
285
+ }
286
+ }
287
+ }
288
+ withBudget(grant, run) {
289
+ if (grant.den <= 0n || grant.num < 0n)
290
+ throw new RangeError('work grant must be nonnegative');
291
+ return this.withEndpoint(this.scopes.some(scope => scope.kind === 'root') ? 'scope' : 'root', workAdd(this.actual(), grant), run);
292
+ }
293
+ withShare(numerator, denominator, run) {
294
+ const available = this.available();
295
+ if (available === null)
296
+ throw new Error('work share needs an inherited finite endpoint');
297
+ return this.withBudget(workShare(available, numerator, denominator), run);
298
+ }
299
+ withChunk(sink, requested, run, site) {
300
+ this.checkEntry();
301
+ if (!Object.hasOwn(this.units, sink))
302
+ throw new RangeError('unknown work sink');
303
+ const count = natural(requested), weight = this.units[sink], end = this.endpoint();
304
+ let grant = count;
305
+ if (end !== null && weight > 0n) {
306
+ const left = end.num * this.denominator - (this.consumed + this.held) * end.den;
307
+ const fits = left <= 0n ? 0n : left / (weight * end.den);
308
+ if (grant > fits)
309
+ grant = fits;
310
+ }
311
+ if (count > 0n && grant === 0n) {
312
+ this.emit('refuse', { sink, site, requested: String(count), granted: '0' });
313
+ throw this.capacityError(site ?? sink, 'quantum', workAmount(count * weight, this.denominator));
314
+ }
315
+ this.leaseSequence = nextEpoch(this.leaseSequence);
316
+ const state = { id: this.leaseSequence, sink, site, remaining: grant, granted: Number(grant), epoch: this.counterEpoch, live: true };
317
+ this.leases.add(state);
318
+ this.held += grant * weight;
319
+ this.invariant();
320
+ const lease = Object.freeze({ granted: state.granted, get remaining() { return Number(state.remaining); }, start: (n = 1) => {
321
+ this.checkEntry();
322
+ const take = natural(n);
323
+ if (!state.live || state.epoch !== this.counterEpoch)
324
+ throw new BudgetExpired(`stale lease: ${site ?? sink}`);
325
+ if (take > state.remaining)
326
+ throw new RangeError('work lease overspend');
327
+ if (take === 0n)
328
+ return;
329
+ // Other counters/scopes cannot share this credit. Expected owner commits
330
+ // advance this lease's epoch; all unrelated reservations become stale.
331
+ const nextCounter = nextEpoch(this.counterEpoch);
332
+ this.invalidate(state);
333
+ state.remaining -= take;
334
+ this.held -= take * weight;
335
+ this.consumed += take * weight;
336
+ this.counters[sink] += take;
337
+ this.counterEpoch = nextCounter;
338
+ state.epoch = nextCounter;
339
+ this.invariant();
340
+ this.emit('start', { sink, site, granted: String(take), leaseId: state.id });
341
+ } });
342
+ try {
343
+ this.emit('reserve', { sink, site, requested: String(count), granted: String(grant), leaseId: state.id });
344
+ return synchronous(run(lease));
345
+ }
346
+ finally {
347
+ try {
348
+ if (state.live) {
349
+ this.held -= state.remaining * weight;
350
+ state.remaining = 0n;
351
+ state.live = false;
352
+ this.invariant();
353
+ this.emit('release', { sink, site, leaseId: state.id });
354
+ }
355
+ }
356
+ finally {
357
+ this.leases.delete(state);
358
+ }
359
+ }
360
+ }
361
+ // An indivisible unit has to fit in full. A partial reservation is retired
362
+ // without starting work, but its refusal still names the real boundary.
363
+ start(sink, count = 1, site) {
364
+ this.withChunk(sink, count, lease => {
365
+ if (lease.granted !== count)
366
+ throw this.capacityError(site ?? sink, 'quantum', workAmount(natural(count) * this.units[sink], this.denominator));
367
+ lease.start(count);
368
+ }, site);
369
+ }
370
+ // Compatibility seeds are allowed only outside a bounded root/scope. During
371
+ // counted work, a direct counter assignment is an unadmitted mutation.
372
+ setUnscopedCounter(key, value) {
373
+ this.checkEntry();
374
+ if (this.bounded() || this.leases.size)
375
+ throw new Error(`unadmitted work counter mutation: ${key}`);
376
+ const next = natural(value), epoch = nextEpoch(this.counterEpoch);
377
+ this.consumed += (next - this.counters[key]) * this.units[key];
378
+ this.counters[key] = next;
379
+ this.counterEpoch = epoch;
380
+ }
381
+ }
382
+ const weights = Object.freeze({ ...Object.fromEntries(legacyWeights), ...completeWorkProfile.weights });
383
+ export const workLedger = new WorkLedger(weights);
384
+ export const workSinkRegistry = Object.freeze(workKeys.map(key => Object.freeze({ key, weight: exactRaw(workLedger.weights[key]) })));
385
+ export const withAdmittedChunk = (sink, requested, run, site) => workLedger.withChunk(sink, requested, run, site);
386
+ export const withWorkAdmissionTrace = (observe, run) => workLedger.withTrace(observe, run);
387
+ export const workAdmissionSnapshot = () => workLedger.snapshot();
388
+ // Display only. No allocator or endpoint constructor may consume this value.
389
+ export const admittedWorkNumber = () => workToNumber(workLedger.actual());
390
+ export const admittedWork = () => workLedger.actual();
391
+ export const remainingAdmittedWork = () => workLedger.available();
392
+ export const emptyWork = zeroWork;
393
+ // Atomic adapters still use the one allocator. They refuse a partial grant
394
+ // before any body starts; loops which can stop early consume a lease itemwise.
395
+ export function startWork(sink, count = 1, site) {
396
+ if (!completeWorkProfile.enabled)
397
+ return;
398
+ workLedger.start(sink, count, site);
399
+ }
400
+ export function workCounterView(initial, mapping) {
401
+ if (!completeWorkProfile.enabled)
402
+ return initial;
403
+ return new Proxy(initial, {
404
+ get(target, property, receiver) {
405
+ const key = typeof property === 'string' ? mapping[property] : undefined;
406
+ return key === undefined ? Reflect.get(target, property, receiver) : Number(workLedger.counter(key));
407
+ },
408
+ set(target, property, value, receiver) {
409
+ const key = typeof property === 'string' ? mapping[property] : undefined;
410
+ if (key === undefined)
411
+ return Reflect.set(target, property, value, receiver);
412
+ if (typeof value !== 'number')
413
+ throw new RangeError('work counter must be numeric');
414
+ workLedger.setUnscopedCounter(key, value);
415
+ return true;
416
+ },
417
+ });
418
+ }
@@ -0,0 +1,21 @@
1
+ import { type Rat } from './q.js';
2
+ export type WorkAmount = Readonly<Rat>;
3
+ export type ExactRaw = Readonly<{
4
+ numerator: string;
5
+ denominator: string;
6
+ }>;
7
+ export declare const zeroWork: WorkAmount;
8
+ export declare function workAmount(num: bigint, den?: bigint): WorkAmount;
9
+ export declare function workFromNumber(value: number): WorkAmount;
10
+ export declare function workAdd(a: WorkAmount, b: WorkAmount): WorkAmount;
11
+ export declare function workSub(a: WorkAmount, b: WorkAmount): WorkAmount;
12
+ export declare function workMultiply(a: WorkAmount, b: WorkAmount): WorkAmount;
13
+ export declare function workShare(a: WorkAmount, numerator: bigint, denominator: bigint): WorkAmount;
14
+ export declare function workDivide(a: WorkAmount, b: WorkAmount): WorkAmount;
15
+ export declare const compareWork: (a: WorkAmount, b: WorkAmount) => number;
16
+ export declare const minWork: (a: WorkAmount, b: WorkAmount) => WorkAmount;
17
+ export declare function exactRaw(a: WorkAmount): ExactRaw;
18
+ export declare function workFromExact(a: ExactRaw): WorkAmount;
19
+ export declare function integerQuotient(a: WorkAmount, b: WorkAmount): bigint;
20
+ export declare function workToNumber(a: WorkAmount): number;
21
+ export declare function commonWorkDenominator(values: readonly WorkAmount[]): bigint;
@@ -0,0 +1,80 @@
1
+ // Exact work arithmetic. Numbers enter by their IEEE value, not decimal text.
2
+ // Clock displays are never decoded again to construct an authoritative root.
3
+ import { Q0, bgcd, q, qadd, qcmp, qdiv, qmul, qsub } from "./q.js";
4
+ export const zeroWork = Object.freeze(Q0);
5
+ export function workAmount(num, den = 1n) { return Object.freeze(q(num, den)); }
6
+ export function workFromNumber(value) {
7
+ if (!Number.isFinite(value))
8
+ throw new RangeError('work amount must be finite');
9
+ if (value === 0)
10
+ return zeroWork;
11
+ const bits = new DataView(new ArrayBuffer(8));
12
+ bits.setFloat64(0, value, false);
13
+ const hi = bits.getUint32(0, false), lo = bits.getUint32(4, false);
14
+ const exponent = (hi >>> 20) & 0x7ff;
15
+ let mantissa = (BigInt(hi & 0xfffff) << 32n) | BigInt(lo);
16
+ if (exponent)
17
+ mantissa |= 1n << 52n;
18
+ if (hi >>> 31)
19
+ mantissa = -mantissa;
20
+ const shift = exponent ? exponent - 1075 : -1074;
21
+ return shift >= 0 ? workAmount(mantissa << BigInt(shift)) : workAmount(mantissa, 1n << BigInt(-shift));
22
+ }
23
+ export function workAdd(a, b) { return Object.freeze(qadd(a, b)); }
24
+ export function workSub(a, b) { return Object.freeze(qsub(a, b)); }
25
+ export function workMultiply(a, b) { return Object.freeze(qmul(a, b)); }
26
+ export function workShare(a, numerator, denominator) {
27
+ if (numerator < 0n || denominator <= 0n)
28
+ throw new RangeError('work share requires a nonnegative numerator and positive denominator');
29
+ return Object.freeze(qmul(a, q(numerator, denominator)));
30
+ }
31
+ export function workDivide(a, b) {
32
+ if (b.num <= 0n)
33
+ throw new RangeError('work divisor must be positive');
34
+ return Object.freeze(qdiv(a, b));
35
+ }
36
+ export const compareWork = (a, b) => qcmp(a, b);
37
+ export const minWork = (a, b) => compareWork(a, b) <= 0 ? a : b;
38
+ export function exactRaw(a) { return Object.freeze({ numerator: String(a.num), denominator: String(a.den) }); }
39
+ export function workFromExact(a) {
40
+ const n = BigInt(a.numerator), d = BigInt(a.denominator);
41
+ if (d <= 0n)
42
+ throw new RangeError('work denominator must be positive');
43
+ return workAmount(n, d);
44
+ }
45
+ export function integerQuotient(a, b) {
46
+ if (a.num < 0n || b.num <= 0n)
47
+ throw new RangeError('work quotient requires nonnegative work and a positive quantum');
48
+ return (a.num * b.den) / (a.den * b.num);
49
+ }
50
+ // Correct round-to-nearest/even conversion for TELEMETRY only, including
51
+ // subnormals and values whose numerator or denominator does not fit a Number.
52
+ export function workToNumber(a) {
53
+ if (a.num === 0n)
54
+ return 0;
55
+ const negative = a.num < 0n, n = negative ? -a.num : a.num, d = a.den;
56
+ if (d <= 0n)
57
+ throw new RangeError('work denominator must be positive');
58
+ let exponent = n.toString(2).length - d.toString(2).length;
59
+ if (exponent >= 0 ? n < (d << BigInt(exponent)) : (n << BigInt(-exponent)) < d)
60
+ exponent--;
61
+ if (exponent > 1023)
62
+ return negative ? -Infinity : Infinity;
63
+ const shift = exponent < -1022 ? 1074 : 52 - exponent;
64
+ const dividend = shift >= 0 ? n << BigInt(shift) : n;
65
+ const divisor = shift >= 0 ? d : d << BigInt(-shift);
66
+ let rounded = dividend / divisor;
67
+ const remainder = dividend % divisor, twice = remainder * 2n;
68
+ if (twice > divisor || twice === divisor && (rounded & 1n) !== 0n)
69
+ rounded++;
70
+ const value = exponent < -1022 ? Number(rounded) * Number.MIN_VALUE : Number(rounded) * 2 ** (exponent - 52);
71
+ return negative ? -value : value;
72
+ }
73
+ // The ledger uses an integer lattice for its frozen dyadic coefficients. Exact
74
+ // rational endpoints (including thirds) are compared without rounding to it.
75
+ export function commonWorkDenominator(values) {
76
+ let denominator = 1n;
77
+ for (const value of values)
78
+ denominator = denominator / bgcd(denominator, value.den) * value.den;
79
+ return denominator;
80
+ }
@@ -0,0 +1,11 @@
1
+ export declare function workMap<T, U>(input: readonly T[], map: (x: T, i: number) => U, site: string): U[];
2
+ export declare function workFilter<T>(input: readonly T[], test: (x: T, i: number) => boolean, site: string): T[];
3
+ export declare function workFlatMap<T, U>(input: readonly T[], map: (x: T, i: number) => readonly U[], site: string): U[];
4
+ export declare function workArraySlice<T>(input: readonly T[], start: number, site: string): T[];
5
+ export declare function workConcat<T>(a: readonly T[], b: readonly T[], site: string): T[];
6
+ export declare function workStrings(input: string[], site: string): string[];
7
+ export declare function workJoin(input: readonly string[], separator: string, site: string): string;
8
+ export declare function workSetArray<T>(input: ReadonlySet<T>, site: string): T[];
9
+ export declare function workEntries(input: object, site: string): [string, unknown][];
10
+ export declare function workJSON(value: unknown, site: string): string | undefined;
11
+ export declare function workSlice(text: string, start: number, end?: number, site?: string): string;