gdp-wired 0.47.0 → 0.48.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 (170) hide show
  1. package/README.md +15 -4
  2. package/dist/core/carry.d.ts +15 -0
  3. package/dist/core/carry.js +651 -0
  4. package/dist/core/cli.d.ts +3 -1
  5. package/dist/core/cli.js +28 -8
  6. package/dist/core/count-cases.d.ts +24 -0
  7. package/dist/core/count-cases.js +320 -0
  8. package/dist/core/count-cert-grow.d.ts +4 -0
  9. package/dist/core/count-cert-grow.js +37 -0
  10. package/dist/core/count-cert-transport.d.ts +3 -0
  11. package/dist/core/count-cert-transport.js +58 -0
  12. package/dist/core/count-completion.d.ts +9 -0
  13. package/dist/core/count-completion.js +27 -0
  14. package/dist/core/count-cubes.d.ts +8 -0
  15. package/dist/core/count-cubes.js +69 -0
  16. package/dist/core/count-demand.d.ts +37 -0
  17. package/dist/core/count-demand.js +361 -0
  18. package/dist/core/count-facts.d.ts +52 -0
  19. package/dist/core/count-facts.js +247 -0
  20. package/dist/core/count-focus-proof.d.ts +8 -0
  21. package/dist/core/count-focus-proof.js +140 -0
  22. package/dist/core/count-focused.d.ts +22 -0
  23. package/dist/core/count-focused.js +676 -0
  24. package/dist/core/count-ranges.d.ts +5 -0
  25. package/dist/core/count-ranges.js +65 -0
  26. package/dist/core/count-recovery/action-guard.d.ts +5 -0
  27. package/dist/core/count-recovery/action-guard.js +51 -0
  28. package/dist/core/count-recovery/boolean-core.d.ts +16 -0
  29. package/dist/core/count-recovery/boolean-core.js +258 -0
  30. package/dist/core/count-recovery/carried-case.d.ts +2 -0
  31. package/dist/core/count-recovery/carried-case.js +24 -0
  32. package/dist/core/count-recovery/conditional-check-cache.d.ts +23 -0
  33. package/dist/core/count-recovery/conditional-check-cache.js +130 -0
  34. package/dist/core/count-recovery/conditional-cuts.d.ts +6 -0
  35. package/dist/core/count-recovery/conditional-cuts.js +318 -0
  36. package/dist/core/count-recovery/conditional-proof.d.ts +19 -0
  37. package/dist/core/count-recovery/conditional-proof.js +306 -0
  38. package/dist/core/count-recovery/derivability-closure.d.ts +14 -0
  39. package/dist/core/count-recovery/derivability-closure.js +533 -0
  40. package/dist/core/count-recovery/empty-count-source.d.ts +2 -0
  41. package/dist/core/count-recovery/empty-count-source.js +40 -0
  42. package/dist/core/count-recovery/field-bound-lemmas.d.ts +23 -0
  43. package/dist/core/count-recovery/field-bound-lemmas.js +640 -0
  44. package/dist/core/count-recovery/field-case.d.ts +5 -0
  45. package/dist/core/count-recovery/field-case.js +89 -0
  46. package/dist/core/count-recovery/field-demand.d.ts +46 -0
  47. package/dist/core/count-recovery/field-demand.js +47 -0
  48. package/dist/core/count-recovery/field-only.d.ts +3 -0
  49. package/dist/core/count-recovery/field-only.js +18 -0
  50. package/dist/core/count-recovery/fold-path.d.ts +6 -0
  51. package/dist/core/count-recovery/fold-path.js +35 -0
  52. package/dist/core/count-recovery/frame-lemmas.d.ts +9 -0
  53. package/dist/core/count-recovery/frame-lemmas.js +120 -0
  54. package/dist/core/count-recovery/guard-cases.d.ts +12 -0
  55. package/dist/core/count-recovery/guard-cases.js +138 -0
  56. package/dist/core/count-recovery/key-closure.d.ts +14 -0
  57. package/dist/core/count-recovery/key-closure.js +62 -0
  58. package/dist/core/count-recovery/leaf-allowance.d.ts +4 -0
  59. package/dist/core/count-recovery/leaf-allowance.js +7 -0
  60. package/dist/core/count-recovery/lift-count-proxies.d.ts +6 -0
  61. package/dist/core/count-recovery/lift-count-proxies.js +175 -0
  62. package/dist/core/count-recovery/live-dependencies.d.ts +6 -0
  63. package/dist/core/count-recovery/live-dependencies.js +76 -0
  64. package/dist/core/count-recovery/member-inclusions.d.ts +11 -0
  65. package/dist/core/count-recovery/member-inclusions.js +168 -0
  66. package/dist/core/count-recovery/member-premises.d.ts +29 -0
  67. package/dist/core/count-recovery/member-premises.js +114 -0
  68. package/dist/core/count-recovery/natural-cases.d.ts +6 -0
  69. package/dist/core/count-recovery/natural-cases.js +59 -0
  70. package/dist/core/count-recovery/ops.d.ts +6 -0
  71. package/dist/core/count-recovery/ops.js +8 -0
  72. package/dist/core/count-recovery/pre-state-source.d.ts +8 -0
  73. package/dist/core/count-recovery/pre-state-source.js +18 -0
  74. package/dist/core/count-recovery/rebase-path.d.ts +9 -0
  75. package/dist/core/count-recovery/rebase-path.js +70 -0
  76. package/dist/core/count-recovery/rename-proof.d.ts +2 -0
  77. package/dist/core/count-recovery/rename-proof.js +102 -0
  78. package/dist/core/count-recovery/row-cases.d.ts +16 -0
  79. package/dist/core/count-recovery/row-cases.js +291 -0
  80. package/dist/core/count-recovery/scalar-guards.d.ts +7 -0
  81. package/dist/core/count-recovery/scalar-guards.js +291 -0
  82. package/dist/core/count-recovery/source-memo.d.ts +12 -0
  83. package/dist/core/count-recovery/source-memo.js +67 -0
  84. package/dist/core/count-select.d.ts +16 -0
  85. package/dist/core/count-select.js +24 -0
  86. package/dist/core/count-support.d.ts +598 -0
  87. package/dist/core/count-support.js +2080 -0
  88. package/dist/core/count-unions.d.ts +2 -0
  89. package/dist/core/count-unions.js +139 -0
  90. package/dist/core/count-witness-flags.d.ts +9 -0
  91. package/dist/core/count-witness-flags.js +37 -0
  92. package/dist/core/count-write-frames.d.ts +12 -0
  93. package/dist/core/count-write-frames.js +206 -0
  94. package/dist/core/counts.d.ts +20 -2
  95. package/dist/core/counts.js +807 -156
  96. package/dist/core/dsl.d.ts +50 -6
  97. package/dist/core/dsl.js +307 -65
  98. package/dist/core/effect.js +8 -1
  99. package/dist/core/exists.d.ts +1 -1
  100. package/dist/core/exists.js +80 -15
  101. package/dist/core/extract-check.d.ts +7 -1
  102. package/dist/core/extract-check.js +130 -13
  103. package/dist/core/extract-read.d.ts +22 -8
  104. package/dist/core/extract-read.js +29 -11
  105. package/dist/core/extract-shapes.js +122 -41
  106. package/dist/core/extract-standalone.js +53 -9
  107. package/dist/core/extract.js +9 -3
  108. package/dist/core/field-laws.d.ts +2 -0
  109. package/dist/core/field-laws.js +100 -0
  110. package/dist/core/finite-frontiers.d.ts +5 -0
  111. package/dist/core/finite-frontiers.js +116 -0
  112. package/dist/core/finite-houdini.d.ts +52 -0
  113. package/dist/core/finite-houdini.js +460 -0
  114. package/dist/core/finite-model.d.ts +13 -0
  115. package/dist/core/finite-model.js +68 -0
  116. package/dist/core/finite-tiny.d.ts +72 -0
  117. package/dist/core/finite-tiny.js +1052 -0
  118. package/dist/core/infer.d.ts +1 -1
  119. package/dist/core/infer.js +32 -9
  120. package/dist/core/laws.d.ts +2 -1
  121. package/dist/core/laws.js +47 -14
  122. package/dist/core/lemma-cuts.d.ts +38 -0
  123. package/dist/core/lemma-cuts.js +365 -0
  124. package/dist/core/machine.d.ts +39 -2
  125. package/dist/core/machine.js +240 -35
  126. package/dist/core/mutate.d.ts +55 -0
  127. package/dist/core/mutate.js +210 -0
  128. package/dist/core/native-domain.d.ts +6 -0
  129. package/dist/core/native-domain.js +114 -0
  130. package/dist/core/native-law.d.ts +3 -0
  131. package/dist/core/native-law.js +174 -0
  132. package/dist/core/quorum-laws.d.ts +5 -0
  133. package/dist/core/quorum-laws.js +239 -0
  134. package/dist/core/relational.js +10 -2
  135. package/dist/core/relevance.d.ts +4 -0
  136. package/dist/core/relevance.js +79 -0
  137. package/dist/core/runtime-wall.d.ts +3 -0
  138. package/dist/core/runtime-wall.js +4 -0
  139. package/dist/core/sample-step.d.ts +16 -0
  140. package/dist/core/sample-step.js +28 -0
  141. package/dist/core/source-check.d.ts +44 -0
  142. package/dist/core/source-check.js +126 -0
  143. package/dist/core/source-diagnostic.d.ts +1 -0
  144. package/dist/core/source-diagnostic.js +34 -0
  145. package/dist/core/support-budget.d.ts +2 -0
  146. package/dist/core/support-budget.js +6 -0
  147. package/dist/core/system.js +2 -0
  148. package/dist/core/wall.d.ts +6 -0
  149. package/dist/core/wall.js +23 -0
  150. package/dist/core/watch.js +4 -0
  151. package/dist/kernel/cdcl.d.ts +4 -0
  152. package/dist/kernel/cdcl.js +20 -5
  153. package/dist/kernel/kernel.d.ts +10 -0
  154. package/dist/kernel/kernel.js +56 -3
  155. package/dist/kernel/model-sequence.d.ts +2 -2
  156. package/dist/kernel/model-sequence.js +4 -3
  157. package/dist/kernel/model-values.d.ts +2 -0
  158. package/dist/kernel/model-values.js +60 -0
  159. package/dist/kernel/prove.d.ts +10 -0
  160. package/dist/kernel/prove.js +56 -8
  161. package/dist/kernel/prover-rows.d.ts +29 -0
  162. package/dist/kernel/prover-rows.js +114 -0
  163. package/dist/lean-kernel/emit.d.ts +39 -2
  164. package/dist/lean-kernel/emit.js +136 -24
  165. package/dist/lean-kernel/lean-terms.d.ts +1 -0
  166. package/dist/lean-kernel/lean-terms.js +13 -5
  167. package/dist/lean-kernel/library.js +4 -0
  168. package/dist/lean-kernel/qalpha.d.ts +7 -0
  169. package/dist/lean-kernel/qalpha.js +40 -0
  170. package/package.json +5 -1
@@ -0,0 +1,52 @@
1
+ import { type Law, type Machine, type Request, type State } from './machine.js';
2
+ import { type TinyFiniteOptions, type TinyFiniteStatistics, type TinySeedStatistics } from './finite-tiny.js';
3
+ type Env = Record<string, number>;
4
+ type Samples = {
5
+ p: Env;
6
+ sts: State[];
7
+ }[];
8
+ type Truth = boolean | undefined;
9
+ export declare function finiteEvaluator(m: Machine, stop?: () => boolean): (law: Law, p: Env, st: State) => Truth;
10
+ export type FiniteDrop = {
11
+ round: number;
12
+ law: Law;
13
+ params: Env;
14
+ pre: State;
15
+ request: Request;
16
+ post: State;
17
+ };
18
+ export declare const finiteDump: {
19
+ onStart?: (value: {
20
+ machine: Machine;
21
+ caller: Law[];
22
+ candidates: Law[];
23
+ }) => void;
24
+ onDrop?: (drop: FiniteDrop) => void;
25
+ };
26
+ export type FiniteOptions = {
27
+ randomStates?: number;
28
+ requests?: number;
29
+ seed?: number;
30
+ targeted?: boolean;
31
+ wallMs?: number;
32
+ onFinish?: (row: {
33
+ timedOut: boolean;
34
+ ms: number;
35
+ dropped: number;
36
+ }) => void;
37
+ onDrop?: (drop: FiniteDrop) => void;
38
+ onRound?: (row: {
39
+ round: number;
40
+ alive: number;
41
+ dropped: number;
42
+ randomStates: number;
43
+ steps: number;
44
+ }) => void;
45
+ };
46
+ export declare function finiteHoudini(source: Machine, m: Machine, caller: Law[], candidates: Law[], samples: Samples, options?: FiniteOptions): Law[];
47
+ export declare function finiteTinyHoudini(source: Machine, m: Machine, caller: Law[], candidates: Law[], params: Env[], options?: FiniteOptions & TinyFiniteOptions & {
48
+ rounds?: number;
49
+ onTiny?: (round: number, stats: TinyFiniteStatistics) => void;
50
+ onSeed?: (round: number, stats: TinySeedStatistics) => void;
51
+ }): Law[];
52
+ export {};
@@ -0,0 +1,460 @@
1
+ // A finite relative-CTI filter, never a proof. Unsupported evaluations are
2
+ // unknown; only an actual enabled step from a state satisfying the WHOLE
3
+ // current family may remove a non-caller. The checked prover sees survivors.
4
+ import { carriedView, compileC, compileE, fastStep, interpret, seeded, walk } from "./machine.js";
5
+ import { checkWall, searchWall, WallExpired } from "./wall.js";
6
+ import { boundaryState, lawFrontiers } from "./finite-frontiers.js";
7
+ import { wallAt, withWall } from "../kernel/prove.js";
8
+ import { tinyFiniteCandidates, tinySeedCandidates } from "./finite-tiny.js";
9
+ const variables = (t) => { const out = new Set(); walk(t, o => { if (o.op === 'var')
10
+ out.add(o.name); }); return out; };
11
+ const conjuncts = (c) => c.op === 'and' ? c.xs.flatMap(conjuncts) : [c];
12
+ // Universal binders need a complete finite cover, not merely 0..sampleSize.
13
+ // Guards provide finite upper bounds (including auxiliary half-count witnesses).
14
+ // Otherwise permit only direct finite-map reads and equality between binders:
15
+ // the explicit cells plus one distinct fresh key per binder cover every case.
16
+ export function finiteEvaluator(m, stop = () => false) {
17
+ const checkpoint = () => { checkWall('finite derived count'); if (stop())
18
+ throw new Error('finite evaluation stopped'); };
19
+ const plans = new WeakMap();
20
+ const cache = new WeakMap();
21
+ function plan(law) {
22
+ const keys = [...new Set([law.forall, ...law.keys ?? []].filter((k) => !!k))];
23
+ const guards = law.holds.op === 'or' ? law.holds.xs.flatMap(c => c.op === 'not' ? conjuncts(c.x) : []) : law.holds.op === 'not' ? conjuncts(law.holds.x) : [];
24
+ const gs = guards.map(c => ({ vars: [...variables(c)], test: compileC(c, m) }));
25
+ const cover = keys.map(key => {
26
+ let safe = true;
27
+ const maps = new Set();
28
+ const expression = (e) => {
29
+ if (!variables(e).has(key))
30
+ return;
31
+ if (e.op === 'get' && e.key.op === 'var' && e.key.name === key && e.map in (m.maps ?? {})) {
32
+ maps.add(e.map);
33
+ return;
34
+ }
35
+ safe = false;
36
+ };
37
+ const condition = (c) => {
38
+ if (c.op === 'and' || c.op === 'or')
39
+ c.xs.forEach(condition);
40
+ else if (c.op === 'not')
41
+ condition(c.x);
42
+ else if (c.op === 'all' || c.op === 'flag')
43
+ safe = false;
44
+ else if (!(c.op === '=' && c.a.op === 'var' && c.b.op === 'var' && keys.includes(c.a.name) && keys.includes(c.b.name))) {
45
+ expression(c.a);
46
+ expression(c.b);
47
+ }
48
+ };
49
+ condition(law.holds);
50
+ // Separate the target binder from its affine remainder, without turning
51
+ // natural truncated subtraction into integer subtraction.
52
+ const affine = (e) => {
53
+ if (!variables(e).has(key))
54
+ return { k: 0, rest: compileE(e, m) };
55
+ if (e.op === 'var')
56
+ return { k: 1, rest: () => 0 };
57
+ if (e.op === 'mul') {
58
+ const a = affine(e.a);
59
+ return a && { k: e.k * a.k, rest: (p, s) => e.k * a.rest(p, s) };
60
+ }
61
+ if (e.op === 'add') {
62
+ const a = affine(e.a), b = affine(e.b);
63
+ return a && b && { k: a.k + b.k, rest: (p, s) => a.rest(p, s) + b.rest(p, s) };
64
+ }
65
+ return undefined;
66
+ };
67
+ const upper = guards.flatMap(c => {
68
+ if (c.op !== '<' && c.op !== '<=' && c.op !== '=')
69
+ return [];
70
+ const a = affine(c.a), b = affine(c.b);
71
+ if (!a || !b || a.k === b.k || (a.k < b.k && c.op !== '='))
72
+ return [];
73
+ return [{ vars: [...variables(c)].filter(v => v !== key), test: (p, s) => Math.floor((b.rest(p, s) - a.rest(p, s) - (c.op === '<' ? 1 : 0)) / (a.k - b.k)) }];
74
+ });
75
+ return { key, safe, maps: [...maps], upper };
76
+ });
77
+ let nested = false;
78
+ walk(law.holds, o => { if (o.op === 'all')
79
+ nested = true; });
80
+ return { keys, cover, guards: gs, test: compileC(law.holds, m), supported: !nested && !law.some?.length && !keys.some(k => k in m.state || m.params.includes(k)) && ![...variables(law.holds)].some(k => m.inputs.includes(k) && !keys.includes(k)) };
81
+ }
82
+ return (law, p, st) => {
83
+ checkWall('finite law');
84
+ if (stop())
85
+ return undefined;
86
+ let entry = cache.get(st);
87
+ if (!entry || entry.params !== p) {
88
+ entry = { params: p, view: carriedView(m, st, Object.fromEntries((m.inputMaps ?? []).map(k => [k, new Map()])), undefined, p, checkpoint), values: new Map() };
89
+ cache.set(st, entry);
90
+ }
91
+ if (entry.values.has(law))
92
+ return entry.values.get(law);
93
+ let shape = plans.get(law);
94
+ if (!shape) {
95
+ shape = plan(law);
96
+ plans.set(law, shape);
97
+ }
98
+ if (!shape.supported)
99
+ return undefined;
100
+ const env = { ...p, ...st.scalars }, view = entry.view;
101
+ let visited = 0;
102
+ const go = (left) => {
103
+ if ((visited++ & 255) === 0) {
104
+ checkWall('finite law bindings');
105
+ if (stop())
106
+ return undefined;
107
+ }
108
+ if (visited > 1_000_000)
109
+ return undefined;
110
+ if (!left.length)
111
+ return shape.test(env, view);
112
+ for (const g of shape.guards)
113
+ if (g.vars.every(k => k in env) && !g.test(env, view))
114
+ return true;
115
+ const choices = left.map(c => {
116
+ const bounds = [];
117
+ for (const f of c.upper)
118
+ if (f.vars.every(k => k in env)) {
119
+ const b = f.test(env, view);
120
+ if (Number.isSafeInteger(b))
121
+ bounds.push(b);
122
+ }
123
+ return { c, bounds };
124
+ }).sort((a, b) => Number(b.bounds.length > 0) - Number(a.bounds.length > 0));
125
+ for (const { c, bounds } of choices) {
126
+ let values;
127
+ if (bounds.length) {
128
+ const hi = Math.min(...bounds);
129
+ if (hi > 1_000_000)
130
+ continue;
131
+ values = Array.from({ length: Math.max(0, hi + 1) }, (_, i) => i);
132
+ }
133
+ else if (c.safe) {
134
+ const cells = new Set([0, ...shape.keys.flatMap(k => k in env ? [env[k]] : []), ...shape.cover.flatMap(c => c.maps.flatMap(mp => [...st.maps[mp]?.keys() ?? []]))]);
135
+ const hi = Math.max(...cells);
136
+ for (let i = 1; i <= shape.keys.length; i++)
137
+ cells.add(hi + i);
138
+ values = [...cells];
139
+ }
140
+ else
141
+ continue;
142
+ const next = left.filter(other => other !== c);
143
+ let unknown = false;
144
+ for (const value of values) {
145
+ env[c.key] = value;
146
+ const truth = go(next);
147
+ delete env[c.key];
148
+ if (truth === false)
149
+ return false;
150
+ if (truth === undefined)
151
+ unknown = true;
152
+ }
153
+ return unknown ? undefined : true;
154
+ }
155
+ return undefined;
156
+ };
157
+ let truth;
158
+ try {
159
+ truth = go(shape.cover);
160
+ }
161
+ catch (e) {
162
+ if (e instanceof WallExpired)
163
+ throw e;
164
+ truth = undefined;
165
+ }
166
+ entry.values.set(law, truth);
167
+ return truth;
168
+ };
169
+ }
170
+ export const finiteDump = {};
171
+ export function finiteHoudini(source, m, caller, candidates, samples, options = {}) {
172
+ const start = performance.now(), end = Math.min(wallAt(), searchWall(Math.max(0, options.wallMs ?? 2_000)));
173
+ let survivors = candidates.slice(), timedOut = false;
174
+ try {
175
+ return withWall(end, () => finiteHoudiniWithin(source, m, caller, candidates, samples, { ...options, onDrop: drop => {
176
+ survivors = survivors.filter(law => law !== drop.law);
177
+ options.onDrop?.(drop);
178
+ } }));
179
+ }
180
+ catch (error) {
181
+ if (!(error instanceof WallExpired))
182
+ throw error;
183
+ // An enclosing deadline must still cancel the caller. Only expiration of
184
+ // this local sampling allowance returns the already-certified survivors.
185
+ checkWall('finite sampling completion');
186
+ timedOut = true;
187
+ return survivors;
188
+ }
189
+ finally {
190
+ options.onFinish?.({ timedOut, ms: performance.now() - start, dropped: candidates.length - survivors.length });
191
+ }
192
+ }
193
+ // What a law reads: its scalars and maps, a count map read as the scalars and maps of its body and bound. A law
194
+ // reading nothing a step changed keeps its truth across that step (the pre-state satisfied it), so it is not evaluated
195
+ // on the post-state: the same drops, fewer evaluations.
196
+ function lawReads(m, law) {
197
+ const scalars = new Set(), maps = new Set(), seen = new Set();
198
+ const visit = (t) => walk(t, o => {
199
+ if (o.op === 'var' && o.name in m.state)
200
+ scalars.add(o.name);
201
+ if (o.op === 'get') {
202
+ const map = o.map;
203
+ if (m.counts?.[map]) {
204
+ if (!seen.has(map)) {
205
+ seen.add(map);
206
+ visit([m.counts[map].below, m.counts[map].body]);
207
+ }
208
+ }
209
+ else
210
+ maps.add(map);
211
+ }
212
+ });
213
+ visit(law.holds);
214
+ return { scalars, maps };
215
+ }
216
+ // Experimental tiny-instance proposal backend. Every drop crosses the same
217
+ // independent whole-family/source-interpreter boundary as sampled Houdini.
218
+ // It is not wired into production generation until its bounded pilot passes.
219
+ export function finiteTinyHoudini(source, m, caller, candidates, params, options = {}) {
220
+ const start = performance.now(), end = Math.min(wallAt(), searchWall(Math.max(0, options.wallMs ?? 2_000)));
221
+ let survivors = candidates.slice(), timedOut = false;
222
+ try {
223
+ return withWall(end, () => {
224
+ if (source.history || m.history || Object.keys(source.leasts ?? {}).length || Object.keys(m.leasts ?? {}).length || Object.keys(source.sums ?? {}).length || Object.keys(m.sums ?? {}).length)
225
+ return survivors;
226
+ finiteDump.onStart?.({ machine: m, caller, candidates });
227
+ const evaluate = finiteEvaluator(m), run = interpret(source), protectedLaws = new Set(caller);
228
+ const declarations = [...(m.pre ? [{ name: 'finite parameter precondition', holds: m.pre }] : []), ...m.facts ?? []];
229
+ const rounds = options.rounds === undefined ? Infinity : Math.max(0, Math.floor(options.rounds));
230
+ for (let round = 0; round < rounds; round++) {
231
+ checkWall('tiny Houdini round');
232
+ const active = [...caller, ...survivors], family = [...declarations, ...active], removed = new Set();
233
+ for (const p of params) {
234
+ checkWall('tiny Houdini instance');
235
+ const certify = (pre, request) => {
236
+ checkWall('tiny Houdini certification');
237
+ // The screen's constraints and reported post-laws are not trusted.
238
+ if (!family.every(law => evaluate(law, p, pre) === true))
239
+ return false;
240
+ let post;
241
+ try {
242
+ post = run.step(p, pre, request);
243
+ }
244
+ catch (e) {
245
+ if (e instanceof WallExpired)
246
+ throw e;
247
+ return false;
248
+ }
249
+ let accepted = false;
250
+ for (const law of survivors) {
251
+ if (protectedLaws.has(law) || removed.has(law) || evaluate(law, p, post) !== false)
252
+ continue;
253
+ removed.add(law);
254
+ accepted = true;
255
+ // Preserve a fully certified drop if the rest of the pass expires.
256
+ survivors = survivors.filter(other => other !== law);
257
+ const drop = { round, law, params: p, pre, request, post };
258
+ options.onDrop?.(drop);
259
+ finiteDump.onDrop?.(drop);
260
+ }
261
+ return accepted;
262
+ };
263
+ const early = options.seedBeforeCompile === true && (options.seedTransitions?.length ?? 0) > 0;
264
+ if (early) {
265
+ const sourceEvaluate = finiteEvaluator(source), sourceChecks = [
266
+ ...(source.pre ? [{ name: 'finite source precondition', holds: source.pre }] : []), ...source.facts ?? [],
267
+ ];
268
+ const seedStats = tinySeedCandidates(source, m, p, (pre, request) => sourceChecks.every(law => sourceEvaluate(law, p, pre) === true) && certify(pre, request), options);
269
+ options.onSeed?.(round, seedStats);
270
+ checkWall('tiny early seed completion');
271
+ }
272
+ // Exactly one seed allowance: front-loading replaces, never adds to,
273
+ // the post-compilation neighborhood phase. Keep this round's family.
274
+ const stats = tinyFiniteCandidates(source, m, active, p, certify, early ? { ...options, seedTransitions: undefined } : options);
275
+ // The proposer reports partial statistics when its wall expires. It
276
+ // cannot suppress either this local cap or an earlier enclosing wall.
277
+ checkWall('tiny Houdini completion');
278
+ options.onTiny?.(round, stats);
279
+ }
280
+ if (!removed.size)
281
+ return survivors;
282
+ }
283
+ return survivors;
284
+ });
285
+ }
286
+ catch (e) {
287
+ if (!(e instanceof WallExpired))
288
+ throw e;
289
+ checkWall('tiny Houdini outer completion');
290
+ timedOut = true;
291
+ return survivors;
292
+ }
293
+ finally {
294
+ options.onFinish?.({ timedOut, ms: performance.now() - start, dropped: candidates.length - survivors.length });
295
+ }
296
+ }
297
+ function finiteHoudiniWithin(source, m, caller, candidates, samples, options) {
298
+ finiteDump.onStart?.({ machine: m, caller, candidates });
299
+ // Derived sum-state consistency is not reconstructed by this finite backend.
300
+ if (Object.keys(m.sums ?? {}).length)
301
+ return candidates;
302
+ const declarations = [...(m.pre ? [{ name: 'finite parameter precondition', holds: m.pre }] : []), ...m.facts ?? []];
303
+ const evaluate = finiteEvaluator(m), rng = seeded(options.seed ?? 17), run = interpret(source), step = fastStep(source) ?? run.step;
304
+ const base = samples.flatMap(({ p, sts }) => sts.map(st => ({ p, st })));
305
+ if (!base.length)
306
+ return candidates;
307
+ const scalars = Object.keys(source.state), maps = Object.keys(source.maps ?? {}), requested = options.randomStates ?? 2000;
308
+ const readsOf = new Map();
309
+ const reads = (law) => { let r = readsOf.get(law); if (!r)
310
+ readsOf.set(law, (r = lawReads(m, law))); return r; };
311
+ const cellsDiffer = (mp, a, b) => {
312
+ const av = a.maps[mp], bv = b.maps[mp], ad = a.defaults?.[mp] ?? source.maps[mp], bd = b.defaults?.[mp] ?? source.maps[mp];
313
+ if (ad !== bd)
314
+ return true;
315
+ if (av === bv)
316
+ return false;
317
+ for (const [k, v] of av ?? [])
318
+ if (v !== (bv?.get(k) ?? bd))
319
+ return true;
320
+ for (const [k, v] of bv ?? [])
321
+ if (v !== (av?.get(k) ?? ad))
322
+ return true;
323
+ return false;
324
+ };
325
+ // The law a state failed first, so a later round re-reads only the states a since-dropped law had rejected.
326
+ const failures = new Map();
327
+ const order = (family) => [...family].sort((a, b) => (failures.get(b) ?? 0) - (failures.get(a) ?? 0));
328
+ const values = new Map(maps.map(mp => [mp, [...new Set([source.maps[mp], ...base.flatMap(({ st }) => [...st.maps[mp]?.values() ?? []])])].sort((a, b) => a - b)]));
329
+ const keyPools = new Map(maps.map(mp => [mp, [...new Set(base.flatMap(({ st }) => [...st.maps[mp] ?? []].filter(([, v]) => v !== (st.defaults?.[mp] ?? source.maps[mp])).map(([k]) => k)))]]));
330
+ const scalarValues = new Map(scalars.map(name => [name, [...new Set(base.map(({ st }) => st.scalars[name]))]]));
331
+ const numericInputs = source.inputs.map(name => ({ name, bound: Math.max(3, ...conjuncts(source.assume ?? { op: 'and', xs: [] }).flatMap(c => (c.op === '<' || c.op === '<=') && c.a.op === 'var' && c.a.name === name && c.b.op === 'const' && c.b.value <= 8 ? [c.b.value + Number(c.op === '<=')] : [])) }));
332
+ const sameState = (a, b) => a.history === b.history && a.last === b.last && scalars.every(k => a.scalars[k] === b.scalars[k]) && maps.every(mp => {
333
+ const av = a.maps[mp], bv = b.maps[mp], ad = a.defaults?.[mp] ?? source.maps[mp], bd = b.defaults?.[mp] ?? source.maps[mp];
334
+ return ad === bd && (av === bv || ([...av ?? []].every(([k, v]) => v === (bv?.get(k) ?? bd)) && [...bv ?? []].every(([k, v]) => v === (av?.get(k) ?? ad))));
335
+ });
336
+ const protectedLaws = new Set(caller), dropped = new Set();
337
+ let alive = [...candidates];
338
+ // A state a round rejected, with the law that rejected it: once that law is dropped the state may be lawful.
339
+ let rejected = [];
340
+ for (let round = 0;; round++) {
341
+ const family = order([...declarations, ...caller, ...alive]), removed = new Set();
342
+ let accepted = 0, steps = 0;
343
+ const rejecting = (p, st) => { for (const law of family)
344
+ if (evaluate(law, p, st) !== true) {
345
+ failures.set(law, (failures.get(law) ?? 0) + 1);
346
+ return law;
347
+ } return undefined; };
348
+ const visit = (p, pre) => {
349
+ const by = rejecting(p, pre);
350
+ if (by) {
351
+ rejected.push({ p, st: pre, by });
352
+ return false;
353
+ }
354
+ const bound = Math.max(3, ...Object.values(p));
355
+ for (let trial = 0; trial < (options.requests ?? 25); trial++) {
356
+ checkWall('finite transitions');
357
+ const request = Object.fromEntries(numericInputs.map(({ name, bound: b }) => [name, rng(b)]));
358
+ for (const mp of source.inputMaps ?? [])
359
+ request[mp] = new Map(Array.from({ length: bound }, (_, i) => [i, 1]).filter(() => rng(2)));
360
+ let post;
361
+ try {
362
+ post = step(p, pre, request);
363
+ }
364
+ catch (e) {
365
+ if (e instanceof WallExpired)
366
+ throw e;
367
+ continue;
368
+ }
369
+ steps++;
370
+ // Laws are state-only. An enabled semantic no-op preserves the already
371
+ // checked family, even if the interpreter allocated fresh map objects.
372
+ if (sameState(pre, post))
373
+ continue;
374
+ const changedScalars = scalars.filter(k => pre.scalars[k] !== post.scalars[k]), changedMaps = maps.filter(mp => cellsDiffer(mp, pre, post));
375
+ for (const law of alive) {
376
+ if (protectedLaws.has(law) || removed.has(law))
377
+ continue;
378
+ const r = reads(law);
379
+ if (!changedScalars.some(k => r.scalars.has(k)) && !changedMaps.some(mp => r.maps.has(mp)))
380
+ continue;
381
+ if (evaluate(law, p, post) === false) {
382
+ removed.add(law);
383
+ const drop = { round, law, params: p, pre, request, post };
384
+ options.onDrop?.(drop);
385
+ finiteDump.onDrop?.(drop);
386
+ }
387
+ }
388
+ }
389
+ return true;
390
+ };
391
+ // A later round re-reads only the states a since-dropped law had rejected: every other rejected state still fails
392
+ // a law that is still in the family, and every visited state was read against every law then alive.
393
+ if (round > 0) {
394
+ const revived = rejected.filter(r => dropped.has(r.by));
395
+ rejected = rejected.filter(r => !dropped.has(r.by));
396
+ for (const { p, st } of revived)
397
+ if (visit(p, st))
398
+ accepted++;
399
+ options.onRound?.({ round, alive: alive.length, dropped: removed.size, randomStates: accepted, steps });
400
+ if (!removed.size)
401
+ return alive;
402
+ for (const law of removed)
403
+ dropped.add(law);
404
+ alive = alive.filter(law => !removed.has(law));
405
+ continue;
406
+ }
407
+ // Use each law's own atoms before spending the random budget: a cube's
408
+ // one-sided boundary, a guard enabled, or a bounded field at its limit.
409
+ const frontiers = options.targeted === false ? [] : alive.flatMap(law => lawFrontiers(law).map(conditions => ({ law, conditions })));
410
+ for (let i = 0; frontiers.length && i < Math.min(requested, frontiers.length * 8); i++) {
411
+ checkWall('finite frontiers');
412
+ const { p, st: old } = base[rng(base.length)], { law, conditions } = frontiers[i % frontiers.length];
413
+ const bound = Math.max(1, ...Object.values(p)), keys = Object.fromEntries([law.forall, ...law.keys ?? []].filter((k) => !!k).map(k => [k, rng(bound)]));
414
+ const st = boundaryState(source, m, conditions, p, old, keys);
415
+ if (st)
416
+ visit(p, st);
417
+ }
418
+ for (const { p, st } of base)
419
+ visit(p, st);
420
+ for (let tries = 0; accepted < requested && tries < Math.max(requested * 8, requested); tries++) {
421
+ checkWall('finite neighbors');
422
+ const { p, st: old } = base[rng(base.length)], st = { ...old, scalars: { ...old.scalars }, maps: { ...old.maps } };
423
+ const bound = Math.max(3, ...Object.values(p));
424
+ if (rng(2)) {
425
+ // Independent finite configurations, not only near-reachable states:
426
+ // relative CTIs often require several fields/rows to differ together.
427
+ for (const name of scalars) {
428
+ const vs = scalarValues.get(name);
429
+ st.scalars[name] = vs[rng(vs.length)];
430
+ }
431
+ for (const mp of maps) {
432
+ const vs = values.get(mp).slice(0, bound), cells = new Map(old.maps[mp]);
433
+ for (const key of keyPools.get(mp))
434
+ cells.set(key, vs[rng(vs.length)]);
435
+ st.maps[mp] = cells;
436
+ }
437
+ }
438
+ else
439
+ for (let i = 0, n = 1 + rng(2); i < n; i++) {
440
+ if (maps.length && (!scalars.length || rng(2) === 0)) {
441
+ const mp = maps[rng(maps.length)], keys = [...old.maps[mp]?.keys() ?? []], key = keys.length ? keys[rng(keys.length)] : 0, vs = values.get(mp), value = vs.length ? vs[rng(vs.length)] : 0;
442
+ st.maps[mp] = new Map(st.maps[mp]);
443
+ st.maps[mp].set(key, value);
444
+ }
445
+ else if (scalars.length) {
446
+ const name = scalars[rng(scalars.length)];
447
+ st.scalars[name] = Math.max(0, st.scalars[name] + rng(3) - 1);
448
+ }
449
+ }
450
+ if (visit(p, st))
451
+ accepted++;
452
+ }
453
+ options.onRound?.({ round, alive: alive.length, dropped: removed.size, randomStates: accepted, steps });
454
+ if (!removed.size)
455
+ return alive;
456
+ for (const law of removed)
457
+ dropped.add(law);
458
+ alive = alive.filter(law => !removed.has(law));
459
+ }
460
+ }
@@ -0,0 +1,13 @@
1
+ import { type Law, type Machine, type Request, type State } from './machine.js';
2
+ export type FiniteModel = {
3
+ genuine: true;
4
+ params: Record<string, number>;
5
+ pre: State;
6
+ request: Request;
7
+ post: State;
8
+ } | {
9
+ genuine: false;
10
+ reason: string;
11
+ failedLaw?: string;
12
+ };
13
+ export declare function finiteModelChecker(m: Machine): (family: Law[], law: Law, model: Record<string, number>, stop?: () => boolean) => FiniteModel;
@@ -0,0 +1,68 @@
1
+ // A model is not a counterexample until its completed finite machine state
2
+ // satisfies the entire current family and an enabled real step breaks the law.
3
+ // This is a falsifier only: an unsupported or failed completion proves nothing.
4
+ import { interpret } from "./machine.js";
5
+ import { finiteEvaluator } from "./finite-houdini.js";
6
+ import { keyValue } from "../kernel/prove.js";
7
+ import { checkWall, WallExpired } from "./wall.js";
8
+ export function finiteModelChecker(m) {
9
+ return (family, law, model, stop = () => false) => {
10
+ checkWall('finite model completion');
11
+ const unknown = (reason, failedLaw) => ({ genuine: false, reason, ...(failedLaw ? { failedLaw } : {}) });
12
+ if (stop())
13
+ return unknown('attempt exhausted');
14
+ if (m.history || m.leasts || Object.keys(m.sums ?? {}).length)
15
+ return unknown('unsupported state environment');
16
+ const params = Object.fromEntries(m.params.map(k => [k, model[k] ?? 0]));
17
+ const pre = { scalars: Object.fromEntries(Object.keys(m.state).map(k => [k, model[k] ?? 0])), maps: Object.fromEntries(Object.keys(m.maps ?? {}).map(k => [k, new Map()])), defaults: Object.fromEntries(Object.keys(m.maps ?? {}).map(k => [k, 0])) };
18
+ const request = Object.fromEntries(m.inputs.map(k => [k, model[k] ?? 0]));
19
+ for (const key of m.inputMaps ?? [])
20
+ request[key] = new Map();
21
+ const natural = (x) => Number.isSafeInteger(x) && x >= 0;
22
+ if (![...Object.values(params), ...Object.values(pre.scalars), ...Object.values(request).filter((v) => typeof v === 'number')].every(natural))
23
+ return unknown('non-natural assignment');
24
+ for (const [name, value] of Object.entries(model)) {
25
+ const bracket = name.indexOf('['), map = name.slice(0, bracket);
26
+ if (bracket < 0 || !name.endsWith(']'))
27
+ continue;
28
+ const cells = pre.maps[map] ?? (request[map] instanceof Map ? request[map] : undefined);
29
+ if (!cells)
30
+ continue; // Derived counts and post-state cells are recomputed, never trusted.
31
+ const key = keyValue(name, model);
32
+ if (key === undefined || !natural(key) || !natural(value))
33
+ return unknown('unreadable finite cell');
34
+ if (cells.has(key) && cells.get(key) !== value)
35
+ return unknown('inconsistent finite aliases');
36
+ cells.set(key, value);
37
+ }
38
+ const checkpoint = () => { checkWall('finite transition'); if (stop())
39
+ throw new Error('finite transition stopped'); };
40
+ const evaluate = finiteEvaluator(m, stop);
41
+ try {
42
+ const run = interpret(m, checkpoint);
43
+ if (m.pre && evaluate({ name: 'finite parameter precondition', holds: m.pre }, params, pre) !== true)
44
+ return unknown('parameter precondition');
45
+ for (const fact of m.facts ?? []) {
46
+ const truth = evaluate(fact, params, pre);
47
+ if (truth !== true)
48
+ return unknown(stop() ? 'attempt exhausted' : truth === false ? 'declared fact is false' : 'unsupported declared fact', fact.name);
49
+ }
50
+ for (const member of new Set([...family, law])) {
51
+ const truth = evaluate(member, params, pre);
52
+ if (truth !== true)
53
+ return unknown(stop() ? 'attempt exhausted' : truth === false ? 'predecessor violates the family' : 'unsupported predecessor evaluation', member.name);
54
+ }
55
+ if (stop())
56
+ return unknown('attempt exhausted');
57
+ const post = run.step(params, pre, request);
58
+ if (evaluate(law, params, post) !== false)
59
+ return unknown('no established post-state violation');
60
+ return { genuine: true, params, pre, request, post };
61
+ }
62
+ catch (error) {
63
+ if (error instanceof WallExpired)
64
+ throw error;
65
+ return unknown(stop() ? 'attempt exhausted' : 'unsupported evaluation or refused request');
66
+ }
67
+ };
68
+ }
@@ -0,0 +1,72 @@
1
+ import { type Law, type Machine, type Request, type State } from './machine.js';
2
+ type Env = Record<string, number>;
3
+ export type TinyFiniteSeed = {
4
+ params: Env;
5
+ pre: State;
6
+ request: Request;
7
+ };
8
+ export type TinyFiniteOptions = {
9
+ valueDomain?: readonly number[];
10
+ postTargetPruning?: boolean;
11
+ postTargetIntervals?: boolean;
12
+ seedTransitions?: readonly TinyFiniteSeed[];
13
+ seedUniformMaps?: boolean;
14
+ seedBeforeCompile?: boolean;
15
+ };
16
+ export type TinyFiniteStatistics = {
17
+ scope: {
18
+ params: Env;
19
+ scalarValues: number[];
20
+ cellValues: number[];
21
+ cells: Record<string, number[]>;
22
+ inputValues: Record<string, number[]>;
23
+ inputCells: Record<string, number[]>;
24
+ binderValues: number[];
25
+ postTargetPruning: boolean;
26
+ postTargetIntervals: boolean;
27
+ seedNeighborhood: boolean;
28
+ seedUniformMaps: boolean;
29
+ };
30
+ completed: boolean;
31
+ exhausted: boolean;
32
+ timedOut: boolean;
33
+ unsupported: string[];
34
+ nodes: number;
35
+ states: number;
36
+ steps: number;
37
+ scenarios: number;
38
+ candidates: number;
39
+ postStatePrunes: number;
40
+ postRequestPrunes: number;
41
+ postIntervalFallbacks: number;
42
+ seedModels: number;
43
+ seedCandidates: number;
44
+ seedCoupledModels: number;
45
+ seedCoupledCandidates: number;
46
+ ms: number;
47
+ };
48
+ export type TinySeedStatistics = {
49
+ phase: 'seed-only';
50
+ scope: TinyFiniteStatistics['scope'];
51
+ completed: boolean;
52
+ timedOut: boolean;
53
+ unsupported: string[];
54
+ models: number;
55
+ accepted: number;
56
+ coupledModels: number;
57
+ coupledAccepted: number;
58
+ ms: number;
59
+ };
60
+ export declare function tinySeedCandidates(source: Machine, m: Machine, params: Env, onCandidate: (pre: State, request: Request) => boolean, options?: TinyFiniteOptions): TinySeedStatistics;
61
+ /** A deliberately small heuristic scope: binary source scalars/cells by default,
62
+ * count-bound-sized rows and Boolean carried sets. Unsupported syntax is
63
+ * unknown. completed means this recorded finite SCREEN traversal finished;
64
+ * exhausted additionally means it emitted no proposals. Neither establishes
65
+ * validity, reachability, or a complete universal cover.
66
+ * Callback false rejects a proposal and resumes that search; void/true stops
67
+ * that target at its first proposal. Neither outcome authorizes a drop.
68
+ * WallExpired is caught to return partial statistics; an expired parent wall
69
+ * remains expired, and consumers must immediately check their own checkWall.
70
+ */
71
+ export declare function tinyFiniteCandidates(source: Machine, m: Machine, family: Law[], params: Env, onCandidate: (pre: State, request: Request, violated: Law[]) => boolean | void, options?: TinyFiniteOptions): TinyFiniteStatistics;
72
+ export {};