tla-ts 0.0.10-dev.28c823e4b → 0.0.10-dev.63a6693bd

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 (172) hide show
  1. package/dist/compile.cjs +6 -6
  2. package/dist/compile.js +10 -10
  3. package/dist/deciders.cjs +29 -29
  4. package/dist/deciders.js +40 -40
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/parallel-worker.cjs +1 -1
  8. package/dist/parallel-worker.js +1 -1
  9. package/dist/prove-worker.cjs +1 -1
  10. package/dist/prove-worker.js +1 -1
  11. package/dist/prove.cjs +54 -54
  12. package/dist/prove.js +52 -52
  13. package/dist/run.cjs +42 -42
  14. package/dist/run.js +44 -44
  15. package/dist/tlapm.cjs +2 -2
  16. package/dist/tlapm.js +2 -2
  17. package/dist/transfer.cjs +39 -39
  18. package/dist/transfer.js +41 -41
  19. package/dist/worker.cjs +4 -4
  20. package/dist/worker.js +4 -4
  21. package/package.json +1 -1
  22. package/src/ast.ts +44 -39
  23. package/src/builtins.ts +4 -13
  24. package/src/check-failure.ts +116 -0
  25. package/src/check-trace.ts +282 -0
  26. package/src/check.ts +152 -518
  27. package/src/cli/options.ts +6 -31
  28. package/src/cli/shared.ts +1 -1
  29. package/src/cli/tlapm.ts +14 -13
  30. package/src/cli/tlc-arguments.ts +222 -210
  31. package/src/cli/tlc-output.ts +687 -0
  32. package/src/cli/tlc-usage.ts +1 -1
  33. package/src/cli/tlc.ts +34 -701
  34. package/src/cli/xml-exporter.ts +23 -33
  35. package/src/codegen.ts +5 -10
  36. package/src/coverage.ts +3 -10
  37. package/src/dependencies.ts +8 -13
  38. package/src/dfid.ts +16 -16
  39. package/src/environment-config.ts +315 -0
  40. package/src/environment.ts +45 -333
  41. package/src/errors.ts +3 -2
  42. package/src/evaluate.ts +5 -4
  43. package/src/fingerprints.ts +65 -1
  44. package/src/instances.ts +47 -10
  45. package/src/java-hash.ts +7 -0
  46. package/src/json.ts +4 -7
  47. package/src/levels.ts +39 -42
  48. package/src/liveness-checker.ts +24 -37
  49. package/src/liveness.ts +47 -54
  50. package/src/obligations/action.ts +4 -11
  51. package/src/obligations/anonymize.ts +4 -2
  52. package/src/obligations/expression.ts +18 -2
  53. package/src/obligations/generate.ts +45 -38
  54. package/src/obligations/index.ts +2 -2
  55. package/src/obligations/module.ts +27 -38
  56. package/src/obligations/normalize.ts +2 -1
  57. package/src/obligations/simplify.ts +39 -44
  58. package/src/obligations/source.ts +47 -57
  59. package/src/obligations/temporal.ts +5 -5
  60. package/src/parallel-worker.ts +10 -30
  61. package/src/parallel.ts +22 -45
  62. package/src/parser.ts +19 -34
  63. package/src/prover/decide-pool.ts +3 -3
  64. package/src/prover/deciders.ts +3 -3
  65. package/src/prover/isabelle/encode.ts +1 -1
  66. package/src/prover/isabelle/isar/inner-syntax.ts +9 -4
  67. package/src/prover/isabelle/isar/method.ts +14 -25
  68. package/src/prover/isabelle/isar/theory.ts +11 -10
  69. package/src/prover/isabelle/isar/type-check.ts +6 -6
  70. package/src/prover/isabelle/provers/blast/blast.ts +7 -63
  71. package/src/prover/isabelle/provers/hypsubst.ts +17 -26
  72. package/src/prover/isabelle/pure/bicompose.ts +9 -25
  73. package/src/prover/isabelle/pure/conv.ts +2 -8
  74. package/src/prover/isabelle/pure/drule.ts +9 -2
  75. package/src/prover/isabelle/pure/logic.ts +1 -1
  76. package/src/prover/isabelle/pure/raw-simplifier.ts +4 -13
  77. package/src/prover/isabelle/pure/rewriter.ts +5 -9
  78. package/src/prover/isabelle/pure/table.ts +2 -1
  79. package/src/prover/isabelle/pure/tactical.ts +42 -35
  80. package/src/prover/isabelle/pure/thm.ts +14 -11
  81. package/src/prover/isabelle/tla/classical-setup.ts +17 -14
  82. package/src/prover/isabelle/tla/context.ts +7 -2
  83. package/src/prover/isabelle/tla/logic.ts +10 -21
  84. package/src/prover/isabelle/tla/simpdata.ts +1 -10
  85. package/src/prover/prep/action.ts +11 -19
  86. package/src/prover/prep/fingerprint.ts +2 -5
  87. package/src/prover/prep/methods.ts +24 -3
  88. package/src/prover/prove.ts +87 -64
  89. package/src/prover/smt/context.ts +1 -2
  90. package/src/prover/smt/data.ts +418 -406
  91. package/src/prover/smt/encode.ts +30 -18
  92. package/src/prover/smt/rewrite.ts +657 -626
  93. package/src/prover/smt/solver/ast.ts +0 -22
  94. package/src/prover/smt/solver/auf-solver.ts +2 -5
  95. package/src/prover/smt/solver/context.ts +3 -3
  96. package/src/prover/smt/solver/e-matching.ts +1 -1
  97. package/src/prover/smt/solver/expr-safe-replace.ts +1 -1
  98. package/src/prover/smt/solver/internalizer.ts +1 -2
  99. package/src/prover/smt/solver/lp/dioph-eq.ts +1 -8
  100. package/src/prover/smt/solver/lp/hnf-cutter.ts +1 -1
  101. package/src/prover/smt/solver/lp/nla-core.ts +2 -6
  102. package/src/prover/smt/solver/mam-compiler.ts +4 -2
  103. package/src/prover/smt/solver/model-checker.ts +1 -1
  104. package/src/prover/smt/solver/model-finder.ts +12 -17
  105. package/src/prover/smt/solver/model-macro-solver.ts +11 -19
  106. package/src/prover/smt/solver/nlsat/algebraic.ts +9 -9
  107. package/src/prover/smt/solver/nlsat/atoms.ts +20 -4
  108. package/src/prover/smt/solver/nlsat/explain.ts +7 -22
  109. package/src/prover/smt/solver/nlsat/levelwise.ts +1 -6
  110. package/src/prover/smt/solver/nlsat/polynomial.ts +12 -3
  111. package/src/prover/smt/solver/nlsat/solver.ts +12 -24
  112. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -1
  113. package/src/prover/smt/solver/proto-model.ts +0 -4
  114. package/src/prover/smt/solver/quantifier-analyzer.ts +10 -10
  115. package/src/prover/smt/solver/quantifier-manager.ts +1 -5
  116. package/src/prover/smt/solver/smtlib-parser.ts +78 -94
  117. package/src/prover/smt/solver/theory-lra-bounds.ts +1 -2
  118. package/src/prover/smt/solver/theory-lra-internalize.ts +5 -16
  119. package/src/prover/tlapm/cache.ts +28 -18
  120. package/src/prover/tlapm/tlapm.ts +15 -9
  121. package/src/prover/verdict.ts +7 -0
  122. package/src/prover/zenon/check/check.ts +1 -2
  123. package/src/prover/zenon/check/records.ts +1 -1
  124. package/src/prover/zenon/check/relations.ts +2 -1
  125. package/src/prover/zenon/check/rewrites.ts +2 -15
  126. package/src/prover/zenon/check/sets.ts +40 -58
  127. package/src/prover/zenon/check/terms.ts +1 -2
  128. package/src/prover/zenon/eqrel.ts +2 -0
  129. package/src/prover/zenon/expr.ts +7 -0
  130. package/src/prover/zenon/index-table.ts +9 -19
  131. package/src/prover/zenon/isar.ts +35 -35
  132. package/src/prover/zenon/llproof.ts +2 -11
  133. package/src/prover/zenon/mltoll.ts +12 -28
  134. package/src/prover/zenon/parse.ts +3 -6
  135. package/src/prover/zenon/search.ts +4 -14
  136. package/src/prover/zenon/tla/functions.ts +2 -2
  137. package/src/prover/zenon/tla/llproof.ts +9 -11
  138. package/src/prover/zenon/tla/records.ts +1 -6
  139. package/src/prover/zenon/tla/sets.ts +15 -14
  140. package/src/prover/zenon/tla/tla.ts +7 -6
  141. package/src/resolve.ts +55 -72
  142. package/src/sany/generation.ts +394 -0
  143. package/src/sany/generator-def-entries.ts +210 -0
  144. package/src/sany/generator-definitions.ts +686 -0
  145. package/src/sany/generator-expressions.ts +1100 -0
  146. package/src/sany/generator-proofs.ts +662 -0
  147. package/src/sany/generator.ts +155 -2625
  148. package/src/sany/lexer.ts +17 -16
  149. package/src/sany/nodes.ts +6 -13
  150. package/src/sany/report.ts +3 -6
  151. package/src/sany/selectors.ts +35 -38
  152. package/src/sany/xml.ts +23 -55
  153. package/src/search.ts +65 -27
  154. package/src/simulate.ts +157 -133
  155. package/src/spec-description.ts +33 -48
  156. package/src/standard-modules.ts +16 -32
  157. package/src/state-graph.ts +2 -7
  158. package/src/substitution-levels.ts +5 -4
  159. package/src/successors.ts +5 -7
  160. package/src/tlc/messages.ts +20 -15
  161. package/src/tlc/order.ts +2 -9
  162. package/src/tlc/random.ts +4 -4
  163. package/src/tlc/replay.ts +8 -15
  164. package/src/tlc/tlc-operators.ts +2 -3
  165. package/src/tlc/trace-spec.ts +25 -45
  166. package/src/typescript/actions.ts +2 -4
  167. package/src/typescript/collections.ts +34 -20
  168. package/src/typescript/compile.ts +1 -3
  169. package/src/typescript/formula.ts +5 -3
  170. package/src/typescript/model.ts +4 -5
  171. package/src/typescript/steps.ts +20 -18
  172. package/src/values.ts +63 -158
@@ -40,6 +40,40 @@ const getSetEqualSpec = (formula: Term, isNegated: boolean, checker: Checker): R
40
40
  return { premises: [formula], branches: [[isNegated ? not(extensional) : extensional]] };
41
41
  };
42
42
 
43
+ const getUnionSpec = (formula: Term, isNegated: boolean, checker: Checker): RuleSpec => {
44
+ const spec = getMembershipSpec(formula, isNegated, "TLA.UNION", 1);
45
+ const exists = checker.bind("ex", "", (bound) =>
46
+ and(member(bound, spec.operands[0]), member(spec.element, bound)),
47
+ );
48
+ return { premises: [formula], branches: [[isNegated ? not(exists) : exists]] };
49
+ };
50
+
51
+ const getSetOfAllSpec = (formula: Term, isNegated: boolean, checker: Checker): RuleSpec => {
52
+ const spec = getMembershipSpec(formula, isNegated, "TLA.setOfAll", 2);
53
+ const mapping = spec.operands[1];
54
+ ensure(mapping.kind === "lam");
55
+ const exists = checker.bind("ex", "", (bound) =>
56
+ and(member(bound, spec.operands[0]), equal(spec.element, instantiate(mapping, bound))),
57
+ );
58
+ return { premises: [formula], branches: [[isNegated ? not(exists) : exists]] };
59
+ };
60
+
61
+ const getFuncSetSpec = (formula: Term, isNegated: boolean, checker: Checker): RuleSpec => {
62
+ const spec = getMembershipSpec(formula, isNegated, "TLA.FuncSet", 2);
63
+ const fcn = spec.element;
64
+ const conjuncts = [
65
+ app("TLA.isAFcn", [fcn]),
66
+ equal(domain(fcn), spec.operands[0]),
67
+ checker.bind("all", "", (bound) =>
68
+ imply(member(bound, spec.operands[0]), member(fapply(fcn, bound), spec.operands[1])),
69
+ ),
70
+ ];
71
+ return {
72
+ premises: [formula],
73
+ branches: isNegated ? conjuncts.map((inner) => [not(inner)]) : [conjuncts],
74
+ };
75
+ };
76
+
43
77
  export const SET_RULES = {
44
78
  in_emptyset: (args) => {
45
79
  ensure(isVariable(expectApp(args[0], "TLA.in", 2)[1], "TLA.emptyset"));
@@ -112,20 +146,8 @@ export const SET_RULES = {
112
146
  branches: [[not(app("TLA.subseteq", [spec.element, spec.operands[0]]))]],
113
147
  };
114
148
  },
115
- in_UNION: (args, checker) => {
116
- const spec = getMembershipSpec(args[0], false, "TLA.UNION", 1);
117
- const exists = checker.bind("ex", "", (bound) =>
118
- and(member(bound, spec.operands[0]), member(spec.element, bound)),
119
- );
120
- return { premises: [args[0]], branches: [[exists]] };
121
- },
122
- notin_UNION: (args, checker) => {
123
- const spec = getMembershipSpec(args[0], true, "TLA.UNION", 1);
124
- const exists = checker.bind("ex", "", (bound) =>
125
- and(member(bound, spec.operands[0]), member(spec.element, bound)),
126
- );
127
- return { premises: [args[0]], branches: [[not(exists)]] };
128
- },
149
+ in_UNION: (args, checker) => getUnionSpec(args[0], false, checker),
150
+ notin_UNION: (args, checker) => getUnionSpec(args[0], true, checker),
129
151
  in_cup: (args) => {
130
152
  const spec = getMembershipSpec(args[0], false, "TLA.cup", 2);
131
153
  return {
@@ -194,50 +216,10 @@ export const SET_RULES = {
194
216
  ],
195
217
  };
196
218
  },
197
- in_setofall: (args, checker) => {
198
- const spec = getMembershipSpec(args[0], false, "TLA.setOfAll", 2);
199
- const mapping = spec.operands[1];
200
- ensure(mapping.kind === "lam");
201
- const exists = checker.bind("ex", "", (bound) =>
202
- and(member(bound, spec.operands[0]), equal(spec.element, instantiate(mapping, bound))),
203
- );
204
- return { premises: [args[0]], branches: [[exists]] };
205
- },
206
- notin_setofall: (args, checker) => {
207
- const spec = getMembershipSpec(args[0], true, "TLA.setOfAll", 2);
208
- const mapping = spec.operands[1];
209
- ensure(mapping.kind === "lam");
210
- const exists = checker.bind("ex", "", (bound) =>
211
- and(member(bound, spec.operands[0]), equal(spec.element, instantiate(mapping, bound))),
212
- );
213
- return { premises: [args[0]], branches: [[not(exists)]] };
214
- },
215
- in_funcset: (args, checker) => {
216
- const spec = getMembershipSpec(args[0], false, "TLA.FuncSet", 2);
217
- const fcn = spec.element;
218
- const maps = checker.bind("all", "", (bound) =>
219
- imply(member(bound, spec.operands[0]), member(fapply(fcn, bound), spec.operands[1])),
220
- );
221
- return {
222
- premises: [args[0]],
223
- branches: [[app("TLA.isAFcn", [fcn]), equal(domain(fcn), spec.operands[0]), maps]],
224
- };
225
- },
226
- notin_funcset: (args, checker) => {
227
- const spec = getMembershipSpec(args[0], true, "TLA.FuncSet", 2);
228
- const fcn = spec.element;
229
- const maps = checker.bind("all", "", (bound) =>
230
- imply(member(bound, spec.operands[0]), member(fapply(fcn, bound), spec.operands[1])),
231
- );
232
- return {
233
- premises: [args[0]],
234
- branches: [
235
- [not(app("TLA.isAFcn", [fcn]))],
236
- [not(equal(domain(fcn), spec.operands[0]))],
237
- [not(maps)],
238
- ],
239
- };
240
- },
219
+ in_setofall: (args, checker) => getSetOfAllSpec(args[0], false, checker),
220
+ notin_setofall: (args, checker) => getSetOfAllSpec(args[0], true, checker),
221
+ in_funcset: (args, checker) => getFuncSetSpec(args[0], false, checker),
222
+ notin_funcset: (args, checker) => getFuncSetSpec(args[0], true, checker),
241
223
  except_notin_funcset: (args) => {
242
224
  const spec = getMembershipSpec(args[0], true, "TLA.FuncSet", 2);
243
225
  const except = expectApp(spec.element, "TLA.except", 3);
@@ -1,3 +1,4 @@
1
+ import type { RelationProperty } from "../eqrel";
1
2
  import type { ExprKind } from "../expr";
2
3
  import type { Definition } from "../parse";
3
4
  import type { PlainRuleName, RuleArgs } from "../proof";
@@ -20,8 +21,6 @@ export interface RuleSpec {
20
21
  branches: Term[][];
21
22
  }
22
23
 
23
- export type RelationProperty = "reflexive" | "symmetric" | "transitive";
24
-
25
24
  export type Binding = number | { formula: Term; env: Env; operators?: Operators };
26
25
 
27
26
  export type Env = Map<string, Binding>;
@@ -4,6 +4,8 @@ import { TRUE, type Expr, type Expressions } from "./expr";
4
4
 
5
5
  export type Direction = "left" | "right";
6
6
 
7
+ export type RelationProperty = "reflexive" | "symmetric" | "transitive";
8
+
7
9
  export interface Origin {
8
10
  formula: Expr;
9
11
  directions: Direction[];
@@ -217,6 +217,11 @@ export const isApp = <Symbol extends string>(
217
217
  expression.symbol === symbol &&
218
218
  (arity === undefined || expression.args.length === arity);
219
219
 
220
+ export const getStringName = (expression: Expr) =>
221
+ isApp(expression, "$string", 1) && expression.args[0].kind === "var"
222
+ ? expression.args[0].symbol
223
+ : undefined;
224
+
220
225
  export const isMeta = (expression: Expr): expression is MetaExpr => expression.kind === "meta";
221
226
 
222
227
  export const isRelation = (expression: Expr): expression is RelationExpr =>
@@ -504,6 +509,8 @@ export const createExpressions = () => {
504
509
  emeta,
505
510
  eapp,
506
511
  enot,
512
+ binary,
513
+ binder,
507
514
  eand: (left: Expr, right: Expr) => binary("and", left, right),
508
515
  eor: (left: Expr, right: Expr) => binary("or", left, right),
509
516
  eimply: (left: Expr, right: Expr) => binary("imply", left, right),
@@ -1,6 +1,8 @@
1
1
  // Ported from Zenon's index.ml, as shipped in tlapm. Copyright 2004 INRIA, see LICENSE.
2
2
 
3
3
  import {
4
+ getStringName,
5
+ isApp,
4
6
  isNegatedRelation,
5
7
  isRelation,
6
8
  type Expr,
@@ -128,35 +130,23 @@ export const createIndex = (exprs: Expressions) => {
128
130
  if (head !== undefined) action(positive, getHeadKey(head), formula);
129
131
  };
130
132
 
131
- const getStringLiteral = (expression: Expr) =>
132
- expression.kind === "app" &&
133
- expression.symbol === "$string" &&
134
- expression.args.length === 1 &&
135
- expression.args[0].kind === "var"
136
- ? expression.args[0].symbol
137
- : undefined;
138
-
139
133
  const getStringEquality = (formula: Expr) => {
140
- if (formula.kind !== "app" || formula.symbol !== "=" || formula.args.length !== 2)
141
- return undefined;
142
- const rightString = getStringLiteral(formula.args[1]);
134
+ if (!isApp(formula, "=", 2)) return undefined;
135
+ const rightString = getStringName(formula.args[1]);
143
136
  if (rightString !== undefined)
144
137
  return { isReversed: false, term: formula.args[0], value: rightString };
145
- const leftString = getStringLiteral(formula.args[0]);
138
+ const leftString = getStringName(formula.args[0]);
146
139
  return leftString === undefined
147
140
  ? undefined
148
141
  : { isReversed: true, term: formula.args[1], value: leftString };
149
142
  };
150
143
 
151
- const isEquality = (formula: Expr) =>
152
- formula.kind === "app" && formula.symbol === "=" && formula.args.length === 2;
153
-
154
144
  const add = (formula: Expr, goalness: number) => {
155
145
  pushValue(formulas, formula, goalness);
156
- if (isEquality(formula)) {
146
+ if (isApp(formula, "=", 2)) {
157
147
  pushValue(equalLeftRight, formula.args[0], formula.args[1]);
158
148
  pushValue(equalRightLeft, formula.args[1], formula.args[0]);
159
- } else if (formula.kind === "not" && isEquality(formula.args[0])) {
149
+ } else if (formula.kind === "not" && isApp(formula.args[0], "=", 2)) {
160
150
  pushValue(unequalLeftRight, formula.args[0].args[0], formula.args[0].args[1]);
161
151
  pushValue(unequalRightLeft, formula.args[0].args[1], formula.args[0].args[0]);
162
152
  }
@@ -209,10 +199,10 @@ export const createIndex = (exprs: Expressions) => {
209
199
  const stringEquality = getStringEquality(formula);
210
200
  if (stringEquality !== undefined)
211
201
  (stringEquality.isReversed ? reversedStringEqualities : stringEqualities).shift();
212
- if (isEquality(formula)) {
202
+ if (isApp(formula, "=", 2)) {
213
203
  popValue(equalLeftRight, formula.args[0]);
214
204
  popValue(equalRightLeft, formula.args[1]);
215
- } else if (formula.kind === "not" && isEquality(formula.args[0])) {
205
+ } else if (formula.kind === "not" && isApp(formula.args[0], "=", 2)) {
216
206
  popValue(unequalLeftRight, formula.args[0].args[0]);
217
207
  popValue(unequalRightLeft, formula.args[0].args[1]);
218
208
  }
@@ -10,40 +10,40 @@ import { isMetaName, translateProof, type MlProof } from "./mltoll";
10
10
  import type { Phrase } from "./parse";
11
11
  import { postprocessTla } from "./tla/llproof";
12
12
 
13
- const INFIXES: Record<string, string> = {
14
- "=": "=",
15
- "TLA.cup": " \\\\cup ",
16
- "TLA.cap": " \\\\cap ",
17
- "TLA.setminus": " \\\\ ",
18
- "TLA.in": " \\\\in ",
19
- "TLA.subseteq": " \\\\subseteq ",
20
- "arith.natrange": "..",
21
- "arith.add": " + ",
22
- "arith.sub": " - ",
23
- "arith.mul": " * ",
24
- "arith.le": " <= ",
25
- "arith.lt": " < ",
26
- "TLA.concat": " \\\\circ ",
27
- "TLA.oneArg": " :> ",
28
- "TLA.extend": " @@ ",
29
- };
13
+ const INFIXES = new Map([
14
+ ["=", "="],
15
+ ["TLA.cup", " \\\\cup "],
16
+ ["TLA.cap", " \\\\cap "],
17
+ ["TLA.setminus", " \\\\ "],
18
+ ["TLA.in", " \\\\in "],
19
+ ["TLA.subseteq", " \\\\subseteq "],
20
+ ["arith.natrange", ".."],
21
+ ["arith.add", " + "],
22
+ ["arith.sub", " - "],
23
+ ["arith.mul", " * "],
24
+ ["arith.le", " <= "],
25
+ ["arith.lt", " < "],
26
+ ["TLA.concat", " \\\\circ "],
27
+ ["TLA.oneArg", " :> "],
28
+ ["TLA.extend", " @@ "],
29
+ ]);
30
30
 
31
- const CONSTANTS: Record<string, string> = {
32
- "TLA.emptyset": "{}",
33
- "arith.N": "Nat",
34
- "arith.Z": "Int",
35
- "arith.R": "isReal",
36
- "arith.Infinity": "isInfinity",
37
- };
31
+ const CONSTANTS = new Map([
32
+ ["TLA.emptyset", "{}"],
33
+ ["arith.N", "Nat"],
34
+ ["arith.Z", "Int"],
35
+ ["arith.R", "isReal"],
36
+ ["arith.Infinity", "isInfinity"],
37
+ ]);
38
38
 
39
- const PREFIXES: Record<string, string> = {
40
- "arith.div": "isa'slash",
41
- "arith.euclidiv": "isa'div",
42
- "arith.mod": "isa'pc",
43
- "arith.minus": " -.",
44
- "arith.intrange": "isa'dotdot",
45
- "TLA.box": "isa'box",
46
- };
39
+ const PREFIXES = new Map([
40
+ ["arith.div", "isa'slash"],
41
+ ["arith.euclidiv", "isa'div"],
42
+ ["arith.mod", "isa'pc"],
43
+ ["arith.minus", " -."],
44
+ ["arith.intrange", "isa'dotdot"],
45
+ ["TLA.box", "isa'box"],
46
+ ]);
47
47
 
48
48
  const stripNamespace = (symbol: string) =>
49
49
  symbol.length > 4 && symbol.startsWith("TLA.")
@@ -159,7 +159,7 @@ export const printIsar = (proof: MlProof, context: IsarContext): string | undefi
159
159
  case "var":
160
160
  return isMetaName(expression.symbol)
161
161
  ? "(CHOOSE x : TRUE)"
162
- : (CONSTANTS[expression.symbol] ?? stripNamespace(expression.symbol));
162
+ : (CONSTANTS.get(expression.symbol) ?? stripNamespace(expression.symbol));
163
163
  case "app": {
164
164
  const args = expression.args;
165
165
  switch (expression.symbol) {
@@ -192,11 +192,11 @@ export const printIsar = (proof: MlProof, context: IsarContext): string | undefi
192
192
  if (numeral !== undefined) return String(numeral + 1);
193
193
  return `(${print(args[0])}[${print(args[1])}])`;
194
194
  }
195
- const infix = INFIXES[expression.symbol];
195
+ const infix = INFIXES.get(expression.symbol);
196
196
  if (infix !== undefined && args.length === 2)
197
197
  return `(${print(args[0])}${infix}${print(args[1])})`;
198
198
  if (args.length === 0) return expression.symbol;
199
- return `${PREFIXES[expression.symbol] ?? stripNamespace(expression.symbol)}(${printList(args)})`;
199
+ return `${PREFIXES.get(expression.symbol) ?? stripNamespace(expression.symbol)}(${printList(args)})`;
200
200
  }
201
201
  case "not": {
202
202
  const operand = expression.args[0];
@@ -39,15 +39,6 @@ export interface Lemma {
39
39
  proof: LlProof;
40
40
  }
41
41
 
42
- export const connect = (exprs: Expressions, connective: Connective, left: Expr, right: Expr) =>
43
- connective === "and"
44
- ? exprs.eand(left, right)
45
- : connective === "or"
46
- ? exprs.eor(left, right)
47
- : connective === "imply"
48
- ? exprs.eimply(left, right)
49
- : exprs.eequiv(left, right);
50
-
51
42
  const getLemma = (lemmas: Map<string, Lemma>, name: string) => {
52
43
  const lemma = lemmas.get(name);
53
44
  if (lemma === undefined) throw new TlaZenonError(`Zenon: no lemma ${name}`);
@@ -102,9 +93,9 @@ const getEliminated = (exprs: Expressions, lemmas: Map<string, Lemma>, rule: LlR
102
93
  case "notnot":
103
94
  return [exprs.enot(exprs.enot(rule.formula))];
104
95
  case "connect":
105
- return [connect(exprs, rule.connective, rule.left, rule.right)];
96
+ return [exprs.binary(rule.connective, rule.left, rule.right)];
106
97
  case "notconnect":
107
- return [exprs.enot(connect(exprs, rule.connective, rule.left, rule.right))];
98
+ return [exprs.enot(exprs.binary(rule.connective, rule.left, rule.right))];
108
99
  case "ex":
109
100
  case "all":
110
101
  return [rule.quantified];
@@ -1,7 +1,7 @@
1
1
  // Ported from Zenon's mltoll.ml, as shipped in tlapm. Copyright 2004 INRIA, see LICENSE.
2
2
 
3
3
  import { TlaZenonError } from "../../errors";
4
- import type { Direction, Origin, Relations } from "./eqrel";
4
+ import type { Direction, Origin, RelationProperty, Relations } from "./eqrel";
5
5
  import {
6
6
  difference,
7
7
  union,
@@ -10,7 +10,7 @@ import {
10
10
  type Expressions,
11
11
  type VarExpr,
12
12
  } from "./expr";
13
- import { connect, type Connective, type Lemma, type LlProof, type LlRule } from "./llproof";
13
+ import type { Connective, Lemma, LlProof, LlRule } from "./llproof";
14
14
  import type { Definition, Phrase } from "./parse";
15
15
  import type { Rule } from "./proof";
16
16
  import { getTlaLlProof } from "./tla/llproof";
@@ -32,8 +32,6 @@ interface TranslateContext {
32
32
  relations: Relations;
33
33
  }
34
34
 
35
- type RelationProperty = "reflexive" | "symmetric" | "transitive";
36
-
37
35
  type HypothesisKind =
38
36
  | { kind: "reflexive"; origin: Origin }
39
37
  | { kind: "symmetric"; origin: Origin }
@@ -145,10 +143,8 @@ export const translateProof = (
145
143
  ): Lemma[] => {
146
144
  const exprs = context.exprs;
147
145
  const translatedExprs = new Map<Expr, Expr>();
148
- const lemmaNumbers = new Map<MlProof, number>();
149
- const lemmaTable = new Map<string, [Lemma, Expr[]]>();
146
+ const lemmaTable = new Map<MlProof, [Lemma, Expr[]]>();
150
147
  const lemmas: Lemma[] = [];
151
- const getLemmaName = (number: number) => `${LEMMA_PREFIX}${number}_`;
152
148
 
153
149
  const equal = (left: Expr, right: Expr) => exprs.eapp("=", [left, right]);
154
150
 
@@ -175,13 +171,13 @@ export const translateProof = (
175
171
  case "imply":
176
172
  case "equiv": {
177
173
  const right = translateExpr(expression.args[1]);
178
- return connect(exprs, expression.kind, translateExpr(expression.args[0]), right);
174
+ return exprs.binary(expression.kind, translateExpr(expression.args[0]), right);
179
175
  }
180
176
  case "all":
181
177
  case "ex":
182
178
  case "tau":
183
179
  case "lam":
184
- return makeBinder(
180
+ return exprs.binder(
185
181
  expression.kind,
186
182
  expression.args[0],
187
183
  expression.symbol,
@@ -195,15 +191,6 @@ export const translateProof = (
195
191
  return result;
196
192
  };
197
193
 
198
- const makeBinder = (kind: BinderExpr["kind"], variable: VarExpr, type: string, body: Expr) =>
199
- kind === "all"
200
- ? exprs.eall(variable, type, body)
201
- : kind === "ex"
202
- ? exprs.eex(variable, type, body)
203
- : kind === "tau"
204
- ? exprs.etau(variable, type, body)
205
- : exprs.elam(variable, type, body);
206
-
207
194
  const translateRule = (rule: MlRule): LlRule => {
208
195
  switch (rule.name) {
209
196
  case "close":
@@ -374,8 +361,7 @@ export const translateProof = (
374
361
  };
375
362
 
376
363
  const getLemmaReference = (proof: MlProof): Translated => {
377
- const number = lemmaNumbers.get(proof);
378
- const entry = number === undefined ? undefined : lemmaTable.get(getLemmaName(number));
364
+ const entry = lemmaTable.get(proof);
379
365
  if (entry === undefined) throw new TlaZenonError("Zenon: a lemma that was never made");
380
366
  const lemma = entry[0];
381
367
  return [
@@ -389,19 +375,17 @@ export const translateProof = (
389
375
  };
390
376
 
391
377
  const makeLemma = (translated: LlProof, extras: Expr[], proof: MlProof) => {
392
- const number = lemmas.length + 1;
393
- lemmaNumbers.set(proof, number);
394
378
  const lemma = {
395
- name: getLemmaName(number),
379
+ name: `${LEMMA_PREFIX}${lemmas.length + 1}_`,
396
380
  params: translated.conclusions.reduce(getParams, []),
397
381
  proof: translated,
398
382
  };
399
- lemmaTable.set(lemma.name, [lemma, extras]);
383
+ lemmaTable.set(proof, [lemma, extras]);
400
384
  lemmas.push(lemma);
401
385
  };
402
386
 
403
387
  const translate = (proof: MlProof): Translated => {
404
- if (lemmaNumbers.has(proof)) return getLemmaReference(proof);
388
+ if (lemmaTable.has(proof)) return getLemmaReference(proof);
405
389
  const result = isDerived(proof.rule)
406
390
  ? translateDerived(proof)
407
391
  : ((): Translated => {
@@ -422,7 +406,7 @@ export const translateProof = (
422
406
  };
423
407
 
424
408
  const isSharedProof = (proof: MlProof) =>
425
- context.sharedProofs.has(proof) && !lemmaNumbers.has(proof);
409
+ context.sharedProofs.has(proof) && !lemmaTable.has(proof);
426
410
 
427
411
  const translateAll = (proofs: MlProof[]): [LlProof[], Expr[]] => {
428
412
  const translated = proofs.map(translate);
@@ -1420,10 +1404,10 @@ export const translateProof = (
1420
1404
  ) {
1421
1405
  if (left.args[0] === right.args[0]) {
1422
1406
  const diff = findDiff(variable, left.args[1], right.args[1]);
1423
- return [connect(exprs, left.kind, left.args[0], diff[0]), diff[1], diff[2]];
1407
+ return [exprs.binary(left.kind, left.args[0], diff[0]), diff[1], diff[2]];
1424
1408
  }
1425
1409
  const diff = findDiff(variable, left.args[0], right.args[0]);
1426
- return [connect(exprs, left.kind, diff[0], left.args[1]), diff[1], diff[2]];
1410
+ return [exprs.binary(left.kind, diff[0], left.args[1]), diff[1], diff[2]];
1427
1411
  }
1428
1412
  if (
1429
1413
  left.kind === right.kind &&
@@ -123,16 +123,13 @@ export const parseZenon = (exprs: Expressions, text: string): Phrase[] => {
123
123
  };
124
124
  const tokens = tokenize(text);
125
125
  let position = 0;
126
- const peek = () => tokens[position];
127
126
  const next = () => tokens[position++];
128
- const expect = (kind: TokenKind, value?: string) => {
127
+ const expect = (kind: TokenKind) => {
129
128
  const token = next();
130
- if (token.kind !== kind || (value !== undefined && token.text !== value))
131
- throw new TlaZenonError(`Zenon: line ${token.line}: syntax error`);
129
+ if (token.kind !== kind) throw new TlaZenonError(`Zenon: line ${token.line}: syntax error`);
132
130
  return token;
133
131
  };
134
- const isAt = (kind: TokenKind, value?: string) =>
135
- peek().kind === kind && (value === undefined || peek().text === value);
132
+ const isAt = (kind: TokenKind) => tokens[position].kind === kind;
136
133
 
137
134
  const parseLambda = () => {
138
135
  expect("open");
@@ -1,7 +1,7 @@
1
1
  // Ported from Zenon's prove.ml, as shipped in tlapm. Copyright 2002 INRIA, see LICENSE.
2
2
 
3
3
  import { TlaZenonError } from "../../errors";
4
- import { difference, isApp, isDisjoint, isMeta, union, type Expr } from "./expr";
4
+ import { difference, isApp, isDisjoint, isMeta, isRelation, union, type Expr } from "./expr";
5
5
  import { getLimitFailure, type Limits } from "./limits";
6
6
  import { EMPTY_QUEUE, getQueueHead, removeNode, type Node, type Queue } from "./node";
7
7
  import { stableSort } from "./ocaml";
@@ -13,8 +13,7 @@ import { addNodes, type SearchContext } from "./rules";
13
13
  const isTrivial = (context: SearchContext, formula: Expr) =>
14
14
  formula.kind === "true" ||
15
15
  (formula.kind === "not" && formula.args[0].kind === "false") ||
16
- (formula.kind === "app" &&
17
- formula.args.length === 2 &&
16
+ (isRelation(formula) &&
18
17
  formula.args[0] === formula.args[1] &&
19
18
  context.relations.isReflexive(formula.symbol));
20
19
 
@@ -26,8 +25,7 @@ const reduceBranch = (context: SearchContext, branch: Expr[]) => {
26
25
  const isKnown = (formula: Expr) => index.isMember(formula) || kept.includes(formula);
27
26
  for (const formula of branch) {
28
27
  if (
29
- formula.kind === "true" ||
30
- (formula.kind === "not" && formula.args[0].kind === "false") ||
28
+ isTrivial(context, formula) ||
31
29
  (formula.kind === "not" &&
32
30
  isApp(formula.args[0], "TLA.in", 2) &&
33
31
  formula.args[0].args[1].kind === "var" &&
@@ -35,15 +33,7 @@ const reduceBranch = (context: SearchContext, branch: Expr[]) => {
35
33
  )
36
34
  continue;
37
35
  const atom = formula.kind === "not" ? formula.args[0] : formula;
38
- const isRelation = atom.kind === "app" && atom.args.length === 2;
39
- if (
40
- formula.kind === "app" &&
41
- isRelation &&
42
- formula.args[0] === formula.args[1] &&
43
- relations.isReflexive(formula.symbol)
44
- )
45
- continue;
46
- if (isRelation && relations.isSymmetric(atom.symbol)) {
36
+ if (isRelation(atom) && relations.isSymmetric(atom.symbol)) {
47
37
  const swapped = exprs.eapp(atom.symbol, [atom.args[1], atom.args[0]]);
48
38
  const reversed = formula.kind === "not" ? exprs.enot(swapped) : swapped;
49
39
  if (!isKnown(formula) && !isKnown(reversed)) kept.unshift(formula);
@@ -68,7 +68,7 @@ export const getFunctionSetNodes = (literal: Literal): Item[] | undefined => {
68
68
  "arity",
69
69
  makeRule("except_notin_funcset", [
70
70
  formula,
71
- exprs.enot(member(exprs, fcn.args[0], exprs.eapp("TLA.FuncSet", [source, target]))),
71
+ exprs.enot(member(exprs, fcn.args[0], set)),
72
72
  exprs.enot(member(exprs, fcn.args[2], target)),
73
73
  fcn.args[0],
74
74
  fcn.args[1],
@@ -77,7 +77,7 @@ export const getFunctionSetNodes = (literal: Literal): Item[] | undefined => {
77
77
  target,
78
78
  ]),
79
79
  [
80
- [exprs.enot(member(exprs, fcn.args[0], exprs.eapp("TLA.FuncSet", [source, target])))],
80
+ [exprs.enot(member(exprs, fcn.args[0], set))],
81
81
  [exprs.enot(member(exprs, fcn.args[2], target))],
82
82
  ],
83
83
  )
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { TlaZenonError } from "../../../errors";
4
4
  import { difference, union, type Expr, type Expressions } from "../expr";
5
- import { connect, type Lemma, type LlProof, type LlRule } from "../llproof";
5
+ import type { Lemma, LlProof, LlRule } from "../llproof";
6
6
  import type { MlProof, Translated } from "../mltoll";
7
7
 
8
8
  type LlArgs = [string, Expr[], Expr[], Expr[][]];
@@ -121,11 +121,7 @@ const SHAPES: Record<string, Shape> = {
121
121
  if (third === undefined) throw getShapeError(name);
122
122
  return [`zenon_${name}`, rest, [conclusion], [[first, second, third]]];
123
123
  },
124
- except_notin_funcset: (name, args) => {
125
- const [conclusion, first, second, ...rest] = args;
126
- if (second === undefined) throw getShapeError(name);
127
- return [`zenon_${name}`, rest, [conclusion], [[first], [second]]];
128
- },
124
+ except_notin_funcset: beta,
129
125
  notin_funcset: (name, args) => {
130
126
  const [conclusion, first, second, third, ...rest] = args;
131
127
  if (third === undefined) throw getShapeError(name);
@@ -381,16 +377,18 @@ export const postprocessTla = (exprs: Expressions, lemmas: Lemma[]): Lemma[] =>
381
377
  case "imply":
382
378
  case "equiv": {
383
379
  const right = postprocess(expression.args[1]);
384
- return connect(exprs, expression.kind, postprocess(expression.args[0]), right);
380
+ return exprs.binary(expression.kind, postprocess(expression.args[0]), right);
385
381
  }
386
382
  case "all":
387
- return exprs.eall(expression.args[0], expression.symbol, postprocess(expression.args[1]));
388
383
  case "ex":
389
- return exprs.eex(expression.args[0], expression.symbol, postprocess(expression.args[1]));
390
384
  case "tau":
391
- return exprs.etau(expression.args[0], expression.symbol, postprocess(expression.args[1]));
392
385
  case "lam":
393
- return exprs.elam(expression.args[0], expression.symbol, postprocess(expression.args[1]));
386
+ return exprs.binder(
387
+ expression.kind,
388
+ expression.args[0],
389
+ expression.symbol,
390
+ postprocess(expression.args[1]),
391
+ );
394
392
  }
395
393
  })();
396
394
  cache.set(expression, result);
@@ -1,6 +1,6 @@
1
1
  // Ported from Zenon's ext_tla.ml, as shipped in tlapm. Copyright 2008 INRIA, see LICENSE.
2
2
 
3
- import { compareExprs, isApp, type Expr } from "../expr";
3
+ import { compareExprs, getStringName, isApp, type Expr } from "../expr";
4
4
  import { stableSort } from "../ocaml";
5
5
  import { makeRule } from "../proof";
6
6
  import {
@@ -17,11 +17,6 @@ import {
17
17
  type Literal,
18
18
  } from "./terms";
19
19
 
20
- const getStringName = (expression: Expr) =>
21
- isApp(expression, "$string", 1) && expression.args[0].kind === "var"
22
- ? expression.args[0].symbol
23
- : undefined;
24
-
25
20
  const hasDistinctLabels = (pairs: [Expr, Expr][]) => {
26
21
  for (let index = 0; index + 1 < pairs.length; index++) {
27
22
  const left = pairs[index][0];