gdp-wired 0.2.0 → 0.4.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.
@@ -0,0 +1,5 @@
1
+ import { type C, type E } from '../core/machine.js';
2
+ export declare function leanTerms(vars: readonly string[], maps: readonly string[], where: string): {
3
+ e: (t: E) => string;
4
+ c: (t: C) => string;
5
+ };
@@ -0,0 +1,44 @@
1
+ // Terms and conditions as Lean.Kern data (Kernel.lean's E and C): the one printer the exporters use and the
2
+ // conformance test (core/conformance.test.ts) checks against Lean's own evalE and evalC. Variables and maps are
3
+ // numbered by their place in `vars` and `maps`; a flag is the variable ?flag read as `= 1` (Progress.lean inlines it).
4
+ // A name with no number fails here, never as a malformed index in the Lean text.
5
+ import { unreachable } from "../core/machine.js";
6
+ export function leanTerms(vars, maps, where) {
7
+ const ix = (name) => { const j = vars.indexOf(name); if (j < 0)
8
+ throw new Error(`${where}: no variable for ${name}`); return j; };
9
+ const mx = (name) => { const j = maps.indexOf(name); if (j < 0)
10
+ throw new Error(`${where}: no map for ${name}`); return j; };
11
+ const e = (t) => {
12
+ switch (t.op) {
13
+ case 'var': return `.var ${ix(t.name)}`;
14
+ case 'const': return `.const ${t.value}`;
15
+ case 'mul': return `.mul ${t.k} (${e(t.a)})`;
16
+ case 'add':
17
+ case 'sub':
18
+ case 'min':
19
+ case 'max':
20
+ case 'prod': return `.${t.op} (${e(t.a)}) (${e(t.b)})`;
21
+ case 'if': return `.ite (${c(t.c)}) (${e(t.then)}) (${e(t.else)})`;
22
+ case 'get': return `.get ${mx(t.map)} (${e(t.key)})`;
23
+ default: return unreachable(t);
24
+ }
25
+ };
26
+ const c = (t) => {
27
+ switch (t.op) {
28
+ case '<=': return `.le (${e(t.a)}) (${e(t.b)})`;
29
+ case '<': return `.lt (${e(t.a)}) (${e(t.b)})`;
30
+ case '=': return `.eq (${e(t.a)}) (${e(t.b)})`;
31
+ case 'not': return `.not (${c(t.x)})`;
32
+ case 'and':
33
+ case 'or': {
34
+ if (t.xs.length === 0)
35
+ return t.op === 'and' ? '.le (.const 0) (.const 0)' : '.lt (.const 0) (.const 0)';
36
+ return t.xs.map(c).reduceRight((acc, y) => `.${t.op} (${y}) (${acc})`);
37
+ }
38
+ case 'flag': return `.eq (.var ${ix(`?${t.name}`)}) (.const 1)`;
39
+ case 'all': throw new Error(`${where}: a quantified flag goes to Lean as a flag of its own, not a condition`);
40
+ default: return unreachable(t);
41
+ }
42
+ };
43
+ return { e, c };
44
+ }
@@ -0,0 +1 @@
1
+ export declare const leanLibrary: Record<string, string>;