tla-ts 0.0.4-dev.6dec595 → 0.0.4-dev.7b5087a

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 (307) hide show
  1. package/README.md +27 -141
  2. package/dist/deciders.cjs +366 -0
  3. package/dist/deciders.js +366 -0
  4. package/dist/index.cjs +1 -1
  5. package/dist/index.d.cts +35 -1
  6. package/dist/index.d.ts +35 -1
  7. package/dist/index.js +1 -1
  8. package/dist/parallel-worker.cjs +1 -4
  9. package/dist/parallel-worker.js +1 -4
  10. package/dist/prove-worker.cjs +9 -0
  11. package/dist/prove-worker.d.cts +9 -0
  12. package/dist/prove-worker.d.ts +9 -0
  13. package/dist/prove-worker.js +9 -0
  14. package/dist/prove.cjs +996 -0
  15. package/dist/prove.js +996 -0
  16. package/dist/run-cli.cjs +517 -47
  17. package/dist/run-cli.js +517 -47
  18. package/dist/tlapm.cjs +10 -0
  19. package/dist/tlapm.js +10 -0
  20. package/dist/transfer.cjs +38 -44
  21. package/dist/transfer.js +38 -44
  22. package/dist/worker.cjs +21 -0
  23. package/dist/worker.js +21 -0
  24. package/package.json +21 -12
  25. package/src/errors.ts +86 -0
  26. package/src/evaluate.ts +28 -7
  27. package/src/index.ts +10 -0
  28. package/src/{obligation-action.ts → obligations/action.ts} +258 -37
  29. package/src/{obligation-anon.ts → obligations/anon.ts} +13 -7
  30. package/src/obligations/ctx.ts +64 -0
  31. package/src/{obligation-deref.ts → obligations/deref.ts} +2 -2
  32. package/src/{obligation-expression.ts → obligations/expression.ts} +54 -8
  33. package/src/{obligation-format.ts → obligations/format.ts} +6 -5
  34. package/src/{obligation-generate.ts → obligations/generate.ts} +134 -61
  35. package/src/{obligations.ts → obligations/index.ts} +28 -12
  36. package/src/{obligation-levels.ts → obligations/levels.ts} +12 -2
  37. package/src/{obligation-module.ts → obligations/module.ts} +46 -20
  38. package/src/obligations/pickle.ts +100 -0
  39. package/src/obligations/pragma.ts +189 -0
  40. package/src/{obligation-printer.ts → obligations/printer.ts} +9 -63
  41. package/src/{obligation-proof.ts → obligations/proof.ts} +7 -1
  42. package/src/{obligation-source.ts → obligations/source.ts} +91 -35
  43. package/src/obligations/temporal.ts +319 -0
  44. package/src/{obligation-tuples.ts → obligations/tuples.ts} +1 -1
  45. package/src/ocaml-marshal.ts +172 -0
  46. package/src/parallel-worker.ts +2 -18
  47. package/src/parallel.ts +10 -43
  48. package/src/prove/decide-pool.ts +100 -0
  49. package/src/prove/deciders.ts +33 -0
  50. package/src/prove/isabelle/LICENSE +36 -0
  51. package/src/prove/isabelle/LICENSE-tlapm +26 -0
  52. package/src/prove/isabelle/decide.ts +47 -0
  53. package/src/prove/isabelle/encode.ts +512 -0
  54. package/src/prove/isabelle/isar/inner-syntax.ts +579 -0
  55. package/src/prove/isabelle/isar/method.ts +367 -0
  56. package/src/prove/isabelle/isar/proof.ts +28 -0
  57. package/src/prove/isabelle/isar/statement.ts +57 -0
  58. package/src/prove/isabelle/isar/theory.ts +192 -0
  59. package/src/prove/isabelle/isar/type-check.ts +278 -0
  60. package/src/prove/isabelle/provers/blast/blast.ts +258 -0
  61. package/src/prove/isabelle/provers/blast/branch.ts +322 -0
  62. package/src/prove/isabelle/provers/blast/prove.ts +347 -0
  63. package/src/prove/isabelle/provers/blast/rules.ts +330 -0
  64. package/src/prove/isabelle/provers/blast/state.ts +180 -0
  65. package/src/prove/isabelle/provers/blast/term.ts +547 -0
  66. package/src/prove/isabelle/provers/clasimp.ts +150 -0
  67. package/src/prove/isabelle/provers/classical.ts +389 -0
  68. package/src/prove/isabelle/provers/hypsubst.ts +441 -0
  69. package/src/prove/isabelle/pure/bicompose.ts +174 -0
  70. package/src/prove/isabelle/pure/consts.ts +32 -0
  71. package/src/prove/isabelle/pure/conv.ts +79 -0
  72. package/src/prove/isabelle/pure/drule.ts +264 -0
  73. package/src/prove/isabelle/pure/envir.ts +363 -0
  74. package/src/prove/isabelle/pure/goal.ts +53 -0
  75. package/src/prove/isabelle/pure/interrupt.ts +16 -0
  76. package/src/prove/isabelle/pure/list.ts +12 -0
  77. package/src/prove/isabelle/pure/logic.ts +402 -0
  78. package/src/prove/isabelle/pure/name.ts +110 -0
  79. package/src/prove/isabelle/pure/net.ts +262 -0
  80. package/src/prove/isabelle/pure/object-logic.ts +41 -0
  81. package/src/prove/isabelle/pure/pattern.ts +650 -0
  82. package/src/prove/isabelle/pure/raw-simplifier.ts +353 -0
  83. package/src/prove/isabelle/pure/rewriter.ts +602 -0
  84. package/src/prove/isabelle/pure/search.ts +68 -0
  85. package/src/prove/isabelle/pure/seq.ts +156 -0
  86. package/src/prove/isabelle/pure/simplifier.ts +112 -0
  87. package/src/prove/isabelle/pure/table.ts +208 -0
  88. package/src/prove/isabelle/pure/tactic.ts +276 -0
  89. package/src/prove/isabelle/pure/tactical.ts +347 -0
  90. package/src/prove/isabelle/pure/term-ord.ts +159 -0
  91. package/src/prove/isabelle/pure/term.ts +808 -0
  92. package/src/prove/isabelle/pure/thm.ts +806 -0
  93. package/src/prove/isabelle/pure/type.ts +133 -0
  94. package/src/prove/isabelle/pure/unify.ts +753 -0
  95. package/src/prove/isabelle/pure/variable.ts +25 -0
  96. package/src/prove/isabelle/tla/classical-setup.ts +101 -0
  97. package/src/prove/isabelle/tla/context.ts +74 -0
  98. package/src/prove/isabelle/tla/logic-data.ts +5 -0
  99. package/src/prove/isabelle/tla/logic.ts +215 -0
  100. package/src/prove/isabelle/tla/simpdata.ts +241 -0
  101. package/src/prove/isabelle/tools/intuitionistic.ts +132 -0
  102. package/src/prove/ocaml.ts +22 -0
  103. package/src/prove/prep/action.ts +520 -0
  104. package/src/prove/prep/defs.ts +33 -0
  105. package/src/prove/prep/elab.ts +156 -0
  106. package/src/prove/prep/enabled-axioms.ts +189 -0
  107. package/src/prove/prep/enabled.ts +43 -0
  108. package/src/prove/prep/fingerprint.ts +388 -0
  109. package/src/prove/prep/flatten.ts +70 -0
  110. package/src/prove/prep/level-comparison.ts +552 -0
  111. package/src/prove/prep/md5.ts +67 -0
  112. package/src/prove/prep/pragma.ts +221 -0
  113. package/src/prove/prep/trivial.ts +22 -0
  114. package/src/prove/prove-worker.ts +27 -0
  115. package/src/prove/prove.ts +528 -0
  116. package/src/prove/ptl/decide.ts +68 -0
  117. package/src/prove/ptl/encode.ts +256 -0
  118. package/src/prove/ptl/sat.ts +151 -0
  119. package/src/prove/ptl/tableau.ts +276 -0
  120. package/src/prove/smt/axiomatize.ts +69 -0
  121. package/src/prove/smt/axioms.ts +210 -0
  122. package/src/prove/smt/context.ts +108 -0
  123. package/src/prove/smt/data.ts +665 -0
  124. package/src/prove/smt/encode.ts +169 -0
  125. package/src/prove/smt/extensionality.ts +63 -0
  126. package/src/prove/smt/flatten.ts +127 -0
  127. package/src/prove/smt/format.ts +143 -0
  128. package/src/prove/smt/instances.ts +182 -0
  129. package/src/prove/smt/rewrite.ts +784 -0
  130. package/src/prove/smt/simplify.ts +57 -0
  131. package/src/prove/smt/solver/act-cache.ts +265 -0
  132. package/src/prove/smt/solver/arith-rewriter.ts +962 -0
  133. package/src/prove/smt/solver/array.ts +22 -0
  134. package/src/prove/smt/solver/asserted-formulas.ts +469 -0
  135. package/src/prove/smt/solver/ast-lt.ts +157 -0
  136. package/src/prove/smt/solver/ast-util.ts +147 -0
  137. package/src/prove/smt/solver/ast.ts +1315 -0
  138. package/src/prove/smt/solver/auf-solver.ts +572 -0
  139. package/src/prove/smt/solver/case-split-queue.ts +178 -0
  140. package/src/prove/smt/solver/cg-table.ts +175 -0
  141. package/src/prove/smt/solver/clause.ts +276 -0
  142. package/src/prove/smt/solver/conflict-resolution.ts +343 -0
  143. package/src/prove/smt/solver/context.ts +1292 -0
  144. package/src/prove/smt/solver/ctx-simplify.ts +334 -0
  145. package/src/prove/smt/solver/der.ts +224 -0
  146. package/src/prove/smt/solver/dyn-ack.ts +141 -0
  147. package/src/prove/smt/solver/e-matching.ts +659 -0
  148. package/src/prove/smt/solver/enode.ts +259 -0
  149. package/src/prove/smt/solver/expr-ref.ts +21 -0
  150. package/src/prove/smt/solver/expr-safe-replace.ts +172 -0
  151. package/src/prove/smt/solver/fingerprints.ts +92 -0
  152. package/src/prove/smt/solver/flat-literals.ts +51 -0
  153. package/src/prove/smt/solver/goal.ts +138 -0
  154. package/src/prove/smt/solver/hash.ts +173 -0
  155. package/src/prove/smt/solver/hashtable.ts +166 -0
  156. package/src/prove/smt/solver/internalizer.ts +1381 -0
  157. package/src/prove/smt/solver/lbool.ts +5 -0
  158. package/src/prove/smt/solver/literal.ts +24 -0
  159. package/src/prove/smt/solver/lp/bound-propagator.ts +391 -0
  160. package/src/prove/smt/solver/lp/constraints.ts +78 -0
  161. package/src/prove/smt/solver/lp/containers.ts +296 -0
  162. package/src/prove/smt/solver/lp/core-solver.ts +504 -0
  163. package/src/prove/smt/solver/lp/cross-nested.ts +224 -0
  164. package/src/prove/smt/solver/lp/dep-intervals.ts +656 -0
  165. package/src/prove/smt/solver/lp/dependency.ts +51 -0
  166. package/src/prove/smt/solver/lp/dioph-eq.ts +1181 -0
  167. package/src/prove/smt/solver/lp/explanation.ts +46 -0
  168. package/src/prove/smt/solver/lp/gomory.ts +255 -0
  169. package/src/prove/smt/solver/lp/hnf-cutter.ts +125 -0
  170. package/src/prove/smt/solver/lp/hnf.ts +281 -0
  171. package/src/prove/smt/solver/lp/int-cube.ts +295 -0
  172. package/src/prove/smt/solver/lp/int-solver.ts +514 -0
  173. package/src/prove/smt/solver/lp/lar-solver.ts +816 -0
  174. package/src/prove/smt/solver/lp/lar-term.ts +62 -0
  175. package/src/prove/smt/solver/lp/lp-settings.ts +91 -0
  176. package/src/prove/smt/solver/lp/maximize-term.ts +347 -0
  177. package/src/prove/smt/solver/lp/nex-creator.ts +381 -0
  178. package/src/prove/smt/solver/lp/nex.ts +120 -0
  179. package/src/prove/smt/solver/lp/nla-backoff.ts +43 -0
  180. package/src/prove/smt/solver/lp/nla-basics.ts +398 -0
  181. package/src/prove/smt/solver/lp/nla-core.ts +968 -0
  182. package/src/prove/smt/solver/lp/nla-divisions.ts +332 -0
  183. package/src/prove/smt/solver/lp/nla-emonics.ts +373 -0
  184. package/src/prove/smt/solver/lp/nla-factorization.ts +30 -0
  185. package/src/prove/smt/solver/lp/nla-grobner.ts +904 -0
  186. package/src/prove/smt/solver/lp/nla-horner.ts +126 -0
  187. package/src/prove/smt/solver/lp/nla-intervals.ts +265 -0
  188. package/src/prove/smt/solver/lp/nla-monomial-bounds.ts +715 -0
  189. package/src/prove/smt/solver/lp/nla-monotone.ts +59 -0
  190. package/src/prove/smt/solver/lp/nla-order.ts +307 -0
  191. package/src/prove/smt/solver/lp/nla-patcher.ts +112 -0
  192. package/src/prove/smt/solver/lp/nla-tangents.ts +251 -0
  193. package/src/prove/smt/solver/lp/nla-throttle.ts +85 -0
  194. package/src/prove/smt/solver/lp/nla-types.ts +124 -0
  195. package/src/prove/smt/solver/lp/nla-var-eqs.ts +141 -0
  196. package/src/prove/smt/solver/lp/nra-solver.ts +440 -0
  197. package/src/prove/smt/solver/lp/numeric-pair.ts +65 -0
  198. package/src/prove/smt/solver/lp/pdd-interval.ts +31 -0
  199. package/src/prove/smt/solver/lp/pdd-simplifier.ts +184 -0
  200. package/src/prove/smt/solver/lp/pdd-solver.ts +408 -0
  201. package/src/prove/smt/solver/lp/pdd.ts +971 -0
  202. package/src/prove/smt/solver/lp/random-updater.ts +138 -0
  203. package/src/prove/smt/solver/lp/static-matrix.ts +246 -0
  204. package/src/prove/smt/solver/lp/union-find.ts +96 -0
  205. package/src/prove/smt/solver/mam-compiler.ts +847 -0
  206. package/src/prove/smt/solver/mam-interpreter.ts +400 -0
  207. package/src/prove/smt/solver/maximize-ac-sharing.ts +118 -0
  208. package/src/prove/smt/solver/model-checker.ts +347 -0
  209. package/src/prove/smt/solver/model-evaluator.ts +262 -0
  210. package/src/prove/smt/solver/model-finder.ts +155 -0
  211. package/src/prove/smt/solver/model-generator.ts +97 -0
  212. package/src/prove/smt/solver/model-macro-solver.ts +728 -0
  213. package/src/prove/smt/solver/nlsat/algebraic.ts +1161 -0
  214. package/src/prove/smt/solver/nlsat/atoms.ts +238 -0
  215. package/src/prove/smt/solver/nlsat/evaluator.ts +303 -0
  216. package/src/prove/smt/solver/nlsat/explain.ts +607 -0
  217. package/src/prove/smt/solver/nlsat/interval-set.ts +351 -0
  218. package/src/prove/smt/solver/nlsat/levelwise.ts +740 -0
  219. package/src/prove/smt/solver/nlsat/mpbq.ts +161 -0
  220. package/src/prove/smt/solver/nlsat/polynomial.ts +1722 -0
  221. package/src/prove/smt/solver/nlsat/solver.ts +911 -0
  222. package/src/prove/smt/solver/nlsat/types.ts +43 -0
  223. package/src/prove/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
  224. package/src/prove/smt/solver/nlsat/upolynomial.ts +996 -0
  225. package/src/prove/smt/solver/nnf.ts +469 -0
  226. package/src/prove/smt/solver/pattern-inference.ts +351 -0
  227. package/src/prove/smt/solver/poly-rewriter.ts +477 -0
  228. package/src/prove/smt/solver/propagate-values.ts +83 -0
  229. package/src/prove/smt/solver/proto-model.ts +551 -0
  230. package/src/prove/smt/solver/pull-quant.ts +139 -0
  231. package/src/prove/smt/solver/qe-lite-der.ts +526 -0
  232. package/src/prove/smt/solver/qe-lite-fm.ts +576 -0
  233. package/src/prove/smt/solver/qe-lite.ts +381 -0
  234. package/src/prove/smt/solver/qi-queue.ts +362 -0
  235. package/src/prove/smt/solver/quant-tactics.ts +117 -0
  236. package/src/prove/smt/solver/quantifier-analyzer.ts +562 -0
  237. package/src/prove/smt/solver/quantifier-manager.ts +186 -0
  238. package/src/prove/smt/solver/random-gen.ts +10 -0
  239. package/src/prove/smt/solver/rational.ts +165 -0
  240. package/src/prove/smt/solver/ref-vector.ts +62 -0
  241. package/src/prove/smt/solver/relevancy.ts +247 -0
  242. package/src/prove/smt/solver/rewriter-tpl.ts +1159 -0
  243. package/src/prove/smt/solver/rewriter.ts +843 -0
  244. package/src/prove/smt/solver/rlimit.ts +79 -0
  245. package/src/prove/smt/solver/smtlib-parser.ts +526 -0
  246. package/src/prove/smt/solver/solver.ts +71 -0
  247. package/src/prove/smt/solver/sort.ts +35 -0
  248. package/src/prove/smt/solver/sticky-generations.ts +69 -0
  249. package/src/prove/smt/solver/theory-lra-axioms.ts +340 -0
  250. package/src/prove/smt/solver/theory-lra-bounds.ts +226 -0
  251. package/src/prove/smt/solver/theory-lra-final-check.ts +252 -0
  252. package/src/prove/smt/solver/theory-lra-internalize.ts +476 -0
  253. package/src/prove/smt/solver/theory-lra-model.ts +243 -0
  254. package/src/prove/smt/solver/theory-lra-propagate.ts +405 -0
  255. package/src/prove/smt/solver/theory-lra-state.ts +43 -0
  256. package/src/prove/smt/solver/theory-lra.ts +56 -0
  257. package/src/prove/smt/solver/var-subst.ts +258 -0
  258. package/src/prove/smt/solver/z3-license.txt +10 -0
  259. package/src/prove/smt/table.ts +170 -0
  260. package/src/prove/tlapm/tlapm.ts +97 -0
  261. package/src/prove/tlaps-module.ts +510 -0
  262. package/src/prove/verdict.ts +19 -0
  263. package/src/prove/zenon/LICENSE +32 -0
  264. package/src/prove/zenon/check/check.ts +105 -0
  265. package/src/prove/zenon/check/definitions.ts +144 -0
  266. package/src/prove/zenon/check/equality.ts +182 -0
  267. package/src/prove/zenon/check/functions.ts +62 -0
  268. package/src/prove/zenon/check/keys.ts +125 -0
  269. package/src/prove/zenon/check/propositional.ts +104 -0
  270. package/src/prove/zenon/check/records.ts +188 -0
  271. package/src/prove/zenon/check/relations.ts +121 -0
  272. package/src/prove/zenon/check/rewrites.ts +224 -0
  273. package/src/prove/zenon/check/sets.ts +302 -0
  274. package/src/prove/zenon/check/terms.ts +127 -0
  275. package/src/prove/zenon/check/tla.ts +126 -0
  276. package/src/prove/zenon/decide.ts +113 -0
  277. package/src/prove/zenon/encode.ts +444 -0
  278. package/src/prove/zenon/eqrel.ts +300 -0
  279. package/src/prove/zenon/equality-rules.ts +435 -0
  280. package/src/prove/zenon/expr.ts +551 -0
  281. package/src/prove/zenon/index-table.ts +350 -0
  282. package/src/prove/zenon/isar-case.ts +513 -0
  283. package/src/prove/zenon/isar.ts +1249 -0
  284. package/src/prove/zenon/limits.ts +15 -0
  285. package/src/prove/zenon/llproof.ts +173 -0
  286. package/src/prove/zenon/mltoll.ts +1566 -0
  287. package/src/prove/zenon/node.ts +297 -0
  288. package/src/prove/zenon/ocaml.ts +169 -0
  289. package/src/prove/zenon/parse.ts +247 -0
  290. package/src/prove/zenon/phrase.ts +191 -0
  291. package/src/prove/zenon/proof.ts +198 -0
  292. package/src/prove/zenon/propositional-rules.ts +387 -0
  293. package/src/prove/zenon/rules.ts +94 -0
  294. package/src/prove/zenon/search.ts +288 -0
  295. package/src/prove/zenon/tla/functions.ts +151 -0
  296. package/src/prove/zenon/tla/llproof.ts +480 -0
  297. package/src/prove/zenon/tla/records.ts +225 -0
  298. package/src/prove/zenon/tla/rewrites.ts +447 -0
  299. package/src/prove/zenon/tla/sets.ts +304 -0
  300. package/src/prove/zenon/tla/terms.ts +181 -0
  301. package/src/prove/zenon/tla/tla.ts +506 -0
  302. package/src/run-cli.ts +338 -52
  303. package/src/tlapm-cache.ts +250 -0
  304. package/src/values.ts +8 -3
  305. package/src/worker.ts +65 -0
  306. package/dist/parallel.cjs +0 -12
  307. package/dist/parallel.js +0 -12
@@ -14,8 +14,8 @@ import type {
14
14
  SourceLocation,
15
15
  SourceRange,
16
16
  UseOrHide,
17
- } from "./ast";
18
- import { TlaProofError, TlaUnsupportedError } from "./errors";
17
+ } from "../ast";
18
+ import { TlaProofError, TlaUnsupportedError } from "../errors";
19
19
  import {
20
20
  at,
21
21
  type Bound,
@@ -27,8 +27,9 @@ import {
27
27
  type Locus,
28
28
  type Selector,
29
29
  type Sequent,
30
- } from "./obligation-expression";
31
- import type { ModuleUnit, Mule } from "./obligation-module";
30
+ } from "./expression";
31
+ import type { ModuleUnit, Mule } from "./module";
32
+ import { readNewMethod, readOldMethod } from "./pragma";
32
33
  import {
33
34
  expandChoose,
34
35
  expandFcn,
@@ -37,8 +38,8 @@ import {
37
38
  expandSetSt,
38
39
  getUnbounded,
39
40
  type TuplyBound,
40
- } from "./obligation-tuples";
41
- import { lookupOperator, type Fixity, type Operator } from "./obligation-printer";
41
+ } from "./tuples";
42
+ import { lookupOperator, type Fixity, type Operator } from "./printer";
42
43
  import {
43
44
  getUnique,
44
45
  type Counter,
@@ -47,7 +48,7 @@ import {
47
48
  type StepNumber,
48
49
  type UseDef,
49
50
  type Usable,
50
- } from "./obligation-proof";
51
+ } from "./proof";
51
52
 
52
53
  const BUILTINS: Record<string, Builtin> = {
53
54
  "=>": "Implies",
@@ -231,6 +232,22 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
231
232
  return locus;
232
233
  };
233
234
 
235
+ const getMethod = (range: SourceRange | undefined) =>
236
+ range && readOldMethod(lines, { line: range.end.line - 1, column: range.end.column });
237
+
238
+ // A method pragma belongs to the node it follows, whose locus then takes it in.
239
+ const withMethod = (range: SourceRange) => {
240
+ const method = getMethod(range);
241
+ const location = getRangeLocus(range);
242
+ return method ? { location: withPragma(location), method } : { location };
243
+ };
244
+
245
+ // Module.Parser's with_meth, which wraps the expression a method follows.
246
+ const withExpressionMethod = (expression: Expr, range: SourceRange | undefined): Expr => {
247
+ const method = getMethod(range);
248
+ return method ? at({ kind: "With", expression, method }, expression) : expression;
249
+ };
250
+
234
251
  const getNameLocus = (name: string, location: SourceLocation): Locus => ({
235
252
  file,
236
253
  startLine: location.line,
@@ -376,8 +393,14 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
376
393
  const [integer, fraction] = expression.text.split(".");
377
394
  return at({ kind: "Num", integer, fraction }, { location });
378
395
  }
379
- case "String":
380
- return at({ kind: "String", value: expression.value }, { location });
396
+ case "String": {
397
+ // tlapm's lexer keeps a string's escapes as written. The location ends at the closing
398
+ // quote.
399
+ const written = /"((?:[^"\\]|\\.)*)"$/.exec(
400
+ (lines[location.endLine - 1] ?? "").slice(0, location.endColumn - 1),
401
+ );
402
+ return at({ kind: "String", value: written?.[1] ?? expression.value }, { location });
403
+ }
381
404
  case "Identifier":
382
405
  return getName(expression.name, [], location);
383
406
  case "Apply": {
@@ -768,24 +791,26 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
768
791
  location,
769
792
  };
770
793
  }
771
- if (definition.params.length === 0) return { kind: "Operator", name, body, location };
772
- return {
773
- kind: "Operator",
774
- name,
775
- body: at(
776
- {
777
- kind: "Lambda",
778
- params: definition.params.map((param) => ({
779
- name: getCanonicalName(param.name),
780
- shape: param.arity,
781
- ...(param.location && { location: getNameLocus(param.name, param.location) }),
782
- })),
783
- body,
784
- },
785
- { location },
786
- ),
787
- location,
788
- };
794
+ const operatorBody =
795
+ definition.params.length === 0
796
+ ? body
797
+ : at(
798
+ {
799
+ kind: "Lambda",
800
+ params: definition.params.map((param) => ({
801
+ name: getCanonicalName(param.name),
802
+ shape: param.arity,
803
+ ...(param.location && { location: getNameLocus(param.name, param.location) }),
804
+ })),
805
+ body,
806
+ },
807
+ { location },
808
+ );
809
+ const end = definition.location.range?.end;
810
+ const methods = end && readNewMethod(lines, { line: end.line - 1, column: end.column });
811
+ return methods
812
+ ? { kind: "Bpragma", name, body: operatorBody, methods, location }
813
+ : { kind: "Operator", name, body: operatorBody, location };
789
814
  };
790
815
 
791
816
  const convertNewSymbol = (symbol: NewSymbol): Hyp => {
@@ -802,6 +827,7 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
802
827
  };
803
828
  };
804
829
 
830
+ // Anonymization judges the time of each assumption once it resolves the names in it.
805
831
  const convertSequent = (statement: Expression | AssumeProve): Sequent => {
806
832
  if (statement.kind !== "AssumeProve")
807
833
  return { context: [], active: convertExpression(statement, false) };
@@ -814,11 +840,18 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
814
840
  kind: "Fact",
815
841
  expression: at({ kind: "Sequent", sequent: convertSequent(assumption) }, { location }),
816
842
  visibility: "Visible",
843
+ time: "Now",
817
844
  location,
818
845
  };
819
846
  }
820
847
  const expression = convertFactLabel(assumption);
821
- return { kind: "Fact", expression, visibility: "Visible", location: expression.location };
848
+ return {
849
+ kind: "Fact",
850
+ expression,
851
+ visibility: "Visible",
852
+ time: "Now",
853
+ location: expression.location,
854
+ };
822
855
  }),
823
856
  active: convertExpression(statement.conclusion, false),
824
857
  };
@@ -880,7 +913,7 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
880
913
  if (!proof) return { kind: "Omitted", omission: "Implicit", location: enclosing };
881
914
  switch (proof.kind) {
882
915
  case "Obvious":
883
- return { kind: "Obvious", location: withPragma(getRangeLocus(proof.keyword)) };
916
+ return { kind: "Obvious", ...withMethod(proof.keyword) };
884
917
  case "Omitted":
885
918
  return {
886
919
  kind: "Omitted",
@@ -894,6 +927,7 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
894
927
  isOnly: proof.isOnly,
895
928
  location: getRangeLocus(proof.keyword),
896
929
  step: { kind: "Unnamed", level, id: 0 },
930
+ method: getMethod(proof.location.range),
897
931
  };
898
932
  case "Steps": {
899
933
  // A <*> first step takes the enclosing level only after PROOF, and the top level
@@ -937,6 +971,11 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
937
971
  return { ...make(proof), location: mergeLoci(head, proof.location), step: number };
938
972
  };
939
973
  const plain = (converted: Step): Step => ({ ...converted, location: head, step: number });
974
+ const withStepMethod = (converted: Step): Step => ({
975
+ ...converted,
976
+ ...withMethod(step.head),
977
+ step: number,
978
+ });
940
979
  switch (body.kind) {
941
980
  case "Use":
942
981
  case "Hide": {
@@ -946,7 +985,14 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
946
985
  );
947
986
  const usable = convertUsable(body);
948
987
  return body.kind === "Use"
949
- ? { kind: "Use", usable, isOnly: body.isOnly, location, step: number }
988
+ ? {
989
+ kind: "Use",
990
+ usable,
991
+ isOnly: body.isOnly,
992
+ location,
993
+ step: number,
994
+ method: getMethod(body.location.range),
995
+ }
950
996
  : { kind: "Hide", usable, location, step: number };
951
997
  }
952
998
  case "Instance":
@@ -957,15 +1003,18 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
957
1003
  definitions: body.definitions.map((definition) => convertDefinition(definition)),
958
1004
  });
959
1005
  case "Have":
960
- return plain({ kind: "Have", expression: convertExpression(body.expression, false) });
1006
+ return withStepMethod({
1007
+ kind: "Have",
1008
+ expression: convertExpression(body.expression, false),
1009
+ });
961
1010
  case "Take":
962
- return plain({
1011
+ return withStepMethod({
963
1012
  kind: "Take",
964
1013
  bounds:
965
1014
  body.names.length > 0 ? getUnbounded(body.names) : convertBounds(body.bounds, false),
966
1015
  });
967
1016
  case "Witness":
968
- return plain({
1017
+ return withStepMethod({
969
1018
  kind: "Witness",
970
1019
  expressions: body.expressions.map((expression) => convertExpression(expression, false)),
971
1020
  });
@@ -1048,17 +1097,24 @@ export const createSource = (file: string, text: string, counter: Counter, isExp
1048
1097
  return {
1049
1098
  kind: "Axiom",
1050
1099
  name: unit.assumption.name,
1051
- expression: convertExpression(unit.assumption.expression, false),
1100
+ expression: withExpressionMethod(
1101
+ convertExpression(unit.assumption.expression, false),
1102
+ unit.assumption.location.range,
1103
+ ),
1052
1104
  location: getLocus(unit.assumption.location),
1053
1105
  };
1054
1106
  case "Theorem": {
1055
1107
  const theorem = unit.theorem;
1056
1108
  const location = getLocus(theorem.location);
1057
1109
  const end = withPragma(location);
1110
+ const sequent = convertSequent(theorem.statement);
1058
1111
  return {
1059
1112
  kind: "Theorem",
1060
1113
  name: theorem.name,
1061
- sequent: convertSequent(theorem.statement),
1114
+ sequent: {
1115
+ ...sequent,
1116
+ active: withExpressionMethod(sequent.active, theorem.statement.location.range),
1117
+ },
1062
1118
  axiomCount: 0,
1063
1119
  proof: convertProof(theorem.proof, 0, {
1064
1120
  ...end,
@@ -0,0 +1,319 @@
1
+ // tlapm's expansions of temporal operators (Expr.Tla_norm), constant detection (Expr.Constness), and
2
+ // the time of a fact (Expr.Temporal_props): a fact holds always when it is closed under [].
3
+
4
+ import {
5
+ adjoin,
6
+ applyBuiltin,
7
+ at,
8
+ getFresh,
9
+ getScopeAt,
10
+ mapChildren,
11
+ type Builtin,
12
+ type Expr,
13
+ type Hyp,
14
+ type Scope,
15
+ type Time,
16
+ } from "./expression";
17
+
18
+ const isApplied = (expression: Expr, builtins: Builtin[]) =>
19
+ expression.kind === "Apply" &&
20
+ expression.operator.kind === "Internal" &&
21
+ builtins.includes(expression.operator.builtin);
22
+
23
+ const unchanged = (expression: Expr) => applyBuiltin("UNCHANGED", [expression], expression);
24
+
25
+ // Each visitor rewrites the outermost match and leaves the rest of the tree as it is.
26
+ const rewrite =
27
+ (match: (expression: Expr, recurse: (inner: Expr) => Expr) => Expr | undefined) =>
28
+ (expression: Expr): Expr => {
29
+ const recurse = rewrite(match);
30
+ return match(expression, recurse) ?? mapChildren(expression, recurse);
31
+ };
32
+
33
+ export const expandLeadsto = rewrite((expression, recurse) =>
34
+ expression.kind === "Apply" && isApplied(expression, ["Leadsto"])
35
+ ? applyBuiltin(
36
+ "BoxTrue",
37
+ [
38
+ applyBuiltin(
39
+ "Implies",
40
+ [
41
+ recurse(expression.args[0]),
42
+ applyBuiltin("Diamond", [recurse(expression.args[1])], expression),
43
+ ],
44
+ expression,
45
+ ),
46
+ ],
47
+ expression,
48
+ )
49
+ : undefined,
50
+ );
51
+
52
+ export const expandFairness = rewrite((expression) => {
53
+ if (expression.kind !== "Fair") return undefined;
54
+ const action = expression.action;
55
+ const subscript = expression.subscript;
56
+ const enabled = applyBuiltin(
57
+ "ENABLED",
58
+ [at({ kind: "Sub", modal: "Dia", action, subscript }, action)],
59
+ action,
60
+ );
61
+ const outer = expression.fairness === "Weak" ? "Diamond" : "BoxTrue";
62
+ const inner = expression.fairness === "Weak" ? "BoxTrue" : "Diamond";
63
+ return applyBuiltin(
64
+ "Implies",
65
+ [
66
+ applyBuiltin(outer, [applyBuiltin(inner, [enabled], action)], action),
67
+ applyBuiltin(
68
+ "BoxTrue",
69
+ [at({ kind: "Tsub", modal: "Dia", action, subscript }, action)],
70
+ action,
71
+ ),
72
+ ],
73
+ action,
74
+ );
75
+ });
76
+
77
+ export const expandAction = rewrite((expression, recurse) => {
78
+ if (expression.kind !== "Sub" && expression.kind !== "Tsub") return undefined;
79
+ const action = recurse(expression.action);
80
+ const subscript = recurse(expression.subscript);
81
+ const step =
82
+ expression.modal === "Box"
83
+ ? applyBuiltin("Disj", [action, unchanged(subscript)], expression)
84
+ : applyBuiltin(
85
+ "Conj",
86
+ [action, applyBuiltin("Neg", [unchanged(subscript)], expression)],
87
+ expression,
88
+ );
89
+ if (expression.kind === "Sub") return step;
90
+ return applyBuiltin(expression.modal === "Box" ? "BoxTrue" : "Diamond", [step], expression);
91
+ });
92
+
93
+ const flattenTuple = (expression: Expr): Expr[] =>
94
+ expression.kind === "Tuple" ? expression.elements.flatMap(flattenTuple) : [expression];
95
+
96
+ const expandUnchanged = rewrite((expression) => {
97
+ if (expression.kind !== "Apply" || !isApplied(expression, ["UNCHANGED"])) return undefined;
98
+ const equalities = flattenTuple(expression.args[0]).map((element) =>
99
+ applyBuiltin("Eq", [applyBuiltin("Prime", [element], element), element], element),
100
+ );
101
+ if (equalities.length === 0) return at({ kind: "Internal", builtin: "TRUE" }, expression);
102
+ if (equalities.length === 1) return equalities[0];
103
+ return at({ kind: "List", bullet: "And", items: equalities }, expression);
104
+ });
105
+
106
+ const TEMPORAL_BUILTINS: Builtin[] = [
107
+ "Prime",
108
+ "StrongPrime",
109
+ "Leadsto",
110
+ "ENABLED",
111
+ "UNCHANGED",
112
+ "Cdot",
113
+ "Actplus",
114
+ "BoxTrue",
115
+ "BoxFalse",
116
+ "Diamond",
117
+ ];
118
+
119
+ const constantBodies = new WeakMap<Expr, boolean>();
120
+
121
+ const isConstantHyp = (scope: Scope | undefined, hyp: Hyp) => {
122
+ switch (hyp.kind) {
123
+ case "Fresh":
124
+ return hyp.level === "Constant";
125
+ case "Defn":
126
+ return hyp.definition.kind === "Operator" && isConstant(scope, hyp.definition.body);
127
+ case "Fact":
128
+ return isConstant(scope, hyp.expression);
129
+ case "Flex":
130
+ return false;
131
+ }
132
+ };
133
+
134
+ const isConstantBound = (scope: Scope | undefined, names: string[]) =>
135
+ names.reduce<Scope | undefined>(
136
+ (inner, name) => adjoin(inner, getFresh(name, "Constant")),
137
+ scope,
138
+ );
139
+
140
+ export const isConstant = (scope: Scope | undefined, expression: Expr): boolean => {
141
+ const recurse = (inner: Expr) => isConstant(scope, inner);
142
+ switch (expression.kind) {
143
+ case "Ix": {
144
+ const found = getScopeAt(scope, expression.index - 1);
145
+ const hyp = found?.hyp;
146
+ if (hyp?.kind === "Fresh") return hyp.level === "Constant";
147
+ if (hyp?.kind !== "Defn" || hyp.definition.kind !== "Operator" || hyp.isConstnessUnset)
148
+ return false;
149
+ const body = hyp.definition.body;
150
+ const cached = constantBodies.get(body);
151
+ if (cached !== undefined) return cached;
152
+ const result = isConstant(found?.rest, body);
153
+ constantBodies.set(body, result);
154
+ return result;
155
+ }
156
+ case "Opaque":
157
+ case "String":
158
+ case "Num":
159
+ case "At":
160
+ return true;
161
+ case "Internal":
162
+ return !TEMPORAL_BUILTINS.includes(expression.builtin);
163
+ case "Tquant":
164
+ case "Sub":
165
+ case "Tsub":
166
+ case "Fair":
167
+ return false;
168
+ case "Lambda":
169
+ return isConstant(
170
+ isConstantBound(
171
+ scope,
172
+ expression.params.map((param) => param.name),
173
+ ),
174
+ expression.body,
175
+ );
176
+ case "Sequent": {
177
+ const inner = expression.sequent.context.reduce<{
178
+ scope: Scope | undefined;
179
+ isGood: boolean;
180
+ }>(
181
+ (state, hyp) => ({
182
+ scope: adjoin(state.scope, hyp),
183
+ isGood: state.isGood && isConstantHyp(state.scope, hyp),
184
+ }),
185
+ { scope, isGood: true },
186
+ );
187
+ return inner.isGood && isConstant(inner.scope, expression.sequent.active);
188
+ }
189
+ case "Bang":
190
+ case "With":
191
+ case "Dot":
192
+ case "Parens":
193
+ return recurse(expression.expression);
194
+ case "Apply":
195
+ return recurse(expression.operator) && expression.args.every(recurse);
196
+ case "Let": {
197
+ const inner = expression.definitions.reduce<{ scope: Scope | undefined; isGood: boolean }>(
198
+ (state, definition) => ({
199
+ scope: adjoin(state.scope, {
200
+ kind: "Defn",
201
+ definition,
202
+ whereDefined: "User",
203
+ visibility: "Visible",
204
+ isLocal: true,
205
+ }),
206
+ isGood:
207
+ state.isGood &&
208
+ definition.kind === "Operator" &&
209
+ isConstant(state.scope, definition.body),
210
+ }),
211
+ { scope, isGood: true },
212
+ );
213
+ return inner.isGood && isConstant(inner.scope, expression.body);
214
+ }
215
+ case "Quant":
216
+ case "Fcn":
217
+ case "SetOf": {
218
+ const body = expression.kind === "SetOf" ? expression.element : expression.body;
219
+ return (
220
+ expression.bounds.every(
221
+ (bound) => bound.domain.kind !== "Domain" || recurse(bound.domain.expression),
222
+ ) &&
223
+ isConstant(
224
+ isConstantBound(
225
+ scope,
226
+ expression.bounds.map((bound) => bound.name),
227
+ ),
228
+ body,
229
+ )
230
+ );
231
+ }
232
+ case "Choose":
233
+ case "SetSt":
234
+ return (
235
+ (expression.domain === undefined || recurse(expression.domain)) &&
236
+ isConstant(isConstantBound(scope, [expression.name]), expression.body)
237
+ );
238
+ case "If":
239
+ return (
240
+ recurse(expression.condition) &&
241
+ recurse(expression.consequent) &&
242
+ recurse(expression.alternative)
243
+ );
244
+ case "List":
245
+ return expression.items.every(recurse);
246
+ case "Tuple":
247
+ case "SetEnum":
248
+ return expression.elements.every(recurse);
249
+ case "Product":
250
+ return expression.factors.every(recurse);
251
+ case "FcnApp":
252
+ return recurse(expression.function) && expression.args.every(recurse);
253
+ case "Rect":
254
+ case "Record":
255
+ return expression.fields.every((field) => recurse(field.value));
256
+ case "Arrow":
257
+ return recurse(expression.domain) && recurse(expression.range);
258
+ case "Except":
259
+ return (
260
+ recurse(expression.function) &&
261
+ expression.specs.every(
262
+ (spec) =>
263
+ spec.trail.every((point) => point.kind === "Dot" || recurse(point.expression)) &&
264
+ recurse(spec.value),
265
+ )
266
+ );
267
+ case "Case":
268
+ return (
269
+ expression.arms.every((arm) => recurse(arm.condition) && recurse(arm.body)) &&
270
+ (expression.other === undefined || recurse(expression.other))
271
+ );
272
+ }
273
+ };
274
+
275
+ // Temporal_props.box_closure: whether the formula is equivalent to [] of itself, judged by its
276
+ // shape. Under a negation or on the left of =>, <> takes the place of [].
277
+ const isClosed = (scope: Scope | undefined, expression: Expr, isBox: boolean): boolean => {
278
+ if (isConstant(scope, expression)) return true;
279
+ if (expression.kind === "Internal")
280
+ return ["Eq", "Neq", "UNCHANGED", "TRUE", "FALSE"].includes(expression.builtin);
281
+ if (expression.kind === "List")
282
+ return expression.items.every((item) => isClosed(scope, item, isBox));
283
+ if (expression.kind === "Sequent") {
284
+ const inner = expression.sequent.context.reduce<Scope | undefined>(adjoin, scope);
285
+ return isClosed(inner, expression.sequent.active, isBox);
286
+ }
287
+ if (expression.kind !== "Apply") return false;
288
+ const args = expression.args;
289
+ if (isApplied(expression, ["BoxTrue", "BoxFalse"]) && isBox) return true;
290
+ if (isApplied(expression, ["Diamond"]) && !isBox) return true;
291
+ if (args.length === 1 && isApplied(expression, ["BoxTrue", "BoxFalse", "Diamond", "Prime"]))
292
+ return isClosed(scope, args[0], isBox);
293
+ if (args.length === 1 && isApplied(expression, ["Neg"])) return isClosed(scope, args[0], !isBox);
294
+ if (args.length === 2 && isApplied(expression, ["Conj", "Disj"]))
295
+ return isClosed(scope, args[0], isBox) && isClosed(scope, args[1], isBox);
296
+ if (args.length === 2 && isApplied(expression, ["Implies"]))
297
+ return isClosed(scope, args[0], !isBox) && isClosed(scope, args[1], isBox);
298
+ if (args.length === 2 && isApplied(expression, ["Equiv"]))
299
+ return [true, false].every(
300
+ (isFlipped) =>
301
+ isClosed(scope, args[0], isBox !== isFlipped) &&
302
+ isClosed(scope, args[1], isBox === isFlipped),
303
+ );
304
+ return (
305
+ isClosed(scope, expression.operator, isBox) && args.every((arg) => isClosed(scope, arg, isBox))
306
+ );
307
+ };
308
+
309
+ export const getTime = (scope: Scope | undefined, expression: Expr): Time =>
310
+ isClosed(scope, expandLeadsto(expandFairness(expandAction(expandUnchanged(expression)))), true)
311
+ ? "Always"
312
+ : "Now";
313
+
314
+ // Temporal_props.check_time_change: a proof stays in the always scope while no fact it assumes
315
+ // holds only now.
316
+ export const getScopeTime = (context: Hyp[], time: Time): Time =>
317
+ time === "Always" && context.some((hyp) => hyp.kind === "Fact" && hyp.time === "Now")
318
+ ? "Now"
319
+ : time;
@@ -1,6 +1,6 @@
1
1
  // tlapm's E_tuply_declarations: declarations such as <<x, y>> \in S become declarations of names.
2
2
 
3
- import type { Bound, BoundDomain, Defn, Expr } from "./obligation-expression";
3
+ import type { Bound, BoundDomain, Defn, Expr } from "./expression";
4
4
 
5
5
  export type TuplyBound =
6
6
  | { kind: "Name"; name: string; domain: BoundDomain }