gdp-wired 0.48.0 → 0.49.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 (295) hide show
  1. package/README.md +2 -2
  2. package/dist/core/bmc.js +10 -7
  3. package/dist/core/check.js +7 -2
  4. package/dist/core/count-attempt-work.d.ts +29 -0
  5. package/dist/core/count-attempt-work.js +96 -0
  6. package/dist/core/count-boolean-partition.d.ts +5 -0
  7. package/dist/core/count-boolean-partition.js +47 -0
  8. package/dist/core/count-bounded-quotient.d.ts +2 -0
  9. package/dist/core/count-bounded-quotient.js +13 -0
  10. package/dist/core/count-case-compose.d.ts +20 -0
  11. package/dist/core/count-case-compose.js +289 -0
  12. package/dist/core/count-cases.js +3 -2
  13. package/dist/core/count-cert-rename.d.ts +10 -0
  14. package/dist/core/count-cert-rename.js +69 -0
  15. package/dist/core/count-cert-transport.d.ts +10 -2
  16. package/dist/core/count-cert-transport.js +60 -9
  17. package/dist/core/count-certificate-minimize.d.ts +57 -0
  18. package/dist/core/count-certificate-minimize.js +263 -0
  19. package/dist/core/count-closed-family.d.ts +32 -0
  20. package/dist/core/count-closed-family.js +143 -0
  21. package/dist/core/count-closing-budget.d.ts +10 -0
  22. package/dist/core/count-closing-budget.js +49 -0
  23. package/dist/core/count-closing-needs.d.ts +5 -0
  24. package/dist/core/count-closing-needs.js +9 -0
  25. package/dist/core/count-component-budget.d.ts +5 -0
  26. package/dist/core/count-component-budget.js +9 -0
  27. package/dist/core/count-copy-shape.d.ts +11 -0
  28. package/dist/core/count-copy-shape.js +40 -0
  29. package/dist/core/count-disjoint-funding.d.ts +75 -0
  30. package/dist/core/count-disjoint-funding.js +284 -0
  31. package/dist/core/count-emitter-frame-pool.d.ts +23 -0
  32. package/dist/core/count-emitter-frame-pool.js +87 -0
  33. package/dist/core/count-final-step.d.ts +5 -0
  34. package/dist/core/count-final-step.js +20 -0
  35. package/dist/core/count-fixed-frame.d.ts +4 -0
  36. package/dist/core/count-fixed-frame.js +30 -0
  37. package/dist/core/count-frames.d.ts +25 -0
  38. package/dist/core/count-frames.js +118 -0
  39. package/dist/core/count-frozen-guard.d.ts +2 -0
  40. package/dist/core/count-frozen-guard.js +31 -0
  41. package/dist/core/count-generation-phase.d.ts +7 -0
  42. package/dist/core/count-generation-phase.js +33 -0
  43. package/dist/core/count-guard-composition.d.ts +12 -0
  44. package/dist/core/count-guard-composition.js +48 -0
  45. package/dist/core/count-guard-context.d.ts +11 -0
  46. package/dist/core/count-guard-context.js +50 -0
  47. package/dist/core/count-guard-facts.d.ts +50 -0
  48. package/dist/core/count-guard-facts.js +97 -0
  49. package/dist/core/count-guard-proposals.d.ts +7 -0
  50. package/dist/core/count-guard-proposals.js +106 -0
  51. package/dist/core/count-guard-shape.d.ts +18 -0
  52. package/dist/core/count-guard-shape.js +100 -0
  53. package/dist/core/count-guard-tree.d.ts +17 -0
  54. package/dist/core/count-guard-tree.js +125 -0
  55. package/dist/core/count-leader-facts.d.ts +10 -0
  56. package/dist/core/count-leader-facts.js +52 -0
  57. package/dist/core/count-leader.d.ts +10 -0
  58. package/dist/core/count-leader.js +331 -0
  59. package/dist/core/count-lemma-transport.d.ts +8 -0
  60. package/dist/core/count-lemma-transport.js +47 -0
  61. package/dist/core/count-lifted-budget.d.ts +54 -0
  62. package/dist/core/count-lifted-budget.js +97 -0
  63. package/dist/core/count-lifted-copy.d.ts +3 -0
  64. package/dist/core/count-lifted-copy.js +166 -0
  65. package/dist/core/count-lifted-increment.d.ts +3 -0
  66. package/dist/core/count-lifted-increment.js +146 -0
  67. package/dist/core/count-lifted-load.d.ts +5 -0
  68. package/dist/core/count-lifted-load.js +179 -0
  69. package/dist/core/count-lifted-prerequisite.d.ts +14 -0
  70. package/dist/core/count-lifted-prerequisite.js +53 -0
  71. package/dist/core/count-lifted-replacement.d.ts +3 -0
  72. package/dist/core/count-lifted-replacement.js +540 -0
  73. package/dist/core/count-lifted-shape.d.ts +63 -0
  74. package/dist/core/count-lifted-shape.js +115 -0
  75. package/dist/core/count-lifted-strategy.d.ts +7 -0
  76. package/dist/core/count-lifted-strategy.js +226 -0
  77. package/dist/core/count-lifted-transports.d.ts +32 -0
  78. package/dist/core/count-lifted-transports.js +293 -0
  79. package/dist/core/count-load-shape.d.ts +17 -0
  80. package/dist/core/count-load-shape.js +67 -0
  81. package/dist/core/count-minimal-view.d.ts +26 -0
  82. package/dist/core/count-minimal-view.js +46 -0
  83. package/dist/core/count-operation-observation.d.ts +9 -0
  84. package/dist/core/count-operation-observation.js +22 -0
  85. package/dist/core/count-operation-order.d.ts +5 -0
  86. package/dist/core/count-operation-order.js +4 -0
  87. package/dist/core/count-phase.d.ts +9 -0
  88. package/dist/core/count-phase.js +127 -0
  89. package/dist/core/count-premise-search.d.ts +9 -0
  90. package/dist/core/count-premise-search.js +41 -0
  91. package/dist/core/count-premise-view.d.ts +19 -0
  92. package/dist/core/count-premise-view.js +220 -0
  93. package/dist/core/count-prerequisite-components.d.ts +67 -0
  94. package/dist/core/count-prerequisite-components.js +239 -0
  95. package/dist/core/count-prerequisite-memory.d.ts +24 -0
  96. package/dist/core/count-prerequisite-memory.js +37 -0
  97. package/dist/core/count-prerequisite-plan.d.ts +12 -0
  98. package/dist/core/count-prerequisite-plan.js +88 -0
  99. package/dist/core/count-primitive-budget.d.ts +1 -0
  100. package/dist/core/count-primitive-budget.js +8 -0
  101. package/dist/core/count-project-free.d.ts +3 -0
  102. package/dist/core/count-project-free.js +24 -0
  103. package/dist/core/count-project-witness.d.ts +4 -0
  104. package/dist/core/count-project-witness.js +48 -0
  105. package/dist/core/count-proof-rescope.d.ts +14 -0
  106. package/dist/core/count-proof-rescope.js +71 -0
  107. package/dist/core/count-proof-scope.d.ts +68 -0
  108. package/dist/core/count-proof-scope.js +333 -0
  109. package/dist/core/count-prune-owned-root.d.ts +5 -0
  110. package/dist/core/count-prune-owned-root.js +27 -0
  111. package/dist/core/count-query-context.d.ts +3 -0
  112. package/dist/core/count-query-context.js +7 -0
  113. package/dist/core/count-query.d.ts +15 -0
  114. package/dist/core/count-query.js +59 -0
  115. package/dist/core/count-quorum-leaf.d.ts +9 -0
  116. package/dist/core/count-quorum-leaf.js +38 -0
  117. package/dist/core/count-reachability-budget.d.ts +1 -0
  118. package/dist/core/count-reachability-budget.js +7 -0
  119. package/dist/core/count-reachability-reconcile.d.ts +11 -0
  120. package/dist/core/count-reachability-reconcile.js +19 -0
  121. package/dist/core/count-reachability.d.ts +50 -0
  122. package/dist/core/count-reachability.js +351 -0
  123. package/dist/core/count-rebase-path.d.ts +9 -0
  124. package/dist/core/count-rebase-path.js +68 -0
  125. package/dist/core/count-recipe-context.d.ts +45 -0
  126. package/dist/core/count-recipe-context.js +71 -0
  127. package/dist/core/count-recipe-controller.d.ts +115 -0
  128. package/dist/core/count-recipe-controller.js +417 -0
  129. package/dist/core/count-recipe-graph.d.ts +36 -0
  130. package/dist/core/count-recipe-graph.js +211 -0
  131. package/dist/core/count-recovery/conditional-check-cache.js +3 -2
  132. package/dist/core/count-recovery/conditional-cuts.js +5 -4
  133. package/dist/core/count-recovery/conditional-proof.d.ts +37 -3
  134. package/dist/core/count-recovery/conditional-proof.js +72 -30
  135. package/dist/core/count-recovery/derivability-closure.js +2 -1
  136. package/dist/core/count-recovery/guard-cases.js +2 -1
  137. package/dist/core/count-recovery/reframe-tree.d.ts +2 -0
  138. package/dist/core/count-recovery/reframe-tree.js +24 -0
  139. package/dist/core/count-recovery/replay-linear-skeleton.d.ts +2 -0
  140. package/dist/core/count-recovery/replay-linear-skeleton.js +28 -0
  141. package/dist/core/count-recovery/row-cases.js +2 -1
  142. package/dist/core/count-rejection-budget.d.ts +8 -0
  143. package/dist/core/count-rejection-budget.js +15 -0
  144. package/dist/core/count-replacement.d.ts +5 -0
  145. package/dist/core/count-replacement.js +129 -0
  146. package/dist/core/count-replay-diagnostic.d.ts +21 -0
  147. package/dist/core/count-replay-diagnostic.js +49 -0
  148. package/dist/core/count-replay-skeleton.d.ts +4 -0
  149. package/dist/core/count-replay-skeleton.js +28 -0
  150. package/dist/core/count-rescope-funding.d.ts +3 -0
  151. package/dist/core/count-rescope-funding.js +17 -0
  152. package/dist/core/count-restrictions.d.ts +11 -0
  153. package/dist/core/count-restrictions.js +31 -0
  154. package/dist/core/count-retry-budget.d.ts +67 -0
  155. package/dist/core/count-retry-budget.js +114 -0
  156. package/dist/core/count-retry-round.d.ts +24 -0
  157. package/dist/core/count-retry-round.js +44 -0
  158. package/dist/core/count-row-agreement.d.ts +35 -0
  159. package/dist/core/count-row-agreement.js +270 -0
  160. package/dist/core/count-row-aliases.d.ts +3 -0
  161. package/dist/core/count-row-aliases.js +59 -0
  162. package/dist/core/count-row-composition.d.ts +6 -0
  163. package/dist/core/count-row-composition.js +55 -0
  164. package/dist/core/count-row-copy-linear.d.ts +4 -0
  165. package/dist/core/count-row-copy-linear.js +83 -0
  166. package/dist/core/count-row-copy.d.ts +4 -0
  167. package/dist/core/count-row-copy.js +94 -0
  168. package/dist/core/count-row-policy.d.ts +3 -0
  169. package/dist/core/count-row-policy.js +56 -0
  170. package/dist/core/count-row-reindex.d.ts +11 -0
  171. package/dist/core/count-row-reindex.js +126 -0
  172. package/dist/core/count-row-support.d.ts +9 -0
  173. package/dist/core/count-row-support.js +42 -0
  174. package/dist/core/count-row-symmetry.d.ts +7 -0
  175. package/dist/core/count-row-symmetry.js +100 -0
  176. package/dist/core/count-scope-hyps.d.ts +2 -0
  177. package/dist/core/count-scope-hyps.js +163 -0
  178. package/dist/core/count-scope-row-reuse.d.ts +3 -0
  179. package/dist/core/count-scope-row-reuse.js +92 -0
  180. package/dist/core/count-search-allowance.d.ts +1 -0
  181. package/dist/core/count-search-allowance.js +17 -0
  182. package/dist/core/count-stabilize-tree.d.ts +9 -0
  183. package/dist/core/count-stabilize-tree.js +35 -0
  184. package/dist/core/count-stage-trace.d.ts +8 -0
  185. package/dist/core/count-stage-trace.js +45 -0
  186. package/dist/core/count-strategies.d.ts +16 -0
  187. package/dist/core/count-strategies.js +155 -0
  188. package/dist/core/count-strategy-premises.d.ts +5 -0
  189. package/dist/core/count-strategy-premises.js +14 -0
  190. package/dist/core/count-strategy.d.ts +41 -0
  191. package/dist/core/count-strategy.js +76 -0
  192. package/dist/core/count-support.js +3 -2
  193. package/dist/core/count-tier-budget.d.ts +14 -0
  194. package/dist/core/count-tier-budget.js +64 -0
  195. package/dist/core/count-unwritten-prefix.d.ts +24 -0
  196. package/dist/core/count-unwritten-prefix.js +97 -0
  197. package/dist/core/count-write-shape.d.ts +15 -0
  198. package/dist/core/count-write-shape.js +73 -0
  199. package/dist/core/counts.d.ts +37 -13
  200. package/dist/core/counts.js +990 -127
  201. package/dist/core/cycles.js +5 -4
  202. package/dist/core/cyclic.js +11 -10
  203. package/dist/core/data.js +16 -15
  204. package/dist/core/dsl-deadline.d.ts +3 -0
  205. package/dist/core/dsl-deadline.js +27 -0
  206. package/dist/core/dsl.d.ts +9 -0
  207. package/dist/core/dsl.js +156 -51
  208. package/dist/core/evaluation-admission.d.ts +1 -0
  209. package/dist/core/evaluation-admission.js +3 -0
  210. package/dist/core/exists.d.ts +6 -1
  211. package/dist/core/exists.js +51 -9
  212. package/dist/core/field-laws.d.ts +3 -1
  213. package/dist/core/field-laws.js +140 -2
  214. package/dist/core/finite-houdini.d.ts +6 -0
  215. package/dist/core/finite-houdini.js +63 -21
  216. package/dist/core/finite-tiny.js +95 -67
  217. package/dist/core/fixtures/count-completion/paxos-decision.json +1 -0
  218. package/dist/core/fresh.js +5 -1
  219. package/dist/core/infer.js +45 -30
  220. package/dist/core/kind.js +2 -1
  221. package/dist/core/lemma-cuts.js +11 -10
  222. package/dist/core/linear-admission.d.ts +14 -0
  223. package/dist/core/linear-admission.js +151 -0
  224. package/dist/core/machine.d.ts +5 -2
  225. package/dist/core/machine.js +105 -31
  226. package/dist/core/meter.d.ts +22 -0
  227. package/dist/core/meter.js +34 -0
  228. package/dist/core/nonterm.js +4 -3
  229. package/dist/core/prover-row-budget.d.ts +3 -0
  230. package/dist/core/prover-row-budget.js +106 -0
  231. package/dist/core/quorum-laws.d.ts +21 -1
  232. package/dist/core/quorum-laws.js +27 -3
  233. package/dist/core/rationals.js +3 -2
  234. package/dist/core/rejection-discovery.d.ts +34 -0
  235. package/dist/core/rejection-discovery.js +36 -0
  236. package/dist/core/rejection-stage.d.ts +39 -0
  237. package/dist/core/rejection-stage.js +205 -0
  238. package/dist/core/request-quotient.d.ts +8 -0
  239. package/dist/core/request-quotient.js +299 -0
  240. package/dist/core/row-agreement-shape.d.ts +15 -0
  241. package/dist/core/row-agreement-shape.js +68 -0
  242. package/dist/core/runtime-wall.d.ts +2 -0
  243. package/dist/core/search-policy.d.ts +15 -0
  244. package/dist/core/search-policy.js +68 -0
  245. package/dist/core/solver.d.ts +1 -1
  246. package/dist/core/solver.js +40 -6
  247. package/dist/core/step-work.d.ts +12 -0
  248. package/dist/core/step-work.js +14 -0
  249. package/dist/core/strategy-premises.d.ts +8 -0
  250. package/dist/core/strategy-premises.js +64 -0
  251. package/dist/core/system.js +4 -3
  252. package/dist/core/table-admission.d.ts +1 -0
  253. package/dist/core/table-admission.js +3 -0
  254. package/dist/core/trace-clock.d.ts +3 -0
  255. package/dist/core/trace-clock.js +16 -0
  256. package/dist/core/transfer.js +3 -2
  257. package/dist/core/translate.js +16 -3
  258. package/dist/core/wall.d.ts +6 -1
  259. package/dist/core/wall.js +23 -9
  260. package/dist/core/watch.d.ts +1 -1
  261. package/dist/core/watch.js +13 -4
  262. package/dist/core/work-admission.d.ts +164 -0
  263. package/dist/core/work-admission.js +418 -0
  264. package/dist/core/work-amount.d.ts +21 -0
  265. package/dist/core/work-amount.js +80 -0
  266. package/dist/core/work-collections.d.ts +11 -0
  267. package/dist/core/work-collections.js +198 -0
  268. package/dist/core/work-kinds.d.ts +11 -0
  269. package/dist/core/work-kinds.js +9 -0
  270. package/dist/core/work-meter.d.ts +8 -0
  271. package/dist/core/work-meter.js +83 -0
  272. package/dist/core/work-observe.d.ts +12 -0
  273. package/dist/core/work-observe.js +39 -0
  274. package/dist/core/work-profile.d.ts +10 -0
  275. package/dist/core/work-profile.js +21 -0
  276. package/dist/core/work-refusal.d.ts +1 -0
  277. package/dist/core/work-refusal.js +6 -0
  278. package/dist/interchange/format.js +2 -0
  279. package/dist/kernel/cdcl.js +93 -40
  280. package/dist/kernel/epr.js +23 -8
  281. package/dist/kernel/kernel.d.ts +47 -1
  282. package/dist/kernel/kernel.js +417 -68
  283. package/dist/kernel/prove.d.ts +49 -3
  284. package/dist/kernel/prove.js +468 -122
  285. package/dist/kernel/prover-rows.d.ts +1 -0
  286. package/dist/kernel/prover-rows.js +12 -1
  287. package/dist/kernel/reader.d.ts +1 -1
  288. package/dist/kernel/reader.js +57 -12
  289. package/dist/kernel/simplex.js +9 -2
  290. package/dist/lean-kernel/emit.d.ts +9 -1
  291. package/dist/lean-kernel/emit.js +144 -22
  292. package/dist/lean-kernel/legacy-family-library.d.ts +1 -0
  293. package/dist/lean-kernel/legacy-family-library.js +5 -0
  294. package/dist/lean-kernel/library.js +3 -3
  295. package/package.json +1 -1
@@ -0,0 +1,115 @@
1
+ // Untrusted discovery for a lifted comparison of stored rows and two halves.
2
+ // The generator's provenance supplies the correspondence; no law, protocol,
3
+ // operation, flag, or map name is a dispatch key.
4
+ import { all, n, same, walkOnce, x } from "./machine.js";
5
+ import { discoverRowAgreement } from "./row-agreement-shape.js";
6
+ import { classifyRowValueWrite } from "./count-row-policy.js";
7
+ import { finiteCountChoice } from "./count-cases.js";
8
+ import { discoverCountGuardShape } from "./count-guard-shape.js";
9
+ import { discoverCountRowCopy } from "./count-copy-shape.js";
10
+ import { discoverCountThresholdWrite } from "./count-write-shape.js";
11
+ import { quorumLawProvenance } from "./quorum-laws.js";
12
+ export function discoverLiftedCountGuard(m, law, family, observe) {
13
+ const origin = quorumLawProvenance(law);
14
+ if (!origin) {
15
+ if (observe && law.forall && law.keys?.length === 3) {
16
+ const maps = new Set(), variables = new Set();
17
+ walkOnce(law.holds, (node) => { if (node.op === 'get' && m.counts?.[node.map])
18
+ maps.add(node.map); if (node.op === 'var')
19
+ variables.add(node.name); });
20
+ if (maps.size >= 3 && law.keys.slice(1).every(key => variables.has(key)))
21
+ observe({ stage: 'lifted-decline', reason: 'no provenance', message: 'lifted-decline: no provenance' });
22
+ }
23
+ return;
24
+ }
25
+ if (!origin.disabled || origin.halves.length !== 2 || !law.forall || law.keys?.length !== 3 || !origin.twins.length)
26
+ return;
27
+ if (!(origin.membershipMap in (m.maps ?? {})) || !m.inputMaps?.includes(origin.requestSet) || !m.inputs.includes(origin.rowInput) || JSON.stringify(m.step.flags?.[origin.guard]) !== origin.guardFormula)
28
+ return;
29
+ if (Object.entries(origin.definitions).some(([name, definition]) => JSON.stringify(m.counts?.[name]) !== definition))
30
+ return;
31
+ const choices = family.flatMap(candidate => {
32
+ const shape = discoverCountGuardShape(m, candidate, family);
33
+ if (!shape || shape.rowMap !== origin.rowCount || shape.membershipMap !== origin.membershipMap || shape.width !== origin.width)
34
+ return [];
35
+ let size = 0;
36
+ walkOnce(m.counts[shape.voteMap].body, () => { size++; });
37
+ return [{ shape, size }];
38
+ }).sort((a, b) => b.size - a.size);
39
+ if (!choices.length)
40
+ return;
41
+ const signature = (shape) => JSON.stringify([shape.membershipMap, shape.rowMap, shape.memberField, shape.thresholdField, shape.width]);
42
+ if (choices.some(choice => signature(choice.shape) !== signature(choices[0].shape)))
43
+ return;
44
+ const countMaps = new Set();
45
+ walkOnce(law.holds, (node) => { if (node.op === 'get' && m.counts?.[node.map])
46
+ countMaps.add(node.map); });
47
+ if (countMaps.size < 3 || !countMaps.has(origin.rowCount) || origin.twins.some(twin => !countMaps.has(twin.row)))
48
+ return;
49
+ const agreements = family.flatMap(candidate => { const row = discoverRowAgreement(m, candidate); return row?.map === origin.membershipMap && row.width === origin.width ? [{ law: candidate, shape: row }] : []; }).sort((a, b) => b.shape.markers.length - a.shape.markers.length);
50
+ // Offer the marked row law first; preserve every other match for a checked
51
+ // fallback if a minimal transport query is satisfiable with that premise.
52
+ return { origin, countShape: choices[0].shape, countMaps: [...countMaps], rowAgreements: agreements, ...(agreements[0] ? { rowAgreement: agreements[0].shape } : {}) };
53
+ }
54
+ // The stored action's provenance decides replacement, independently of any
55
+ // threshold write. The ordinary row-write classifier must agree with it.
56
+ function replacementOperation(m, shape, name) {
57
+ const write = m.step.maps?.[shape.origin.membershipMap];
58
+ let usesGuard = false, usesSet = false;
59
+ walkOnce(write, (node) => { if (node.op === 'flag' && node.name === shape.origin.guard)
60
+ usesGuard = true; if (node.op === 'get' && node.map === shape.origin.requestSet)
61
+ usesSet = true; });
62
+ const values = new Set(), seen = new Set();
63
+ const visit = (condition) => {
64
+ if (condition.op === 'and') {
65
+ condition.xs.forEach(visit);
66
+ return;
67
+ }
68
+ if (condition.op === 'flag' && !seen.has(condition.name)) {
69
+ seen.add(condition.name);
70
+ const nested = m.step.flags?.[condition.name];
71
+ if (nested)
72
+ visit(nested);
73
+ return;
74
+ }
75
+ if (condition.op !== '=')
76
+ return;
77
+ const [variable, value] = condition.a.op === 'var' ? [condition.a, condition.b] : [condition.b, condition.a];
78
+ if (variable.op === 'var' && variable.name === name && value.op === 'const')
79
+ values.add(value.value);
80
+ };
81
+ const guard = m.step.flags?.[shape.origin.guard];
82
+ if (guard)
83
+ visit(guard);
84
+ return { stores: usesGuard && usesSet, ...(values.size === 1 ? { value: [...values][0] } : {}) };
85
+ }
86
+ // A fixed-case emitter must classify only that case: its assumption can make
87
+ // every other operation unreachable without invalidating the requested one.
88
+ export function discoverLiftedCountOperation(m, shape, value, observe) {
89
+ const choice = finiteCountChoice(m);
90
+ if (!choice || !choice[1].has(value))
91
+ return;
92
+ const [name, values] = choice, replacement = replacementOperation(m, shape, name);
93
+ const decline = (kind, reason) => { observe?.({ stage: 'lifted-decline', reason, guard: shape.origin.guard, value, kind, replacement: replacement.value, writes: m.step.maps?.[shape.origin.membershipMap] }); return undefined; };
94
+ if (replacement.stores && (replacement.value === undefined || !values.has(replacement.value)))
95
+ return decline(undefined, 'replacement-operation');
96
+ const branch = { name, value }, copy = discoverCountRowCopy(m, shape.countShape, branch), write = discoverCountThresholdWrite(m, shape.countShape, branch);
97
+ const fixed = { ...m, assume: all(...(m.assume ? [m.assume] : []), same(x(name), n(value))) }, rowKind = classifyRowValueWrite(fixed, { map: shape.origin.membershipMap, fields: shape.rowAgreement?.fields ?? [] });
98
+ const replacing = replacement.stores && replacement.value === value;
99
+ if (replacing && rowKind !== 'replacement' || !replacing && rowKind === 'replacement')
100
+ return decline(rowKind, 'replacement-write-disagreement');
101
+ return { name, value, ...(replacing ? { kind: 'threshold-replace', replacement: { guard: shape.origin.guard, input: shape.origin.requestSet }, ...(write ? { write } : {}) } : copy ? { kind: 'copy', copy } : write ? { kind: write.increment ? 'threshold-increment' : 'threshold-replace', write } : { kind: rowKind ?? 'frame-or-phase' }) };
102
+ }
103
+ export function discoverLiftedCountOperations(m, shape, observe) {
104
+ const choice = finiteCountChoice(m);
105
+ if (!choice)
106
+ return;
107
+ const planned = [];
108
+ for (const value of [...choice[1]].sort((a, b) => a - b)) {
109
+ const operation = discoverLiftedCountOperation(m, shape, value, observe);
110
+ if (!operation)
111
+ return;
112
+ planned.push(operation);
113
+ }
114
+ return planned;
115
+ }
@@ -0,0 +1,7 @@
1
+ import { type LiftedWorkBudget } from './count-lifted-budget.js';
2
+ import { type Law, type Machine } from './machine.js';
3
+ import { type CountStrategyProof, type CountRequestBuilder, type CountStrategyOptions } from './count-strategy.js';
4
+ import { type CountCert, type Instances } from '../kernel/kernel.js';
5
+ export declare function proveLiftedCountFrame(m: Machine, family: Law[], law: Law, until: number, requestFor: CountRequestBuilder, observe?: (event: Record<string, unknown>) => void, options?: CountStrategyOptions): CountStrategyProof | undefined;
6
+ export declare function proveLiftedCountInitial(m: Machine, family: Law[], law: Law, instances: Instances, until: number, requestFor: CountRequestBuilder): CountCert | undefined;
7
+ export declare function proveLiftedCountComposition(m: Machine, family: Law[], law: Law, until: number, requestFor: CountRequestBuilder, observe?: (event: Record<string, unknown>) => void, workAllowance?: number | LiftedWorkBudget): CountStrategyProof | undefined;
@@ -0,0 +1,226 @@
1
+ // First F5 emitter: discover and check frame operations from the original
2
+ // machine. Other operation kinds decline; no saved proof or supplied transport
3
+ // can fill a missing case. The shared composer runs only for an exhaustive set.
4
+ import { traceNow } from "./trace-clock.js";
5
+ import { liftedLeaseOptions, liftedWorkBudget, withLiftedCase, withLiftedLeaf } from "./count-lifted-budget.js";
6
+ import { all, n, same, x } from "./machine.js";
7
+ import { countsForReads } from "./count-facts.js";
8
+ import { startWork } from "./work-admission.js";
9
+ import { workMap } from "./work-collections.js";
10
+ import { countFrameConditions, fixedCountFrameCase, ownCountLawInstance, proveCountFrameGoal } from "./count-frames.js";
11
+ import { composeCountOperationProofs } from "./count-case-compose.js";
12
+ import { discoverLiftedCountGuard, discoverLiftedCountOperations } from "./count-lifted-shape.js";
13
+ import { checkMC, countedObligations, frameOk, linear, mcGoal } from "../kernel/kernel.js";
14
+ import { growCdcl } from "../kernel/cdcl.js";
15
+ import { add, k, env } from "./solver.js";
16
+ import { clock, fullRate, fullWork, late, withDeadline } from "../kernel/prove.js";
17
+ import { proveLiftedCountLoad } from "./count-lifted-load.js";
18
+ import { proveLiftedCountCopy } from "./count-lifted-copy.js";
19
+ import { proveLiftedCountIncrement } from "./count-lifted-increment.js";
20
+ import { proveLiftedCountReplacement } from "./count-lifted-replacement.js";
21
+ import { recordCountStrategyPremises } from "./count-strategy-premises.js";
22
+ import { observeCountOperation } from "./count-operation-observation.js";
23
+ // A checked fixed-operation STEP fragment, not a standalone INIT/STEP proof.
24
+ export function proveLiftedCountFrame(m, family, law, until, requestFor, observe, options = {}) {
25
+ return withDeadline(until, () => {
26
+ const shape = discoverLiftedCountGuard(m, law, family, observe), choice = fixedCountFrameCase(m);
27
+ if (!shape || !choice || !family.includes(law) || late(until)) {
28
+ observe?.({ stage: 'frame-decline', reason: !shape ? 'shape' : !choice ? 'operation' : 'scope-or-time' });
29
+ return;
30
+ }
31
+ const instances = ownCountLawInstance(law, {}), step = countedObligations(m, family, { [law.name]: instances }, family.indexOf(law)).at(-1);
32
+ const request = requestFor(step.goal, step.decls), counts = countsForReads(step.decls, request.reads), targets = new Set(shape.countMaps), when = countFrameConditions(choice);
33
+ if (!counts) {
34
+ observe?.({ stage: 'frame-decline', reason: 'counts' });
35
+ return;
36
+ }
37
+ const post = request.reads.filter(read => read[1].endsWith('#') && targets.has(read[1].slice(0, -1)));
38
+ // An unchanged post formula can reuse the pre count directly, leaving no
39
+ // post-labelled read at all. Refute that actual goal; do not invent a frame.
40
+ if (!post.length) {
41
+ const goal = mcGoal(step.goal.hyps, step.decls, request), result = goal && withLiftedLeaf(until, options, Infinity, 'leaf:frame:direct', end => growCdcl(goal, new Map(), { nodes: 0, until: end }));
42
+ if (!result || !('tree' in result)) {
43
+ observe?.({ stage: 'frame-decline', reason: 'direct-search', outcome: result && 'stuck' in result ? result.stuck : 'encoding' });
44
+ return;
45
+ }
46
+ const cert = { ...request, tree: result.tree };
47
+ return checkMC(step.goal.hyps, step.decls, cert) && !late(until) ? { instances, certs: { [step.goal.name]: cert } } : undefined;
48
+ }
49
+ const extraWhen = [];
50
+ for (const [, map, key] of post) {
51
+ const declaration = step.decls.find(decl => decl.map === map);
52
+ if (!declaration?.base)
53
+ continue;
54
+ if (key.op !== 'add' || key.a.op !== 'mul' || key.a.k !== declaration.base)
55
+ return;
56
+ const low = linear(key.b, new Map());
57
+ if (!low)
58
+ return;
59
+ extraWhen.push(add(low, k(1 - declaration.base)));
60
+ }
61
+ const framedWhen = [...when, ...extraWhen];
62
+ const missing = post.filter(([name, map, key]) => {
63
+ const pre = request.reads.find(read => read[1] === map.slice(0, -1) && JSON.stringify(read[2]) === JSON.stringify(key));
64
+ return !pre || !frameOk(counts, { post: name, pre: pre[0], when: framedWhen });
65
+ });
66
+ if (missing.length) {
67
+ observe?.({ stage: 'frame-decline', reason: 'unframed-count', reads: missing.map(read => read[1]) });
68
+ return;
69
+ }
70
+ const run = (end) => proveCountFrameGoal(step.goal, step.decls, request, choice, targets, end, undefined, { extraWhen, leafUnits: options.leafUnits });
71
+ const cert = options.leafWork ? withLiftedLeaf(until, options, 100, 'leaf:frame:framed', run) : run(until);
72
+ observe?.({ stage: 'frame-search', checked: !!cert });
73
+ return cert ? { instances, certs: { [step.goal.name]: cert } } : undefined;
74
+ });
75
+ }
76
+ // INIT is built from the actual lifted target, not the vote-map assumption of
77
+ // the older two-count strategy. Every zero proposal is an ordinary CountInst.
78
+ export function proveLiftedCountInitial(m, family, law, instances, until, requestFor) {
79
+ if (late(until))
80
+ return;
81
+ const initial = countedObligations(m, family, { [law.name]: instances }, family.indexOf(law))[0];
82
+ if (!initial)
83
+ return;
84
+ const base = requestFor(initial.goal, initial.decls), counts = countsForReads(initial.decls, base.reads);
85
+ if (!counts)
86
+ return;
87
+ const scope = JSON.stringify([m, family, instances, base]);
88
+ let prefix = 'liftedInitial$';
89
+ while (scope.includes(prefix))
90
+ prefix = '$' + prefix;
91
+ const request = { ...base, insts: counts.map((count, index) => ({ wit: prefix + index, below: count.below, terms: [[1, count.v]], unit: 0 })), picks: [] };
92
+ const goal = mcGoal(initial.goal.hyps, initial.decls, request), result = goal && growCdcl(goal, new Map(), { nodes: 0, until });
93
+ if (!result || !('tree' in result))
94
+ return;
95
+ const cert = { ...request, tree: result.tree };
96
+ return checkMC(initial.goal.hyps, initial.decls, cert) && !late(until) ? cert : undefined;
97
+ }
98
+ export function proveLiftedCountComposition(m, family, law, until, requestFor, observe, workAllowance = Math.max(0, until - clock())) {
99
+ const budget = typeof workAllowance === 'number' ? liftedWorkBudget(workAllowance) : workAllowance;
100
+ if (budget.lease?.owners)
101
+ return proveOwnerFundedLiftedComposition(m, family, law, requestFor, observe, budget);
102
+ if (budget.lease)
103
+ until = Infinity;
104
+ return withDeadline(until, () => {
105
+ if (!family.includes(law))
106
+ return;
107
+ const shape = discoverLiftedCountGuard(m, law, family, observe), plan = shape && discoverLiftedCountOperations(m, shape);
108
+ if (!shape || !plan || late(until))
109
+ return;
110
+ const cases = [];
111
+ const rank = { 'frame-or-phase': 0, load: 1, copy: 2, 'threshold-increment': 3, 'threshold-replace': 4, replacement: 4 };
112
+ for (const operation of [...plan].sort((a, b) => rank[a.kind] - rank[b.kind] || a.value - b.value)) {
113
+ if (late(until))
114
+ return;
115
+ if (operation.kind === 'replacement' || operation.kind === 'threshold-replace' && env.GDP_COUNT_LIFTED_REPLACEMENT !== '1') {
116
+ observe?.({ stage: 'lifted-operation', value: operation.value, kind: operation.kind, proposed: false, reason: 'replacement emitter unavailable' });
117
+ return;
118
+ }
119
+ const fixed = { ...m, assume: all(...(m.assume ? [m.assume] : []), same(x(operation.name), n(operation.value))) }, emit = operation.kind === 'load' ? proveLiftedCountLoad : operation.kind === 'copy' ? proveLiftedCountCopy : operation.kind === 'threshold-replace' ? proveLiftedCountReplacement : proveLiftedCountIncrement;
120
+ const before = fullWork(), wall = observe ? traceNow() : 0, key = 'op:' + operation.value, report = observe ? (event) => observe({ value: operation.value, ...event }) : undefined;
121
+ const owned = env.GDP_COUNT_C2_REPLAY === '1', caseOptions = liftedLeaseOptions(budget, key);
122
+ const proof = observeCountOperation({ owner: law.name, value: operation.value, kind: operation.kind }, () => withLiftedCase(until, budget, operation.kind === 'frame-or-phase', key, end => operation.kind === 'frame-or-phase' ? proveLiftedCountFrame(fixed, family, law, end, requestFor, report, caseOptions) : emit(fixed, family, law, end, requestFor, report, { ...caseOptions, deferToComposition: env.GDP_COUNT_LIFTED_REPLACEMENT === '1', deferIntermediateChecks: env.GDP_COUNT_DEFER_CHECKS === '1', deferOwnedReplacementLemmas: owned, batchOwnedReplacementPruning: owned, deferOwnedReplacementReplay: owned, slicedLemmas: env.GDP_COUNT_C2_LEMMAS === '1', emitterFramePool: env.GDP_COUNT_EMITTER_FRAME_POOL === '1' })));
123
+ observe?.({ stage: 'lifted-operation', value: operation.value, kind: operation.kind, proposed: !!proof, units: (fullWork() - before) / fullRate, wallMs: traceNow() - wall });
124
+ if (!proof)
125
+ return;
126
+ cases.push({ value: operation.value, proof });
127
+ }
128
+ if (cases.length !== plan.length)
129
+ return;
130
+ const initialBefore = fullWork(), initialWall = observe ? traceNow() : 0, initial = proveLiftedCountInitial(m, family, law, cases[0].proof.instances, until, requestFor);
131
+ observe?.({ stage: 'lifted-initial', checked: !!initial, units: (fullWork() - initialBefore) / fullRate, wallMs: traceNow() - initialWall });
132
+ if (!initial)
133
+ return;
134
+ const compositionBefore = fullWork(), compositionWall = observe ? traceNow() : 0, result = composeCountOperationProofs({ original: m, machine: m, shape: shape.countShape, restrictions: [], inputCounts: {} }, family, law, cases, until, requestFor, observe ? (stage, value) => observe({ stage, value }) : undefined, { initial, ...(budget.lease ? { propagateBudgetExpiry: true } : {}), ...(env.GDP_COUNT_C2_LEMMAS === '1' ? { slicedLemmas: true } : {}) });
135
+ observe?.({ stage: 'lifted-composition', checked: !!result, units: (fullWork() - compositionBefore) / fullRate, wallMs: traceNow() - compositionWall });
136
+ return result && recordCountStrategyPremises(family, result);
137
+ });
138
+ }
139
+ // Explicit next-pin route only. Each non-case segment consumes the SAME
140
+ // cumulative body budget; case and leaf helpers run outside those segments.
141
+ // The ordinary lease path above is left unchanged until policy activation.
142
+ function proveOwnerFundedLiftedComposition(m, family, law, requestFor, observe, budget) {
143
+ const owners = budget.lease.owners, until = Infinity;
144
+ const prepared = owners.body(() => {
145
+ let present = false;
146
+ for (const candidate of family) {
147
+ startWork('ticks', 1, 'owned lifted owner lookup');
148
+ if (candidate === law) {
149
+ present = true;
150
+ break;
151
+ }
152
+ }
153
+ if (!present)
154
+ return;
155
+ const shape = discoverLiftedCountGuard(m, law, family, observe), plan = shape && discoverLiftedCountOperations(m, shape);
156
+ if (!shape || !plan || late(until))
157
+ return;
158
+ const rank = { 'frame-or-phase': 0, load: 1, copy: 2, 'threshold-increment': 3, 'threshold-replace': 4, replacement: 4 };
159
+ const ordered = workMap(plan, operation => operation, 'owned lifted operation copy');
160
+ // Stable insertion sorting is fully charged, unlike a native sort's opaque
161
+ // pre-comparator copies. This preserves the existing kind/value ordering.
162
+ for (let i = 1; i < ordered.length; i++) {
163
+ startWork('ticks', 1, 'owned lifted operation sort');
164
+ const item = ordered[i];
165
+ let j = i;
166
+ while (j > 0) {
167
+ startWork('ticks', 1, 'owned lifted operation compare');
168
+ const previous = ordered[j - 1];
169
+ if (rank[previous.kind] < rank[item.kind] || rank[previous.kind] === rank[item.kind] && previous.value <= item.value)
170
+ break;
171
+ startWork('ticks', 1, 'owned lifted operation move');
172
+ ordered[j] = previous;
173
+ j--;
174
+ }
175
+ startWork('ticks', 1, 'owned lifted operation insert');
176
+ ordered[j] = item;
177
+ }
178
+ return { shape, ordered, cases: [] };
179
+ });
180
+ if (!prepared)
181
+ return;
182
+ for (const operation of prepared.ordered) {
183
+ const setup = owners.body(() => {
184
+ startWork('ticks', 1, 'owned lifted case setup');
185
+ if (late(until))
186
+ return;
187
+ if (operation.kind === 'replacement' || operation.kind === 'threshold-replace' && env.GDP_COUNT_LIFTED_REPLACEMENT !== '1') {
188
+ observe?.({ stage: 'lifted-operation', value: operation.value, kind: operation.kind, proposed: false, reason: 'replacement emitter unavailable' });
189
+ return;
190
+ }
191
+ const fixed = { ...m, assume: all(...(m.assume ? [m.assume] : []), same(x(operation.name), n(operation.value))) };
192
+ const emit = operation.kind === 'load' ? proveLiftedCountLoad : operation.kind === 'copy' ? proveLiftedCountCopy : operation.kind === 'threshold-replace' ? proveLiftedCountReplacement : proveLiftedCountIncrement;
193
+ const key = 'op:' + operation.value, report = observe ? (event) => observe({ value: operation.value, ...event }) : undefined;
194
+ return { fixed, emit, key, report, before: fullWork(), wall: observe ? traceNow() : 0, owned: env.GDP_COUNT_C2_REPLAY === '1', options: liftedLeaseOptions(budget, key) };
195
+ });
196
+ if (!setup)
197
+ return;
198
+ const proof = withLiftedCase(until, budget, operation.kind === 'frame-or-phase', setup.key, end => observeCountOperation({ owner: law.name, value: operation.value, kind: operation.kind }, () => operation.kind === 'frame-or-phase'
199
+ ? proveLiftedCountFrame(setup.fixed, family, law, end, requestFor, setup.report, setup.options)
200
+ : setup.emit(setup.fixed, family, law, end, requestFor, setup.report, { ...setup.options, deferToComposition: env.GDP_COUNT_LIFTED_REPLACEMENT === '1', deferIntermediateChecks: env.GDP_COUNT_DEFER_CHECKS === '1', deferOwnedReplacementLemmas: setup.owned, batchOwnedReplacementPruning: setup.owned, deferOwnedReplacementReplay: setup.owned, slicedLemmas: env.GDP_COUNT_C2_LEMMAS === '1', emitterFramePool: env.GDP_COUNT_EMITTER_FRAME_POOL === '1' })));
201
+ const retained = owners.body(() => {
202
+ startWork('ticks', 1, 'owned lifted case result');
203
+ observe?.({ stage: 'lifted-operation', value: operation.value, kind: operation.kind, proposed: !!proof, units: (fullWork() - setup.before) / fullRate, wallMs: traceNow() - setup.wall });
204
+ if (!proof)
205
+ return false;
206
+ prepared.cases.push({ value: operation.value, proof });
207
+ return true;
208
+ });
209
+ if (!retained)
210
+ return;
211
+ }
212
+ return owners.body(() => {
213
+ startWork('ticks', 1, 'owned lifted final phases');
214
+ if (prepared.cases.length !== prepared.ordered.length || !prepared.cases.length)
215
+ return;
216
+ const initialBefore = fullWork(), initialWall = observe ? traceNow() : 0;
217
+ const initial = proveLiftedCountInitial(m, family, law, prepared.cases[0].proof.instances, until, requestFor);
218
+ observe?.({ stage: 'lifted-initial', checked: !!initial, units: (fullWork() - initialBefore) / fullRate, wallMs: traceNow() - initialWall });
219
+ if (!initial)
220
+ return;
221
+ const compositionBefore = fullWork(), compositionWall = observe ? traceNow() : 0;
222
+ const result = composeCountOperationProofs({ original: m, machine: m, shape: prepared.shape.countShape, restrictions: [], inputCounts: {} }, family, law, prepared.cases, until, requestFor, observe ? (stage, value) => observe({ stage, value }) : undefined, { initial, propagateBudgetExpiry: true, ...(env.GDP_COUNT_C2_LEMMAS === '1' ? { slicedLemmas: true } : {}) });
223
+ observe?.({ stage: 'lifted-composition', checked: !!result, units: (fullWork() - compositionBefore) / fullRate, wallMs: traceNow() - compositionWall });
224
+ return result && recordCountStrategyPremises(family, result);
225
+ });
226
+ }
@@ -0,0 +1,32 @@
1
+ import { type C, type E, type Law, type Machine } from './machine.js';
2
+ import { type Count, type MapRead } from '../kernel/kernel.js';
3
+ export type LiftedTransport = {
4
+ post: MapRead;
5
+ target?: MapRead;
6
+ kind: 'equality' | 'upper' | 'zero';
7
+ postBody: E;
8
+ targetBody: E;
9
+ derived: boolean;
10
+ derivedFrom?: number[];
11
+ };
12
+ export type LiftedTransportRegion = {
13
+ name: string;
14
+ when: C[];
15
+ premises: Law[];
16
+ tuples: E[][];
17
+ activeTuple: E[];
18
+ relations: LiftedTransport[];
19
+ partitions: {
20
+ terms: [number, string][];
21
+ }[];
22
+ unmatched: {
23
+ read: MapRead;
24
+ body: E;
25
+ }[];
26
+ };
27
+ export declare function matchLiftedCountBodies(left: Count, right: Count): boolean;
28
+ export declare function proposeTransportPartitions(counts: Count[]): {
29
+ terms: [number, string][];
30
+ }[];
31
+ export declare function liftedCopyTuples(law: Law, source: E): E[][];
32
+ export declare function proposeLiftedTransports(m: Machine, family: Law[], law: Law, value: number): LiftedTransportRegion[] | undefined;