gdp-wired 0.28.0 → 0.30.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/dist/core/cycles.js +30 -3
- package/dist/core/data.d.ts +4 -0
- package/dist/core/data.js +188 -24
- package/dist/core/dsl.d.ts +11 -1
- package/dist/core/dsl.js +106 -11
- package/dist/core/extract-read.d.ts +1 -1
- package/dist/core/extract-read.js +4 -3
- package/dist/core/extract-shapes.js +9 -4
- package/dist/core/extract-xstate.js +89 -10
- package/dist/core/fresh.js +16 -1
- package/dist/core/infer.js +819 -188
- package/dist/core/machine.d.ts +5 -0
- package/dist/core/machine.js +3 -3
- package/dist/kernel/cdcl.d.ts +34 -11
- package/dist/kernel/cdcl.js +601 -60
- package/dist/kernel/kernel.d.ts +17 -1
- package/dist/kernel/kernel.js +187 -11
- package/dist/kernel/prove.d.ts +5 -1
- package/dist/kernel/prove.js +200 -63
- package/dist/kernel/reader.d.ts +35 -1
- package/dist/kernel/reader.js +342 -7
- package/dist/kernel/simplex.d.ts +3 -0
- package/dist/kernel/simplex.js +52 -6
- package/dist/lean-kernel/emit.d.ts +12 -0
- package/dist/lean-kernel/emit.js +108 -14
- package/dist/lean-kernel/library.js +2 -1
- package/package.json +3 -2
package/dist/lean-kernel/emit.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { atMost, n, not, pointWrite } from "../core/machine.js";
|
|
2
2
|
import { add, k, scale, sub } from "../core/solver.js";
|
|
3
|
-
import { boundOf, caseGoals, check, checkRecur, checkRecurCases, coverGoal, recurGoal, canon, decided, factorsOf, isCell, isMonomial, columnTerm, stateName, termColumn, truth, historyMachine, foldObligations, kInductionStart, kInductionSteps, leafConstraints, loopLiveness, loopMachine, linear, livenessHelpful, livenessParts, livenessRanks, loopObligations, trueC, obligations, progressObligations, stepLawObligations, substC, witnessesOf, withProducts } from "../kernel/kernel.js";
|
|
4
|
-
import { grow, minimal, proveBuilt, proveLaws, proveStepLaws, withDeadline } from "../kernel/prove.js";
|
|
3
|
+
import { boundOf, caseGoals, check, checkRecur, checkRecurCases, coverGoal, recurGoal, canon, decided, factorsOf, isCell, isMonomial, columnTerm, stateName, termColumn, truth, historyMachine, sumMachine, sumCovers, sumParts, foldObligations, kInductionStart, kInductionSteps, leafConstraints, loopLiveness, loopMachine, linear, livenessHelpful, livenessParts, livenessLevels, livenessRanks, strongly, loopObligations, trueC, obligations, progressObligations, stepLawObligations, substC, witnessesOf, withProducts } from "../kernel/kernel.js";
|
|
4
|
+
import { chooseLevels, grow, minimal, proveBuilt, proveLaws, proveStepLaws, withDeadline } from "../kernel/prove.js";
|
|
5
5
|
import { refinement, refinementSides } from "../core/compose.js";
|
|
6
6
|
import { leanSurface, leanTerms } from "./lean-terms.js";
|
|
7
7
|
import { descentGoal, mainGoal, premiseGoal } from "../kernel/cyclic.js";
|
|
@@ -948,7 +948,10 @@ function machineNames(m, laws, allSteps, stepLaws, opts) {
|
|
|
948
948
|
export function smachineToLean(id, given, laws, opts = {}) {
|
|
949
949
|
const hm = given.history ? { ...given, history: { ...given.history, prune: undefined } } : undefined;
|
|
950
950
|
const hplain = hm ? historyMachine(hm) : undefined, stepLaws = opts.stepLaws ?? [], rf = opts.refined, gv = opts.ghosts ?? [];
|
|
951
|
-
|
|
951
|
+
// A machine with sums goes as its plain machine too (kernel.ts's sumMachine), built in Lean (Sums.lean's
|
|
952
|
+
// SumMachine.plain) from the rule without them and the sums.
|
|
953
|
+
const sm = !hm && given.sums && Object.keys(given.sums).length ? given : undefined;
|
|
954
|
+
const m = hplain ? hplain.machine : sm ? sumMachine(sm).machine : given;
|
|
952
955
|
const claims = [];
|
|
953
956
|
const claimSteps = () => claims.flatMap(cl => cl.steps);
|
|
954
957
|
// A step law's SKStep literal: its whens, then, the names its later requests and states are read by, its proof.
|
|
@@ -1017,22 +1020,68 @@ theorem ${id}_refines : ∀ ρ M, SReach ${id}_refined.impl ρ M → ∃ ρc Mc
|
|
|
1017
1020
|
} });
|
|
1018
1021
|
// Liveness (Live.lean's sleads_sound): its step laws (stay, cover, one per helpful request), and where each helpful
|
|
1019
1022
|
// request is proven allowed in its region, the same under weak fairness (sleads_wf_sound).
|
|
1020
|
-
for (const [j,
|
|
1023
|
+
for (const [j, l0] of (opts.liveness ?? []).entries()) {
|
|
1024
|
+
// (strong fairness: the levels the helpful requests hand over by, chosen as proveLiveness chooses them)
|
|
1025
|
+
const l = strongly(l0) && !l0.levels && livenessHelpful(l0).length > 1 ? { ...l0, levels: chooseLevels(sm ?? m, laws, l0) ?? livenessLevels(l0) } : l0;
|
|
1021
1026
|
const { stay, cover, helps } = livenessParts(m, l), helpful = livenessHelpful(l), lid = `${id}_live${j}`;
|
|
1022
1027
|
const allows = helps.map((hs, i) => ({ when: hs.when, request: helpful[i].request }));
|
|
1028
|
+
if (strongly(l)) {
|
|
1029
|
+
claims.push({ steps: [stay, cover, ...helps], allows, render: h => {
|
|
1030
|
+
const al = allows.map(h.allow);
|
|
1031
|
+
if (!al.every(a => a !== undefined))
|
|
1032
|
+
throw new Error(`${id}: ${l.name}: under strong fairness each helpful request is shown allowed in its region`);
|
|
1033
|
+
const own = sm ? `${id}_sums.s.f.m.assume` : `${id}_machine.f.m.assume`;
|
|
1034
|
+
return `-- Liveness under strong fairness: ${l.name}
|
|
1035
|
+
def ${lid} : Live := ${liveLit(l, { e, c }, ix, list(Object.keys(m.state).map(s2 => `(${ix(s2)}, ${ix(`${s2}'`)})`)), list(Object.keys(m.maps ?? {}).map(mp => `(${mx(mp)}, ${mx(`${mp}'`)})`)))}
|
|
1036
|
+
def ${lid}_lv : List Nat := ${list(livenessLevels(l).map(String))}
|
|
1037
|
+
def ${lid}_sp : SProof := ${h.sproof(stay)}
|
|
1038
|
+
def ${lid}_cp : SProof := ${h.sproof(cover)}
|
|
1039
|
+
def ${lid}_hp : List SProof := ${list(helps.map(h.sproof))}
|
|
1040
|
+
def ${lid}_ap : List (List (Nat × E) × SProof × List E) := ${list(al)}
|
|
1041
|
+
theorem ${lid}_ok : sliveOk ${id}_machine ${lid} = true := by ${checkBy}
|
|
1042
|
+
theorem ${lid}_stay : checkSKStep ${id}_machine ${id}_proof (sliveStep ${lid} ${lid}.pend (liveStaySC ${lid}) ${lid}_sp) = true := by ${checkBy}
|
|
1043
|
+
theorem ${lid}_cover : checkSKStep ${id}_machine ${id}_proof (sliveStep ${lid} ${lid}.pend (liveCoverC ${lid}) ${lid}_cp) = true := by ${checkBy}
|
|
1044
|
+
theorem ${lid}_helps : sliveHelpsOkS ${id}_machine ${id}_proof ${lid} ${lid}_lv ${lid}_hp = true := by ${checkBy}
|
|
1045
|
+
theorem ${lid}_allows : sliveAllowsOkA ${id}_machine ${id}_proof ${lid} ${lid}_ap ${own} = true := by ${checkBy}
|
|
1046
|
+
/-- ${l.name}, under strong fairness: along every run that takes each helpful request in its region infinitely often
|
|
1047
|
+
wherever, infinitely often, it is allowed there, \`from\` is followed by \`to\`. -/
|
|
1048
|
+
theorem ${lid}_holds (run : SRun ${id}_machine)
|
|
1049
|
+
(fair : ∀ h ∈ ${lid}.helps, (∀ n, ∃ m, n ≤ m ∧ evalC (run.st m).1 (run.st m).2 h.1 = true ∧ ∃ ι κ, (∀ p ∈ h.2, ι p.1 = evalE (run.st m).1 (run.st m).2 p.2)
|
|
1050
|
+
∧ evalC (sView ${id}_machine (run.st m).1 (run.st m).2 ι κ).1 (sView ${id}_machine (run.st m).1 (run.st m).2 ι κ).2 ${own} = true) →
|
|
1051
|
+
∀ n, ∃ m, n ≤ m ∧ evalC (run.st m).1 (run.st m).2 h.1 = true ∧ ∀ p ∈ h.2, (run.req m).1 p.1 = evalE (run.st m).1 (run.st m).2 p.2) :
|
|
1052
|
+
∀ n, evalC (run.st n).1 (run.st n).2 ${lid}.from_ = true → ∃ m, n ≤ m ∧ evalC (run.st m).1 (run.st m).2 ${lid}.to = true :=
|
|
1053
|
+
sleads_sf_soundA ${id}_machine ${id}_proof ${lid} ${lid}_lv _ _ _ _ _ ${id}_check ${lid}_ok ${lid}_stay ${lid}_cover ${lid}_helps ${lid}_allows run fair${j === 0 ? (opts.liveTampers ?? []).map(t => {
|
|
1054
|
+
const L = `(${liveLit(t.l, { e, c }, ix, list(Object.keys(m.state).map(s2 => `(${ix(s2)}, ${ix(`${s2}'`)})`)), list(Object.keys(m.maps ?? {}).map(mp => `(${mx(mp)}, ${mx(`${mp}'`)})`)))} : Live)`;
|
|
1055
|
+
const steps = strongly(t.l) ? `checkSKStep ${id}_machine ${id}_proof (sliveStep ${L} ${L}.pend (liveStaySC ${L}) ${lid}_sp)
|
|
1056
|
+
&& checkSKStep ${id}_machine ${id}_proof (sliveStep ${L} ${L}.pend (liveCoverC ${L}) ${lid}_cp) && sliveHelpsOkS ${id}_machine ${id}_proof ${L} ${list(livenessLevels(t.l).map(String))} ${lid}_hp`
|
|
1057
|
+
: `checkSKStep ${id}_machine ${id}_proof (sliveStep ${L} ${L}.pend (liveStayC ${L}) ${lid}_sp)
|
|
1058
|
+
&& checkSKStep ${id}_machine ${id}_proof (sliveStep ${L} ${L}.pend (liveCoverC ${L}) ${lid}_cp) && sliveHelpsOk ${id}_machine ${id}_proof ${L} ${lid}_hp`;
|
|
1059
|
+
return `\n-- TAMPERED: ${t.what}. Lean computes the check to ${t.expect}, kernel.ts's answer.\nexample : (${steps}) = ${t.expect} := by ${checkBy}`;
|
|
1060
|
+
}).join('') : ''}`;
|
|
1061
|
+
} });
|
|
1062
|
+
continue;
|
|
1063
|
+
}
|
|
1023
1064
|
claims.push({ steps: [stay, cover, ...helps], allows, render: h => {
|
|
1024
1065
|
const al = allows.map(h.allow);
|
|
1025
1066
|
const wf = al.every(a => a !== undefined) ? `
|
|
1026
1067
|
def ${lid}_ap : List (List (Nat × E) × SProof × List E) := ${list(al)}
|
|
1027
|
-
theorem ${lid}_allows : sliveAllowsOk ${id}_machine ${id}_proof ${lid} ${lid}_ap = true := by ${checkBy}
|
|
1068
|
+
theorem ${lid}_allows : ${sm ? `sliveAllowsOkA ${id}_machine ${id}_proof ${lid} ${lid}_ap ${id}_sums.s.f.m.assume` : `sliveAllowsOk ${id}_machine ${id}_proof ${lid} ${lid}_ap`} = true := by ${checkBy}
|
|
1028
1069
|
/-- ${l.name}, under weak fairness: along every run that takes each helpful request whenever, from some point on, it
|
|
1029
1070
|
stays allowed, \`from\` is followed by \`to\`. -/
|
|
1030
1071
|
theorem ${lid}_holds_wf (run : SRun ${id}_machine)
|
|
1031
1072
|
(fair : ∀ h ∈ ${lid}.helps, ∀ n, (∀ m, n ≤ m → ∃ ι κ, (∀ p ∈ h.2, ι p.1 = evalE (run.st m).1 (run.st m).2 p.2)
|
|
1032
|
-
∧ evalC (sView ${id}_machine (run.st m).1 (run.st m).2 ι κ).1 (sView ${id}_machine (run.st m).1 (run.st m).2 ι κ).2 ${id}_machine.f.m.assume = true) →
|
|
1073
|
+
∧ evalC (sView ${id}_machine (run.st m).1 (run.st m).2 ι κ).1 (sView ${id}_machine (run.st m).1 (run.st m).2 ι κ).2 ${sm ? `${id}_sums.s` : `${id}_machine`}.f.m.assume = true) →
|
|
1074
|
+
∃ m, n ≤ m ∧ ∀ p ∈ h.2, (run.req m).1 p.1 = evalE (run.st m).1 (run.st m).2 p.2) :
|
|
1075
|
+
∀ n, evalC (run.st n).1 (run.st n).2 ${lid}.from_ = true → ∃ m, n ≤ m ∧ evalC (run.st m).1 (run.st m).2 ${lid}.to = true :=
|
|
1076
|
+
${sm ? `sleads_wf_soundA ${id}_machine ${id}_proof ${lid} _ _ _ _ _ ${id}_check ${lid}_ok ${lid}_stay ${lid}_cover ${lid}_helps ${lid}_allows run fair` : `sleads_wf_sound ${id}_machine ${id}_proof ${lid} _ _ _ _ ${id}_check ${lid}_ok ${lid}_stay ${lid}_cover ${lid}_helps ${lid}_allows run fair`}${sm ? `
|
|
1077
|
+
/-- ${l.name}, for the rule with its sums under weak fairness of its own assumption: along every run of requests the
|
|
1078
|
+
rule allows, each helpful request taken whenever, from some point on, the rule allows it. -/
|
|
1079
|
+
theorem ${lid}_sums_wf (run : SumRun ${id}_sums)
|
|
1080
|
+
(fair : ∀ h ∈ ${lid}.helps, ∀ n, (∀ m, n ≤ m → ∃ ι κ, (∀ p ∈ h.2, ι p.1 = evalE (run.st m).1 (run.st m).2 p.2)
|
|
1081
|
+
∧ evalC (sView ${id}_machine (run.st m).1 (run.st m).2 ι κ).1 (sView ${id}_machine (run.st m).1 (run.st m).2 ι κ).2 ${id}_sums.s.f.m.assume = true) →
|
|
1033
1082
|
∃ m, n ≤ m ∧ ∀ p ∈ h.2, (run.req m).1 p.1 = evalE (run.st m).1 (run.st m).2 p.2) :
|
|
1034
1083
|
∀ n, evalC (run.st n).1 (run.st n).2 ${lid}.from_ = true → ∃ m, n ≤ m ∧ evalC (run.st m).1 (run.st m).2 ${lid}.to = true :=
|
|
1035
|
-
|
|
1084
|
+
sumleads_wf_sound ${id}_sums ${id}_covers ${id}_proof ${lid} _ _ _ _ ${id}_scheck ${id}_check ${lid}_ok ${lid}_stay ${lid}_cover ${lid}_helps ${lid}_allows run fair` : ''}` : '';
|
|
1036
1085
|
return `-- Liveness: ${l.name}
|
|
1037
1086
|
def ${lid} : Live := ${liveLit(l, { e, c }, ix, list(Object.keys(m.state).map(s2 => `(${ix(s2)}, ${ix(`${s2}'`)})`)), list(Object.keys(m.maps ?? {}).map(mp => `(${mx(mp)}, ${mx(`${mp}'`)})`)))}
|
|
1038
1087
|
def ${lid}_sp : SProof := ${h.sproof(stay)}
|
|
@@ -1133,7 +1182,7 @@ theorem ${id}_orig_laws : ∀ ρ M, SReach ${id}_ghosted.orig ρ M → ∀ e ∈
|
|
|
1133
1182
|
...Array.from({ length: Math.floor(qi.length / n) }, (_, t) => ({ op: 'or', xs: [eqC({ op: 'var', name: `?${f}` }, zero1(0)), at(qi.slice(t * n, (t + 1) * n))] })),
|
|
1134
1183
|
{ op: 'or', xs: [eqC({ op: 'var', name: `?${f}` }, zero1(1)), { op: 'not', x: at(qwits(f).map((name) => ({ op: 'var', name }))) }] }];
|
|
1135
1184
|
})];
|
|
1136
|
-
const last = { op: 'not', x: sInline(m.assume ?? trueC) }, zkeys = carriedKeys([...base, last]);
|
|
1185
|
+
const last = { op: 'not', x: sInline((sm ? sm.assume : m.assume) ?? trueC) }, zkeys = carriedKeys([...base, last]);
|
|
1137
1186
|
return { name: 'allowed', hyps: [...base, ...(m.inputMaps ?? []).flatMap(mp => zkeys.map(t => eqC({ op: 'get', map: mp, key: t }, zero1(0)))), last], zkeys };
|
|
1138
1187
|
};
|
|
1139
1188
|
const allowed = new Map(claims.flatMap(cl => cl.allows).map(a => [a, withWitness(m, a.request, wit => {
|
|
@@ -1141,8 +1190,11 @@ theorem ${id}_orig_laws : ∀ ρ M, SReach ${id}_ghosted.orig ρ M → ∀ e ∈
|
|
|
1141
1190
|
return r2.proven ? r2 : undefined;
|
|
1142
1191
|
})]));
|
|
1143
1192
|
const allowGoals = [...allowed.values()].flatMap(a => (a ? [a.out.goal] : []));
|
|
1193
|
+
// Each sum's cover goals (kernel.ts builds them as Sums.lean's sumCoverGoal does), per sum in order.
|
|
1194
|
+
const covers = sm ? Object.keys(sm.sums).map(s2 => sumMachine(sm).goals.filter(g => g.name.startsWith(`${s2} @cover `))) : [];
|
|
1144
1195
|
const named = machineNames(m, laws, allSteps, stepLaws, { ...opts, ...(hm ? { record: hm.history.record } : {}) });
|
|
1145
|
-
const
|
|
1196
|
+
const sumNames = sm ? Object.entries(sm.sums).flatMap(([s2, sum]) => { const { flag, x } = sumParts(s2); return [s2, sum.key, `?${flag}`, `w?${flag}`, x]; }) : [];
|
|
1197
|
+
const vars = [...new Set([...named.vars, ...sumNames, ...[...goalsL, ...goalsS, ...allowGoals, ...(hplain?.goals ?? []), ...covers.flat(), ...(opts.kind ? [opts.kind.start.goal] : [])].flatMap(g => g.hyps.flatMap(varsOf))])];
|
|
1146
1198
|
const mapNames = [...new Set([...named.maps, ...[...JSON.stringify([...goalsL, ...goalsS, ...allowGoals]).matchAll(/"op":"get","map":"([^"]+)"/g)].map(x2 => x2[1])])];
|
|
1147
1199
|
const enc = (g, tree) => encode({ name: `${id}: ${g.name}`, goal: g, tree }, false, true, vars, mapNames);
|
|
1148
1200
|
const { e, c } = leanTerms(vars, mapNames, id);
|
|
@@ -1172,6 +1224,45 @@ theorem ${id}_orig_laws : ∀ ρ M, SReach ${id}_ghosted.orig ρ M → ∀ e ∈
|
|
|
1172
1224
|
${list(rels.map(rel => { if (rel.holds.op !== '<=')
|
|
1173
1225
|
throw new Error(`${id}: a relation is a <= b`); return `(${c(rel.when)}, ${e(rel.holds.a)}, ${e(rel.holds.b)})`; }))}⟩`;
|
|
1174
1226
|
};
|
|
1227
|
+
// The sums: the rule without them (its state without their variables) and each sum (Sums.lean's SumDecl: the
|
|
1228
|
+
// variable, the term's key, the term, the cover keys, the quantified flag and its witness, the cover goals' key).
|
|
1229
|
+
const sumsDef = () => {
|
|
1230
|
+
const sums = Object.entries(sm.sums), cov = sumCovers(sm);
|
|
1231
|
+
const base = { ...sm, sums: undefined, state: Object.fromEntries(Object.entries(sm.state).filter(([n2]) => !(n2 in sm.sums))) };
|
|
1232
|
+
return `def ${id}_sums : SumMachine := ⟨${lit(base)},
|
|
1233
|
+
${list(sums.map(([s2, sum]) => { const { flag, x } = sumParts(s2); return `⟨${ix(s2)}, ${ix(sum.key)}, ${e(sum.term)}, ${list(cov[s2].map(e))}, ${ix(`?${flag}`)}, ${ix(`w?${flag}`)}, ${ix(x)}⟩`; }))}⟩
|
|
1234
|
+
def ${id}_machine : SMachine := ${id}_sums.plain`;
|
|
1235
|
+
};
|
|
1236
|
+
// Each cover goal's tree, the sums' check, and what it gives: each sum exact, the rule's assumption the plain
|
|
1237
|
+
// machine's, the laws.
|
|
1238
|
+
const sumsBlock = () => {
|
|
1239
|
+
const trees = covers.map(gs => list(gs.map(g => {
|
|
1240
|
+
const t2 = opts.coverTrees?.[g.name] ?? (() => { const out = grow(g); if (!('tree' in out))
|
|
1241
|
+
throw new Error(`${id}: ${g.name} not proven`); return out.tree; })();
|
|
1242
|
+
const x2 = enc(g, t2);
|
|
1243
|
+
return `(${x2.tab}, ${x2.tree})`;
|
|
1244
|
+
})));
|
|
1245
|
+
const tamperLit = (t) => {
|
|
1246
|
+
const cov = t.covers ?? sumCovers(t.m), base = { ...t.m, sums: undefined, state: Object.fromEntries(Object.entries(t.m.state).filter(([n2]) => !(n2 in t.m.sums))) };
|
|
1247
|
+
return `(⟨${lit(base)},
|
|
1248
|
+
${list(Object.entries(t.m.sums).map(([s2, sum]) => { const { flag, x } = sumParts(s2); return `⟨${ix(s2)}, ${ix(sum.key)}, ${e(sum.term)}, ${list(cov[s2].map(e))}, ${ix(`?${flag}`)}, ${ix(`w?${flag}`)}, ${ix(x)}⟩`; }))}⟩ : SumMachine)`;
|
|
1249
|
+
};
|
|
1250
|
+
const tampered = (opts.sumTampers ?? []).map(t => `-- TAMPERED: ${t.what}. Lean computes the check to ${t.expect}, kernel.ts's answer.
|
|
1251
|
+
example : (checkSums ${tamperLit(t)} ${id}_covers && checkSMachine ${tamperLit(t)}.plain ${id}_proof) = ${t.expect} := by ${checkBy}`);
|
|
1252
|
+
return `
|
|
1253
|
+
def ${id}_covers : List (List (List VDef × Tree)) := ${list(trees)}
|
|
1254
|
+
theorem ${id}_scheck : checkSums ${id}_sums ${id}_covers = true := by ${checkBy}
|
|
1255
|
+
/-- Each sum's variable is, in every state the machine reaches, the sum over every key of its term there. -/
|
|
1256
|
+
theorem ${id}_exact : ∀ ρ M, SReach ${id}_machine ρ M → ∀ d ∈ ${id}_sums.sums, IsSum (gAt d.g M) (ρ d.v) :=
|
|
1257
|
+
sum_holds ${id}_sums ${id}_scheck
|
|
1258
|
+
/-- There the machine allows a request exactly when the rule's own assumption does. -/
|
|
1259
|
+
theorem ${id}_own : ∀ ρ M, SReach ${id}_machine ρ M → ∀ ι κ, evalC (sView ${id}_machine ρ M ι κ).1 (sView ${id}_machine ρ M ι κ).2 ${id}_machine.f.m.assume
|
|
1260
|
+
= evalC (sView ${id}_machine ρ M ι κ).1 (sView ${id}_machine ρ M ι κ).2 ${id}_sums.s.f.m.assume :=
|
|
1261
|
+
sum_allowed ${id}_sums ${id}_scheck (sOk_of ${id}_check)
|
|
1262
|
+
${Object.entries(sm.sums).map(([s2, sum], j) => `/-- ${s2}: the sum over every key of its term (Sums.lean's IsSum). -/
|
|
1263
|
+
theorem ${id}_sum${j} : ∀ ρ M, SReach ${id}_machine ρ M → IsSum (gAt (${e(sum.term)}) M) (ρ ${ix(s2)}) :=
|
|
1264
|
+
fun ρ M h => ${id}_exact ρ M h (${id}_sums.sums[${j}]'(by decide)) (List.getElem_mem (by decide))`).join('\n')}${tampered.length ? `\n${tampered.join('\n')}` : ''}`;
|
|
1265
|
+
};
|
|
1175
1266
|
// Each relation's record goal and its tree, the history's check, and the laws over histories.
|
|
1176
1267
|
const histBlock = () => {
|
|
1177
1268
|
const records = hplain.goals.map(g => { const out = grow(g); if (!('tree' in out))
|
|
@@ -1239,14 +1330,14 @@ def ${id}_machine : SMachine := ${id}_refined.full` : gv.length ? `def ${id}_gho
|
|
|
1239
1330
|
${list(gv.map(v2 => `(${ix(v2)}, ${e(m.state[v2])}, ${e(m.step.state?.[v2] ?? { op: 'var', name: v2 })})`))}⟩
|
|
1240
1331
|
def ${id}_machine : SMachine := ${id}_ghosted.full
|
|
1241
1332
|
theorem ${id}_ghostOk : sghostOk ${id}_ghosted = true := by ${checkBy}` : hm ? `def ${id}_hist : HMachine := ${hlit(hm.history.relations ?? [])}
|
|
1242
|
-
def ${id}_machine : SMachine := ${id}_hist.plain` : lp0 ? `def ${id}_loop : Loop := ${loopLit(lp0.loop)}
|
|
1333
|
+
def ${id}_machine : SMachine := ${id}_hist.plain` : sm ? sumsDef() : lp0 ? `def ${id}_loop : Loop := ${loopLit(lp0.loop)}
|
|
1243
1334
|
def ${id}_machine : SMachine := ${id}_loop.machine` : `def ${id}_machine : SMachine := ${lit(m)}`}
|
|
1244
1335
|
${entries.join('\n')}
|
|
1245
1336
|
def ${id}_proof : List SEntry := ${list(laws.map((_, j) => `${id}_e${j}`))}
|
|
1246
1337
|
theorem ${id}_check : checkSMachine ${id}_machine ${id}_proof = true := by ${checkBy}
|
|
1247
1338
|
theorem ${id}_laws : ∀ ρ M, SReach ${id}_machine ρ M → ∀ e ∈ ${id}_proof, e.Holds ρ M :=
|
|
1248
1339
|
smachine_sound ${id}_machine ${id}_proof ${id}_check
|
|
1249
|
-
${hm ? histBlock() : readable(id, laws, vars, mapNames, { binders: '(ρ : Nat → Nat) (μ : Nat → Nat → Nat)', hyp: `SReach ${id}_machine ρ μ`, call: `${id}_laws ρ μ h`, lit: c, eLit: e })}${opts.noFacts ? '' : factsProof(id, m, mapNames, vars, opts.simp)}${opts.tamper ? `
|
|
1340
|
+
${hm ? histBlock() : readable(id, laws, vars, mapNames, { binders: '(ρ : Nat → Nat) (μ : Nat → Nat → Nat)', hyp: `SReach ${id}_machine ρ μ`, call: `${id}_laws ρ μ h`, lit: c, eLit: e })}${sm ? sumsBlock() : ''}${opts.noFacts ? '' : factsProof(id, m, mapNames, vars, opts.simp)}${opts.tamper ? `
|
|
1250
1341
|
-- TAMPERED: ${opts.tamper.what}. Lean computes the check to false.
|
|
1251
1342
|
def ${id}_tampered : SMachine := ${lit(opts.tamper.machine)}
|
|
1252
1343
|
example : checkSMachine ${id}_tampered ${id}_proof = false := by ${checkBy}` : ''}${records.length ? `\n\n${records.join('\n\n')}` : ''}${opts.after ? `\n\n${opts.after(ix)}` : ''}`;
|
|
@@ -1916,13 +2007,16 @@ function toLeanWith(items, opts) {
|
|
|
1916
2007
|
const mopts = { stepLaws: item.stepLaws, ...(item.liveness?.length ? { liveness: item.liveness } : {}),
|
|
1917
2008
|
...(item.ghosts?.length ? { ghosts: item.ghosts } : {}), ...(item.lean?.simp ? { simp: item.lean.simp } : {}), ...(item.lean?.after ? { after: item.lean.after } : {}) };
|
|
1918
2009
|
const defs = `${recurDefs(m)}${item.lean?.defs ? `${item.lean.defs}\n` : ''}`;
|
|
1919
|
-
|
|
2010
|
+
// (a machine with sums has no cyclic twin: the usual trees, Sums.lean)
|
|
2011
|
+
// (nor a liveness under strong fairness: Live.lean's sleads_sf_soundA reads the usual step laws)
|
|
2012
|
+
const sums = !!(m.sums && Object.keys(m.sums).length), sf = (item.liveness ?? []).some(strongly);
|
|
2013
|
+
const cyc = certsOn && !sums && !sf ? cycMachineToLean(id, m, item.laws, mopts) : undefined;
|
|
1920
2014
|
if (cyc && 'text' in cyc)
|
|
1921
2015
|
certReport.cyclic.push(item.id);
|
|
1922
2016
|
else if (cyc)
|
|
1923
2017
|
certReport.usual.push({ id: item.id, why: cyc.why });
|
|
1924
2018
|
parts.push(`-- ${item.id}\n${defs}${cyc && 'text' in cyc ? cyc.text : smachineToLean(id, m, item.laws, mopts)}`);
|
|
1925
|
-
theorems.push(`${id}_laws`, ...item.laws.flatMap((l, j) => (l.ex ? [`${id}.some${j}`] : [])), ...(m.history ? [`${id}_hlaws`] : []), ...(item.stepLaws ?? []).map((_, j) => `${id}_step${j}_holds`), ...(item.liveness ?? []).map((_, j) => `${id}_live${j}_holds`));
|
|
2019
|
+
theorems.push(`${id}_laws`, ...item.laws.flatMap((l, j) => (l.ex ? [`${id}.some${j}`] : [])), ...(m.history ? [`${id}_hlaws`] : []), ...(sums ? [`${id}_exact`, `${id}_own`] : []), ...(item.stepLaws ?? []).map((_, j) => `${id}_step${j}_holds`), ...(item.liveness ?? []).map((_, j) => `${id}_live${j}_holds`));
|
|
1926
2020
|
if (item.lean?.after)
|
|
1927
2021
|
theorems.push(...[...item.lean.after(() => 0).matchAll(/^theorem (\S+)/gm)].map(x2 => x2[1]));
|
|
1928
2022
|
}
|
|
@@ -1994,7 +2088,7 @@ function toLeanWith(items, opts) {
|
|
|
1994
2088
|
}
|
|
1995
2089
|
// The file the items need: Live.lean for a liveness or a loop, Sets.lean (which imports Steps.lean) for any machine.
|
|
1996
2090
|
return `import History
|
|
1997
|
-
${items.some(item => 'neverEnds' in item) ? 'import NonTerm\n' : ''}${items.some(item => 'kInduction' in item) ? 'import KInd\n' : ''}${cycTexts ? 'import BridgeRules\n' : ''}${items.some(item => 'cyclic' in item) ? (items.some(item => 'cyclic' in item && (item.bridge || item.recur || item.fold)) ? 'import Bridge\n' : 'import Cyclic\n') : ''}${items.some(item => 'cyclic' in item && item.data) ? 'import Data\n' : ''}import ${items.some(item => 'refinement' in item) ? 'Refine' : items.some(item => 'machine' in item && (item.ghosts?.length || item.laws.some(l => l.some?.length))) ? 'Ghost' : items.some(item => ('machine' in item && item.liveness?.length) || 'loop' in item) ? 'Live' : items.some(item => 'machine' in item) ? 'Sets' : 'Steps'}
|
|
2091
|
+
${items.some(item => 'machine' in item && item.machine.sums && Object.keys(item.machine.sums).length) ? 'import Sums\n' : ''}${items.some(item => 'neverEnds' in item) ? 'import NonTerm\n' : ''}${items.some(item => 'kInduction' in item) ? 'import KInd\n' : ''}${cycTexts ? 'import BridgeRules\n' : ''}${items.some(item => 'cyclic' in item) ? (items.some(item => 'cyclic' in item && (item.bridge || item.recur || item.fold)) ? 'import Bridge\n' : 'import Cyclic\n') : ''}${items.some(item => 'cyclic' in item && item.data) ? 'import Data\n' : ''}import ${items.some(item => 'refinement' in item) ? 'Refine' : items.some(item => 'machine' in item && (item.ghosts?.length || item.laws.some(l => l.some?.length))) ? 'Ghost' : items.some(item => ('machine' in item && item.liveness?.length) || 'loop' in item) ? 'Live' : items.some(item => 'machine' in item) ? 'Sets' : 'Steps'}
|
|
1998
2092
|
open Kern Cert
|
|
1999
2093
|
set_option maxRecDepth 100000
|
|
2000
2094
|
set_option maxHeartbeats 0
|