gdp-wired 0.46.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 (182) hide show
  1. package/README.md +18 -5
  2. package/dist/core/carry.d.ts +15 -0
  3. package/dist/core/carry.js +651 -0
  4. package/dist/core/cli.d.ts +4 -1
  5. package/dist/core/cli.js +31 -11
  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-schema.d.ts +90 -0
  99. package/dist/core/effect-schema.js +500 -0
  100. package/dist/core/effect.d.ts +3 -7
  101. package/dist/core/effect.js +10 -65
  102. package/dist/core/exists.d.ts +1 -1
  103. package/dist/core/exists.js +80 -15
  104. package/dist/core/extract-check.d.ts +7 -1
  105. package/dist/core/extract-check.js +161 -19
  106. package/dist/core/extract-go-check.js +24 -4
  107. package/dist/core/extract-go.d.ts +7 -0
  108. package/dist/core/extract-go.js +29 -2
  109. package/dist/core/extract-read.d.ts +31 -9
  110. package/dist/core/extract-read.js +36 -11
  111. package/dist/core/extract-rs.js +58 -14
  112. package/dist/core/extract-shapes.d.ts +1 -0
  113. package/dist/core/extract-shapes.js +190 -27
  114. package/dist/core/extract-standalone.d.ts +3 -0
  115. package/dist/core/extract-standalone.js +265 -0
  116. package/dist/core/extract.d.ts +1 -0
  117. package/dist/core/extract.js +25 -5
  118. package/dist/core/field-laws.d.ts +2 -0
  119. package/dist/core/field-laws.js +100 -0
  120. package/dist/core/finite-frontiers.d.ts +5 -0
  121. package/dist/core/finite-frontiers.js +116 -0
  122. package/dist/core/finite-houdini.d.ts +52 -0
  123. package/dist/core/finite-houdini.js +460 -0
  124. package/dist/core/finite-model.d.ts +13 -0
  125. package/dist/core/finite-model.js +68 -0
  126. package/dist/core/finite-tiny.d.ts +72 -0
  127. package/dist/core/finite-tiny.js +1052 -0
  128. package/dist/core/infer.d.ts +1 -1
  129. package/dist/core/infer.js +32 -9
  130. package/dist/core/laws.d.ts +2 -1
  131. package/dist/core/laws.js +76 -19
  132. package/dist/core/lemma-cuts.d.ts +38 -0
  133. package/dist/core/lemma-cuts.js +365 -0
  134. package/dist/core/machine.d.ts +39 -2
  135. package/dist/core/machine.js +240 -35
  136. package/dist/core/mutate.d.ts +55 -0
  137. package/dist/core/mutate.js +210 -0
  138. package/dist/core/native-domain.d.ts +6 -0
  139. package/dist/core/native-domain.js +114 -0
  140. package/dist/core/native-law.d.ts +3 -0
  141. package/dist/core/native-law.js +174 -0
  142. package/dist/core/quorum-laws.d.ts +5 -0
  143. package/dist/core/quorum-laws.js +239 -0
  144. package/dist/core/relational.js +10 -2
  145. package/dist/core/relevance.d.ts +4 -0
  146. package/dist/core/relevance.js +79 -0
  147. package/dist/core/rs/Cargo.toml +1 -1
  148. package/dist/core/rs/src/main.rs +458 -9
  149. package/dist/core/runtime-wall.d.ts +3 -0
  150. package/dist/core/runtime-wall.js +4 -0
  151. package/dist/core/sample-step.d.ts +16 -0
  152. package/dist/core/sample-step.js +28 -0
  153. package/dist/core/source-check.d.ts +44 -0
  154. package/dist/core/source-check.js +126 -0
  155. package/dist/core/source-diagnostic.d.ts +1 -0
  156. package/dist/core/source-diagnostic.js +34 -0
  157. package/dist/core/support-budget.d.ts +2 -0
  158. package/dist/core/support-budget.js +6 -0
  159. package/dist/core/system.js +2 -0
  160. package/dist/core/wall.d.ts +6 -0
  161. package/dist/core/wall.js +23 -0
  162. package/dist/core/watch.js +4 -0
  163. package/dist/kernel/cdcl.d.ts +4 -0
  164. package/dist/kernel/cdcl.js +20 -5
  165. package/dist/kernel/kernel.d.ts +10 -0
  166. package/dist/kernel/kernel.js +56 -3
  167. package/dist/kernel/model-sequence.d.ts +2 -2
  168. package/dist/kernel/model-sequence.js +4 -3
  169. package/dist/kernel/model-values.d.ts +2 -0
  170. package/dist/kernel/model-values.js +60 -0
  171. package/dist/kernel/prove.d.ts +10 -0
  172. package/dist/kernel/prove.js +56 -8
  173. package/dist/kernel/prover-rows.d.ts +29 -0
  174. package/dist/kernel/prover-rows.js +114 -0
  175. package/dist/lean-kernel/emit.d.ts +39 -2
  176. package/dist/lean-kernel/emit.js +136 -24
  177. package/dist/lean-kernel/lean-terms.d.ts +1 -0
  178. package/dist/lean-kernel/lean-terms.js +13 -5
  179. package/dist/lean-kernel/library.js +4 -0
  180. package/dist/lean-kernel/qalpha.d.ts +7 -0
  181. package/dist/lean-kernel/qalpha.js +40 -0
  182. package/package.json +5 -1
@@ -0,0 +1,28 @@
1
+ // Hot random walks reuse the existing persistent compiled step. No request,
2
+ // random draw, sample order or work counter is skipped. Cold/unsupported machines
3
+ // keep the interpreter. A refused request returns undefined; other errors retain
4
+ // the interpreter's exception behavior (the sampler ends that trial).
5
+ import { carriedView, compileC, fastStep, interpret, numbersOf } from "./machine.js";
6
+ import { allowed } from "./watch.js";
7
+ export function sampleStep(m, run = interpret(m)) {
8
+ let calls = 0, step = run.step;
9
+ let accepts = (params, st, input) => allowed(m, run, params, st, input);
10
+ return (params, st, input) => {
11
+ if (++calls === 1000) {
12
+ const fast = fastStep(m);
13
+ if (fast) {
14
+ step = fast;
15
+ const flags = Object.entries(m.step.flags ?? {}).map(([name, c]) => [name, compileC(c, m)]);
16
+ const assume = m.assume && compileC(m.assume, m);
17
+ accepts = !assume ? () => true : (params, st, input) => {
18
+ const env = { ...params, ...numbersOf(input), ...run.queries(params, st, input) };
19
+ const view = carriedView(m, st, input, undefined, params);
20
+ for (const [name, f] of flags)
21
+ env[`?${name}`] = f(env, view) ? 1 : 0;
22
+ return assume(env, view);
23
+ };
24
+ }
25
+ }
26
+ return accepts(params, st, input) ? step(params, st, input) : undefined;
27
+ };
28
+ }
@@ -0,0 +1,44 @@
1
+ export type Translation = 'exhaustive' | 'sampled' | 'unchecked' | 'error';
2
+ export type NativeObservation = {
3
+ where: string;
4
+ method?: string;
5
+ before: unknown;
6
+ after: unknown;
7
+ params: Record<string, unknown>;
8
+ inputs: Record<string, unknown>;
9
+ bindings: Record<string, unknown>;
10
+ args: unknown[];
11
+ result: unknown;
12
+ failed: boolean;
13
+ legacyResult?: boolean;
14
+ };
15
+ export type NativeJournal = {
16
+ enabled: boolean;
17
+ complete: boolean;
18
+ scope: 'exhaustive' | 'sampled';
19
+ reason?: string;
20
+ observations: NativeObservation[];
21
+ };
22
+ export type TranslationFields = {
23
+ translation?: Translation;
24
+ translationChecks?: number;
25
+ translationWitness?: NativeObservation;
26
+ kernelProven?: boolean;
27
+ };
28
+ export declare function inheritSource(from: object, to: object, transparent?: boolean): void;
29
+ export declare function rememberNative(e: object, journal: NativeJournal): void;
30
+ export declare function attachSource(rule: object, e: object, generated: object[]): void;
31
+ export declare function attachNativeLaw(rule: object, law: object, name: string, method: string | undefined, evaluate: (observation: NativeObservation) => boolean): void;
32
+ type TranslatedVerdict<V> = Omit<V, 'proven' | 'checked'> & {
33
+ proven: boolean;
34
+ checked: boolean;
35
+ } & TranslationFields;
36
+ export declare function translationVerdict<V extends {
37
+ proven: boolean;
38
+ checked: boolean;
39
+ why?: string;
40
+ stuck?: string;
41
+ }>(rule: object, laws: object[], verdict: V): TranslatedVerdict<V>;
42
+ export declare const nativeSame: (a: unknown, b: unknown) => boolean;
43
+ export declare function nativeSnapshot(value: unknown, seen?: Map<object, unknown>): unknown;
44
+ export {};
@@ -0,0 +1,126 @@
1
+ // A non-enumerable, versioned marker survives independent module copies. Losing
2
+ // the private observations must downgrade a source proof, not turn it into a DSL proof.
3
+ const sourceMarker = Symbol.for('gdp-wired.source-proof.v1');
4
+ const marked = (value) => Object.prototype.hasOwnProperty.call(value, sourceMarker);
5
+ const mark = (value, enumerable = false) => { if (!marked(value))
6
+ Object.defineProperty(value, sourceMarker, { value: true, enumerable }); };
7
+ const markRule = (value) => {
8
+ mark(value);
9
+ // A Rule's immutable specification is spread by constructor-based transforms.
10
+ // Carry only the fail-closed marker, never a native journal, across such copies.
11
+ const spec = Object.getOwnPropertyDescriptor(value, 'spec')?.value;
12
+ if (spec && typeof spec === 'object')
13
+ mark(spec, true);
14
+ };
15
+ export function inheritSource(from, to, transparent = false) {
16
+ if (marked(from))
17
+ markRule(to);
18
+ const source = sources.get(from);
19
+ if (transparent && source)
20
+ sources.set(to, source);
21
+ }
22
+ const evidence = new WeakMap();
23
+ const sources = new WeakMap();
24
+ const nativeLaws = new WeakMap();
25
+ export function rememberNative(e, journal) { evidence.set(e, journal); }
26
+ export function attachSource(rule, e, generated) {
27
+ markRule(rule);
28
+ sources.set(rule, { root: rule, journal: evidence.get(e), generated: new Set(generated) });
29
+ }
30
+ export function attachNativeLaw(rule, law, name, method, evaluate) {
31
+ mark(law);
32
+ nativeLaws.set(law, { rule: sources.get(rule)?.root ?? rule, name, method, evaluate });
33
+ }
34
+ export function translationVerdict(rule, laws, verdict) {
35
+ const source = sources.get(rule), bound = laws.map(l => nativeLaws.get(l)).filter(x => x !== undefined);
36
+ if (!source && !bound.length && !marked(rule) && !laws.some(marked))
37
+ return verdict;
38
+ const journal = source?.journal;
39
+ const unchecked = (why) => ({ ...verdict, proven: false, checked: false, kernelProven: verdict.proven && verdict.checked, translation: 'unchecked', why: `source translation unchecked: ${why}` });
40
+ if (!journal?.enabled || !journal.complete)
41
+ return unchecked(journal?.reason ?? 'native source replay is unavailable or disabled');
42
+ if (bound.some(b => b.rule !== source?.root))
43
+ return unchecked('the source law belongs to a different rule');
44
+ if (laws.some(l => !nativeLaws.has(l) && !source.generated.has(l)))
45
+ return unchecked('a source proof contains a law with no native interpretation');
46
+ if (!verdict.proven || !verdict.checked)
47
+ return { ...verdict, translation: journal.scope };
48
+ let checks = 0;
49
+ for (const law of bound) {
50
+ let observed = 0;
51
+ for (const observation of journal.observations) {
52
+ if (law.method && observation.method !== law.method)
53
+ continue;
54
+ observed++;
55
+ checks++;
56
+ let holds;
57
+ try {
58
+ holds = law.evaluate(observation);
59
+ }
60
+ catch (e) {
61
+ return unchecked(`native interpretation of ${law.name}: ${e instanceof Error ? e.message : String(e)}`);
62
+ }
63
+ if (!holds)
64
+ return { ...verdict, proven: false, checked: false, kernelProven: true, translation: 'error', translationChecks: checks,
65
+ translationWitness: observation, stuck: 'translation-error', why: `translation error: ${law.name} is false in the native code (${observation.where})` };
66
+ }
67
+ if (!observed)
68
+ return unchecked(`no native observation of ${law.method ?? law.name}`);
69
+ }
70
+ return { ...verdict, translation: journal.scope, translationChecks: checks };
71
+ }
72
+ const sourceIdentity = new WeakMap(), cloneIdentity = new WeakMap();
73
+ let nextIdentity = 0;
74
+ const identify = (original, clone) => {
75
+ let id = sourceIdentity.get(original);
76
+ if (id === undefined) {
77
+ id = ++nextIdentity;
78
+ sourceIdentity.set(original, id);
79
+ }
80
+ cloneIdentity.set(clone, id);
81
+ };
82
+ export const nativeSame = (a, b) => a === b || (a !== null && b !== null && typeof a === 'object' && typeof b === 'object' && cloneIdentity.has(a) && cloneIdentity.get(a) === cloneIdentity.get(b));
83
+ // Snapshot real JS values, preserving undefined, NaN, keys, aliasing and class prototypes.
84
+ // Functions are not invoked; laws cannot introduce arbitrary calls. An unsupported snapshot
85
+ // must make source proof finalization unchecked, never silently lose an observation.
86
+ export function nativeSnapshot(value, seen = new Map()) {
87
+ if (value === null || typeof value !== 'object')
88
+ return value;
89
+ if (seen.has(value))
90
+ return seen.get(value);
91
+ if (seen.size >= 10000)
92
+ throw new Error('native state exceeds the snapshot bound');
93
+ const tag = Object.prototype.toString.call(value);
94
+ if (tag === '[object Date]') {
95
+ const out = new Date(Number(value));
96
+ identify(value, out);
97
+ return out;
98
+ }
99
+ if (tag === '[object Map]') {
100
+ const out = new Map();
101
+ seen.set(value, out);
102
+ identify(value, out);
103
+ for (const [k, v] of value.entries())
104
+ out.set(nativeSnapshot(k, seen), nativeSnapshot(v, seen));
105
+ return out;
106
+ }
107
+ if (tag === '[object Set]') {
108
+ const out = new Set();
109
+ seen.set(value, out);
110
+ identify(value, out);
111
+ for (const v of value.values())
112
+ out.add(nativeSnapshot(v, seen));
113
+ return out;
114
+ }
115
+ const out = (Array.isArray(value) ? [] : Object.create(Object.getPrototypeOf(value)));
116
+ seen.set(value, out);
117
+ identify(value, out);
118
+ for (const key of Reflect.ownKeys(value)) {
119
+ const d = Object.getOwnPropertyDescriptor(value, key);
120
+ if ('value' in d)
121
+ Object.defineProperty(out, key, { ...d, value: nativeSnapshot(d.value, seen) });
122
+ else
123
+ Object.defineProperty(out, key, d);
124
+ }
125
+ return out;
126
+ }
@@ -0,0 +1 @@
1
+ export declare function sourceDiagnostic(value: unknown, active?: Set<object>, depth?: number): unknown;
@@ -0,0 +1,34 @@
1
+ // JSON-safe native witnesses. Keep absence and non-finite numbers explicit; never
2
+ // invoke a getter while printing an error. This is diagnostic data, not a replay format.
3
+ export function sourceDiagnostic(value, active = new Set(), depth = 0) {
4
+ if (value === undefined)
5
+ return { $undefined: true };
6
+ if (typeof value === 'number' && !Number.isFinite(value))
7
+ return { $number: String(value) };
8
+ if (typeof value === 'bigint')
9
+ return { $bigint: String(value) };
10
+ if (typeof value === 'function' || typeof value === 'symbol')
11
+ return { $unsupported: typeof value };
12
+ if (value === null || typeof value !== 'object')
13
+ return value;
14
+ if (active.has(value))
15
+ return { $circular: true };
16
+ if (depth >= 32)
17
+ return { $truncated: true };
18
+ active.add(value);
19
+ const visit = (v) => sourceDiagnostic(v, active, depth + 1);
20
+ try {
21
+ if (value instanceof Date)
22
+ return { $date: Number.isNaN(Number(value)) ? 'Invalid Date' : value.toISOString() };
23
+ if (value instanceof Map)
24
+ return { $map: [...value].map(([k, v]) => [visit(k), visit(v)]) };
25
+ if (value instanceof Set)
26
+ return { $set: [...value].map(visit) };
27
+ if (Array.isArray(value))
28
+ return value.map(visit);
29
+ return Object.fromEntries(Object.entries(Object.getOwnPropertyDescriptors(value)).map(([k, d]) => [k, 'value' in d ? visit(d.value) : { $accessor: true }]));
30
+ }
31
+ finally {
32
+ active.delete(value);
33
+ }
34
+ }
@@ -0,0 +1,2 @@
1
+ export declare const attemptShare: (remaining: number, pending: ReadonlySet<string>) => number;
2
+ export declare function supportBudget(remaining: number, share: number, priority: boolean, structural?: boolean): number;
@@ -0,0 +1,6 @@
1
+ // Shared untrusted allowance rule; existing law-level behavior is unchanged.
2
+ // Pending excludes already-tried, kept and carried laws of this round.
3
+ export const attemptShare = (remaining, pending) => Math.max(0, remaining) / Math.max(1, pending.size);
4
+ export function supportBudget(remaining, share, priority, structural = false) {
5
+ return Math.max(0, Math.min(remaining, structural ? 5_000 : priority ? Math.max(share, remaining / 3) : share));
6
+ }
@@ -21,6 +21,7 @@ import { substC, substE } from "../kernel/kernel.js";
21
21
  import { Cond, Term, nat, oneOf, rule } from "./dsl.js";
22
22
  import { interpret } from "./machine.js";
23
23
  import { allowed, watch } from "./watch.js";
24
+ import { inheritSource } from "./source-check.js";
24
25
  const models = new WeakMap();
25
26
  const modelled = (m, ...ms) => { models.set(m, [...(models.get(m) ?? []), ...ms]); return m; };
26
27
  // m made from `from`: the models it assumes, and the scalars it keeps shared (`sharedOf`), carried over.
@@ -544,6 +545,7 @@ export function inEnv(r, env, o = {}) {
544
545
  parts[`expiry${stores.length > 1 ? i : ''}`] = e;
545
546
  });
546
547
  const sys = system(`${machineOf(r).name} (${envText(env) || 'atomic'})`, parts, { act });
548
+ inheritSource(r, sys);
547
549
  const ms = [...modelsOf(sys), ...(env.retries ? [RETRIES] : [])];
548
550
  models.set(sys, ms);
549
551
  const locals = Object.keys(m.state).filter(s => own.includes(s)), on = same(x(act), n(0));
@@ -0,0 +1,6 @@
1
+ export declare const searchWall: (ms: number) => number;
2
+ export declare class WallExpired extends Error {
3
+ readonly phase: string;
4
+ constructor(phase: string);
5
+ }
6
+ export declare function checkWall(phase: string): void;
@@ -0,0 +1,23 @@
1
+ // Cooperative cancellation of untrusted search only. Never debits counted work,
2
+ // changes a proof rule, or turns an interrupted filter into a successful one.
3
+ import { pastWall } from "../kernel/prove.js";
4
+ import { runtimeWall } from "./runtime-wall.js";
5
+ // Leave bounded completion headroom for an in-flight synchronous operation,
6
+ // result checking and output. This shortens only wall time, never counted fuel.
7
+ // The same rule applies to every protocol and budget.
8
+ export const searchWall = (ms) => performance.now() + ms - Math.min(1000, Math.max(0, ms) / 20);
9
+ export class WallExpired extends Error {
10
+ phase;
11
+ constructor(phase) {
12
+ super(`time (${phase})`);
13
+ this.phase = phase;
14
+ this.name = 'WallExpired';
15
+ }
16
+ }
17
+ export function checkWall(phase) {
18
+ if (pastWall())
19
+ throw new WallExpired(phase);
20
+ }
21
+ // The interpreter must not import the proof engine to check its active wall:
22
+ // that would initialize cyclic proof constants before the machine constructors.
23
+ runtimeWall.check = checkWall;
@@ -9,6 +9,7 @@
9
9
  // request as input@j, and the state and maps after the last step (primed names).
10
10
  import { carriedView, evalC, evalE, numbersOf, walk } from "./machine.js";
11
11
  import { someHolds } from "./exists.js";
12
+ import { checkWall } from "./wall.js";
12
13
  export const isStepLaw = (w) => 'then' in w;
13
14
  // A request's environment: the params, its inputs and queries, and the step's flags decided (as ?name).
14
15
  export function requestEnv(m, run, params, st, input) {
@@ -129,7 +130,10 @@ export function watch(m, run, w, params, bound) {
129
130
  mapRead.add(x); });
130
131
  const turn = names.some(x => !mapRead.has(x)) ? turns(isStepLaw(w) ? w.then : w.holds, names) : undefined;
131
132
  const atKeys = (keys, env, f, st, mm) => {
133
+ let visited = 0;
132
134
  const go = (i) => {
135
+ if ((visited++ & 255) === 0)
136
+ checkWall('preflight law bindings');
133
137
  if (i === names.length) {
134
138
  watchWork.n++;
135
139
  return f(env);
@@ -24,6 +24,10 @@ export declare const cdclStats: {
24
24
  proven: number;
25
25
  conflicts: number;
26
26
  decisions: number;
27
+ setupMs: number;
28
+ propagationMs: number;
29
+ firstDecisionMs: number;
30
+ firstDecisions: number;
27
31
  solveMs: number;
28
32
  rowsMs: number;
29
33
  coreMs: number;
@@ -55,7 +55,7 @@ const keyOf = (lin) => {
55
55
  const pointLeaf = env.GDP_CDCL_POINT !== '0';
56
56
  const lpFill = Number(env.GDP_CDCL_FILL ?? 8), lpGrow = Number(env.GDP_CDCL_GROW ?? 4), lpBase = Number(env.GDP_CDCL_BASE ?? 500), lpGreedy = Number(env.GDP_CDCL_GREEDY ?? 200), useLp = env.GDP_CDCL_LP !== '0', verify = env.GDP_CDCL_VERIFY === '1';
57
57
  // Counters research/step reads (times only while `on`).
58
- export const cdclStats = { on: false, runs: 0, proven: 0, conflicts: 0, decisions: 0, solveMs: 0, rowsMs: 0, coreMs: 0, unfoldMs: 0, leaves: 0, resolved: 0, coreSize: 0, pathSize: 0, lpMisses: 0, resolved2: 0, unfoldWhy: '', orderMs: 0, boundMs: 0, openMisses: 0, lpMs: 0, lpUnknown: 0, fmCalls: 0, pivots: 0, lpRebuilds: 0, lpRows: 0, lpNnz: 0, lpVars: 0, lpLoad: 0, nodes: 0, boundRounds: 0, fmLeafMs: 0, fmOpenMs: 0, fastMs: 0, missMs: 0 };
58
+ export const cdclStats = { on: false, runs: 0, proven: 0, conflicts: 0, decisions: 0, setupMs: 0, propagationMs: 0, firstDecisionMs: 0, firstDecisions: 0, solveMs: 0, rowsMs: 0, coreMs: 0, unfoldMs: 0, leaves: 0, resolved: 0, coreSize: 0, pathSize: 0, lpMisses: 0, resolved2: 0, unfoldWhy: '', orderMs: 0, boundMs: 0, openMisses: 0, lpMs: 0, lpUnknown: 0, fmCalls: 0, pivots: 0, lpRebuilds: 0, lpRows: 0, lpNnz: 0, lpVars: 0, lpLoad: 0, nodes: 0, boundRounds: 0, fmLeafMs: 0, fmOpenMs: 0, fastMs: 0, missMs: 0 };
59
59
  // `opts.model`: only whether the goal has a model is wanted (core/bmc.ts): a refutation isn't unfolded into a tree, its
60
60
  // outcome `unknown` with `why` REFUTED; each decision's phase is the simplex's point's (phaseAtPoint; in the tree search too
61
61
  // where prove.ts's `atPoint` is on); past `opts.wall` (wall time) the search stops as past its budget.
@@ -93,7 +93,16 @@ export function cdclSession(goal, root, opts = {}) {
93
93
  // brings it down to its own; each assumption's index by name)
94
94
  // (and on each assumption's variable, `aq`, its index this run: the undo's lookup by variable, not by name)
95
95
  let aq = 0, aqOf = new Map(), aqVars = [];
96
- const st = cdclStats, timing = st.on;
96
+ const st = cdclStats, timing = st.on, setupStarted = timing ? performance.now() : 0;
97
+ let runStarted = 0, sawDecision = false;
98
+ const noteDecision = () => {
99
+ st.decisions++;
100
+ if (timing && !sawDecision) {
101
+ sawDecision = true;
102
+ st.firstDecisions++;
103
+ st.firstDecisionMs += performance.now() - runStarted;
104
+ }
105
+ };
97
106
  const t = (f, add) => { if (!timing)
98
107
  return f(); const t0 = performance.now(); try {
99
108
  return f();
@@ -797,7 +806,7 @@ export function cdclSession(goal, root, opts = {}) {
797
806
  if (!x.quiet && sx)
798
807
  phaseAtPoint(x, sx);
799
808
  levels.push(trail.length);
800
- st.decisions++;
809
+ noteDecision();
801
810
  assignVar(x, x.phase);
802
811
  return true;
803
812
  };
@@ -869,6 +878,10 @@ export function cdclSession(goal, root, opts = {}) {
869
878
  until = b.until ?? Infinity;
870
879
  wall = w;
871
880
  last = goal.hyps.length - 1;
881
+ if (timing) {
882
+ runStarted = performance.now();
883
+ sawDecision = false;
884
+ }
872
885
  restartAt = 32;
873
886
  nRestart = 0;
874
887
  sinceRestart = 0;
@@ -961,7 +974,7 @@ export function cdclSession(goal, root, opts = {}) {
961
974
  if (++budget.nodes > 200_000 || late(until) || (wall !== undefined && performance.now() > wall))
962
975
  return stuck('unknown', budget.nodes > 200_000 ? 'nodes' : 'time');
963
976
  let conflict;
964
- const ci = propagate();
977
+ const ci = t(propagate, ms => { st.propagationMs += ms; });
965
978
  let open = -1, wrong = -1;
966
979
  if (ci === undefined)
967
980
  for (; aq < assumed.length; aq++) {
@@ -1287,7 +1300,7 @@ export function cdclSession(goal, root, opts = {}) {
1287
1300
  if (!pick)
1288
1301
  return verdict?.kind === 'sat' ? stuck('sat', 'a model', { witness: verdict.witness }) : stuck('unknown', 'no split');
1289
1302
  levels.push(trail.length);
1290
- st.decisions++;
1303
+ noteDecision();
1291
1304
  assign(pick, vars.get(pick).phase);
1292
1305
  if (clausal && lpSat)
1293
1306
  free = batch;
@@ -1378,6 +1391,8 @@ export function cdclSession(goal, root, opts = {}) {
1378
1391
  // extends to (a gate its formula's value).
1379
1392
  const retire = (hyp) => { for (const ci of byHyp[hyp] ?? [])
1380
1393
  retired[ci] = true; };
1394
+ if (timing)
1395
+ st.setupMs += performance.now() - setupStarted;
1381
1396
  return { run, retire };
1382
1397
  }
1383
1398
  // The DAG as a kernel tree below `root`, walked depth first with a reader of its own (the tree's path is a stack, as
@@ -64,6 +64,14 @@ export declare function cellParts(cell: string): {
64
64
  };
65
65
  export declare function withProducts(rows: Constraint[], pairs: [number, number][], squares?: Lin[]): Constraint[];
66
66
  export declare function check(goal: Goal, tree: Tree, path?: Path): boolean;
67
+ export type LemmaCut = {
68
+ when: Lin[];
69
+ cut: Lin;
70
+ tree: Tree;
71
+ slice?: number[];
72
+ };
73
+ export declare function lemmaPath(lemmas: LemmaCut[], path: Path): Path;
74
+ export declare function checkGoalLemmas(goal: Goal, tree: Tree, lemmas?: LemmaCut[]): boolean;
67
75
  export type Subst = {
68
76
  vars: Record<string, E>;
69
77
  maps: Record<string, (key: E) => E>;
@@ -337,6 +345,7 @@ export declare function countedOk(hyps: C[], cs: Count[], is: CountInst[]): bool
337
345
  export declare function checkCounted(g: CountedGoal, cert: {
338
346
  insts: CountInst[];
339
347
  tree: Tree;
348
+ lemmas?: LemmaCut[];
340
349
  }): boolean;
341
350
  export declare function countedGoal(g: CountedGoal, insts: CountInst[]): Goal | undefined;
342
351
  export type CountDecl = {
@@ -354,6 +363,7 @@ export type CountCert = {
354
363
  insts: CountInst[];
355
364
  tree: Tree;
356
365
  picks?: [string, E[]][];
366
+ lemmas?: LemmaCut[];
357
367
  };
358
368
  export declare const postName: (map: string) => string;
359
369
  export declare const stateCounts: (m: Machine) => string[];
@@ -664,6 +664,59 @@ export function check(goal, tree, path = new Map()) {
664
664
  const yes = new Map(path).set(id, { lin: tree.split, holds: true }), no = new Map(path).set(id, { lin: tree.split, holds: false });
665
665
  return check(goal, tree.yes, yes) && check(goal, tree.no, no);
666
666
  }
667
+ const lemmaLin = (lin) => !!lin && typeof lin === 'object' && !Array.isArray(lin)
668
+ && (Object.getPrototypeOf(lin) === Object.prototype || Object.getPrototypeOf(lin) === null)
669
+ && Object.values(lin).every(Number.isSafeInteger);
670
+ // Lean's path is a list, so repeated atoms remain input rows, with the first deciding lookup. Keep that exact
671
+ // behavior in a Map: noncanonical duplicate keys contain no colon and cannot collide with a nonempty canon(lin).
672
+ function prependAtoms(front, path) {
673
+ const out = new Map();
674
+ let duplicate = 0;
675
+ for (const atom of [...front, ...path.values()]) {
676
+ const id = canon(atom.lin);
677
+ out.set(out.has(id) ? `@${duplicate++}` : id, atom);
678
+ }
679
+ return out;
680
+ }
681
+ // Eligibility uses only the original split path, never another cut. The returned path is for a leaf alone.
682
+ export function lemmaPath(lemmas, path) {
683
+ // Lean's dec treats all-zero variable coefficients as constant. Normalize only this
684
+ // new-condition decision boundary: preserve the original proof rows and every legacy path.
685
+ lemmas = lemmas.map(l => ({ ...l, when: l.when.map(w => Object.keys(w).every(key => key === '1' || w[key] === 0) ? k(w['1'] ?? 0) : w) }));
686
+ const active = lemmas.filter(l => l.when.every(w => decide(w, path) === true));
687
+ return active.length ? prependAtoms(active.map(l => ({ lin: l.cut, holds: true })), path) : path;
688
+ }
689
+ export function checkGoalLemmas(goal, tree, lemmas = []) {
690
+ if (!Array.isArray(lemmas))
691
+ return false;
692
+ if (!lemmas.length)
693
+ return check(goal, tree); // Exact legacy path, including all old refusal checks.
694
+ try {
695
+ if (!Array.from(lemmas).every(l => !!l && typeof l === 'object' && Array.isArray(l.when)
696
+ && Array.from(l.when).every(lemmaLin) && lemmaLin(l.cut) && !!l.tree && typeof l.tree === 'object'
697
+ && (l.slice === undefined || Array.isArray(l.slice) && Array.from(l.slice).every(i => Number.isSafeInteger(i) && i >= 0 && i < goal.hyps.length))))
698
+ return false;
699
+ for (const l of lemmas) {
700
+ const hyps = l.slice === undefined ? goal.hyps : l.slice.map(i => goal.hyps[i]);
701
+ const path = prependAtoms([{ lin: l.cut, holds: false }, ...l.when.map(lin => ({ lin, holds: true }))], new Map());
702
+ if (!check({ ...goal, hyps }, l.tree, path))
703
+ return false;
704
+ }
705
+ const visit = (t, path) => {
706
+ if ('leaf' in t)
707
+ return check(goal, t, lemmaPath(lemmas, path));
708
+ const id = canon(t.split);
709
+ if (path.has(id) || Object.keys(t.split).every(key => key === '1'))
710
+ return false;
711
+ return visit(t.yes, new Map(path).set(id, { lin: t.split, holds: true }))
712
+ && visit(t.no, new Map(path).set(id, { lin: t.split, holds: false }));
713
+ };
714
+ return visit(tree, new Map());
715
+ }
716
+ catch {
717
+ return false;
718
+ } // Malformed new payloads, including non-tree lemma references, are refusals.
719
+ }
667
720
  // --- machines ----------------------------------------------------------------------------------------------------------
668
721
  // Every constant and factor is a natural, so every value a machine computes is one (∸ truncates).
669
722
  function natural(e) {
@@ -2274,7 +2327,7 @@ export function checkCounted(g, cert) {
2274
2327
  if (!(countedOk(g.hyps, g.counts, cert.insts) && typed(cert.insts)))
2275
2328
  return false;
2276
2329
  const goal = countedGoal(g, cert.insts);
2277
- return goal !== undefined && check(goal, cert.tree);
2330
+ return goal !== undefined && checkGoalLemmas(goal, cert.tree, cert.lemmas);
2278
2331
  }
2279
2332
  // The goal a certificate's tree refutes: the goal's hypotheses, then the instances' (also what the search and the
2280
2333
  // exporter read), or none.
@@ -2407,7 +2460,7 @@ function checkCountedW(hyps, cs, cert) {
2407
2460
  if (!(countedOkW(cs, cert.insts) && typed(cert.insts)))
2408
2461
  return false;
2409
2462
  const hs = countHyps(cs, cert.insts);
2410
- return hs !== undefined && check({ name: 'counted', hyps: [...hyps, ...hs] }, cert.tree);
2463
+ return hs !== undefined && checkGoalLemmas({ name: 'counted', hyps: [...hyps, ...hs] }, cert.tree, cert.lemmas);
2411
2464
  }
2412
2465
  // checkMC: each declaration's j and lo differ from its key, the reads are fresh, no read is a witness or reads one in
2413
2466
  // its key term, and checkCountedW accepts the counted goal they make (the goal's hypotheses, each read variable equal to
@@ -2418,7 +2471,7 @@ export function checkMC(hyps, ds, k) {
2418
2471
  if (!k.reads.every(r => k.insts.every(i => i.wit !== r[0] && !readsVar(r[2], i.wit))))
2419
2472
  return false;
2420
2473
  const cs = toCounts(ds, k.reads);
2421
- return cs !== undefined && checkCountedW([...hyps, ...k.reads.map(r => readHyp(ds, r)), ...pickHyps(ds, k.reads, k.picks ?? [])], cs, { insts: k.insts, tree: k.tree });
2474
+ return cs !== undefined && checkCountedW([...hyps, ...k.reads.map(r => readHyp(ds, r)), ...pickHyps(ds, k.reads, k.picks ?? [])], cs, { insts: k.insts, tree: k.tree, lemmas: k.lemmas });
2422
2475
  }
2423
2476
  // The goal a certificate's tree refutes (what the search and the exporter read), or none.
2424
2477
  export function mcGoal(hyps, ds, k) {
@@ -1,3 +1,3 @@
1
- import type { Goal } from './kernel.js';
1
+ import type { Goal, Path } from './kernel.js';
2
2
  import { type Refuted } from './cdcl.js';
3
- export declare function modelSequence(): (goal: Goal, end: number) => Refuted;
3
+ export declare function modelSequence(path?: Path): (goal: Goal, end: number) => Refuted;
@@ -1,19 +1,20 @@
1
1
  import { cdclSession, growCdcl } from "./cdcl.js";
2
2
  import { wideFor } from "./prove.js";
3
- export function modelSequence() {
3
+ export function modelSequence(path = new Map()) {
4
+ const fixedPath = new Map(path);
4
5
  let session, held, texts = [];
5
6
  return (goal, end) => {
6
7
  const budget = { nodes: 0, until: end };
7
8
  if (wideFor(goal)) {
8
9
  session = undefined;
9
10
  held = undefined;
10
- return growCdcl(goal, new Map(), budget, { model: true, core: true, point: true });
11
+ return growCdcl(goal, fixedPath, budget, { model: true, core: true, point: true });
11
12
  }
12
13
  const current = goal.hyps.map(h => JSON.stringify(h)), at = new Map(current.map((h, i) => [h, i]));
13
14
  if (!held || !session || texts.some(h => !at.has(h))) {
14
15
  held = { name: goal.name, hyps: [...goal.hyps] };
15
16
  texts = [...current];
16
- session = cdclSession(held, new Map(), { model: true, core: true, point: true });
17
+ session = cdclSession(held, fixedPath, { model: true, core: true, point: true });
17
18
  }
18
19
  else {
19
20
  const old = new Set(texts);
@@ -0,0 +1,2 @@
1
+ import { type C, type E } from '../core/machine.js';
2
+ export declare function modelValueTerms(body: C, name: string, free: ReadonlySet<string>, value: (e: E) => number | undefined): E[];
@@ -0,0 +1,60 @@
1
+ // Untrusted MBQI proposals for naturals that are values, not map keys.
2
+ // A model supplies the other terms in a linear comparison. Its boundary and
3
+ // neighbours are candidate constants; only the instantiated law is assumed,
4
+ // and the ordinary kernel must still check the resulting proof.
5
+ import { walkOnce } from "../core/machine.js";
6
+ export function modelValueTerms(body, name, free, value) {
7
+ // Function arguments are keys too. Preserve their existing symbolic domain:
8
+ // replacing f(k)'s key by an equal-valued constant can lose later instances.
9
+ // Only a natural never used as a read key gets arithmetic boundary proposals.
10
+ let keyed = false;
11
+ walkOnce(body, o => {
12
+ const e = o;
13
+ if (e.op !== 'get')
14
+ return;
15
+ walkOnce(e.key, k => { const part = k; if (part.op === 'var' && part.name === name)
16
+ keyed = true; });
17
+ });
18
+ if (keyed)
19
+ return [];
20
+ const linear = (e) => {
21
+ if (e.op === 'var' && e.name === name)
22
+ return { coefficient: 1, constant: 0 };
23
+ if (e.op === 'add') {
24
+ const a = linear(e.a), b = linear(e.b);
25
+ return a && b ? { coefficient: a.coefficient + b.coefficient, constant: a.constant + b.constant } : undefined;
26
+ }
27
+ if (e.op === 'mul') {
28
+ const a = linear(e.a);
29
+ return a ? { coefficient: e.k * a.coefficient, constant: e.k * a.constant } : undefined;
30
+ }
31
+ const text = JSON.stringify(e);
32
+ if ([...free].some(n => text.includes(`"name":${JSON.stringify(n)}`)))
33
+ return undefined;
34
+ const constant = value(e);
35
+ return constant === undefined || !Number.isSafeInteger(constant) ? undefined : { coefficient: 0, constant };
36
+ };
37
+ const terms = new Set();
38
+ const visit = (c) => {
39
+ if (c.op === 'not')
40
+ return visit(c.x);
41
+ if (c.op === 'and' || c.op === 'or') {
42
+ c.xs.forEach(visit);
43
+ return;
44
+ }
45
+ if (c.op !== '=' && c.op !== '<=' && c.op !== '<')
46
+ return;
47
+ const a = linear(c.a), b = linear(c.b);
48
+ if (!a || !b)
49
+ return;
50
+ const coefficient = a.coefficient - b.coefficient, constant = b.constant - a.constant;
51
+ if (!coefficient || !Number.isSafeInteger(coefficient) || !Number.isSafeInteger(constant))
52
+ return;
53
+ const boundary = Math.floor(constant / coefficient);
54
+ for (const v of [boundary, boundary + 1, boundary - 1])
55
+ if (Number.isSafeInteger(v) && v >= 0)
56
+ terms.add(v);
57
+ };
58
+ visit(body);
59
+ return [...terms].slice(0, 16).map(value => ({ op: 'const', value }));
60
+ }
@@ -66,6 +66,10 @@ export declare function grow(goal: Goal, path?: Path, budget?: {
66
66
  until?: number;
67
67
  units?: boolean;
68
68
  }): Outcome;
69
+ export declare const treeReuseStats: {
70
+ hits: number;
71
+ kept: number;
72
+ };
69
73
  export declare function withTrees<T>(f: () => T): T;
70
74
  export declare const queryHook: {
71
75
  on?: (q: {
@@ -128,6 +132,12 @@ export declare function withModels<T>(m: Machine, laws: Law[], inst: Instances,
128
132
  inst: Instances;
129
133
  };
130
134
  export declare const relatedMost = 512, relatedBudget = 8192;
135
+ export declare function instancesFor(m: Machine, laws: Law[], build: (inst: Instances) => Goal[], opts?: {
136
+ seed?: E[];
137
+ focus?: string[];
138
+ start?: Instances;
139
+ reads?: boolean;
140
+ }): Instances;
131
141
  export declare function triggered(m: Machine, laws: Law[], inst: Instances, build: (inst: Instances) => Goal[], focus?: string[]): Instances;
132
142
  export declare const minimal: {
133
143
  on: boolean;