tla-ts 0.0.10-dev.c92e6a4ea → 0.0.10-dev.d166e0ae9

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 (235) hide show
  1. package/dist/compile.cjs +3 -3
  2. package/dist/compile.js +1 -1
  3. package/dist/deciders.cjs +36 -36
  4. package/dist/deciders.js +54 -54
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.d.cts +13 -3
  7. package/dist/index.d.ts +13 -3
  8. package/dist/index.js +1 -1
  9. package/dist/parallel-worker.cjs +1 -1
  10. package/dist/parallel-worker.js +1 -1
  11. package/dist/prove-worker.cjs +1 -1
  12. package/dist/prove-worker.js +1 -1
  13. package/dist/prove.cjs +68 -68
  14. package/dist/prove.js +78 -78
  15. package/dist/run.cjs +42 -42
  16. package/dist/run.js +44 -44
  17. package/dist/tlapm.cjs +1 -1
  18. package/dist/tlapm.js +2 -2
  19. package/dist/transfer.cjs +45 -43
  20. package/dist/transfer.js +45 -43
  21. package/dist/worker.cjs +7 -7
  22. package/dist/worker.js +7 -7
  23. package/package.json +1 -1
  24. package/src/ast.ts +11 -1
  25. package/src/bags.ts +50 -29
  26. package/src/builtins.ts +4 -3
  27. package/src/check-failure.ts +9 -6
  28. package/src/check-trace.ts +116 -64
  29. package/src/check.ts +356 -173
  30. package/src/cli/tlc-output.ts +1 -0
  31. package/src/cli/tlc.ts +4 -3
  32. package/src/cli/xml-exporter.ts +1 -1
  33. package/src/codegen.ts +34 -13
  34. package/src/coverage.ts +3 -0
  35. package/src/dependencies.ts +61 -13
  36. package/src/dfid.ts +22 -10
  37. package/src/environment.ts +71 -35
  38. package/src/errors.ts +7 -0
  39. package/src/evaluate.ts +149 -54
  40. package/src/exit-codes.ts +29 -15
  41. package/src/instances.ts +16 -6
  42. package/src/java-hash.ts +14 -0
  43. package/src/java-overrides.ts +2 -2
  44. package/src/levels.ts +186 -97
  45. package/src/liveness-checker.ts +131 -83
  46. package/src/liveness.ts +52 -11
  47. package/src/obligations/index.ts +1 -1
  48. package/src/obligations/normalize.ts +1 -4
  49. package/src/obligations/printer.ts +5 -5
  50. package/src/obligations/source.ts +2 -0
  51. package/src/parser.ts +115 -145
  52. package/src/prover/isabelle/isar/attrib.ts +4 -4
  53. package/src/prover/isabelle/isar/rule-cases.ts +8 -6
  54. package/src/prover/isabelle/provers/clasimp.ts +1 -1
  55. package/src/prover/isabelle/provers/hypsubst.ts +2 -2
  56. package/src/prover/isabelle/pure/rewriter.ts +3 -3
  57. package/src/prover/isabelle/pure/term.ts +3 -3
  58. package/src/prover/prep/md5.ts +26 -29
  59. package/src/prover/smt/rewrite.ts +2 -7
  60. package/src/prover/smt/simplify.ts +1 -1
  61. package/src/prover/smt/solver/arith-rewriter.ts +11 -3
  62. package/src/prover/smt/solver/array-rewriter.ts +12 -2
  63. package/src/prover/smt/solver/asserted-formulas.ts +169 -58
  64. package/src/prover/smt/solver/ast-lt.ts +1 -1
  65. package/src/prover/smt/solver/ast.ts +63 -14
  66. package/src/prover/smt/solver/auf-solver.ts +23 -12
  67. package/src/prover/smt/solver/bit-blast-tactic.ts +26 -0
  68. package/src/prover/smt/solver/blast-term-ite.ts +47 -0
  69. package/src/prover/smt/solver/bound-simplifier.ts +11 -13
  70. package/src/prover/smt/solver/bv-decl-plugin.ts +13 -10
  71. package/src/prover/smt/solver/bv-rewriter.ts +1 -1
  72. package/src/prover/smt/solver/card2bv.ts +35 -18
  73. package/src/prover/smt/solver/cofactor-elim-term-ite.ts +39 -24
  74. package/src/prover/smt/solver/context.ts +67 -13
  75. package/src/prover/smt/solver/ctx-simplify.ts +1 -2
  76. package/src/prover/smt/solver/datatype-decl-plugin.ts +15 -7
  77. package/src/prover/smt/solver/dependent-expr-state.ts +26 -15
  78. package/src/prover/smt/solver/diff-neq.ts +1 -2
  79. package/src/prover/smt/solver/dt2bv-tactic.ts +36 -20
  80. package/src/prover/smt/solver/elim-bounds.ts +89 -0
  81. package/src/prover/smt/solver/elim-term-ite-tactic.ts +48 -0
  82. package/src/prover/smt/solver/elim-uncnstr.ts +5 -8
  83. package/src/prover/smt/solver/euf/arith-internalize.ts +1 -1
  84. package/src/prover/smt/solver/euf/array-internalize.ts +1 -1
  85. package/src/prover/smt/solver/euf/bv-internalize.ts +1 -1
  86. package/src/prover/smt/solver/euf/egraph.ts +4 -11
  87. package/src/prover/smt/solver/euf/euf-solver.ts +1 -2
  88. package/src/prover/smt/solver/euf/mam.ts +1 -5
  89. package/src/prover/smt/solver/euf/q-ematch.ts +1 -2
  90. package/src/prover/smt/solver/euf/th-solver.ts +0 -7
  91. package/src/prover/smt/solver/expr2polynomial.ts +204 -79
  92. package/src/prover/smt/solver/factor.ts +36 -14
  93. package/src/prover/smt/solver/fd-solver.ts +148 -39
  94. package/src/prover/smt/solver/fix-dl-var.ts +1 -2
  95. package/src/prover/smt/solver/fpa-rewriter.ts +1 -2
  96. package/src/prover/smt/solver/fpa2bv-converter.ts +3 -1
  97. package/src/prover/smt/solver/fpa2bv-rewriter.ts +1 -0
  98. package/src/prover/smt/solver/goal.ts +6 -3
  99. package/src/prover/smt/solver/goal2nlsat.ts +57 -30
  100. package/src/prover/smt/solver/hashtable.ts +4 -0
  101. package/src/prover/smt/solver/internalizer.ts +1 -1
  102. package/src/prover/smt/solver/logic-tactics.ts +9 -2
  103. package/src/prover/smt/solver/lp/lp-settings.ts +5 -1
  104. package/src/prover/smt/solver/lp/nla-core.ts +1 -1
  105. package/src/prover/smt/solver/lp/nla-grobner.ts +2 -2
  106. package/src/prover/smt/solver/lp/nra-solver.ts +45 -39
  107. package/src/prover/smt/solver/lp/pdd.ts +2 -3
  108. package/src/prover/smt/solver/lp/union-find.ts +1 -1
  109. package/src/prover/smt/solver/mam-compiler.ts +1 -1
  110. package/src/prover/smt/solver/maxcore.ts +2 -1
  111. package/src/prover/smt/solver/maxsmt-base.ts +1 -0
  112. package/src/prover/smt/solver/model-based-opt.ts +1 -1
  113. package/src/prover/smt/solver/model-checker.ts +1 -1
  114. package/src/prover/smt/solver/model-evaluator.ts +2 -0
  115. package/src/prover/smt/solver/model-generator.ts +85 -43
  116. package/src/prover/smt/solver/mpf.ts +2 -4
  117. package/src/prover/smt/solver/mus.ts +2 -3
  118. package/src/prover/smt/solver/muz/dl-context.ts +22 -44
  119. package/src/prover/smt/solver/muz/dl-mk-coi-filter.ts +1 -1
  120. package/src/prover/smt/solver/muz/dl-mk-slice.ts +3 -3
  121. package/src/prover/smt/solver/muz/dl-rule.ts +8 -9
  122. package/src/prover/smt/solver/muz/hnf.ts +2 -2
  123. package/src/prover/smt/solver/muz/horn-subsume-model-converter.ts +1 -1
  124. package/src/prover/smt/solver/muz/horn-tactic.ts +15 -2
  125. package/src/prover/smt/solver/muz/rule-properties.ts +22 -0
  126. package/src/prover/smt/solver/muz/spacer-context.ts +2 -4
  127. package/src/prover/smt/solver/muz/spacer-pdr.ts +1 -0
  128. package/src/prover/smt/solver/muz/spacer-prop-solver.ts +1 -1
  129. package/src/prover/smt/solver/nlqsat.ts +1 -1
  130. package/src/prover/smt/solver/nlsat/algebraic.ts +196 -92
  131. package/src/prover/smt/solver/nlsat/atoms.ts +52 -33
  132. package/src/prover/smt/solver/nlsat/explain.ts +375 -217
  133. package/src/prover/smt/solver/nlsat/levelwise.ts +460 -240
  134. package/src/prover/smt/solver/nlsat/polynomial.ts +2366 -681
  135. package/src/prover/smt/solver/nlsat/solver.ts +74 -64
  136. package/src/prover/smt/solver/nlsat/transcendentals.ts +41 -17
  137. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +8 -4
  138. package/src/prover/smt/solver/nlsat/upolynomial.ts +41 -18
  139. package/src/prover/smt/solver/nlsat-tactic.ts +1 -1
  140. package/src/prover/smt/solver/nnf.ts +6 -2
  141. package/src/prover/smt/solver/opt-context.ts +21 -7
  142. package/src/prover/smt/solver/opt-nlsat.ts +29 -18
  143. package/src/prover/smt/solver/opt-pareto.ts +19 -0
  144. package/src/prover/smt/solver/opt-preprocess.ts +1 -1
  145. package/src/prover/smt/solver/opt-solver.ts +10 -6
  146. package/src/prover/smt/solver/optsmt.ts +1 -1
  147. package/src/prover/smt/solver/parallel-tactic.ts +1 -1
  148. package/src/prover/smt/solver/pb-rewriter.ts +1 -4
  149. package/src/prover/smt/solver/poly-rewriter.ts +75 -18
  150. package/src/prover/smt/solver/probes.ts +88 -23
  151. package/src/prover/smt/solver/proto-model.ts +8 -8
  152. package/src/prover/smt/solver/push-app-ite.ts +37 -0
  153. package/src/prover/smt/solver/qe-arith-plugin.ts +2 -4
  154. package/src/prover/smt/solver/qe-lite.ts +2 -2
  155. package/src/prover/smt/solver/qe.ts +3 -2
  156. package/src/prover/smt/solver/qsat.ts +23 -8
  157. package/src/prover/smt/solver/quantifier-manager.ts +14 -9
  158. package/src/prover/smt/solver/recfun-decl-plugin.ts +2 -1
  159. package/src/prover/smt/solver/rewriter-tpl.ts +7 -6
  160. package/src/prover/smt/solver/rewriter.ts +31 -25
  161. package/src/prover/smt/solver/rlimit.ts +4 -0
  162. package/src/prover/smt/solver/sat/config.ts +1 -1
  163. package/src/prover/smt/solver/sat/goal2sat.ts +0 -1
  164. package/src/prover/smt/solver/sat/inc-sat-solver.ts +81 -28
  165. package/src/prover/smt/solver/sat/model-converter.ts +1 -1
  166. package/src/prover/smt/solver/sat/pb-solver.ts +1 -1
  167. package/src/prover/smt/solver/sat/sat-tactic.ts +17 -7
  168. package/src/prover/smt/solver/sat/sat2goal.ts +10 -7
  169. package/src/prover/smt/solver/sat/simplifier.ts +1 -1
  170. package/src/prover/smt/solver/sat/solver.ts +25 -47
  171. package/src/prover/smt/solver/seq-axioms.ts +20 -35
  172. package/src/prover/smt/solver/seq-decl-plugin.ts +1 -1
  173. package/src/prover/smt/solver/seq-derive.ts +2 -2
  174. package/src/prover/smt/solver/seq-eq-solver.ts +2 -2
  175. package/src/prover/smt/solver/seq-monadic.ts +7 -5
  176. package/src/prover/smt/solver/seq-re-rewriter.ts +2 -1
  177. package/src/prover/smt/solver/seq-re-util.ts +1 -1
  178. package/src/prover/smt/solver/seq-regex-bisim.ts +1 -1
  179. package/src/prover/smt/solver/seq-regex-live.ts +2 -2
  180. package/src/prover/smt/solver/seq-rewriter.ts +31 -29
  181. package/src/prover/smt/solver/seq-skolem.ts +0 -23
  182. package/src/prover/smt/solver/seq-view-witness.ts +4 -4
  183. package/src/prover/smt/solver/smt-consequences.ts +1 -1
  184. package/src/prover/smt/solver/smt-kernel.ts +48 -7
  185. package/src/prover/smt/solver/smt-setup.ts +96 -10
  186. package/src/prover/smt/solver/smtlib-parser.ts +589 -224
  187. package/src/prover/smt/solver/smtlib-script.ts +674 -195
  188. package/src/prover/smt/solver/solve-eqs.ts +36 -37
  189. package/src/prover/smt/solver/solver.ts +18 -3
  190. package/src/prover/smt/solver/tactic.ts +332 -189
  191. package/src/prover/smt/solver/theory-bv.ts +13 -3
  192. package/src/prover/smt/solver/theory-fpa.ts +1 -1
  193. package/src/prover/smt/solver/theory-lra-final-check.ts +1 -0
  194. package/src/prover/smt/solver/theory-lra-internalize.ts +2 -0
  195. package/src/prover/smt/solver/theory-lra-propagate.ts +11 -3
  196. package/src/prover/smt/solver/theory-lra.ts +1 -1
  197. package/src/prover/smt/solver/theory-pb.ts +24 -7
  198. package/src/prover/smt/solver/theory-seq-solve.ts +1 -1
  199. package/src/prover/smt/solver/theory-seq-state.ts +2 -21
  200. package/src/prover/smt/solver/tseitin-cnf.ts +1 -0
  201. package/src/prover/tlapm/cache.ts +8 -8
  202. package/src/prover/zenon/index-table.ts +5 -2
  203. package/src/prover/zenon/isar-case.ts +1 -1
  204. package/src/prover/zenon/isar.ts +2 -2
  205. package/src/prover/zenon/phrase.ts +1 -1
  206. package/src/resolve.ts +1071 -251
  207. package/src/runtime.ts +5 -1
  208. package/src/sany/builtins.ts +10 -10
  209. package/src/sany/generation.ts +2 -13
  210. package/src/sany/generator-definitions.ts +3 -1
  211. package/src/sany/generator-expressions.ts +38 -30
  212. package/src/sany/generator-proofs.ts +6 -3
  213. package/src/sany/generator.ts +2 -1
  214. package/src/sany/lexer.ts +3 -3
  215. package/src/sany/modules.ts +4 -2
  216. package/src/sany/nodes.ts +1 -1
  217. package/src/sany/selectors.ts +11 -6
  218. package/src/sany/xml.ts +2 -3
  219. package/src/search.ts +197 -117
  220. package/src/simulate.ts +165 -102
  221. package/src/spec-description.ts +8 -6
  222. package/src/standard-modules.ts +56 -22
  223. package/src/subexpressions.ts +518 -123
  224. package/src/successors.ts +10 -3
  225. package/src/symmetry.ts +2 -1
  226. package/src/tlc/jar-data.ts +10 -0
  227. package/src/tlc/messages.ts +3 -3
  228. package/src/tlc/random.ts +2 -1
  229. package/src/tlc/replay.ts +27 -14
  230. package/src/tlc/tlc-operators.ts +10 -8
  231. package/src/tlc/tlcext-operators.ts +26 -10
  232. package/src/tlc/trace-spec.ts +9 -22
  233. package/src/typed-tier.ts +44 -27
  234. package/src/typescript/types.ts +2 -2
  235. package/src/values.ts +135 -78
package/src/levels.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import {
2
2
  getChildren,
3
3
  type AssumeProve,
4
+ type Bound,
4
5
  type Definition,
5
6
  type Expression,
6
7
  type Module,
8
+ type NewSymbol,
7
9
  type OperatorParam,
8
10
  type Proof,
9
11
  type ProofStep,
@@ -18,6 +20,7 @@ import {
18
20
  } from "./errors";
19
21
  import { forEachChild } from "./instances";
20
22
  import { collectSemanticErrors, getBoundNames, getPatternNames } from "./resolve";
23
+ import { resolveSynonym } from "./tlc/jar-data";
21
24
  import { STANDARD_LEVELS } from "./standard-definitions";
22
25
 
23
26
  interface LevelData {
@@ -46,7 +49,7 @@ interface LevelContext {
46
49
  }
47
50
 
48
51
  type ScopeEntry =
49
- | { kind: "Formal"; arity: number }
52
+ | { kind: "Formal"; arity: number; level: number }
50
53
  | { kind: "Let"; definition: Definition; scope: Scope };
51
54
 
52
55
  export type Scope = Map<string, ScopeEntry>;
@@ -65,6 +68,14 @@ export const VARIABLE_LEVEL = 1;
65
68
  export const ACTION_LEVEL = 2;
66
69
  export const TEMPORAL_LEVEL = 3;
67
70
 
71
+ const NEW_SYMBOL_LEVELS = {
72
+ Constant: CONSTANT_LEVEL,
73
+ Variable: VARIABLE_LEVEL,
74
+ State: VARIABLE_LEVEL,
75
+ Action: ACTION_LEVEL,
76
+ Temporal: TEMPORAL_LEVEL,
77
+ } satisfies Record<NewSymbol["level"], number>;
78
+
68
79
  const SEPARATOR = "\u0000";
69
80
 
70
81
  export const getArgumentKey = (operator: string, index: number) =>
@@ -154,27 +165,50 @@ const CORE_SIGNATURES = new Map(
154
165
  ["BOOLEAN", 0, [], []],
155
166
  ["STRING", 0, [], []],
156
167
  ] as const
157
- ).map(([name, level, maxLevels, weights]): [string, OperatorLevels] => [
158
- name,
168
+ ).map((signature): [string, OperatorLevels] => [
169
+ signature[0],
159
170
  {
160
- ...createSignature(name, level, [...maxLevels], [...weights]),
161
- nonLeibniz: new Set(level > 1 ? [0, 1] : []),
171
+ ...createSignature(signature[0], signature[1], [...signature[2]], [...signature[3]]),
172
+ nonLeibniz: new Set(signature[1] > 1 ? [0, 1] : []),
162
173
  },
163
174
  ]),
164
175
  );
165
176
 
166
- const SET_LEVELS = createSignature("$Set", 0, [2], [1]);
167
- const JUNCTION_LEVELS = createSignature("$Junction", 0, [3], [1]);
168
- const CHOOSE_LEVELS = createSignature("$Choose", 0, [2], [1]);
169
- const FUNCTION_LEVELS = createSignature("$Function", 0, [3], [1]);
170
- const APPLY_LEVELS = createSignature("$FcnApply", 0, [2, 2], [1, 1]);
171
- const SELECT_LEVELS = createSignature("$RcdSelect", 0, [2, 0], [1, 1]);
172
177
  const PRIME_LEVELS = createSignature("'", 2, [1], [0]);
178
+ const UNCHANGED_LEVELS = createSignature("UNCHANGED", 2, [1], [0]);
173
179
  const ENABLED_LEVELS = createSignature("ENABLED", 1, [2], [0]);
174
- const TEMPORAL_LEVELS = createSignature("[]", 3, [3], [0]);
175
- const ACTION_LEVELS = createSignature("$SquareAct", 2, [2, 1], [0, 0]);
176
- const FAIRNESS_LEVELS = createSignature("$WF", 3, [1, 2], [0, 0]);
177
- const TEMPORAL_QUANTIFIER_LEVELS = createSignature("$TemporalExists", 3, [3], [0]);
180
+ const ALWAYS_LEVELS = createSignature("[]", 3, [3], [0]);
181
+ const EVENTUALLY_LEVELS = createSignature("<>", 3, [3], [0]);
182
+ const AND_LEVELS = createSignature("$ConjList", 0, [3], [1]);
183
+ const OR_LEVELS = createSignature("$DisjList", 0, [3], [1]);
184
+ const IF_LEVELS = createSignature("$IfThenElse", 0, [3], [1]);
185
+ const CASE_LEVELS = createSignature("$Case", 0, [3], [1]);
186
+ const FORALL_LEVELS = createSignature("$BoundedForall", 0, [3], [1]);
187
+ const EXISTS_LEVELS = createSignature("$BoundedExists", 0, [3], [1]);
188
+ const UNBOUNDED_FORALL_LEVELS = createSignature("$UnboundedForall", 0, [3], [1]);
189
+ const UNBOUNDED_EXISTS_LEVELS = createSignature("$UnboundedExists", 0, [3], [1]);
190
+ const TEMPORAL_FORALL_LEVELS = createSignature("$TemporalForall", 3, [3], [0]);
191
+ const TEMPORAL_EXISTS_LEVELS = createSignature("$TemporalExists", 3, [3], [0]);
192
+ const BOUNDED_CHOOSE_LEVELS = createSignature("$BoundedChoose", 0, [2], [1]);
193
+ const UNBOUNDED_CHOOSE_LEVELS = createSignature("$UnboundedChoose", 0, [2], [1]);
194
+ const SET_ENUMERATE_LEVELS = createSignature("$SetEnumerate", 0, [2], [1]);
195
+ const TUPLE_LEVELS = createSignature("$Tuple", 0, [2], [1]);
196
+ const SET_OF_FCNS_LEVELS = createSignature("$SetOfFcns", 0, [2], [1]);
197
+ const CARTESIAN_PROD_LEVELS = createSignature("$CartesianProd", 0, [2], [1]);
198
+ const SUBSET_OF_LEVELS = createSignature("$SubsetOf", 0, [2], [1]);
199
+ const SET_OF_ALL_LEVELS = createSignature("$SetOfAll", 0, [2], [1]);
200
+ const FCN_CONSTRUCTOR_LEVELS = createSignature("$FcnConstructor", 0, [3], [1]);
201
+ const RCD_CONSTRUCTOR_LEVELS = createSignature("$RcdConstructor", 0, [3], [1]);
202
+ const SET_OF_RCDS_LEVELS = createSignature("$SetOfRcds", 0, [2], [1]);
203
+ const EXCEPT_LEVELS = createSignature("$Except", 0, [2], [1]);
204
+ const PAIR_LEVELS = createSignature("$Pair", 0, [3], [1]);
205
+ const SEQ_LEVELS = createSignature("$Seq", 0, [2], [1]);
206
+ const APPLY_LEVELS = createSignature("$FcnApply", 0, [2, 2], [1, 1]);
207
+ const SELECT_LEVELS = createSignature("$RcdSelect", 0, [2, 0], [1, 1]);
208
+ const SQUARE_ACT_LEVELS = createSignature("$SquareAct", 2, [2, 1], [0, 0]);
209
+ const ANGLE_ACT_LEVELS = createSignature("$AngleAct", 2, [2, 1], [0, 0]);
210
+ const WF_LEVELS = createSignature("$WF", 3, [1, 2], [0, 0]);
211
+ const SF_LEVELS = createSignature("$SF", 3, [1, 2], [0, 0]);
178
212
 
179
213
  const bindFormals = (scope: Scope, formals: OperatorParam[]) =>
180
214
  formals.length === 0
@@ -183,7 +217,7 @@ const bindFormals = (scope: Scope, formals: OperatorParam[]) =>
183
217
  ...scope,
184
218
  ...formals.map((formal): [string, ScopeEntry] => [
185
219
  formal.name,
186
- { kind: "Formal", arity: formal.arity },
220
+ { kind: "Formal", arity: formal.arity, level: CONSTANT_LEVEL },
187
221
  ]),
188
222
  ]);
189
223
 
@@ -203,11 +237,12 @@ const isOperatorApplication = (expression: Expression) =>
203
237
 
204
238
  export const createLevelAnalyzer = (context: LevelContext) => {
205
239
  const definitionLevels = new Map<Definition, OperatorLevels>();
240
+ const selectionLevels = new Map<Expression, LevelData>();
206
241
 
207
242
  const resolve = (name: string, scope: Scope): Resolved => {
208
243
  const entry = scope.get(name);
209
244
  if (entry?.kind === "Formal") {
210
- return { kind: "Declared", name, level: 0, arity: entry.arity };
245
+ return { kind: "Declared", name, level: entry.level, arity: entry.arity };
211
246
  }
212
247
  if (entry?.kind === "Let") {
213
248
  return { kind: "Defined", levels: analyzeDefinition(entry.definition, entry.scope) };
@@ -253,15 +288,10 @@ export const createLevelAnalyzer = (context: LevelContext) => {
253
288
  if (operand.kind !== "Value") return;
254
289
  if (operand.data.level > getMaxLevel(operator, index)) {
255
290
  throw new TlaSyntaxError(
256
- `Level error in applying operator ${operator.name}:\nThe level of argument ${index + 1} exceeds the maximum level allowed by the operator`,
291
+ `Level error in applying operator ${resolveSynonym(operator.name)}:\nThe level of argument ${index + 1} exceeds the maximum level allowed by the operator`,
257
292
  );
258
293
  }
259
294
  });
260
- if (ranges.some((range) => range.level > ACTION_LEVEL)) {
261
- throw new TlaSyntaxError(
262
- `Level error in applying operator ${operator.name}:\nThe level of the range for a bounded variable exceeds the maximum level allowed by the operator`,
263
- );
264
- }
265
295
  const getOperand = (formal: string) => {
266
296
  const index = operator.formals.findIndex((param) => param.name === formal);
267
297
  return index === -1 ? undefined : operands[index];
@@ -448,16 +478,20 @@ export const createLevelAnalyzer = (context: LevelContext) => {
448
478
  operator: OperatorLevels,
449
479
  expressions: Expression[],
450
480
  scope: Scope,
451
- ranges: Expression[] = [],
452
- bound: string[] = [],
481
+ bounds: Bound[] = [],
482
+ bound = getBoundNames(bounds),
453
483
  ) => {
454
- const inner = bindFormals(scope, toFormals(bound));
455
- return applyDefined(
456
- operator,
457
- toOperands(expressions, inner),
458
- ranges.map((range) => analyze(range, scope)),
459
- bound,
460
- );
484
+ const operands = toOperands(expressions, bindFormals(scope, toFormals(bound)));
485
+ const ranges = bounds.map((range) => analyze(range.set, scope));
486
+ const data = applyDefined(operator, operands, ranges, bound);
487
+ const pattern = bounds[ranges.findIndex((range) => range.level > ACTION_LEVEL)]?.pattern;
488
+ if (pattern) {
489
+ const range = pattern.ranges?.[0];
490
+ throw new TlaSyntaxError(
491
+ `Level error in applying operator ${operator.name}:\nThe level of the range for the bounded variable ${range ? formatRange(range) : getPatternNames(pattern)[0]} \nexceeds the maximum level allowed by the operator`,
492
+ );
493
+ }
494
+ return data;
461
495
  };
462
496
 
463
497
  const applyResolved = (resolved: Resolved, operands: Operand[]) =>
@@ -465,11 +499,11 @@ export const createLevelAnalyzer = (context: LevelContext) => {
465
499
  ? applyDeclared(resolved.name, resolved.level, operands)
466
500
  : applyDefined(resolved.levels, operands);
467
501
 
468
- const checkJunction = (operands: Operand[], expression: Expression) => {
502
+ const checkJunction = (operands: Operand[], expression: Expression, name: string) => {
469
503
  const levels = operands.map((operand) => operand.data.level);
470
504
  if (levels.includes(ACTION_LEVEL) && levels.includes(TEMPORAL_LEVEL)) {
471
505
  throw createLevelError(
472
- "Formula has both temporal formula and action as arguments",
506
+ `${name} has both temporal formula and action as arguments`,
473
507
  expression,
474
508
  );
475
509
  }
@@ -483,7 +517,9 @@ export const createLevelAnalyzer = (context: LevelContext) => {
483
517
  expression,
484
518
  );
485
519
  }
486
- if (LOGICAL_OPERATORS.has(expression.operator)) checkJunction(operands, expression);
520
+ if (LOGICAL_OPERATORS.has(expression.operator)) {
521
+ checkJunction(operands, expression, resolveSynonym(expression.operator));
522
+ }
487
523
  };
488
524
 
489
525
  const checkTemporal = (
@@ -549,29 +585,41 @@ export const createLevelAnalyzer = (context: LevelContext) => {
549
585
  case "And":
550
586
  case "Or": {
551
587
  const operands = toOperands(expression.operands, scope);
552
- checkJunction(operands, expression);
553
- return applyDefined(JUNCTION_LEVELS, operands);
588
+ const isAnd = expression.kind === "And";
589
+ checkJunction(
590
+ operands,
591
+ expression,
592
+ expression.isBulleted
593
+ ? `${isAnd ? "Conjunction" : "Disjunction"} list`
594
+ : isAnd
595
+ ? "\\land"
596
+ : "\\lor",
597
+ );
598
+ return applyDefined(isAnd ? AND_LEVELS : OR_LEVELS, operands);
554
599
  }
555
600
  case "Prime":
556
- case "Unchanged":
557
601
  return applyBuiltin(PRIME_LEVELS, [expression.expression], scope);
602
+ case "Unchanged":
603
+ return applyBuiltin(UNCHANGED_LEVELS, [expression.expression], scope);
558
604
  case "Enabled":
559
605
  return applyBuiltin(ENABLED_LEVELS, [expression.expression], scope);
560
606
  case "Always":
561
607
  case "Eventually": {
562
608
  const operand = toOperand(expression.expression, scope);
563
609
  checkTemporal(expression, operand.data.level);
564
- return applyDefined(TEMPORAL_LEVELS, [operand]);
610
+ return applyDefined(expression.kind === "Always" ? ALWAYS_LEVELS : EVENTUALLY_LEVELS, [
611
+ operand,
612
+ ]);
565
613
  }
566
614
  case "If":
567
615
  return applyBuiltin(
568
- JUNCTION_LEVELS,
616
+ IF_LEVELS,
569
617
  [expression.condition, expression.consequent, expression.alternative],
570
618
  scope,
571
619
  );
572
620
  case "Case":
573
621
  return applyBuiltin(
574
- JUNCTION_LEVELS,
622
+ CASE_LEVELS,
575
623
  [
576
624
  ...expression.arms.flatMap((arm) => [arm.condition, arm.body]),
577
625
  ...(expression.other ? [expression.other] : []),
@@ -583,11 +631,10 @@ export const createLevelAnalyzer = (context: LevelContext) => {
583
631
  case "Forall":
584
632
  case "Exists": {
585
633
  const data = applyBuiltin(
586
- JUNCTION_LEVELS,
634
+ expression.kind === "Forall" ? FORALL_LEVELS : EXISTS_LEVELS,
587
635
  [expression.body],
588
636
  scope,
589
- expression.bounds.map((bound) => bound.set),
590
- getBoundNames(expression.bounds),
637
+ expression.bounds,
591
638
  );
592
639
  const actionBound =
593
640
  data.level === TEMPORAL_LEVEL
@@ -603,7 +650,13 @@ export const createLevelAnalyzer = (context: LevelContext) => {
603
650
  }
604
651
  case "UnboundedQuantifier":
605
652
  return applyBuiltin(
606
- expression.isTemporal ? TEMPORAL_QUANTIFIER_LEVELS : JUNCTION_LEVELS,
653
+ expression.isTemporal
654
+ ? expression.quantifier === "Forall"
655
+ ? TEMPORAL_FORALL_LEVELS
656
+ : TEMPORAL_EXISTS_LEVELS
657
+ : expression.quantifier === "Forall"
658
+ ? UNBOUNDED_FORALL_LEVELS
659
+ : UNBOUNDED_EXISTS_LEVELS,
607
660
  [expression.body],
608
661
  scope,
609
662
  [],
@@ -611,79 +664,67 @@ export const createLevelAnalyzer = (context: LevelContext) => {
611
664
  );
612
665
  case "Choose":
613
666
  return applyBuiltin(
614
- CHOOSE_LEVELS,
667
+ expression.set ? BOUNDED_CHOOSE_LEVELS : UNBOUNDED_CHOOSE_LEVELS,
615
668
  [expression.body],
616
669
  scope,
617
- expression.set ? [expression.set] : [],
670
+ expression.set ? [{ pattern: expression.pattern, set: expression.set }] : [],
618
671
  getPatternNames(expression.pattern),
619
672
  );
620
673
  case "SetEnumeration":
674
+ return applyBuiltin(SET_ENUMERATE_LEVELS, expression.elements, scope);
621
675
  case "Tuple":
676
+ return applyBuiltin(TUPLE_LEVELS, expression.elements, scope);
622
677
  case "FunctionSet":
678
+ return applyBuiltin(SET_OF_FCNS_LEVELS, [expression.domain, expression.range], scope);
623
679
  case "Product":
624
- return applyBuiltin(
625
- SET_LEVELS,
626
- expression.kind === "FunctionSet"
627
- ? [expression.domain, expression.range]
628
- : expression.kind === "Product"
629
- ? expression.factors
630
- : expression.elements,
631
- scope,
632
- );
680
+ return applyBuiltin(CARTESIAN_PROD_LEVELS, expression.factors, scope);
633
681
  case "SetFilter":
634
- return applyBuiltin(
635
- SET_LEVELS,
636
- [expression.predicate],
637
- scope,
638
- [expression.bound.set],
639
- getPatternNames(expression.bound.pattern),
640
- );
682
+ return applyBuiltin(SUBSET_OF_LEVELS, [expression.predicate], scope, [expression.bound]);
641
683
  case "SetMap":
642
- return applyBuiltin(
643
- SET_LEVELS,
644
- [expression.expression],
645
- scope,
646
- expression.bounds.map((bound) => bound.set),
647
- getBoundNames(expression.bounds),
648
- );
684
+ return applyBuiltin(SET_OF_ALL_LEVELS, [expression.expression], scope, expression.bounds);
649
685
  case "FunctionConstruction":
650
- return applyBuiltin(
651
- FUNCTION_LEVELS,
652
- [expression.body],
653
- scope,
654
- expression.bounds.map((bound) => bound.set),
655
- getBoundNames(expression.bounds),
656
- );
686
+ return applyBuiltin(FCN_CONSTRUCTOR_LEVELS, [expression.body], scope, expression.bounds);
657
687
  case "Record":
658
688
  return applyBuiltin(
659
- FUNCTION_LEVELS,
689
+ RCD_CONSTRUCTOR_LEVELS,
660
690
  expression.fields.map((field) => field.value),
661
691
  scope,
662
692
  );
663
693
  case "RecordSet":
664
694
  return applyBuiltin(
665
- SET_LEVELS,
695
+ SET_OF_RCDS_LEVELS,
666
696
  expression.fields.map((field) => field.value),
667
697
  scope,
668
698
  );
669
699
  case "Except":
670
- return applyBuiltin(
671
- SET_LEVELS,
672
- [
673
- expression.function,
674
- ...expression.updates.flatMap((update) => [
675
- ...update.path.flatMap((step) => (step.kind === "Index" ? step.args : [])),
676
- update.value,
700
+ return applyDefined(EXCEPT_LEVELS, [
701
+ toOperand(expression.function, scope),
702
+ ...expression.updates.map((update): Operand => ({
703
+ kind: "Value",
704
+ data: applyDefined(PAIR_LEVELS, [
705
+ {
706
+ kind: "Value",
707
+ data: applyDefined(
708
+ SEQ_LEVELS,
709
+ update.path.map((step): Operand =>
710
+ step.kind === "Field"
711
+ ? { kind: "Value", data: createData() }
712
+ : step.args.length === 1
713
+ ? toOperand(step.args[0], scope)
714
+ : { kind: "Value", data: applyBuiltin(TUPLE_LEVELS, step.args, scope) },
715
+ ),
716
+ ),
717
+ },
718
+ toOperand(update.value, scope),
677
719
  ]),
678
- ],
679
- scope,
680
- );
720
+ })),
721
+ ]);
681
722
  case "FunctionApplication":
682
723
  return applyDefined(APPLY_LEVELS, [
683
724
  toOperand(expression.function, scope),
684
725
  expression.args.length === 1
685
726
  ? toOperand(expression.args[0], scope)
686
- : { kind: "Value", data: applyBuiltin(SET_LEVELS, expression.args, scope) },
727
+ : { kind: "Value", data: applyBuiltin(TUPLE_LEVELS, expression.args, scope) },
687
728
  ]);
688
729
  case "Bracket":
689
730
  return createData();
@@ -694,12 +735,28 @@ export const createLevelAnalyzer = (context: LevelContext) => {
694
735
  ]);
695
736
  case "BoxAction":
696
737
  case "AngleAction":
697
- return applyBuiltin(ACTION_LEVELS, [expression.action, expression.subscript], scope);
738
+ return applyBuiltin(
739
+ expression.kind === "BoxAction" ? SQUARE_ACT_LEVELS : ANGLE_ACT_LEVELS,
740
+ [expression.action, expression.subscript],
741
+ scope,
742
+ );
698
743
  case "WeakFairness":
699
744
  case "StrongFairness":
700
- return applyBuiltin(FAIRNESS_LEVELS, [expression.subscript, expression.action], scope);
745
+ return applyBuiltin(
746
+ expression.kind === "WeakFairness" ? WF_LEVELS : SF_LEVELS,
747
+ [expression.subscript, expression.action],
748
+ scope,
749
+ );
701
750
  case "Label":
702
751
  return analyze(expression.body, scope);
752
+ case "Selection": {
753
+ const selected = expression.expression;
754
+ const known = selectionLevels.get(selected);
755
+ if (known) return known;
756
+ const data = analyze(selected, scope);
757
+ selectionLevels.set(selected, data);
758
+ return data;
759
+ }
703
760
  case "Subexpression":
704
761
  return createData();
705
762
  }
@@ -733,6 +790,7 @@ export const createLevelAnalyzer = (context: LevelContext) => {
733
790
  return names;
734
791
  case "Lambda":
735
792
  case "Let":
793
+ case "Selection":
736
794
  return names;
737
795
  case "Prime":
738
796
  case "Unchanged":
@@ -769,7 +827,10 @@ export const createLevelAnalyzer = (context: LevelContext) => {
769
827
  const inner = bindFormals(scope, formals);
770
828
  const data = analyze(body, inner);
771
829
  const isFormal = (param: string) => formals.some((formal) => formal.name === param);
772
- const nonLeibnizNames = getNonLeibnizNames(body, inner);
830
+ const nonLeibnizNames = getNonLeibnizNames(
831
+ body.kind === "Selection" ? body.expression : body,
832
+ inner,
833
+ );
773
834
  const levels: OperatorLevels = {
774
835
  ...createData(data.level),
775
836
  name,
@@ -850,17 +911,29 @@ export const analyzeAssumeProve = (
850
911
  assumeProve: AssumeProve,
851
912
  scope: Scope,
852
913
  analyzer: ReturnType<typeof createLevelAnalyzer>,
914
+ errors: SanyError[] = [],
853
915
  ): LevelData => {
854
916
  const inner = new Map(scope);
855
917
  const parts = assumeProve.assumptions.flatMap((assumption) => {
856
918
  if (assumption.kind === "NewSymbol") {
857
919
  const set = assumption.set && analyzer.analyze(assumption.set, inner);
858
- inner.set(assumption.name, { kind: "Formal", arity: assumption.arity });
920
+ const range = assumption.location.range;
921
+ if (set?.level === TEMPORAL_LEVEL && range) {
922
+ errors.push({
923
+ location: formatRange(range),
924
+ message: "Level error:\nTemporal formula used as set.",
925
+ });
926
+ }
927
+ inner.set(assumption.name, {
928
+ kind: "Formal",
929
+ arity: assumption.arity,
930
+ level: NEW_SYMBOL_LEVELS[assumption.level],
931
+ });
859
932
  return set ? [set] : [];
860
933
  }
861
934
  return [
862
935
  assumption.kind === "AssumeProve"
863
- ? analyzeAssumeProve(assumption, inner, analyzer)
936
+ ? analyzeAssumeProve(assumption, inner, analyzer, errors)
864
937
  : analyzer.analyze(assumption, inner),
865
938
  ];
866
939
  });
@@ -925,6 +998,10 @@ export const checkModuleLevels = (
925
998
  ? []
926
999
  : proof.steps.flatMap((step) => {
927
1000
  const body = step.body;
1001
+ const newSymbolErrors: SanyError[] = [];
1002
+ if (body.kind === "Assert" && body.statement.kind === "AssumeProve") {
1003
+ analyzeAssumeProve(body.statement, new Map(), analyzer, newSymbolErrors);
1004
+ }
928
1005
  const isTemporal = () => getStepLevel(step) === TEMPORAL_LEVEL;
929
1006
  const pickErrors =
930
1007
  body.kind === "Pick" && body.bounds.length > 0 && isTemporal()
@@ -942,6 +1019,7 @@ export const checkModuleLevels = (
942
1019
  )
943
1020
  : [];
944
1021
  return [
1022
+ ...newSymbolErrors,
945
1023
  ...checkProof(step.proof),
946
1024
  ...pickErrors,
947
1025
  ...(step.proof?.kind === "Steps" && isTemporal() ? checkTemporalGoal(step.proof) : []),
@@ -957,16 +1035,27 @@ export const checkModuleLevels = (
957
1035
  })),
958
1036
  ...module.assumptions.map((assumption) => ({
959
1037
  location: assumption.location,
960
- check: () => analyzer.analyze(assumption.expression, new Map()),
1038
+ check: () => {
1039
+ const level = analyzer.analyze(assumption.expression, new Map()).level;
1040
+ const range = assumption.location.range;
1041
+ if (level !== CONSTANT_LEVEL && range) {
1042
+ throw createSemanticError(
1043
+ `Level error: assumptions must be level 0 (Constant), \nbut this one has level ${level}.`,
1044
+ range,
1045
+ );
1046
+ }
1047
+ },
961
1048
  })),
962
1049
  ...module.theorems.map((theorem) => ({
963
1050
  location: theorem.location,
964
1051
  check: () => {
1052
+ const newSymbolErrors: SanyError[] = [];
965
1053
  const data =
966
1054
  theorem.statement.kind === "AssumeProve"
967
- ? analyzeAssumeProve(theorem.statement, new Map(), analyzer)
1055
+ ? analyzeAssumeProve(theorem.statement, new Map(), analyzer, newSymbolErrors)
968
1056
  : analyzer.analyze(theorem.statement, new Map());
969
1057
  const errors = [
1058
+ ...newSymbolErrors,
970
1059
  ...checkProof(theorem.proof),
971
1060
  ...(data.level === TEMPORAL_LEVEL ? checkTemporalGoal(theorem.proof) : []),
972
1061
  ];