gdp-wired 0.50.6 → 0.52.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 (91) hide show
  1. package/README.md +2 -2
  2. package/dist/core/accel-refute.d.ts +53 -0
  3. package/dist/core/accel-refute.js +997 -0
  4. package/dist/core/cli.d.ts +2 -0
  5. package/dist/core/cli.js +8 -1
  6. package/dist/core/cycles.d.ts +2 -0
  7. package/dist/core/cycles.js +12 -9
  8. package/dist/core/dsl.d.ts +11 -2
  9. package/dist/core/dsl.js +194 -29
  10. package/dist/core/fixed-division.d.ts +9 -0
  11. package/dist/core/fixed-division.js +87 -0
  12. package/dist/core/fixed-integers.d.ts +33 -0
  13. package/dist/core/fixed-integers.js +279 -0
  14. package/dist/core/live-support.d.ts +5 -0
  15. package/dist/core/live-support.js +148 -0
  16. package/dist/core/live.js +194 -37
  17. package/dist/core/lockstep.d.ts +5 -0
  18. package/dist/core/lockstep.js +23 -0
  19. package/dist/core/machine.d.ts +1 -0
  20. package/dist/core/machine.js +33 -3
  21. package/dist/core/ordered-pair-seeds.d.ts +2 -0
  22. package/dist/core/ordered-pair-seeds.js +109 -0
  23. package/dist/core/proof-output.d.ts +38 -1
  24. package/dist/core/proof-output.js +38 -0
  25. package/dist/core/search-termination.d.ts +4 -0
  26. package/dist/core/search-termination.js +1 -1
  27. package/dist/core/source-check.d.ts +4 -1
  28. package/dist/core/source-check.js +5 -2
  29. package/dist/core/sparse-kind-proof.d.ts +7 -0
  30. package/dist/core/sparse-kind-proof.js +49 -0
  31. package/dist/core/step-seeds.d.ts +46 -0
  32. package/dist/core/step-seeds.js +316 -0
  33. package/dist/kernel/integer-primitives.d.ts +38 -0
  34. package/dist/kernel/integer-primitives.js +179 -0
  35. package/dist/kernel/kernel.d.ts +1 -0
  36. package/dist/kernel/kernel.js +44 -5
  37. package/dist/kernel/prove.js +13 -0
  38. package/dist/kernel/word-division-cuts.d.ts +6 -0
  39. package/dist/kernel/word-division-cuts.js +69 -0
  40. package/dist/kernel/word-division.d.ts +12 -0
  41. package/dist/kernel/word-division.js +167 -0
  42. package/dist/lean-kernel/Cert.lean +222 -0
  43. package/dist/lean-kernel/Count.lean +1568 -0
  44. package/dist/lean-kernel/Ghost.lean +373 -0
  45. package/dist/lean-kernel/GhostMap.lean +426 -0
  46. package/dist/lean-kernel/Kernel.lean +2881 -0
  47. package/dist/lean-kernel/Live.lean +1168 -0
  48. package/dist/lean-kernel/Progress.lean +543 -0
  49. package/dist/lean-kernel/Sets.lean +1975 -0
  50. package/dist/lean-kernel/StepLaw.lean +128 -0
  51. package/dist/lean-kernel/Steps.lean +477 -0
  52. package/dist/lean-kernel/Sums.lean +916 -0
  53. package/dist/lean-kernel/emit.d.ts +8 -1
  54. package/dist/lean-kernel/emit.js +59 -15
  55. package/dist/lean-kernel/integer-primitives.d.ts +17 -0
  56. package/dist/lean-kernel/integer-primitives.js +81 -0
  57. package/dist/lean-kernel/lean-aggregate/FiniteFold.lean +44 -0
  58. package/dist/lean-kernel/lean-aggregate/GroupedTransport.lean +308 -0
  59. package/dist/lean-kernel/lean-aggregate/aggregate.d.ts +13 -0
  60. package/dist/lean-kernel/lean-aggregate/aggregate.js +68 -0
  61. package/dist/lean-kernel/lean-aggregate/assets.d.ts +5 -0
  62. package/dist/lean-kernel/lean-aggregate/assets.js +7 -0
  63. package/dist/lean-kernel/lean-aggregate/audit.d.ts +3 -0
  64. package/dist/lean-kernel/lean-aggregate/audit.js +13 -0
  65. package/dist/lean-kernel/lean-aggregate/exact.d.ts +15 -0
  66. package/dist/lean-kernel/lean-aggregate/exact.js +51 -0
  67. package/dist/lean-kernel/lean-aggregate/index.d.ts +19 -0
  68. package/dist/lean-kernel/lean-aggregate/index.js +52 -0
  69. package/dist/lean-kernel/lean-aggregate/point-fold.d.ts +27 -0
  70. package/dist/lean-kernel/lean-aggregate/point-fold.js +79 -0
  71. package/dist/lean-kernel/lean-aggregate/replay-fold.d.ts +2 -0
  72. package/dist/lean-kernel/lean-aggregate/replay-fold.js +163 -0
  73. package/dist/lean-kernel/lean-aggregate/source.d.ts +2 -0
  74. package/dist/lean-kernel/lean-aggregate/source.js +141 -0
  75. package/dist/lean-kernel/lean-aggregate/weighted-flags.d.ts +2 -0
  76. package/dist/lean-kernel/lean-aggregate/weighted-flags.js +26 -0
  77. package/dist/lean-kernel/lean-aggregate/weighted-replay.d.ts +7 -0
  78. package/dist/lean-kernel/lean-aggregate/weighted-replay.js +53 -0
  79. package/dist/lean-kernel/lean-aggregate/weighted-seeded.d.ts +30 -0
  80. package/dist/lean-kernel/lean-aggregate/weighted-seeded.js +64 -0
  81. package/dist/lean-kernel/lean-aggregate/weighted.d.ts +18 -0
  82. package/dist/lean-kernel/lean-aggregate/weighted.js +115 -0
  83. package/dist/lean-kernel/lean-aggregate/worker.d.ts +10 -0
  84. package/dist/lean-kernel/lean-aggregate/worker.js +46 -0
  85. package/dist/lean-kernel/library.js +13 -0
  86. package/dist/lean-kernel/word-division-export.d.ts +26 -0
  87. package/dist/lean-kernel/word-division-export.js +172 -0
  88. package/dist/lean-kernel/word-division-lower.d.ts +10 -0
  89. package/dist/lean-kernel/word-division-lower.js +103 -0
  90. package/docs/lean-aggregate.md +29 -0
  91. package/package.json +6 -1
@@ -1,4 +1,7 @@
1
- import type { C, E, Law, Machine, Recurrence } from '../core/machine.js';
1
+ import { type C, type E, type Law, type Machine, type Recurrence } from '../core/machine.js';
2
+ export { primitiveFunctionLean, toLeanIntegerPrimitive, primitiveSpecimenLean } from './integer-primitives.js';
3
+ export { wordReads, wordDigitLean, wordKeyPartsLean, wordMapOverlayLean } from './word-division-export.js';
4
+ export { q8RangeMachineToLean, wordDigitRangeMachineToLean } from './word-division-lower.js';
2
5
  import { type Lin, type Step } from '../core/solver.js';
3
6
  import { type CountCert, type CountDecl, type CountedGoal, type CountInst, type FrameCut, type MonoCut, type LinCut, type LemmaCut, type Ghosted, type Fold, type Goal, type Instances, type KInduction, type Liveness, type Loop, type Path, type Recur, type RecurCases, type StepLaw, type Tree } from '../kernel/kernel.js';
4
7
  import { proveStepLaws } from '../kernel/prove.js';
@@ -231,6 +234,10 @@ export declare function retainedSMachineToLean(id: string, m: Machine, laws: Law
231
234
  instances: Record<string, Instances>;
232
235
  trees: Record<string, Tree>;
233
236
  }, projection?: Pick<NonNullable<Parameters<typeof smachineToLean>[3]>, 'ghosts' | 'ghosted' | 'ghostSubst' | 'forallSome' | 'free' | 'after'>): string;
237
+ export declare function retainedSumMachineToLean(id: string, m: Machine, laws: Law[], proof: {
238
+ instances: Record<string, Instances>;
239
+ trees: Record<string, Tree>;
240
+ }, projection: Pick<NonNullable<Parameters<typeof smachineToLean>[3]>, 'free' | 'after'>): string;
234
241
  export declare const cyclicCerts: () => boolean;
235
242
  export declare const certReport: {
236
243
  cyclic: string[];
@@ -1,3 +1,8 @@
1
+ export { primitiveFunctionLean, toLeanIntegerPrimitive, primitiveSpecimenLean } from "./integer-primitives.js";
2
+ export { wordReads, wordDigitLean, wordKeyPartsLean, wordMapOverlayLean } from "./word-division-export.js";
3
+ // Legacy restricted scalar digit-range convenience lane; generic words use WordSReach below.
4
+ export { q8RangeMachineToLean, wordDigitRangeMachineToLean } from "./word-division-lower.js";
5
+ import { wordReads, wordMachineBridgeLean, wordSchemaMapNames } from "./word-division-export.js";
1
6
  import { atMost, n, not, pointWrite } from "../core/machine.js";
2
7
  import { add, k, scale, sub } from "../core/solver.js";
3
8
  import { framePath, lemmaPath, checkMC, checkCounted, checkCountedLaws, checkLaws, countedGoal, countedObligations, countHyps, mcGoal, postName, boundOf, caseGoals, cellParts, 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";
@@ -1035,14 +1040,14 @@ export function readable(id, laws, vars, maps, reach) {
1035
1040
  case 'mul': return `(${e.k} * ${t(e.a)})`;
1036
1041
  case 'prod': return `(${t(e.a)} * ${t(e.b)})`;
1037
1042
  case 'min':
1038
- case 'max': return `(${e.op} ${t(e.a)} ${t(e.b)})`;
1043
+ case 'max': return `(${e.op} (${t(e.a)}) (${t(e.b)}))`;
1039
1044
  case 'if': return `(if ${p(e.c)} then ${t(e.then)} else ${t(e.else)})`;
1040
1045
  case 'get': {
1041
1046
  const a = plain ? arithOf(e.map) : undefined;
1042
1047
  return a ? `(${t(e.key)} ${a.op} ${a.k})` : `(μ ${q(e.map)} (${t(e.key)}))`;
1043
1048
  }
1044
- case 'tup': return `(Kern.cpair ${t(e.a)} ${t(e.b)})`;
1045
- case 'proj': return `(Kern.pickP ${e.k} ${t(e.a)})`;
1049
+ case 'tup': return `(Kern.cpair (${t(e.a)}) (${t(e.b)}))`;
1050
+ case 'proj': return `(Kern.pickP ${e.k} (${t(e.a)}))`;
1046
1051
  }
1047
1052
  };
1048
1053
  const p = (c) => {
@@ -1401,6 +1406,11 @@ function machineNames(m, laws, allSteps, stepLaws, opts) {
1401
1406
  return { vars, maps };
1402
1407
  }
1403
1408
  export function smachineToLean(id, given, laws, opts = {}) {
1409
+ const words = wordReads([given, laws, opts]).length > 0;
1410
+ // Higher-level temporal/refinement bridges require their own framed-world proof.
1411
+ // Never route them through the arbitrary-map soundness theorem by accident.
1412
+ if (words && (given.history || given.sums || opts.refined || opts.ghosted || opts.ghosts?.length || opts.kind || opts.loop || opts.liveness?.length || opts.tamper || opts.ghostSubst?.length))
1413
+ throw new Error(`${id}: word export supports generic SMachine invariants; this auxiliary bridge needs a concrete-world theorem`);
1404
1414
  const hm = given.history ? { ...given, history: { ...given.history, prune: undefined } } : undefined;
1405
1415
  const hplain = hm ? historyMachine(hm) : undefined, stepLaws = opts.stepLaws ?? [], rf = opts.refined, gv = opts.ghosts ?? [];
1406
1416
  // A machine with sums goes as its plain machine too (kernel.ts's sumMachine), built in Lean (Sums.lean's
@@ -1434,8 +1444,8 @@ export function smachineToLean(id, given, laws, opts = {}) {
1434
1444
  if (!rf)
1435
1445
  stepLaws.forEach((sl, j) => claims.push({ steps: [sl], allows: [], render: h => `-- Step law${(sl.steps ?? 1) > 1 ? ` over ${sl.steps} steps` : ''}: ${sl.name}
1436
1446
  def ${id}_step${j} : SKStep := ${skLit(h, sl)}
1437
- theorem ${id}_step${j}_holds : SKStepHolds ${id}_machine ${id}_step${j} :=
1438
- skstep_sound ${id}_machine ${id}_proof ${id}_step${j} ${id}_check (by ${checkBy})` }));
1447
+ theorem ${id}_step${j}_holds : ${words ? `Kern.WordSMachine.WordSKStepHolds ${id}_word ${id}_step${j}` : `SKStepHolds ${id}_machine ${id}_step${j}`} :=
1448
+ ${words ? `Kern.WordSMachine.word_skstep_sound ${id}_word ${id}_proof ${id}_step${j} ${id}_word_extra ${id}_check ${id}_word_extra_sound (by ${checkBy})` : `skstep_sound ${id}_machine ${id}_proof ${id}_step${j} ${id}_check (by ${checkBy})`}` }));
1439
1449
  // k-induction (KInd.lean's kind_sound): Lean builds each base goal's and the step's whens and then from the law; the
1440
1450
  // trees, instances and names are the k-step laws' kernel.ts made (kInductionSteps), the start goal's tree its own.
1441
1451
  const kd = opts.kind;
@@ -1686,7 +1696,10 @@ theorem ${id}_orig_laws : ∀ ρ M, SReach ${id}_ghosted.orig ρ M → ∀ e ∈
1686
1696
  const named = machineNames(m, laws, allSteps, stepLaws, { ...opts, ...(hm ? { record: hm.history.record } : {}) });
1687
1697
  const sumNames = sm ? Object.entries(sm.sums).flatMap(([s2, sum]) => { const { flag, x } = sumParts(s2); return [s2, sum.key, `?${flag}`, `w?${flag}`, x]; }) : [];
1688
1698
  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))])];
1689
- const mapNames = [...new Set([...named.maps, ...[...JSON.stringify([...goalsL, ...goalsS, ...allowGoals]).matchAll(/"op":"get","map":"([^"]+)"/g)].map(x2 => x2[1])])];
1699
+ // A computation irrelevant to a proved law is still part of the source machine.
1700
+ // Include its getter namespace and all native schema helpers, not only goal reads.
1701
+ const sourceTerms = words ? [m, laws, allSteps] : [];
1702
+ const mapNames = [...new Set([...named.maps, ...[...JSON.stringify([...goalsL, ...goalsS, ...allowGoals, ...sourceTerms]).matchAll(/"op":"get","map":"([^"]+)"/g)].map(x2 => x2[1]), ...wordSchemaMapNames(sourceTerms)])];
1690
1703
  const enc = (g, tree) => encode({ name: `${id}: ${g.name}`, goal: g, tree }, false, true, vars, mapNames);
1691
1704
  const { e, c } = leanTerms(vars, mapNames, id);
1692
1705
  const ix = (name) => { const j = vars.indexOf(name); if (j < 0)
@@ -1728,8 +1741,14 @@ def ${id}_machine : SMachine := ${id}_sums.plain`;
1728
1741
  // machine's, the laws.
1729
1742
  const sumsBlock = () => {
1730
1743
  const trees = covers.map(gs => list(gs.map(g => {
1731
- const t2 = opts.coverTrees?.[g.name] ?? (() => { const out = grow(g); if (!('tree' in out))
1732
- throw new Error(`${id}: ${g.name} not proven`); return out.tree; })();
1744
+ const t2 = opts.coverTrees?.[g.name] ?? (() => {
1745
+ if (retainedOnly)
1746
+ throw new Error(`${id}: missing retained cover tree for ${g.name}`);
1747
+ const out = grow(g);
1748
+ if (!('tree' in out))
1749
+ throw new Error(`${id}: ${g.name} not proven`);
1750
+ return out.tree;
1751
+ })();
1733
1752
  const x2 = enc(g, t2);
1734
1753
  return `(${x2.tab}, ${x2.tree})`;
1735
1754
  })));
@@ -1838,10 +1857,14 @@ def ${id}_machine : SMachine := ${id}_hist.plain` : sm ? sumsDef() : lp0 ? `def
1838
1857
  def ${id}_machine : SMachine := ${id}_loop.machine` : `def ${id}_machine : SMachine := ${lit(m)}`}
1839
1858
  ${entries.join('\n')}
1840
1859
  def ${id}_proof : List SEntry := ${list(laws.map((_, j) => `${id}_e${j}`))}
1841
- theorem ${id}_check : checkSMachine ${id}_machine ${id}_proof = true := by ${checkBy}
1860
+ ${words ? `${wordMachineBridgeLean(id, [m, laws, goalsL, goalsS], vars, mapNames)}
1861
+ theorem ${id}_check : Kern.WordSMachine.checkSMachineWithFacts ${id}_machine ${id}_proof ${id}_word_extra = true := by ${checkBy}
1862
+ theorem ${id}_laws : ∀ ρ M, Kern.WordReach.WordSReach ${id}_word ρ M → ∀ e ∈ ${id}_proof, e.Holds ρ M :=
1863
+ Kern.WordSMachine.concrete_smachine_sound ${id}_word ${id}_proof ${id}_word_extra ${id}_check ${id}_word_extra_sound` : `theorem ${id}_check : checkSMachine ${id}_machine ${id}_proof = true := by ${checkBy}
1842
1864
  theorem ${id}_laws : ∀ ρ M, SReach ${id}_machine ρ M → ∀ e ∈ ${id}_proof, e.Holds ρ M :=
1843
- smachine_sound ${id}_machine ${id}_proof ${id}_check
1844
- ${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, ghosts: !rf && !gm && gv.length > 0, explicitExistentials: new Set((opts.ghostSubst ?? []).map(g => g.law)) })}${sm ? sumsBlock() : ''}${opts.noFacts ? '' : factsProof(id, m, mapNames, vars, opts.simp)}${opts.tamper ? `
1865
+ smachine_sound ${id}_machine ${id}_proof ${id}_check`}
1866
+
1867
+ ${hm ? histBlock() : readable(id, laws, vars, mapNames, { binders: '(ρ : Nat → Nat) (μ : Nat → Nat → Nat)', hyp: words ? `Kern.WordReach.WordSReach ${id}_word ρ μ` : `SReach ${id}_machine ρ μ`, call: `${id}_laws ρ μ h`, lit: c, eLit: e, ghosts: !rf && !gm && gv.length > 0, explicitExistentials: new Set((opts.ghostSubst ?? []).map(g => g.law)) })}${sm ? sumsBlock() : ''}${opts.noFacts ? '' : factsProof(id, m, mapNames, vars, opts.simp)}${opts.tamper ? `
1845
1868
  -- TAMPERED: ${opts.tamper.what}. Lean computes the check to false.
1846
1869
  def ${id}_tampered : SMachine := ${lit(opts.tamper.machine)}
1847
1870
  example : checkSMachine ${id}_tampered ${id}_proof = false := by ${checkBy}` : ''}${records.length ? `\n\n${records.join('\n\n')}` : ''}${opts.after ? `\n\n${opts.after(ix, mx, lit, c)}` : ''}`;
@@ -1917,13 +1940,26 @@ export function retainedSMachineToLean(id, m, laws, proof, projection = {}) {
1917
1940
  retainedShape(id, m, laws);
1918
1941
  if (!checkLaws(m, laws, proof))
1919
1942
  throw new Error('captured usual family does not check');
1943
+ return emitRetainedSMachine(id, m, m, laws, proof, projection);
1944
+ }
1945
+ // Sum machinery and all source transport still check in Lean; this only reuses
1946
+ // the instrumented family's retained local trees and forbids fresh cover search.
1947
+ export function retainedSumMachineToLean(id, m, laws, proof, projection) {
1948
+ if (!m.sums || !Object.keys(m.sums).length || m.history)
1949
+ throw new Error('retained sum export needs a sums machine without history');
1950
+ retainedShape(id, { ...m, sums: undefined }, laws);
1951
+ if (!checkLaws(m, laws, proof))
1952
+ throw new Error('captured sums family does not check');
1953
+ return emitRetainedSMachine(id, m, sumMachine(m).machine, laws, proof, { ...projection, coverTrees: proof.trees });
1954
+ }
1955
+ function emitRetainedSMachine(id, given, plain, laws, proof, options) {
1920
1956
  const old = checkBy, oldRetained = retainedOnly, oldCache = [...usualMade];
1921
1957
  try {
1922
1958
  usualMade.clear();
1923
1959
  retainedOnly = true;
1924
1960
  checkBy = 'decide +kernel';
1925
- seedStepProof(m, laws, [], { proven: true, checked: true, nodes: 0, leaves: 0, proof: { laws: proof, instances: {}, perStep: {}, trees: {} } });
1926
- return smachineToLean(id, m, laws, projection);
1961
+ seedStepProof(plain, laws, [], { proven: true, checked: true, nodes: 0, leaves: 0, proof: { laws: proof, instances: {}, perStep: {}, trees: {} } });
1962
+ return smachineToLean(id, given, laws, options);
1927
1963
  }
1928
1964
  finally {
1929
1965
  usualMade.clear();
@@ -2019,6 +2055,8 @@ function cycMachineProofBy(m, laws, allSteps, allows, r, until) {
2019
2055
  }
2020
2056
  // A machine (with a history, ghosts, a liveness or as a loop's) from one cyclic proof, or why it can't be.
2021
2057
  export function cycMachineToLean(id, given, laws, opts = {}) {
2058
+ if (wordReads([given, laws, opts]).length)
2059
+ return { why: 'word primitives require the concrete SMachine export route' };
2022
2060
  const hm = given.history ? { ...given, history: { ...given.history, prune: undefined } } : undefined;
2023
2061
  const hplain = hm ? historyMachine(hm) : undefined, m = hplain ? hplain.machine : given;
2024
2062
  const stepLaws = opts.stepLaws ?? [], gv = opts.ghosts ?? [], lp0 = opts.loop;
@@ -2502,6 +2540,12 @@ export function hmachineToLean(id, m, laws, tampers = [], corollary) {
2502
2540
  // `cyclic`: each machine, loop and fold the cyclic route covers from cyclic certificates (see cycMachineToLean); defaults
2503
2541
  // to GDP_CERT=cyclic. `certReport` then says which items went which way.
2504
2542
  export function toLean(items, opts = {}) {
2543
+ // Generic intrinsic machines use the same serialized certificates, with every
2544
+ // extra hypothesis constructed and discharged by WordFacts under WordSReach.
2545
+ // Other item kinds need their own concrete-world simulation, never SReach.
2546
+ for (const item of items)
2547
+ if (wordReads(item).length && !('machine' in item))
2548
+ throw new Error('word primitives require the concrete SMachine export route');
2505
2549
  // Admit source-derived models before changing exporter state or emitting any text.
2506
2550
  // Ordinary typed DSL machines have no provenance entry and pass unchanged.
2507
2551
  for (const item of items) {
@@ -2608,7 +2652,7 @@ function toLeanWith(items, opts) {
2608
2652
  // (a machine with sums has no cyclic twin: the usual trees, Sums.lean)
2609
2653
  // (nor a liveness under strong fairness: Live.lean's sleads_sf_soundA reads the usual step laws)
2610
2654
  const sums = !!(m.sums && Object.keys(m.sums).length), sf = (item.liveness ?? []).some(strongly);
2611
- const cyc = certsOn && !sums && !sf ? cycMachineToLean(id, m, item.laws, mopts) : undefined;
2655
+ const cyc = certsOn && !sums && !sf && !wordReads([m, item.laws, item.stepLaws, item.liveness]).length ? cycMachineToLean(id, m, item.laws, mopts) : undefined;
2612
2656
  if (cyc && 'text' in cyc)
2613
2657
  certReport.cyclic.push(item.id);
2614
2658
  else if (cyc)
@@ -2686,7 +2730,7 @@ function toLeanWith(items, opts) {
2686
2730
  }
2687
2731
  // The file the items need: Live.lean for a liveness or a loop, Sets.lean (which imports Steps.lean) for any machine.
2688
2732
  return `import History
2689
- ${items.some(item => 'countedGoal' in item || 'countedMachine' in item) ? 'import QAlpha\n' : ''}${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'}
2733
+ ${wordReads(items).length ? 'import WordFacts\nimport WordSMachine\n' : ''}${items.some(item => 'countedGoal' in item || 'countedMachine' in item) ? 'import QAlpha\n' : ''}${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'}
2690
2734
  open Kern Cert
2691
2735
  set_option maxRecDepth 100000
2692
2736
  set_option maxHeartbeats 0
@@ -0,0 +1,17 @@
1
+ import { type PrimitiveSpec } from '../kernel/integer-primitives.js';
2
+ export type { PrimitiveSpec, PrimitiveResult } from '../kernel/integer-primitives.js';
3
+ /** A Lean term for the complete spec. Runtime validation remains in evaluatePrimitive. */
4
+ export declare function primitiveSpecLean(s: PrimitiveSpec): string;
5
+ /** A closed obligation; Lean computes the result, not a custom arithmetic restatement.
6
+ * `a`/`b` are strict exact decimal strings because specimens can cross JSON.
7
+ * There is no write, check, toolchain invocation, or proof claim in this function.
8
+ */
9
+ export declare function primitiveSpecimenObligation(spec: PrimitiveSpec, a: string, b?: string, name?: string): string;
10
+ /** Symbolic native-typed Lean definition. Each input is Lean's actual UIntN/IntN;
11
+ * arithmetic/division uses IntegerPrimitives' standard BitVec/Int operations.
12
+ * This exports semantics, not a proof of the separate TypeScript limb lowering.
13
+ */
14
+ export declare function primitiveFunctionLean(spec: PrimitiveSpec, name?: string): string;
15
+ export declare function toLeanIntegerPrimitive(spec: PrimitiveSpec, name?: string): string;
16
+ /** Standalone Lean source for a closed native probe; import path expects lean-kernel on LEAN_PATH. */
17
+ export declare function primitiveSpecimenLean(spec: PrimitiveSpec, a: string, b?: string, name?: string): string;
@@ -0,0 +1,81 @@
1
+ // Untrusted serialization only. The native Lean checker independently computes
2
+ // IntegerPrimitives.evaluate against the exact BigInt evaluator's claimed result.
3
+ import { evaluatePrimitive, evaluatePrimitiveReceipt } from "../kernel/integer-primitives.js";
4
+ const intLiteral = (n) => n < 0n ? `(${n.toString(10)})` : n.toString(10);
5
+ const decimal = (n) => {
6
+ if (!/^-?(?:0|[1-9][0-9]*)$/.test(n))
7
+ throw new Error('expected exact decimal integer string');
8
+ return BigInt(n);
9
+ };
10
+ const identifier = (s) => {
11
+ if (!/^[A-Za-z][A-Za-z0-9_]*$/.test(s))
12
+ throw new Error('expected Lean identifier');
13
+ return s;
14
+ };
15
+ const operation = (s) => {
16
+ if (!['add', 'sub', 'mul', 'neg', 'cast', 'div', 'rem'].includes(s))
17
+ throw new Error('invalid operation');
18
+ return `.${s}`;
19
+ };
20
+ const overflow = (s) => {
21
+ if (!['WRAP', 'SATURATE', 'TRAP'].includes(s))
22
+ throw new Error('invalid overflow mode');
23
+ return `.${s}`;
24
+ };
25
+ const division = (s) => {
26
+ if (s === undefined)
27
+ return 'none';
28
+ if (!['FLOOR', 'TRUNCATING', 'EUCLIDEAN'].includes(s))
29
+ throw new Error('invalid division mode');
30
+ return `some .${s}`;
31
+ };
32
+ /** A Lean term for the complete spec. Runtime validation remains in evaluatePrimitive. */
33
+ export function primitiveSpecLean(s) {
34
+ if (![8, 16, 32, 64].includes(s.width) || typeof s.signed !== 'boolean')
35
+ throw new Error('invalid width or signed flag');
36
+ return `{ width := ${s.width}, signed := ${s.signed}, operation := ${operation(s.operation)}, overflow := ${overflow(s.overflow)}, division := ${division(s.division)} }`;
37
+ }
38
+ const errorLean = (reason) => {
39
+ if (reason === 'division by zero')
40
+ return '.error .divisionByZero';
41
+ if (reason === 'overflow')
42
+ return '.error .overflow';
43
+ if (reason === 'a out of bounds' || reason === 'b out of bounds')
44
+ return '.error .invalidInput';
45
+ throw new Error(`cannot serialize primitive failure: ${reason}`);
46
+ };
47
+ const resultLean = (result) => result.ok
48
+ ? `.ok ${intLiteral(result.value)}` : errorLean(result.reason);
49
+ /** A closed obligation; Lean computes the result, not a custom arithmetic restatement.
50
+ * `a`/`b` are strict exact decimal strings because specimens can cross JSON.
51
+ * There is no write, check, toolchain invocation, or proof claim in this function.
52
+ */
53
+ export function primitiveSpecimenObligation(spec, a, b, name = 'integer_primitive_specimen') {
54
+ const left = decimal(a), right = b === undefined ? undefined : decimal(b);
55
+ const result = evaluatePrimitive(spec, left, right);
56
+ const expected = resultLean(result);
57
+ return `theorem ${identifier(name)} : IntegerPrimitives.evaluate (${primitiveSpecLean(spec)}) ${intLiteral(left)} ${right === undefined ? 'none' : `(some ${intLiteral(right)})`} = ${expected} := by decide
58
+ #print axioms ${identifier(name)}`;
59
+ }
60
+ /** Symbolic native-typed Lean definition. Each input is Lean's actual UIntN/IntN;
61
+ * arithmetic/division uses IntegerPrimitives' standard BitVec/Int operations.
62
+ * This exports semantics, not a proof of the separate TypeScript limb lowering.
63
+ */
64
+ export function primitiveFunctionLean(spec, name = 'integer_primitive') {
65
+ const captured = evaluatePrimitiveReceipt(spec, 0n).spec;
66
+ if (!captured)
67
+ throw new Error('invalid primitive spec');
68
+ const native = `${captured.signed ? 'Int' : 'UInt'}${captured.width}`;
69
+ const binary = ['add', 'sub', 'mul', 'div', 'rem'].includes(captured.operation);
70
+ const left = captured.signed ? 'a.toInt' : '(Int.ofNat a.toNat)';
71
+ const right = binary ? `(some ${captured.signed ? 'b.toInt' : '(Int.ofNat b.toNat)'})` : 'none';
72
+ const convert = captured.signed ? `${native}.ofInt z` : `${native}.ofNat z.toNat`;
73
+ return `def ${identifier(name)} (a : ${native})${binary ? ` (b : ${native})` : ''} : Except IntegerPrimitives.Failure ${native} :=\n (IntegerPrimitives.evaluate (${primitiveSpecLean(captured)}) ${left} ${right}).map (fun z => ${convert})\n#print axioms ${identifier(name)}\n`;
74
+ }
75
+ export function toLeanIntegerPrimitive(spec, name = 'integer_primitive') {
76
+ return `import IntegerPrimitives\n\n${primitiveFunctionLean(spec, name)}`;
77
+ }
78
+ /** Standalone Lean source for a closed native probe; import path expects lean-kernel on LEAN_PATH. */
79
+ export function primitiveSpecimenLean(spec, a, b, name = 'integer_primitive_specimen') {
80
+ return `import IntegerPrimitives\n\n${primitiveSpecimenObligation(spec, a, b, name)}\n`;
81
+ }
@@ -0,0 +1,44 @@
1
+ import Count
2
+
3
+ /- No new count-checker rule. An ordinary Lean finite-sum theorem composes
4
+ the checked local transition obligations of the research certificate. -/
5
+ namespace FiniteFold
6
+ open Kern
7
+
8
+ theorem spike (n t : Nat) (v : Nat) (ht : t < n) :
9
+ sumBelow (fun k => if k = t then v else 0) n = v := by
10
+ induction n with
11
+ | zero => omega
12
+ | succ n ih =>
13
+ by_cases h : n = t
14
+ · subst t
15
+ have hz : sumBelow (fun k => if k = n then v else 0) n = 0 := by
16
+ calc
17
+ _ = sumBelow (fun _ => 0) n := by
18
+ apply sumBelow_congr
19
+ intro k hk
20
+ simp [Nat.ne_of_lt hk]
21
+ _ = 0 := sumBelow_zero_fn n
22
+ simp [sumBelow, hz]
23
+ · have hn : t < n := by omega
24
+ simp [sumBelow, ih hn, h]
25
+
26
+ theorem point_delta (f g : Nat → Nat) (n t : Nat) (ht : t < n)
27
+ (frame : ∀ k, k < n → k ≠ t → g k = f k) :
28
+ sumBelow g n + f t = sumBelow f n + g t := by
29
+ rw [← spike n t (f t) ht, ← spike n t (g t) ht]
30
+ rw [← sumBelow_add, ← sumBelow_add]
31
+ apply sumBelow_congr n
32
+ intro k hk
33
+ by_cases he : k = t
34
+ · subst k; simp [Nat.add_comm]
35
+ · simp [he, frame k hk he]
36
+
37
+ theorem coupled_change (f g : Nat → Nat) (n t before after : Nat)
38
+ (ht : t < n) (frame : ∀ k, k < n → k ≠ t → g k = f k)
39
+ (old : before = sumBelow f n) (delta : after + f t = before + g t) :
40
+ after = sumBelow g n := by
41
+ have h := point_delta f g n t ht frame
42
+ omega
43
+
44
+ end FiniteFold
@@ -0,0 +1,308 @@
1
+ -- Generic structural transport reused from feat/grouped-sums@3a397980d.
2
+ -- No machine, field, law, or proof tree is encoded in this library.
3
+ import GhostMap
4
+
5
+ open Kern
6
+
7
+ namespace GroupedSumsResearch
8
+
9
+ private abbrev Env := Nat → Nat
10
+ private abbrev Maps := Nat → Nat → Nat
11
+ private abbrev Flag := Nat × C
12
+ private abbrev QFlag := Nat × List Nat × C
13
+
14
+ private def liftFlag (binder : Nat → Nat) (p : Flag) : QFlag :=
15
+ (p.1, [binder p.1], p.2)
16
+
17
+ def promote (s : SMachine) (binder : Nat → Nat)
18
+ (ws : List (Nat × List Nat)) : SMachine :=
19
+ { s with
20
+ f := { s.f with flags := [] }
21
+ qflags := s.f.flags.map (liftFlag binder)
22
+ wits := ws }
23
+
24
+ def bindersOK (s : SMachine) (binder : Nat → Nat) : Bool :=
25
+ s.f.flags.all fun p => !occC (binder p.1) p.2
26
+
27
+ private theorem hit_mem {α : Type} (test : α → Bool) (xs : List α) (a : α)
28
+ (h : lookup test xs = some a) : a ∈ xs := by
29
+ induction xs with
30
+ | nil => simp [lookup] at h
31
+ | cons x xs ih =>
32
+ cases hx : test x with
33
+ | false =>
34
+ exact List.mem_cons_of_mem _ (ih (by simpa [lookup, hx] using h))
35
+ | true =>
36
+ have he : x = a := by simpa [lookup, hx] using h
37
+ simp [he]
38
+
39
+ private theorem hit_test {α : Type} (test : α → Bool) (xs : List α) (a : α)
40
+ (h : lookup test xs = some a) : test a = true := by
41
+ induction xs with
42
+ | nil => simp [lookup] at h
43
+ | cons x xs ih =>
44
+ cases hx : test x with
45
+ | false => exact ih (by simpa [lookup, hx] using h)
46
+ | true =>
47
+ have he : x = a := by simpa [lookup, hx] using h
48
+ simpa [← he] using hx
49
+
50
+ private theorem lift_hit (b : Nat → Nat) (i : Nat) (fs : List Flag) :
51
+ lookup (fun q : QFlag => q.1 == i) (fs.map (liftFlag b)) =
52
+ (lookup (fun p : Flag => p.1 == i) fs).map (liftFlag b) := by
53
+ induction fs with
54
+ | nil => rfl
55
+ | cons p fs ih =>
56
+ cases hp : p.1 == i with
57
+ | false => simpa [lookup, liftFlag, hp] using ih
58
+ | true => simp [lookup, liftFlag, hp]
59
+
60
+ private theorem unused_key (X : Env) (N : Maps) (b : Nat) (c : C)
61
+ (h : occC b c = false) :
62
+ (∀ v, holdsC (atKeys X [b] v) N c) ↔ evalC X N c = true := by
63
+ have he (v : Env) : evalC (atKeys X [b] v) N c = evalC X N c := by
64
+ apply congrC
65
+ intro i hi
66
+ have hn : i ≠ b := by
67
+ intro e
68
+ subst i
69
+ simp [h] at hi
70
+ exact atKeys_out (by simpa using hn)
71
+ constructor
72
+ · intro hall
73
+ rw [← he X]
74
+ exact (evalC_iff _ _ _).mpr (hall X)
75
+ · intro hc v
76
+ apply (evalC_iff _ _ _).mp
77
+ rwa [he v]
78
+
79
+ private theorem promoted_bits (s : SMachine) (b : Nat → Nat)
80
+ (ws : List (Nat × List Nat)) (hb : bindersOK s b = true)
81
+ (X : Env) (N : Maps) :
82
+ decideQ (promote s b ws) X N = decideFlags s.f.flags X N := by
83
+ classical
84
+ have fresh : ∀ p ∈ s.f.flags, occC (b p.1) p.2 = false := by
85
+ simpa [bindersOK] using hb
86
+ funext i
87
+ simp only [decideQ, promote, lift_hit, decideFlags, applyS, assoc_flagSub,
88
+ flagOf]
89
+ cases hh : lookup (fun p : Flag => p.1 == i) s.f.flags with
90
+ | none => rfl
91
+ | some p =>
92
+ have hp := fresh p (hit_mem _ _ _ hh)
93
+ have hk := unused_key X N (b p.1) p.2 hp
94
+ cases hc : evalC X N p.2 <;>
95
+ simp [liftFlag, hk, hc, evalE]
96
+
97
+ private theorem empty_bits (s : SMachine) (hq : s.qflags = [])
98
+ (X : Env) (N : Maps) : decideQ s X N = X := by
99
+ funext i
100
+ simp [decideQ, hq, lookup]
101
+
102
+ theorem promote_view (s : SMachine) (b : Nat → Nat)
103
+ (ws : List (Nat × List Nat)) (hq : s.qflags = [])
104
+ (hb : bindersOK s b = true) : sView (promote s b ws) = sView s := by
105
+ funext ρ M ι κ
106
+ let X := withInputs s.f.m.inputs ρ ι
107
+ let N := withCarried s M κ
108
+ change (decideQ (promote s b ws) X N, N) =
109
+ (decideFlags s.f.flags (decideQ s X N) N, N)
110
+ rw [empty_bits s hq, promoted_bits s b ws hb]
111
+
112
+ theorem promote_next (s : SMachine) (b : Nat → Nat)
113
+ (ws : List (Nat × List Nat)) (hq : s.qflags = [])
114
+ (hb : bindersOK s b = true) : sNext (promote s b ws) = sNext s := by
115
+ funext ρ M ι κ
116
+ simp only [sNext, promote_view s b ws hq hb]
117
+ rfl
118
+
119
+ private theorem transport {s t : SMachine}
120
+ (hm : s.f.m = t.f.m) (hf : s.facts = t.facts)
121
+ (hp : s.pfacts = t.pfacts) (hv : sView s = sView t)
122
+ (hn : sNext s = sNext t) {ρ M} (hr : SReach s ρ M) :
123
+ SReach t ρ M := by
124
+ induction hr with
125
+ | start X N hM hc hl hpl =>
126
+ rw [hm]
127
+ apply SReach.start
128
+ · simpa only [hm] using hM
129
+ · simpa only [hm] using hc
130
+ · simpa only [hf] using hl
131
+ · simpa only [SMachine.PFacts, hp] using hpl
132
+ | step X N ι κ _ hc ih =>
133
+ rw [hn]
134
+ exact SReach.step X N ι κ ih (by simpa only [hm, hv] using hc)
135
+
136
+ theorem promote_reach (s : SMachine) (b : Nat → Nat)
137
+ (ws : List (Nat × List Nat)) (hq : s.qflags = [])
138
+ (hb : bindersOK s b = true) {ρ M} :
139
+ SReach (promote s b ws) ρ M ↔ SReach s ρ M := by
140
+ have hv := promote_view s b ws hq hb
141
+ have hn := promote_next s b ws hq hb
142
+ exact ⟨transport (s := promote s b ws) (t := s) rfl rfl rfl hv hn,
143
+ transport (s := s) (t := promote s b ws) rfl rfl rfl hv.symm hn.symm⟩
144
+
145
+ -- Supply literal identity proofs, not observations of selected executions.
146
+ theorem candidate_reach {source candidate : SMachine} (b : Nat → Nat)
147
+ (ws : List (Nat × List Nat)) (hid : candidate = promote source b ws)
148
+ (hq : source.qflags = []) (hb : bindersOK source b = true) {ρ M} :
149
+ SReach candidate ρ M ↔ SReach source ρ M := by
150
+ subst candidate
151
+ exact promote_reach source b ws hq hb
152
+
153
+ private theorem readE (X : Env) (N : Maps) (o g : Nat) (e : E)
154
+ (h : occE o e = false) : evalE (upd X o g) N e = evalE X N e := by
155
+ apply congrE
156
+ intro i hi
157
+ by_cases eq : i = o
158
+ · subst i
159
+ simp [h] at hi
160
+ · simp [upd, eq]
161
+
162
+ private theorem readC (X : Env) (N : Maps) (o g : Nat) (c : C)
163
+ (h : occC o c = false) : evalC (upd X o g) N c = evalC X N c := by
164
+ apply congrC
165
+ intro i hi
166
+ by_cases eq : i = o
167
+ · subst i
168
+ simp [h] at hi
169
+ · simp [upd, eq]
170
+
171
+ private def assignsOK (o : Nat) (xs : List (Nat × E)) : Bool :=
172
+ xs.all fun p => !(p.1 == o) && !occE o p.2
173
+
174
+ def observerOK (s : SMachine) (o : Nat) : Bool :=
175
+ !s.f.m.inputs.contains o &&
176
+ !occC o s.f.m.pre &&
177
+ !occC o s.f.m.assume &&
178
+ assignsOK o s.f.m.init &&
179
+ assignsOK o s.f.m.step &&
180
+ (s.f.flags.all fun p => !(p.1 == o) && !occC o p.2) &&
181
+ (s.f.m.writes.all fun w => !occE o w.2.1 && !occE o w.2.2) &&
182
+ (s.every.all fun w => !occE o w.2.2)
183
+
184
+ private theorem assoc_member (xs : List (Nat × E)) (i : Nat) (e : E)
185
+ (h : assoc xs i = some e) : (i, e) ∈ xs := by
186
+ induction xs with
187
+ | nil => simp [assoc, lookup] at h
188
+ | cons p xs ih =>
189
+ obtain ⟨j, a⟩ := p
190
+ by_cases hj : j = i
191
+ · subst j
192
+ have ha : a = e := by simpa [assoc, lookup] using h
193
+ simp [ha]
194
+ · exact List.mem_cons_of_mem _ (ih (by
195
+ simpa [assoc, lookup, hj, Ne.symm hj] using h))
196
+
197
+ private theorem assigns_upd (xs : List (Nat × E)) (X : Env) (N : Maps)
198
+ (o g : Nat) (h : assignsOK o xs = true) :
199
+ applyS xs (upd X o g) N = upd (applyS xs X N) o g := by
200
+ have fresh : ∀ p ∈ xs, p.1 ≠ o ∧ occE o p.2 = false := by
201
+ simpa [assignsOK] using h
202
+ funext i
203
+ cases ha : assoc xs i with
204
+ | none => simp [applyS, upd, ha]
205
+ | some e =>
206
+ have hp := fresh (i, e) (assoc_member xs i e ha)
207
+ simp [applyS, upd, ha, hp.1, readE X N o g e hp.2]
208
+
209
+ private theorem inputs_upd (ins : List Nat) (o g : Nat) (X I : Env)
210
+ (h : o ∉ ins) :
211
+ withInputs ins (upd X o g) I = upd (withInputs ins X I) o g := by
212
+ funext i
213
+ by_cases hi : i = o
214
+ · subst i
215
+ simp [withInputs, upd, List.contains_iff_mem, h]
216
+ · simp [withInputs, upd, hi]
217
+
218
+ private theorem flags_upd (fs : List Flag) (X : Env) (N : Maps)
219
+ (o g : Nat) (fresh : ∀ p ∈ fs, p.1 ≠ o ∧ occC o p.2 = false) :
220
+ decideFlags fs (upd X o g) N = upd (decideFlags fs X N) o g := by
221
+ funext i
222
+ simp only [decideFlags, applyS, assoc_flagSub, flagOf, upd]
223
+ cases hh : lookup (fun p : Flag => p.1 == i) fs with
224
+ | none => rfl
225
+ | some p =>
226
+ have hp := fresh p (hit_mem _ _ _ hh)
227
+ have he : p.1 = i := by simpa using hit_test _ _ _ hh
228
+ have hi : i ≠ o := he ▸ hp.1
229
+ have hc := readC X N o g p.2 hp.2
230
+ change evalE (upd X o g) N (.ite p.2 (.const 1) (.const 0)) =
231
+ (if i = o then g else evalE X N (.ite p.2 (.const 1) (.const 0)))
232
+ simp only [if_neg hi, evalE, hc]
233
+
234
+ private theorem view_upd (s : SMachine) (o g : Nat) (X : Env) (N : Maps)
235
+ (I : Env) (K : Maps) (hq : s.qflags = []) (hin : o ∉ s.f.m.inputs)
236
+ (hf : ∀ p ∈ s.f.flags, p.1 ≠ o ∧ occC o p.2 = false) :
237
+ sView s (upd X o g) N I K =
238
+ (upd (sView s X N I K).1 o g, (sView s X N I K).2) := by
239
+ simp only [sView, empty_bits s hq, inputs_upd _ o g X I hin,
240
+ flags_upd _ _ _ o g hf]
241
+
242
+ private theorem writes_upd (ws : List (Nat × E × E)) (D : Env) (N : Maps)
243
+ (o g : Nat)
244
+ (hf : ∀ w ∈ ws, occE o w.2.1 = false ∧ occE o w.2.2 = false) :
245
+ writeMaps ws (upd D o g) N = writeMaps ws D N := by
246
+ funext mp k
247
+ simp only [writeMaps]
248
+ cases hh : lookup (fun w : Nat × E × E => w.1 == mp) ws with
249
+ | none => rfl
250
+ | some w =>
251
+ have hw := hf w (hit_mem _ _ _ hh)
252
+ change (if k = evalE (upd D o g) N w.2.1 then evalE (upd D o g) N w.2.2 else N mp k) =
253
+ (if k = evalE D N w.2.1 then evalE D N w.2.2 else N mp k)
254
+ rw [readE D N o g w.2.1 hw.1, readE D N o g w.2.2 hw.2]
255
+
256
+ private theorem every_upd (s : SMachine) (D : Env) (N : Maps) (o g : Nat)
257
+ (hw : ∀ w ∈ s.f.m.writes, occE o w.2.1 = false ∧ occE o w.2.2 = false)
258
+ (he : ∀ w ∈ s.every, occE o w.2.2 = false) :
259
+ everyMaps s (upd D o g) N = everyMaps s D N := by
260
+ funext mp k
261
+ simp only [everyMaps]
262
+ cases hh : lookup (fun w : Nat × Nat × E => w.1 == mp) s.every with
263
+ | none => rw [writes_upd _ _ _ _ _ hw]
264
+ | some w =>
265
+ have h := he w (hit_mem _ _ _ hh)
266
+ apply congrE
267
+ intro i hi
268
+ by_cases hio : i = o
269
+ · subst i
270
+ simp [h] at hi
271
+ · simp [upd, hio]
272
+
273
+ theorem source_rebind (source : SMachine) (obs : Nat)
274
+ (hq : source.qflags = []) (hfacts : source.facts = [])
275
+ (hpfacts : source.pfacts = []) (hok : observerOK source obs = true) :
276
+ ∀ {ρ M}, SReach source ρ M → ∀ g, SReach source (upd ρ obs g) M := by
277
+ have parts :
278
+ obs ∉ source.f.m.inputs ∧
279
+ occC obs source.f.m.pre = false ∧
280
+ occC obs source.f.m.assume = false ∧
281
+ assignsOK obs source.f.m.init = true ∧
282
+ assignsOK obs source.f.m.step = true ∧
283
+ (∀ p ∈ source.f.flags, p.1 ≠ obs ∧ occC obs p.2 = false) ∧
284
+ (∀ w ∈ source.f.m.writes,
285
+ occE obs w.2.1 = false ∧ occE obs w.2.2 = false) ∧
286
+ (∀ w ∈ source.every, occE obs w.2.2 = false) := by
287
+ simpa [observerOK, List.contains_iff_mem, and_assoc] using hok
288
+ obtain ⟨hin, hpre, hassume, hinit, hstep, hflags, hw, he⟩ := parts
289
+ intro ρ M hr
290
+ induction hr with
291
+ | start X N hM hc _ _ =>
292
+ intro g
293
+ rw [← assigns_upd _ X N obs g hinit]
294
+ apply SReach.start (upd X obs g) N hM
295
+ · rwa [readC _ _ _ _ _ hpre]
296
+ · simp [hfacts]
297
+ · simp [SMachine.PFacts, hpfacts]
298
+ | step X N I K _ hc ih =>
299
+ intro g
300
+ have hv := view_upd source obs g X N I K hq hin hflags
301
+ have hc' : evalC (sView source (upd X obs g) N I K).1
302
+ (sView source (upd X obs g) N I K).2 source.f.m.assume = true := by
303
+ simpa only [hv, readC _ _ obs g _ hassume] using hc
304
+ have hr' := SReach.step (s := source) (upd X obs g) N I K (ih g) hc'
305
+ simpa only [sNext, hv, assigns_upd _ _ _ obs g hstep,
306
+ every_upd source _ _ obs g hw he] using hr'
307
+
308
+ end GroupedSumsResearch
@@ -0,0 +1,13 @@
1
+ import { type C, type E, type Law, type Machine } from '../../core/machine.js';
2
+ export type FilteredCounterProposal = {
3
+ map: string;
4
+ key: string;
5
+ reset: C;
6
+ bound: E;
7
+ offset: number;
8
+ fields: {
9
+ field: string;
10
+ value: number;
11
+ }[];
12
+ };
13
+ export declare function proposeFilteredCounters(m: Machine, caller: Law): FilteredCounterProposal[];