tla-ts 0.0.4-dev.b254db0 → 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 -10
  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,6 +1,6 @@
1
1
  // Worker threads that decide the obligations prove sends them, the earliest obligation first.
2
2
 
3
- import { TlaProverError, TlaUnsupportedError } from "../errors";
3
+ import { TlaProverError } from "../errors";
4
4
  import { spawnWorker, type WorkerHandle } from "../worker";
5
5
  import type { DecideOptions, Decision } from "./verdict";
6
6
 
@@ -10,10 +10,9 @@ export interface DecideRequest {
10
10
  timeLimitMs: number;
11
11
  }
12
12
 
13
- // A backend's decision, or the error that prove turns into a result.
14
- export type DecideResponse =
15
- | Decision
16
- | { error: { name: "TlaProverError" | "TlaUnsupportedError"; message: string } };
13
+ // A backend's decision, or the message of the TlaProverError it threw, which prove turns into a
14
+ // result.
15
+ export type DecideResponse = Decision | { error: string };
17
16
 
18
17
  interface PendingDecision {
19
18
  request: DecideRequest;
@@ -33,7 +32,7 @@ export interface DecidePool {
33
32
  terminate: (reason: unknown) => void;
34
33
  }
35
34
 
36
- export const createDecidePool = async (count: number): Promise<DecidePool> => {
35
+ export const createDecidePool = async (workerCount: number): Promise<DecidePool> => {
37
36
  const workers: WorkerHandle[] = [];
38
37
  const queue: PendingDecision[] = [];
39
38
  const running = new Map<number, PendingDecision>();
@@ -57,11 +56,7 @@ export const createDecidePool = async (count: number): Promise<DecidePool> => {
57
56
  running.delete(index);
58
57
  idle.push(index);
59
58
  if ("verdict" in response) decision?.resolve(response);
60
- if ("error" in response) {
61
- const ErrorClass =
62
- response.error.name === "TlaProverError" ? TlaProverError : TlaUnsupportedError;
63
- decision?.reject(new ErrorClass(response.error.message));
64
- }
59
+ if ("error" in response) decision?.reject(new TlaProverError(response.error));
65
60
  dispatch();
66
61
  };
67
62
  const terminate = (reason: unknown) => {
@@ -73,7 +68,7 @@ export const createDecidePool = async (count: number): Promise<DecidePool> => {
73
68
  };
74
69
  workers.push(
75
70
  ...(await Promise.all(
76
- Array.from({ length: count }, (_, index) =>
71
+ Array.from({ length: workerCount }, (_, index) =>
77
72
  spawnWorker(
78
73
  new URL("./prove-worker.js", import.meta.url),
79
74
  (message) => onResponse(index, message),
@@ -1,6 +1,10 @@
1
- // Tla_parser.pickle: renames an identifier that some backend would reject.
1
+ // What backend/zenon.ml and backend/isabelle.ml share in printing an obligation that Backend.Prep
2
+ // has shipped.
2
3
 
3
- import { TlapmBugError } from "../errors";
4
+ import { TlapmBugError, TlaProverError, TlaUnsupportedError } from "../errors";
5
+ import { popNames, type Context } from "../obligations/printer";
6
+ import { shiftExpr } from "../obligations/substitution";
7
+ import type { Bound, Builtin, Expr } from "../obligations/expression";
4
8
 
5
9
  const CHARACTER_NAMES: Record<string, string> = {
6
10
  "!": "excl_",
@@ -86,6 +90,7 @@ const getCharacterName = (character: string) => {
86
90
  return name;
87
91
  };
88
92
 
93
+ // Tla_parser.pickle: renames an identifier that some backend would reject.
89
94
  export const pickle = (name: string) => {
90
95
  const characters = [...name];
91
96
  const isPlain =
@@ -96,3 +101,75 @@ export const pickle = (name: string) => {
96
101
  if (isPlain) return name;
97
102
  return `a_${characters.map((character) => getCharacterName(character) ?? character).join("")}a`;
98
103
  };
104
+
105
+ // The temporal operators neither backend has a counterpart for, by the name tlapm reports.
106
+ const TEMPORAL_OPERATORS: Partial<Record<Builtin, [string, number]>> = {
107
+ Leadsto: ["Leadsto", 2],
108
+ ENABLED: ["ENABLED", 1],
109
+ Cdot: ["\\cdot", 2],
110
+ Actplus: ["-+->", 2],
111
+ BoxTrue: ["[]", 1],
112
+ BoxFalse: ["[]", 1],
113
+ Diamond: ["<>", 1],
114
+ };
115
+
116
+ // Why a backend can't print an application of builtin, which it reports as where.
117
+ export const getUnprintableError = (builtin: Builtin, arity: number, where: string) => {
118
+ const isFrontend = builtin === "Prime" || builtin === "StrongPrime" || builtin === "UNCHANGED";
119
+ if (isFrontend && arity === 1) return new TlapmBugError();
120
+ const temporal = TEMPORAL_OPERATORS[builtin];
121
+ return temporal && temporal[1] === arity
122
+ ? new TlaProverError(`Unsupported operator \`${temporal[0]}\`.\n`)
123
+ : new TlaProverError(where);
124
+ };
125
+
126
+ interface SplitQuantifier {
127
+ first: Bound;
128
+ inner: Expr;
129
+ }
130
+
131
+ // A quantifier's first bound binds around a quantifier over the others, which move under it. A
132
+ // ditto after the first bound copies its domain.
133
+ export const splitFirstBound = (
134
+ quantifier: "Forall" | "Exists",
135
+ bounds: Bound[],
136
+ body: Expr,
137
+ ): SplitQuantifier => {
138
+ const first = bounds[0];
139
+ const rest = bounds.slice(1);
140
+ const undittoed =
141
+ rest[0]?.domain.kind === "Ditto"
142
+ ? [{ ...rest[0], domain: first.domain }, ...rest.slice(1)]
143
+ : rest;
144
+ if (undittoed.length === 0) return { first, inner: body };
145
+ return {
146
+ first,
147
+ inner: {
148
+ kind: "Quant",
149
+ quantifier,
150
+ bounds: undittoed.map((other) =>
151
+ other.domain.kind === "Domain"
152
+ ? {
153
+ ...other,
154
+ domain: { kind: "Domain", expression: shiftExpr(1, other.domain.expression) },
155
+ }
156
+ : other,
157
+ ),
158
+ body,
159
+ location: body.location,
160
+ },
161
+ };
162
+ };
163
+
164
+ // tlapm prints a fact to a formatter that drops its output first, to omit an unsupported one: the
165
+ // fact's print, or the error that omits it once the names it bound are out of scope.
166
+ export const printFact = <Printed>(context: Context, print: () => Printed) => {
167
+ const depth = context.stack.length;
168
+ try {
169
+ return print();
170
+ } catch (error) {
171
+ if (!(error instanceof TlaUnsupportedError)) throw error;
172
+ popNames(context, context.stack.length - depth);
173
+ return error;
174
+ }
175
+ };
@@ -1,7 +1,7 @@
1
1
  // Decides a theory tlapm writes for Isabelle, as tlapm's Isabelle backend runs it: use_thy on the
2
2
  // heap of Isabelle/TLA+ succeeds or fails.
3
3
 
4
- import { TlaIsabelleError } from "../../errors";
4
+ import { isStackOverflow, TlaIsabelleError } from "../../errors";
5
5
  import type { DecideOptions, Verdict } from "../verdict";
6
6
  import { parseProofText, terminalProof } from "./isar/method";
7
7
  import { getFacts, initGoal } from "./isar/proof";
@@ -13,11 +13,6 @@ import { aconv } from "./pure/term";
13
13
  import { getProofContext } from "./tla/context";
14
14
  import { loadLogic } from "./tla/logic";
15
15
 
16
- // V8's error when a recursion runs out of stack. Poly/ML grows its stack instead, until the
17
- // recursion ends or Isabelle breaks down for lack of memory, which tlapm counts as a failure.
18
- const isStackOverflow = (error: unknown) =>
19
- error instanceof RangeError && error.message === "Maximum call stack size exceeded";
20
-
21
16
  export const decideIsabelle = (text: string, options: DecideOptions): Exclude<Verdict, "sat"> => {
22
17
  const limits = { deadline: Date.now() + options.timeLimitMs, signal: options.signal };
23
18
  try {
@@ -41,6 +36,8 @@ export const decideIsabelle = (text: string, options: DecideOptions): Exclude<Ve
41
36
  ? "unsat"
42
37
  : "unknown";
43
38
  } catch (error) {
39
+ // Poly/ML grows its stack instead, until Isabelle runs out of memory, which tlapm counts as a
40
+ // failure.
44
41
  if (error instanceof TlaIsabelleError || isStackOverflow(error)) return "unknown";
45
42
  throw error;
46
43
  }
@@ -2,15 +2,9 @@
2
2
  // An obligation as the Isabelle/TLA+ theory tlapm writes for Isabelle to prove with a tactic.
3
3
 
4
4
  import { TlapmBugError, TlaProverError, TlaUnsupportedError } from "../../errors";
5
- import { createContext, getBoundName, popNames, pushName } from "../../obligations/ctx";
6
- import {
7
- shiftExpr,
8
- type Bound,
9
- type Builtin,
10
- type Expr,
11
- type Sequent,
12
- } from "../../obligations/expression";
13
- import { pickle } from "../../obligations/pickle";
5
+ import { createContext, getBoundName, popNames, pushName } from "../../obligations/printer";
6
+ import type { Bound, Builtin, Expr, Sequent } from "../../obligations/expression";
7
+ import { getUnprintableError, pickle, printFact, splitFirstBound } from "../first-order";
14
8
 
15
9
  const cook = (name: string) => `is${pickle(name)}`;
16
10
 
@@ -85,17 +79,6 @@ const NONFIX: Partial<Record<Builtin, [string, number]>> = {
85
79
  ToString: ["ToString", 1],
86
80
  };
87
81
 
88
- // The temporal operators Isabelle/TLA+ has no counterpart for, by the name tlapm reports.
89
- const TEMPORAL: Partial<Record<Builtin, [string, number]>> = {
90
- Leadsto: ["Leadsto", 2],
91
- ENABLED: ["ENABLED", 1],
92
- Cdot: ["\\cdot", 2],
93
- Actplus: ["-+->", 2],
94
- BoxTrue: ["[]", 1],
95
- BoxFalse: ["[]", 1],
96
- Diamond: ["<>", 1],
97
- };
98
-
99
82
  // thy_header's tdoms_table: the operators the theory declares, with their arities.
100
83
  const DECLARED: [string, number][] = [
101
84
  ["Real", 0],
@@ -135,13 +118,12 @@ const printLemma = (sequent: Sequent) => {
135
118
  const context = createContext();
136
119
  const adjoin = (name: string) => pushName(context, pickle(name));
137
120
  const bump = () => pushName(context, "");
138
- const state = { isAssumed: false };
139
121
 
140
122
  // A binder's name binds in what prints inside it.
141
123
  const withBound = (name: string, print: (bound: string) => string) => {
142
- const doc = print(adjoin(name));
124
+ const printed = print(adjoin(name));
143
125
  popNames(context, 1);
144
- return doc;
126
+ return printed;
145
127
  };
146
128
 
147
129
  // pp_print_expr: every expression, apart from the obligation's sequent, prints in parentheses.
@@ -162,12 +144,7 @@ const printLemma = (sequent: Sequent) => {
162
144
  if (builtin === "Unprimable" && args.length === 1) return printExpr(args[0]);
163
145
  // tlapm prints an irregular expression as the hash of its TLA+ text, but never makes one.
164
146
  if (builtin === "Irregular" && args.length === 1) throw new TlaUnsupportedError("Irregular");
165
- const isFrontend = builtin === "Prime" || builtin === "StrongPrime" || builtin === "UNCHANGED";
166
- if (isFrontend && args.length === 1) throw new TlapmBugError();
167
- const temporal = TEMPORAL[builtin];
168
- if (temporal && temporal[1] === args.length)
169
- throw new TlaProverError(`Unsupported operator \`${temporal[0]}\`.\n`);
170
- throw new TlaProverError("Backend.Isabelle.pp_apply");
147
+ throw getUnprintableError(builtin, args.length, "Backend.Isabelle.pp_apply");
171
148
  };
172
149
 
173
150
  const printApply = (operator: Expr, args: Expr[]): string => {
@@ -186,49 +163,26 @@ const printLemma = (sequent: Sequent) => {
186
163
  // tlapm prints a lambda without the arguments it's applied to.
187
164
  case "Lambda": {
188
165
  const names = operator.params.map((param) => `${adjoin(param.name)} `).join("");
189
- const doc = `\\<lambda> ${names}. ${printExpr(operator.body)}`;
166
+ const printed = `\\<lambda> ${names}. ${printExpr(operator.body)}`;
190
167
  popNames(context, operator.params.length);
191
- return doc;
168
+ return printed;
192
169
  }
193
170
  default:
194
171
  throw new TlapmBugError();
195
172
  }
196
173
  };
197
174
 
198
- // The first bound binds around a quantifier over the others, which move under it.
199
175
  const printQuant = (quantifier: "Forall" | "Exists", bounds: Bound[], body: Expr): string => {
200
176
  if (bounds.length === 0) return formatExpr(body);
201
- const bound = bounds[0];
202
- const rest = bounds.slice(1);
203
- const undittoed =
204
- rest[0]?.domain.kind === "Ditto"
205
- ? [{ ...rest[0], domain: bound.domain }, ...rest.slice(1)]
206
- : rest;
207
- const inner: Expr =
208
- undittoed.length === 0
209
- ? body
210
- : {
211
- kind: "Quant",
212
- quantifier,
213
- bounds: undittoed.map((other) =>
214
- other.domain.kind === "Domain"
215
- ? {
216
- ...other,
217
- domain: { kind: "Domain", expression: shiftExpr(1, other.domain.expression) },
218
- }
219
- : other,
220
- ),
221
- body,
222
- location: body.location,
223
- };
177
+ const split = splitFirstBound(quantifier, bounds, body);
224
178
  const symbol = quantifier === "Forall" ? "\\<forall>" : "\\<exists>";
225
- if (bound.domain.kind === "NoDomain")
226
- return withBound(bound.name, (name) => `${symbol}${name} : ${printExpr(inner)}`);
227
- if (bound.domain.kind !== "Domain") throw new TlapmBugError();
228
- const domain = printExpr(bound.domain.expression);
179
+ if (split.first.domain.kind === "NoDomain")
180
+ return withBound(split.first.name, (name) => `${symbol}${name} : ${printExpr(split.inner)}`);
181
+ if (split.first.domain.kind !== "Domain") throw new TlapmBugError();
182
+ const domain = printExpr(split.first.domain.expression);
229
183
  return withBound(
230
- bound.name,
231
- (name) => `${symbol} ${name} \\<in> ${domain} : ${printExpr(inner)}`,
184
+ split.first.name,
185
+ (name) => `${symbol} ${name} \\<in> ${domain} : ${printExpr(split.inner)}`,
232
186
  );
233
187
  };
234
188
 
@@ -256,9 +210,9 @@ const printLemma = (sequent: Sequent) => {
256
210
  case "Fact": {
257
211
  const fact = hyp.visibility === "Visible" ? printExpr(hyp.expression) : undefined;
258
212
  bump();
259
- const doc = fact ? `(${fact} \\<Longrightarrow> ${printRest()})` : printRest();
213
+ const printed = fact ? `(${fact} \\<Longrightarrow> ${printRest()})` : printRest();
260
214
  popNames(context, 1);
261
- return doc;
215
+ return printed;
262
216
  }
263
217
  case "Defn":
264
218
  throw new TlaUnsupportedError("Inner definition");
@@ -339,10 +293,10 @@ const printLemma = (sequent: Sequent) => {
339
293
  });
340
294
  }
341
295
  case "FcnApp": {
342
- const fcn = printExpr(expression.function);
296
+ const printedFunction = printExpr(expression.function);
343
297
  return expression.args.length === 1
344
- ? `fapply (${fcn}, ${printExpr(expression.args[0])})`
345
- : `fapply (${fcn}, <<${delimited(expression.args)}>>)`;
298
+ ? `fapply (${printedFunction}, ${printExpr(expression.args[0])})`
299
+ : `fapply (${printedFunction}, <<${delimited(expression.args)}>>)`;
346
300
  }
347
301
  case "Arrow":
348
302
  return `[${printExpr(expression.domain)} \\<rightarrow> ${printExpr(expression.range)}]`;
@@ -394,20 +348,8 @@ const printLemma = (sequent: Sequent) => {
394
348
  }
395
349
  };
396
350
 
397
- // tlapm prints a fact to a formatter that drops its output first, to omit an unsupported one.
398
- const getFact = (expression: Expr) => {
399
- const depth = context.stack.length;
400
- try {
401
- return printExpr(expression);
402
- } catch (error) {
403
- if (!(error instanceof TlaUnsupportedError)) throw error;
404
- popNames(context, context.stack.length - depth);
405
- return error;
406
- }
407
- };
408
-
409
- // pp_print_sequent_outer: the obligation's sequent as the fixes, assumes and shows of a lemma. A
410
- // pragma's definition ends it, without the goal.
351
+ // pp_print_sequent_outer: the obligation's sequent as the lines of a lemma's fixes, assumes and
352
+ // shows. A pragma's definition ends it with an empty line in place of the goal.
411
353
  const printSequent = (sequent: Sequent) => {
412
354
  const lines: string[] = [];
413
355
  for (const hyp of sequent.context) {
@@ -423,35 +365,40 @@ const printLemma = (sequent: Sequent) => {
423
365
  const name = adjoin(hyp.name);
424
366
  lines.push(`fixes ${name}`);
425
367
  if (domain === undefined) break;
426
- state.isAssumed = true;
427
368
  lines.push(`assumes ${name}_in : "(${name} \\<in> ${domain})"`);
428
369
  break;
429
370
  }
430
371
  case "Fact": {
431
372
  const count = context.stack.length;
432
- const fact = hyp.visibility === "Visible" ? getFact(hyp.expression) : undefined;
373
+ const fact =
374
+ hyp.visibility === "Visible"
375
+ ? printFact(context, () => printExpr(hyp.expression))
376
+ : undefined;
433
377
  bump();
434
378
  if (fact instanceof TlaUnsupportedError) {
435
379
  lines.push(`(* omitted temporal assumption : ${fact.message} *)`);
436
380
  break;
437
381
  }
438
382
  if (fact === undefined) break;
439
- state.isAssumed = true;
440
383
  lines.push(`assumes v'${count}: "${fact}"`);
441
384
  break;
442
385
  }
443
386
  case "Defn":
444
- if (hyp.definition.kind === "Bpragma") return lines.map((line) => `${line}\n`).join("");
387
+ if (hyp.definition.kind === "Bpragma") return [...lines, ""];
445
388
  lines.push(`(* usable definition ${hyp.definition.name} suppressed *)`);
446
389
  adjoin(hyp.definition.name);
447
390
  break;
448
391
  }
449
392
  }
450
- return [...lines, `shows "${printExpr(sequent.active)}"`].join("\n");
393
+ return [...lines, `shows "${printExpr(sequent.active)}"`];
451
394
  };
452
395
 
453
396
  try {
454
- return { text: printSequent(sequent), isAssumed: state.isAssumed };
397
+ const lines = printSequent(sequent);
398
+ return {
399
+ text: lines.join("\n"),
400
+ isAssumed: lines.some((line) => line.startsWith("assumes ")),
401
+ };
455
402
  } catch (error) {
456
403
  if (!(error instanceof TlaUnsupportedError)) throw error;
457
404
  throw new TlaProverError(`isabelle : unsupported operator ${error.message}`);
@@ -459,15 +406,10 @@ const printLemma = (sequent: Sequent) => {
459
406
  };
460
407
 
461
408
  // thy_temp: the theory tlapm writes for Isabelle to prove obligation id.
462
- export const encodeIsabelle = (
463
- id: number,
464
- sequent: Sequent,
465
- tactic: string,
466
- theoryName: string,
467
- ): string => {
409
+ export const encodeIsabelle = (id: number, sequent: Sequent, tactic: string): string => {
468
410
  const lemma = printLemma(sequent);
469
411
  return [
470
- ...getTheoryHeader(theoryName, false),
412
+ ...getTheoryHeader(`tlapm_${id}`, false),
471
413
  `lemma ob'${id}:`,
472
414
  `${lemma.text}(is "PROP ?ob'${id}")`,
473
415
  "proof -",
@@ -7,7 +7,7 @@
7
7
  import { TlaIsabelleError } from "../../../errors";
8
8
  import { funT, mkType, propT, type Typ } from "../pure/term";
9
9
 
10
- export const TLA_TYPE = mkType("PredicateLogic.c");
10
+ const TLA_TYPE = mkType("PredicateLogic.c");
11
11
 
12
12
  // A parsed term before names resolve and types are inferred. A name is a bound or free variable
13
13
  // or a constant; a constant comes from notation.
@@ -50,12 +50,12 @@ import { proverTac, type IntuitionisticContext } from "../tools/intuitionistic";
50
50
  import { insertTac } from "./proof";
51
51
  import type { OuterToken } from "./theory";
52
52
 
53
- export interface Modifier {
53
+ interface Modifier {
54
54
  readonly kind: "intro" | "dest";
55
55
  readonly facts: readonly string[];
56
56
  }
57
57
 
58
- export type MethodText =
58
+ type MethodText =
59
59
  | {
60
60
  readonly kind: "auto" | "blast" | "force" | "clarsimp";
61
61
  readonly modifiers: readonly Modifier[];
@@ -66,7 +66,7 @@ export type MethodText =
66
66
  | { readonly kind: "try"; readonly method: MethodText };
67
67
 
68
68
  // The methods of by: the initial one, and the terminal one that qed runs.
69
- export interface ProofText {
69
+ interface ProofText {
70
70
  readonly initial: MethodText;
71
71
  readonly terminal: MethodText | undefined;
72
72
  }
@@ -32,7 +32,7 @@ import type { Ast } from "./inner-syntax";
32
32
  // The name a type parameter carries until it is fixed, as Type_Infer.param does.
33
33
  const PARAM_NAME = "?'a";
34
34
 
35
- export interface NameScope {
35
+ interface NameScope {
36
36
  readonly consts: ReadonlyMap<string, ConstInfo>;
37
37
  // The constant an unqualified name stands for.
38
38
  readonly constNames: ReadonlyMap<string, string>;
@@ -44,7 +44,7 @@ import {
44
44
  type VarRef,
45
45
  } from "./term";
46
46
 
47
- export type { BlastContext, BlastData } from "./state";
47
+ export type { BlastContext } from "./state";
48
48
 
49
49
  // Blast's depth_limit configuration option.
50
50
  const DEPTH_LIMIT = 20;
@@ -30,7 +30,7 @@ import {
30
30
  type BlastTerm,
31
31
  } from "./term";
32
32
 
33
- export const negate = (state: BlastState, term: BlastTerm) =>
33
+ const negate = (state: BlastState, term: BlastTerm) =>
34
34
  mkBlastApp(mkBlastConst(state.context.data.notName), term);
35
35
 
36
36
  // Converts a *Goal* to an ordinary negation.
@@ -169,7 +169,7 @@ export const blastAconv = (left: BlastTerm, right: BlastTerm): boolean => {
169
169
  const blastAconvs = (lefts: readonly BlastTerm[], rights: readonly BlastTerm[]) =>
170
170
  lefts.length === rights.length && lefts.every((left, index) => blastAconv(left, rights[index]));
171
171
 
172
- export const memTerm = (term: BlastTerm, terms: readonly BlastTerm[]) =>
172
+ const memTerm = (term: BlastTerm, terms: readonly BlastTerm[]) =>
173
173
  terms.some((other) => blastAconv(term, other));
174
174
 
175
175
  export const insTerm = (term: BlastTerm, terms: readonly BlastTerm[]) =>
@@ -178,7 +178,7 @@ export const insTerm = (term: BlastTerm, terms: readonly BlastTerm[]) =>
178
178
  export const sameVars = (left: readonly VarRef[], right: readonly VarRef[]) =>
179
179
  left.length === right.length && left.every((ref, index) => ref === right[index]);
180
180
 
181
- export const memVar = (ref: VarRef, refs: readonly VarRef[]) => refs.includes(ref);
181
+ const memVar = (ref: VarRef, refs: readonly VarRef[]) => refs.includes(ref);
182
182
 
183
183
  const insVar = (ref: VarRef, refs: readonly VarRef[]) =>
184
184
  memVar(ref, refs) ? refs : [ref, ...refs];
@@ -525,8 +525,7 @@ export const toTerm = (depth: number, term: BlastTerm): Term => {
525
525
  }
526
526
  };
527
527
 
528
- export const stripTrueprop = (trueprop: string, term: BlastTerm) =>
529
- destConstApp(term, trueprop) ?? term;
528
+ const stripTrueprop = (trueprop: string, term: BlastTerm) => destConstApp(term, trueprop) ?? term;
530
529
 
531
530
  // A1 ==> ... ==> An ==> B goes to [A1, ..., An], where B is not an implication.
532
531
  export const stripBlastImpPrems = (trueprop: string, term: BlastTerm): BlastTerm[] =>
@@ -120,7 +120,7 @@ const pruneParamsTac = (simp: SimpContext): Tactic => {
120
120
  );
121
121
  };
122
122
 
123
- export const mkAutoTac = (context: ClasimpContext, depth: number, nodupDepth: number): Tactic => {
123
+ const mkAutoTac = (context: ClasimpContext, depth: number, nodupDepth: number): Tactic => {
124
124
  const mainTac = orElseGoal(context.blastDepthTac(context.classical, depth), (index) =>
125
125
  changed(nodupDepthTac(addss(context), nodupDepth)(index)),
126
126
  );
@@ -264,7 +264,7 @@ export const appWrappers = (context: ClassicalContext, tactic: GoalTactic) =>
264
264
  context.claset.uwrappers.reduce((result, wrapper) => wrapper.wrap(result), tactic);
265
265
 
266
266
  // contr_tac: solves a goal that assumes both P and ~P.
267
- export const contrTac = (context: ClassicalContext): GoalTactic =>
267
+ const contrTac = (context: ClassicalContext): GoalTactic =>
268
268
  thenGoal(
269
269
  eresolveTac(context.limits, [context.data.notElim]),
270
270
  orElseGoal(eqAssumeTac, assumeTac(context.limits)),
@@ -280,7 +280,7 @@ const eqMpTac =
280
280
  );
281
281
 
282
282
  // safe_step_tac: one safe inference, by matching rather than unification.
283
- export const safeStepTac = (context: ClassicalContext): GoalTactic =>
283
+ const safeStepTac = (context: ClassicalContext): GoalTactic =>
284
284
  appSWrappers(
285
285
  context,
286
286
  firstGoal([
@@ -365,7 +365,7 @@ export const unsafeStepTac = (context: ClassicalContext): GoalTactic =>
365
365
  biresolveFromNetsTac(context.limits, context.claset.unsafe);
366
366
 
367
367
  // step_tac: a safe step, or else an unsafe one.
368
- export const stepTac =
368
+ const stepTac =
369
369
  (context: ClassicalContext): GoalTactic =>
370
370
  (index) =>
371
371
  orElse(
@@ -16,7 +16,6 @@ import {
16
16
  every,
17
17
  firstGoal,
18
18
  noTac,
19
- orElseGoal,
20
19
  repeatDetermN,
21
20
  repeatDeterm1,
22
21
  subgoal,
@@ -73,7 +72,7 @@ export interface HypsubstData {
73
72
  readonly thinRefl: Thm;
74
73
  }
75
74
 
76
- export interface HypsubstContext {
75
+ interface HypsubstContext {
77
76
  readonly limits: Limits;
78
77
  readonly data: HypsubstData;
79
78
  }
@@ -368,13 +367,6 @@ export const hypSubstTac =
368
367
  ])(index),
369
368
  );
370
369
 
371
- export const boundHypSubstTac =
372
- (context: HypsubstContext): GoalTactic =>
373
- (index) =>
374
- repeatDeterm1(
375
- orElseGoal(genHypSubstTac(context, true), varsGenHypSubstTac(context, true))(index),
376
- );
377
-
378
370
  const reverseNTac = (context: HypsubstContext, count: number, index: number): Tactic =>
379
371
  count === 0
380
372
  ? allTac
@@ -17,7 +17,7 @@ import {
17
17
  type Thm,
18
18
  } from "./thm";
19
19
 
20
- export type Conversion = (term: Term) => Thm;
20
+ type Conversion = (term: Term) => Thm;
21
21
 
22
22
  const isReflexive = (eq: Thm) => {
23
23
  const [lhs, rhs] = destEquals(eq.prop);
@@ -135,7 +135,7 @@ export const isNormHhf = (isProtecting: boolean, term: Term): boolean => {
135
135
  };
136
136
 
137
137
  // Drule.outer_params: the outermost parameters, named apart.
138
- export const outerParams = (term: Term) => {
138
+ const outerParams = (term: Term) => {
139
139
  const vars = stripAllVars(term);
140
140
  const names = variantList(
141
141
  [],
@@ -228,7 +228,7 @@ export const zeroVarIndexes = (thm: Thm): Thm => {
228
228
  export const makeElim = (rule: Thm) => zeroVarIndexes(rs(rule, revcutRl));
229
229
 
230
230
  // Drule.compose: resolves tha into premise index of thb without lifting, with a unique result.
231
- export const compose = (tha: Thm, index: number, thb: Thm): Thm => {
231
+ const compose = (tha: Thm, index: number, thb: Thm): Thm => {
232
232
  const results = listOfSeq(
233
233
  bicompose(
234
234
  undefined,