gdp-wired 0.44.0 → 0.46.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 (133) hide show
  1. package/README.md +58 -7
  2. package/dist/core/bitsets.d.ts +2 -0
  3. package/dist/core/bitsets.js +23 -0
  4. package/dist/core/bmc.js +6 -2
  5. package/dist/core/c/reader.d.ts +9 -1
  6. package/dist/core/c/reader.js +445 -38
  7. package/dist/core/calendar.d.ts +29 -0
  8. package/dist/core/calendar.js +82 -0
  9. package/dist/core/check.js +3 -2
  10. package/dist/core/cli.d.ts +4 -0
  11. package/dist/core/cli.js +335 -39
  12. package/dist/core/compose.js +3 -1
  13. package/dist/core/counts.d.ts +5 -2
  14. package/dist/core/counts.js +335 -88
  15. package/dist/core/cycles.js +8 -1
  16. package/dist/core/cyclic.d.ts +1 -0
  17. package/dist/core/cyclic.js +13 -7
  18. package/dist/core/data-synth.d.ts +3 -0
  19. package/dist/core/data-synth.js +252 -0
  20. package/dist/core/data.d.ts +8 -2
  21. package/dist/core/data.js +1113 -172
  22. package/dist/core/discover.js +3 -1
  23. package/dist/core/draft.d.ts +19 -0
  24. package/dist/core/draft.js +53 -0
  25. package/dist/core/dsl.d.ts +39 -3
  26. package/dist/core/dsl.js +250 -31
  27. package/dist/core/effect-prims.js +2 -2
  28. package/dist/core/effect.d.ts +1 -4
  29. package/dist/core/effect.js +1 -15
  30. package/dist/core/ex/reader.exs +17 -1
  31. package/dist/core/exists.d.ts +16 -1
  32. package/dist/core/exists.js +447 -50
  33. package/dist/core/extract-c.d.ts +2 -0
  34. package/dist/core/extract-c.js +185 -31
  35. package/dist/core/extract-check.d.ts +7 -0
  36. package/dist/core/extract-check.js +115 -3
  37. package/dist/core/extract-ex.js +3 -3
  38. package/dist/core/extract-go-check.d.ts +1 -1
  39. package/dist/core/extract-go-check.js +21 -13
  40. package/dist/core/extract-go.d.ts +1 -0
  41. package/dist/core/extract-go.js +58 -9
  42. package/dist/core/extract-ir.d.ts +1 -0
  43. package/dist/core/extract-ir.js +15 -0
  44. package/dist/core/extract-jvm.d.ts +1 -1
  45. package/dist/core/extract-jvm.js +65 -14
  46. package/dist/core/extract-orm.d.ts +12 -0
  47. package/dist/core/extract-orm.js +244 -0
  48. package/dist/core/extract-print.js +23 -1
  49. package/dist/core/extract-py.d.ts +1 -0
  50. package/dist/core/extract-py.js +4 -4
  51. package/dist/core/extract-rb.js +3 -3
  52. package/dist/core/extract-read.d.ts +25 -0
  53. package/dist/core/extract-read.js +60 -5
  54. package/dist/core/extract-rs.js +22 -20
  55. package/dist/core/extract-shapes.js +22 -0
  56. package/dist/core/extract-sol.d.ts +10 -1
  57. package/dist/core/extract-sol.js +89 -30
  58. package/dist/core/extract-step.d.ts +201 -4
  59. package/dist/core/extract-step.js +1514 -111
  60. package/dist/core/extract-swift.js +24 -13
  61. package/dist/core/extract.d.ts +9 -0
  62. package/dist/core/extract.js +88 -7
  63. package/dist/core/fiber-run.d.ts +5 -0
  64. package/dist/core/fiber-run.js +18 -0
  65. package/dist/core/fresh.d.ts +2 -2
  66. package/dist/core/fresh.js +7 -3
  67. package/dist/core/go/reader.go +7 -1
  68. package/dist/core/infer.d.ts +4 -1
  69. package/dist/core/infer.js +1020 -246
  70. package/dist/core/jvm/JavaReader.java +33 -8
  71. package/dist/core/jvm/Jvm.java +20 -1
  72. package/dist/core/jvm/KtReader.java +59 -6
  73. package/dist/core/laws.d.ts +10 -3
  74. package/dist/core/laws.js +193 -14
  75. package/dist/core/machine.d.ts +16 -3
  76. package/dist/core/machine.js +212 -28
  77. package/dist/core/nonterm.js +14 -1
  78. package/dist/core/orm/harness.js +61 -0
  79. package/dist/core/orm-fixtures/schema.prisma +5 -0
  80. package/dist/core/py/harness.py +260 -21
  81. package/dist/core/py/reader.py +278 -39
  82. package/dist/core/rb/reader.rb +52 -5
  83. package/dist/core/reader-fixtures/README.md +28 -0
  84. package/dist/core/reader-fixtures/c-693042.cpp +8 -0
  85. package/dist/core/reader-fixtures/go-685506.go +14 -0
  86. package/dist/core/reader-fixtures/jvm-724362.kt +8 -0
  87. package/dist/core/reader-fixtures/jvm-737430.kt +7 -0
  88. package/dist/core/reader-fixtures/jvm-765282.kt +3 -0
  89. package/dist/core/reader-fixtures/swift-735726.swift +15 -0
  90. package/dist/core/reader-fixtures/swift-735990.swift +15 -0
  91. package/dist/core/reader-fixtures/swift-739158.swift +4 -0
  92. package/dist/core/reader-fixtures/swift-744834.swift +15 -0
  93. package/dist/core/reader-fixtures/swift-746946.swift +31 -0
  94. package/dist/core/reader-fixtures/typescript-673062.ts.txt +2 -0
  95. package/dist/core/relation.d.ts +1 -1
  96. package/dist/core/relation.js +29 -2
  97. package/dist/core/relational.js +4 -2
  98. package/dist/core/rs/src/main.rs +18 -2
  99. package/dist/core/sample-cache.d.ts +8 -0
  100. package/dist/core/sample-cache.js +46 -0
  101. package/dist/core/security.d.ts +38 -0
  102. package/dist/core/security.js +88 -0
  103. package/dist/core/sol/harness.py +63 -7
  104. package/dist/core/sol-concrete.d.ts +23 -0
  105. package/dist/core/sol-concrete.js +195 -0
  106. package/dist/core/solver.js +8 -5
  107. package/dist/core/swift/Sources/gdp-swiftreader/main.swift +50 -7
  108. package/dist/core/system.d.ts +62 -1
  109. package/dist/core/system.js +263 -4
  110. package/dist/core/transfer.js +39 -9
  111. package/dist/core/translate.js +39 -10
  112. package/dist/core/watch.js +51 -6
  113. package/dist/interchange/check.js +10 -10
  114. package/dist/interchange/format.d.ts +4 -0
  115. package/dist/interchange/format.js +24 -6
  116. package/dist/kernel/cdcl.d.ts +5 -0
  117. package/dist/kernel/cdcl.js +88 -10
  118. package/dist/kernel/epr.js +141 -29
  119. package/dist/kernel/kernel.d.ts +31 -1
  120. package/dist/kernel/kernel.js +391 -101
  121. package/dist/kernel/model-sequence.d.ts +3 -0
  122. package/dist/kernel/model-sequence.js +34 -0
  123. package/dist/kernel/prove.d.ts +30 -1
  124. package/dist/kernel/prove.js +481 -71
  125. package/dist/kernel/reader.d.ts +3 -0
  126. package/dist/kernel/reader.js +101 -14
  127. package/dist/kernel/share.d.ts +1 -0
  128. package/dist/kernel/share.js +27 -0
  129. package/dist/lean-kernel/emit.d.ts +9 -3
  130. package/dist/lean-kernel/emit.js +200 -66
  131. package/dist/lean-kernel/lean-terms.js +5 -0
  132. package/dist/lean-kernel/library.js +10 -10
  133. package/package.json +7 -2
@@ -1,6 +1,7 @@
1
- import { assumed, checkCountedLaws, countedObligations, mcGoal, scope, substC } from "../kernel/kernel.js";
2
- import { clock, counted, fullRate, grow, modelInstances, wallAt, widen, withWall } from "../kernel/prove.js";
3
- import { REFUTED, cdclStats, growCdcl } from "../kernel/cdcl.js";
1
+ import { assumed, checkCountedLaws, countedObligations, mcGoal, scope, substC, substE } from "../kernel/kernel.js";
2
+ import { brokenOf, clock, counted, fullRate, grow, modelInstances, wallAt, widen, withWall } from "../kernel/prove.js";
3
+ import { REFUTED, cdclStats } from "../kernel/cdcl.js";
4
+ import { modelSequence } from "../kernel/model-sequence.js";
4
5
  import { inferLaws } from "./infer.js";
5
6
  import { smallOf, trueSmall } from "./exists.js";
6
7
  import { env } from "./solver.js";
@@ -8,6 +9,7 @@ import { env } from "./solver.js";
8
9
  // profiles: each step goal left unknown or with a model past GDP_COUNTS_DUMP_MIN (300) hypotheses, the first GDP_COUNTS_DUMP_N (3))
9
10
  export const cprof = {};
10
11
  export const countsDump = {};
12
+ const tally = (k, n = 1) => { cprof[k] = (cprof[k] ?? 0) + n; };
11
13
  const ptime = (k, f) => { const t = performance.now(); try {
12
14
  return f();
13
15
  }
@@ -15,6 +17,9 @@ finally {
15
17
  cprof[k] = (cprof[k] ?? 0) + performance.now() - t;
16
18
  } };
17
19
  let dumped = 0;
20
+ // (GDP_COUNTS_LAZY=0: every instance and pick certFor proposes in the goal at once, as before; `wide`: the narrow
21
+ // instances at once, the widened goal's further instances and picks lazily)
22
+ const lazyMode = env.GDP_COUNTS_LAZY ?? 'wide', pool = Number(env.GDP_COUNTS_POOL ?? 1000);
18
23
  const v = (name) => ({ op: 'var', name }), k = (value) => ({ op: 'const', value });
19
24
  const json = (t) => JSON.stringify(t);
20
25
  const one = k(1), zero = k(0);
@@ -33,6 +38,8 @@ function reads(t0, map, out = new Map()) {
33
38
  return out;
34
39
  }
35
40
  const mentions = (t, name) => json(t).includes(`"name":${json(name)}`);
41
+ // Whether some object within t0 meets p (a condition nested in a term's `if` too).
42
+ const some = (t0, p) => !!t0 && typeof t0 === 'object' && (p(t0) || Object.values(t0).some(y => some(y, p)));
36
43
  const atoms = (c) => (c.op === 'and' || c.op === 'or' ? c.xs.flatMap(atoms) : c.op === 'not' ? atoms(c.x) : [c]);
37
44
  // --- candidates from the guard's shape -----------------------------------------------------------------------------------
38
45
  export function guardLaws(m) {
@@ -67,38 +74,120 @@ export function guardLaws(m) {
67
74
  }
68
75
  }
69
76
  for (const [mp, w] of Object.entries(m.step.maps ?? {})) {
70
- if ('each' in w || w.key.op !== 'var' || !m.inputs.includes(w.key.name))
77
+ // (the written key: a request's value t, or two, t and u, composed N·t + u (a relation's cell): a count of two
78
+ // parameters, read at the law's N·a + b with b < N)
79
+ if ('each' in w)
71
80
  continue;
72
- const t = w.key.name, written = inline({ op: '<=', a: one, b: w.value });
73
- const law = (name, cmp) => when(name, { op: '<=', a: one, b: { op: 'get', map: mp, key: v('a$c') } }, cmp);
81
+ const k0 = w.key, ps = k0.op === 'var' ? [k0.name] : k0.op === 'add' && k0.a.op === 'mul' && k0.a.k > 1 && k0.a.a.op === 'var' && k0.b.op === 'var' && k0.a.a.name !== k0.b.name ? [k0.a.a.name, k0.b.name] : [];
82
+ if (!ps.length || !ps.every(i => m.inputs.includes(i)))
83
+ continue;
84
+ const t = ps[0], base = ps.length === 2 && k0.op === 'add' && k0.a.op === 'mul' ? k0.a.k : 0, written = inline({ op: '<=', a: one, b: w.value });
85
+ const at = base ? { op: 'add', a: { op: 'mul', k: base, a: v('a$c') }, b: v('b$c') } : v('a$c');
86
+ const law = (name, cmp) => (base
87
+ ? { name, forall: 'a$c', keys: ['b$c'], holds: { op: 'or', xs: [{ op: 'not', x: { op: 'and', xs: [{ op: '<=', a: one, b: { op: 'get', map: mp, key: at } }, { op: '<', a: v('b$c'), b: k(base) }] } }, cmp] } }
88
+ : when(name, { op: '<=', a: one, b: { op: 'get', map: mp, key: v('a$c') } }, cmp));
74
89
  // A comparison with a state count at the written key.
75
- for (const g of guards)
76
- for (const [, [c, key]] of reads(g, isCount)) {
77
- if (json(key) !== json(v(t)) || mentions(m.counts[c].body, t))
78
- continue;
79
- if (m.inputs.some(i => i !== t && mentions(g, i)))
80
- continue;
81
- laws.push(law(`${mp} keeps ${c}'s bound`, substC(g, { vars: { [t]: v('a$c') }, maps: {}, flags: {} })));
82
- }
83
- // A quantified flag the write reads: every member of a counted set satisfies R(member, t).
90
+ if (!base)
91
+ for (const g of guards)
92
+ for (const [, [c, key]] of reads(g, isCount)) {
93
+ if (json(key) !== json(v(t)) || mentions(m.counts[c].body, t))
94
+ continue;
95
+ if (m.inputs.some(i => i !== t && mentions(g, i)))
96
+ continue;
97
+ laws.push(law(`${mp} keeps ${c}'s bound`, substC(g, { vars: { [t]: v('a$c') }, maps: {}, flags: {} })));
98
+ }
99
+ // What the write reads of every member of a counted set: R(member, t) by a quantified flag (∀ q. h(q) → R(q, t)),
100
+ // or by a request's count of the members without it read 0 (|{k: h(k) ∧ ¬R(k, t)}| = 0).
101
+ const said = [];
84
102
  for (const [f, q] of Object.entries(flags)) {
85
103
  if (q.op !== 'all' || q.keys?.length || !mentions(written, `?${f}`) || q.c.op !== 'or' || q.c.xs.length !== 2)
86
104
  continue;
87
105
  const [h, r] = q.c.xs[0].op === 'not' ? [q.c.xs[0].x, q.c.xs[1]] : [q.c.xs[1].op === 'not' ? q.c.xs[1].x : undefined, q.c.xs[0]];
88
- if (!h || !r)
106
+ if (h && r)
107
+ said.push({ key: q.key, h, r });
108
+ }
109
+ for (const [c0, d0] of Object.entries(m.counts ?? {})) {
110
+ const zero0 = some(written, x => x.op === '=' && x.a?.op === 'get' && x.a.map === c0 && x.b?.op === 'const' && x.b.value === 0);
111
+ const b0 = d0.body.op === 'if' && d0.body.c.op === 'and' && d0.body.c.xs.length === 2 ? d0.body.c.xs : undefined;
112
+ if (!zero0 || !b0 || mentions([d0.body, d0.below], d0.j))
89
113
  continue;
114
+ const [h, r] = b0[1].op === 'not' ? [b0[0], b0[1].x] : b0[0].op === 'not' ? [b0[1], b0[0].x] : [];
115
+ if (h && r)
116
+ said.push({ key: d0.key, h, r });
117
+ }
118
+ for (const { key: qk, h, r } of said) {
90
119
  for (const [c, d] of Object.entries(all)) {
91
- // the set: the count's body is the flag's hypothesis at its key
120
+ // the set: the count's body is the hypothesis at its key
92
121
  const body = d.body.op === 'if' ? d.body.c : undefined;
93
- if (!body || json(substC(body, { vars: { [d.key]: v(q.key) }, maps: {}, flags: {} })) !== json(h))
122
+ if (!body || json(substC(body, { vars: { [d.key]: v(qk) }, maps: {}, flags: {} })) !== json(h))
94
123
  continue;
95
- if (m.inputs.some(i => i !== t && mentions(r, i)))
124
+ if (m.inputs.some(i => !ps.includes(i) && mentions(r, i)))
96
125
  continue;
97
- const name = `${c}$${mp}`, j = `${name}$x`, key = `${name}$k`;
98
- counts[name] = { j, key, below: d.below, body: { op: 'if', c: substC(r, { vars: { [q.key]: v(key), [t]: v(j) }, maps: {}, flags: {} }), then: one, else: zero } };
126
+ const name = `${c}$${mp}`, j = `${name}$x`, key = `${name}$k`, lo = `${name}$y`;
127
+ counts[name] = { j, key, below: d.below, body: { op: 'if', c: substC(r, { vars: { [qk]: v(key), [t]: v(j), ...(base ? { [ps[1]]: v(lo) } : {}) }, maps: {}, flags: {} }), then: one, else: zero }, ...(base ? { lo, base } : {}) };
99
128
  for (const g of [...guards, ...more])
100
129
  if (reads(g, x => x === c).size)
101
- laws.push(law(`${mp} keeps ${c}'s bound through ${name}`, substC(g, { vars: {}, maps: { [c]: () => ({ op: 'get', map: name, key: v('a$c') }) }, flags: {} })));
130
+ laws.push(law(`${mp} keeps ${c}'s bound through ${name}`, substC(g, { vars: {}, maps: { [c]: () => ({ op: 'get', map: name, key: at }) }, flags: {} })));
131
+ }
132
+ }
133
+ }
134
+ // Who did or still can write a relation: a write W[N²·n + N·t + u] := 1 by a request's node n (below the bound of the
135
+ // set the guard counts) under a flag whose literals reading n are G(n, t, u). Its count over two parameters,
136
+ // c(t, u) = |{k: G(k, t, u) ∨ W[N²·k + N·t + u]}|, the keys that wrote it at (t, u) or may yet; a set the guard counts
137
+ // and every such k meet unless c is at most what the guard's comparison forbids. Proposed under each map P the flag
138
+ // reads at N·t + u alone (a cell the writes at (t, u) need), at another (c, d): P[N·c + d] ∧ a < c (∧ b ≠ d, or a ≤ c ∧
139
+ // b ≠ d) ⇒ ¬(the guard's comparison with c at (a, b)): no majority could write W at (a, b) once P holds further on.
140
+ const lin = (e) => {
141
+ if (e.op === 'var')
142
+ return new Map([[e.name, 1]]);
143
+ if (e.op === 'mul' && e.a.op === 'var')
144
+ return new Map([[e.a.name, e.k]]);
145
+ if (e.op !== 'add')
146
+ return undefined;
147
+ const x = lin(e.a), y = lin(e.b);
148
+ if (!x || !y || [...x.keys()].some(q => y.has(q)))
149
+ return undefined;
150
+ return new Map([...x, ...y]);
151
+ };
152
+ const conj = (c) => (c.op === 'and' ? c.xs.flatMap(conj) : [c]);
153
+ for (const [mp, w] of Object.entries(m.step.maps ?? {})) {
154
+ if ('each' in w)
155
+ continue;
156
+ const l = lin(w.key), es = l && [...l.entries()].sort((x, y) => y[1] - x[1]);
157
+ if (!es || es.length !== 3 || !es.every(([q]) => m.inputs.includes(q)))
158
+ continue;
159
+ const [[nd, c0], [t, c1], [u, c2]] = es;
160
+ if (c2 !== 1 || c1 < 2 || c0 !== c1 * c1)
161
+ continue;
162
+ const base = c1;
163
+ for (const [f, fc] of Object.entries(flags)) {
164
+ if (fc.op === 'all' || !json(w.value).includes(`"op":"flag","name":${json(f)}`))
165
+ continue;
166
+ const parts = conj(inline(fc)), dep = parts.filter(x => mentions(x, nd));
167
+ if (!dep.length || dep.some(x => m.inputs.some(i => ![nd, t, u].includes(i) && mentions(x, i))))
168
+ continue;
169
+ const ps = parts.flatMap(x => (x.op === '=' && x.a.op === 'get' && x.b.op === 'const' && x.b.value === 1 ? [x.a] : x.op === '<=' && x.a.op === 'const' && x.a.value === 1 && x.b.op === 'get' ? [x.b] : []))
170
+ .filter(g => { const kl = lin(g.key); return !!kl && kl.size === 2 && kl.get(t) === base && kl.get(u) === 1; });
171
+ if (!ps.length)
172
+ continue;
173
+ for (const [c, d] of Object.entries(all)) {
174
+ if (d.body.op !== 'if' || !json(m.assume).includes(json({ op: '<', a: v(nd), b: d.below })))
175
+ continue;
176
+ const gs = guards.filter(g => reads(g, x => x === c).size);
177
+ if (!gs.length || mentions(d.body, d.j))
178
+ continue;
179
+ const name = `can$${mp}$${c}`, j = `${name}$x`, key = `${name}$k`, lo = `${name}$y`, sub = { vars: { [nd]: v(key), [t]: v(j), [u]: v(lo) }, maps: {}, flags: {} };
180
+ const body = { op: 'or', xs: [{ op: 'and', xs: dep.map(x => substC(x, sub)) }, { op: '<=', a: one, b: { op: 'get', map: mp, key: substE(w.key, sub) } }] };
181
+ counts[name] = { j, key, lo, base, below: d.below, body: { op: 'if', c: body, then: one, else: zero } };
182
+ const pk2 = (a, b) => ({ op: 'add', a: { op: 'mul', k: base, a: v(a) }, b: v(b) });
183
+ for (const g of gs)
184
+ for (const pg of ps)
185
+ for (const [r1, r2] of [['<', true], ['<', false], ['<=', true]]) {
186
+ const hyp = { op: 'and', xs: [{ op: '<=', a: one, b: { op: 'get', map: pg.map, key: pk2('c$c', 'd$c') } }, { op: r1, a: v('a$c'), b: v('c$c') },
187
+ ...(r2 ? [{ op: 'not', x: { op: '=', a: v('b$c'), b: v('d$c') } }] : []), { op: '<', a: v('b$c'), b: k(base) }, { op: '<', a: v('d$c'), b: k(base) }] };
188
+ laws.push({ name: `${pg.map} at (c, d) bounds ${name} at (a, b): a ${r1} c${r2 ? ', b ≠ d' : ''}`, forall: 'a$c', keys: ['b$c', 'c$c', 'd$c'],
189
+ holds: { op: 'or', xs: [{ op: 'not', x: hyp }, { op: 'not', x: substC(g, { vars: {}, maps: { [c]: () => ({ op: 'get', map: name, key: pk2('a$c', 'b$c') }) }, flags: {} }) }] } });
190
+ }
102
191
  }
103
192
  }
104
193
  }
@@ -108,7 +197,7 @@ export function guardLaws(m) {
108
197
  // The count cells the goal reads (each before the step with its post name's twin), instances over pairs of them with one
109
198
  // bound (a count that doesn't drop, +1 and −1; two that meet, +1, +1 and −1), each with a fresh witness; and the laws and
110
199
  // quantified flags at the witnesses (returned, for the goal's law's instances).
111
- export function certFor(goal, decls) {
200
+ export function certFor(goal, decls, wide = false, most = wide ? 24 : 10) {
112
201
  const byMap = new Map(decls.map(d => [d.map, d])), last = goal.hyps.at(-1);
113
202
  // (the conclusion's reads first, then those at a constant or the law's own names, then the rest)
114
203
  const own = (t) => t.op === 'const' || (t.op === 'var' && json(last).includes(`"name":${json(t.name)}`));
@@ -142,7 +231,59 @@ export function certFor(goal, decls) {
142
231
  for (const [j, c] of named.entries())
143
232
  if (i < j && !(ranked(a) || ranked(c)) && bound(a) === bound(c) && !post(a) && !post(c))
144
233
  add([[1, a[0]], [1, c[0]]], -1, byMap.get(a[1]).below);
145
- return { reads: named, insts: insts.slice(0, 10), wits: wits.slice(0, 10) };
234
+ // (a count after the step, the conclusion's, at least a request's count less another: a set's members all in it but
235
+ // those a guard's count of the rest finds, |Q| ≤ missing + votes)
236
+ for (const c of named)
237
+ if (post(c) && rank([c[1], c[2]]) === 0)
238
+ for (const a of named)
239
+ for (const d of named)
240
+ if (a !== d && !post(a) && !post(d) && keyless(a[1]) && keyless(d[1]) && bound(a) === bound(c) && bound(d) === bound(c))
241
+ add([[1, a[0]], [-1, d[0]], [-1, c[0]]], 0, byMap.get(c[1]).below);
242
+ // (wide, asked by a model the instances above leave: every count at most each other one of its bound, either way, and
243
+ // each positive only where a key is in it; a count read with no partner is then tied to its cells at a witness)
244
+ // (`most`: the instances kept, 24 widened; a lazy goal's pool takes many more, as only those a model breaks are asked)
245
+ const cap = most;
246
+ if (wide) {
247
+ insts.splice(10), wits.splice(10);
248
+ for (const a of named)
249
+ for (const c of named)
250
+ if (a !== c && bound(a) === bound(c) && !(post(c) && !post(a)))
251
+ add([[1, a[0]], [-1, c[0]]], 0, byMap.get(a[1]).below);
252
+ for (const a of named)
253
+ add([[1, a[0]]], 0, byMap.get(a[1]).below);
254
+ // (a lazy pool's further instances: each count at most its bound, and every two of a bound that meet)
255
+ if (cap > 24) {
256
+ for (const a of named)
257
+ add([[1, a[0]]], -1, byMap.get(a[1]).below);
258
+ const had = new Set(insts.map(i => json([i.terms, i.unit])));
259
+ for (const [i, a] of named.entries())
260
+ for (const [j, c] of named.entries())
261
+ if (i < j && bound(a) === bound(c) && post(a) === post(c) && !had.has(json([[[1, a[0]], [1, c[0]]], -1])))
262
+ add([[1, a[0]], [1, c[0]]], -1, byMap.get(a[1]).below);
263
+ }
264
+ }
265
+ // (wide: each count picked at the keys the goal reads the maps its body reads at its key and its instances' witnesses:
266
+ // at least its body there, at every two of them and at all of them)
267
+ const picks = [];
268
+ if (wide)
269
+ for (const r of named) {
270
+ const d = byMap.get(r[1]), at = [...reads(d.body, () => true).values()].filter(([, key]) => json(key) === json(v(d.key))).map(([mp]) => mp);
271
+ if (!at.length)
272
+ continue;
273
+ // (the key terms the goal reads those maps at, and the witnesses of the instances that name this count: a member the
274
+ // counting lemma found is a key too; three of each first, six at most)
275
+ const gs = [...new Map([...reads(goal.hyps, mp => at.includes(mp)).values()].map(([, t]) => [json(t), t])).values()].filter(t => !mentions(t, d.key));
276
+ const ws = insts.slice(0, cap).filter(i => i.terms.some(([, x]) => x === r[0])).map(i => v(i.wit)), ts0 = [...gs.slice(0, 3), ...ws.slice(0, 3), ...gs.slice(3), ...ws.slice(3)];
277
+ const ts = [...new Map(ts0.map(t => [json(t), t])).values()].slice(0, 6);
278
+ for (let i = 0; i < ts.length; i++)
279
+ for (let j = i + 1; j < ts.length; j++)
280
+ picks.push([r[0], [ts[i], ts[j]]]);
281
+ if (ts.length > 2)
282
+ picks.push([r[0], ts]);
283
+ }
284
+ // (loose: a read no instance among the first ten names, which only widening ties to its cells)
285
+ const loose = named.some(r => !insts.slice(0, 10).some(i => i.terms.some(([, x]) => x === r[0])));
286
+ return { reads: named, insts: insts.slice(0, cap), wits: wits.slice(0, cap), picks, loose };
146
287
  }
147
288
  // --- the candidates --------------------------------------------------------------------------------------------------
148
289
  // One list from the machine's shapes, each kept only if true on every small state: each map's cells at most what the
@@ -221,8 +362,8 @@ export function candidates(src, m, caller, shapes, guarded, ms, until) {
221
362
  console.error(`counts: ${kinds.length + guarded.length + rowLaws.length + cubes.length - out.length} candidates said before or false on the small instances`);
222
363
  return out;
223
364
  }
224
- export function cone(m, set, attempt, until) {
225
- const kept = new Map(), inCone = (l) => kept.has(l.name), tried = new Map(), times = new Map(), asked = new Set();
365
+ export function cone(m, set, attempt, until, houdini = false) {
366
+ const kept = new Map(), inCone = (l) => kept.has(l.name), tried = new Map(), times = new Map(), asked = new Set(), slow = new Set();
226
367
  const stopAt = until - (until - clock()) / 3, brief = (stopAt - clock()) / Math.max(1, set.length);
227
368
  // (the maps a law reads, a count's through its body)
228
369
  const mapsOf = (l) => new Set([...reads(l.holds, () => true).values()].flatMap(([mp]) => [mp, ...(m.counts?.[mp] ? [...reads(m.counts[mp].body, () => true).values()].map(([q]) => q) : [])]));
@@ -233,7 +374,7 @@ export function cone(m, set, attempt, until) {
233
374
  grew = false;
234
375
  for (const law of set) {
235
376
  const id = `${t} ${law.name}`;
236
- if (kept.has(law.name) || tried.get(id) === kept.size || (t === 0 && tried.has(id)) || (t === 2 && (times.get(law.name) ?? 0) >= 2) || clock() > stopAt)
377
+ if (kept.has(law.name) || tried.get(id) === kept.size || (t === 0 && tried.has(id)) || (t === 2 && ((times.get(law.name) ?? 0) >= 2 || slow.has(law.name))) || clock() > stopAt)
237
378
  continue;
238
379
  tried.set(id, kept.size);
239
380
  if (t === 2)
@@ -248,10 +389,14 @@ export function cone(m, set, attempt, until) {
248
389
  continue;
249
390
  asked.add(same);
250
391
  const r = attempt(law, ls, brief);
392
+ // (a law out of time over every kept law: tried again over more, its goals only grow; where Houdini follows, its
393
+ // share is larger)
394
+ if (houdini && t === 2 && 'stuck' in r && r.stuck !== 'sat')
395
+ slow.add(law.name);
251
396
  if ('proof' in r) {
252
397
  kept.set(law.name, r.proof);
253
398
  grew = any = true;
254
- if (env.GDP_COUNTS_TRACE === '3')
399
+ if (env.GDP_COUNTS_TRACE?.includes('3'))
255
400
  console.error(`counts: keep ${law.name.slice(0, 50)} tier ${t}`);
256
401
  }
257
402
  }
@@ -268,30 +413,37 @@ export function cone(m, set, attempt, until) {
268
413
  }
269
414
  // On the counted clock (kernel/prove.ts's `counted`, the cost model's work at fullRate a millisecond), as the engine's
270
415
  // search is: what a budget lets it try, and so its verdict, is the same on a slow or shared machine as on a fast one; the
271
- // wall a stop only at twice the budget.
416
+ // wall a stop only at twice the budget. The small instances (exists.ts's smallOf) are read before the wall starts: their
417
+ // search is bounded by its own count of steps, on neither clock, and took 3.6 to 5.2 s of an 8 s budget's 16 s wall on
418
+ // a boat VM (exists.test.ts's two counts), so a shared VM crossed the wall before the search began and left every goal
419
+ // unknown (2 runs in 4 on main; 4 in 4 beside three busy loops).
272
420
  export function searchCounted(m0, caller, ms = 60_000) {
273
- const run = () => withWall(performance.now() + 2 * ms, () => counted(fullRate, () => searchCounted0(m0, caller, ms), true));
421
+ const g = guardLaws(m0), m = { ...m0, counts: { ...m0.counts, ...g.counts } };
422
+ ptime('small', () => smallOf(m));
423
+ const run = () => withWall(performance.now() + 2 * ms, () => counted(fullRate, () => searchCounted0(m0, g, m, caller, ms), true));
274
424
  if (!env.GDP_COUNTS_PROF)
275
425
  return run();
276
426
  cdclStats.on = true;
277
427
  const t = performance.now(), out = run();
278
- console.error(`counts: prof total ${Math.round(performance.now() - t)} ms; ${Object.entries(cprof).map(([k2, x]) => `${k2} ${Math.round(x)}`).join(', ')}; cdcl runs ${cdclStats.runs} conflicts ${cdclStats.conflicts} decisions ${cdclStats.decisions} solveMs ${Math.round(cdclStats.solveMs)} rowsMs ${Math.round(cdclStats.rowsMs)} coreMs ${Math.round(cdclStats.coreMs)} unfoldMs ${Math.round(cdclStats.unfoldMs)} lpMs ${Math.round(cdclStats.lpMs)} boundMs ${Math.round(cdclStats.boundMs)} orderMs ${Math.round(cdclStats.orderMs)}`);
428
+ console.error(`counts: prof total ${Math.round(performance.now() - t)} ms; ${Object.entries(cprof).map(([k2, x]) => `${k2} ${Math.round(x)}`).join(', ')}; cdcl runs ${cdclStats.runs} conflicts ${cdclStats.conflicts} decisions ${cdclStats.decisions} solveMs ${Math.round(cdclStats.solveMs)} rowsMs ${Math.round(cdclStats.rowsMs)} coreMs ${Math.round(cdclStats.coreMs)} unfoldMs ${Math.round(cdclStats.unfoldMs)} lpMs ${Math.round(cdclStats.lpMs)} boundMs ${Math.round(cdclStats.boundMs)} orderMs ${Math.round(cdclStats.orderMs)} fmCalls ${cdclStats.fmCalls} lpMisses ${cdclStats.lpMisses} lpUnknown ${cdclStats.lpUnknown} missMs ${Math.round(cdclStats.missMs)} fastMs ${Math.round(cdclStats.fastMs)} fmOpenMs ${Math.round(cdclStats.fmOpenMs)} fmLeafMs ${Math.round(cdclStats.fmLeafMs)} nodes ${cdclStats.nodes}`);
279
429
  return out;
280
430
  }
281
- function searchCounted0(m0, caller, ms = 60_000) {
282
- const until = clock() + ms, g = guardLaws(m0), m = { ...m0, counts: { ...m0.counts, ...g.counts } };
431
+ function searchCounted0(m0, g, m, caller, ms) {
432
+ const until = clock() + ms;
283
433
  if (!caller.every(l => clock() < until && trueSmall(m, [l])))
284
434
  return { proven: false, laws: caller, m, why: clock() < until ? 'a law fails on the small instances' : 'time' };
285
435
  const t1 = clock();
286
- let set = [...caller, ...candidates(m0, m, caller, caller, g.laws, ms, until)];
436
+ // (GDP_COUNTS_GIVEN=1, research's: the callers alone, no candidate: whether a set written whole goes through)
437
+ let set = env.GDP_COUNTS_GIVEN === '1' ? [...caller] : [...caller, ...candidates(m0, m, caller, caller, g.laws, ms, until)];
287
438
  if (env.GDP_COUNTS_TRACE)
288
439
  console.error(`counts: candidates at ${Math.round(clock() - t1)} ms: ${set.map(l => l.name).join('; ')}`);
289
440
  // (the law's own names and the request's values that key a map: an action's value keys none)
290
441
  const keys0 = [...[...reads([m.step, m.assume ?? null], () => true).values()].map(([, key]) => key), ...Object.values(m.step.maps ?? {}).flatMap(w => ('each' in w ? [] : [w.key]))];
291
442
  const keyed = m.inputs.filter(i => keys0.some(key => mentions(key, i))).map(v);
292
443
  const terms = (l) => [...(l.forall ? [v(`${l.forall}#`)] : []), ...(l.keys ?? []).map(v), ...keyed];
293
- let counted = true;
294
- const none = { reads: [], insts: [] };
444
+ const widened = new Set();
445
+ let counted = true, houdini = false; // (houdini: the rounds over the whole set; only they widen)
446
+ const none = { reads: [], insts: [], wits: [], picks: [], loose: false };
295
447
  // One law's goals and their certificates, the laws `ls` assumed (a subsequence of the set): pass 0 with no instances of
296
448
  // the lemma, pass 1 with the cells' (one set of witnesses a law); a tree each within `ms`. The instances: the
297
449
  // quantified flags at the law's own terms, then what the goals' models ask.
@@ -300,18 +452,83 @@ function searchCounted0(m0, caller, ms = 60_000) {
300
452
  // broken at a tuple of the goal's keys); none broken, it is still a model, and the law is refuted again without a
301
453
  // solve. (Not where a law added reads a count: its goal's count instances aren't read here.)
302
454
  const models = new Map(), isCount = (mp) => !!m.counts?.[mp];
455
+ // Cone tiers and Houdini may ask the same law again with more instances. Keep a
456
+ // bounded set of sessions; each independently resets unless its hypotheses are
457
+ // still present verbatim. This reuses work, never a verdict from a weaker goal.
458
+ const decisions = new Map();
303
459
  const attempt = (law, ls, pass, ms) => {
460
+ // A cached model can return before the no-count optimization below. A helper
461
+ // without count reads must not suppress the next law's counting-lemma pass.
462
+ if (!pass)
463
+ counted = true;
304
464
  const ts = terms(law), id = `${pass} ${law.name}`, cti = models.get(id);
305
- if (cti && !ls.some(l => !cti.ls.has(l.name) && reads(l.holds, isCount).size)) {
465
+ // (the model broken: the attempt starts at the instances it asks for, its last attempt's and the tuples the new laws
466
+ // break it at, where the rounds of models would lead it again)
467
+ let seed;
468
+ // (not where the attempt may widen: its narrow model is no model of the widened goal)
469
+ if (cti && !(houdini && caller.some(l => l.name === law.name) && !widened.has(law.name)) && !ls.some(l => !cti.ls.has(l.name) && reads(l.holds, isCount).size)) {
306
470
  const at0 = Object.fromEntries(Object.entries(cti.at).filter(([n]) => n.startsWith('?') || ls.some(l => l.name === n)));
307
- if (!ptime('mbqi', () => modelInstances(m, ls, at0, cti.gg, cti.w)))
471
+ if (!(seed = ptime('mbqi', () => modelInstances(m, ls, at0, cti.gg, cti.w))))
308
472
  return { stuck: 'sat' };
309
473
  }
310
474
  const refuted = (gg, w) => { models.set(id, { gg, w, at, ls: new Set(ls.map(l => l.name)) }); return { stuck: 'sat' }; };
311
- let at = Object.fromEntries(Object.entries(m.step.flags ?? {}).flatMap(([f, q]) => (q.op === 'all' && !q.keys?.length ? [[`?${f}`, ts]] : [])));
475
+ let at = seed ?? Object.fromEntries(Object.entries(m.step.flags ?? {}).flatMap(([f, q]) => (q.op === 'all' && !q.keys?.length ? [[`?${f}`, ts]] : [])));
312
476
  const obligations = (i) => ptime('encode', () => countedObligations(m, ls, { [law.name]: i }, ls.indexOf(law)));
313
- const build = () => obligations(at).map(({ goal, decls }) => { const c = pass ? certFor(goal, decls) : none; return { goal, decls, c, gg: ptime('encode', () => mcGoal(goal.hyps, decls, c)) }; });
477
+ // (`wide`: the count instances widened once, where a model is left that the narrow ones and the laws don't refute, for
478
+ // a caller's law or where a read is in none of them: the cone's many refuted candidates keep the narrow ones)
479
+ let wide = false;
480
+ const isCaller = houdini && caller.some(l => l.name === law.name);
481
+ // (lazy (CEGAR): the goal carries the counting lemma's instances and picks some model of it broke, of all certFor
482
+ // proposes: each model read against the rest, as a state, and those it breaks added, until a model breaks none; an
483
+ // instance by the reads it names, a pick by its read and terms, so the choice outlives the goal's rebuilds)
484
+ const chosen = new Set();
485
+ const build = () => obligations(at).map(({ goal, decls }) => {
486
+ const full = pass ? certFor(goal, decls, wide, wide && lazyMode !== '0' ? pool : undefined) : none;
487
+ if (!pass || lazyMode === '0' || (lazyMode === 'wide' && !wide))
488
+ return { goal, decls, c: full, gg: ptime('encode', () => mcGoal(goal.hyps, decls, full)), pool: undefined };
489
+ const rd = new Map(full.reads.map(r => [r[0], json([r[1], r[2]])]));
490
+ const keys = [...full.picks.map(q => `p${json([rd.get(q[0]), q[1]])}`), ...full.insts.map(i => `i${json([i.terms.map(([z, x]) => [z, rd.get(x)]), i.unit, i.below])}`)];
491
+ if (lazyMode === 'wide')
492
+ for (const q of keys.slice(full.picks.length, full.picks.length + 10))
493
+ chosen.add(q);
494
+ const c = { ...full, picks: full.picks.filter((_, j) => chosen.has(keys[j])), insts: full.insts.filter((_, j) => chosen.has(keys[j + full.picks.length])) };
495
+ const fg = ptime('encode', () => mcGoal(goal.hyps, decls, full));
496
+ return { goal, decls, c, gg: ptime('encode', () => mcGoal(goal.hyps, decls, c)), pool: fg && keys.length ? { fg, keys, wits: [...full.picks.map(() => undefined), ...full.insts.map(i => i.wit)] } : undefined };
497
+ });
498
+ // (the pool's hypotheses a model breaks, chosen; whether there were any)
499
+ // (`strict`, where nothing else is broken or asked: the cells it leaves out at their start alone, as a model whose
500
+ // completion meets an instance may still meet it only at a witness some law then breaks)
501
+ const breaks = (b, w, strict = false) => ptime('lazy', () => {
502
+ if (!b?.pool)
503
+ return false;
504
+ // (broken where no completion of the model meets it: the cells it leaves out at their start, at 1, or one map's
505
+ // flipped from either, and an instance's witness at each value below 16)
506
+ const { fg, keys, wits } = b.pool, base = fg.hyps.length - keys.length, ids = keys.flatMap((q, j) => (chosen.has(q) ? [] : [base + j])), judge = brokenOf(fg);
507
+ let bad = ids.length ? judge(w, ids) : [];
508
+ const mps = [...new Set(bad.flatMap(i => [...reads(fg.hyps[i], () => true).values()].map(([mp]) => mp)))], one1 = Object.fromEntries(mps.map(mp => [mp, 1]));
509
+ for (const d of strict ? [undefined] : [undefined, one1, ...mps.map(mp => ({ [mp]: 1 })), ...mps.map(mp => ({ ...one1, [mp]: 0 }))])
510
+ for (let x = 0; x < 16 && bad.length; x++) {
511
+ if (x && !bad.some(i => wits[i - base]))
512
+ break;
513
+ const w2 = { ...w };
514
+ for (const i of bad)
515
+ if (wits[i - base])
516
+ w2[wits[i - base]] = x;
517
+ const still = new Set(judge(w2, bad, false, d));
518
+ bad = bad.filter(i => still.has(i));
519
+ }
520
+ for (const i of bad)
521
+ chosen.add(keys[i - base]);
522
+ tally('#lazy', bad.length);
523
+ return bad.length > 0;
524
+ });
314
525
  let built = build();
526
+ let decideStep = decisions.get(id);
527
+ if (!decideStep) {
528
+ if (decisions.size >= 64)
529
+ decisions.delete(decisions.keys().next().value);
530
+ decisions.set(id, (decideStep = modelSequence()));
531
+ }
315
532
  const t0 = clock(), more = () => clock() - t0 <= Math.max(ms, 1_000);
316
533
  // The step goal decided first by the CDCL search for a model (its phases the simplex's point: a model is met where the
317
534
  // tree search would split on), within 2·ms (5 s at most):
@@ -328,7 +545,7 @@ function searchCounted0(m0, caller, ms = 60_000) {
328
545
  const step = built.at(-1);
329
546
  if (!step?.gg)
330
547
  break;
331
- const q = ptime('decide', () => growCdcl(step.gg, new Map(), { nodes: 0, until: Math.min(until, clock() + Math.min(2 * ms, 5_000)) }, { model: true, core: true }));
548
+ const q = ptime('decide', () => decideStep(step.gg, Math.min(until, clock() + Math.min(2 * ms, 5_000))));
332
549
  if (!('tree' in q) && q.why === REFUTED && q.core) {
333
550
  const gg = step.gg, last = gg.hyps.length - 1, used = new Set(q.core.map(h => json(gg.hyps[h]))), cut = {};
334
551
  for (const [name, ts2] of Object.entries(at)) {
@@ -336,7 +553,7 @@ function searchCounted0(m0, caller, ms = 60_000) {
336
553
  cut[name] = !l ? ts2 : Array.from({ length: ts2.length / n }, (_, t) => ts2.slice(t * n, t * n + n)).filter(t => used.has(json(assumed([l], { [name]: t })[0]))).flat();
337
554
  }
338
555
  at = cut;
339
- built = obligations(at).map(({ goal, decls }, j) => ({ goal, decls, c: built[j].c, gg: mcGoal(goal.hyps, decls, built[j].c) }));
556
+ built = obligations(at).map(({ goal, decls }, j) => ({ goal, decls, c: built[j].c, gg: mcGoal(goal.hyps, decls, built[j].c), pool: built[j].pool }));
340
557
  part = { gg: built.at(-1).gg, core: { name: gg.name, hyps: (q.core.includes(last) ? q.core : [...q.core, last]).map(h => gg.hyps[h]) } };
341
558
  break;
342
559
  }
@@ -344,12 +561,24 @@ function searchCounted0(m0, caller, ms = 60_000) {
344
561
  break;
345
562
  if (!more())
346
563
  return { stuck: 'unknown' };
347
- const asked = ptime('mbqi', () => modelInstances(m, ls, at, step.gg, q.witness));
564
+ const asked = ptime('mbqi', () => modelInstances(m, ls, at, step.gg, q.witness)), lz = breaks(step, q.witness) || (!asked && breaks(step, q.witness, true));
565
+ tally('#rounds');
566
+ tally('#hyps', step.gg.hyps.length);
567
+ if (lz && !asked) {
568
+ built = build();
569
+ continue;
570
+ }
348
571
  if (!asked) {
349
572
  if (countsDump.on && pass && dumped < Number(env.GDP_COUNTS_DUMP_N ?? 3)) {
350
573
  dumped++;
351
574
  countsDump.on({ law: law.name, goal: step.goal.name, ls: ls.map(l => l.name), stuck: 'sat', witness: q.witness, reads: step.c.reads, insts: step.c.insts, hyps: step.gg.hyps });
352
575
  }
576
+ if (pass && !wide && houdini && 'loose' in step.c && (step.c.loose || isCaller) && more()) {
577
+ wide = true;
578
+ widened.add(law.name);
579
+ built = build();
580
+ continue;
581
+ }
353
582
  return refuted(step.gg, q.witness);
354
583
  }
355
584
  at = asked;
@@ -370,71 +599,89 @@ function searchCounted0(m0, caller, ms = 60_000) {
370
599
  dumped++;
371
600
  countsDump.on({ law: law.name, goal: goal.name, ls: ls.map(l => l.name), stuck: o.stuck, hyps: gg.hyps });
372
601
  }
373
- if (env.GDP_COUNTS_TRACE === '2')
374
- console.error(`counts: ${ls.length === 1 ? 'alone' : `with ${ls.length}`} ${pass} ${goal.name}: ${o && 'tree' in o ? 'proven' : gg ? o.stuck : 'no read'} ${gg?.hyps.length ?? 0} hyps ${Math.round(clock() - t0)} ms`);
602
+ if (env.GDP_COUNTS_TRACE?.includes('2'))
603
+ console.error(`counts: ${ls.length === 1 ? 'alone' : `with ${ls.length}`} ${pass} ${goal.name}: ${o && 'tree' in o ? 'proven' : gg ? o.stuck : 'no read'} ${gg?.hyps.length ?? 0} hyps (insts ${'insts' in c ? c.insts.length : 0} picks ${'picks' in c ? c.picks.length : 0}${wide ? ' wide' : ''}${built.find(b => b.gg === gg)?.pool ? ` of ${built.find(b => b.gg === gg).pool.keys.length}` : ''}) ${Math.round(clock() - t0)} ms`);
375
604
  // (the tree search's model of the step goal: the instances it asks for, as the CDCL search's, and the goals again)
376
605
  if (gg && o && !('tree' in o) && o.stuck === 'sat' && o.witness && gg === built.at(-1).gg && more()) {
377
- const asked = ptime('mbqi', () => modelInstances(m, ls, at, gg, o.witness));
378
- if (asked) {
379
- at = asked;
606
+ const asked = ptime('mbqi', () => modelInstances(m, ls, at, gg, o.witness)), lz = breaks(built.at(-1), o.witness) || (!asked && breaks(built.at(-1), o.witness, true));
607
+ if (asked || lz) {
608
+ if (asked)
609
+ at = asked;
380
610
  built = build();
381
611
  again = true;
382
612
  break;
383
613
  }
384
614
  }
615
+ if (gg && o && !('tree' in o) && o.stuck === 'sat' && o.witness && gg === built.at(-1).gg && pass && !wide && houdini && 'loose' in c && (c.loose || isCaller) && more()) {
616
+ wide = true;
617
+ widened.add(law.name);
618
+ built = build();
619
+ again = true;
620
+ break;
621
+ }
385
622
  if (gg && o && !('tree' in o) && o.stuck === 'sat' && o.witness && gg === built.at(-1).gg)
386
623
  return refuted(gg, o.witness);
387
624
  if (!o || !('tree' in o))
388
625
  return { stuck: gg ? o.stuck ?? '' : '' };
389
- certs[goal.name] = { reads: c.reads, insts: c.insts, tree: o.tree };
626
+ certs[goal.name] = { reads: c.reads, insts: c.insts, tree: o.tree, ...('picks' in c && c.picks.length ? { picks: c.picks } : {}) };
390
627
  }
391
628
  if (!again)
392
629
  return { proof: { instances: at, certs } };
393
630
  }
394
631
  };
395
632
  const traced = (law, ls, pass, ms) => {
396
- const t0 = clock(), r = attempt(law, ls, pass, ms);
397
- if (env.GDP_COUNTS_TRACE === '3')
398
- console.error(`counts: try ${law.name.slice(0, 50)} | ls ${ls.length} pass ${pass} ms ${ms} took ${Math.round(clock() - t0)} -> ${'proof' in r ? 'kept' : r.stuck}`);
633
+ const t0 = clock(), w0 = performance.now(), p0 = { ...cprof }, r = attempt(law, ls, pass, ms);
634
+ if (env.GDP_COUNTS_TRACE?.includes('3'))
635
+ console.error(`counts: try ${law.name.slice(0, 50)} | ls ${ls.length} pass ${pass} ms ${Math.round(ms)} took ${Math.round(clock() - t0)} wall ${Math.round(performance.now() - w0)} [${Object.entries(cprof).filter(([k2, x]) => x - (p0[k2] ?? 0) >= 1).map(([k2, x]) => `${k2} ${Math.round(x - (p0[k2] ?? 0))}`).join(' ')}] -> ${'proof' in r ? 'kept' : r.stuck}`);
399
636
  return r;
400
637
  };
401
- // The cone (a law about no key is assumed in every goal, so with one in the set nothing is kept); with every caller
402
- // kept, the kept laws are the proof; else Houdini over the whole set, the kept laws' proofs reused.
403
- const kept = set.every(l => l.forall) ? cone(m, set, (law, ls, ms2) => traced(law, ls, 1, ms2), until) : new Map();
404
- if (env.GDP_COUNTS_TRACE)
405
- console.error(`counts: kept ${kept.size} of ${set.length} in ${Math.round(clock() - t1)} ms`);
638
+ // Prove the proposed set together. A preliminary cone reproved many helpers in
639
+ // several smaller contexts before asking these same induction goals. Houdini
640
+ // drops failed helpers and carries proofs whose instantiated support survives.
641
+ // Every returned set still passes checkCountedLaws, including all caller laws.
406
642
  const finish = (ls, proof) => (ptime('kernel', () => checkCountedLaws(m, ls, proof)) ? { proven: true, laws: ls, m, proof } : { proven: false, laws: ls, m, why: 'the kernel refused the set' });
407
- const keptProof = () => ({ instances: Object.fromEntries([...kept].map(([n, pr]) => [n, pr.instances])), certs: Object.assign({}, ...[...kept.values()].map(pr => pr.certs)) });
408
- if (caller.every(l => kept.has(l.name)))
409
- return finish(set.filter(l => kept.has(l.name)), keptProof());
410
- // (each law not kept an even share of what is left a round)
411
- for (let round = 0; clock() < until; round++) {
412
- const { instances, certs } = keptProof(), failed = new Set(), share = (until - clock()) / Math.max(1, set.filter(l => !kept.has(l.name)).length);
413
- // (the callers last, so they meet every support kept so far)
414
- for (const law of [...set.filter(l => !caller.includes(l)), ...set.filter(l => caller.includes(l))]) {
415
- if (clock() > until)
416
- return { proven: false, laws: set, m, why: 'time' };
417
- if (kept.has(law.name))
418
- continue;
419
- let r = traced(law, set, 0, share);
420
- if (!('proof' in r) && counted)
421
- r = traced(law, set, 1, share);
422
- if (!('proof' in r)) {
423
- failed.add(law.name);
424
- continue;
643
+ const join = (kept = new Map()) => {
644
+ const keptProof = () => ({ instances: Object.fromEntries([...kept].map(([n, pr]) => [n, pr.instances])), certs: Object.assign({}, ...[...kept.values()].map(pr => pr.certs)) });
645
+ if (caller.every(l => kept.has(l.name)))
646
+ return finish(set.filter(l => kept.has(l.name)), keptProof());
647
+ // (each law without a carried proof an even share of what is left a round)
648
+ let carried = new Map();
649
+ houdini = true;
650
+ for (let round = 0; clock() < until; round++) {
651
+ const { instances, certs } = keptProof();
652
+ const failed = new Set(), proofs = new Map(), share = (until - clock()) / Math.max(1, set.filter(l => !kept.has(l.name) && !carried.has(l.name)).length);
653
+ // (the callers last, so they meet every support kept so far)
654
+ for (const law of [...set.filter(l => !caller.includes(l)), ...set.filter(l => caller.includes(l))]) {
655
+ if (clock() > until)
656
+ return { proven: false, laws: set, m, why: 'time' };
657
+ if (kept.has(law.name))
658
+ continue;
659
+ const was = carried.get(law.name);
660
+ let r = was ? { proof: was } : traced(law, set, 0, share);
661
+ if (!('proof' in r) && counted)
662
+ r = traced(law, set, 1, share);
663
+ if (!('proof' in r)) {
664
+ failed.add(law.name);
665
+ continue;
666
+ }
667
+ proofs.set(law.name, r.proof);
668
+ instances[law.name] = r.proof.instances;
669
+ Object.assign(certs, r.proof.certs);
425
670
  }
426
- instances[law.name] = r.proof.instances;
427
- Object.assign(certs, r.proof.certs);
671
+ if (env.GDP_COUNTS_TRACE)
672
+ console.error(`counts: round ${round}: ${set.length} laws, ${kept.size} kept, ${carried.size} carried, failed ${[...failed].join('; ').slice(0, 600)}`);
673
+ if (!failed.size)
674
+ return finish(set, { instances, certs });
675
+ const next = set.filter(l => !failed.has(l.name) || caller.includes(l));
676
+ // (only callers fail: drop nothing more, give up)
677
+ if (next.length === set.length)
678
+ return { proven: false, laws: set, m, why: `not proven: ${[...failed].join(', ')}` };
679
+ // (a proof that assumes no law dropped at any key is one over the rest: its goals are the same; the kernel checks all)
680
+ const dropped = set.filter(l => !next.includes(l));
681
+ carried = new Map([...proofs].filter(([, pr]) => dropped.every(d => d.forall && !pr.instances[d.name]?.length)));
682
+ set = next;
428
683
  }
429
- if (env.GDP_COUNTS_TRACE)
430
- console.error(`counts: round ${round}: ${set.length} laws, ${kept.size} kept, failed ${[...failed].join('; ').slice(0, 600)}`);
431
- if (!failed.size)
432
- return finish(set, { instances, certs });
433
- const next = set.filter(l => !failed.has(l.name) || caller.includes(l));
434
- // (only callers fail: drop nothing more, give up)
435
- if (next.length === set.length)
436
- return { proven: false, laws: set, m, why: `not proven: ${[...failed].join(', ')}` };
437
- set = next;
438
- }
439
- return { proven: false, laws: set, m, why: 'time' };
684
+ return { proven: false, laws: set, m, why: 'time' };
685
+ };
686
+ return join();
440
687
  }