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
@@ -67,18 +67,417 @@ export interface CollectState {
67
67
 
68
68
  const SEQUENCE_DEPS = ["Mem", "Seq", "Len", "FunApp", "NatSet", "Cast_Int", "Proj_Int"];
69
69
 
70
+ const INT_EXP = tla("IntExp");
71
+
72
+ const SUB_SEQ_RANGE = `(${SUB_SEQ} s (${CAST_INT} x) (${CAST_INT} y))`;
73
+
74
+ const createSpec = (
75
+ declaration: string | undefined,
76
+ deps: string[],
77
+ axioms: Axiom[],
78
+ ): SymbolSpec => ({ declaration, deps, axioms });
79
+
80
+ const declareSpec = (name: string, arity: number, deps: string[], axioms: Axiom[], sort = "Idv") =>
81
+ createSpec(declare(tla(name), arity, sort), deps, axioms);
82
+
83
+ const getSetOperationDef = (name: string, condition: string) =>
84
+ axiom(
85
+ `${name}Def`,
86
+ [],
87
+ `(forall ((a Idv) (b Idv) (x Idv)) (! (= (${MEM} x (${tla(name)} a b)) ${condition}) :pattern ((${MEM} x (${tla(name)} a b))) :pattern ((${MEM} x a) (${tla(name)} a b)) :pattern ((${MEM} x b) (${tla(name)} a b))))`,
88
+ );
89
+
90
+ const STATIC_SPECS = new Map(
91
+ Object.entries({
92
+ IntExp: declareSpec(
93
+ "IntExp",
94
+ 2,
95
+ ["Mem", "IntSet", "Cast_Int", "TIntLteq", "TIntLit_0", "TIntLit_1"],
96
+ [
97
+ axiom(
98
+ "IntExpTyping",
99
+ [],
100
+ `(forall ((x Idv) (y Idv)) (! (=> (and (${MEM} x ${INT_SET}) (${MEM} y ${INT_SET}) (or (distinct x (${CAST_INT} 0)) (${INT_LTEQ} (${CAST_INT} 1) y))) (${MEM} (${INT_EXP} x y) ${INT_SET})) :pattern ((${INT_EXP} x y))))`,
101
+ ),
102
+ ],
103
+ ),
104
+ SelectSeq: createSpec(
105
+ undefined,
106
+ [
107
+ "Mem",
108
+ "Seq",
109
+ "Len",
110
+ "Append",
111
+ "FunApp",
112
+ "FunDom",
113
+ "IntSet",
114
+ "NatSet",
115
+ "Tuple_0",
116
+ "Proj_Int",
117
+ ],
118
+ [
119
+ axiom("SeqSelectseqTyping", [], undefined),
120
+ axiom("SeqSelectseqLen", [], undefined),
121
+ axiom("SeqSelectseqNil", [], undefined),
122
+ axiom("SeqSelectseqApp", [], undefined),
123
+ axiom("SeqSelectseqAppend", [], undefined),
124
+ ],
125
+ ),
126
+ Choose: createSpec(undefined, [], [axiom("ChooseDef", [], undefined)]),
127
+ Mem: declareSpec(
128
+ "Mem",
129
+ 2,
130
+ ["SetExtTrigger"],
131
+ [
132
+ axiom(
133
+ "SetExt",
134
+ [],
135
+ `(forall ((x Idv) (y Idv)) (! (=> (forall ((z Idv)) (= (${MEM} z x) (${MEM} z y))) (= x y)) :pattern ((${SET_EXT_TRIGGER} x y))))`,
136
+ ),
137
+ ],
138
+ "Bool",
139
+ ),
140
+ SubsetEq: declareSpec(
141
+ "SubsetEq",
142
+ 2,
143
+ ["Mem"],
144
+ [
145
+ axiom(
146
+ "SubsetEqIntro",
147
+ [],
148
+ `(forall ((x Idv) (y Idv)) (! (=> (forall ((z Idv)) (=> (${MEM} z x) (${MEM} z y))) (${SUBSET_EQ} x y)) :pattern ((${SUBSET_EQ} x y))))`,
149
+ ),
150
+ axiom(
151
+ "SubsetEqElim",
152
+ [],
153
+ `(forall ((x Idv) (y Idv) (z Idv)) (! (=> (and (${SUBSET_EQ} x y) (${MEM} z x)) (${MEM} z y)) :pattern ((${SUBSET_EQ} x y) (${MEM} z x))))`,
154
+ ),
155
+ ],
156
+ "Bool",
157
+ ),
158
+ Union: declareSpec(
159
+ "Union",
160
+ 1,
161
+ ["Mem"],
162
+ [
163
+ axiom(
164
+ "UnionIntro",
165
+ [],
166
+ `(forall ((a Idv) (x Idv) (y Idv)) (! (=> (and (${MEM} y a) (${MEM} x y)) (${MEM} x (${UNION} a))) :pattern ((${MEM} y a) (${MEM} x (${UNION} a))) :pattern ((${MEM} x y) (${MEM} x (${UNION} a))) :pattern ((${MEM} y a) (${MEM} x y) (${UNION} a))))`,
167
+ ),
168
+ axiom(
169
+ "UnionElim",
170
+ [],
171
+ `(forall ((a Idv) (x Idv)) (! (=> (${MEM} x (${UNION} a)) (exists ((y Idv)) (and (${MEM} y a) (${MEM} x y)))) :pattern ((${MEM} x (${UNION} a)))))`,
172
+ ),
173
+ ],
174
+ ),
175
+ Subset: declareSpec(
176
+ "Subset",
177
+ 1,
178
+ ["Mem", "SubsetEq"],
179
+ [
180
+ axiom(
181
+ "SubsetDefAlt",
182
+ [],
183
+ `(forall ((a Idv) (x Idv)) (! (= (${MEM} x (${SUBSET} a)) (${SUBSET_EQ} x a)) :pattern ((${MEM} x (${SUBSET} a))) :pattern ((${SUBSET_EQ} x a) (${SUBSET} a))))`,
184
+ ),
185
+ ],
186
+ ),
187
+ Cup: declareSpec(
188
+ "Cup",
189
+ 2,
190
+ ["Mem"],
191
+ [getSetOperationDef("Cup", `(or (${MEM} x a) (${MEM} x b))`)],
192
+ ),
193
+ Cap: declareSpec(
194
+ "Cap",
195
+ 2,
196
+ ["Mem", "SetEnum_0", "SetExtTrigger"],
197
+ [
198
+ getSetOperationDef("Cap", `(and (${MEM} x a) (${MEM} x b))`),
199
+ axiom(
200
+ "DisjointTrigger",
201
+ [],
202
+ `(forall ((x Idv) (y Idv)) (! (${SET_EXT_TRIGGER} (${CAP} x y) ${tla("SetEnum_0")}) :pattern ((${CAP} x y))))`,
203
+ ),
204
+ ],
205
+ ),
206
+ SetMinus: declareSpec(
207
+ "SetMinus",
208
+ 2,
209
+ ["Mem"],
210
+ [getSetOperationDef("SetMinus", `(and (${MEM} x a) (not (${MEM} x b)))`)],
211
+ ),
212
+ SetSt: createSpec(
213
+ undefined,
214
+ ["Mem", "SetEnum_0", "SetExtTrigger"],
215
+ [axiom("SetStDef", [], undefined), axiom("EmptyComprehensionTrigger", [], undefined)],
216
+ ),
217
+ NatSet: declareSpec(
218
+ "NatSet",
219
+ 0,
220
+ ["IntSet", "TIntLit_0", "Cast_Int", "IntLteq"],
221
+ [
222
+ axiom(
223
+ "NatSetDef",
224
+ [],
225
+ `(forall ((x Idv)) (! (= (${MEM} x ${NAT_SET}) (and (${MEM} x ${INT_SET}) (${INT_LTEQ} (${CAST_INT} 0) x))) :pattern ((${MEM} x ${NAT_SET}))))`,
226
+ ),
227
+ ],
228
+ ),
229
+ IntRange: declareSpec(
230
+ "IntRange",
231
+ 2,
232
+ ["Mem", "IntSet", "IntLteq"],
233
+ [
234
+ axiom(
235
+ "IntRangeDef",
236
+ [],
237
+ `(forall ((a Idv) (b Idv) (x Idv)) (! (= (${MEM} x (${INT_RANGE} a b)) (and (${MEM} x ${INT_SET}) (${INT_LTEQ} a x) (${INT_LTEQ} x b))) :pattern ((${MEM} x (${INT_RANGE} a b)))))`,
238
+ ),
239
+ ],
240
+ ),
241
+ FunIsafcn: declareSpec(
242
+ "FunIsafcn",
243
+ 1,
244
+ ["Mem", "FunDom", "FunFcn", "FunApp"],
245
+ [
246
+ axiom(
247
+ "FunExt",
248
+ [],
249
+ `(forall ((f Idv) (g Idv)) (! (=> (and (${FUN_ISAFCN} f) (${FUN_ISAFCN} g) (= (${FUN_DOM} f) (${FUN_DOM} g)) (forall ((x Idv)) (=> (${MEM} x (${FUN_DOM} f)) (= (${FUN_APP} f x) (${FUN_APP} g x))))) (= f g)) :pattern ((${FUN_ISAFCN} f) (${FUN_ISAFCN} g))))`,
250
+ ),
251
+ ],
252
+ "Bool",
253
+ ),
254
+ FunDom: declareSpec("FunDom", 1, ["FunFcn"], [axiom("FunDomDef", [], undefined)]),
255
+ FunApp: declareSpec("FunApp", 2, ["Mem", "FunFcn"], [axiom("FunAppDef", [], undefined)]),
256
+ // tlapm labels SeqSetElim1 and SeqSetElim2 SetSetElim1 and SetSetElim2.
257
+ Seq: declareSpec(
258
+ "Seq",
259
+ 1,
260
+ [
261
+ "Mem",
262
+ "Len",
263
+ "FunIsafcn",
264
+ "FunDom",
265
+ "FunApp",
266
+ "IntSet",
267
+ "NatSet",
268
+ "IntRange",
269
+ "Cast_Int",
270
+ "Proj_Int",
271
+ ],
272
+ [
273
+ axiom(
274
+ "SeqSetIntro",
275
+ [],
276
+ `(forall ((a Idv) (s Idv)) (! (=> (and (${FUN_ISAFCN} s) (>= (${PROJ_INT} (${LEN} s)) 0) (forall ((i Idv)) (= (${MEM} i (${FUN_DOM} s)) (and (${MEM} i ${INT_SET}) (<= 1 (${PROJ_INT} i)) (<= (${PROJ_INT} i) (${PROJ_INT} (${LEN} s)))))) (forall ((i Int)) (=> (and (<= 1 i) (<= i (${PROJ_INT} (${LEN} s)))) (${MEM} (${FUN_APP} s (${CAST_INT} i)) a)))) (${MEM} s (${SEQ} a))) :pattern ((${MEM} s (${SEQ} a)))))`,
277
+ ),
278
+ axiom(
279
+ "SeqSetElim1",
280
+ [],
281
+ `(forall ((a Idv) (s Idv)) (! (=> (${MEM} s (${SEQ} a)) (and (${FUN_ISAFCN} s) (${MEM} (${LEN} s) ${NAT_SET}) (= (${FUN_DOM} s) (${INT_RANGE} (${CAST_INT} 1) (${LEN} s))))) :pattern ((${MEM} s (${SEQ} a)))))`,
282
+ "SetSetElim1",
283
+ ),
284
+ axiom(
285
+ "SeqSetElim2",
286
+ [],
287
+ `(forall ((a Idv) (s Idv) (i Int)) (! (=> (and (${MEM} s (${SEQ} a)) (<= 1 i) (<= i (${PROJ_INT} (${LEN} s)))) (${MEM} (${FUN_APP} s (${CAST_INT} i)) a)) :pattern ((${MEM} s (${SEQ} a)) (${FUN_APP} s (${CAST_INT} i)))))`,
288
+ "SetSetElim2",
289
+ ),
290
+ ],
291
+ ),
292
+ Len: declareSpec(
293
+ "Len",
294
+ 1,
295
+ ["FunDom", "IntRange", "Cast_Int"],
296
+ [
297
+ axiom(
298
+ "SeqLenDef",
299
+ [],
300
+ `(forall ((s Idv) (z Int)) (=> (and (>= z 0) (= (${FUN_DOM} s) (${INT_RANGE} (${CAST_INT} 1) (${CAST_INT} z)))) (= (${LEN} s) (${CAST_INT} z))))`,
301
+ ),
302
+ ],
303
+ ),
304
+ BSeq: declareSpec("BSeq", 1, [], []),
305
+ Cat: declareSpec("Cat", 2, SEQUENCE_DEPS, [
306
+ axiom(
307
+ "SeqCatTyping",
308
+ [],
309
+ `(forall ((a Idv) (s Idv) (t Idv)) (! (=> (and (${MEM} s (${SEQ} a)) (${MEM} t (${SEQ} a))) (${MEM} (${CAT} s t) (${SEQ} a))) :pattern ((${MEM} s (${SEQ} a)) (${CAT} s t)) :pattern ((${MEM} t (${SEQ} a)) (${CAT} s t))))`,
310
+ ),
311
+ axiom(
312
+ "SeqCatLen",
313
+ [],
314
+ `(forall ((s Idv) (t Idv)) (! (=> (and (${MEM} (${LEN} s) ${NAT_SET}) (${MEM} (${LEN} t) ${NAT_SET})) (= (${LEN} (${CAT} s t)) (${CAST_INT} (+ (${PROJ_INT} (${LEN} s)) (${PROJ_INT} (${LEN} t)))))) :pattern ((${CAT} s t))))`,
315
+ ),
316
+ axiom(
317
+ "SeqCatApp1",
318
+ [],
319
+ `(forall ((s Idv) (t Idv) (i Int)) (! (=> (and (${MEM} (${LEN} s) ${NAT_SET}) (${MEM} (${LEN} t) ${NAT_SET}) (<= 1 i) (<= i (${PROJ_INT} (${LEN} s)))) (= (${FUN_APP} (${CAT} s t) (${CAST_INT} i)) (${FUN_APP} s (${CAST_INT} i)))) :pattern ((${FUN_APP} (${CAT} s t) (${CAST_INT} i))) :pattern ((${CAT} s t) (${FUN_APP} s (${CAST_INT} i)))))`,
320
+ ),
321
+ axiom(
322
+ "SeqCatApp2",
323
+ [],
324
+ `(forall ((s Idv) (t Idv) (i Int)) (! (=> (and (${MEM} (${LEN} s) ${NAT_SET}) (${MEM} (${LEN} t) ${NAT_SET}) (<= i (+ (${PROJ_INT} (${LEN} s)) (${PROJ_INT} (${LEN} t)))) (< (${PROJ_INT} (${LEN} s)) i)) (= (${FUN_APP} (${CAT} s t) (${CAST_INT} i)) (${FUN_APP} t (${CAST_INT} (- i (${PROJ_INT} (${LEN} s))))))) :pattern ((${FUN_APP} (${CAT} s t) (${CAST_INT} i)))))`,
325
+ ),
326
+ ]),
327
+ Append: declareSpec("Append", 2, SEQUENCE_DEPS, [
328
+ axiom(
329
+ "SeqAppendTyping",
330
+ [],
331
+ `(forall ((a Idv) (s Idv) (x Idv)) (! (=> (and (${MEM} s (${SEQ} a)) (${MEM} x a)) (${MEM} (${APPEND} s x) (${SEQ} a))) :pattern ((${MEM} s (${SEQ} a)) (${APPEND} s x))))`,
332
+ ),
333
+ axiom(
334
+ "SeqAppendLen",
335
+ [],
336
+ `(forall ((s Idv) (x Idv)) (! (=> (${MEM} (${LEN} s) ${NAT_SET}) (= (${LEN} (${APPEND} s x)) (${CAST_INT} (+ (${PROJ_INT} (${LEN} s)) 1)))) :pattern ((${APPEND} s x))))`,
337
+ ),
338
+ axiom(
339
+ "SeqAppendApp1",
340
+ [],
341
+ `(forall ((s Idv) (x Idv) (i Int)) (! (=> (and (${MEM} (${LEN} s) ${NAT_SET}) (<= 1 i) (<= i (${PROJ_INT} (${LEN} s)))) (= (${FUN_APP} (${APPEND} s x) (${CAST_INT} i)) (${FUN_APP} s (${CAST_INT} i)))) :pattern ((${FUN_APP} (${APPEND} s x) (${CAST_INT} i))) :pattern ((${APPEND} s x) (${FUN_APP} s (${CAST_INT} i)))))`,
342
+ ),
343
+ axiom(
344
+ "SeqAppendApp2",
345
+ [],
346
+ `(forall ((s Idv) (x Idv)) (! (=> (${MEM} (${LEN} s) ${NAT_SET}) (= (${FUN_APP} (${APPEND} s x) (${CAST_INT} (+ (${PROJ_INT} (${LEN} s)) 1))) x)) :pattern ((${APPEND} s x))))`,
347
+ ),
348
+ ]),
349
+ Head: declareSpec(
350
+ "Head",
351
+ 1,
352
+ ["FunApp", "Cast_Int"],
353
+ [
354
+ axiom(
355
+ "SeqHeadDef",
356
+ [],
357
+ `(forall ((s Idv)) (! (= (${HEAD} s) (${FUN_APP} s (${CAST_INT} 1))) :pattern ((${HEAD} s))))`,
358
+ ),
359
+ ],
360
+ ),
361
+ Tail: declareSpec("Tail", 1, SEQUENCE_DEPS, [
362
+ axiom(
363
+ "SeqTailTyping",
364
+ [],
365
+ `(forall ((a Idv) (s Idv)) (! (=> (and (${MEM} s (${SEQ} a)) (distinct (${PROJ_INT} (${LEN} s)) 0)) (${MEM} (${TAIL} s) (${SEQ} a))) :pattern ((${MEM} s (${SEQ} a)) (${TAIL} s))))`,
366
+ ),
367
+ axiom(
368
+ "SeqTailLen",
369
+ [],
370
+ `(forall ((s Idv)) (! (=> (and (${MEM} (${LEN} s) ${NAT_SET}) (distinct (${PROJ_INT} (${LEN} s)) 0)) (= (${LEN} (${TAIL} s)) (${CAST_INT} (- (${PROJ_INT} (${LEN} s)) 1)))) :pattern ((${TAIL} s))))`,
371
+ ),
372
+ axiom(
373
+ "SeqTailApp",
374
+ [],
375
+ `(forall ((s Idv) (i Int)) (! (=> (and (${MEM} (${LEN} s) ${NAT_SET}) (distinct (${PROJ_INT} (${LEN} s)) 0) (<= 1 i) (<= i (- (${PROJ_INT} (${LEN} s)) 1))) (= (${FUN_APP} (${TAIL} s) (${CAST_INT} i)) (${FUN_APP} s (${CAST_INT} (+ i 1))))) :pattern ((${FUN_APP} (${TAIL} s) (${CAST_INT} i)))))`,
376
+ ),
377
+ ]),
378
+ SubSeq: declareSpec(
379
+ "SubSeq",
380
+ 3,
381
+ ["Mem", "Seq", "Len", "FunApp", "IntSet", "Cast_Int", "Proj_Int"],
382
+ [
383
+ axiom(
384
+ "SeqSubseqTyping",
385
+ [],
386
+ `(forall ((a Idv) (s Idv) (x Int) (y Int)) (! (=> (or (< y x) (and (${MEM} s (${SEQ} a)) (<= 1 x) (<= y (${PROJ_INT} (${LEN} s))))) (${MEM} ${SUB_SEQ_RANGE} (${SEQ} a))) :pattern ((${MEM} s (${SEQ} a)) ${SUB_SEQ_RANGE})))`,
387
+ ),
388
+ axiom(
389
+ "SeqSubseqLen",
390
+ [],
391
+ `(forall ((s Idv) (x Int) (y Int)) (! (and (=> (<= x (+ y 1)) (= (${LEN} ${SUB_SEQ_RANGE}) (${CAST_INT} (- (+ y 1) x)))) (=> (> x (+ y 1)) (= (${LEN} ${SUB_SEQ_RANGE}) (${CAST_INT} 0)))) :pattern (${SUB_SEQ_RANGE})))`,
392
+ ),
393
+ axiom(
394
+ "SeqSubseqApp",
395
+ [],
396
+ `(forall ((s Idv) (x Int) (y Int) (z Int)) (! (=> (and (<= 1 x) (<= 1 z) (<= z (- (+ y 1) x))) (= (${FUN_APP} ${SUB_SEQ_RANGE} (${CAST_INT} z)) (${FUN_APP} s (${CAST_INT} (- (+ z x) 1))))) :pattern ((${FUN_APP} ${SUB_SEQ_RANGE} (${CAST_INT} z)))))`,
397
+ ),
398
+ ],
399
+ ),
400
+ Cast_Int: createSpec(
401
+ declare(tla("Cast_Int"), 1, "Idv", "Int"),
402
+ ["Mem", "IntSet", "Proj_Int"],
403
+ [
404
+ axiom(
405
+ "CastInjAlt",
406
+ ["Int"],
407
+ `(forall ((x Int)) (! (= x (${PROJ_INT} (${CAST_INT} x))) :pattern ((${CAST_INT} x))))`,
408
+ ),
409
+ axiom(
410
+ "TypeGuardIntro",
411
+ ["Int"],
412
+ `(forall ((z Int)) (! (${MEM} (${CAST_INT} z) ${INT_SET}) :pattern ((${CAST_INT} z))))`,
413
+ ),
414
+ axiom(
415
+ "TypeGuardElim",
416
+ ["Int"],
417
+ `(forall ((x Idv)) (! (=> (${MEM} x ${INT_SET}) (= x (${CAST_INT} (${PROJ_INT} x)))) :pattern ((${MEM} x ${INT_SET}))))`,
418
+ ),
419
+ ],
420
+ ),
421
+ Cast_Bool: createSpec(
422
+ declare(tla("Cast_Bool"), 1, "Idv", "Bool"),
423
+ ["Mem", "BoolSet", "Tt_Idv"],
424
+ [
425
+ axiom(
426
+ "CastInjAlt",
427
+ ["Bool"],
428
+ `(and (= (${CAST_BOOL} true) ${TT_IDV}) (distinct (${CAST_BOOL} false) ${TT_IDV}))`,
429
+ ),
430
+ axiom(
431
+ "TypeGuardIntro",
432
+ ["Bool"],
433
+ `(forall ((z Bool)) (! (${MEM} (${CAST_BOOL} z) ${BOOL_SET}) :pattern ((${CAST_BOOL} z))))`,
434
+ ),
435
+ axiom(
436
+ "TypeGuardElim",
437
+ ["Bool"],
438
+ `(forall ((x Idv)) (! (=> (${MEM} x ${BOOL_SET}) (or (= x (${CAST_BOOL} true)) (= x (${CAST_BOOL} false)))) :pattern ((${MEM} x ${BOOL_SET}))))`,
439
+ ),
440
+ ],
441
+ ),
442
+ Proj_Int: createSpec(declare(tla("Proj_Int"), 1, "Int"), [], []),
443
+ TrigEq_Set$Idv$: declareSpec(
444
+ "TrigEq_Set$Idv$",
445
+ 2,
446
+ ["SetExtTrigger"],
447
+ [
448
+ axiom(
449
+ "ExtTrigEqDef",
450
+ ["Set$Idv$"],
451
+ `(forall ((x Idv) (y Idv)) (! (= (${TRIG_EQ} x y) (= x y)) :pattern ((${TRIG_EQ} x y))))`,
452
+ ),
453
+ axiom(
454
+ "ExtTrigEqTrigger",
455
+ ["Idv"],
456
+ `(forall ((x Idv) (y Idv)) (! (${SET_EXT_TRIGGER} x y) :pattern ((${TRIG_EQ} x y))))`,
457
+ ),
458
+ ],
459
+ "Bool",
460
+ ),
461
+ SetExtTrigger: declareSpec("SetExtTrigger", 2, [], [], "Bool"),
462
+ IsSetOf: declareSpec("IsSetOf", 1, [], [], "Bool"),
463
+ BoolSet: declareSpec("BoolSet", 0, [], []),
464
+ StrSet: declareSpec("StrSet", 0, [], []),
465
+ IntSet: declareSpec("IntSet", 0, [], []),
466
+ Tt_Idv: declareSpec("Tt_Idv", 0, [], []),
467
+ TIntLteq: createSpec(undefined, ["IntLteq"], [getTyping("IntLteq")]),
468
+ }),
469
+ );
470
+
70
471
  export const getSymbolSpec = (name: string, state: CollectState): SymbolSpec => {
71
- const createSpec = (declaration: string | undefined, deps: string[], axioms: Axiom[]) => ({
72
- declaration,
73
- deps,
74
- axioms,
75
- });
76
472
  const symbol = tla(name);
77
- const declareSpec = (arity: number, deps: string[], axioms: Axiom[], sort = "Idv") =>
78
- createSpec(declare(symbol, arity, sort), deps, axioms);
79
473
  const enumeration = /^SetEnum_(\d+)$/.exec(name);
80
474
  if (enumeration)
81
- return declareSpec(Number(enumeration[1]), ["Mem"], getEnumeration(Number(enumeration[1])));
475
+ return declareSpec(
476
+ name,
477
+ Number(enumeration[1]),
478
+ ["Mem"],
479
+ getEnumeration(Number(enumeration[1])),
480
+ );
82
481
  const setOf = /^SetOf_(\d+)$/.exec(name);
83
482
  if (setOf) {
84
483
  const count = Number(setOf[1]);
@@ -106,6 +505,7 @@ export const getSymbolSpec = (name: string, state: CollectState): SymbolSpec =>
106
505
  );
107
506
  state.strings.push(value);
108
507
  return declareSpec(
508
+ name,
109
509
  0,
110
510
  ["Mem", "StrSet"],
111
511
  [axiom("StrLitIsstr", [value], `(${MEM} ${symbol} ${STR_SET})`), ...distinct],
@@ -119,12 +519,13 @@ export const getSymbolSpec = (name: string, state: CollectState): SymbolSpec =>
119
519
  count === 0
120
520
  ? ["FunIsafcn", "Cast_Int", "Seq", "Len"]
121
521
  : ["FunIsafcn", "FunDom", "FunApp", `SetEnum_${count}`, "Cast_Int", "Mem", "Seq", "Len"];
122
- return declareSpec(count, deps, getTupleAxioms(count, state.isExcept));
522
+ return declareSpec(name, count, deps, getTupleAxioms(count, state.isExcept));
123
523
  }
124
524
  const product = /^Product_(\d+)$/.exec(name);
125
525
  if (product) {
126
526
  const count = Number(product[1]);
127
527
  return declareSpec(
528
+ name,
128
529
  count,
129
530
  ["Mem", `Tuple_${count}`, "FunApp", "Cast_Int", "Proj_Int"],
130
531
  getComponentSet("Product", [count], symbol, tla(`Tuple_${count}`), getIntegers(count), "t"),
@@ -134,6 +535,7 @@ export const getSymbolSpec = (name: string, state: CollectState): SymbolSpec =>
134
535
  if (fields && name.startsWith("Record_")) {
135
536
  state.records.push(fields);
136
537
  return declareSpec(
538
+ name,
137
539
  fields.length,
138
540
  [
139
541
  "FunIsafcn",
@@ -148,193 +550,30 @@ export const getSymbolSpec = (name: string, state: CollectState): SymbolSpec =>
148
550
  if (fields && name.startsWith("RecordSet_")) {
149
551
  const record = `Record_${fields.join("_")}`;
150
552
  return declareSpec(
553
+ name,
151
554
  fields.length,
152
555
  ["Mem", record, "FunApp", ...fields.map((field) => `StrLit_${field}`)],
153
556
  getComponentSet("RecSet", [fields], symbol, tla(record), getFieldKeys(fields), "r"),
154
557
  );
155
558
  }
156
559
  const anonymous = state.anonymous.get(name);
157
- if (anonymous !== undefined) return declareSpec(anonymous, [], []);
560
+ if (anonymous !== undefined) return declareSpec(name, anonymous, [], []);
561
+ const known = STATIC_SPECS.get(name);
562
+ if (known) return known;
158
563
  const typed = TYPED_OPERATORS[name];
159
564
  if (typed)
160
565
  return declareSpec(
566
+ name,
161
567
  typed[1],
162
568
  ["Cast_Int"],
163
569
  [getTyping(name)],
164
570
  name === "IntLteq" ? "Bool" : "Idv",
165
571
  );
166
572
  switch (name) {
167
- case "IntExp":
168
- return declareSpec(
169
- 2,
170
- ["Mem", "IntSet", "Cast_Int", "TIntLteq", "TIntLit_0", "TIntLit_1"],
171
- [
172
- axiom(
173
- "IntExpTyping",
174
- [],
175
- `(forall ((x Idv) (y Idv)) (! (=> (and (${MEM} x ${INT_SET}) (${MEM} y ${INT_SET}) (or (distinct x (${CAST_INT} 0)) (${INT_LTEQ} (${CAST_INT} 1) y))) (${MEM} (${symbol} x y) ${INT_SET})) :pattern ((${symbol} x y))))`,
176
- ),
177
- ],
178
- );
179
- case "SelectSeq":
180
- return createSpec(
181
- undefined,
182
- [
183
- "Mem",
184
- "Seq",
185
- "Len",
186
- "Append",
187
- "FunApp",
188
- "FunDom",
189
- "IntSet",
190
- "NatSet",
191
- "Tuple_0",
192
- "Proj_Int",
193
- ],
194
- [
195
- axiom("SeqSelectseqTyping", [], undefined),
196
- axiom("SeqSelectseqLen", [], undefined),
197
- axiom("SeqSelectseqNil", [], undefined),
198
- axiom("SeqSelectseqApp", [], undefined),
199
- axiom("SeqSelectseqAppend", [], undefined),
200
- ],
201
- );
202
- case "Choose":
203
- return createSpec(undefined, [], [axiom("ChooseDef", [], undefined)]);
204
- case "Mem":
205
- return declareSpec(
206
- 2,
207
- ["SetExtTrigger"],
208
- [
209
- axiom(
210
- "SetExt",
211
- [],
212
- `(forall ((x Idv) (y Idv)) (! (=> (forall ((z Idv)) (= (${MEM} z x) (${MEM} z y))) (= x y)) :pattern ((${SET_EXT_TRIGGER} x y))))`,
213
- ),
214
- ],
215
- "Bool",
216
- );
217
- case "SubsetEq":
218
- return declareSpec(
219
- 2,
220
- ["Mem"],
221
- [
222
- axiom(
223
- "SubsetEqIntro",
224
- [],
225
- `(forall ((x Idv) (y Idv)) (! (=> (forall ((z Idv)) (=> (${MEM} z x) (${MEM} z y))) (${SUBSET_EQ} x y)) :pattern ((${SUBSET_EQ} x y))))`,
226
- ),
227
- axiom(
228
- "SubsetEqElim",
229
- [],
230
- `(forall ((x Idv) (y Idv) (z Idv)) (! (=> (and (${SUBSET_EQ} x y) (${MEM} z x)) (${MEM} z y)) :pattern ((${SUBSET_EQ} x y) (${MEM} z x))))`,
231
- ),
232
- ],
233
- "Bool",
234
- );
235
- case "Union":
236
- return declareSpec(
237
- 1,
238
- ["Mem"],
239
- [
240
- axiom(
241
- "UnionIntro",
242
- [],
243
- `(forall ((a Idv) (x Idv) (y Idv)) (! (=> (and (${MEM} y a) (${MEM} x y)) (${MEM} x (${UNION} a))) :pattern ((${MEM} y a) (${MEM} x (${UNION} a))) :pattern ((${MEM} x y) (${MEM} x (${UNION} a))) :pattern ((${MEM} y a) (${MEM} x y) (${UNION} a))))`,
244
- ),
245
- axiom(
246
- "UnionElim",
247
- [],
248
- `(forall ((a Idv) (x Idv)) (! (=> (${MEM} x (${UNION} a)) (exists ((y Idv)) (and (${MEM} y a) (${MEM} x y)))) :pattern ((${MEM} x (${UNION} a)))))`,
249
- ),
250
- ],
251
- );
252
- case "Subset":
253
- return declareSpec(
254
- 1,
255
- ["Mem", "SubsetEq"],
256
- [
257
- axiom(
258
- "SubsetDefAlt",
259
- [],
260
- `(forall ((a Idv) (x Idv)) (! (= (${MEM} x (${SUBSET} a)) (${SUBSET_EQ} x a)) :pattern ((${MEM} x (${SUBSET} a))) :pattern ((${SUBSET_EQ} x a) (${SUBSET} a))))`,
261
- ),
262
- ],
263
- );
264
- case "Cup":
265
- case "Cap":
266
- case "SetMinus": {
267
- const condition =
268
- name === "Cup"
269
- ? "(or (MEM x a) (MEM x b))"
270
- : name === "Cap"
271
- ? "(and (MEM x a) (MEM x b))"
272
- : "(and (MEM x a) (not (MEM x b)))";
273
- const definition = axiom(
274
- `${name}Def`,
275
- [],
276
- `(forall ((a Idv) (b Idv) (x Idv)) (! (= (${MEM} x (${symbol} a b)) ${condition.replaceAll("MEM", MEM)}) :pattern ((${MEM} x (${symbol} a b))) :pattern ((${MEM} x a) (${symbol} a b)) :pattern ((${MEM} x b) (${symbol} a b))))`,
277
- );
278
- if (name !== "Cap") return declareSpec(2, ["Mem"], [definition]);
279
- return declareSpec(
280
- 2,
281
- ["Mem", "SetEnum_0", "SetExtTrigger"],
282
- [
283
- definition,
284
- axiom(
285
- "DisjointTrigger",
286
- [],
287
- `(forall ((x Idv) (y Idv)) (! (${SET_EXT_TRIGGER} (${CAP} x y) ${tla("SetEnum_0")}) :pattern ((${CAP} x y))))`,
288
- ),
289
- ],
290
- );
291
- }
292
- case "SetSt":
293
- return createSpec(
294
- undefined,
295
- ["Mem", "SetEnum_0", "SetExtTrigger"],
296
- [axiom("SetStDef", [], undefined), axiom("EmptyComprehensionTrigger", [], undefined)],
297
- );
298
- case "NatSet":
299
- return declareSpec(
300
- 0,
301
- ["IntSet", "TIntLit_0", "Cast_Int", "IntLteq"],
302
- [
303
- axiom(
304
- "NatSetDef",
305
- [],
306
- `(forall ((x Idv)) (! (= (${MEM} x ${NAT_SET}) (and (${MEM} x ${INT_SET}) (${INT_LTEQ} (${CAST_INT} 0) x))) :pattern ((${MEM} x ${NAT_SET}))))`,
307
- ),
308
- ],
309
- );
310
- case "IntRange":
311
- return declareSpec(
312
- 2,
313
- ["Mem", "IntSet", "IntLteq"],
314
- [
315
- axiom(
316
- "IntRangeDef",
317
- [],
318
- `(forall ((a Idv) (b Idv) (x Idv)) (! (= (${MEM} x (${INT_RANGE} a b)) (and (${MEM} x ${INT_SET}) (${INT_LTEQ} a x) (${INT_LTEQ} x b))) :pattern ((${MEM} x (${INT_RANGE} a b)))))`,
319
- ),
320
- ],
321
- );
322
- case "FunIsafcn":
323
- return declareSpec(
324
- 1,
325
- ["Mem", "FunDom", "FunFcn", "FunApp"],
326
- [
327
- axiom(
328
- "FunExt",
329
- [],
330
- `(forall ((f Idv) (g Idv)) (! (=> (and (${FUN_ISAFCN} f) (${FUN_ISAFCN} g) (= (${FUN_DOM} f) (${FUN_DOM} g)) (forall ((x Idv)) (=> (${MEM} x (${FUN_DOM} f)) (= (${FUN_APP} f x) (${FUN_APP} g x))))) (= f g)) :pattern ((${FUN_ISAFCN} f) (${FUN_ISAFCN} g))))`,
331
- ),
332
- ],
333
- "Bool",
334
- );
335
573
  case "FunSet":
336
574
  state.isFunSet = true;
337
575
  return declareSpec(
576
+ name,
338
577
  2,
339
578
  ["Mem", "FunIsafcn", "FunDom", "FunApp"],
340
579
  [
@@ -366,14 +605,11 @@ export const getSymbolSpec = (name: string, state: CollectState): SymbolSpec =>
366
605
  ...(state.isFunSet ? [axiom("FunTyping", [], undefined)] : []),
367
606
  ],
368
607
  );
369
- case "FunDom":
370
- return declareSpec(1, ["FunFcn"], [axiom("FunDomDef", [], undefined)]);
371
- case "FunApp":
372
- return declareSpec(2, ["Mem", "FunFcn"], [axiom("FunAppDef", [], undefined)]);
373
608
  case "FunExcept": {
374
609
  state.isExcept = true;
375
610
  const updated = `(${FUN_EXCEPT} f x y)`;
376
611
  return declareSpec(
612
+ name,
377
613
  3,
378
614
  ["Mem", "FunIsafcn", "FunDom", "FunApp"],
379
615
  [
@@ -402,230 +638,6 @@ export const getSymbolSpec = (name: string, state: CollectState): SymbolSpec =>
402
638
  ],
403
639
  );
404
640
  }
405
- // tlapm labels SeqSetElim1 and SeqSetElim2 SetSetElim1 and SetSetElim2.
406
- case "Seq":
407
- return declareSpec(
408
- 1,
409
- [
410
- "Mem",
411
- "Len",
412
- "FunIsafcn",
413
- "FunDom",
414
- "FunApp",
415
- "IntSet",
416
- "NatSet",
417
- "IntRange",
418
- "Cast_Int",
419
- "Proj_Int",
420
- ],
421
- [
422
- axiom(
423
- "SeqSetIntro",
424
- [],
425
- `(forall ((a Idv) (s Idv)) (! (=> (and (${FUN_ISAFCN} s) (>= (${PROJ_INT} (${LEN} s)) 0) (forall ((i Idv)) (= (${MEM} i (${FUN_DOM} s)) (and (${MEM} i ${INT_SET}) (<= 1 (${PROJ_INT} i)) (<= (${PROJ_INT} i) (${PROJ_INT} (${LEN} s)))))) (forall ((i Int)) (=> (and (<= 1 i) (<= i (${PROJ_INT} (${LEN} s)))) (${MEM} (${FUN_APP} s (${CAST_INT} i)) a)))) (${MEM} s (${SEQ} a))) :pattern ((${MEM} s (${SEQ} a)))))`,
426
- ),
427
- axiom(
428
- "SeqSetElim1",
429
- [],
430
- `(forall ((a Idv) (s Idv)) (! (=> (${MEM} s (${SEQ} a)) (and (${FUN_ISAFCN} s) (${MEM} (${LEN} s) ${NAT_SET}) (= (${FUN_DOM} s) (${INT_RANGE} (${CAST_INT} 1) (${LEN} s))))) :pattern ((${MEM} s (${SEQ} a)))))`,
431
- "SetSetElim1",
432
- ),
433
- axiom(
434
- "SeqSetElim2",
435
- [],
436
- `(forall ((a Idv) (s Idv) (i Int)) (! (=> (and (${MEM} s (${SEQ} a)) (<= 1 i) (<= i (${PROJ_INT} (${LEN} s)))) (${MEM} (${FUN_APP} s (${CAST_INT} i)) a)) :pattern ((${MEM} s (${SEQ} a)) (${FUN_APP} s (${CAST_INT} i)))))`,
437
- "SetSetElim2",
438
- ),
439
- ],
440
- );
441
- case "Len":
442
- return declareSpec(
443
- 1,
444
- ["FunDom", "IntRange", "Cast_Int"],
445
- [
446
- axiom(
447
- "SeqLenDef",
448
- [],
449
- `(forall ((s Idv) (z Int)) (=> (and (>= z 0) (= (${FUN_DOM} s) (${INT_RANGE} (${CAST_INT} 1) (${CAST_INT} z)))) (= (${LEN} s) (${CAST_INT} z))))`,
450
- ),
451
- ],
452
- );
453
- case "BSeq":
454
- return declareSpec(1, [], []);
455
- case "Cat":
456
- return declareSpec(2, SEQUENCE_DEPS, [
457
- axiom(
458
- "SeqCatTyping",
459
- [],
460
- `(forall ((a Idv) (s Idv) (t Idv)) (! (=> (and (${MEM} s (${SEQ} a)) (${MEM} t (${SEQ} a))) (${MEM} (${CAT} s t) (${SEQ} a))) :pattern ((${MEM} s (${SEQ} a)) (${CAT} s t)) :pattern ((${MEM} t (${SEQ} a)) (${CAT} s t))))`,
461
- ),
462
- axiom(
463
- "SeqCatLen",
464
- [],
465
- `(forall ((s Idv) (t Idv)) (! (=> (and (${MEM} (${LEN} s) ${NAT_SET}) (${MEM} (${LEN} t) ${NAT_SET})) (= (${LEN} (${CAT} s t)) (${CAST_INT} (+ (${PROJ_INT} (${LEN} s)) (${PROJ_INT} (${LEN} t)))))) :pattern ((${CAT} s t))))`,
466
- ),
467
- axiom(
468
- "SeqCatApp1",
469
- [],
470
- `(forall ((s Idv) (t Idv) (i Int)) (! (=> (and (${MEM} (${LEN} s) ${NAT_SET}) (${MEM} (${LEN} t) ${NAT_SET}) (<= 1 i) (<= i (${PROJ_INT} (${LEN} s)))) (= (${FUN_APP} (${CAT} s t) (${CAST_INT} i)) (${FUN_APP} s (${CAST_INT} i)))) :pattern ((${FUN_APP} (${CAT} s t) (${CAST_INT} i))) :pattern ((${CAT} s t) (${FUN_APP} s (${CAST_INT} i)))))`,
471
- ),
472
- axiom(
473
- "SeqCatApp2",
474
- [],
475
- `(forall ((s Idv) (t Idv) (i Int)) (! (=> (and (${MEM} (${LEN} s) ${NAT_SET}) (${MEM} (${LEN} t) ${NAT_SET}) (<= i (+ (${PROJ_INT} (${LEN} s)) (${PROJ_INT} (${LEN} t)))) (< (${PROJ_INT} (${LEN} s)) i)) (= (${FUN_APP} (${CAT} s t) (${CAST_INT} i)) (${FUN_APP} t (${CAST_INT} (- i (${PROJ_INT} (${LEN} s))))))) :pattern ((${FUN_APP} (${CAT} s t) (${CAST_INT} i)))))`,
476
- ),
477
- ]);
478
- case "Append":
479
- return declareSpec(2, SEQUENCE_DEPS, [
480
- axiom(
481
- "SeqAppendTyping",
482
- [],
483
- `(forall ((a Idv) (s Idv) (x Idv)) (! (=> (and (${MEM} s (${SEQ} a)) (${MEM} x a)) (${MEM} (${APPEND} s x) (${SEQ} a))) :pattern ((${MEM} s (${SEQ} a)) (${APPEND} s x))))`,
484
- ),
485
- axiom(
486
- "SeqAppendLen",
487
- [],
488
- `(forall ((s Idv) (x Idv)) (! (=> (${MEM} (${LEN} s) ${NAT_SET}) (= (${LEN} (${APPEND} s x)) (${CAST_INT} (+ (${PROJ_INT} (${LEN} s)) 1)))) :pattern ((${APPEND} s x))))`,
489
- ),
490
- axiom(
491
- "SeqAppendApp1",
492
- [],
493
- `(forall ((s Idv) (x Idv) (i Int)) (! (=> (and (${MEM} (${LEN} s) ${NAT_SET}) (<= 1 i) (<= i (${PROJ_INT} (${LEN} s)))) (= (${FUN_APP} (${APPEND} s x) (${CAST_INT} i)) (${FUN_APP} s (${CAST_INT} i)))) :pattern ((${FUN_APP} (${APPEND} s x) (${CAST_INT} i))) :pattern ((${APPEND} s x) (${FUN_APP} s (${CAST_INT} i)))))`,
494
- ),
495
- axiom(
496
- "SeqAppendApp2",
497
- [],
498
- `(forall ((s Idv) (x Idv)) (! (=> (${MEM} (${LEN} s) ${NAT_SET}) (= (${FUN_APP} (${APPEND} s x) (${CAST_INT} (+ (${PROJ_INT} (${LEN} s)) 1))) x)) :pattern ((${APPEND} s x))))`,
499
- ),
500
- ]);
501
- case "Head":
502
- return declareSpec(
503
- 1,
504
- ["FunApp", "Cast_Int"],
505
- [
506
- axiom(
507
- "SeqHeadDef",
508
- [],
509
- `(forall ((s Idv)) (! (= (${HEAD} s) (${FUN_APP} s (${CAST_INT} 1))) :pattern ((${HEAD} s))))`,
510
- ),
511
- ],
512
- );
513
- case "Tail":
514
- return declareSpec(1, SEQUENCE_DEPS, [
515
- axiom(
516
- "SeqTailTyping",
517
- [],
518
- `(forall ((a Idv) (s Idv)) (! (=> (and (${MEM} s (${SEQ} a)) (distinct (${PROJ_INT} (${LEN} s)) 0)) (${MEM} (${TAIL} s) (${SEQ} a))) :pattern ((${MEM} s (${SEQ} a)) (${TAIL} s))))`,
519
- ),
520
- axiom(
521
- "SeqTailLen",
522
- [],
523
- `(forall ((s Idv)) (! (=> (and (${MEM} (${LEN} s) ${NAT_SET}) (distinct (${PROJ_INT} (${LEN} s)) 0)) (= (${LEN} (${TAIL} s)) (${CAST_INT} (- (${PROJ_INT} (${LEN} s)) 1)))) :pattern ((${TAIL} s))))`,
524
- ),
525
- axiom(
526
- "SeqTailApp",
527
- [],
528
- `(forall ((s Idv) (i Int)) (! (=> (and (${MEM} (${LEN} s) ${NAT_SET}) (distinct (${PROJ_INT} (${LEN} s)) 0) (<= 1 i) (<= i (- (${PROJ_INT} (${LEN} s)) 1))) (= (${FUN_APP} (${TAIL} s) (${CAST_INT} i)) (${FUN_APP} s (${CAST_INT} (+ i 1))))) :pattern ((${FUN_APP} (${TAIL} s) (${CAST_INT} i)))))`,
529
- ),
530
- ]);
531
- case "SubSeq": {
532
- const range = `(${SUB_SEQ} s (${CAST_INT} x) (${CAST_INT} y))`;
533
- return declareSpec(
534
- 3,
535
- ["Mem", "Seq", "Len", "FunApp", "IntSet", "Cast_Int", "Proj_Int"],
536
- [
537
- axiom(
538
- "SeqSubseqTyping",
539
- [],
540
- `(forall ((a Idv) (s Idv) (x Int) (y Int)) (! (=> (or (< y x) (and (${MEM} s (${SEQ} a)) (<= 1 x) (<= y (${PROJ_INT} (${LEN} s))))) (${MEM} ${range} (${SEQ} a))) :pattern ((${MEM} s (${SEQ} a)) ${range})))`,
541
- ),
542
- axiom(
543
- "SeqSubseqLen",
544
- [],
545
- `(forall ((s Idv) (x Int) (y Int)) (! (and (=> (<= x (+ y 1)) (= (${LEN} ${range}) (${CAST_INT} (- (+ y 1) x)))) (=> (> x (+ y 1)) (= (${LEN} ${range}) (${CAST_INT} 0)))) :pattern (${range})))`,
546
- ),
547
- axiom(
548
- "SeqSubseqApp",
549
- [],
550
- `(forall ((s Idv) (x Int) (y Int) (z Int)) (! (=> (and (<= 1 x) (<= 1 z) (<= z (- (+ y 1) x))) (= (${FUN_APP} ${range} (${CAST_INT} z)) (${FUN_APP} s (${CAST_INT} (- (+ z x) 1))))) :pattern ((${FUN_APP} ${range} (${CAST_INT} z)))))`,
551
- ),
552
- ],
553
- );
554
- }
555
- case "Cast_Int":
556
- return createSpec(
557
- declare(symbol, 1, "Idv", "Int"),
558
- ["Mem", "IntSet", "Proj_Int"],
559
- [
560
- axiom(
561
- "CastInjAlt",
562
- ["Int"],
563
- `(forall ((x Int)) (! (= x (${PROJ_INT} (${CAST_INT} x))) :pattern ((${CAST_INT} x))))`,
564
- ),
565
- axiom(
566
- "TypeGuardIntro",
567
- ["Int"],
568
- `(forall ((z Int)) (! (${MEM} (${CAST_INT} z) ${INT_SET}) :pattern ((${CAST_INT} z))))`,
569
- ),
570
- axiom(
571
- "TypeGuardElim",
572
- ["Int"],
573
- `(forall ((x Idv)) (! (=> (${MEM} x ${INT_SET}) (= x (${CAST_INT} (${PROJ_INT} x)))) :pattern ((${MEM} x ${INT_SET}))))`,
574
- ),
575
- ],
576
- );
577
- case "Cast_Bool":
578
- return createSpec(
579
- declare(symbol, 1, "Idv", "Bool"),
580
- ["Mem", "BoolSet", "Tt_Idv"],
581
- [
582
- axiom(
583
- "CastInjAlt",
584
- ["Bool"],
585
- `(and (= (${CAST_BOOL} true) ${TT_IDV}) (distinct (${CAST_BOOL} false) ${TT_IDV}))`,
586
- ),
587
- axiom(
588
- "TypeGuardIntro",
589
- ["Bool"],
590
- `(forall ((z Bool)) (! (${MEM} (${CAST_BOOL} z) ${BOOL_SET}) :pattern ((${CAST_BOOL} z))))`,
591
- ),
592
- axiom(
593
- "TypeGuardElim",
594
- ["Bool"],
595
- `(forall ((x Idv)) (! (=> (${MEM} x ${BOOL_SET}) (or (= x (${CAST_BOOL} true)) (= x (${CAST_BOOL} false)))) :pattern ((${MEM} x ${BOOL_SET}))))`,
596
- ),
597
- ],
598
- );
599
- case "Proj_Int":
600
- return createSpec(declare(symbol, 1, "Int"), [], []);
601
- case "TrigEq_Set$Idv$":
602
- return declareSpec(
603
- 2,
604
- ["SetExtTrigger"],
605
- [
606
- axiom(
607
- "ExtTrigEqDef",
608
- ["Set$Idv$"],
609
- `(forall ((x Idv) (y Idv)) (! (= (${TRIG_EQ} x y) (= x y)) :pattern ((${TRIG_EQ} x y))))`,
610
- ),
611
- axiom(
612
- "ExtTrigEqTrigger",
613
- ["Idv"],
614
- `(forall ((x Idv) (y Idv)) (! (${SET_EXT_TRIGGER} x y) :pattern ((${TRIG_EQ} x y))))`,
615
- ),
616
- ],
617
- "Bool",
618
- );
619
- case "SetExtTrigger":
620
- case "IsSetOf":
621
- return declareSpec(name === "IsSetOf" ? 1 : 2, [], [], "Bool");
622
- case "BoolSet":
623
- case "StrSet":
624
- case "IntSet":
625
- case "Tt_Idv":
626
- return declareSpec(0, [], []);
627
- case "TIntLteq":
628
- return createSpec(undefined, ["IntLteq"], [getTyping("IntLteq")]);
629
641
  default:
630
642
  if (name.startsWith("TIntLit_")) return createSpec(undefined, [], []);
631
643
  throw new TlaUnsupportedError(`the symbol ${name}`);