tla-ts 0.0.4-dev.c4929d7 → 0.0.4-dev.ca40dfe

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 (207) hide show
  1. package/README.md +31 -6
  2. package/dist/cli.cjs +1 -1
  3. package/dist/cli.js +1 -1
  4. package/dist/deciders.cjs +27 -27
  5. package/dist/deciders.js +34 -34
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +12 -14
  8. package/dist/index.d.ts +12 -14
  9. package/dist/index.js +1 -1
  10. package/dist/parallel-worker.cjs +1 -1
  11. package/dist/parallel-worker.js +1 -1
  12. package/dist/prove-worker.cjs +1 -1
  13. package/dist/prove-worker.js +1 -1
  14. package/dist/prove.cjs +37 -27
  15. package/dist/prove.js +39 -29
  16. package/dist/run.cjs +45 -0
  17. package/dist/run.js +45 -0
  18. package/dist/tlapm.cjs +2 -2
  19. package/dist/tlapm.js +2 -2
  20. package/dist/transfer.cjs +76 -86
  21. package/dist/transfer.js +73 -83
  22. package/dist/worker.cjs +6 -6
  23. package/dist/worker.js +6 -6
  24. package/package.json +1 -1
  25. package/src/ast.ts +2 -2
  26. package/src/bags.ts +22 -23
  27. package/src/builtins.ts +16 -8
  28. package/src/check.ts +131 -1154
  29. package/src/{cli-options.ts → cli/options.ts} +54 -9
  30. package/src/cli/run.ts +63 -0
  31. package/src/cli/shared.ts +106 -0
  32. package/src/cli/tlapm.ts +374 -0
  33. package/src/cli/tlc.ts +941 -0
  34. package/src/cli/xml-exporter.ts +221 -0
  35. package/src/cli.ts +1 -1
  36. package/src/codegen.ts +17 -15
  37. package/src/config.ts +5 -5
  38. package/src/dependencies.ts +4 -6
  39. package/src/environment.ts +55 -60
  40. package/src/errors.ts +12 -36
  41. package/src/evaluate.ts +81 -101
  42. package/src/exit-codes.ts +1 -1
  43. package/src/fingerprints.ts +3 -3
  44. package/src/instances.ts +56 -46
  45. package/src/java-overrides.ts +79 -41
  46. package/src/json.ts +31 -36
  47. package/src/levels.ts +10 -13
  48. package/src/{live-check.ts → liveness-checker.ts} +169 -142
  49. package/src/liveness.ts +38 -34
  50. package/src/obligations/action.ts +9 -45
  51. package/src/obligations/{anon.ts → anonymize.ts} +13 -25
  52. package/src/obligations/equality.ts +260 -0
  53. package/src/obligations/expression.ts +42 -517
  54. package/src/obligations/generate.ts +88 -778
  55. package/src/obligations/index.ts +20 -22
  56. package/src/obligations/levels.ts +36 -41
  57. package/src/obligations/module.ts +88 -708
  58. package/src/obligations/normalize.ts +554 -0
  59. package/src/obligations/operators.ts +176 -0
  60. package/src/obligations/pragma.ts +21 -15
  61. package/src/obligations/printer.ts +81 -188
  62. package/src/obligations/proof.ts +0 -1
  63. package/src/obligations/regroup.ts +100 -0
  64. package/src/obligations/simplify.ts +668 -0
  65. package/src/obligations/source.ts +25 -131
  66. package/src/obligations/{deref.ts → subexpression.ts} +48 -56
  67. package/src/obligations/substitution.ts +261 -0
  68. package/src/obligations/temporal.ts +28 -26
  69. package/src/obligations/tuples.ts +37 -53
  70. package/src/parallel-worker.ts +37 -33
  71. package/src/parallel.ts +30 -24
  72. package/src/parser.ts +67 -74
  73. package/src/{pcal-ast.ts → pcal/ast.ts} +2 -17
  74. package/src/{pcal-parse.ts → pcal/parse.ts} +28 -64
  75. package/src/{pcal-tokenize.ts → pcal/tokenize.ts} +10 -39
  76. package/src/{pcal-translate.ts → pcal/translate.ts} +30 -109
  77. package/src/{pcal-validate.ts → pcal/validate.ts} +10 -20
  78. package/src/prove/decide-pool.ts +7 -12
  79. package/src/{obligations/pickle.ts → prove/first-order.ts} +79 -2
  80. package/src/prove/isabelle/decide.ts +3 -6
  81. package/src/prove/isabelle/encode.ts +35 -93
  82. package/src/prove/isabelle/isar/inner-syntax.ts +1 -1
  83. package/src/prove/isabelle/isar/method.ts +3 -3
  84. package/src/prove/isabelle/isar/type-check.ts +1 -1
  85. package/src/prove/isabelle/provers/blast/blast.ts +1 -1
  86. package/src/prove/isabelle/provers/blast/branch.ts +1 -1
  87. package/src/prove/isabelle/provers/blast/term.ts +3 -4
  88. package/src/prove/isabelle/provers/clasimp.ts +1 -1
  89. package/src/prove/isabelle/provers/classical.ts +3 -3
  90. package/src/prove/isabelle/provers/hypsubst.ts +1 -9
  91. package/src/prove/isabelle/pure/conv.ts +1 -1
  92. package/src/prove/isabelle/pure/drule.ts +2 -2
  93. package/src/prove/isabelle/pure/envir.ts +3 -35
  94. package/src/prove/isabelle/pure/logic.ts +4 -76
  95. package/src/prove/isabelle/pure/name.ts +1 -13
  96. package/src/prove/isabelle/pure/net.ts +2 -49
  97. package/src/prove/isabelle/pure/pattern.ts +3 -22
  98. package/src/prove/isabelle/pure/raw-simplifier.ts +3 -18
  99. package/src/prove/isabelle/pure/seq.ts +0 -23
  100. package/src/prove/isabelle/pure/simplifier.ts +2 -8
  101. package/src/prove/isabelle/pure/table.ts +1 -8
  102. package/src/prove/isabelle/pure/tactic.ts +5 -113
  103. package/src/prove/isabelle/pure/tactical.ts +1 -84
  104. package/src/prove/isabelle/pure/term-ord.ts +1 -55
  105. package/src/prove/isabelle/pure/term.ts +8 -128
  106. package/src/prove/isabelle/pure/thm.ts +4 -27
  107. package/src/prove/isabelle/pure/type.ts +0 -12
  108. package/src/prove/isabelle/pure/unify.ts +1 -1
  109. package/src/prove/isabelle/tla/classical-setup.ts +1 -1
  110. package/src/prove/ocaml.ts +1 -1
  111. package/src/prove/prep/action.ts +23 -36
  112. package/src/prove/prep/enabled-axioms.ts +2 -2
  113. package/src/prove/prep/fingerprint.ts +3 -3
  114. package/src/prove/prep/level-comparison.ts +9 -37
  115. package/src/prove/prep/md5.ts +2 -9
  116. package/src/prove/prep/normalize.ts +309 -0
  117. package/src/prove/prove-worker.ts +2 -5
  118. package/src/prove/prove.ts +98 -111
  119. package/src/prove/ptl/encode.ts +19 -31
  120. package/src/prove/smt/axioms.ts +45 -58
  121. package/src/prove/smt/encode.ts +124 -15
  122. package/src/prove/smt/instances.ts +2 -3
  123. package/src/prove/smt/rewrite.ts +24 -31
  124. package/src/prove/smt/solver/ast-util.ts +0 -56
  125. package/src/prove/smt/solver/case-split-queue.ts +1 -1
  126. package/src/prove/smt/solver/enode.ts +1 -1
  127. package/src/prove/smt/solver/lp/dep-intervals.ts +0 -14
  128. package/src/prove/smt/solver/model-macro-solver.ts +1 -1
  129. package/src/prove/smt/solver/nlsat/algebraic.ts +3 -3
  130. package/src/prove/smt/solver/nlsat/atoms.ts +1 -1
  131. package/src/prove/smt/solver/nlsat/explain.ts +1 -1
  132. package/src/prove/smt/solver/nlsat/interval-set.ts +1 -1
  133. package/src/prove/smt/solver/nlsat/levelwise.ts +4 -7
  134. package/src/prove/smt/solver/nlsat/polynomial.ts +4 -4
  135. package/src/prove/smt/solver/nlsat/upolynomial.ts +2 -2
  136. package/src/prove/smt/solver/pattern-inference.ts +1 -1
  137. package/src/prove/smt/solver/relevancy.ts +2 -2
  138. package/src/prove/smt/solver/rewriter.ts +1 -1
  139. package/src/prove/smt/solver/solver.ts +2 -2
  140. package/src/{tlapm-cache.ts → prove/tlapm/cache.ts} +11 -11
  141. package/src/{ocaml-marshal.ts → prove/tlapm/ocaml-marshal.ts} +1 -1
  142. package/src/prove/verdict.ts +0 -5
  143. package/src/prove/zenon/decide.ts +5 -11
  144. package/src/prove/zenon/encode.ts +21 -80
  145. package/src/prove/zenon/eqrel.ts +1 -1
  146. package/src/prove/zenon/equality-rules.ts +1 -1
  147. package/src/prove/zenon/expr.ts +2 -2
  148. package/src/prove/zenon/index-table.ts +1 -1
  149. package/src/prove/zenon/isar.ts +1 -1
  150. package/src/prove/zenon/llproof.ts +1 -1
  151. package/src/prove/zenon/mltoll.ts +1 -1
  152. package/src/prove/zenon/node.ts +1 -1
  153. package/src/prove/zenon/search.ts +1 -1
  154. package/src/prove/zenon/tla/terms.ts +1 -20
  155. package/src/prove/zenon/tla/tla.ts +1 -1
  156. package/src/randomization.ts +19 -24
  157. package/src/resolve.ts +15 -22
  158. package/src/runtime.ts +8 -8
  159. package/src/{sany-builtins.ts → sany/builtins.ts} +1 -1
  160. package/src/{sany-generator.ts → sany/generator.ts} +38 -55
  161. package/src/{sany-levels.ts → sany/levels.ts} +45 -48
  162. package/src/{sany-lexer.ts → sany/lexer.ts} +2 -3
  163. package/src/{sany-linter.ts → sany/linter.ts} +1 -1
  164. package/src/{sany-modules.ts → sany/modules.ts} +2 -2
  165. package/src/{sany-nodes.ts → sany/nodes.ts} +2 -2
  166. package/src/{sany-parse-error.ts → sany/parse-error.ts} +2 -2
  167. package/src/{sany-report.ts → sany/report.ts} +16 -17
  168. package/src/{sany-selectors.ts → sany/selectors.ts} +3 -5
  169. package/src/{sany-source.ts → sany/source.ts} +6 -7
  170. package/src/{sany-xml.ts → sany/xml.ts} +5 -6
  171. package/src/search.ts +969 -0
  172. package/src/spec-description.ts +26 -20
  173. package/src/{standard-levels.ts → standard-definitions.ts} +118 -2
  174. package/src/standard-modules.ts +16 -20
  175. package/src/state-graph.ts +9 -8
  176. package/src/substitution-levels.ts +2 -2
  177. package/src/successors.ts +16 -19
  178. package/src/symmetry.ts +1 -1
  179. package/src/tableau.ts +6 -7
  180. package/src/tlc/fingerprint.ts +214 -0
  181. package/src/{tlc-messages.ts → tlc/messages.ts} +119 -7
  182. package/src/{tlc-order.ts → tlc/order.ts} +7 -7
  183. package/src/{tlc-random.ts → tlc/random.ts} +3 -213
  184. package/src/{tlc-replay.ts → tlc/replay.ts} +40 -36
  185. package/src/{tlc-module.ts → tlc/tlc-operators.ts} +9 -9
  186. package/src/{tlc-ext.ts → tlc/tlcext-operators.ts} +30 -25
  187. package/src/transfer.ts +32 -32
  188. package/src/values.ts +72 -67
  189. package/src/worker.ts +1 -4
  190. package/dist/run-cli.cjs +0 -45
  191. package/dist/run-cli.js +0 -45
  192. package/src/canonical.ts +0 -40
  193. package/src/obligations/ctx.ts +0 -64
  194. package/src/prove/prep/defs.ts +0 -33
  195. package/src/prove/prep/elab.ts +0 -156
  196. package/src/prove/prep/enabled.ts +0 -43
  197. package/src/prove/prep/flatten.ts +0 -70
  198. package/src/prove/prep/trivial.ts +0 -22
  199. package/src/prove/smt/axiomatize.ts +0 -69
  200. package/src/prove/smt/simplify.ts +0 -57
  201. package/src/run-cli.ts +0 -1806
  202. package/src/standard-ranges.ts +0 -116
  203. package/src/value-sources.ts +0 -29
  204. /package/src/prove/prep/{pragma.ts → methods.ts} +0 -0
  205. /package/src/{tlc-modules.ts → tlc/jar-data.ts} +0 -0
  206. /package/src/{tlc-summary.ts → tlc/summary.ts} +0 -0
  207. /package/src/{tlc-version.ts → tlc/version.ts} +0 -0
@@ -1,40 +1,27 @@
1
- // A port of tlapm's proof simplification (Proof.Simplify) and obligation generation (Proof.Gen):
2
- // leaf proofs become obligations whose context is everything the proof may use at that point.
1
+ // A port of tlapm's obligation generation (Proof.Gen and Module.Gen): leaf proofs become obligations
2
+ // whose context is everything the proof may use at that point.
3
3
 
4
4
  import { TlapmBugError, TlaProofError } from "../errors";
5
+ import { isEqualExpr } from "./equality";
5
6
  import {
6
- applyBuiltin,
7
7
  at,
8
- consSubstitution,
9
8
  exprifySequent,
10
9
  getErrorNote,
11
- isEqualExpr,
10
+ getFact,
11
+ isBuiltinApply,
12
12
  mapAccumulate,
13
- mapChildren,
14
- normalizeApply,
15
- shift,
16
- shiftExpr,
17
- substituteBounds,
18
- substituteExpr,
19
- stripProps,
20
- type Bound,
21
- type Builtin,
22
13
  type Expr,
23
14
  type Hyp,
24
15
  type Locus,
25
- type ObligationWarning,
26
16
  type Sequent,
27
17
  type Time,
28
18
  type Visibility,
19
+ type Warn,
29
20
  } from "./expression";
30
- import { format, renderDoc, type Doc } from "./format";
31
- import { printExpression } from "./printer";
21
+ import { bindTheoremName, getUnitHyps, type Mule } from "./module";
32
22
  import type { OldMethod } from "./pragma";
33
- import { getScopeTime } from "./temporal";
34
23
  import {
35
24
  getStepName,
36
- getUnique,
37
- type Counter,
38
25
  type Obligation,
39
26
  type ObligationKind,
40
27
  type Proof,
@@ -43,59 +30,15 @@ import {
43
30
  type UseDef,
44
31
  type Usable,
45
32
  } from "./proof";
33
+ import { shiftExpr } from "./substitution";
34
+ import { getScopeTime } from "./temporal";
46
35
 
47
- const AT_NOWHERE: Expr = { kind: "At", isExcept: false };
48
-
49
- // tlapm builds nodes with x @@ step, which copies all of the step's properties.
50
- const getProps = (from: Step) => ({
51
- location: from.location,
52
- step: from.step,
53
- isSuppressed: from.isSuppressed,
54
- method: from.method,
55
- });
36
+ export const AT_NOWHERE: Expr = { kind: "At", isExcept: false };
56
37
 
57
38
  const isAnonymous = (step: StepNumber | undefined) => step?.kind === "Named" && step.isAnonymous;
58
39
 
59
- const getLevel = (step: StepNumber | undefined) => step?.level ?? 0;
60
-
61
- const getTrue = (from: { location?: Locus }) => at({ kind: "Internal", builtin: "TRUE" }, from);
62
-
63
- const isBinary = (
64
- expression: Expr,
65
- builtin: Builtin,
66
- ): expression is Extract<Expr, { kind: "Apply" }> =>
67
- expression.kind === "Apply" &&
68
- expression.operator.kind === "Internal" &&
69
- expression.operator.builtin === builtin &&
70
- expression.args.length === 2;
71
-
72
- const getMessage = (pattern: string, ...args: (string | Doc)[]) =>
73
- renderDoc(format(pattern, ...args));
74
-
75
- // Visit.hyps_of_bounds_unditto: dittos repeat the previous domain, and each domain shifts past the
76
- // names bound before it.
77
- const getBoundHyps = (bounds: Bound[]): Hyp[] =>
78
- expandDittoes(bounds).map((bound, index): Hyp => {
79
- const domain =
80
- bound.domain.kind === "Domain" ? shiftExpr(index, bound.domain.expression) : undefined;
81
- return {
82
- kind: "Fresh",
83
- name: bound.name,
84
- shape: 0,
85
- level: domain ? "Constant" : bound.level,
86
- domain,
87
- domainVisibility: "Visible",
88
- };
89
- });
90
-
91
- const expandDittoes = (bounds: Bound[]): Bound[] => {
92
- let domain: Bound["domain"] = { kind: "NoDomain" };
93
- return bounds.map((bound) => {
94
- if (bound.domain.kind === "Ditto") return { ...bound, domain };
95
- domain = bound.domain;
96
- return bound;
97
- });
98
- };
40
+ export const getTrue = (from: { location?: Locus }) =>
41
+ at({ kind: "Internal", builtin: "TRUE" }, from);
99
42
 
100
43
  // Each visible fact of the sequent, shifted past the hypotheses after it.
101
44
  const getAssumedFacts = (offset: number, sequent: Sequent) =>
@@ -119,7 +62,7 @@ const getStepDefinition = (step: Step, body: Expr, time: Time): Hyp => {
119
62
 
120
63
  // The proof of an assertion leaves the always scope when the assertion assumes a fact that holds
121
64
  // only now.
122
- const proveAssertion = (context: Hyp[], sequent: Sequent, step: Step, time: Time) => {
65
+ export const proveAssertion = (context: Hyp[], sequent: Sequent, step: Step, time: Time) => {
123
66
  const visibility: Visibility = isAnonymous(step.step) ? "Visible" : "Hidden";
124
67
  const hyps = sequent.context.map((hyp): Hyp =>
125
68
  hyp.kind === "Fact" ? { ...hyp, visibility } : hyp,
@@ -130,28 +73,16 @@ const proveAssertion = (context: Hyp[], sequent: Sequent, step: Step, time: Time
130
73
  context: [
131
74
  ...context,
132
75
  ...hyps,
133
- {
134
- kind: "Fact",
135
- expression: getTrue(step),
136
- visibility: "Hidden",
137
- time,
138
- location: step.location,
139
- },
76
+ getFact(getTrue(step), "Hidden", time, step.location),
140
77
  getStepDefinition(step, body, scopeTime),
141
- {
142
- kind: "Fact",
143
- expression: at({ kind: "Ix", index: 1 }, step),
144
- visibility: "Hidden",
145
- time: scopeTime,
146
- location: step.location,
147
- },
148
- ] satisfies Hyp[],
78
+ getFact(at({ kind: "Ix", index: 1 }, step), "Hidden", scopeTime, step.location),
79
+ ],
149
80
  active: shiftExpr(3, sequent.active),
150
81
  time: scopeTime,
151
82
  };
152
83
  };
153
84
 
154
- const useAssertion = (
85
+ export const useAssertion = (
155
86
  isSuffices: boolean,
156
87
  context: Hyp[],
157
88
  goal: Expr,
@@ -164,14 +95,8 @@ const useAssertion = (
164
95
  context: [
165
96
  ...context,
166
97
  getStepDefinition(step, at(exprifySequent(sequent), step), time),
167
- {
168
- kind: "Fact",
169
- expression: at({ kind: "Ix", index: 1 }, step),
170
- visibility,
171
- time,
172
- location: step.location,
173
- },
174
- ] satisfies Hyp[],
98
+ getFact(at({ kind: "Ix", index: 1 }, step), visibility, time, step.location),
99
+ ],
175
100
  active: shiftExpr(2, goal),
176
101
  };
177
102
  };
@@ -197,15 +122,13 @@ const setDefinition = (visibility: Visibility, context: Hyp[], def: UseDef): Hyp
197
122
  };
198
123
 
199
124
  const isDomainMatch = (fact: Expr, domain: Expr) =>
200
- fact.kind === "Apply" &&
201
- fact.operator.kind === "Internal" &&
202
- fact.operator.builtin === "Mem" &&
125
+ isBuiltinApply(fact, "Mem") &&
203
126
  fact.args[0]?.kind === "Ix" &&
204
127
  fact.args[0].index === 0 &&
205
128
  isEqualExpr(domain, fact.args[1]);
206
129
 
207
130
  const setExpression = (
208
- onWarning: (warning: ObligationWarning) => void,
131
+ onWarning: Warn,
209
132
  visibility: Visibility,
210
133
  fact: Expr,
211
134
  context: Hyp[],
@@ -240,105 +163,32 @@ export interface LineRange {
240
163
  end: number;
241
164
  }
242
165
 
243
- export interface Generator {
244
- generate: (sequent: Sequent, proof: Proof, time: Time) => Proof;
245
- collect: (proof: Proof) => Obligation[];
246
- mutate: (
247
- context: Hyp[],
248
- mode: "Use" | "Hide",
249
- usable: Usable,
250
- location: Locus | undefined,
251
- ) => [Hyp[], Obligation[]];
252
- simplify: (context: Hyp[], goal: Expr, proof: Proof, time: Time) => Proof;
253
- }
254
-
255
- // The bounds after a witnessed one, where a ditto takes the witnessed domain.
256
- const getRemainingBounds = (first: Bound, rest: Bound[]): Bound[] => {
257
- const shifted = substituteBounds(shift(1), rest)[1];
258
- return shifted[0].domain.kind === "Ditto" && first.domain.kind === "Domain"
259
- ? [
260
- {
261
- ...shifted[0],
262
- domain: { kind: "Domain", expression: shiftExpr(1, first.domain.expression) },
263
- },
264
- ...shifted.slice(1),
265
- ]
266
- : shifted;
267
- };
268
-
269
- // A WITNESS proves each membership and subset it relies on, then the goal from them.
270
- const getWitnessProof = (step: Step, aux: Expr[]): Proof => {
271
- if (step.isSuppressed || aux.length === 0) return { kind: "Obvious", ...getProps(step) };
272
- const steps = aux.map((item, index): Step => {
273
- const active = shiftExpr(2 * index + 2, item);
274
- return {
275
- kind: "Assert",
276
- sequent: { context: [], active },
277
- proof: {
278
- kind: "By",
279
- usable: { facts: [shiftExpr(3, active)], defs: [] },
280
- isOnly: false,
281
- location: item.location,
282
- method: step.method,
283
- },
284
- location: item.location,
285
- };
286
- });
287
- const facts = [
288
- at({ kind: "Ix", index: 2 * aux.length + 2 }, step),
289
- ...aux.map((_item, index) => at({ kind: "Ix", index: 2 * (aux.length - index) }, step)),
290
- ];
291
- // tlapm removes the method from the QED.
292
- const qedProof: Proof = {
293
- kind: "By",
294
- usable: { facts, defs: [] },
295
- isOnly: true,
296
- ...getProps(step),
297
- method: undefined,
298
- };
299
- return {
300
- kind: "Steps",
301
- steps,
302
- qed: { proof: qedProof, location: qedProof.location },
303
- ...getProps(step),
304
- };
305
- };
306
-
307
166
  const obligate = (
308
167
  sequent: Sequent,
309
168
  from: { location?: Locus; method?: OldMethod },
310
169
  kind: ObligationKind,
311
170
  ): Obligation => ({ sequent, location: from.location, kind, method: from.method });
312
171
 
313
- export interface ProofSummary {
172
+ interface ProofSummary {
314
173
  total: number;
315
174
  absent: Locus[];
316
175
  omitted: Locus[];
317
176
  }
318
177
 
319
- export const EMPTY_SUMMARY: ProofSummary = { total: 0, absent: [], omitted: [] };
178
+ const EMPTY_SUMMARY: ProofSummary = { total: 0, absent: [], omitted: [] };
320
179
 
321
- export const joinSummaries = (left: ProofSummary, right: ProofSummary): ProofSummary => ({
180
+ const joinSummaries = (left: ProofSummary, right: ProofSummary): ProofSummary => ({
322
181
  total: left.total + right.total,
323
182
  absent: [...left.absent, ...right.absent],
324
183
  omitted: [...left.omitted, ...right.omitted],
325
184
  });
326
185
 
327
186
  const getStepSummary = (step: Step): ProofSummary => {
328
- switch (step.kind) {
329
- case "Use":
330
- return { ...EMPTY_SUMMARY, total: step.obligations?.length ?? 0 };
331
- case "Assert":
332
- case "Suffices":
333
- case "Pcase":
334
- case "Pick":
335
- return getProofSummary(step.proof);
336
- default:
337
- return EMPTY_SUMMARY;
338
- }
187
+ if (step.kind === "Use") return { ...EMPTY_SUMMARY, total: step.obligations?.length ?? 0 };
188
+ return "proof" in step ? getProofSummary(step.proof) : EMPTY_SUMMARY;
339
189
  };
340
190
 
341
- export const getProofSummary = (proof: Proof): ProofSummary => {
191
+ const getProofSummary = (proof: Proof): ProofSummary => {
342
192
  if (proof.kind === "Steps") {
343
193
  return [...proof.steps.map(getStepSummary), getProofSummary(proof.qed.proof)].reduce(
344
194
  joinSummaries,
@@ -353,17 +203,15 @@ export const getProofSummary = (proof: Proof): ProofSummary => {
353
203
  };
354
204
  };
355
205
 
356
- const replaceAt = (expression: Expr, replacement: Expr): Expr =>
357
- expression.kind === "At" && !expression.isExcept
358
- ? at(stripProps(replacement), expression)
359
- : mapChildren(expression, (inner) => replaceAt(inner, replacement));
206
+ export interface TheoremSummary extends ProofSummary {
207
+ location: Locus | undefined;
208
+ }
209
+
210
+ export interface ModuleSummary extends ProofSummary {
211
+ theorems: TheoremSummary[];
212
+ }
360
213
 
361
- export const createGenerator = (
362
- counter: Counter,
363
- inputFiles: Set<string>,
364
- lines: LineRange,
365
- onWarning: (warning: ObligationWarning) => void,
366
- ): Generator => {
214
+ export const createGenerator = (inputFiles: Set<string>, lines: LineRange, onWarning: Warn) => {
367
215
  const generate = (sequent: Sequent, proof: Proof, time: Time): Proof => {
368
216
  const location = proof.location;
369
217
  if (
@@ -420,11 +268,12 @@ export const createGenerator = (
420
268
  context: [
421
269
  ...sequent.context,
422
270
  {
423
- kind: "Fact",
424
- expression: fact,
425
- visibility: "Visible",
426
- time: getFactTime(sequent.context, fact, time),
427
- location: fact.location,
271
+ ...getFact(
272
+ fact,
273
+ "Visible",
274
+ getFactTime(sequent.context, fact, time),
275
+ fact.location,
276
+ ),
428
277
  useLocation: step.useLocation,
429
278
  },
430
279
  ],
@@ -544,604 +393,65 @@ export const createGenerator = (
544
393
  item.steps.forEach(visitStep);
545
394
  return;
546
395
  }
547
- if (item.obligations && !item.isSuppressed) obligations.push(...item.obligations);
396
+ if (item.obligations) obligations.push(...item.obligations);
548
397
  };
549
398
  const visitStep = (step: Step) => {
550
- if (step.kind === "Use" && step.obligations && !step.isSuppressed)
551
- obligations.push(...step.obligations);
552
- if (
553
- step.kind === "Assert" ||
554
- step.kind === "Suffices" ||
555
- step.kind === "Pcase" ||
556
- step.kind === "Pick"
557
- ) {
558
- visitProof(step.proof);
559
- }
399
+ if (step.kind === "Use" && step.obligations) obligations.push(...step.obligations);
400
+ if ("proof" in step) visitProof(step.proof);
560
401
  };
561
402
  visitProof(proof);
562
403
  return obligations;
563
404
  };
564
405
 
565
- const getAnonymous = (level: number): StepNumber => ({
566
- kind: "Named",
567
- level,
568
- label: `_a${getUnique(counter)}`,
569
- isAnonymous: true,
570
- });
571
-
572
- const renumberNumber = (level: number, step: StepNumber | undefined): StepNumber =>
573
- step?.kind === "Named" ? { ...step, level } : getAnonymous(level);
574
-
575
- const renumber = (level: number, proof: Proof): Proof => {
576
- const renumbered: Proof = { ...proof, step: renumberNumber(level, proof.step) };
577
- if (renumbered.kind !== "Steps") return renumbered;
578
- const steps = renumbered.steps.map((step) => renumberStep(level, step));
579
- return {
580
- ...renumbered,
581
- steps,
582
- qed: { ...renumbered.qed, proof: renumber(level + 1, renumbered.qed.proof) },
583
- };
584
- };
585
-
586
- const renumberStep = (level: number, step: Step): Step => {
587
- const renumbered: Step = { ...step, step: renumberNumber(level, step.step) };
588
- switch (renumbered.kind) {
589
- case "Assert":
590
- case "Suffices":
591
- case "Pcase":
592
- case "Pick":
593
- return { ...renumbered, proof: renumber(level + 1, renumbered.proof) };
594
- default:
595
- return renumbered;
596
- }
597
- };
598
-
599
- const exposeConnective = (context: Hyp[], goal: Expr): Expr => {
600
- const head = goal.kind === "Apply" ? goal.operator : goal;
601
- if (head.kind === "Ix") {
602
- const hyp = context[context.length - head.index];
603
- if (!hyp) throw new TlaProofError("expose_connective");
604
- if (hyp.kind !== "Defn" || hyp.definition.kind !== "Operator") return goal;
605
- const body = shiftExpr(head.index, hyp.definition.body);
606
- if (goal.kind !== "Apply") return exposeConnective(context, body);
607
- const operator: Expr = { ...body, location: goal.location };
608
- return exposeConnective(context, at(normalizeApply(operator, goal.args), operator));
609
- }
610
- if (
611
- goal.kind === "Apply" &&
612
- goal.operator.kind === "Internal" &&
613
- goal.operator.builtin === "Prime"
614
- ) {
615
- const inner = exposeConnective(context, goal.args[0]);
616
- const prime = (expression: Expr) => applyBuiltin("Prime", [expression], expression);
617
- if (inner.kind === "Quant") {
618
- return at(
619
- {
620
- kind: "Quant",
621
- quantifier: inner.quantifier,
622
- bounds: inner.bounds.map((bound) =>
623
- bound.domain.kind === "Domain"
624
- ? {
625
- ...bound,
626
- domain: { kind: "Domain", expression: prime(bound.domain.expression) },
627
- }
628
- : bound,
629
- ),
630
- body: prime(inner.body),
631
- },
632
- goal,
633
- );
634
- }
635
- if (isBinary(inner, "Implies") || isBinary(inner, "Mem")) {
636
- return at(
637
- {
638
- kind: "Apply",
639
- operator: inner.operator,
640
- args: [prime(inner.args[0]), prime(inner.args[1])],
641
- },
642
- goal,
643
- );
644
- }
645
- return prime(inner);
646
- }
647
- if (goal.kind === "Parens") return exposeConnective(context, goal.expression);
648
- return goal;
649
- };
650
-
651
- const getRightOperand = (step: Step): Expr | undefined => {
652
- if (step.kind !== "Assert") return undefined;
653
- const active = step.sequent.active;
654
- return active.kind === "Apply" && active.args.length === 2 ? active.args[1] : undefined;
655
- };
656
-
657
- // at_expand: @ in a step stands for the right side of the previous step's assertion.
658
- const expandAt = (proof: Proof): Proof => {
659
- if (proof.kind !== "Steps") return proof;
660
- const steps: Step[] = [];
661
- proof.steps.forEach((step) => {
662
- const previous = steps.at(-1);
663
- const right = previous && getRightOperand(previous);
664
- if (step.kind !== "Assert" || !right) {
665
- steps.push(step);
666
- return;
667
- }
668
- const active = replaceAt(step.sequent.active, shiftExpr(2, right));
669
- steps.push({ ...step, sequent: { ...step.sequent, active } });
670
- });
671
- return { ...proof, steps };
672
- };
673
-
674
- const simplify = (context: Hyp[], goal: Expr, original: Proof, time: Time): Proof => {
675
- const proof = expandAt(original);
676
- switch (proof.kind) {
677
- case "Obvious":
678
- case "Omitted":
679
- case "Error":
680
- return proof;
681
- case "By": {
682
- const usable = proof.usable;
683
- const useDefs: Step[] =
684
- usable.defs.length === 0
685
- ? []
686
- : [
687
- {
688
- kind: "Use",
689
- usable: { facts: [], defs: usable.defs },
690
- isOnly: false,
691
- location: proof.location,
692
- },
693
- ];
694
- const useFacts = usable.facts.map((fact, index): Step => ({
695
- kind: "Use",
696
- usable: { facts: [shiftExpr(index, fact)], defs: [] },
697
- isOnly: false,
698
- location: fact.location,
699
- isSuppressed: proof.isSuppressed,
700
- useLocation: proof.location,
701
- }));
702
- const forget: Step[] = proof.isOnly
703
- ? [{ kind: "Forget", count: usable.facts.length, location: proof.location }]
704
- : [];
705
- const level = getLevel(proof.step);
706
- const steps = [...useDefs, ...useFacts, ...forget].map((step): Step => ({
707
- ...step,
708
- step: getAnonymous(level),
709
- }));
710
- const qedProof: Proof = {
711
- kind: "Obvious",
712
- location: proof.location,
713
- step: getAnonymous(level),
714
- isSuppressed: proof.isSuppressed,
715
- method: proof.method,
716
- };
717
- return {
718
- kind: "Steps",
719
- steps,
720
- qed: { proof: qedProof, location: qedProof.location, step: qedProof.step },
721
- location: proof.location,
722
- step: proof.step,
723
- isSuppressed: proof.isSuppressed,
724
- };
725
- }
726
- case "Steps": {
727
- const [inner, steps] = mapAccumulate(
728
- { context, goal, time },
729
- proof.steps,
730
- (state, step) => {
731
- const [nextContext, nextGoal, simplified, nextTime] = simplifyStep(
732
- state.context,
733
- state.goal,
734
- step,
735
- state.time,
736
- );
737
- return [{ context: nextContext, goal: nextGoal, time: nextTime }, simplified];
738
- },
739
- );
740
- const qedProof = simplify(inner.context, inner.goal, proof.qed.proof, inner.time);
741
- return { ...proof, steps: steps.flat(), qed: { ...proof.qed, proof: qedProof } };
742
- }
743
- }
744
- };
745
-
746
- const simplifyStep = (
747
- context: Hyp[],
748
- goal: Expr,
749
- step: Step,
750
- time: Time,
751
- ): [Hyp[], Expr, Step[], Time] => {
752
- const level = getLevel(step.step);
753
- switch (step.kind) {
754
- case "Forget":
755
- return [context, goal, [step], time];
756
- case "Assert": {
757
- const inner = proveAssertion(context, step.sequent, step, time);
758
- const simplified: Step = {
759
- ...step,
760
- proof: simplify(inner.context, inner.active, step.proof, inner.time),
761
- };
762
- const next = useAssertion(false, context, goal, step.sequent, simplified, time);
763
- return [next.context, next.active, [simplified], time];
764
- }
765
- case "Suffices": {
766
- const inner = useAssertion(true, context, goal, step.sequent, step, time);
767
- const simplified: Step = {
768
- ...step,
769
- proof: simplify(inner.context, inner.active, step.proof, time),
770
- };
771
- const next = proveAssertion(context, step.sequent, simplified, time);
772
- return [next.context, next.active, [simplified], next.time];
773
- }
774
- case "Use": {
775
- const byProof: Proof = {
776
- kind: "By",
777
- usable: step.usable,
778
- isOnly: step.isOnly,
779
- location: step.location,
780
- step: step.step,
781
- isSuppressed: step.isSuppressed,
782
- method: step.method,
783
- };
784
- const simplified = simplify(context, goal, byProof, time);
785
- if (simplified.kind !== "Steps")
786
- throw new TlaProofError("simplifying BY does not produce a non-leaf proof!");
787
- const assumed = step.usable.facts.map((): Hyp => ({
788
- kind: "Fact",
789
- expression: AT_NOWHERE,
790
- visibility: "Visible",
791
- time,
792
- location: step.location,
793
- }));
794
- return [
795
- [...context, ...assumed],
796
- shiftExpr(step.usable.facts.length, goal),
797
- simplified.steps,
798
- time,
799
- ];
800
- }
801
- case "Hide": {
802
- const hidden = step.usable.defs.reduce((current, def) => {
803
- if (def.kind !== "Dx") throw new TlaProofError("set_vis");
804
- const index = current.length - def.index;
805
- const hyp = current[index];
806
- if (hyp?.kind !== "Defn") {
807
- const name = hyp ? (hyp.kind === "Fact" ? "??? FACT ???" : hyp.name) : "";
808
- throw new TlaProofError(
809
- `USE DEF ${name} invalid because ${name} is not a defined operator`,
810
- );
811
- }
812
- return current.map((entry, position) =>
813
- position === index
814
- ? { ...hyp, visibility: "Hidden" as const, location: step.location }
815
- : entry,
816
- );
817
- }, context);
818
- return [hidden, goal, [step], time];
819
- }
820
- case "Define":
821
- return [
822
- [
823
- ...context,
824
- ...step.definitions.map((definition): Hyp => ({
825
- kind: "Defn",
826
- definition,
827
- whereDefined: { kind: "Proof", time },
828
- visibility: "Visible",
829
- isLocal: true,
830
- location: step.location,
831
- })),
832
- ],
833
- shiftExpr(step.definitions.length, goal),
834
- [step],
835
- time,
836
- ];
837
- case "Have": {
838
- const connective = exposeConnective(context, goal);
839
- const fact: Hyp = {
840
- kind: "Fact",
841
- expression: step.expression,
842
- visibility: "Visible",
843
- time,
844
- location: step.location,
845
- };
846
- const isImplication = isBinary(connective, "Implies");
847
- const sequent: Sequent = {
848
- context: [fact],
849
- active: isImplication ? shiftExpr(1, connective.args[1]) : connective,
850
- };
851
- const proof: Proof = isImplication
852
- ? {
853
- kind: "By",
854
- usable: { facts: [at({ kind: "Ix", index: 2 }, step)], defs: [] },
855
- isOnly: true,
856
- ...getProps(step),
857
- }
858
- : {
859
- kind: "Error",
860
- message: getMessage(
861
- "@.@[<v2>@[%s@ %s@]@,%a@]@.",
862
- "Error: this HAVE step is applied to the following goal,",
863
- "which is not an implication:",
864
- printExpression(context, goal),
865
- ),
866
- ...getProps(step),
867
- };
868
- const suffices = renumberStep(level, {
869
- kind: "Suffices",
870
- sequent,
871
- proof,
872
- location: step.location,
873
- step: step.step,
874
- });
875
- return simplifyStep(context, goal, suffices, time);
876
- }
877
- case "Take":
878
- return simplifyStep(
879
- context,
880
- goal,
881
- renumberStep(level, getTakeSuffices(context, goal, step)),
882
- time,
883
- );
884
- case "Witness":
885
- return simplifyStep(
886
- context,
887
- goal,
888
- renumberStep(level, getWitnessSuffices(context, goal, step)),
889
- time,
890
- );
891
- case "Pcase": {
892
- const assertion: Step = {
893
- kind: "Assert",
894
- sequent: {
895
- context: [
896
- {
897
- kind: "Fact",
898
- expression: step.expression,
899
- visibility: "Visible",
900
- time,
901
- location: step.location,
902
- },
903
- ],
904
- active: shiftExpr(1, goal),
905
- },
906
- proof: step.proof,
907
- ...getProps(step),
908
- };
909
- return simplifyStep(context, goal, renumberStep(level, assertion), time);
910
- }
911
- case "Pick": {
912
- const existential: Expr = at(
913
- { kind: "Quant", quantifier: "Exists", bounds: step.bounds, body: step.expression },
914
- step,
915
- );
916
- const salted = getSalted(step.step, "ex");
917
- const [assertContext, assertGoal, asserted, assertTime] = simplifyStep(
918
- context,
919
- goal,
920
- {
921
- kind: "Assert",
922
- sequent: { context: [], active: existential },
923
- proof: step.proof,
924
- ...getProps(step),
925
- step: salted,
926
- },
927
- time,
928
- );
929
- const shifted = shiftExpr(2, existential);
930
- if (shifted.kind !== "Quant") throw new TlaProofError("Proof.Simplify.simplify_step/PICK");
931
- const hyps = [
932
- ...getBoundHyps(shifted.bounds),
933
- {
934
- kind: "Fact",
935
- expression: shifted.body,
936
- visibility: "Visible",
937
- time: assertTime,
938
- location: shifted.body.location,
939
- } satisfies Hyp,
940
- ];
941
- const [nextContext, nextGoal, sufficed, nextTime] = simplifyStep(
942
- assertContext,
943
- assertGoal,
944
- {
945
- kind: "Suffices",
946
- sequent: { context: hyps, active: shiftExpr(hyps.length, assertGoal) },
947
- proof: { kind: "Omitted", omission: "Elsewhere", ...getProps(step) },
948
- ...getProps(step),
949
- },
950
- assertTime,
951
- );
952
- return [nextContext, nextGoal, [...asserted, ...sufficed], nextTime];
953
- }
954
- }
955
- };
956
-
957
- const getSalted = (step: StepNumber | undefined, salt: string): StepNumber => ({
958
- kind: "Named",
959
- level: getLevel(step),
960
- label: `${step?.kind === "Named" ? step.label : "_a"}${salt}${getUnique(counter)}`,
961
- isAnonymous: false,
962
- });
963
-
964
- const getTakeSuffices = (context: Hyp[], goal: Expr, step: Step & { kind: "Take" }): Step => {
965
- const bounds = expandDittoes(step.bounds);
966
- const stripBounds = (
967
- amount: number,
968
- aux: Expr[],
969
- current: Expr,
970
- rest: Bound[],
971
- ): { aux: Expr[]; goal: Expr } | string => {
972
- const bound = rest[0];
973
- if (!bound) return { aux, goal: current };
974
- const exposed = exposeConnective(context, current);
975
- if (
976
- exposed.kind !== "Quant" ||
977
- exposed.quantifier !== "Forall" ||
978
- exposed.bounds.length === 0
979
- ) {
980
- return getMessage(
981
- "@.@[<v2>@[<b0>%s@ %s@]@,%a@]@.",
982
- "Error: this TAKE step is applied to the following goal,",
983
- "which is not a universal formula:",
984
- printExpression(context, current),
985
- );
986
- }
987
- const goalBound = exposed.bounds[0];
988
- const goalBounds = expandDittoes(exposed.bounds).slice(1);
989
- const domain = bound.domain;
990
- const goalDomain = goalBound.domain;
991
- if (domain.kind === "NoDomain" && goalDomain.kind === "Domain") {
992
- return getMessage(
993
- "@.@[<b0>%s (%s)@ %s (%s \\in %a)@]@.",
994
- "Error: the TAKE argument",
995
- bound.name,
996
- "does not match the pattern",
997
- goalBound.name,
998
- printExpression(context, goalDomain.expression),
999
- );
1000
- }
1001
- if (domain.kind === "Domain" && goalDomain.kind === "NoDomain") {
1002
- return getMessage(
1003
- "@.@[<b0>%s (%s \\in %a)@ %s (%s)@]@.",
1004
- "Error: the TAKE argument",
1005
- bound.name,
1006
- printExpression(context, domain.expression),
1007
- "does not match the pattern",
1008
- goalBound.name,
1009
- );
1010
- }
1011
- const nextAux =
1012
- domain.kind === "Domain" &&
1013
- goalDomain.kind === "Domain" &&
1014
- !isEqualExpr(domain.expression, goalDomain.expression)
1015
- ? [
1016
- {
1017
- kind: "Apply",
1018
- operator: { kind: "Internal", builtin: "Subseteq" },
1019
- args: [goalDomain.expression, domain.expression],
1020
- } satisfies Expr,
1021
- ...aux,
1022
- ]
1023
- : aux;
1024
- if (goalBounds.length === 0) return stripBounds(1, nextAux, exposed.body, rest.slice(1));
1025
- const shiftedBounds =
1026
- rest.length === 1
1027
- ? goalBounds.map((item) => substituteBounds(shift(amount), [item])[1][0])
1028
- : goalBounds;
1029
- return stripBounds(
1030
- amount + 1,
1031
- nextAux,
1032
- at(
1033
- { kind: "Quant", quantifier: "Forall", bounds: shiftedBounds, body: exposed.body },
1034
- exposed,
1035
- ),
1036
- rest.slice(1),
1037
- );
1038
- };
1039
- const stripped = stripBounds(1, [], goal, bounds);
1040
- if (typeof stripped === "string") {
1041
- return {
1042
- kind: "Suffices",
1043
- sequent: {
1044
- context: [
1045
- {
1046
- kind: "Fact",
1047
- expression: getTrue(goal),
1048
- visibility: "Visible",
1049
- time: "Now",
1050
- location: step.location,
1051
- },
1052
- ],
1053
- active: goal,
1054
- },
1055
- proof: { kind: "Error", message: stripped, ...getProps(step) },
1056
- ...getProps(step),
1057
- };
1058
- }
1059
- const unique = stripped.aux.filter(
1060
- (item, index) => stripped.aux.findIndex((other) => isEqualExpr(item, other)) === index,
1061
- );
1062
- const facts = [at({ kind: "Ix", index: 2 }, step), ...unique.map((item) => shiftExpr(2, item))];
1063
- return {
1064
- kind: "Suffices",
1065
- sequent: { context: getBoundHyps(bounds), active: stripped.goal },
1066
- proof: { kind: "By", usable: { facts, defs: [] }, isOnly: true, ...getProps(step) },
1067
- ...getProps(step),
1068
- };
1069
- };
1070
-
1071
- const getWitnessSuffices = (
406
+ // Module.Gen.generate.
407
+ const generateModule = (
1072
408
  context: Hyp[],
1073
- goal: Expr,
1074
- step: Step & { kind: "Witness" },
1075
- ): Step => {
1076
- const aux: Expr[] = [];
1077
- let error = "";
1078
- let current = goal;
1079
- for (const witness of step.expressions) {
1080
- const exposed = exposeConnective(context, current);
1081
- if (
1082
- exposed.kind !== "Quant" ||
1083
- exposed.quantifier !== "Exists" ||
1084
- exposed.bounds.length === 0
1085
- ) {
1086
- error ||= getMessage(
1087
- "@.@[<v2>@[<b0>%s@ %s@]@,%a@]@.",
1088
- "Error: this WITNESS step is applied to the following goal,",
1089
- "which is not an existential formula:",
1090
- printExpression(context, exposed),
1091
- );
1092
- current = exposed;
1093
- break;
1094
- }
1095
- const [first, ...rest] = exposed.bounds;
1096
- const next =
1097
- rest.length === 0
1098
- ? exposed.body
1099
- : at(
1100
- {
1101
- kind: "Quant",
1102
- quantifier: "Exists",
1103
- bounds: getRemainingBounds(first, rest),
1104
- body: exposed.body,
1105
- },
1106
- exposed,
1107
- );
1108
- let value = witness;
1109
- if (first.domain.kind === "Domain") {
1110
- const domain = first.domain.expression;
1111
- const membership = exposeConnective(context, witness);
1112
- if (isBinary(membership, "Mem")) {
1113
- const [term, termDomain] = membership.args;
1114
- const subset = isEqualExpr(termDomain, domain)
1115
- ? []
1116
- : [applyBuiltin("Subseteq", [termDomain, domain], termDomain)];
1117
- aux.push(...subset, membership);
1118
- value = term;
1119
- } else {
1120
- error ||= getMessage(
1121
- "@.@[<b0>%s (%a)@ %s (%s \\in %a)@]@.",
1122
- "Error: the WITNESS argument",
1123
- printExpression(context, membership),
1124
- "does not match the pattern",
1125
- first.name,
1126
- printExpression(context, domain),
409
+ module: Mule,
410
+ ): { obligations: Obligation[]; summary: ModuleSummary } => {
411
+ const obligations: Obligation[] = [];
412
+ const theorems: TheoremSummary[] = [];
413
+ let summary = EMPTY_SUMMARY;
414
+ let current = context;
415
+ for (const unit of module.body) {
416
+ switch (unit.kind) {
417
+ case "Theorem": {
418
+ const binding = bindTheoremName(unit.name, unit.sequent, unit.location);
419
+ const named = [...current, ...binding.hyps];
420
+ const context = [...named, ...binding.sequent.context];
421
+ const proof = generate(
422
+ { context, active: binding.sequent.active },
423
+ unit.proof,
424
+ getScopeTime(context, "Always"),
1127
425
  );
1128
- value = membership;
426
+ obligations.push(...collect(proof));
427
+ const theorem = getProofSummary(proof);
428
+ theorems.push({ ...theorem, location: unit.location });
429
+ summary = joinSummaries(summary, theorem);
430
+ const fact: Expr =
431
+ unit.name === undefined
432
+ ? at(exprifySequent(unit.sequent), unit)
433
+ : { kind: "Ix", index: 1, location: unit.location };
434
+ current = [...named, getFact(fact, "Hidden", "Always", unit.location)];
435
+ continue;
436
+ }
437
+ case "Submod": {
438
+ const generated = generateModule(current, unit.module);
439
+ obligations.push(...generated.obligations);
440
+ summary = joinSummaries(summary, generated.summary);
441
+ continue;
1129
442
  }
443
+ case "Mutate": {
444
+ const [next, generated] = mutate(current, unit.mode, unit.usable, unit.location);
445
+ obligations.push(...generated);
446
+ current = next;
447
+ continue;
448
+ }
449
+ default:
450
+ current = [...current, ...getUnitHyps(unit)];
1130
451
  }
1131
- const unprimable = applyBuiltin("Unprimable", [value], value);
1132
- current = substituteExpr(consSubstitution(unprimable, shift(0)), next);
1133
452
  }
1134
- const proof: Proof =
1135
- error === ""
1136
- ? getWitnessProof(step, aux)
1137
- : { kind: "Error", message: error, ...getProps(step) };
1138
- return {
1139
- kind: "Suffices",
1140
- sequent: { context: [], active: current },
1141
- proof,
1142
- ...getProps(step),
1143
- };
453
+ return { obligations, summary: { ...summary, theorems } };
1144
454
  };
1145
455
 
1146
- return { generate, collect, mutate, simplify };
456
+ return generateModule;
1147
457
  };