gdp-wired 0.31.1 → 0.33.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 (84) hide show
  1. package/README.md +95 -6
  2. package/dist/core/c/reader.d.ts +86 -0
  3. package/dist/core/c/reader.js +860 -0
  4. package/dist/core/check.js +20 -6
  5. package/dist/core/cli.d.ts +76 -0
  6. package/dist/core/cli.js +636 -0
  7. package/dist/core/dsl.d.ts +6 -4
  8. package/dist/core/dsl.js +30 -16
  9. package/dist/core/effect.d.ts +6 -4
  10. package/dist/core/effect.js +48 -10
  11. package/dist/core/ex/harness.exs +177 -0
  12. package/dist/core/ex/json.exs +46 -0
  13. package/dist/core/ex/reader.exs +462 -0
  14. package/dist/core/exists.d.ts +3 -0
  15. package/dist/core/exists.js +19 -5
  16. package/dist/core/extract-c.d.ts +35 -0
  17. package/dist/core/extract-c.js +424 -0
  18. package/dist/core/extract-check.js +27 -6
  19. package/dist/core/extract-ex.d.ts +16 -0
  20. package/dist/core/extract-ex.js +33 -0
  21. package/dist/core/extract-go-check.d.ts +28 -0
  22. package/dist/core/extract-go-check.js +639 -0
  23. package/dist/core/extract-go.d.ts +231 -0
  24. package/dist/core/extract-go.js +1166 -0
  25. package/dist/core/extract-jvm.d.ts +23 -0
  26. package/dist/core/extract-jvm.js +220 -0
  27. package/dist/core/extract-print.js +17 -7
  28. package/dist/core/extract-py.d.ts +15 -0
  29. package/dist/core/extract-py.js +31 -0
  30. package/dist/core/extract-rb.d.ts +17 -0
  31. package/dist/core/extract-rb.js +31 -0
  32. package/dist/core/extract-read.d.ts +20 -0
  33. package/dist/core/extract-read.js +46 -6
  34. package/dist/core/extract-rs.d.ts +12 -0
  35. package/dist/core/extract-rs.js +306 -0
  36. package/dist/core/extract-shapes.d.ts +2 -0
  37. package/dist/core/extract-shapes.js +6 -5
  38. package/dist/core/extract-step.d.ts +806 -0
  39. package/dist/core/extract-step.js +4141 -0
  40. package/dist/core/extract-swift.d.ts +27 -0
  41. package/dist/core/extract-swift.js +484 -0
  42. package/dist/core/extract-xstate.d.ts +10 -3
  43. package/dist/core/extract-xstate.js +50 -4
  44. package/dist/core/extract.d.ts +22 -3
  45. package/dist/core/extract.js +107 -18
  46. package/dist/core/go/go.mod +3 -0
  47. package/dist/core/go/reader.go +901 -0
  48. package/dist/core/infer.d.ts +4 -0
  49. package/dist/core/infer.js +1838 -69
  50. package/dist/core/jvm/Harness.java +361 -0
  51. package/dist/core/jvm/JavaReader.java +825 -0
  52. package/dist/core/jvm/Jvm.java +332 -0
  53. package/dist/core/jvm/KtReader.java +960 -0
  54. package/dist/core/jvm/Rt.java +10 -0
  55. package/dist/core/laws.d.ts +83 -0
  56. package/dist/core/laws.js +623 -0
  57. package/dist/core/machine.d.ts +2 -0
  58. package/dist/core/machine.js +87 -0
  59. package/dist/core/py/harness.py +328 -0
  60. package/dist/core/py/reader.py +447 -0
  61. package/dist/core/rb/harness.rb +233 -0
  62. package/dist/core/rb/reader.rb +375 -0
  63. package/dist/core/relational.d.ts +49 -0
  64. package/dist/core/relational.js +345 -0
  65. package/dist/core/rs/Cargo.lock +108 -0
  66. package/dist/core/rs/Cargo.toml +14 -0
  67. package/dist/core/rs/src/main.rs +681 -0
  68. package/dist/core/swift/Harness.swift +124 -0
  69. package/dist/core/swift/Main.swift +34 -0
  70. package/dist/core/swift/Package.swift +13 -0
  71. package/dist/core/swift/Sources/gdp-swiftreader/main.swift +1341 -0
  72. package/dist/interchange/check.d.ts +16 -0
  73. package/dist/interchange/check.js +111 -0
  74. package/dist/interchange/format.d.ts +150 -0
  75. package/dist/interchange/format.js +678 -0
  76. package/dist/kernel/epr.d.ts +40 -0
  77. package/dist/kernel/epr.js +1882 -0
  78. package/dist/kernel/kernel.d.ts +45 -1
  79. package/dist/kernel/kernel.js +138 -13
  80. package/dist/kernel/prove.d.ts +45 -0
  81. package/dist/kernel/prove.js +658 -51
  82. package/dist/lean-kernel/emit.d.ts +17 -2
  83. package/dist/lean-kernel/emit.js +87 -7
  84. package/package.json +57 -2
@@ -7,21 +7,25 @@ export function checkRefutation(constraints, steps, integral = true) {
7
7
  if (!(Number.isInteger(s.index) && s.index >= 0 && s.index < constraints.length))
8
8
  return false;
9
9
  const c = constraints[s.index];
10
- if (!integral && !exact(c.lin))
10
+ if (!exact(c.lin))
11
11
  return false;
12
12
  rows.push(c.lin);
13
13
  strict.push(!integral && c.strict === true);
14
14
  }
15
15
  else if (s.kind === 'combine') {
16
- if (!(s.a < i && s.b < i && Number.isInteger(s.ma) && Number.isInteger(s.mb) && s.ma > 0 && s.mb > 0))
16
+ if (!(s.a < i && s.b < i && Number.isSafeInteger(s.ma) && Number.isSafeInteger(s.mb) && s.ma > 0 && s.mb > 0))
17
17
  return false;
18
18
  if (!integral && !(Number.isInteger(s.a) && Number.isInteger(s.b) && s.a >= 0 && s.b >= 0))
19
19
  return false;
20
20
  const out = {};
21
+ // Each product safe too: a rounded one is past 2^53, but the other row's could bring the sum back under it.
21
22
  for (const [lin, m] of [[rows[s.a], s.ma], [rows[s.b], s.mb]])
22
- for (const [key, c] of Object.entries(lin))
23
+ for (const [key, c] of Object.entries(lin)) {
24
+ if (!Number.isSafeInteger(m * c))
25
+ return false;
23
26
  out[key] = (out[key] ?? 0) + m * c;
24
- if (!integral && !exact(out))
27
+ }
28
+ if (!exact(out))
25
29
  return false;
26
30
  rows.push(out);
27
31
  strict.push(strict[s.a] || strict[s.b]);
@@ -29,8 +33,9 @@ export function checkRefutation(constraints, steps, integral = true) {
29
33
  else {
30
34
  if (!integral)
31
35
  return false;
36
+ // (c / g rounded is never an integer c / g isn't, nor past the next one, for a safe c: its ceiling is exact.)
32
37
  const row = rows[s.of];
33
- if (!(row !== undefined && s.of < i && Number.isInteger(s.g) && s.g > 0 && vars(row).every(key => row[key] % s.g === 0)))
38
+ if (!(row !== undefined && s.of < i && Number.isSafeInteger(s.g) && s.g > 0 && vars(row).every(key => row[key] % s.g === 0)))
34
39
  return false;
35
40
  rows.push({ ...Object.fromEntries(vars(row).map(key => [key, row[key] / s.g])), 1: Math.ceil((row['1'] ?? 0) / s.g) });
36
41
  strict.push(false);
@@ -40,5 +45,14 @@ export function checkRefutation(constraints, steps, integral = true) {
40
45
  return last !== undefined && vars(last).every(key => last[key] === 0) && (constant > 0 || (strict.at(-1) && constant >= 0));
41
46
  }
42
47
  export function checkWitness(constraints, witness) {
43
- return constraints.every(c => Object.entries(c.lin).reduce((sum, [key, a]) => sum + a * (key === '1' ? 1 : (witness[key] ?? NaN)), 0) <= 0);
48
+ return constraints.every(c => {
49
+ let sum = 0;
50
+ for (const [key, a] of Object.entries(c.lin)) {
51
+ const value = key === '1' ? 1 : witness[key], term = a * value;
52
+ if (!(Number.isSafeInteger(a) && Number.isSafeInteger(value) && Number.isSafeInteger(term) && Number.isSafeInteger(sum + term)))
53
+ return false;
54
+ sum += term;
55
+ }
56
+ return sum <= 0;
57
+ });
44
58
  }
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env node
2
+ import type { Extraction, Name } from './extract.js';
3
+ import { type Verdict } from './dsl.js';
4
+ export declare const colors: (env: Record<string, string | undefined>, tty: boolean, json?: boolean) => boolean;
5
+ export type Opts = {
6
+ entry?: string;
7
+ methods?: string[];
8
+ failures?: 'refuse' | 'kept';
9
+ onError?: 'refuse' | 'discard';
10
+ json?: boolean;
11
+ ms: number;
12
+ propose: boolean;
13
+ root?: string;
14
+ python?: string;
15
+ clock?: string;
16
+ cert?: string;
17
+ [k: string]: unknown;
18
+ };
19
+ export type Lang = 'python' | 'ruby' | 'elixir' | 'java' | 'kotlin' | 'go' | 'rust' | 'swift' | 'c' | 'cpp' | 'ts';
20
+ export declare const LANG_NAME: Record<Lang, string>;
21
+ type Target = {
22
+ lang: Lang;
23
+ at: string;
24
+ files: string[];
25
+ };
26
+ export declare function up(d: string, ok: (d: string) => boolean): string | undefined;
27
+ type Config = {
28
+ all: Record<string, unknown>;
29
+ rules: Record<string, Record<string, unknown>>;
30
+ at?: string;
31
+ };
32
+ export declare function configFor(from: string): Config;
33
+ export declare function toml(text: string): Record<string, unknown>;
34
+ type LawOut = {
35
+ name: string;
36
+ expr: string;
37
+ where?: string;
38
+ kind?: 'law' | 'step' | 'two runs';
39
+ verdict: 'proven' | 'broken' | 'unknown' | 'not read';
40
+ run?: string[];
41
+ why?: string;
42
+ assumes?: string[];
43
+ found?: string[];
44
+ cites?: string[];
45
+ cert?: string;
46
+ ms: number;
47
+ };
48
+ export type RuleOut = {
49
+ file: string;
50
+ lang: string;
51
+ entry?: string;
52
+ ok: boolean;
53
+ refusals: {
54
+ where: string;
55
+ what: string;
56
+ }[];
57
+ notes: string[];
58
+ names: Name[];
59
+ checked?: string;
60
+ laws: LawOut[];
61
+ proposed: LawOut[];
62
+ brokenProposed?: number;
63
+ source?: string;
64
+ };
65
+ export declare function checkTarget(t: Target, o: Opts): Promise<RuleOut[]>;
66
+ export declare function runOf(x: Extraction, run: NonNullable<Verdict['run']>): string[];
67
+ export declare const proposedLaws: (x: Extraction, lang: Lang, ms?: number) => {
68
+ shown: LawOut[];
69
+ broken: number;
70
+ };
71
+ export declare function check(targets: string[], given?: Partial<Opts>, each?: (r: RuleOut) => void): Promise<{
72
+ rules: RuleOut[];
73
+ exit: number;
74
+ }>;
75
+ export declare function main(argv: string[]): Promise<number>;
76
+ export {};