gdp-wired 0.41.0 → 0.42.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.
@@ -84,7 +84,8 @@ export function cdclSession(goal, root, opts = {}) {
84
84
  let until = Infinity, budget = { nodes: 0 }, wall, assumed = [], listed = false;
85
85
  // (the first assumption not known to hold: those before it held when last looked at, and an assumption taken back
86
86
  // brings it down to its own; each assumption's index by name)
87
- let aq = 0, aqOf = new Map();
87
+ // (and on each assumption's variable, `aq`, its index this run: the undo's lookup by variable, not by name)
88
+ let aq = 0, aqOf = new Map(), aqVars = [];
88
89
  const st = cdclStats, timing = st.on;
89
90
  const t = (f, add) => { if (!timing)
90
91
  return f(); const t0 = performance.now(); try {
@@ -340,7 +341,7 @@ export function cdclSession(goal, root, opts = {}) {
340
341
  const undoKernel = (l) => {
341
342
  const keep = levels[l] ?? trail.length;
342
343
  while (trail.length > Math.max(keep, fixed)) {
343
- const name = trail.pop(), x = tv.pop(), q = aqOf.size ? aqOf.get(name) : undefined;
344
+ const name = trail.pop(), x = tv.pop(), q = x.aq;
344
345
  x.val = undefined;
345
346
  x.level = -1;
346
347
  x.reason = undefined;
@@ -358,7 +359,8 @@ export function cdclSession(goal, root, opts = {}) {
358
359
  const undoClausal = (l) => {
359
360
  const keep = levels[l] ?? trail.length, undone = [];
360
361
  while (trail.length > keep) {
361
- const name = trail.pop(), x = tv.pop(), q = aqOf.size ? aqOf.get(name) : undefined;
362
+ trail.pop();
363
+ const x = tv.pop(), q = x.aq;
362
364
  vals[x.id] = 0;
363
365
  undone.push(x);
364
366
  x.val = undefined;
@@ -796,7 +798,9 @@ export function cdclSession(goal, root, opts = {}) {
796
798
  };
797
799
  let restartAt = 32, nRestart = 0, sinceRestart = 0, free = 0;
798
800
  const batch = Number(env.GDP_CDCL_BATCH ?? 16);
799
- const stuck = (kind, why, extra = {}) => ({ stuck: kind, path: pathOf(), why, ...extra });
801
+ // (the clausal mode's path left empty: its callers, core/interp.ts's sessions, read a model's witness and never the
802
+ // path, which over a session's gates is a map of thousands, made at every model)
803
+ const stuck = (kind, why, extra = {}) => ({ stuck: kind, path: clausal ? new Map() : pathOf(), why, ...extra });
800
804
  const run = (b, w, assume) => {
801
805
  budget = b;
802
806
  until = b.until ?? Infinity;
@@ -823,6 +827,9 @@ export function cdclSession(goal, root, opts = {}) {
823
827
  }
824
828
  aq = 0;
825
829
  aqOf = new Map(assumed.map(([name], q) => [name, q]));
830
+ for (const y of aqVars)
831
+ y.aq = undefined;
832
+ aqVars = assumed.map(([name], q) => { const y = vars.get(name); y.aq = q; return y; });
826
833
  undoTo(keep);
827
834
  qhead = Math.min(qhead, trail.length);
828
835
  take();
@@ -834,24 +841,34 @@ export function cdclSession(goal, root, opts = {}) {
834
841
  };
835
842
  // The assumptions a falsified one rests on: the decisions its reasons reach, each reason materialized where it is a
836
843
  // bound's (every decision on the trail is an assumption here: the search decides nothing else until they all hold).
844
+ // (the walk by variables, each seen once a call (`fs`, a stamp); a clause of the clausal mode read by its codes)
845
+ let finalN = 0;
837
846
  const final = (q0) => {
838
- const at = aqOf, out = new Set([q0]), seen = new Set(), todo = [assumed[q0][0]];
847
+ const out = new Set([q0]), todo = [vars.get(assumed[q0][0])], stamp = ++finalN;
839
848
  while (todo.length) {
840
- const name = todo.pop(), x = vars.get(name);
841
- if (seen.has(name) || x.level <= 0)
849
+ const x = todo.pop();
850
+ if (x.fs === stamp || x.level <= 0)
842
851
  continue;
843
- seen.add(name);
852
+ x.fs = stamp;
844
853
  if (x.reason === undefined) {
845
- const q = at.get(name);
846
- if (q !== undefined)
847
- out.add(q);
854
+ if (x.aq !== undefined)
855
+ out.add(x.aq);
848
856
  continue;
849
857
  }
850
858
  if (clauses[x.reason].node < 0)
851
859
  materialize(x.reason);
852
- for (const w of clauses[x.reason].lits.keys())
853
- if (w !== name)
854
- todo.push(w);
860
+ const c = clausal ? cls[x.reason] : undefined;
861
+ if (c) {
862
+ for (let j = 0; j < c.length; j++) {
863
+ const y = byId[c[j] >> 1];
864
+ if (y !== x)
865
+ todo.push(y);
866
+ }
867
+ }
868
+ else
869
+ for (const w of clauses[x.reason].lits.keys())
870
+ if (w !== x.name)
871
+ todo.push(vars.get(w));
855
872
  }
856
873
  return [...out].sort((a, b) => a - b);
857
874
  };
@@ -792,8 +792,14 @@ function inScope(what, ts, vars, maps = [], flags = []) {
792
792
  // A name the kernel's linear forms would read as something else: '1' is the constant, and '*', '[', ']', ',' and ':'
793
793
  // build monomials and cells; '#' marks the fresh name a law is proven at (k#, its key's), which a name of the machine or
794
794
  // another key of the law would capture. Such a name could never be proven about; refused instead, with its name.
795
- const plainName = (what, name) => { if (name === '1' || /[*[\],:#]/.test(name))
796
- throw new Error(`${what}: the name ${name} is reserved (1, or * [ ] , : #)`); };
795
+ // The names the kernel makes are kept apart the same way: '?' a flag's variable ?f and its witnesses w?f, w2?f; '~' a
796
+ // state named after a step (s~1); ''' the state and maps after the step (s', M'); '⟦' and '⟧' a term's column (⟦n⟧).
797
+ // ('@', a later step's a@2, ?f@2, I@2, is not reserved: compose's steps names its inputs x@s1; stepLawObligations
798
+ // keeps a later step's names apart from every name of the machine instead.) A name of the machine, a law's or step
799
+ // law's key with one of them would be read as the kernel's own (a param ?f as the flag f's 0/1 variable: "s <= ?f" was
800
+ // accepted, false at ?f = 0; Lean refuses it).
801
+ const plainName = (what, name) => { if (name === '1' || /[*[\],:#?~'⟦⟧]/.test(name))
802
+ throw new Error(`${what}: the name ${name} is reserved (1, or * [ ] , : # ? ~ ' ⟦ ⟧)`); };
797
803
  const distinct = (what, names) => { const seen = new Set(); for (const name of names) {
798
804
  if (seen.has(name))
799
805
  throw new Error(`${what} declares ${name} twice`);
@@ -1532,6 +1538,7 @@ export function checkRecurCases(l, r) {
1532
1538
  // hold of every request where the sums are exact: Sums.lean's sum_allowed).
1533
1539
  export function progressObligations(m0, laws, instances, p) {
1534
1540
  const m = plainOf(m0), own = m0.sums && Object.keys(m0.sums).length ? m0.assume : m.assume;
1541
+ scope(m, laws); // (as obligations scopes it: a param ?f would be read as the flag f's variable here too)
1535
1542
  if (!m.inputs.every(i => i in p.request) || !Object.values(p.request).every(natural) || mentions(p.when, m.inputs))
1536
1543
  throw new Error('outside the kernel');
1537
1544
  for (const e of Object.values(p.request))
@@ -1621,11 +1628,17 @@ export function stepLawObligations(machine, laws, instances, sl) {
1621
1628
  const later = laters.flatMap(l => Object.values(l.vars).map(e => e.name)), laterMaps = laters.flatMap(l => Object.values(l.maps));
1622
1629
  const names = Array.from({ length: k - 1 }, (_, i) => state.map(n => stateName(n, i + 1))).flat();
1623
1630
  const taken = [...m.params, ...m.inputs, ...state, ...maps, ...carried];
1631
+ // (and every name the run reads besides: the functions, each flag's variable ?f and its witnesses, which a later
1632
+ // step's names, a@2, I@2, ?f@2, must not be: a function I@2 was read as the second request's carried map)
1633
+ const own = [...taken, ...Object.keys(m.fns ?? {}), ...flagNames.map(f => `?${f}`), ...quantified(m).flatMap(([f, q]) => witnessesOf(f, q))];
1624
1634
  for (const p of [...primes, ...later, ...laterMaps, ...names])
1625
- if (taken.includes(p))
1635
+ if (own.includes(p))
1626
1636
  throw new Error(`${m.name}: ${p} is a name of the machine and a name a step law reads`);
1627
1637
  for (const key of [sl.forall, ...(sl.keys ?? [])])
1628
- if (key && [...taken, ...primes, ...later].includes(key))
1638
+ if (key)
1639
+ plainName(`step law ${sl.name}'s key`, key);
1640
+ for (const key of [sl.forall, ...(sl.keys ?? [])])
1641
+ if (key && [...own, ...primes, ...later, ...names].includes(key))
1629
1642
  throw new Error(`step law ${sl.name}'s key ${key} is already a name of ${m.name}`);
1630
1643
  if (sl.keys?.length && (!sl.forall || new Set([sl.forall, ...sl.keys]).size !== sl.keys.length + 1))
1631
1644
  throw new Error(`step law ${sl.name}: further keys come with a first, each a different name`);
@@ -1706,6 +1719,12 @@ export function foldObligations(f, laws) {
1706
1719
  throw new Error('outside the kernel');
1707
1720
  const names = Object.keys(f.leaf);
1708
1721
  distinct(f.name, [...f.params, ...f.inputs, ...names]);
1722
+ // The children's copies (l_n, r_n) are names of their own (Lean's copiesOk): a param l_size would be read as the left
1723
+ // child's size at a node.
1724
+ const copies = names.flatMap(n => [`l_${n}`, `r_${n}`]);
1725
+ for (const name of [...f.params, ...f.inputs, ...names])
1726
+ if (copies.includes(name))
1727
+ throw new Error(`${f.name}: ${name} is a name of the fold and a child's copy (l_<name>, r_<name>)`);
1709
1728
  if (Object.keys(f.node).sort().join() !== [...names].sort().join())
1710
1729
  throw new Error(`${f.name}'s leaf and node set the same names`);
1711
1730
  inScope(`${f.name}'s leaf`, [...Object.values(f.leaf), ...(f.assume ? [f.assume] : [])], [...f.params, ...f.inputs]);
@@ -1776,7 +1795,7 @@ export function qdec(path, r) {
1776
1795
  }
1777
1796
  export function qlinear(e, path) {
1778
1797
  switch (e.op) {
1779
- case 'var': return e.name === '1' ? undefined : { row: { cs: new Map([[e.name, 1n]]), c: 0n }, den: 1n };
1798
+ case 'var': return e.name === '1' || /[*[\],:⟦]/.test(e.name) ? undefined : { row: { cs: new Map([[e.name, 1n]]), c: 0n }, den: 1n }; // (a row's key is its canonical text: a variable x:1,y read as x + y's)
1780
1799
  case 'const': {
1781
1800
  const q = ratNorm(e.q);
1782
1801
  return { row: { cs: new Map(), c: q.num }, den: q.den };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gdp-wired",
3
- "version": "0.41.0",
3
+ "version": "0.42.0",
4
4
  "description": "An automatic prover for stateful rules (budgets, caps, windows, workflows, policies): laws proven with no proof to write, checked again in Lean, counterexamples found on the GPU, the rule shipped as code",
5
5
  "keywords": [
6
6
  "verification",