gdp-wired 0.50.6 → 0.52.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 (91) hide show
  1. package/README.md +2 -2
  2. package/dist/core/accel-refute.d.ts +53 -0
  3. package/dist/core/accel-refute.js +997 -0
  4. package/dist/core/cli.d.ts +2 -0
  5. package/dist/core/cli.js +8 -1
  6. package/dist/core/cycles.d.ts +2 -0
  7. package/dist/core/cycles.js +12 -9
  8. package/dist/core/dsl.d.ts +11 -2
  9. package/dist/core/dsl.js +194 -29
  10. package/dist/core/fixed-division.d.ts +9 -0
  11. package/dist/core/fixed-division.js +87 -0
  12. package/dist/core/fixed-integers.d.ts +33 -0
  13. package/dist/core/fixed-integers.js +279 -0
  14. package/dist/core/live-support.d.ts +5 -0
  15. package/dist/core/live-support.js +148 -0
  16. package/dist/core/live.js +194 -37
  17. package/dist/core/lockstep.d.ts +5 -0
  18. package/dist/core/lockstep.js +23 -0
  19. package/dist/core/machine.d.ts +1 -0
  20. package/dist/core/machine.js +33 -3
  21. package/dist/core/ordered-pair-seeds.d.ts +2 -0
  22. package/dist/core/ordered-pair-seeds.js +109 -0
  23. package/dist/core/proof-output.d.ts +38 -1
  24. package/dist/core/proof-output.js +38 -0
  25. package/dist/core/search-termination.d.ts +4 -0
  26. package/dist/core/search-termination.js +1 -1
  27. package/dist/core/source-check.d.ts +4 -1
  28. package/dist/core/source-check.js +5 -2
  29. package/dist/core/sparse-kind-proof.d.ts +7 -0
  30. package/dist/core/sparse-kind-proof.js +49 -0
  31. package/dist/core/step-seeds.d.ts +46 -0
  32. package/dist/core/step-seeds.js +316 -0
  33. package/dist/kernel/integer-primitives.d.ts +38 -0
  34. package/dist/kernel/integer-primitives.js +179 -0
  35. package/dist/kernel/kernel.d.ts +1 -0
  36. package/dist/kernel/kernel.js +44 -5
  37. package/dist/kernel/prove.js +13 -0
  38. package/dist/kernel/word-division-cuts.d.ts +6 -0
  39. package/dist/kernel/word-division-cuts.js +69 -0
  40. package/dist/kernel/word-division.d.ts +12 -0
  41. package/dist/kernel/word-division.js +167 -0
  42. package/dist/lean-kernel/Cert.lean +222 -0
  43. package/dist/lean-kernel/Count.lean +1568 -0
  44. package/dist/lean-kernel/Ghost.lean +373 -0
  45. package/dist/lean-kernel/GhostMap.lean +426 -0
  46. package/dist/lean-kernel/Kernel.lean +2881 -0
  47. package/dist/lean-kernel/Live.lean +1168 -0
  48. package/dist/lean-kernel/Progress.lean +543 -0
  49. package/dist/lean-kernel/Sets.lean +1975 -0
  50. package/dist/lean-kernel/StepLaw.lean +128 -0
  51. package/dist/lean-kernel/Steps.lean +477 -0
  52. package/dist/lean-kernel/Sums.lean +916 -0
  53. package/dist/lean-kernel/emit.d.ts +8 -1
  54. package/dist/lean-kernel/emit.js +59 -15
  55. package/dist/lean-kernel/integer-primitives.d.ts +17 -0
  56. package/dist/lean-kernel/integer-primitives.js +81 -0
  57. package/dist/lean-kernel/lean-aggregate/FiniteFold.lean +44 -0
  58. package/dist/lean-kernel/lean-aggregate/GroupedTransport.lean +308 -0
  59. package/dist/lean-kernel/lean-aggregate/aggregate.d.ts +13 -0
  60. package/dist/lean-kernel/lean-aggregate/aggregate.js +68 -0
  61. package/dist/lean-kernel/lean-aggregate/assets.d.ts +5 -0
  62. package/dist/lean-kernel/lean-aggregate/assets.js +7 -0
  63. package/dist/lean-kernel/lean-aggregate/audit.d.ts +3 -0
  64. package/dist/lean-kernel/lean-aggregate/audit.js +13 -0
  65. package/dist/lean-kernel/lean-aggregate/exact.d.ts +15 -0
  66. package/dist/lean-kernel/lean-aggregate/exact.js +51 -0
  67. package/dist/lean-kernel/lean-aggregate/index.d.ts +19 -0
  68. package/dist/lean-kernel/lean-aggregate/index.js +52 -0
  69. package/dist/lean-kernel/lean-aggregate/point-fold.d.ts +27 -0
  70. package/dist/lean-kernel/lean-aggregate/point-fold.js +79 -0
  71. package/dist/lean-kernel/lean-aggregate/replay-fold.d.ts +2 -0
  72. package/dist/lean-kernel/lean-aggregate/replay-fold.js +163 -0
  73. package/dist/lean-kernel/lean-aggregate/source.d.ts +2 -0
  74. package/dist/lean-kernel/lean-aggregate/source.js +141 -0
  75. package/dist/lean-kernel/lean-aggregate/weighted-flags.d.ts +2 -0
  76. package/dist/lean-kernel/lean-aggregate/weighted-flags.js +26 -0
  77. package/dist/lean-kernel/lean-aggregate/weighted-replay.d.ts +7 -0
  78. package/dist/lean-kernel/lean-aggregate/weighted-replay.js +53 -0
  79. package/dist/lean-kernel/lean-aggregate/weighted-seeded.d.ts +30 -0
  80. package/dist/lean-kernel/lean-aggregate/weighted-seeded.js +64 -0
  81. package/dist/lean-kernel/lean-aggregate/weighted.d.ts +18 -0
  82. package/dist/lean-kernel/lean-aggregate/weighted.js +115 -0
  83. package/dist/lean-kernel/lean-aggregate/worker.d.ts +10 -0
  84. package/dist/lean-kernel/lean-aggregate/worker.js +46 -0
  85. package/dist/lean-kernel/library.js +13 -0
  86. package/dist/lean-kernel/word-division-export.d.ts +26 -0
  87. package/dist/lean-kernel/word-division-export.js +172 -0
  88. package/dist/lean-kernel/word-division-lower.d.ts +10 -0
  89. package/dist/lean-kernel/word-division-lower.js +103 -0
  90. package/docs/lean-aggregate.md +29 -0
  91. package/package.json +6 -1
@@ -0,0 +1,172 @@
1
+ // The reserved word maps are *not* arbitrary state maps. This module records the
2
+ // exact source-level encoding and renders their Nat semantics for Lean obligations.
3
+ // A machine certificate may use these only when the Lean checker itself derives
4
+ // the corresponding digit/carry facts; merely adding facts to a certificate is unsound.
5
+ import { parseWordDivisionName, wordDivisionArgs, wordDivisionName } from "../kernel/word-division.js";
6
+ import { leanTerms } from "./lean-terms.js";
7
+ /** Walk arbitrary machine/law syntax; invalid reserved names or tuple arity fail closed. */
8
+ export function wordReads(source) {
9
+ const out = [], seen = new WeakSet();
10
+ const visit = (node) => {
11
+ if (node === null || typeof node !== 'object' || seen.has(node))
12
+ return;
13
+ seen.add(node);
14
+ if (!Array.isArray(node)) {
15
+ const x = node;
16
+ if (x.op === 'get' && typeof x.map === 'string' && x.map.startsWith('worddiv$')) {
17
+ const spec = parseWordDivisionName(x.map);
18
+ if (!spec || !x.key || typeof x.key !== 'object')
19
+ throw new Error('invalid reserved word-division read');
20
+ const key = x.key, args = wordDivisionArgs(key, spec.width);
21
+ if (!args)
22
+ throw new Error('invalid reserved word-division tuple');
23
+ out.push({ spec, args, key, map: x.map });
24
+ }
25
+ }
26
+ for (const child of Object.values(node))
27
+ visit(child);
28
+ };
29
+ visit(source);
30
+ return out;
31
+ }
32
+ /** Native helper IDs needed even when a word-valued update is irrelevant to all
33
+ * exported laws and therefore absent from the minimized proof obligations. */
34
+ export function wordSchemaMapNames(source) {
35
+ const widths = new Set(wordReads(source).map(read => read.spec.width));
36
+ return [...widths].flatMap(width => {
37
+ const n = width === 8 ? 1 : width / 16;
38
+ return [...Array.from({ length: n }, (_, i) => wordDivisionName(width, 'q', i)),
39
+ ...Array.from({ length: n }, (_, i) => wordDivisionName(width, 'r', i)),
40
+ ...Array.from({ length: 2 * n }, (_, i) => wordDivisionName(width, 'c', i + 1))];
41
+ });
42
+ }
43
+ /** Build a closed Lean computation from actual lowered limb values. The expression
44
+ * is independently evaluated by Lean's Nat division, not by a TS answer. */
45
+ export function wordDigitLean(read, operands) {
46
+ const { width, part, index } = read.spec;
47
+ const n = width === 8 ? 1 : width / 16, radix = width === 8 ? 256 : 65536;
48
+ if (operands.length !== 2 * n || operands.some(v => !Number.isSafeInteger(v) || v < 0 || v >= radix))
49
+ throw new Error('closed word gate requires exactly bounded limbs');
50
+ const args = '[' + operands.join(', ') + ']';
51
+ return `WordDivision.value ${width} ${part === 'q' ? 0 : part === 'r' ? 1 : 2} ${index} ${args}`;
52
+ }
53
+ /** Right-associated Kern.cpair key decoded in the same order as wordDivisionArgs. */
54
+ export function wordKeyPartsLean(key, count) {
55
+ if (!Number.isSafeInteger(count) || count < 2 || count > 8)
56
+ throw new Error('invalid word limb count');
57
+ let tail = key;
58
+ const parts = [];
59
+ for (let i = 1; i < count; i++) {
60
+ parts.push(`(Kern.pickP 0 ${tail})`);
61
+ tail = `(Kern.pickP 1 ${tail})`;
62
+ }
63
+ return [...parts, tail];
64
+ }
65
+ /** A concrete, transparent interpretation of every reserved map index, including
66
+ * helper digit/carry maps introduced only by generated certificate hypotheses.
67
+ * Ordinary map indices continue to read base. This overlay alone is NOT a proof
68
+ * of a machine certificate: all used helper facts need a Lean semantic discharge. */
69
+ export function wordMapOverlayLean(reads, maps, name) {
70
+ if (!/^[A-Za-z][A-Za-z0-9_]*$/.test(name))
71
+ throw new Error('invalid Lean name');
72
+ const cases = new Map();
73
+ for (const read of reads) {
74
+ const at = maps.indexOf(read.map);
75
+ if (at < 0)
76
+ throw new Error(`missing word map ${read.map}`);
77
+ const old = cases.get(read.map);
78
+ if (old && JSON.stringify(old) !== JSON.stringify(read.spec))
79
+ throw new Error('inconsistent reserved map');
80
+ cases.set(read.map, read.spec);
81
+ }
82
+ for (const map of maps) {
83
+ if (!map.startsWith('worddiv$'))
84
+ continue;
85
+ const spec = parseWordDivisionName(map);
86
+ if (!spec)
87
+ throw new Error(`invalid reserved word map ${map}`);
88
+ cases.set(map, spec);
89
+ }
90
+ let body = 'base mp key';
91
+ for (const [map, spec] of [...cases].reverse()) {
92
+ const n = spec.width === 8 ? 1 : spec.width / 16;
93
+ const args = `[${wordKeyPartsLean('key', 2 * n).join(', ')}]`;
94
+ const tag = spec.part === 'q' ? 0 : spec.part === 'r' ? 1 : 2;
95
+ body = `if mp = ${maps.indexOf(map)} then WordDivision.value ${spec.width} ${tag} ${spec.index} ${args} else ${body}`;
96
+ }
97
+ return `def ${name} (base : Nat → Nat → Nat) (mp key : Nat) : Nat :=\n ${body}`;
98
+ }
99
+ /** Exact descriptor data for the generic Lean schema. No caller-supplied fact
100
+ * proposition is trusted: Lean constructs the complete clause list itself. */
101
+ export function wordMachineBridgeLean(id, source, vars, maps) {
102
+ const reads = wordReads(source);
103
+ if (!reads.length)
104
+ return '';
105
+ const unique = new Map();
106
+ for (const read of reads)
107
+ unique.set(`${read.spec.width}:${JSON.stringify(read.args)}`, read);
108
+ const terms = leanTerms(vars, maps, id);
109
+ const list = (xs) => `[${xs.join(', ')}]`;
110
+ const reserved = maps.flatMap((map, i) => map.startsWith('worddiv$') ? [i] : []);
111
+ const mapId = (width, part, i) => {
112
+ const map = wordDivisionName(width, part, i), at = maps.indexOf(map);
113
+ if (at < 0)
114
+ throw new Error(`${id}: missing schema map ${map}`);
115
+ return at;
116
+ };
117
+ const names = [], blocks = [];
118
+ for (const [i, read] of [...unique.values()].entries()) {
119
+ const name = `${id}_word_spec${i}`, width = read.spec.width, n = width === 8 ? 1 : width / 16;
120
+ names.push(name);
121
+ const q = Array.from({ length: n }, (_, j) => mapId(width, 'q', j));
122
+ const r = Array.from({ length: n }, (_, j) => mapId(width, 'r', j));
123
+ const carries = Array.from({ length: 2 * n }, (_, j) => mapId(width, 'c', j + 1));
124
+ const ids = [...q, ...r, ...carries];
125
+ const finiteCases = (indices) => `have cases : ${indices.map(j => `i = ${j}`).join(' ∨ ')} := by omega\n rcases cases with ${indices.map(() => 'rfl').join(' | ')}\n all_goals rfl`;
126
+ blocks.push(`def ${name} : WordFacts.Spec := ⟨${width}, ${list(read.args.map(x => `(${terms.e(x)})`))}, ${list(q)}, ${list(r)}, ${list(carries)}⟩
127
+ theorem ${name}_valid : ${name}.Valid := by unfold WordFacts.Spec.Valid; decide +kernel
128
+ -- Dispatch is checked for every native digit at every concrete tuple key.
129
+ theorem ${name}_values : WordFacts.ValueMatches ${name} ${id}_word.value := by
130
+ refine ⟨?_, ?_, ?_⟩
131
+ · intro i hi key
132
+ change i < ${n} at hi
133
+ ${finiteCases(Array.from({ length: n }, (_, j) => j))}
134
+ · intro i hi key
135
+ change i < ${n} at hi
136
+ ${finiteCases(Array.from({ length: n }, (_, j) => j))}
137
+ · intro i hlo hhi key
138
+ change i ≤ ${2 * n} at hhi
139
+ ${finiteCases(Array.from({ length: 2 * n }, (_, j) => j + 1))}
140
+ theorem ${name}_reserved {mp : Nat} (hm : mp ∈ ${name}.reserved) :
141
+ mp ∈ ${id}_word.reserved := by
142
+ change mp ∈ ${list(ids)} at hm
143
+ change mp ∈ ${list(reserved)}
144
+ simp only [List.mem_cons, List.not_mem_nil, or_false] at hm
145
+ rcases hm with ${ids.map(() => 'rfl').join(' | ')}
146
+ all_goals decide +kernel
147
+ `);
148
+ }
149
+ return `${wordMapOverlayLean(reads, maps, `${id}_word_maps`)}
150
+ def ${id}_word : Kern.WordReach.WordSMachine := {
151
+ s := ${id}_machine
152
+ reserved := ${list(reserved)}
153
+ value := ${id}_word_maps (fun _ _ => 0)
154
+ startDisjoint := by decide +kernel
155
+ carriedDisjoint := by decide +kernel
156
+ everyDisjoint := by decide +kernel
157
+ writesDisjoint := by decide +kernel
158
+ }
159
+ ${blocks.join('\n')}
160
+ def ${id}_word_extra : List Kern.C := (${list(names)} : List WordFacts.Spec).flatMap WordFacts.facts
161
+ theorem ${id}_word_extra_sound : ∀ X N,
162
+ Kern.WordReach.WordInterpret ${id}_word.reserved ${id}_word.value N →
163
+ ∀ c ∈ ${id}_word_extra, Kern.evalC X N c = true := by
164
+ intro X N h c hc
165
+ simp only [${id}_word_extra, List.mem_flatMap] at hc
166
+ obtain ⟨spec, hs, hc⟩ := hc
167
+ simp only [List.mem_cons, List.not_mem_nil, or_false] at hs
168
+ rcases hs with ${names.map(() => 'rfl').join(' | ')}
169
+ ${names.map(name => ` · exact WordFacts.facts_sound ${name} ${name}_valid X N
170
+ (WordFacts.interpret_sound ${name} ${name}_valid ${id}_word.value N X ${name}_values
171
+ (fun mp hm key => h mp (${name}_reserved hm) key)) c hc`).join('\n')}`;
172
+ }
@@ -0,0 +1,10 @@
1
+ import type { Machine } from '../core/machine.js';
2
+ /** Certified scalar-machine range for any actual q/r/c digit (8/16/32/64).
3
+ * This is NOT a generic SMachine exporter; the exact source shape is verified. */
4
+ export declare function wordDigitRangeMachineToLean(id: string, m: Machine, opts?: {
5
+ fragment?: boolean;
6
+ }): string;
7
+ /** Compatibility wrapper: admit only the original one-limb u8 quotient lane. */
8
+ export declare function q8RangeMachineToLean(id: string, m: Machine, opts?: {
9
+ fragment?: boolean;
10
+ }): string;
@@ -0,0 +1,103 @@
1
+ import { check } from "../kernel/kernel.js";
2
+ import { grow } from "../kernel/prove.js";
3
+ import { encode, TRUE } from "./emit.js";
4
+ import { leanTerms } from "./lean-terms.js";
5
+ import { wordReads, wordMapOverlayLean } from "./word-division-export.js";
6
+ import { wordDivisionKey } from "../kernel/word-division.js";
7
+ const constant = (value) => ({ op: 'const', value });
8
+ const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
9
+ /** Certified scalar-machine range for any actual q/r/c digit (8/16/32/64).
10
+ * This is NOT a generic SMachine exporter; the exact source shape is verified. */
11
+ export function wordDigitRangeMachineToLean(id, m, opts = {}) {
12
+ const reads = wordReads(m);
13
+ if (reads.length !== 1)
14
+ throw new Error('expected one valid reserved word read');
15
+ const { width, part, index } = reads[0].spec;
16
+ // Model shape is an allowlist, not a denylist: future Machine/step fields
17
+ // cannot silently change runtime semantics while this export omits them.
18
+ const machineKeys = new Set(['name', 'params', 'inputs', 'state', 'step']);
19
+ if (Object.keys(m).some(key => !machineKeys.has(key)) ||
20
+ Object.keys(m.step).some(key => key !== 'state'))
21
+ throw new Error('unsupported scalar machine metadata or step effect');
22
+ const n = width === 8 ? 1 : width / 16, radix = width === 8 ? 256 : 65536;
23
+ const bound = part === 'c' ? n * radix : radix, op = part === 'c' ? '<=' : '<';
24
+ if (!/^[A-Za-z][A-Za-z0-9_]*$/.test(id) || m.params.length || m.inputs.length !== 2 * n ||
25
+ Object.keys(m.state).length !== 1 || Object.keys(m.step.state ?? {}).length !== 1 ||
26
+ new Set([...m.inputs, ...Object.keys(m.state)]).size !== 2 * n + 1 ||
27
+ !Array.isArray(m.params) || !Array.isArray(m.inputs))
28
+ throw new Error('word digit range machine requires exact scalar shape without auxiliary effects');
29
+ const out = Object.keys(m.state)[0];
30
+ const key = wordDivisionKey(m.inputs.map((name) => ({ op: 'var', name })));
31
+ const expr = { op: 'get', map: reads[0].map, key };
32
+ if (!same(m.state[out], constant(0)) || !same(m.step.state?.[out], expr) || !same(reads[0].key, key))
33
+ throw new Error('word digit range machine must use its exact reserved read and zero initialization');
34
+ const law = { op, a: { op: 'var', name: out }, b: constant(bound) };
35
+ const fact = { op, a: expr, b: constant(bound) };
36
+ const neg = (x) => ({ op: 'not', x });
37
+ const pre = { op: '<=', a: constant(0), b: constant(0) };
38
+ const start = { name: id + '_start', hyps: [pre, neg({ op, a: constant(0), b: constant(bound) })] };
39
+ const step = { name: id + '_step', hyps: [pre, pre, law, fact, neg(fact)] };
40
+ const vars = [...m.inputs, out], maps = [expr.map];
41
+ const terms = leanTerms(vars, maps, id);
42
+ const prove = (g) => {
43
+ const result = grow(g);
44
+ if (!('tree' in result) || !check(g, result.tree))
45
+ throw new Error(id + ': proof tree does not check');
46
+ return encode({ name: g.name, goal: g, tree: result.tree }, false, true, vars, maps);
47
+ };
48
+ const a = prove(start), b = prove(step);
49
+ const overlay = wordMapOverlayLean(reads, maps, id + '_maps');
50
+ const e = terms.e, c = terms.c, state = m.inputs.length;
51
+ const values = `[${m.inputs.map((_, i) => `env ${i}`).join(', ')}]`;
52
+ const lemma = part === 'q' ? 'value_q_lt' : 'value_r_lt';
53
+ const factProof = part === 'c'
54
+ ? `have hb := WordDivision.carry_bound ${width} ${values} ${index}
55
+ simpa [${id}_maps, Kern.evalC, Kern.evalE, Kern.pickP, Kern.cun_cpair,
56
+ WordDivision.value_c, WordDivision.limbs, WordDivision.radix] using hb`
57
+ : `have hb := WordDivision.${lemma} ${width} ${index} ${values}
58
+ simpa [${id}_maps, Kern.evalC, Kern.evalE, Kern.pickP,
59
+ Kern.cun_cpair, WordDivision.radix] using hb`;
60
+ const source = `${overlay}
61
+ def ${id}_machine : Kern.Machine := ⟨[${m.inputs.map((_, i) => i).join(', ')}], [(${state}, ${e(constant(0))})],
62
+ [(${state}, ${e(expr)})], ${TRUE}, ${TRUE}⟩
63
+ def ${id}_entry : WordDivisionBridge.Entry :=
64
+ ⟨${c(law)}, [], [${c(fact)}], (${a.tab}, ${a.tree}), (${b.tab}, ${b.tree})⟩
65
+ theorem ${id}_check : WordDivisionBridge.checkEntries ${id}_machine [${id}_entry] = true := by decide +kernel
66
+ /-- Full reachable-state machine law, for all input sequences and all base maps. -/
67
+ theorem ${id}_range (base : Nat → Nat → Nat) (ρ : Nat → Nat)
68
+ (hr : Kern.Reach ${id}_machine (${id}_maps base) ρ) :
69
+ Kern.evalC ρ (${id}_maps base) (${c(law)}) = true := by
70
+ have hf : ∀ env p, p ∈ ([${id}_entry] : List WordDivisionBridge.Entry) →
71
+ (∀ f ∈ p.startFacts, Kern.evalC env (${id}_maps base) f = true) ∧
72
+ (∀ f ∈ p.stepFacts, Kern.evalC env (${id}_maps base) f = true) := by
73
+ intro env p hp
74
+ simp only [List.mem_singleton] at hp
75
+ subst p
76
+ constructor
77
+ · intro f h
78
+ change f ∈ ([] : List Kern.C) at h
79
+ simp at h
80
+ · intro f h
81
+ change f ∈ [${c(fact)}] at h
82
+ simp only [List.mem_singleton] at h
83
+ subst f
84
+ ${factProof}
85
+ have hs := WordDivisionBridge.checkEntries_sound ${id}_machine [${id}_entry]
86
+ ${id}_check (${id}_maps base) hf
87
+ exact hs ρ hr (${c(law)}) (by simp [${id}_entry])
88
+ #print axioms ${id}_range`;
89
+ return opts.fragment ? source : `import WordDivisionBridge
90
+ open Kern
91
+ set_option maxRecDepth 100000
92
+ set_option maxHeartbeats 0
93
+
94
+ ${source}
95
+ `;
96
+ }
97
+ /** Compatibility wrapper: admit only the original one-limb u8 quotient lane. */
98
+ export function q8RangeMachineToLean(id, m, opts = {}) {
99
+ const reads = wordReads(m);
100
+ if (reads.length !== 1 || reads[0].spec.width !== 8 || reads[0].spec.part !== 'q' || reads[0].spec.index !== 0)
101
+ throw new Error('expected one actual u8 quotient digit');
102
+ return wordDigitRangeMachineToLean(id, m, opts);
103
+ }
@@ -0,0 +1,29 @@
1
+ # Opt-in aggregate proofs in Lean
2
+
3
+ `gdp-wired/lean-aggregate` is a separate, experimental entry for aggregate invariants. It is off by default. Neither `proveRule`, the standard CLI, nor the default corpus scores use it. There is no new gdp-wired kernel rule for aggregate closure in this release.
4
+
5
+ Install the official Lean **4.34.0** toolchain and put `lean` on `PATH` (with elan: `elan toolchain install leanprover/lean4:v4.34.0`). No Lake project or separate proof library is needed: the npm package ships the Lean sources used by this entry. Use this API from Node:
6
+
7
+ ```ts
8
+ import {proveLeanAggregate} from 'gdp-wired/lean-aggregate'
9
+
10
+ const result = await proveLeanAggregate(rule.machine, invariant)
11
+ if (result.kind === 'lean-checked') {
12
+ console.log(result.verdict) // checked in Lean, not by the kernel
13
+ console.log(result.receipt.inputSha256, result.receipt.sourceSha256)
14
+ } else {
15
+ console.log(result.reason, result.detail) // not checked; not a refutation
16
+ }
17
+ ```
18
+
19
+ Pass one invariant over reachable states, not a step or a liveness law. The adapter checks **unmarked symbolic models only**: it refuses source-bound machines or laws even if native translation evidence is available. Pass plain records and dense arrays of own enumerable data (ordinary DSL output or parsed JSON); omit absent optional fields instead of writing `undefined`. Proxies, accessors, serialization hooks (including inherited `toJSON`), custom prototypes, and extra fields outside the supported AST are refused. The adapter snapshots the data without calling hooks and applies the ordinary kernel scope check to that exact source before looking for either proof shape:
20
+
21
+
22
+ - **Finite fold:** counters over disjoint classes in a bounded table, maintained by a point update and a broadcast reset. The gdp-wired kernel checks local sequents. Lean checks those trees and composes them into the full original invariant.
23
+ - **Weighted sum:** an account-like accumulator updated by adding or removing weights associated with a key. The adapter proposes an instrumented row, an exact weighted equality, and the supporting invariants. Lean transports the checked instrumented family to the caller's original machine and original universally quantified invariant.
24
+
25
+ This route is intended for both etcd Raft tally invariants and TigerBeetle transfer limit invariants #0 and #1 in the repository corpus. The claims are about the corpus models, not equivalence with the upstream implementations. No special case in the prover matches those names or law indices. Other shapes, including custom functions, finite binders, and existing count/sum instrumentation, can be refused.
26
+
27
+ Success is **checked in Lean, not by the kernel**. There is no `checked: true` (or `proven` boolean) to mix with a native verdict. The receipt identifies the exact input (SHA-256 of the UTF-8 JSON snapshot of `[machine, law]`), the emitted `.lean` source and its digest, each used library's digest, the Lean version, and the axiom report for `aggregate_claim`. The adapter builds the packaged libraries in a fresh directory, runs Lean on the emitted theorem, and permits only `propext`, `Classical.choice`, and `Quot.sound`. It refuses incomplete reports, unexpected axioms, wrong toolchains, failures and timeouts. The receipt records local execution, not a signed attestation: trust the installed package and the local Lean executable as you would when running Lean yourself.
28
+
29
+ Imports do not start Lean or search. Calling the function starts an isolated search worker; only a retained candidate starts Lean. `{searchMs, leanMs}` sets separate deadlines (defaults: 60 s for search, with a small worker/serialization allowance; 180 s for compiling and checking in Lean). A refusal does not change the ordinary prover's result.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gdp-wired",
3
- "version": "0.50.6",
3
+ "version": "0.52.0",
4
4
  "description": "An automatic prover for stateful rules (budgets, caps, windows, workflows, policies): laws proven with no proof to write, checked again in Lean, counterexamples found on the GPU, the rule shipped as code",
5
5
  "keywords": [
6
6
  "verification",
@@ -48,6 +48,10 @@
48
48
  "types": "./dist/lean-kernel/emit.d.ts",
49
49
  "default": "./dist/lean-kernel/emit.js"
50
50
  },
51
+ "./lean-aggregate": {
52
+ "types": "./dist/lean-kernel/lean-aggregate/index.d.ts",
53
+ "default": "./dist/lean-kernel/lean-aggregate/index.js"
54
+ },
51
55
  "./lift": {
52
56
  "types": "./dist/lean-kernel/lift.d.ts",
53
57
  "default": "./dist/lean-kernel/lift.js"
@@ -188,6 +192,7 @@
188
192
  "README.md",
189
193
  "LICENSE",
190
194
  "docs/agent-consult.md",
195
+ "docs/lean-aggregate.md",
191
196
  "docs/agent-consult-workspace-check.md",
192
197
  "examples/agent-consult.json"
193
198
  ],