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
@@ -7,7 +7,7 @@
7
7
  // at every k steps in a row the run takes: each step's `when` read with the state it starts from, its request, queries
8
8
  // and flags; `then` with the state before the first step (plain names), the first request and its flags, the j-th
9
9
  // request as input@j, and the state and maps after the last step (primed names).
10
- import { carriedView, evalC, numbersOf, walk } from "./machine.js";
10
+ import { carriedView, evalC, evalE, numbersOf, walk } from "./machine.js";
11
11
  import { someHolds } from "./exists.js";
12
12
  export const isStepLaw = (w) => 'then' in w;
13
13
  // A request's environment: the params, its inputs and queries, and the step's flags decided (as ?name).
@@ -77,6 +77,43 @@ function keysPer(c, names) {
77
77
  return [...vals];
78
78
  });
79
79
  }
80
+ // A key no map reads, scaled and compared linearly with what the run holds (c·k ⋈ t, c >= 16: a time's week,
81
+ // core/calendar.ts), is read
82
+ // where that comparison turns too: ⌊t/c⌋ and the keys beside it, each later key 0 while it is solved. Untrusted: more
83
+ // keys read is only more of the law checked.
84
+ function turns(c, names) {
85
+ const atoms = [];
86
+ walk(c, o => {
87
+ if (o.op !== '<' && o.op !== '<=' && o.op !== '=')
88
+ return;
89
+ // (a key scaled past the small keys a run reads, k·x with k at least 16: its turn is far from 0 to bound + 1)
90
+ const t = JSON.stringify(o), reads = new Set(names.filter(x => [...t.matchAll(new RegExp(`"op":"mul","k":(\\d+),"a":\\{"op":"var","name":${JSON.stringify(x).replace(/[$]/g, '\\$&')}\\}`, 'g'))].some(m => Number(m[1]) >= 16)));
91
+ if (reads.size)
92
+ atoms.push({ a: o.a, b: o.b, reads });
93
+ });
94
+ return (i, env, st, m) => {
95
+ const x = names[i], out = new Set(), saved = names.slice(i).map(y => env[y]);
96
+ for (let j = i + 1; j < names.length; j++)
97
+ env[names[j]] = 0;
98
+ for (const at of atoms) {
99
+ if (!at.reads.has(x))
100
+ continue;
101
+ try {
102
+ const f = (v) => { env[x] = v; return evalE(at.a, env, st, m) - evalE(at.b, env, st, m); };
103
+ const f0 = f(0), slope = f(1) - f0;
104
+ if (slope) {
105
+ const k = Math.floor(-f0 / slope);
106
+ for (const v of [k - 1, k, k + 1])
107
+ if (v >= 0 && Number.isSafeInteger(v))
108
+ out.add(v);
109
+ }
110
+ }
111
+ catch { /* (a value the run doesn't hold: no turn) */ }
112
+ }
113
+ names.slice(i).forEach((y, j) => { env[y] = saved[j]; });
114
+ return [...out];
115
+ };
116
+ }
80
117
  // The tuples every watch has read a law at (core/dsl.ts's refuteByRuns counts its budget in them).
81
118
  export const watchWork = { n: 0 };
82
119
  // Watches one law or step law along one run: `start` with the state at the start, `step` after each step the run takes
@@ -84,13 +121,21 @@ export const watchWork = { n: 0 };
84
121
  export function watch(m, run, w, params, bound) {
85
122
  // At every tuple of the keys (each name's own: keysPer), one key per name, in one environment set in place.
86
123
  const names = w.forall ? [w.forall, ...(w.keys ?? [])] : [], per = keysPer(isStepLaw(w) ? w.then : w.holds, names);
87
- const atKeys = (keys, env, f) => {
124
+ // (the keys no map reads, also where a comparison of theirs turns)
125
+ const mapRead = new Set();
126
+ walk(isStepLaw(w) ? w.then : w.holds, o => { if (o.op === 'get')
127
+ for (const x of names)
128
+ if (JSON.stringify(o.key).includes(`"name":${JSON.stringify(x)}`))
129
+ mapRead.add(x); });
130
+ const turn = names.some(x => !mapRead.has(x)) ? turns(isStepLaw(w) ? w.then : w.holds, names) : undefined;
131
+ const atKeys = (keys, env, f, st, mm) => {
88
132
  const go = (i) => {
89
133
  if (i === names.length) {
90
134
  watchWork.n++;
91
135
  return f(env);
92
136
  }
93
- for (const key of keys[i]) {
137
+ const more = turn && st && mm && !mapRead.has(names[i]) ? turn(i, env, st, mm).filter(k => !keys[i].includes(k)) : [];
138
+ for (const key of more.length ? [...keys[i], ...more] : keys[i]) {
94
139
  env[names[i]] = key;
95
140
  if (!go(i + 1))
96
141
  return false;
@@ -102,8 +147,8 @@ export function watch(m, run, w, params, bound) {
102
147
  if (!isStepLaw(w)) {
103
148
  // A law with "there exists" (core/exists.ts): broken only where no value can be a witness, as far as that is decided
104
149
  // (one natural or integer read linearly); undecided, it is kept.
105
- const at = (env, st) => (w.some?.length ? someHolds(w.holds, w.some, { ...env }, st, m)?.holds ?? true : evalC(w.holds, env, st, m));
106
- const holds = (st) => atKeys(per(bound, st, () => keysOf(bound, st)), { ...params }, env => at(env, st));
150
+ const at = (env, st) => (w.some?.length ? someHolds(w.holds, w.some, { ...env }, st, m, true)?.holds ?? true : evalC(w.holds, env, st, m));
151
+ const holds = (st) => atKeys(per(bound, st, () => keysOf(bound, st)), { ...params }, env => at(env, st), st, m);
107
152
  return { start: holds, step: (_before, _input, after) => holds(after) };
108
153
  }
109
154
  const k = w.steps ?? 1, whens = w.when === undefined ? [] : Array.isArray(w.when) ? w.when : [w.when];
@@ -132,7 +177,7 @@ export function watch(m, run, w, params, bound) {
132
177
  maps: { ...first.maps, ...Object.fromEntries(Object.entries(after.maps).map(([n, cells]) => [`${n}'`, cells])) },
133
178
  defaults: { ...first.defaults, ...Object.fromEntries(Object.entries(after.defaults ?? {}).map(([n, d]) => [`${n}'`, d])) },
134
179
  };
135
- return atKeys(per(bound, both, () => keysOf(bound, first, after)), { ...env }, e => evalC(w.then, e, both, primedMaps));
180
+ return atKeys(per(bound, both, () => keysOf(bound, first, after)), { ...env }, e => evalC(w.then, e, both, primedMaps), both, primedMaps);
136
181
  },
137
182
  };
138
183
  }
@@ -5,7 +5,7 @@
5
5
  // loops (loopObligations), folds (foldObligations), progress (progressObligations), liveness (livenessParts, then
6
6
  // checkStepLaws). Around them, untrusted: reading the document (format.ts) and the guard that it was read faithfully
7
7
  // (written again, it must be the document read).
8
- import { check, checkKInduction, checkLaws, checkQMachine, checkQTree, checkRecur, checkStepLaws, foldObligations, kInductionStart, kInductionSteps, livenessParts, loopObligations, obligations, progressObligations, qObligations, recurGoal, stepLawObligations } from "../kernel/kernel.js";
8
+ import { check, checkKInduction, checkLaws, checkQMachine, checkQTree, checkRecur, checkStepLaws, foldObligations, kInductionStart, kInductionSteps, livenessParts, loopObligations, obligations, own, progressObligations, qObligations, recurGoal, stepLawObligations } from "../kernel/kernel.js";
9
9
  import { descentGoal, mainGoal, premiseGoal, refuseCyclic } from "../kernel/cyclic.js";
10
10
  import { FormatError, fromInterchange, resolved, sameJson, toInterchange } from "./format.js";
11
11
  const attempt = (f) => { try {
@@ -14,11 +14,11 @@ const attempt = (f) => { try {
14
14
  catch (e) {
15
15
  return { ok: false, why: e instanceof Error ? e.message : String(e) };
16
16
  } };
17
- const treeOk = (g, trees) => trees[g.name] !== undefined && check(g, trees[g.name]);
17
+ const treeOk = (g, trees) => { const t = own(trees, g.name); return t !== undefined && check(g, t); };
18
18
  // Each goal's own answer, for a refusal's why (never the verdict: that is the kernel's entry point's).
19
19
  const failing = (goals, trees) => {
20
20
  try {
21
- const bad = goals().filter(g => !treeOk(g, trees)).map(g => (trees[g.name] ? `${g.name}: its tree doesn't refute it` : `${g.name}: no tree`));
21
+ const bad = goals().filter(g => !treeOk(g, trees)).map(g => (own(trees, g.name) ? `${g.name}: its tree doesn't refute it` : `${g.name}: no tree`));
22
22
  return bad.length ? bad.slice(0, 3).join('; ') + (bad.length > 3 ? `; and ${bad.length - 3} more` : '') : undefined;
23
23
  }
24
24
  catch (e) {
@@ -38,13 +38,13 @@ export function checkCertificate(c) {
38
38
  case 'qgoals': return c.goals.map(g => { const r = attempt(() => checkQTree(g.goal, g.tree)); return { name: g.goal.name, accepted: r.ok, ...(r.ok ? {} : { why: r.why ?? 'the tree doesn\'t refute the goal' }) }; });
39
39
  // A set of laws is proven together (each step assumes them all), so each is accepted exactly when the set is.
40
40
  case 'laws': return all(c.laws.map(l => l.name), attempt(() => checkLaws(c.machine, c.laws, c.proof)), () => failing(() => obligations(c.machine, c.laws, c.proof.instances), c.proof.trees));
41
- case 'stepLaws': return all([...c.laws.map(l => l.name), ...c.stepLaws.map(s => s.name)], attempt(() => checkStepLaws(c.machine, c.laws, c.stepLaws, c.proof)), () => failing(() => [...obligations(c.machine, c.laws, c.proof.laws.instances), ...c.stepLaws.flatMap(s => stepLawObligations(c.machine, c.laws, c.proof.perStep?.[s.name] ?? c.proof.instances, s))], { ...c.proof.laws.trees, ...c.proof.trees })
41
+ case 'stepLaws': return all([...c.laws.map(l => l.name), ...c.stepLaws.map(s => s.name)], attempt(() => checkStepLaws(c.machine, c.laws, c.stepLaws, c.proof)), () => failing(() => [...obligations(c.machine, c.laws, c.proof.laws.instances), ...c.stepLaws.flatMap(s => stepLawObligations(c.machine, c.laws, own(c.proof.perStep ?? {}, s.name) ?? c.proof.instances, s))], { ...c.proof.laws.trees, ...c.proof.trees })
42
42
  ?? 'a later step\'s names read before it (the zone condition)');
43
- case 'kInduction': return all([c.kInduction.law.name], attempt(() => checkKInduction(c.machine, c.laws, c.kInduction, c.proof)), () => failing(() => [kInductionStart(c.machine, c.kInduction, c.proof.perStep?.[`${c.kInduction.law.name} @start`] ?? c.proof.instances), ...kInductionSteps(c.machine, c.kInduction).flatMap(s => stepLawObligations(c.machine, c.laws, c.proof.perStep?.[s.name] ?? c.proof.instances, s))], c.proof.trees)
43
+ case 'kInduction': return all([c.kInduction.law.name], attempt(() => checkKInduction(c.machine, c.laws, c.kInduction, c.proof)), () => failing(() => [kInductionStart(c.machine, c.kInduction, own(c.proof.perStep ?? {}, `${c.kInduction.law.name} @start`) ?? c.proof.instances), ...kInductionSteps(c.machine, c.kInduction).flatMap(s => stepLawObligations(c.machine, c.laws, own(c.proof.perStep ?? {}, s.name) ?? c.proof.instances, s))], c.proof.trees)
44
44
  ?? failing(() => obligations(c.machine, c.laws, c.proof.laws.instances), c.proof.laws.trees));
45
45
  case 'liveness': {
46
46
  const r = attempt(() => { const { stay, cover, helps } = livenessParts(c.machine, c.liveness); return checkStepLaws(c.machine, c.laws, [stay, cover, ...helps], c.proof); });
47
- return all([c.liveness.name], r, () => failing(() => { const { stay, cover, helps } = livenessParts(c.machine, c.liveness); return [stay, cover, ...helps].flatMap(s => stepLawObligations(c.machine, c.laws, c.proof.perStep?.[s.name] ?? c.proof.instances, s)); }, c.proof.trees));
47
+ return all([c.liveness.name], r, () => failing(() => { const { stay, cover, helps } = livenessParts(c.machine, c.liveness); return [stay, cover, ...helps].flatMap(s => stepLawObligations(c.machine, c.laws, own(c.proof.perStep ?? {}, s.name) ?? c.proof.instances, s)); }, c.proof.trees));
48
48
  }
49
49
  // Progress assumes the laws: proven here by their own trees where the document has them, else not accepted.
50
50
  case 'progress': {
@@ -86,16 +86,16 @@ export function checkDocument(doc) {
86
86
  // check, as a `goals` (or `qgoals`) certificate a second checker reads (interchange/py/check.py checks trees alone).
87
87
  // (The checks past trees stay the kernel's: a stem evaluated, a cyclic proof's ranks of one length, the step laws' zone.)
88
88
  export function goalsOf(c) {
89
- const pick = (goals, trees) => goals.flatMap(goal => (trees[goal.name] ? [{ goal, tree: trees[goal.name] }] : []));
89
+ const pick = (goals, trees) => goals.flatMap(goal => { const tree = own(trees, goal.name); return tree ? [{ goal, tree }] : []; });
90
90
  const cyclic = (p) => p.nodes.flatMap(n => [{ goal: mainGoal(p.facts, p.nodes, n), tree: n.main }, ...n.uses.flatMap(u => {
91
91
  const m = p.nodes[u.node];
92
92
  return m ? [...m.hyps.flatMap((h, i) => (u.premises[i] ? [{ goal: premiseGoal(p.facts, n, u, h, i), tree: u.premises[i] }] : [])), ...(m.rank.length === n.rank.length ? [{ goal: descentGoal(p.facts, n, u, m), tree: u.descent }] : [])] : [];
93
93
  })]);
94
- const steps = (m, sls) => [...pick(obligations(m.machine, m.laws, m.proof.laws.instances), m.proof.laws.trees), ...pick(sls.flatMap(s => stepLawObligations(m.machine, m.laws, m.proof.perStep?.[s.name] ?? m.proof.instances, s)), m.proof.trees)];
94
+ const steps = (m, sls) => [...pick(obligations(m.machine, m.laws, m.proof.laws.instances), m.proof.laws.trees), ...pick(sls.flatMap(s => stepLawObligations(m.machine, m.laws, own(m.proof.perStep ?? {}, s.name) ?? m.proof.instances, s)), m.proof.trees)];
95
95
  switch (c.kind) {
96
96
  case 'goals':
97
97
  case 'qgoals': return c;
98
- case 'qmachine': return { kind: 'qgoals', goals: c.laws.flatMap(l => { const g = qObligations(c.machine, c.laws, l), t = c.trees[l.name]; return t ? [{ goal: g.start, tree: t.start }, { goal: g.step, tree: t.step }] : []; }) };
98
+ case 'qmachine': return { kind: 'qgoals', goals: c.laws.flatMap(l => { const g = qObligations(c.machine, c.laws, l), t = own(c.trees, l.name); return t ? [{ goal: g.start, tree: t.start }, { goal: g.step, tree: t.step }] : []; }) };
99
99
  case 'laws': return { kind: 'goals', goals: pick(obligations(c.machine, c.laws, c.proof.instances), c.proof.trees) };
100
100
  case 'stepLaws': return { kind: 'goals', goals: steps(c, c.stepLaws) };
101
101
  case 'liveness': {
@@ -103,7 +103,7 @@ export function goalsOf(c) {
103
103
  return { kind: 'goals', goals: steps(c, [stay, cover, ...helps]) };
104
104
  }
105
105
  case 'kInduction': {
106
- const start = kInductionStart(c.machine, c.kInduction, c.proof.perStep?.[`${c.kInduction.law.name} @start`] ?? c.proof.instances);
106
+ const start = kInductionStart(c.machine, c.kInduction, own(c.proof.perStep ?? {}, `${c.kInduction.law.name} @start`) ?? c.proof.instances);
107
107
  return { kind: 'goals', goals: [...pick([start], c.proof.trees), ...steps(c, kInductionSteps(c.machine, c.kInduction))] };
108
108
  }
109
109
  case 'progress': return { kind: 'goals', goals: [...(c.lawsProof ? pick(obligations(c.machine, c.laws, c.lawsProof.instances), c.lawsProof.trees) : []), ...pick(progressObligations(c.machine, c.laws, c.instances, c.progress), c.trees)] };
@@ -23,6 +23,10 @@ export type Measure = {
23
23
  comps: {
24
24
  coef: number[];
25
25
  c: number;
26
+ fold?: {
27
+ fn: string;
28
+ of: number;
29
+ };
26
30
  }[];
27
31
  };
28
32
  export type Obligation = {
@@ -1,6 +1,7 @@
1
1
  import { canon, columnTerm, factorsOf, isCell, isMonomial, termColumn } from "../kernel/kernel.js";
2
- // 1.1 adds a liveness's fairness and levels (strong fairness, Live.lean's sleads_sound): a document is written at the
3
- // lowest version that holds it (1.0 unless a liveness is strong or has levels), and read at either.
2
+ // 1.1 adds a liveness's fairness and levels (strong fairness, Live.lean's sleads_sf_soundA) and a measure part's fold (a
3
+ // fold function's value at a parameter, core/data.ts's Measure): a document is written at the lowest version that holds
4
+ // it (1.0 unless it has one of these), and read at either.
4
5
  export const FORMAT = 'gdp-wired-interchange', VERSION = '1.1', VERSIONS = ['1.0', '1.1'];
5
6
  export const KINDS = ['goals', 'laws', 'stepLaws', 'kInduction', 'progress', 'liveness', 'loop', 'recur', 'fold', 'cyclic', 'qgoals', 'qmachine', 'termination'];
6
7
  // Why a value is outside the format: where, and what.
@@ -69,6 +70,8 @@ export function encE(e, at = 'term') {
69
70
  case 'mul': return { op: e.op, k: nat(e.k, `${at}.k`), a: encE(e.a, `${at}.a`) };
70
71
  case 'if': return { op: e.op, c: encC(e.c, `${at}.c`), then: encE(e.then, `${at}.then`), else: encE(e.else, `${at}.else`) };
71
72
  case 'get': return { op: e.op, map: name(e.map, `${at}.map`), key: encE(e.key, `${at}.key`) };
73
+ case 'tup':
74
+ case 'proj': return fail(at, 'tuple terms are not supported by interchange 1.1');
72
75
  default: return fail(at, `no term op ${JSON.stringify(e.op)}`);
73
76
  }
74
77
  }
@@ -99,6 +102,8 @@ export function decE(x, at = 'term') {
99
102
  case 'get':
100
103
  obj(o, at, ['op', 'map', 'key']);
101
104
  return { op: 'get', map: name(o.map, `${at}.map`), key: decE(o.key, `${at}.key`) };
105
+ case 'tup':
106
+ case 'proj': return fail(at, 'tuple terms are not supported by interchange 1.1');
102
107
  default: return fail(at, `no term op ${JSON.stringify(o.op ?? null)}`);
103
108
  }
104
109
  }
@@ -266,6 +271,9 @@ function encAtom(key, cols, at) {
266
271
  return { mono: factorsOf(key).map((f, i) => encAtom(f, cols, `${at}.mono[${i}]`)) };
267
272
  if (isCell(key)) {
268
273
  const map = key.slice(0, key.indexOf('[')), inner = key.slice(key.indexOf('[') + 1, -1);
274
+ // Version 1.1 has one linear key, not the native tuple's list of linear parts.
275
+ if (inner.startsWith('⟨'))
276
+ fail(at, 'tuple-keyed cells are not supported by interchange 1.1');
269
277
  // (a cell's name is the kernel's canon of its key: written back from the key read, it must be the same text)
270
278
  const lin = parseKey(inner);
271
279
  if (canon(lin) !== inner)
@@ -296,7 +304,10 @@ function decAtom(x, cols, at) {
296
304
  return [...fs].sort().join('*');
297
305
  }
298
306
  obj(o, at, ['cell', 'key']);
299
- return `${name(o.cell, `${at}.cell`)}[${canon(decLin(o.key, cols, `${at}.key`))}]`;
307
+ const key = canon(decLin(o.key, cols, `${at}.key`));
308
+ if (key.startsWith('⟨'))
309
+ fail(at, 'tuple-keyed cells are not supported by interchange 1.1');
310
+ return `${name(o.cell, `${at}.cell`)}[${key}]`;
300
311
  }
301
312
  export function encLin(lin, cols, at = 'row') {
302
313
  if (!isObj(lin))
@@ -561,10 +572,15 @@ const decRecur = (x, cols, at) => {
561
572
  const o = obj(x, at, ['start', 'stem', 'set', 'wit', 'tree']);
562
573
  return { start: record(o.start, nat, `${at}.start`), stem: arr(o.stem, `${at}.stem`).map((t, i) => record(t, nat, `${at}.stem[${i}]`)), set: decC(o.set, `${at}.set`), wit: record(o.wit, decE, `${at}.wit`), tree: decTree(o.tree, cols, `${at}.tree`) };
563
574
  };
564
- const encMeasure = (m, at) => ({ comps: arr(m.comps, `${at}.comps`).map((c, i) => { const q = c; return { coef: arr(q.coef, `${at}.comps[${i}].coef`).map((k, j) => int(k, `${at}.comps[${i}].coef[${j}]`)), c: int(q.c, `${at}.comps[${i}].c`) }; }) });
575
+ const encFoldPart = (f, at) => ({ fn: name(f.fn, `${at}.fn`), of: nat(f.of, `${at}.of`) });
576
+ const encMeasure = (m, at) => ({ comps: arr(m.comps, `${at}.comps`).map((c, i) => { const q = c; return clean({ coef: arr(q.coef, `${at}.comps[${i}].coef`).map((k, j) => int(k, `${at}.comps[${i}].coef[${j}]`)), c: int(q.c, `${at}.comps[${i}].c`), fold: q.fold && encFoldPart(q.fold, `${at}.comps[${i}].fold`) }); }) });
565
577
  const decMeasure = (x, at) => {
566
578
  const o = obj(x, at, ['comps']);
567
- return { comps: arr(o.comps, `${at}.comps`).map((c, i) => { const q = obj(c, `${at}.comps[${i}]`, ['coef', 'c']); return { coef: arr(q.coef, `${at}.comps[${i}].coef`).map((k, j) => int(k, `${at}.comps[${i}].coef[${j}]`)), c: int(q.c, `${at}.comps[${i}].c`) }; }) };
579
+ return { comps: arr(o.comps, `${at}.comps`).map((c, i) => {
580
+ const q = obj(c, `${at}.comps[${i}]`, ['coef', 'c'], ['fold']);
581
+ return clean({ coef: arr(q.coef, `${at}.comps[${i}].coef`).map((k, j) => int(k, `${at}.comps[${i}].coef[${j}]`)), c: int(q.c, `${at}.comps[${i}].c`),
582
+ fold: opt(q, 'fold', (y, a) => { const f = obj(y, a, ['fn', 'of']); return { fn: name(f.fn, `${a}.fn`), of: nat(f.of, `${a}.of`) }; }, `${at}.comps[${i}]`) });
583
+ }) };
568
584
  };
569
585
  // --- documents ---------------------------------------------------------------------------------------------------------------
570
586
  // The fields each kind has, in the order a document is written.
@@ -600,7 +616,7 @@ export function toInterchange(c, meta) {
600
616
  default: return fail('kind', `no kind ${JSON.stringify(c.kind)}`);
601
617
  }
602
618
  })();
603
- const v11 = c.kind === 'liveness' && (c.liveness.fairness !== undefined || c.liveness.levels !== undefined);
619
+ const v11 = (c.kind === 'liveness' && (c.liveness.fairness !== undefined || c.liveness.levels !== undefined)) || (c.kind === 'termination' && c.measures.some(m => m.comps.some(q => q.fold !== undefined)));
604
620
  return clean({ format: FORMAT, version: v11 ? '1.1' : '1.0', kind: c.kind, meta, columns: 'terms' in cols && cols.terms.length ? cols.terms : undefined, ...body });
605
621
  }
606
622
  // A document read back into the kernel's objects, or a FormatError saying where it leaves the format.
@@ -612,6 +628,8 @@ export function fromInterchange(doc) {
612
628
  fail('version', `one of ${VERSIONS.join(', ')} (this reader's)`);
613
629
  if (head.version === '1.0' && head.kind === 'liveness' && isObj(head.liveness) && ('fairness' in head.liveness || 'levels' in head.liveness))
614
630
  fail('liveness', 'no fairness or levels in a 1.0 document (1.1\'s)');
631
+ if (head.version === '1.0' && head.kind === 'termination' && JSON.stringify(head.measures ?? []).includes('"fold"'))
632
+ fail('measures', 'no fold in a 1.0 document (1.1\'s)');
615
633
  const kind = head.kind;
616
634
  if (!KINDS.includes(kind))
617
635
  fail('kind', `one of ${KINDS.join(', ')}`);
@@ -49,6 +49,10 @@ export declare const cdclStats: {
49
49
  lpLoad: number;
50
50
  nodes: number;
51
51
  boundRounds: number;
52
+ fmLeafMs: number;
53
+ fmOpenMs: number;
54
+ fastMs: number;
55
+ missMs: number;
52
56
  };
53
57
  export declare const REFUTED = "refuted, not unfolded";
54
58
  export type Refuted = Outcome & {
@@ -64,6 +68,7 @@ export type CdclOptions = {
64
68
  clausal?: boolean;
65
69
  sideOf?: (hyp: number) => number;
66
70
  quiet?: (name: string) => boolean;
71
+ point?: boolean;
67
72
  };
68
73
  export declare function growCdcl(goal: Goal, root: Path, budget: {
69
74
  nodes: number;
@@ -20,7 +20,7 @@
20
20
  import { costs, env, refuteFast, solve, work } from "../core/solver.js";
21
21
  import { checkRefutation } from "../core/check.js";
22
22
  import { atomOf, canon, canonFlip, isMonomial, leafConstraints } from "./kernel.js";
23
- import { atPoint, cellPair, late, leafRowsOf, logged, nearOf, openAt, pairedKeys, queryHook, rowsAt, unitAtoms } from "./prove.js";
23
+ import { atPoint, cellPair, tupleCellPairs, growWide, late, leafRowsOf, logged, nearOf, openAt, pairedKeys, queryHook, rowsAt, unitAtoms, wideFor, wideScope } from "./prove.js";
24
24
  import { Clausal, Reader, namesOf } from "./reader.js";
25
25
  import { Simplex } from "./simplex.js";
26
26
  // A derivation's own inputs: the rows it reads, in order, and the steps renumbered to them.
@@ -52,9 +52,10 @@ const keyOf = (lin) => {
52
52
  };
53
53
  // GDP_CDCL_LP=0: each node solved by elimination alone (no simplex); GDP_CDCL_FILL (8): the simplex's tableau begun
54
54
  // again past this many entries a row the node reads (research/step's comparisons).
55
+ const pointLeaf = env.GDP_CDCL_POINT !== '0';
55
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';
56
57
  // Counters research/step reads (times only while `on`).
57
- 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 };
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
59
  // `opts.model`: only whether the goal has a model is wanted (core/bmc.ts): a refutation isn't unfolded into a tree, its
59
60
  // outcome `unknown` with `why` REFUTED; each decision's phase is the simplex's point's (phaseAtPoint; in the tree search too
60
61
  // where prove.ts's `atPoint` is on); past `opts.wall` (wall time) the search stops as past its budget.
@@ -63,6 +64,12 @@ export const cdclStats = { on: false, runs: 0, proven: 0, conflicts: 0, decision
63
64
  // any value: the trail's atoms, the naturals, the term columns' definitions), as core/infer.ts's join reads it.
64
65
  export const REFUTED = 'refuted, not unfolded';
65
66
  export function growCdcl(goal, root, budget, opts = {}) {
67
+ // (a wide goal's model or refutation: over parts first, prove.ts's growWide)
68
+ if (opts.model && !opts.dag && !opts.clausal && !root.size && wideFor(goal)) {
69
+ const out = growWide(goal, budget, (g, until) => growCdcl(g, root, { nodes: 0, until }, opts));
70
+ if (out)
71
+ return out;
72
+ }
66
73
  const go = () => cdclSession(goal, root, opts).run(budget, opts.wall);
67
74
  return queryHook.on && !queryHook.depth ? logged(opts.model ? 'model' : 'cdcl', goal, go) : go();
68
75
  }
@@ -208,10 +215,20 @@ export function cdclSession(goal, root, opts = {}) {
208
215
  for (let j = i + 1; j < ns.length; j++) {
209
216
  let r = row.get(ns[j]);
210
217
  if (!r) {
211
- const pair = cellPair(ns[i], ns[j]);
212
- row.set(ns[j], (r = { d: pair.d, neg: pair.neg, mono: Object.keys(pair.d).some(isMonomial) }));
218
+ // (two tuple cells: a pair for each part, each split on as a plain key's difference is)
219
+ const parts = tupleCellPairs(ns[i], ns[j]);
220
+ if (parts)
221
+ r = parts.map(([d, neg]) => ({ d: d, neg: neg, mono: false }));
222
+ else {
223
+ const pair = cellPair(ns[i], ns[j]);
224
+ r = { d: pair.d, neg: pair.neg, mono: Object.keys(pair.d).some(isMonomial) };
225
+ }
226
+ row.set(ns[j], r);
213
227
  }
214
- flat.push(r);
228
+ if (Array.isArray(r))
229
+ flat.push(...r);
230
+ else
231
+ flat.push(r);
215
232
  }
216
233
  }
217
234
  }
@@ -537,6 +554,32 @@ export function cdclSession(goal, root, opts = {}) {
537
554
  }
538
555
  return w;
539
556
  };
557
+ // (the point as it is, each name the rows read; undefined where the simplex doesn't know one)
558
+ const roundless = (lp, rows) => {
559
+ const w = {};
560
+ for (const r of rows)
561
+ for (const n of namesOf(r.lin))
562
+ if (!(n in w)) {
563
+ const j = lp.indexOf(n);
564
+ if (j === undefined)
565
+ return undefined;
566
+ w[n] = lp.value(j);
567
+ }
568
+ return w;
569
+ };
570
+ // (the point rounded, each name the rows read; undefined where the simplex doesn't know one)
571
+ const roundedOf = (lp, rows) => {
572
+ const w = {};
573
+ for (const r of rows)
574
+ for (const n of namesOf(r.lin))
575
+ if (!(n in w)) {
576
+ const j = lp.indexOf(n);
577
+ if (j === undefined)
578
+ return undefined;
579
+ w[n] = Math.max(0, Math.round(lp.value(j)));
580
+ }
581
+ return w;
582
+ };
540
583
  let qhead = 0;
541
584
  // Unit propagation: a clause whose literals all hold is a conflict (its index); all but one, the last is flipped.
542
585
  const propagateKernel = () => {
@@ -972,7 +1015,7 @@ export function cdclSession(goal, root, opts = {}) {
972
1015
  if (verify && !clausal) {
973
1016
  const mine = new Set(rowsR.map(r => canon(r.lin))), theirs = new Set(leafConstraints(goal, pathOf()).map(r => canon(r.lin)));
974
1017
  if (mine.size !== theirs.size || [...mine].some(x => !theirs.has(x)))
975
- throw new Error(`reader.ts's rows differ from kernel.ts's at a node of ${goal.name}`);
1018
+ throw new Error(`reader.ts's rows differ from kernel.ts's at a node of ${goal.name}: reader's alone ${[...mine].filter(x => !theirs.has(x)).slice(0, 4).join(' ; ')}; kernel's alone ${[...theirs].filter(x => !mine.has(x)).slice(0, 4).join(' ; ')}; path ${[...pathOf()].map(([k2, a]) => `${a.holds ? '' : '¬'}${k2}`).join(' ; ')}`);
976
1019
  }
977
1020
  work.n += 1 + full.length;
978
1021
  costs.cdclNodes++;
@@ -1093,7 +1136,7 @@ export function cdclSession(goal, root, opts = {}) {
1093
1136
  continue;
1094
1137
  }
1095
1138
  }
1096
- let steps, lpSat = false;
1139
+ let steps, lpSat = false, judged = false;
1097
1140
  let verdict;
1098
1141
  t(() => {
1099
1142
  // The simplex first (warm from the node before): a conflict's rows, refuted exactly, are the leaf. With a case
@@ -1138,42 +1181,77 @@ export function cdclSession(goal, root, opts = {}) {
1138
1181
  st.lpUnknown++;
1139
1182
  }
1140
1183
  if (lp.kind === 'conflict') {
1141
- const support = lp.rows.sort((x, y) => x - y), out = solve(support.map(i => full[i]));
1184
+ const tm = timing ? performance.now() : 0, support = lp.rows.sort((x, y) => x - y), out = solve(support.map(i => full[i]));
1185
+ if (timing)
1186
+ st.missMs += performance.now() - tm;
1142
1187
  if (out.kind === 'refuted')
1143
1188
  steps = out.steps.map(s => (s.kind === 'input' ? { ...s, index: support[s.index] } : s));
1144
1189
  else
1145
1190
  st.lpMisses++;
1146
1191
  }
1147
1192
  lpSat = lp.kind === 'sat';
1193
+ // (a wide goal's part, prove.ts's growWide: the simplex's point rounded, where it holds every hypothesis of the part
1194
+ // read as a state, is the part's model, whatever atoms are still open)
1195
+ if (open && lpSat && wideScope.judge) {
1196
+ const w = roundedOf(sx, rowsR);
1197
+ if (w && wideScope.judge(w)) {
1198
+ verdict = { kind: 'sat', witness: w };
1199
+ judged = true;
1200
+ return;
1201
+ }
1202
+ }
1148
1203
  if (steps || (open && lp.kind === 'sat'))
1149
1204
  return;
1150
1205
  // (the clausal mode, every clause satisfied: the simplex's point, where it is integral, is a model)
1151
- if (clausal && !open && lpSat) {
1206
+ // (`point`, a model's search over the kernel's reading (GDP_CDCL_POINT=0: not): a leaf whose rows the simplex's
1207
+ // point meets at integers is met, and at one whose point is not integral a fractional name of it is split on
1208
+ // (branch and bound) where one is not split on yet, not the exact elimination over every row; the counted
1209
+ // search's (its leaves' elimination took 228 of paxos-hand's 600 s); the others' models stay the elimination's)
1210
+ const byPoint = pointLeaf && !!opts.point && !!opts.model;
1211
+ if ((clausal || byPoint) && !open && lpSat) {
1152
1212
  const w = pointOf(sx, rowsR);
1153
1213
  if (w) {
1154
1214
  verdict = { kind: 'sat', witness: w };
1155
1215
  return;
1156
1216
  }
1157
1217
  }
1218
+ if (byPoint && !clausal && !open && lpSat) {
1219
+ const point = roundless(sx, rowsR);
1220
+ if (point && Object.entries(point).some(([x0, value]) => Math.abs(value - Math.round(value)) >= 1e-9 && !isMonomial(x0) && !decidedLin(Math.floor(value) === 0 ? { [x0]: 1 } : { [x0]: 1, 1: -Math.floor(value) }))) {
1221
+ verdict = { kind: 'unknown', point };
1222
+ return;
1223
+ }
1224
+ }
1158
1225
  }
1159
1226
  st.fmCalls++;
1160
- const rows = plain();
1227
+ const rows = plain(), tf = timing ? performance.now() : 0;
1161
1228
  if (open && rows.length > 60) {
1162
1229
  const fast = refuteFast(rows);
1163
1230
  if (fast?.kind === 'refuted')
1164
1231
  steps = fast.steps.map(s => (s.kind === 'input' ? { ...s, index: at(s.index) } : s));
1165
1232
  }
1233
+ const tf2 = timing ? performance.now() : 0;
1234
+ if (timing)
1235
+ st.fastMs += tf2 - tf;
1166
1236
  if (!steps) {
1167
1237
  verdict = open && rows.length > 60 ? solve(rows, 2 * rows.length) : solve(rows);
1168
1238
  if (verdict.kind === 'refuted')
1169
1239
  steps = verdict.steps.map(s => (s.kind === 'input' ? { ...s, index: at(s.index) } : s));
1170
1240
  }
1241
+ if (timing) {
1242
+ if (open)
1243
+ st.fmOpenMs += performance.now() - tf2;
1244
+ else
1245
+ st.fmLeafMs += performance.now() - tf2;
1246
+ }
1171
1247
  if (!steps && open && !columns && full.length > rows.length) {
1172
1248
  const k = korder(), fast = refuteFast(k.map(i => full[i]));
1173
1249
  if (fast?.kind === 'refuted')
1174
1250
  steps = fast.steps.map(s => (s.kind === 'input' ? { ...s, index: k[s.index] } : s));
1175
1251
  }
1176
1252
  }, ms => { st.solveMs += ms; });
1253
+ if (judged && verdict?.kind === 'sat')
1254
+ return stuck('sat', 'a model', { witness: verdict.witness });
1177
1255
  if (steps)
1178
1256
  conflict = leafAt(rowsR, steps);
1179
1257
  else {