gdp-wired 0.42.0 → 0.44.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 (66) hide show
  1. package/README.md +14 -3
  2. package/dist/core/cli.d.ts +8 -1
  3. package/dist/core/cli.js +271 -30
  4. package/dist/core/counts.d.ts +8 -1
  5. package/dist/core/counts.js +171 -302
  6. package/dist/core/data.js +2 -2
  7. package/dist/core/dsl.js +26 -30
  8. package/dist/core/effect-prims.d.ts +60 -0
  9. package/dist/core/effect-prims.js +625 -0
  10. package/dist/core/effect-schedule.d.ts +103 -0
  11. package/dist/core/effect-schedule.js +817 -0
  12. package/dist/core/effect.d.ts +36 -1
  13. package/dist/core/effect.js +656 -29
  14. package/dist/core/ex/harness.exs +2 -0
  15. package/dist/core/exists.d.ts +5 -0
  16. package/dist/core/exists.js +98 -34
  17. package/dist/core/extract-c.d.ts +2 -0
  18. package/dist/core/extract-c.js +5 -3
  19. package/dist/core/extract-check.d.ts +2 -0
  20. package/dist/core/extract-check.js +45 -4
  21. package/dist/core/extract-ex.js +2 -2
  22. package/dist/core/extract-go-check.js +4 -6
  23. package/dist/core/extract-go.d.ts +3 -0
  24. package/dist/core/extract-go.js +4 -4
  25. package/dist/core/extract-jvm.js +6 -3
  26. package/dist/core/extract-print.js +9 -2
  27. package/dist/core/extract-py.js +2 -2
  28. package/dist/core/extract-rb.js +2 -2
  29. package/dist/core/extract-read.js +2 -1
  30. package/dist/core/extract-rs.js +12 -7
  31. package/dist/core/extract-sol.js +4 -4
  32. package/dist/core/extract-step.d.ts +18 -0
  33. package/dist/core/extract-step.js +135 -31
  34. package/dist/core/extract-swift.js +3 -3
  35. package/dist/core/extract.d.ts +8 -0
  36. package/dist/core/extract.js +13 -1
  37. package/dist/core/infer.d.ts +1 -0
  38. package/dist/core/infer.js +10 -7
  39. package/dist/core/jvm/Harness.java +8 -1
  40. package/dist/core/jvm/Jvm.java +1 -1
  41. package/dist/core/jvm/KtReader.java +3 -0
  42. package/dist/core/laws.d.ts +4 -0
  43. package/dist/core/laws.js +176 -9
  44. package/dist/core/machine.d.ts +3 -0
  45. package/dist/core/machine.js +17 -3
  46. package/dist/core/py/harness.py +64 -19
  47. package/dist/core/py/reader.py +51 -1
  48. package/dist/core/sol/Replay.sol +52 -0
  49. package/dist/core/sol/harness.py +508 -0
  50. package/dist/core/system.d.ts +44 -0
  51. package/dist/core/system.js +435 -0
  52. package/dist/interchange/check.d.ts +18 -1
  53. package/dist/interchange/check.js +9 -2
  54. package/dist/interchange/cli.d.ts +2 -0
  55. package/dist/interchange/cli.js +45 -0
  56. package/dist/interchange/format.d.ts +1 -1
  57. package/dist/interchange/format.js +15 -7
  58. package/dist/kernel/cdcl.js +32 -12
  59. package/dist/kernel/kernel.js +3 -2
  60. package/dist/kernel/prove.d.ts +1 -0
  61. package/dist/kernel/prove.js +69 -8
  62. package/dist/kernel/reader.js +3 -2
  63. package/dist/lean-kernel/emit.js +3 -3
  64. package/dist/lean-kernel/lean-terms.d.ts +1 -0
  65. package/dist/lean-kernel/lean-terms.js +8 -4
  66. package/package.json +12 -3
package/dist/core/data.js CHANGED
@@ -26,7 +26,7 @@
26
26
  // using the others at the fields of their datatypes (mutual induction). Lemmas the law needs are found by the values
27
27
  // (theory exploration: equations between terms the random values agree on, then the shapes of a predicate kept), proven
28
28
  // the same way at lower levels, and used at the terms of the law they match.
29
- import { argsKey, atMost as leC, get, n as k, same as eqC, walk, x as ev } from "./machine.js";
29
+ import { argsKey, atMost as leC, get, n as k, same as eqC, walk, x as ev, lcgFloat } from "./machine.js";
30
30
  import { substC, substE } from "../kernel/kernel.js";
31
31
  import { and as andC, implies, proveCyclic } from "./cyclic.js";
32
32
  import { clock, counted, pairedKeys, withDeadline } from "../kernel/prove.js";
@@ -1160,7 +1160,7 @@ export const showValue = (d, v) => {
1160
1160
  const c = d.ctors[v.c];
1161
1161
  return c.fields.length ? `${c.name}(${c.fields.map((f, i) => showValue(fieldSort(f), v.f[i])).join(', ')})` : c.name;
1162
1162
  };
1163
- export const rng = (seed) => () => { seed = (seed * 1103515245 + 12345) % 2147483648; return seed / 2147483648; };
1163
+ export const rng = (seed) => () => (seed = lcgFloat(seed)) / 2147483648; // (a search's draws: machine.ts's lcgFloat)
1164
1164
  // `full`: a value that fills its size (a constructor with a field of the group, unless the size is spent, or at 1 in 8),
1165
1165
  // where the plain draw mostly stops at a leaf (a list of length 0 or 1, most often).
1166
1166
  export function randomValue(s, rand, size, natMax = 5, full = false) {
package/dist/core/dsl.js CHANGED
@@ -15,7 +15,7 @@
15
15
  //
16
16
  // A step returns its updates as one object: every right-hand side reads the state before the step, as the kernel and
17
17
  // both runtimes do.
18
- import { searchCounted } from "./counts.js";
18
+ import { candidates, cone, searchCounted } from "./counts.js";
19
19
  import { env as knobs } from "./solver.js";
20
20
  import { argsKey, machineTerms, carriedView, compileFunction, divName, divisor, divisorsIn, evalC, evalE, interpret, isArithmetic, loadJs, modName, numbersOf, pairedArgs, seeded, withArithmetic } from "./machine.js";
21
21
  import { allowed, keysOf, requestEnv, watch, watchWork } from "./watch.js";
@@ -891,7 +891,8 @@ function sumOver(map, at, plain) {
891
891
  export const sumsIn = (ts, more = []) => {
892
892
  if (!sumDecls.size)
893
893
  return undefined;
894
- const names = new Set([...more, ...[...JSON.stringify(ts).matchAll(/"op":"var","name":"(sum\$[^"]+)"/g)].map(x2 => x2[1])].filter(n => sumDecls.has(n)));
894
+ // (a sum read after the step, primed, is the sum's too)
895
+ const names = new Set([...more, ...[...JSON.stringify(ts).matchAll(/"op":"var","name":"(sum\$[^"]+)"/g)].map(x2 => x2[1].replace(/'$/, ''))].filter(n => sumDecls.has(n)));
895
896
  return names.size ? Object.fromEntries([...names].sort().map(n => [n, sumDecls.get(n)])) : undefined;
896
897
  };
897
898
  // A map from naturals to naturals, every cell starting at `init`. One write per map per step.
@@ -2933,7 +2934,10 @@ export function proveRule(r, laws, opts = {}) {
2933
2934
  const c = searchCounted(r.machine, withKinds(r, laws), typeof opts.search === 'object' ? opts.search.ms ?? 60_000 : 60_000);
2934
2935
  return { proven: c.proven, checked: c.proven, ...(c.why ? { why: c.why } : {}), found: { laws: c.laws.map(l => ({ text: l.name })) } };
2935
2936
  }
2936
- const out = (opts.fast ? proveSetFast : proveLaws)(r.machine, withKinds(r, laws));
2937
+ // (with a search budget, the laws as given within it on the wall: a step goal of hundreds of hypotheses has a second
2938
+ // each by its own budget, so the search would never start)
2939
+ const ms = typeof opts.search === 'object' ? opts.search.ms : undefined, given = () => (opts.fast ? proveSetFast : proveLaws)(r.machine, withKinds(r, laws));
2940
+ const out = ms === undefined ? given() : withWall(performance.now() + ms, given);
2937
2941
  const v = { ...verdictOf(out), ...(out.witnesses && out.proven ? { witnesses: out.witnesses } : {}) };
2938
2942
  return searched(r, laws, [], v, opts);
2939
2943
  }
@@ -3094,45 +3098,37 @@ function searchedUntil(r, laws, stepLaws, v, opts, until) {
3094
3098
  return { ...verdict, found: { laws: [...fresh, ...found], ...(lemmas ? { lemmas } : {}) }, ...withAssumes([...fresh, ...found]) };
3095
3099
  }
3096
3100
  // A law with "there exists" about no key, which the join can't take as its goal: its witness core/exists.ts's ghostOf;
3097
- // the engine's minimal ∀ cubes of two literals (core/infer.ts's `cubes`, its template two keys at the bound value's
3098
- // places, framed by the law's conjuncts that read the value and no map), each kept where it is proven from the kept ones
3099
- // and itself (IC3's relative induction, its cone), again while more are kept; then the laws with those kept. (A law about
3100
- // every key goes the usual way: its ghost maps' goals ran past the search's wall here, firewall's, and won nothing.)
3101
+ // then core/counts.ts's pipeline: the candidates, the engine's template two keys at the bound value's places, framed by
3102
+ // the law's conjuncts that read the value and no map, kept by the cone (each proven from the kept ones and itself), the
3103
+ // kernel's proveLaw their proof; then the laws with those kept. (A law about every key goes the usual way: its ghost
3104
+ // maps' goals ran past the search's wall here, firewall's, and won nothing.)
3101
3105
  function someCone(r, laws0, ms) {
3102
3106
  const until = clock() + ms, m = r.machine, yes = { op: '<=', a: { op: 'const', value: 0 }, b: { op: 'const', value: 0 } };
3103
3107
  const laws = laws0.map(l => (l.some?.length && !l.forall && !l.witness ? { ...l, witness: ghostOf(m, l) } : l));
3104
3108
  if (laws.some(l => l.some?.length && !l.forall && !l.witness))
3105
3109
  return undefined;
3106
3110
  const named = (d, l) => l.some.some(x => JSON.stringify(d).includes(`"name":${JSON.stringify(x)}`));
3107
- const shape = (l) => (l.some?.length ? shapeOf(l) : l);
3108
3111
  // (two keys at the bound value's places, the law's conjuncts that read the value and no map their frame)
3109
- function shapeOf(l) {
3112
+ const shapeOf = (l) => {
3110
3113
  const x = l.some[0], at = (c, k) => substVars(c, { [x]: { op: 'var', name: k } }), ks = ['k$some', 'k2$some'];
3111
3114
  const cs = l.holds.op === 'and' ? l.holds.xs : [l.holds], frame = cs.filter(c => named(c, l) && !JSON.stringify(c).includes('"op":"get"')), rest = cs.filter(c => !frame.includes(c));
3112
3115
  return { name: l.name, forall: ks[0], keys: [ks[1]], holds: { op: 'or', xs: [{ op: 'not', x: { op: 'and', xs: ks.flatMap(k => frame.map(c => at(c, k))) } }, ...ks.flatMap(k => rest.map(c => at(c, k))), yes] } };
3113
- }
3114
- const cubes = [...withKinds(r, []), ...inferLaws(r, laws.map(shape), [], { cubes: 2, ms: Math.min(10_000, ms / 3), first: { proven: false, checked: false } }).found.map(f => f.law)];
3115
- const kept = [], tried = new Map();
3116
- for (let grew = true; grew && clock() < until;) {
3117
- grew = false;
3118
- for (const c of cubes) {
3119
- if (kept.includes(c) || tried.get(c.name) === kept.length || clock() > until)
3120
- continue;
3121
- tried.set(c.name, kept.length);
3122
- // (a cube the kernel refuses to state, one past its key rules, is never kept)
3123
- let ok = false;
3124
- try {
3125
- ok = withDeadline(Math.min(until, clock() + 1000), () => proveLaw(m, [...kept, c], kept.length)).proven;
3126
- }
3127
- catch { /* not kept */ }
3128
- if (ok) {
3129
- kept.push(c);
3130
- grew = true;
3131
- }
3116
+ };
3117
+ const shapes = laws.map(l => (l.some?.length ? shapeOf(l) : l));
3118
+ const set = [...withKinds(r, []), ...candidates(r, m, shapes, shapes, [], ms, until)];
3119
+ // (a cube the kernel refuses to state, one past its key rules, is never kept)
3120
+ const plain = (law, ls, ms2) => {
3121
+ try {
3122
+ const o = withDeadline(Math.min(until, clock() + ms2), () => proveLaw(m, ls, ls.indexOf(law)));
3123
+ return o.proven ? { proof: true } : { stuck: o.stuck };
3132
3124
  }
3133
- }
3125
+ catch {
3126
+ return { stuck: '' };
3127
+ }
3128
+ };
3129
+ const proven = cone(m, set, plain, until), kept = set.filter(c => proven.has(c.name));
3134
3130
  if (knobs.GDP_EXISTS_LOG === '1')
3135
- console.error(`exists: cone ${kept.length} of ${cubes.length} kept: ${kept.map(l => l.name).join('; ').slice(0, 2000)}`);
3131
+ console.error(`exists: cone ${kept.length} of ${set.length} kept: ${kept.map(l => l.name).join('; ').slice(0, 2000)}`);
3136
3132
  if (clock() > until)
3137
3133
  return undefined;
3138
3134
  const v = verdictOf(proveSome(m, [...laws, ...kept.filter(c => !laws.some(l => l.name === c.name))]));
@@ -0,0 +1,60 @@
1
+ import ts from 'typescript';
2
+ import type { StepLaw } from './dsl.js';
3
+ import { type Law } from './machine.js';
4
+ import { type Setup } from './extract-read.js';
5
+ import type { Extraction } from './extract.js';
6
+ export type Strategy = 'bounded' | 'dropping' | 'sliding' | 'unbounded';
7
+ export type Prim = {
8
+ name: string;
9
+ kind: 'queue';
10
+ strategy: Strategy;
11
+ capacity?: number | string;
12
+ fields: string[];
13
+ } | {
14
+ name: string;
15
+ kind: 'semaphore';
16
+ permits: number | string;
17
+ fields: string[];
18
+ };
19
+ type Api = (e: ts.Expression) => string | undefined;
20
+ export declare const WAITS_FOREVER = "an operation that interrupts its fiber on a shut-down queue (every one on Effect 3, take on Effect 4) is read as a wait that never ends: the fiber takes no step after it, which is what an interrupted one does";
21
+ export declare function rewritePrims(s: Setup, made: {
22
+ fn: ts.FunctionLikeDeclaration;
23
+ params: readonly ts.ParameterDeclaration[];
24
+ }, api: Api, v4: boolean, opts?: {
25
+ params?: boolean;
26
+ }): {
27
+ code: string;
28
+ prims: Prim[];
29
+ notes: string[];
30
+ } | undefined;
31
+ type Mod = Record<string, any>;
32
+ export type Spec = {
33
+ kind: 'queue';
34
+ strategy: Strategy;
35
+ } | {
36
+ kind: 'semaphore';
37
+ };
38
+ export declare function primitiveRule(spec: Spec, effect: Mod, opts?: {
39
+ runs?: number;
40
+ file?: string;
41
+ }): Extraction;
42
+ export declare function primitiveLaws(x: Extraction, spec: Spec): {
43
+ laws: Law[];
44
+ stepLaws: StepLaw[];
45
+ refuted: Law[];
46
+ };
47
+ export declare function primitiveConforms(spec: Spec, effect: Mod, opts?: {
48
+ runs?: number;
49
+ depth?: number;
50
+ seed?: number;
51
+ x?: Extraction;
52
+ file?: string;
53
+ }): Promise<{
54
+ checked: number;
55
+ waited: number;
56
+ blocked: number;
57
+ interrupted: number;
58
+ failure?: string;
59
+ }>;
60
+ export {};