gdp-wired 0.32.0 → 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.
- package/README.md +13 -0
- package/dist/core/check.js +20 -6
- package/dist/core/cli.d.ts +13 -3
- package/dist/core/cli.js +77 -23
- package/dist/core/dsl.d.ts +2 -2
- package/dist/core/dsl.js +8 -4
- package/dist/core/exists.js +16 -4
- package/dist/core/infer.d.ts +4 -0
- package/dist/core/infer.js +164 -113
- package/dist/core/laws.d.ts +19 -2
- package/dist/core/laws.js +105 -4
- package/dist/core/machine.d.ts +2 -0
- package/dist/core/machine.js +87 -0
- package/dist/core/relational.d.ts +49 -0
- package/dist/core/relational.js +345 -0
- package/dist/interchange/check.d.ts +16 -0
- package/dist/interchange/check.js +111 -0
- package/dist/interchange/format.d.ts +150 -0
- package/dist/interchange/format.js +678 -0
- package/dist/kernel/epr.d.ts +5 -0
- package/dist/kernel/epr.js +1152 -946
- package/dist/kernel/kernel.d.ts +45 -1
- package/dist/kernel/kernel.js +138 -13
- package/dist/kernel/prove.d.ts +1 -0
- package/dist/kernel/prove.js +4 -4
- package/dist/lean-kernel/emit.d.ts +16 -2
- package/dist/lean-kernel/emit.js +66 -3
- package/package.json +6 -2
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
// Laws about two runs (`gdp-wired/relational`): two runs of one rule, or of two rules, side by side as one rule, so a
|
|
2
|
+
// law comparing them is an ordinary law of that rule, proven by the same induction, search and kernel, and checked in
|
|
3
|
+
// Lean as any other. Nothing here is trusted: what is proven is a law of the rule built, and the rule built is the two
|
|
4
|
+
// rules' own steps, their names renamed (a_x for the first run's x, b_x for the second's).
|
|
5
|
+
//
|
|
6
|
+
// noninterference(rule, {secret: ['diagnosis'], visible: ['status']}) two runs whose requests and params differ
|
|
7
|
+
// only in the secret ones give the same visible state, and refuse the same requests: the secret never reaches
|
|
8
|
+
// what the party sees
|
|
9
|
+
// isolation(rule, {owner: 'user_id', sees: ['failures']}) what tenant B sees (its cells, its requests'
|
|
10
|
+
// results and refusals) is the same whether or not anyone else acts: run a takes every request, run b only B's
|
|
11
|
+
// agreement(old, next) the two rules agree on every history: the
|
|
12
|
+
// same state they share by name after every run of the same requests, and the same refusals (a migration)
|
|
13
|
+
// proveTwoRuns(law) the verdict, its run (two runs) if broken
|
|
14
|
+
//
|
|
15
|
+
// Each works on a rule read from code (gdp-wired/extract, extract-py, ...) as on one written with the builders; the
|
|
16
|
+
// rule's own invariants (an extraction's `invariants`) are given to proveTwoRuns and hold of each run.
|
|
17
|
+
// `twoRuns` is the construction itself, for laws of another shape: laws over the a_ and b_ names, proven by proveRule
|
|
18
|
+
// or proveSteps on the rule it returns.
|
|
19
|
+
//
|
|
20
|
+
// Refusals: by default (`refusals: 'same'`) a request one run refuses and the other takes is a difference the law is
|
|
21
|
+
// about (an error is seen as much as a value): the runs then keep their state, and `split$`, which the law
|
|
22
|
+
// `the two runs refuse the same requests` holds at 0, marks it. `refusals: 'assumed'` only takes requests both allow.
|
|
23
|
+
//
|
|
24
|
+
// Two of the law's names are reserved in the rule built: a$ok and b$ok (each run allows the request), split$.
|
|
25
|
+
import { Rule, Term, all, any, forall, nat, no, not, proveSteps, same, when, yes } from "./dsl.js";
|
|
26
|
+
import { proveLaws, proveStepLaws } from "../kernel/prove.js";
|
|
27
|
+
import { fromInterchange, toInterchange } from "../interchange/format.js";
|
|
28
|
+
import { checkCertificate } from "../interchange/check.js";
|
|
29
|
+
const specOf = (r) => r.spec;
|
|
30
|
+
const v = (name) => new Term({ op: 'var', name });
|
|
31
|
+
// The names a side declares that are its own in the rule built (renamed): state and its parts, maps, lists, cells,
|
|
32
|
+
// items, kinded values, flags, and the params and inputs not shared.
|
|
33
|
+
function ownNames(s, shared) {
|
|
34
|
+
const out = new Set();
|
|
35
|
+
const kindParts = (xs) => { for (const [n, k] of xs ?? []) {
|
|
36
|
+
out.add(n);
|
|
37
|
+
for (const p of k.vars(n))
|
|
38
|
+
out.add(p);
|
|
39
|
+
} };
|
|
40
|
+
for (const [n, k] of [...s.params, ...s.inputs])
|
|
41
|
+
if (!shared.has(n)) {
|
|
42
|
+
out.add(n);
|
|
43
|
+
for (const p of k.vars(n))
|
|
44
|
+
out.add(p);
|
|
45
|
+
}
|
|
46
|
+
for (const [n] of s.state)
|
|
47
|
+
out.add(n);
|
|
48
|
+
for (const [n] of s.maps)
|
|
49
|
+
out.add(n);
|
|
50
|
+
for (const n of s.lists ?? [])
|
|
51
|
+
out.add(n);
|
|
52
|
+
kindParts(s.cells);
|
|
53
|
+
kindParts(s.items);
|
|
54
|
+
kindParts(s.kinded);
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
// The rule's env as one side's callbacks read it: its own names without their prefix, the shared ones as they are.
|
|
58
|
+
function view(env, sd) {
|
|
59
|
+
const o = {}, other = sd.p === 'a_' ? 'b_' : 'a_';
|
|
60
|
+
for (const [k, x] of Object.entries(env)) {
|
|
61
|
+
if (k.startsWith(sd.p))
|
|
62
|
+
o[k.slice(2)] = x;
|
|
63
|
+
else if (!k.startsWith(other))
|
|
64
|
+
o[k] = x;
|
|
65
|
+
}
|
|
66
|
+
return o;
|
|
67
|
+
}
|
|
68
|
+
const sameKind = (k1, k2) => k1.constructor === k2.constructor && JSON.stringify(k1.vars('x')) === JSON.stringify(k2.vars('x'))
|
|
69
|
+
&& JSON.stringify(k1.assume('x').map(c => c.c)) === JSON.stringify(k2.assume('x').map(c => c.c));
|
|
70
|
+
// Two runs side by side as one rule: a's step and b's on every request (b's unless `stays`), each over its own state.
|
|
71
|
+
export function twoRuns(a, b = a, opts = {}) {
|
|
72
|
+
const sa = specOf(a), sb = specOf(b), refusals = opts.refusals ?? 'same';
|
|
73
|
+
for (const s of [sa, sb]) {
|
|
74
|
+
const odd = ['record', 'seqs', 'seqTables', 'lists2', 'carried', 'nodes'].filter(f => { const x = s[f]; return Array.isArray(x) ? x.length : !!x; });
|
|
75
|
+
if (odd.length || s.sums.length || s.queries.length)
|
|
76
|
+
throw new Error(`twoRuns: ${s.name} has ${[...odd, ...(s.sums.length ? ['sums'] : []), ...(s.queries.length ? ['queries'] : [])].join(', ')}, which two runs side by side don't take yet`);
|
|
77
|
+
for (const [n] of [...s.params, ...s.inputs, ...s.state, ...s.maps])
|
|
78
|
+
if (/^[ab]_/.test(n))
|
|
79
|
+
throw new Error(`twoRuns: ${s.name}'s ${n}: a_ and b_ name the two runs' own values`);
|
|
80
|
+
}
|
|
81
|
+
const kindsOf = (s) => new Map([...s.params, ...s.inputs]);
|
|
82
|
+
const ka = kindsOf(sa), kb = kindsOf(sb);
|
|
83
|
+
const shared = new Set(opts.shared ?? [...ka.keys()].filter(n => kb.has(n)));
|
|
84
|
+
for (const n of shared) {
|
|
85
|
+
const x = ka.get(n), y = kb.get(n);
|
|
86
|
+
if (!x || !y)
|
|
87
|
+
throw new Error(`twoRuns: ${n} is shared but not a param or input of ${x ? sb.name : sa.name}`);
|
|
88
|
+
if (!sameKind(x, y))
|
|
89
|
+
throw new Error(`twoRuns: ${n} is of another kind in ${sa.name} and ${sb.name}`);
|
|
90
|
+
if (sa.params.some(([m]) => m === n) !== sb.params.some(([m]) => m === n))
|
|
91
|
+
throw new Error(`twoRuns: ${n} is a param of one rule and an input of the other`);
|
|
92
|
+
}
|
|
93
|
+
const A = { p: 'a_', s: sa, shared, own: ownNames(sa, shared) }, B = { p: 'b_', s: sb, shared, own: ownNames(sb, shared) };
|
|
94
|
+
const sides = [A, B];
|
|
95
|
+
const rn = (sd, n) => (sd.own.has(n) ? sd.p + n : n);
|
|
96
|
+
// (a part's name is its value's with a suffix: renamed with it)
|
|
97
|
+
for (const sd of sides)
|
|
98
|
+
for (const [n, k] of [...sd.s.params, ...sd.s.inputs, ...(sd.s.kinded ?? []), ...(sd.s.cells ?? []), ...(sd.s.items ?? [])]) {
|
|
99
|
+
if (sd.own.has(n) && JSON.stringify(k.vars(sd.p + n)) !== JSON.stringify(k.vars(n).map(x => sd.p + x)))
|
|
100
|
+
throw new Error(`twoRuns: ${n}'s parts aren't named after it`);
|
|
101
|
+
}
|
|
102
|
+
const once = (xs) => { const seen = new Set(); return xs.filter(([n]) => !seen.has(n) && !!seen.add(n)); };
|
|
103
|
+
const renamed = (f) => sides.flatMap(sd => (f(sd.s) ?? []).map(([n, t]) => [rn(sd, n), t]));
|
|
104
|
+
const fns = once(sides.flatMap(sd => sd.s.fns ?? []));
|
|
105
|
+
for (const [n, d] of fns)
|
|
106
|
+
for (const sd of sides) {
|
|
107
|
+
const o = (sd.s.fns ?? []).find(([m]) => m === n);
|
|
108
|
+
if (o && o[1] !== d)
|
|
109
|
+
throw new Error(`twoRuns: two functions named ${n}`);
|
|
110
|
+
}
|
|
111
|
+
const okOf = (sd) => (env) => all(...sd.s.assume.map(f => f(view(env, sd))));
|
|
112
|
+
const stays = (env) => opts.stays?.(env) ?? no;
|
|
113
|
+
// Where each run takes the request: both allow it (or b stays and a allows it); else neither moves.
|
|
114
|
+
const goA = (env) => (refusals === 'same' ? all(env['a$ok'], any(stays(env), env['b$ok'])) : yes);
|
|
115
|
+
const goB = (env) => (refusals === 'same' ? all(not(stays(env)), env['a$ok'], env['b$ok']) : not(stays(env)));
|
|
116
|
+
const spec = {
|
|
117
|
+
name: opts.name ?? (a === b ? `${sa.name}, two runs` : `${sa.name} | ${sb.name}`),
|
|
118
|
+
params: once(renamed(s => s.params)), inputs: once(renamed(s => s.inputs)),
|
|
119
|
+
state: [...sides.flatMap(sd => sd.s.state.map(([n, init]) => [sd.p + n, typeof init === 'number' ? init : (pe) => init(view(pe, sd))])),
|
|
120
|
+
...(refusals === 'same' ? [['split$', 0]] : [])],
|
|
121
|
+
maps: renamed(s => s.maps),
|
|
122
|
+
lists: sides.flatMap(sd => (sd.s.lists ?? []).map(n => sd.p + n)),
|
|
123
|
+
cells: renamed(s => s.cells), items: renamed(s => s.items), kinded: renamed(s => s.kinded),
|
|
124
|
+
...(fns.length ? { fns } : {}),
|
|
125
|
+
facts: sides.flatMap(sd => (sd.s.facts ?? []).map(f => (env) => Object.fromEntries(Object.entries(f(view(env, sd))).map(([n, c]) => [`${sd.p}${n}`, c])))),
|
|
126
|
+
arith: new Set([...(sa.arith ?? []), ...(sb.arith ?? [])]),
|
|
127
|
+
flags: [
|
|
128
|
+
...sides.flatMap(sd => sd.s.flags.map(f => (env) => Object.fromEntries(Object.entries(f(view(env, sd))).map(([n, c]) => [sd.p + n, c])))),
|
|
129
|
+
...(refusals === 'same' ? [(env) => ({ 'a$ok': okOf(A)(env), 'b$ok': okOf(B)(env) })] : []),
|
|
130
|
+
],
|
|
131
|
+
pre: sides.flatMap(sd => sd.s.pre.map(f => (p) => f(view(p, sd)))),
|
|
132
|
+
assume: [
|
|
133
|
+
...(refusals === 'assumed' ? [(env) => all(okOf(A)(env), any(stays(env), okOf(B)(env)))] : []),
|
|
134
|
+
...(opts.given ? [(env) => opts.given(env)] : []),
|
|
135
|
+
],
|
|
136
|
+
sums: [], queries: [],
|
|
137
|
+
step: (env) => {
|
|
138
|
+
const out = {};
|
|
139
|
+
for (const sd of sides) {
|
|
140
|
+
const go = (sd === A ? goA : goB)(env), side = view(env, sd);
|
|
141
|
+
for (const [k, w] of Object.entries(sd.s.step?.(side) ?? {})) {
|
|
142
|
+
if (w === undefined)
|
|
143
|
+
continue;
|
|
144
|
+
const key = sd.own.has(k) ? sd.p + k : k.startsWith(sd.p) && sd.own.has(k.slice(2)) ? k : undefined;
|
|
145
|
+
if (!key)
|
|
146
|
+
throw new Error(`twoRuns: ${sd.s.name}'s step writes ${k}, which it doesn't declare`);
|
|
147
|
+
out[key] = guarded(sd, key, w, go);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (refusals === 'same')
|
|
151
|
+
out['split$'] = when(all(not(stays(env)), not(env['a$ok'].iff(env['b$ok']))), 1, env['split$']);
|
|
152
|
+
return out;
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
return new Rule(spec);
|
|
156
|
+
}
|
|
157
|
+
// A run's write kept only where it takes the request (else the value before it).
|
|
158
|
+
function guarded(sd, key, w, go) {
|
|
159
|
+
if (go === yes)
|
|
160
|
+
return w;
|
|
161
|
+
const kept = (value, old) => ({ op: 'if', c: go.c, then: value, else: old });
|
|
162
|
+
const mapWrite = (m) => ({ ...m, value: kept(m.value, { op: 'get', map: m.map, key: m.each ? { op: 'var', name: m.each } : m.key }), concrete: undefined });
|
|
163
|
+
if (typeof w === 'object' && w !== null && 'parts' in w)
|
|
164
|
+
return { parts: Object.fromEntries(Object.entries(w.parts).map(([p, m]) => [p, mapWrite(m)])) };
|
|
165
|
+
if (typeof w === 'object' && w !== null && 'map' in w)
|
|
166
|
+
return mapWrite(w);
|
|
167
|
+
const kind = (sd.s.kinded ?? []).find(([n]) => sd.p + n === key)?.[1];
|
|
168
|
+
if (kind) {
|
|
169
|
+
const parts = kind.store(key, w);
|
|
170
|
+
return kind.build(key, part => when(go, parts[part], v(part)));
|
|
171
|
+
}
|
|
172
|
+
return when(go, w, v(key));
|
|
173
|
+
}
|
|
174
|
+
// What a run's state holds by name: its scalars (state and kinded values) and maps (plain or of a kind).
|
|
175
|
+
function stateNames(s) {
|
|
176
|
+
const parts = new Set([...(s.kinded ?? []), ...(s.cells ?? []), ...(s.items ?? [])].flatMap(([n, k]) => k.vars(n).filter(p => p !== n)));
|
|
177
|
+
const lens = new Set([...(s.items ?? []).map(([n]) => `${n}_len`), ...(s.lists ?? []).map(n => `${n}_len`)]);
|
|
178
|
+
return {
|
|
179
|
+
scalars: [...s.state.map(([n]) => n).filter(n => !parts.has(n) && !lens.has(n)), ...(s.kinded ?? []).map(([n]) => n)].filter((n, i, xs) => xs.indexOf(n) === i),
|
|
180
|
+
maps: [...s.maps.map(([n]) => n).filter(n => !parts.has(n) && !(s.lists ?? []).includes(n)), ...(s.cells ?? []).map(([n]) => n)].filter((n, i, xs) => xs.indexOf(n) === i),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
// The two runs' values of a name, the same: a scalar, or a map at every key (or at `at`).
|
|
184
|
+
const sameIn = (env, n, isMap, at) => {
|
|
185
|
+
const x = env[`a_${n}`], y = env[`b_${n}`];
|
|
186
|
+
if (x === undefined || y === undefined)
|
|
187
|
+
throw new Error(`no ${n} in both runs`);
|
|
188
|
+
return !isMap ? same(x, y) : at ? same(x.at(at), y.at(at)) : (k) => same(x.at(k), y.at(k));
|
|
189
|
+
};
|
|
190
|
+
function viewLaw(r, name, names, maps, at) {
|
|
191
|
+
const ms = names.filter(n => maps.has(n) && !at), ss = names.filter(n => !ms.includes(n));
|
|
192
|
+
return r.law(name, (env) => {
|
|
193
|
+
const flat = ss.map(n => sameIn(env, n, maps.has(n), at?.(env)));
|
|
194
|
+
return ms.length ? forall(k => all(...flat, ...ms.map(n => sameIn(env, n, true)(k)))) : all(...flat);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
const refusalLaw = (r) => r.law('the two runs refuse the same requests', (env) => env['split$'].eq(0));
|
|
198
|
+
const unknownNames = (names, v, what) => { const bad = names.filter(n => !v.scalars.includes(n) && !v.maps.includes(n)); if (bad.length)
|
|
199
|
+
throw new Error(`${what}: no ${bad.join(', ')} in the rule's state (its names: ${[...v.scalars, ...v.maps].join(', ')})`); };
|
|
200
|
+
// The secret params and inputs never reach `visible`: two runs whose requests (and params) are the same but for the
|
|
201
|
+
// secret ones keep every visible value the same, and refuse the same requests. `visible` defaults to all the state that
|
|
202
|
+
// isn't secret itself.
|
|
203
|
+
export function noninterference(r, o) {
|
|
204
|
+
const s = specOf(r), names = [...s.params, ...s.inputs].map(([n]) => n), vw = stateNames(s);
|
|
205
|
+
const bad = o.secret.filter(n => !names.includes(n));
|
|
206
|
+
if (bad.length)
|
|
207
|
+
throw new Error(`noninterference: ${bad.join(', ')} isn't a param or input of ${s.name} (its params and inputs: ${names.join(', ')})`);
|
|
208
|
+
const visible = o.visible ?? [...vw.scalars, ...vw.maps];
|
|
209
|
+
unknownNames(visible, vw, 'noninterference');
|
|
210
|
+
const p = twoRuns(r, r, { name: `${s.name}: ${o.secret.join(', ')} secret`, shared: names.filter(n => !o.secret.includes(n)), refusals: o.refusals });
|
|
211
|
+
const maps = new Set(vw.maps), name = o.name ?? `${o.secret.join(', ')} never reaches ${visible.join(', ')}`;
|
|
212
|
+
return { name, rule: p, laws: [viewLaw(p, name, visible, maps), ...(o.refusals === 'assumed' ? [] : [refusalLaw(p)])], stepLaws: [],
|
|
213
|
+
helpers: [...vw.scalars, ...vw.maps].filter(n => !visible.includes(n)).map(n => viewLaw(p, `${n} is the same in both runs`, [n], maps)), sides: [r, r], shared: names.filter(n => !o.secret.includes(n)) };
|
|
214
|
+
}
|
|
215
|
+
// Tenant isolation: what the tenant `B` sees is the same whatever the others do. A request is B's where its owner (an
|
|
216
|
+
// input, a string's id or a natural) is B (a new param, `tenant`), or where `owner(env, B)` holds; run a takes every
|
|
217
|
+
// request, run b only B's. B sees the cells of `sees` (maps keyed by the owner) at B, the scalars of `results` after
|
|
218
|
+
// each of B's requests, and whether B's requests are refused. `sees` defaults to every map, `results` to none.
|
|
219
|
+
export function isolation(r, o) {
|
|
220
|
+
const s = specOf(r), vw = stateNames(s), tenant = o.tenant ?? 'tenant';
|
|
221
|
+
if (typeof o.owner === 'string' && !s.inputs.some(([n]) => n === o.owner))
|
|
222
|
+
throw new Error(`isolation: ${o.owner} isn't an input of ${s.name}`);
|
|
223
|
+
const sees = o.sees ?? vw.maps, results = o.results ?? [];
|
|
224
|
+
unknownNames([...sees, ...results], vw, 'isolation');
|
|
225
|
+
const scalarsSeen = sees.filter(n => !vw.maps.includes(n));
|
|
226
|
+
if (scalarsSeen.length)
|
|
227
|
+
throw new Error(`isolation: ${scalarsSeen.join(', ')} isn't a map (what B sees of the state is its cells; a result after B's request goes in results)`);
|
|
228
|
+
// (the owner as a key: a string's id, a natural)
|
|
229
|
+
const keyOf = (x) => (x instanceof Term ? x : x.id ?? (() => { throw new Error('isolation: the owner is a natural or a string'); })());
|
|
230
|
+
const mine = (env) => (typeof o.owner === 'string' ? keyOf(env[o.owner]).eq(env[tenant]) : o.owner(env, env[tenant]));
|
|
231
|
+
if ([...s.params, ...s.inputs].some(([n]) => n === tenant))
|
|
232
|
+
throw new Error(`isolation: ${tenant} is a name of ${s.name} already (name the tenant's param: tenant)`);
|
|
233
|
+
const base = new Rule({ ...s, params: [...s.params, [tenant, nat]] });
|
|
234
|
+
const all2 = [...s.params, ...s.inputs].map(([n]) => n);
|
|
235
|
+
const p = twoRuns(base, base, { name: `${s.name}: isolation of ${typeof o.owner === 'string' ? o.owner : 'the owner'}`, shared: [...all2, tenant], stays: env => not(mine(env)), refusals: o.refusals });
|
|
236
|
+
const maps = new Set(vw.maps), name = o.name ?? `what ${typeof o.owner === 'string' ? o.owner : 'a tenant'} B sees is the same whatever the others do`;
|
|
237
|
+
const at = (env) => env[tenant];
|
|
238
|
+
const laws = [...(sees.length ? [viewLaw(p, `${name}: ${sees.join(', ')} at B`, sees, maps, at)] : []), ...(o.refusals === 'assumed' ? [] : [refusalLaw(p)])];
|
|
239
|
+
const stepLaws = results.length ? [p.stepLaw(`${name}: ${results.join(', ')} of B's requests`, (_b, after) => all(...results.map(n => same(after[`a_${n}`], after[`b_${n}`]))), (env) => mine(env))] : [];
|
|
240
|
+
return { name, rule: p, laws, stepLaws, helpers: vw.maps.filter(n => !sees.includes(n)).map(n => viewLaw(p, `${n} at B is the same in both runs`, [n], maps, at)), sides: [base, base], shared: [...all2, tenant] };
|
|
241
|
+
}
|
|
242
|
+
// A migration: `next` agrees with `old` on every history: after the same requests, every value of the state they share
|
|
243
|
+
// by name (or `visible`) is the same, and they refuse the same requests. The requests and params of one name are one.
|
|
244
|
+
export function agreement(old, next, o = {}) {
|
|
245
|
+
const so = specOf(old), sn = specOf(next), vo = stateNames(so), vn = stateNames(sn);
|
|
246
|
+
const common = (xs, ys) => xs.filter(n => ys.includes(n));
|
|
247
|
+
const visible = o.visible ?? [...common(vo.scalars, vn.scalars), ...common(vo.maps, vn.maps)];
|
|
248
|
+
unknownNames(visible, vo, `agreement: ${so.name}`);
|
|
249
|
+
unknownNames(visible, vn, `agreement: ${sn.name}`);
|
|
250
|
+
const p = twoRuns(old, next, { name: `${sn.name} agrees with ${so.name}`, refusals: o.refusals });
|
|
251
|
+
const maps = new Set(vo.maps), name = o.name ?? `${sn.name} agrees with ${so.name} on ${visible.join(', ')}`;
|
|
252
|
+
const kinds = new Map([...so.params, ...so.inputs]), shared = [...sn.params, ...sn.inputs].map(([n]) => n).filter(n => kinds.has(n));
|
|
253
|
+
return { name, rule: p, laws: [viewLaw(p, name, visible, maps), ...(o.refusals === 'assumed' ? [] : [refusalLaw(p)])], stepLaws: [],
|
|
254
|
+
helpers: [...common(vo.scalars, vn.scalars), ...common(vo.maps, vn.maps)].filter(n => !visible.includes(n)).map(n => viewLaw(p, `${n} is the same in both`, [n], maps)), sides: [old, next], shared };
|
|
255
|
+
}
|
|
256
|
+
// --- proving -----------------------------------------------------------------------------------------------------------
|
|
257
|
+
// A law of one run read in the rule built: its names renamed as the run's.
|
|
258
|
+
export function lift(l, r, prefix, shared) {
|
|
259
|
+
const own = ownNames(specOf(r), new Set(shared)), n = (x) => (own.has(x) ? prefix + x : x);
|
|
260
|
+
const e = (x) => {
|
|
261
|
+
switch (x.op) {
|
|
262
|
+
case 'var': return { op: 'var', name: n(x.name) };
|
|
263
|
+
case 'const': return x;
|
|
264
|
+
case 'mul': return { ...x, a: e(x.a) };
|
|
265
|
+
case 'if': return { op: 'if', c: c(x.c), then: e(x.then), else: e(x.else) };
|
|
266
|
+
case 'get': return { op: 'get', map: n(x.map), key: e(x.key) };
|
|
267
|
+
case 'add':
|
|
268
|
+
case 'sub':
|
|
269
|
+
case 'min':
|
|
270
|
+
case 'max':
|
|
271
|
+
case 'prod': return { ...x, a: e(x.a), b: e(x.b) };
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
const c = (x) => {
|
|
275
|
+
switch (x.op) {
|
|
276
|
+
case 'flag': return { op: 'flag', name: n(x.name) };
|
|
277
|
+
case 'not': return { op: 'not', x: c(x.x) };
|
|
278
|
+
case 'and':
|
|
279
|
+
case 'or': return { op: x.op, xs: x.xs.map(c) };
|
|
280
|
+
case 'all': return { ...x, c: c(x.c), ...(x.witness ? { witness: e(x.witness) } : {}) };
|
|
281
|
+
case '<':
|
|
282
|
+
case '<=':
|
|
283
|
+
case '=': return { ...x, a: e(x.a), b: e(x.b) };
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
if (l.some?.length)
|
|
287
|
+
throw new Error(`${l.name}: a law with "there exists" isn't lifted to two runs`);
|
|
288
|
+
return { name: `${prefix.slice(0, 1)}: ${l.name}`, holds: c(l.holds), ...(l.forall ? { forall: l.forall } : {}), ...(l.keys ? { keys: l.keys } : {}) };
|
|
289
|
+
}
|
|
290
|
+
// The verdict on a law about two runs, with `invariants` (laws of each run's rule, an extraction's own) beside it. The
|
|
291
|
+
// helpers first (Houdini: the set proven together without the search, the one a failed goal names dropped, again), so a
|
|
292
|
+
// law that needs "this hidden value is the same in both runs" is proven with it; then the search, as proveSteps runs it.
|
|
293
|
+
// A run that breaks it is two runs side by side (`run`: its params and requests in the rule built's names).
|
|
294
|
+
export function proveTwoRuns(l, opts = {}) {
|
|
295
|
+
const two = (x) => x.length === 2 && Array.isArray(x[0]);
|
|
296
|
+
const inv = !opts.invariants ? [[], []] : two(opts.invariants) ? opts.invariants : [opts.invariants, opts.invariants];
|
|
297
|
+
const lifted = [...inv[0].map(x => lift(x, l.sides[0], 'a_', l.shared)), ...inv[1].map(x => lift(x, l.sides[1], 'b_', l.shared))];
|
|
298
|
+
let helpers = [...l.helpers];
|
|
299
|
+
for (let round = 0; helpers.length && round <= l.helpers.length; round++) {
|
|
300
|
+
const v = proveSteps(l.rule, [...lifted, ...helpers, ...l.laws], l.stepLaws, { search: false });
|
|
301
|
+
if (v.proven && v.checked)
|
|
302
|
+
return { ...v, found: { ...v.found, laws: [...v.found?.laws ?? [], ...helpers.map(h => ({ law: h, text: h.name }))] }, given: lifted };
|
|
303
|
+
const drop = helpers.find(h => v.goal?.startsWith(h.name));
|
|
304
|
+
if (!drop)
|
|
305
|
+
break;
|
|
306
|
+
helpers = helpers.filter(h => h !== drop);
|
|
307
|
+
}
|
|
308
|
+
const { invariants: _i, ...rest } = opts;
|
|
309
|
+
void _i;
|
|
310
|
+
return { ...proveSteps(l.rule, [...lifted, ...l.laws], l.stepLaws, rest), given: lifted };
|
|
311
|
+
}
|
|
312
|
+
// --- certificates ------------------------------------------------------------------------------------------------------
|
|
313
|
+
// A proven set of laws (and step laws) of a rule as one interchange document (docs/interchange.md), the usual trees its
|
|
314
|
+
// proof, checked by the kernel as it is made: `meta` is kept beside it and never read by a checker (the clauses a law
|
|
315
|
+
// answers, where it is stated), so what a citation says is never what is trusted. Undefined where the kernel doesn't
|
|
316
|
+
// prove the set as given (a proof by k-induction, say, or one the search needed more for).
|
|
317
|
+
export function certify(r, laws, stepLaws = [], meta = {}) {
|
|
318
|
+
const env = globalThis.process?.env ?? {};
|
|
319
|
+
const was = env.GDP_CERT;
|
|
320
|
+
env.GDP_CERT = 'usual';
|
|
321
|
+
try {
|
|
322
|
+
const rr = r.withSumsOf(laws, stepLaws), m = rr.machine, given = [...rr.kindLaws().filter(k => !laws.some(l => l.name === k.name)), ...laws];
|
|
323
|
+
let c;
|
|
324
|
+
if (stepLaws.length) {
|
|
325
|
+
const p = proveStepLaws(m, given, stepLaws);
|
|
326
|
+
if (!p.proven || !p.checked || !p.proof)
|
|
327
|
+
return undefined;
|
|
328
|
+
c = { kind: 'stepLaws', machine: p.machine ?? m, laws: p.laws ?? given, stepLaws: p.stepLaws ?? stepLaws, proof: p.proof };
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
const p = proveLaws(m, given);
|
|
332
|
+
if (!p.proven || !p.checked || !p.proof)
|
|
333
|
+
return undefined;
|
|
334
|
+
c = { kind: 'laws', machine: p.machine ?? m, laws: p.laws ?? given, proof: { instances: p.proof.instances, trees: p.proof.trees } };
|
|
335
|
+
}
|
|
336
|
+
const doc = toInterchange(c, meta);
|
|
337
|
+
return checkCertificate(fromInterchange(JSON.parse(JSON.stringify(doc)))).every(x => x.accepted) ? doc : undefined;
|
|
338
|
+
}
|
|
339
|
+
finally {
|
|
340
|
+
if (was === undefined)
|
|
341
|
+
delete env.GDP_CERT;
|
|
342
|
+
else
|
|
343
|
+
env.GDP_CERT = was;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Certificate, type Json } from './format.js';
|
|
2
|
+
export type Claim = {
|
|
3
|
+
name: string;
|
|
4
|
+
accepted: boolean;
|
|
5
|
+
why?: string;
|
|
6
|
+
};
|
|
7
|
+
export type Report = {
|
|
8
|
+
kind?: string;
|
|
9
|
+
accepted: boolean;
|
|
10
|
+
claims: Claim[];
|
|
11
|
+
malformed?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function checkCertificate(c: Certificate): Claim[];
|
|
14
|
+
export declare function checkDocument(doc: unknown): Report;
|
|
15
|
+
export declare function goalsOf(c: Certificate): Certificate;
|
|
16
|
+
export type { Json };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// The standalone checker (gdp-wired-check): a document in, accepted or refused for each claim out. Every verdict is the
|
|
2
|
+
// trusted kernel's (kernel/kernel.ts, kernel/cyclic.ts, core/check.ts, as they are): each kind's check is the kernel's
|
|
3
|
+
// own entry point where it has one (checkLaws, checkStepLaws, checkKInduction, checkRecur, refuseCyclic, checkQMachine,
|
|
4
|
+
// checkQTree, check), and where it has none, the kernel's goals with the tree named for each (as checkLaws reads them):
|
|
5
|
+
// loops (loopObligations), folds (foldObligations), progress (progressObligations), liveness (livenessParts, then
|
|
6
|
+
// checkStepLaws). Around them, untrusted: reading the document (format.ts) and the guard that it was read faithfully
|
|
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";
|
|
9
|
+
import { descentGoal, mainGoal, premiseGoal, refuseCyclic } from "../kernel/cyclic.js";
|
|
10
|
+
import { FormatError, fromInterchange, resolved, sameJson, toInterchange } from "./format.js";
|
|
11
|
+
const attempt = (f) => { try {
|
|
12
|
+
return { ok: f() };
|
|
13
|
+
}
|
|
14
|
+
catch (e) {
|
|
15
|
+
return { ok: false, why: e instanceof Error ? e.message : String(e) };
|
|
16
|
+
} };
|
|
17
|
+
const treeOk = (g, trees) => trees[g.name] !== undefined && check(g, trees[g.name]);
|
|
18
|
+
// Each goal's own answer, for a refusal's why (never the verdict: that is the kernel's entry point's).
|
|
19
|
+
const failing = (goals, trees) => {
|
|
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`));
|
|
22
|
+
return bad.length ? bad.slice(0, 3).join('; ') + (bad.length > 3 ? `; and ${bad.length - 3} more` : '') : undefined;
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
return e instanceof Error ? e.message : String(e);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
// (A certificate of no claims, an empty set of laws, is the kernel's answer on it all the same: a claim of its own.)
|
|
29
|
+
const all = (names, r, why) => (names.length ? names : ['(no claims)']).map(name => ({ name, accepted: r.ok, ...(r.ok ? {} : { why: r.why ?? why?.() ?? 'refused' }) }));
|
|
30
|
+
// The kernel's verdict on a certificate, for each thing it claims.
|
|
31
|
+
export function checkCertificate(c) {
|
|
32
|
+
switch (c.kind) {
|
|
33
|
+
case 'goals': return c.goals.map(g => { const r = attempt(() => check(g.goal, g.tree)); return { name: g.goal.name, accepted: r.ok, ...(r.ok ? {} : { why: r.why ?? 'the tree doesn\'t refute the goal' }) }; });
|
|
34
|
+
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' }) }; });
|
|
35
|
+
// A set of laws is proven together (each step assumes them all), so each is accepted exactly when the set is.
|
|
36
|
+
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));
|
|
37
|
+
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 })
|
|
38
|
+
?? 'a later step\'s names read before it (the zone condition)');
|
|
39
|
+
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)
|
|
40
|
+
?? failing(() => obligations(c.machine, c.laws, c.proof.laws.instances), c.proof.laws.trees));
|
|
41
|
+
case 'liveness': {
|
|
42
|
+
const r = attempt(() => { const { stay, cover, helps } = livenessParts(c.machine, c.liveness); return checkStepLaws(c.machine, c.laws, [stay, cover, ...helps], c.proof); });
|
|
43
|
+
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));
|
|
44
|
+
}
|
|
45
|
+
// Progress assumes the laws: proven here by their own trees where the document has them, else not accepted.
|
|
46
|
+
case 'progress': {
|
|
47
|
+
if (!c.lawsProof)
|
|
48
|
+
return [{ name: c.progress.name, accepted: false, why: 'the laws it assumes have no proof in this document (lawsProof)' }];
|
|
49
|
+
const lp = c.lawsProof;
|
|
50
|
+
return all([c.progress.name], attempt(() => checkLaws(c.machine, c.laws, lp) && progressObligations(c.machine, c.laws, c.instances, c.progress).every(g => treeOk(g, c.trees))), () => failing(() => obligations(c.machine, c.laws, lp.instances), lp.trees) ?? failing(() => progressObligations(c.machine, c.laws, c.instances, c.progress), c.trees));
|
|
51
|
+
}
|
|
52
|
+
case 'loop': return all([`${c.loop.name} halts`, ...c.laws.map(l => l.name)], attempt(() => loopObligations(c.loop, c.laws, c.rank).every(g => treeOk(g, c.trees))), () => failing(() => loopObligations(c.loop, c.laws, c.rank), c.trees));
|
|
53
|
+
case 'fold': return all(c.laws.map(l => l.name), attempt(() => foldObligations(c.fold, c.laws).every(g => treeOk(g, c.trees))), () => failing(() => foldObligations(c.fold, c.laws), c.trees));
|
|
54
|
+
case 'recur': return all([`${c.loop.name} never ends`], attempt(() => checkRecur(c.loop, c.recur)), () => failing(() => [recurGoal(c.loop, c.recur)], { [recurGoal(c.loop, c.recur).name]: c.recur.tree }) ?? 'the start or the stem');
|
|
55
|
+
case 'cyclic': {
|
|
56
|
+
const why = attempt(() => refuseCyclic(c.cyclic) === undefined);
|
|
57
|
+
return all(c.cyclic.nodes.map(n => n.name), why, () => refuseCyclic(c.cyclic));
|
|
58
|
+
}
|
|
59
|
+
case 'qmachine': return all(c.laws.map(l => l.name), attempt(() => checkQMachine(c.machine, c.laws, c.trees)));
|
|
60
|
+
// A ring's termination: each call's obligation by its cyclic proof (that these are the measure's obligations is
|
|
61
|
+
// read from the ring's definitions, which the format doesn't carry: Lean checks that, Data.lean's termination_by).
|
|
62
|
+
case 'termination': return c.obligations.map(o => { const r = attempt(() => refuseCyclic(o.cyclic) === undefined); return { name: `${o.function}: ${o.law}`, accepted: r.ok, ...(r.ok ? {} : { why: r.why ?? refuseCyclic(o.cyclic) ?? 'refused' }) }; });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// A document's report: read, guarded, checked. Never throws.
|
|
66
|
+
export function checkDocument(doc) {
|
|
67
|
+
let c;
|
|
68
|
+
try {
|
|
69
|
+
c = fromInterchange(doc);
|
|
70
|
+
// The guard: the certificate read, written again, is the document (its columns in any order).
|
|
71
|
+
if (!sameJson(resolved(toInterchange(c, doc.meta)), resolved(doc)))
|
|
72
|
+
return { accepted: false, claims: [], malformed: 'read back, the document is not the same (a field the format drops, or a value it changes)' };
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
return { accepted: false, claims: [], malformed: e instanceof FormatError ? e.message : `unreadable: ${e instanceof Error ? e.message : String(e)}` };
|
|
76
|
+
}
|
|
77
|
+
const claims = checkCertificate(c);
|
|
78
|
+
return { kind: c.kind, accepted: claims.every(x => x.accepted), claims };
|
|
79
|
+
}
|
|
80
|
+
// Every goal the kernel builds for a certificate, with the tree the certificate names for it: the tree part of every
|
|
81
|
+
// check, as a `goals` (or `qgoals`) certificate a second checker reads (interchange/py/check.py checks trees alone).
|
|
82
|
+
// (The checks past trees stay the kernel's: a stem evaluated, a cyclic proof's ranks of one length, the step laws' zone.)
|
|
83
|
+
export function goalsOf(c) {
|
|
84
|
+
const pick = (goals, trees) => goals.flatMap(goal => (trees[goal.name] ? [{ goal, tree: trees[goal.name] }] : []));
|
|
85
|
+
const cyclic = (p) => p.nodes.flatMap(n => [{ goal: mainGoal(p.facts, p.nodes, n), tree: n.main }, ...n.uses.flatMap(u => {
|
|
86
|
+
const m = p.nodes[u.node];
|
|
87
|
+
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 }] : [])] : [];
|
|
88
|
+
})]);
|
|
89
|
+
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)];
|
|
90
|
+
switch (c.kind) {
|
|
91
|
+
case 'goals':
|
|
92
|
+
case 'qgoals': return c;
|
|
93
|
+
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 }] : []; }) };
|
|
94
|
+
case 'laws': return { kind: 'goals', goals: pick(obligations(c.machine, c.laws, c.proof.instances), c.proof.trees) };
|
|
95
|
+
case 'stepLaws': return { kind: 'goals', goals: steps(c, c.stepLaws) };
|
|
96
|
+
case 'liveness': {
|
|
97
|
+
const { stay, cover, helps } = livenessParts(c.machine, c.liveness);
|
|
98
|
+
return { kind: 'goals', goals: steps(c, [stay, cover, ...helps]) };
|
|
99
|
+
}
|
|
100
|
+
case 'kInduction': {
|
|
101
|
+
const start = kInductionStart(c.machine, c.kInduction, c.proof.perStep?.[`${c.kInduction.law.name} @start`] ?? c.proof.instances);
|
|
102
|
+
return { kind: 'goals', goals: [...pick([start], c.proof.trees), ...steps(c, kInductionSteps(c.machine, c.kInduction))] };
|
|
103
|
+
}
|
|
104
|
+
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)] };
|
|
105
|
+
case 'loop': return { kind: 'goals', goals: pick(loopObligations(c.loop, c.laws, c.rank), c.trees) };
|
|
106
|
+
case 'fold': return { kind: 'goals', goals: pick(foldObligations(c.fold, c.laws), c.trees) };
|
|
107
|
+
case 'recur': return { kind: 'goals', goals: [{ goal: recurGoal(c.loop, c.recur), tree: c.recur.tree }] };
|
|
108
|
+
case 'cyclic': return { kind: 'goals', goals: cyclic(c.cyclic) };
|
|
109
|
+
case 'termination': return { kind: 'goals', goals: c.obligations.flatMap(o => cyclic(o.cyclic)) };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type { C, E, Law, Machine } from '../core/machine.js';
|
|
2
|
+
import type { Fold, Goal, Instances, KInduction, Liveness, Loop, QC, QE, QGoal, QLaw, QMachine, Recur, StepLaw, Tree } from '../kernel/kernel.js';
|
|
3
|
+
import type { Cyclic } from '../kernel/cyclic.js';
|
|
4
|
+
import type { Lin } from '../core/solver.js';
|
|
5
|
+
export declare const FORMAT = "gdp-wired-interchange", VERSION = "1.0";
|
|
6
|
+
export type LawsProof = {
|
|
7
|
+
instances: Record<string, Instances>;
|
|
8
|
+
trees: Record<string, Tree>;
|
|
9
|
+
};
|
|
10
|
+
export type StepProof = {
|
|
11
|
+
laws: LawsProof;
|
|
12
|
+
instances: Instances;
|
|
13
|
+
perStep?: Record<string, Instances>;
|
|
14
|
+
trees: Record<string, Tree>;
|
|
15
|
+
};
|
|
16
|
+
export type Progress = {
|
|
17
|
+
name: string;
|
|
18
|
+
when: C;
|
|
19
|
+
then: C;
|
|
20
|
+
request: Record<string, E>;
|
|
21
|
+
};
|
|
22
|
+
export type Measure = {
|
|
23
|
+
comps: {
|
|
24
|
+
coef: number[];
|
|
25
|
+
c: number;
|
|
26
|
+
}[];
|
|
27
|
+
};
|
|
28
|
+
export type Obligation = {
|
|
29
|
+
function: string;
|
|
30
|
+
law: string;
|
|
31
|
+
cyclic: Cyclic;
|
|
32
|
+
};
|
|
33
|
+
export type Certificate = {
|
|
34
|
+
kind: 'goals';
|
|
35
|
+
goals: {
|
|
36
|
+
goal: Goal;
|
|
37
|
+
tree: Tree;
|
|
38
|
+
}[];
|
|
39
|
+
} | {
|
|
40
|
+
kind: 'laws';
|
|
41
|
+
machine: Machine;
|
|
42
|
+
laws: Law[];
|
|
43
|
+
proof: LawsProof;
|
|
44
|
+
} | {
|
|
45
|
+
kind: 'stepLaws';
|
|
46
|
+
machine: Machine;
|
|
47
|
+
laws: Law[];
|
|
48
|
+
stepLaws: StepLaw[];
|
|
49
|
+
proof: StepProof;
|
|
50
|
+
} | {
|
|
51
|
+
kind: 'kInduction';
|
|
52
|
+
machine: Machine;
|
|
53
|
+
laws: Law[];
|
|
54
|
+
kInduction: KInduction;
|
|
55
|
+
proof: StepProof;
|
|
56
|
+
} | {
|
|
57
|
+
kind: 'progress';
|
|
58
|
+
machine: Machine;
|
|
59
|
+
laws: Law[];
|
|
60
|
+
progress: Progress;
|
|
61
|
+
instances: Instances;
|
|
62
|
+
trees: Record<string, Tree>;
|
|
63
|
+
lawsProof?: LawsProof;
|
|
64
|
+
} | {
|
|
65
|
+
kind: 'liveness';
|
|
66
|
+
machine: Machine;
|
|
67
|
+
laws: Law[];
|
|
68
|
+
liveness: Liveness;
|
|
69
|
+
proof: StepProof;
|
|
70
|
+
} | {
|
|
71
|
+
kind: 'loop';
|
|
72
|
+
loop: Loop;
|
|
73
|
+
laws: Law[];
|
|
74
|
+
rank: E | E[];
|
|
75
|
+
trees: Record<string, Tree>;
|
|
76
|
+
} | {
|
|
77
|
+
kind: 'recur';
|
|
78
|
+
loop: Loop;
|
|
79
|
+
recur: Recur;
|
|
80
|
+
} | {
|
|
81
|
+
kind: 'fold';
|
|
82
|
+
fold: Fold;
|
|
83
|
+
laws: Law[];
|
|
84
|
+
trees: Record<string, Tree>;
|
|
85
|
+
} | {
|
|
86
|
+
kind: 'cyclic';
|
|
87
|
+
cyclic: Cyclic;
|
|
88
|
+
} | {
|
|
89
|
+
kind: 'qgoals';
|
|
90
|
+
goals: {
|
|
91
|
+
goal: QGoal;
|
|
92
|
+
tree: Tree;
|
|
93
|
+
}[];
|
|
94
|
+
} | {
|
|
95
|
+
kind: 'qmachine';
|
|
96
|
+
machine: QMachine;
|
|
97
|
+
laws: QLaw[];
|
|
98
|
+
trees: Record<string, {
|
|
99
|
+
start: Tree;
|
|
100
|
+
step: Tree;
|
|
101
|
+
}>;
|
|
102
|
+
} | {
|
|
103
|
+
kind: 'termination';
|
|
104
|
+
functions: string[];
|
|
105
|
+
text: string;
|
|
106
|
+
measures: Measure[];
|
|
107
|
+
obligations: Obligation[];
|
|
108
|
+
};
|
|
109
|
+
export type Kind = Certificate['kind'];
|
|
110
|
+
export declare const KINDS: Kind[];
|
|
111
|
+
export type Json = null | boolean | number | string | Json[] | {
|
|
112
|
+
[key: string]: Json | undefined;
|
|
113
|
+
};
|
|
114
|
+
export type Document = {
|
|
115
|
+
format: string;
|
|
116
|
+
version: string;
|
|
117
|
+
kind: Kind;
|
|
118
|
+
meta?: Json;
|
|
119
|
+
columns?: Json[];
|
|
120
|
+
[field: string]: Json | undefined;
|
|
121
|
+
};
|
|
122
|
+
export declare class FormatError extends Error {
|
|
123
|
+
}
|
|
124
|
+
export declare function encE(e: E, at?: string): Json;
|
|
125
|
+
export declare function decE(x: unknown, at?: string): E;
|
|
126
|
+
export declare function encC(c: C, at?: string): Json;
|
|
127
|
+
export declare function decC(x: unknown, at?: string): C;
|
|
128
|
+
export declare function encQE(e: QE, at?: string): Json;
|
|
129
|
+
export declare function decQE(x: unknown, at?: string): QE;
|
|
130
|
+
export declare function encQC(c: QC, at?: string): Json;
|
|
131
|
+
export declare function decQC(x: unknown, at?: string): QC;
|
|
132
|
+
type Columns = {
|
|
133
|
+
terms: Json[];
|
|
134
|
+
index: Map<string, number>;
|
|
135
|
+
} | {
|
|
136
|
+
read: E[];
|
|
137
|
+
};
|
|
138
|
+
export declare function encLin(lin: Lin, cols: Columns, at?: string): Json;
|
|
139
|
+
export declare function decLin(x: unknown, cols: Columns, at?: string): Lin;
|
|
140
|
+
export declare function encTree(t: Tree, cols: Columns, at?: string): Json;
|
|
141
|
+
export declare function decTree(x: unknown, cols: Columns, at?: string): Tree;
|
|
142
|
+
export declare function encMachine(m: Machine, at?: string): Json;
|
|
143
|
+
export declare function decMachine(x: unknown, at?: string): Machine;
|
|
144
|
+
export declare function encLaw(l: Law, at?: string): Json;
|
|
145
|
+
export declare function decLaw(x: unknown, at?: string): Law;
|
|
146
|
+
export declare function toInterchange(c: Certificate, meta?: Json): Document;
|
|
147
|
+
export declare function fromInterchange(doc: unknown): Certificate;
|
|
148
|
+
export declare function resolved(doc: Document): Json;
|
|
149
|
+
export declare function sameJson(a: Json | undefined, b: Json | undefined): boolean;
|
|
150
|
+
export {};
|