tla-ts 0.0.4-dev.0be9567 → 0.0.4-dev.22c041b

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 (378) hide show
  1. package/README.md +77 -122
  2. package/dist/cli.cjs +1 -1
  3. package/dist/cli.js +1 -1
  4. package/dist/deciders.cjs +366 -0
  5. package/dist/deciders.js +366 -0
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +44 -12
  8. package/dist/index.d.ts +44 -12
  9. package/dist/index.js +1 -1
  10. package/dist/parallel-worker.cjs +1 -4
  11. package/dist/parallel-worker.js +1 -4
  12. package/dist/prove-worker.cjs +9 -0
  13. package/dist/prove-worker.d.cts +9 -0
  14. package/dist/prove-worker.d.ts +9 -0
  15. package/dist/prove-worker.js +9 -0
  16. package/dist/prove.cjs +1006 -0
  17. package/dist/prove.js +1006 -0
  18. package/dist/run.cjs +45 -0
  19. package/dist/run.js +45 -0
  20. package/dist/tlapm.cjs +10 -0
  21. package/dist/tlapm.js +10 -0
  22. package/dist/transfer.cjs +76 -92
  23. package/dist/transfer.js +76 -92
  24. package/dist/worker.cjs +21 -0
  25. package/dist/worker.js +21 -0
  26. package/package.json +21 -12
  27. package/src/ast.ts +2 -2
  28. package/src/bags.ts +22 -23
  29. package/src/builtins.ts +16 -8
  30. package/src/check.ts +131 -1153
  31. package/src/{cli-options.ts → cli/options.ts} +54 -9
  32. package/src/cli/run.ts +63 -0
  33. package/src/cli/shared.ts +106 -0
  34. package/src/cli/tlapm.ts +374 -0
  35. package/src/{run-cli.ts → cli/tlc.ts} +115 -721
  36. package/src/cli/xml-exporter.ts +221 -0
  37. package/src/cli.ts +1 -1
  38. package/src/codegen.ts +17 -15
  39. package/src/config.ts +5 -5
  40. package/src/dependencies.ts +4 -6
  41. package/src/environment.ts +55 -60
  42. package/src/errors.ts +97 -35
  43. package/src/evaluate.ts +135 -120
  44. package/src/exit-codes.ts +1 -1
  45. package/src/fingerprints.ts +3 -3
  46. package/src/index.ts +10 -0
  47. package/src/instances.ts +56 -46
  48. package/src/java-overrides.ts +79 -41
  49. package/src/json.ts +31 -36
  50. package/src/levels.ts +10 -13
  51. package/src/{live-check.ts → liveness-checker.ts} +169 -142
  52. package/src/liveness.ts +38 -34
  53. package/src/{obligation-action.ts → obligations/action.ts} +248 -74
  54. package/src/{obligation-anon.ts → obligations/anonymize.ts} +55 -57
  55. package/src/obligations/equality.ts +260 -0
  56. package/src/obligations/expression.ts +618 -0
  57. package/src/{obligation-format.ts → obligations/format.ts} +7 -8
  58. package/src/obligations/generate.ts +457 -0
  59. package/src/{obligations.ts → obligations/index.ts} +46 -32
  60. package/src/{obligation-levels.ts → obligations/levels.ts} +44 -40
  61. package/src/obligations/module.ts +445 -0
  62. package/src/obligations/normalize.ts +554 -0
  63. package/src/obligations/operators.ts +176 -0
  64. package/src/obligations/pragma.ts +195 -0
  65. package/src/{obligation-printer.ts → obligations/printer.ts} +65 -230
  66. package/src/{obligation-proof.ts → obligations/proof.ts} +7 -2
  67. package/src/obligations/regroup.ts +100 -0
  68. package/src/{obligation-generate.ts → obligations/simplify.ts} +130 -536
  69. package/src/{obligation-source.ts → obligations/source.ts} +172 -216
  70. package/src/{obligation-deref.ts → obligations/subexpression.ts} +84 -115
  71. package/src/obligations/substitution.ts +261 -0
  72. package/src/obligations/temporal.ts +321 -0
  73. package/src/{obligation-tuples.ts → obligations/tuples.ts} +38 -54
  74. package/src/parallel-worker.ts +39 -51
  75. package/src/parallel.ts +39 -66
  76. package/src/parser.ts +67 -74
  77. package/src/{pcal-ast.ts → pcal/ast.ts} +2 -17
  78. package/src/{pcal-parse.ts → pcal/parse.ts} +28 -64
  79. package/src/{pcal-tokenize.ts → pcal/tokenize.ts} +10 -39
  80. package/src/{pcal-translate.ts → pcal/translate.ts} +30 -109
  81. package/src/{pcal-validate.ts → pcal/validate.ts} +10 -20
  82. package/src/prover/decide-pool.ts +95 -0
  83. package/src/prover/deciders.ts +33 -0
  84. package/src/prover/first-order.ts +175 -0
  85. package/src/prover/isabelle/LICENSE +36 -0
  86. package/src/prover/isabelle/LICENSE-tlapm +26 -0
  87. package/src/prover/isabelle/decide.ts +44 -0
  88. package/src/prover/isabelle/encode.ts +445 -0
  89. package/src/prover/isabelle/isar/inner-syntax.ts +579 -0
  90. package/src/prover/isabelle/isar/method.ts +367 -0
  91. package/src/prover/isabelle/isar/proof.ts +28 -0
  92. package/src/prover/isabelle/isar/statement.ts +57 -0
  93. package/src/prover/isabelle/isar/theory.ts +192 -0
  94. package/src/prover/isabelle/isar/type-check.ts +278 -0
  95. package/src/prover/isabelle/provers/blast/blast.ts +258 -0
  96. package/src/prover/isabelle/provers/blast/branch.ts +322 -0
  97. package/src/prover/isabelle/provers/blast/prove.ts +347 -0
  98. package/src/prover/isabelle/provers/blast/rules.ts +330 -0
  99. package/src/prover/isabelle/provers/blast/state.ts +180 -0
  100. package/src/prover/isabelle/provers/blast/term.ts +546 -0
  101. package/src/prover/isabelle/provers/clasimp.ts +150 -0
  102. package/src/prover/isabelle/provers/classical.ts +389 -0
  103. package/src/prover/isabelle/provers/hypsubst.ts +433 -0
  104. package/src/prover/isabelle/pure/bicompose.ts +174 -0
  105. package/src/prover/isabelle/pure/consts.ts +32 -0
  106. package/src/prover/isabelle/pure/conv.ts +79 -0
  107. package/src/prover/isabelle/pure/drule.ts +264 -0
  108. package/src/prover/isabelle/pure/envir.ts +331 -0
  109. package/src/prover/isabelle/pure/goal.ts +53 -0
  110. package/src/prover/isabelle/pure/interrupt.ts +16 -0
  111. package/src/prover/isabelle/pure/list.ts +12 -0
  112. package/src/prover/isabelle/pure/logic.ts +330 -0
  113. package/src/prover/isabelle/pure/name.ts +98 -0
  114. package/src/prover/isabelle/pure/net.ts +215 -0
  115. package/src/prover/isabelle/pure/object-logic.ts +41 -0
  116. package/src/prover/isabelle/pure/pattern.ts +631 -0
  117. package/src/prover/isabelle/pure/raw-simplifier.ts +338 -0
  118. package/src/prover/isabelle/pure/rewriter.ts +602 -0
  119. package/src/prover/isabelle/pure/search.ts +68 -0
  120. package/src/prover/isabelle/pure/seq.ts +133 -0
  121. package/src/prover/isabelle/pure/simplifier.ts +106 -0
  122. package/src/prover/isabelle/pure/table.ts +201 -0
  123. package/src/prover/isabelle/pure/tactic.ts +168 -0
  124. package/src/prover/isabelle/pure/tactical.ts +264 -0
  125. package/src/prover/isabelle/pure/term-ord.ts +105 -0
  126. package/src/prover/isabelle/pure/term.ts +688 -0
  127. package/src/prover/isabelle/pure/thm.ts +783 -0
  128. package/src/prover/isabelle/pure/type.ts +121 -0
  129. package/src/prover/isabelle/pure/unify.ts +753 -0
  130. package/src/prover/isabelle/pure/variable.ts +25 -0
  131. package/src/prover/isabelle/tla/classical-setup.ts +101 -0
  132. package/src/prover/isabelle/tla/context.ts +74 -0
  133. package/src/prover/isabelle/tla/logic-data.ts +5 -0
  134. package/src/prover/isabelle/tla/logic.ts +215 -0
  135. package/src/prover/isabelle/tla/simpdata.ts +241 -0
  136. package/src/prover/isabelle/tools/intuitionistic.ts +132 -0
  137. package/src/prover/ocaml.ts +22 -0
  138. package/src/prover/prep/action.ts +508 -0
  139. package/src/prover/prep/enabled-axioms.ts +189 -0
  140. package/src/prover/prep/fingerprint.ts +388 -0
  141. package/src/prover/prep/level-comparison.ts +529 -0
  142. package/src/prover/prep/md5.ts +60 -0
  143. package/src/prover/prep/methods.ts +221 -0
  144. package/src/prover/prep/normalize.ts +309 -0
  145. package/src/prover/prove-worker.ts +22 -0
  146. package/src/prover/prove.ts +492 -0
  147. package/src/prover/ptl/decide.ts +68 -0
  148. package/src/prover/ptl/encode.ts +244 -0
  149. package/src/prover/ptl/sat.ts +151 -0
  150. package/src/prover/ptl/tableau.ts +276 -0
  151. package/src/prover/smt/axioms.ts +209 -0
  152. package/src/prover/smt/context.ts +108 -0
  153. package/src/prover/smt/data.ts +636 -0
  154. package/src/prover/smt/encode.ts +275 -0
  155. package/src/prover/smt/extensionality.ts +65 -0
  156. package/src/prover/smt/flatten.ts +112 -0
  157. package/src/prover/smt/format.ts +154 -0
  158. package/src/prover/smt/instances.ts +181 -0
  159. package/src/prover/smt/rewrite.ts +766 -0
  160. package/src/prover/smt/solver/act-cache.ts +265 -0
  161. package/src/prover/smt/solver/arith-rewriter.ts +962 -0
  162. package/src/prover/smt/solver/array.ts +22 -0
  163. package/src/prover/smt/solver/asserted-formulas.ts +469 -0
  164. package/src/prover/smt/solver/ast-lt.ts +157 -0
  165. package/src/prover/smt/solver/ast-util.ts +91 -0
  166. package/src/prover/smt/solver/ast.ts +1315 -0
  167. package/src/prover/smt/solver/auf-solver.ts +572 -0
  168. package/src/prover/smt/solver/case-split-queue.ts +178 -0
  169. package/src/prover/smt/solver/cg-table.ts +175 -0
  170. package/src/prover/smt/solver/clause.ts +276 -0
  171. package/src/prover/smt/solver/conflict-resolution.ts +343 -0
  172. package/src/prover/smt/solver/context.ts +1292 -0
  173. package/src/prover/smt/solver/ctx-simplify.ts +334 -0
  174. package/src/prover/smt/solver/der.ts +224 -0
  175. package/src/prover/smt/solver/dyn-ack.ts +141 -0
  176. package/src/prover/smt/solver/e-matching.ts +659 -0
  177. package/src/prover/smt/solver/enode.ts +259 -0
  178. package/src/prover/smt/solver/expr-ref.ts +21 -0
  179. package/src/prover/smt/solver/expr-safe-replace.ts +172 -0
  180. package/src/prover/smt/solver/fingerprints.ts +92 -0
  181. package/src/prover/smt/solver/flat-literals.ts +51 -0
  182. package/src/prover/smt/solver/goal.ts +138 -0
  183. package/src/prover/smt/solver/hash.ts +173 -0
  184. package/src/prover/smt/solver/hashtable.ts +166 -0
  185. package/src/prover/smt/solver/internalizer.ts +1381 -0
  186. package/src/prover/smt/solver/lbool.ts +5 -0
  187. package/src/prover/smt/solver/literal.ts +24 -0
  188. package/src/prover/smt/solver/lp/bound-propagator.ts +391 -0
  189. package/src/prover/smt/solver/lp/constraints.ts +78 -0
  190. package/src/prover/smt/solver/lp/containers.ts +296 -0
  191. package/src/prover/smt/solver/lp/core-solver.ts +504 -0
  192. package/src/prover/smt/solver/lp/cross-nested.ts +224 -0
  193. package/src/prover/smt/solver/lp/dep-intervals.ts +642 -0
  194. package/src/prover/smt/solver/lp/dependency.ts +51 -0
  195. package/src/prover/smt/solver/lp/dioph-eq.ts +1181 -0
  196. package/src/prover/smt/solver/lp/explanation.ts +46 -0
  197. package/src/prover/smt/solver/lp/gomory.ts +255 -0
  198. package/src/prover/smt/solver/lp/hnf-cutter.ts +125 -0
  199. package/src/prover/smt/solver/lp/hnf.ts +281 -0
  200. package/src/prover/smt/solver/lp/int-cube.ts +295 -0
  201. package/src/prover/smt/solver/lp/int-solver.ts +514 -0
  202. package/src/prover/smt/solver/lp/lar-solver.ts +816 -0
  203. package/src/prover/smt/solver/lp/lar-term.ts +62 -0
  204. package/src/prover/smt/solver/lp/lp-settings.ts +91 -0
  205. package/src/prover/smt/solver/lp/maximize-term.ts +347 -0
  206. package/src/prover/smt/solver/lp/nex-creator.ts +381 -0
  207. package/src/prover/smt/solver/lp/nex.ts +120 -0
  208. package/src/prover/smt/solver/lp/nla-backoff.ts +43 -0
  209. package/src/prover/smt/solver/lp/nla-basics.ts +398 -0
  210. package/src/prover/smt/solver/lp/nla-core.ts +968 -0
  211. package/src/prover/smt/solver/lp/nla-divisions.ts +332 -0
  212. package/src/prover/smt/solver/lp/nla-emonics.ts +373 -0
  213. package/src/prover/smt/solver/lp/nla-factorization.ts +30 -0
  214. package/src/prover/smt/solver/lp/nla-grobner.ts +904 -0
  215. package/src/prover/smt/solver/lp/nla-horner.ts +126 -0
  216. package/src/prover/smt/solver/lp/nla-intervals.ts +265 -0
  217. package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +715 -0
  218. package/src/prover/smt/solver/lp/nla-monotone.ts +59 -0
  219. package/src/prover/smt/solver/lp/nla-order.ts +307 -0
  220. package/src/prover/smt/solver/lp/nla-patcher.ts +112 -0
  221. package/src/prover/smt/solver/lp/nla-tangents.ts +251 -0
  222. package/src/prover/smt/solver/lp/nla-throttle.ts +85 -0
  223. package/src/prover/smt/solver/lp/nla-types.ts +124 -0
  224. package/src/prover/smt/solver/lp/nla-var-eqs.ts +141 -0
  225. package/src/prover/smt/solver/lp/nra-solver.ts +440 -0
  226. package/src/prover/smt/solver/lp/numeric-pair.ts +65 -0
  227. package/src/prover/smt/solver/lp/pdd-interval.ts +31 -0
  228. package/src/prover/smt/solver/lp/pdd-simplifier.ts +184 -0
  229. package/src/prover/smt/solver/lp/pdd-solver.ts +408 -0
  230. package/src/prover/smt/solver/lp/pdd.ts +971 -0
  231. package/src/prover/smt/solver/lp/random-updater.ts +138 -0
  232. package/src/prover/smt/solver/lp/static-matrix.ts +246 -0
  233. package/src/prover/smt/solver/lp/union-find.ts +96 -0
  234. package/src/prover/smt/solver/mam-compiler.ts +847 -0
  235. package/src/prover/smt/solver/mam-interpreter.ts +400 -0
  236. package/src/prover/smt/solver/maximize-ac-sharing.ts +118 -0
  237. package/src/prover/smt/solver/model-checker.ts +347 -0
  238. package/src/prover/smt/solver/model-evaluator.ts +262 -0
  239. package/src/prover/smt/solver/model-finder.ts +155 -0
  240. package/src/prover/smt/solver/model-generator.ts +97 -0
  241. package/src/prover/smt/solver/model-macro-solver.ts +728 -0
  242. package/src/prover/smt/solver/nlsat/algebraic.ts +1161 -0
  243. package/src/prover/smt/solver/nlsat/atoms.ts +238 -0
  244. package/src/prover/smt/solver/nlsat/evaluator.ts +303 -0
  245. package/src/prover/smt/solver/nlsat/explain.ts +607 -0
  246. package/src/prover/smt/solver/nlsat/interval-set.ts +351 -0
  247. package/src/prover/smt/solver/nlsat/levelwise.ts +737 -0
  248. package/src/prover/smt/solver/nlsat/mpbq.ts +161 -0
  249. package/src/prover/smt/solver/nlsat/polynomial.ts +1722 -0
  250. package/src/prover/smt/solver/nlsat/solver.ts +911 -0
  251. package/src/prover/smt/solver/nlsat/types.ts +43 -0
  252. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
  253. package/src/prover/smt/solver/nlsat/upolynomial.ts +996 -0
  254. package/src/prover/smt/solver/nnf.ts +469 -0
  255. package/src/prover/smt/solver/pattern-inference.ts +351 -0
  256. package/src/prover/smt/solver/poly-rewriter.ts +477 -0
  257. package/src/prover/smt/solver/propagate-values.ts +83 -0
  258. package/src/prover/smt/solver/proto-model.ts +551 -0
  259. package/src/prover/smt/solver/pull-quant.ts +139 -0
  260. package/src/prover/smt/solver/qe-lite-der.ts +526 -0
  261. package/src/prover/smt/solver/qe-lite-fm.ts +576 -0
  262. package/src/prover/smt/solver/qe-lite.ts +381 -0
  263. package/src/prover/smt/solver/qi-queue.ts +362 -0
  264. package/src/prover/smt/solver/quant-tactics.ts +117 -0
  265. package/src/prover/smt/solver/quantifier-analyzer.ts +562 -0
  266. package/src/prover/smt/solver/quantifier-manager.ts +186 -0
  267. package/src/prover/smt/solver/random-gen.ts +10 -0
  268. package/src/prover/smt/solver/rational.ts +165 -0
  269. package/src/prover/smt/solver/ref-vector.ts +62 -0
  270. package/src/prover/smt/solver/relevancy.ts +247 -0
  271. package/src/prover/smt/solver/rewriter-tpl.ts +1159 -0
  272. package/src/prover/smt/solver/rewriter.ts +843 -0
  273. package/src/prover/smt/solver/rlimit.ts +79 -0
  274. package/src/prover/smt/solver/smtlib-parser.ts +526 -0
  275. package/src/prover/smt/solver/solver.ts +71 -0
  276. package/src/prover/smt/solver/sort.ts +35 -0
  277. package/src/prover/smt/solver/sticky-generations.ts +69 -0
  278. package/src/prover/smt/solver/theory-lra-axioms.ts +340 -0
  279. package/src/prover/smt/solver/theory-lra-bounds.ts +226 -0
  280. package/src/prover/smt/solver/theory-lra-final-check.ts +252 -0
  281. package/src/prover/smt/solver/theory-lra-internalize.ts +476 -0
  282. package/src/prover/smt/solver/theory-lra-model.ts +243 -0
  283. package/src/prover/smt/solver/theory-lra-propagate.ts +405 -0
  284. package/src/prover/smt/solver/theory-lra-state.ts +43 -0
  285. package/src/prover/smt/solver/theory-lra.ts +56 -0
  286. package/src/prover/smt/solver/var-subst.ts +258 -0
  287. package/src/prover/smt/solver/z3-license.txt +10 -0
  288. package/src/prover/smt/table.ts +170 -0
  289. package/src/prover/tlapm/cache.ts +236 -0
  290. package/src/prover/tlapm/ocaml-marshal.ts +166 -0
  291. package/src/prover/tlapm/tlapm.ts +96 -0
  292. package/src/prover/tlaps-module.ts +510 -0
  293. package/src/prover/verdict.ts +13 -0
  294. package/src/prover/zenon/LICENSE +32 -0
  295. package/src/prover/zenon/check/check.ts +105 -0
  296. package/src/prover/zenon/check/definitions.ts +144 -0
  297. package/src/prover/zenon/check/equality.ts +182 -0
  298. package/src/prover/zenon/check/functions.ts +62 -0
  299. package/src/prover/zenon/check/keys.ts +125 -0
  300. package/src/prover/zenon/check/propositional.ts +104 -0
  301. package/src/prover/zenon/check/records.ts +188 -0
  302. package/src/prover/zenon/check/relations.ts +121 -0
  303. package/src/prover/zenon/check/rewrites.ts +224 -0
  304. package/src/prover/zenon/check/sets.ts +302 -0
  305. package/src/prover/zenon/check/terms.ts +127 -0
  306. package/src/prover/zenon/check/tla.ts +126 -0
  307. package/src/prover/zenon/decide.ts +107 -0
  308. package/src/prover/zenon/encode.ts +378 -0
  309. package/src/prover/zenon/eqrel.ts +300 -0
  310. package/src/prover/zenon/equality-rules.ts +435 -0
  311. package/src/prover/zenon/expr.ts +551 -0
  312. package/src/prover/zenon/index-table.ts +350 -0
  313. package/src/prover/zenon/isar-case.ts +513 -0
  314. package/src/prover/zenon/isar.ts +1249 -0
  315. package/src/prover/zenon/limits.ts +15 -0
  316. package/src/prover/zenon/llproof.ts +173 -0
  317. package/src/prover/zenon/mltoll.ts +1566 -0
  318. package/src/prover/zenon/node.ts +297 -0
  319. package/src/prover/zenon/ocaml.ts +169 -0
  320. package/src/prover/zenon/parse.ts +247 -0
  321. package/src/prover/zenon/phrase.ts +191 -0
  322. package/src/prover/zenon/proof.ts +198 -0
  323. package/src/prover/zenon/propositional-rules.ts +387 -0
  324. package/src/prover/zenon/rules.ts +94 -0
  325. package/src/prover/zenon/search.ts +288 -0
  326. package/src/prover/zenon/tla/functions.ts +151 -0
  327. package/src/prover/zenon/tla/llproof.ts +480 -0
  328. package/src/prover/zenon/tla/records.ts +225 -0
  329. package/src/prover/zenon/tla/rewrites.ts +447 -0
  330. package/src/prover/zenon/tla/sets.ts +304 -0
  331. package/src/prover/zenon/tla/terms.ts +162 -0
  332. package/src/prover/zenon/tla/tla.ts +506 -0
  333. package/src/randomization.ts +19 -24
  334. package/src/resolve.ts +15 -22
  335. package/src/runtime.ts +8 -8
  336. package/src/{sany-builtins.ts → sany/builtins.ts} +1 -1
  337. package/src/{sany-generator.ts → sany/generator.ts} +38 -55
  338. package/src/{sany-levels.ts → sany/levels.ts} +45 -48
  339. package/src/{sany-lexer.ts → sany/lexer.ts} +2 -3
  340. package/src/{sany-linter.ts → sany/linter.ts} +1 -1
  341. package/src/{sany-modules.ts → sany/modules.ts} +2 -2
  342. package/src/{sany-nodes.ts → sany/nodes.ts} +2 -2
  343. package/src/{sany-parse-error.ts → sany/parse-error.ts} +2 -2
  344. package/src/{sany-report.ts → sany/report.ts} +16 -17
  345. package/src/{sany-selectors.ts → sany/selectors.ts} +3 -5
  346. package/src/{sany-source.ts → sany/source.ts} +6 -7
  347. package/src/{sany-xml.ts → sany/xml.ts} +5 -6
  348. package/src/search.ts +969 -0
  349. package/src/spec-description.ts +26 -20
  350. package/src/{standard-levels.ts → standard-definitions.ts} +118 -2
  351. package/src/standard-modules.ts +16 -20
  352. package/src/state-graph.ts +9 -8
  353. package/src/substitution-levels.ts +2 -2
  354. package/src/successors.ts +38 -22
  355. package/src/symmetry.ts +1 -1
  356. package/src/tableau.ts +6 -7
  357. package/src/tlc/fingerprint.ts +214 -0
  358. package/src/{tlc-messages.ts → tlc/messages.ts} +119 -7
  359. package/src/{tlc-order.ts → tlc/order.ts} +7 -7
  360. package/src/{tlc-random.ts → tlc/random.ts} +3 -190
  361. package/src/{tlc-replay.ts → tlc/replay.ts} +40 -36
  362. package/src/{tlc-module.ts → tlc/tlc-operators.ts} +9 -9
  363. package/src/{tlc-ext.ts → tlc/tlcext-operators.ts} +30 -25
  364. package/src/{tlc-version.ts → tlc/version.ts} +8 -7
  365. package/src/transfer.ts +32 -32
  366. package/src/values.ts +119 -71
  367. package/src/worker.ts +62 -0
  368. package/dist/parallel.cjs +0 -12
  369. package/dist/parallel.js +0 -12
  370. package/dist/run-cli.cjs +0 -55
  371. package/dist/run-cli.js +0 -55
  372. package/src/canonical.ts +0 -40
  373. package/src/obligation-expression.ts +0 -1060
  374. package/src/obligation-module.ts +0 -1042
  375. package/src/standard-ranges.ts +0 -116
  376. package/src/value-sources.ts +0 -29
  377. /package/src/{tlc-modules.ts → tlc/jar-data.ts} +0 -0
  378. /package/src/{tlc-summary.ts → tlc/summary.ts} +0 -0
@@ -0,0 +1,367 @@
1
+ // Ported from Isabelle2025's Pure/Isar/method.ML (method syntax, combinators, SIMPLE_METHOD,
2
+ // finish), the assume_rule_tac and norm_hhf_tac of Pure/goal.ML, and the methods the theories
3
+ // tlapm writes use: auto, force and clarsimp (Provers/clasimp.ML), blast (Provers/blast.ML),
4
+ // iprover (Tools/intuitionistic.ML) and intro. Copyright (c) 1986-2025 University of Cambridge,
5
+ // Technische Universitaet Muenchen, and contributors, see LICENSE.
6
+
7
+ import { TlaIsabelleError } from "../../../errors";
8
+ import { asmRl, isNormHhf, normHhfEq, reflexiveThm, termI } from "../pure/drule";
9
+ import { isEquals, stripImpPrems, stripAssumsConcl } from "../pure/logic";
10
+ import { addSimps, emptySimpset, type Simpset } from "../pure/raw-simplifier";
11
+ import { genericRewriteGoalTac } from "../pure/rewriter";
12
+ import { filterSeq, mapsSeq, singleSeq, type Seq } from "../pure/seq";
13
+ import { atomizePremsTac } from "../pure/object-logic";
14
+ import { normHhf } from "../pure/simplifier";
15
+ import type { Limits } from "../pure/interrupt";
16
+ import { assumeTac, eresolveTac, flexflexTac, matchTac, resolveTac } from "../pure/tactic";
17
+ import {
18
+ allGoals,
19
+ appendGoal,
20
+ changedProp,
21
+ noTac,
22
+ orElse,
23
+ repeatAllNew,
24
+ subgoal,
25
+ thenAllNew,
26
+ thenGoal,
27
+ thenTac,
28
+ type GoalTactic,
29
+ type Tactic,
30
+ } from "../pure/tactical";
31
+ import {
32
+ addFreeNames,
33
+ maxidxOfTerm,
34
+ mkVar,
35
+ stripAllBody,
36
+ stripAllVars,
37
+ substBounds,
38
+ type Term,
39
+ } from "../pure/term";
40
+ import { nprems, trivial, type Thm } from "../pure/thm";
41
+ import { variantList } from "../pure/name";
42
+ import { autoTac, clarsimpTac, forceTac, type ClasimpContext } from "../provers/clasimp";
43
+ import {
44
+ addUnsafeDest,
45
+ addUnsafeIntro,
46
+ withClaset,
47
+ type ClassicalContext,
48
+ } from "../provers/classical";
49
+ import { proverTac, type IntuitionisticContext } from "../tools/intuitionistic";
50
+ import { insertTac } from "./proof";
51
+ import type { OuterToken } from "./theory";
52
+
53
+ interface Modifier {
54
+ readonly kind: "intro" | "dest";
55
+ readonly facts: readonly string[];
56
+ }
57
+
58
+ type MethodText =
59
+ | {
60
+ readonly kind: "auto" | "blast" | "force" | "clarsimp";
61
+ readonly modifiers: readonly Modifier[];
62
+ }
63
+ | { readonly kind: "iprover" }
64
+ | { readonly kind: "intro"; readonly facts: readonly string[] }
65
+ | { readonly kind: "then"; readonly methods: readonly MethodText[] }
66
+ | { readonly kind: "try"; readonly method: MethodText };
67
+
68
+ // The methods of by: the initial one, and the terminal one that qed runs.
69
+ interface ProofText {
70
+ readonly initial: MethodText;
71
+ readonly terminal: MethodText | undefined;
72
+ }
73
+
74
+ // What a proof method reads from the Isabelle proof context.
75
+ export interface ProofContext {
76
+ readonly limits: Limits;
77
+ readonly simpset: Simpset;
78
+ readonly classical: ClassicalContext;
79
+ readonly intuitionistic: IntuitionisticContext;
80
+ readonly atomizeRules: readonly Thm[];
81
+ readonly blastDepthTac: (context: ClassicalContext, limit: number) => GoalTactic;
82
+ readonly blastTac: (context: ClassicalContext) => GoalTactic;
83
+ readonly getFact: (name: string) => readonly Thm[];
84
+ }
85
+
86
+ const syntaxError = (token: OuterToken | undefined) =>
87
+ new TlaIsabelleError(
88
+ "ERROR",
89
+ `Outer syntax error at: ${token === undefined ? "end of input" : token.text}`,
90
+ );
91
+
92
+ // Method.parse for the proof methods of by.
93
+ export const parseProofText = (tokens: readonly OuterToken[]): ProofText => {
94
+ let position = 0;
95
+ const peek = () => tokens[position];
96
+ const isSymbol = (symbol: string, offset = 0) =>
97
+ tokens[position + offset]?.kind === "symbol" && tokens[position + offset].text === symbol;
98
+ const expectSymbol = (symbol: string) => {
99
+ if (!isSymbol(symbol)) throw syntaxError(peek());
100
+ position += 1;
101
+ };
102
+ const isWord = () => peek()?.kind === "word";
103
+ const word = () => {
104
+ const token = peek();
105
+ if (token?.kind !== "word") throw syntaxError(token);
106
+ position += 1;
107
+ return token.text;
108
+ };
109
+ const isSectionStart = () => isWord() && isSymbol(":", 1);
110
+ const facts = () => {
111
+ const names: string[] = [];
112
+ while (isWord() && !isSectionStart()) names.push(word());
113
+ return names;
114
+ };
115
+ const modifiers = (): Modifier[] => {
116
+ const result: Modifier[] = [];
117
+ while (isSectionStart()) {
118
+ const kind = word();
119
+ position += 1;
120
+ if (kind !== "intro" && kind !== "dest")
121
+ throw new TlaIsabelleError("ERROR", `Unsupported method modifier: ${kind}`);
122
+ result.push({ kind, facts: facts() });
123
+ }
124
+ return result;
125
+ };
126
+ const method = (name: string, hasArgs: boolean): MethodText => {
127
+ switch (name) {
128
+ case "auto":
129
+ case "blast":
130
+ case "force":
131
+ case "clarsimp":
132
+ return { kind: name, modifiers: hasArgs ? modifiers() : [] };
133
+ case "iprover":
134
+ return { kind: "iprover" };
135
+ case "intro":
136
+ return { kind: "intro", facts: hasArgs ? facts() : [] };
137
+ default:
138
+ throw new TlaIsabelleError("ERROR", `Undefined method: ${name}`);
139
+ }
140
+ };
141
+ const suffixed = (text: MethodText): MethodText => {
142
+ if (!isSymbol("?")) return text;
143
+ position += 1;
144
+ return suffixed({ kind: "try", method: text });
145
+ };
146
+ const parenthesized = (): MethodText => {
147
+ expectSymbol("(");
148
+ const elements = [suffixed(isSymbol("(") ? parenthesized() : method(word(), true))];
149
+ while (isSymbol(",")) {
150
+ position += 1;
151
+ elements.push(suffixed(isSymbol("(") ? parenthesized() : method(word(), true)));
152
+ }
153
+ expectSymbol(")");
154
+ return elements.length === 1 ? elements[0] : { kind: "then", methods: elements };
155
+ };
156
+ const atom = () => suffixed(isSymbol("(") ? parenthesized() : method(word(), false));
157
+ const initial = atom();
158
+ const terminal = position < tokens.length ? atom() : undefined;
159
+ if (position !== tokens.length) throw syntaxError(peek());
160
+ return { initial, terminal };
161
+ };
162
+
163
+ const getFacts = (context: ProofContext, names: readonly string[]) =>
164
+ names.flatMap((name) => context.getFact(name));
165
+
166
+ // Method.sections: the claset the modifiers declare.
167
+ const withModifiers = (context: ProofContext, modifiers: readonly Modifier[]): ClassicalContext =>
168
+ modifiers.reduce(
169
+ (classical, modifier) =>
170
+ getFacts(context, modifier.facts).reduce(
171
+ (current, fact) =>
172
+ withClaset(
173
+ current,
174
+ modifier.kind === "intro"
175
+ ? addUnsafeIntro(current, fact)
176
+ : addUnsafeDest(current, fact),
177
+ ),
178
+ classical,
179
+ ),
180
+ context.classical,
181
+ );
182
+
183
+ const getClasimp = (context: ProofContext, classical: ClassicalContext): ClasimpContext => ({
184
+ classical,
185
+ simp: { limits: context.limits, simpset: context.simpset, bounds: 0 },
186
+ blastDepthTac: context.blastDepthTac,
187
+ });
188
+
189
+ const insertAllTac = (context: ProofContext, facts: readonly Thm[]) =>
190
+ allGoals((index) => insertTac(context.limits, facts, index));
191
+
192
+ // SIMPLE_METHOD'
193
+ const simpleMethodHead = (context: ProofContext, facts: readonly Thm[], tactic: GoalTactic) =>
194
+ thenGoal((index) => insertTac(context.limits, facts, index), tactic)(1);
195
+
196
+ type Method = (facts: readonly Thm[]) => Tactic;
197
+
198
+ const evaluate = (context: ProofContext, text: MethodText): Method => {
199
+ switch (text.kind) {
200
+ case "auto":
201
+ return (facts) =>
202
+ thenTac(
203
+ insertAllTac(context, facts),
204
+ changedProp(autoTac(getClasimp(context, withModifiers(context, text.modifiers)))),
205
+ );
206
+ case "clarsimp":
207
+ return (facts) =>
208
+ simpleMethodHead(context, facts, (index) =>
209
+ changedProp(
210
+ clarsimpTac(getClasimp(context, withModifiers(context, text.modifiers)))(index),
211
+ ),
212
+ );
213
+ case "force":
214
+ return (facts) =>
215
+ simpleMethodHead(
216
+ context,
217
+ facts,
218
+ forceTac(
219
+ getClasimp(context, withModifiers(context, text.modifiers)),
220
+ context.atomizeRules,
221
+ ),
222
+ );
223
+ case "blast":
224
+ return (facts) =>
225
+ simpleMethodHead(context, facts, context.blastTac(withModifiers(context, text.modifiers)));
226
+ case "iprover":
227
+ return (facts) =>
228
+ simpleMethodHead(
229
+ context,
230
+ facts,
231
+ thenGoal(
232
+ atomizePremsTac(context.limits, context.atomizeRules),
233
+ proverTac(context.intuitionistic),
234
+ ),
235
+ );
236
+ case "intro":
237
+ return (facts) => {
238
+ const rules = getFacts(context, text.facts);
239
+ return simpleMethodHead(context, facts, (index) =>
240
+ changedProp(repeatAllNew(matchTac(context.limits, rules))(index)),
241
+ );
242
+ };
243
+ case "then": {
244
+ const methods = text.methods.map((method) => evaluate(context, method));
245
+ return (facts) => (state) =>
246
+ methods.reduce<Seq<Thm>>(
247
+ (results, method) => mapsSeq(method(facts), results),
248
+ singleSeq(state),
249
+ );
250
+ }
251
+ case "try": {
252
+ const method = evaluate(context, text.method);
253
+ return (facts) => orElse(method(facts), (state) => singleSeq(state));
254
+ }
255
+ }
256
+ };
257
+
258
+ // Goal.norm_hhf_tac
259
+ const normHhfTac = (limits: Limits): GoalTactic => {
260
+ const empty = { limits, simpset: emptySimpset, bounds: 0 };
261
+ const context = { ...empty, simpset: addSimps(empty, [normHhfEq]) };
262
+ return thenGoal(
263
+ resolveTac(limits, [asmRl]),
264
+ subgoal((goal, index) =>
265
+ isNormHhf(false, goal)
266
+ ? (state) => singleSeq(state)
267
+ : genericRewriteGoalTac(
268
+ { simprem: true, useprem: false, mutsimp: false },
269
+ () => undefined,
270
+ context,
271
+ index,
272
+ ),
273
+ ),
274
+ );
275
+ };
276
+
277
+ // Goal.assume_rule_tac: solves a goal with one of its non-atomic premises.
278
+ const assumeRuleTac = (limits: Limits): GoalTactic =>
279
+ thenGoal(
280
+ normHhfTac(limits),
281
+ subgoal((goal, index) => {
282
+ // Variable.focus_cterm and Variable.export: the parameters become schematic variables.
283
+ const params = stripAllVars(goal);
284
+ const names = variantList(
285
+ addFreeNames(goal, []),
286
+ params.map((param) => param.name),
287
+ );
288
+ const maxidx = maxidxOfTerm(goal) + 1;
289
+ const body = substBounds(
290
+ params.map((param, offset) => mkVar(names[offset], maxidx, param.type)).reverse(),
291
+ stripAllBody(goal),
292
+ );
293
+ const rules = stripImpPrems(body).filter(
294
+ (prem) =>
295
+ prem.kind === "App" &&
296
+ ((prem.fun.kind === "App" &&
297
+ prem.fun.fun.kind === "Const" &&
298
+ prem.fun.fun.name === "Pure.imp") ||
299
+ (prem.fun.kind === "Const" && prem.fun.name === "Pure.all")),
300
+ );
301
+ return rules.reduceRight<GoalTactic>(
302
+ (tactic, rule) =>
303
+ appendGoal(
304
+ thenAllNew(eresolveTac(limits, [normHhf(limits, trivial(rule))]), assumeTac(limits)),
305
+ tactic,
306
+ ),
307
+ () => noTac,
308
+ )(index);
309
+ }),
310
+ );
311
+
312
+ // Method.assm_tac
313
+ const assmTac = (limits: Limits): GoalTactic => {
314
+ const condRtac = (isRule: (concl: Term) => boolean, rule: Thm) =>
315
+ subgoal((goal, index) =>
316
+ isRule(stripAssumsConcl(goal)) ? resolveTac(limits, [rule])(index) : noTac,
317
+ );
318
+ return appendGoal(
319
+ assumeTac(limits),
320
+ appendGoal(
321
+ assumeRuleTac(limits),
322
+ appendGoal(
323
+ condRtac(isEquals, reflexiveThm),
324
+ condRtac(
325
+ (concl) =>
326
+ concl.kind === "App" && concl.fun.kind === "Const" && concl.fun.name === "Pure.term",
327
+ termI,
328
+ ),
329
+ ),
330
+ ),
331
+ );
332
+ };
333
+
334
+ // Method.all_assm_tac
335
+ const allAssmTac =
336
+ (limits: Limits) =>
337
+ (index: number): Tactic =>
338
+ (state) =>
339
+ index > nprems(state)
340
+ ? singleSeq(state)
341
+ : orElse(
342
+ thenTac(assmTac(limits)(index), allAssmTac(limits)(index)),
343
+ allAssmTac(limits)(index + 1),
344
+ )(state);
345
+
346
+ // Proof.local_terminal_proof: by initial terminal runs the initial method with the facts, then
347
+ // the terminal one without them and Method.finish, and succeeds on the first result that leaves
348
+ // no goal.
349
+ export const terminalProof = (
350
+ context: ProofContext,
351
+ text: ProofText,
352
+ facts: readonly Thm[],
353
+ state: Thm,
354
+ ): Seq<Thm> => {
355
+ const initial = evaluate(context, text.initial);
356
+ const terminal = text.terminal === undefined ? undefined : evaluate(context, text.terminal);
357
+ const finish: Tactic = (result) =>
358
+ mapsSeq(flexflexTac(context.limits), allAssmTac(context.limits)(1)(result));
359
+ return filterSeq(
360
+ (result) => nprems(result) === 0,
361
+ mapsSeq(
362
+ (result) =>
363
+ mapsSeq(finish, terminal === undefined ? singleSeq(result) : terminal([])(result)),
364
+ initial(facts)(state),
365
+ ),
366
+ );
367
+ };
@@ -0,0 +1,28 @@
1
+ // Ported from Isabelle2025's Pure/goal.ML (init), Pure/Isar/method.ML (insert_tac, finish) and the
2
+ // terminal proof of Pure/Isar/proof.ML. Copyright (c) 1986-2025 University of Cambridge,
3
+ // Technische Universitaet Muenchen, and contributors, see LICENSE.
4
+ //
5
+ // The goal of show "C" is C ==> #C, and using assms makes the assumptions its facts.
6
+ // Goal.conjunction_tac, which METHOD runs first, changes nothing here: tlapm's goals have no Pure
7
+ // conjunctions.
8
+
9
+ import { compIncr, forallIntrVars, protectI, revcutRl } from "../pure/drule";
10
+ import { normHhf } from "../pure/simplifier";
11
+ import { mkVar, propT } from "../pure/term";
12
+ import { every, type Tactic } from "../pure/tactical";
13
+ import type { Limits } from "../pure/interrupt";
14
+ import { resolveTac } from "../pure/tactic";
15
+ import { assume, instantiate, type Thm } from "../pure/thm";
16
+ import type { Statement } from "./statement";
17
+
18
+ // Goal.init: C ==> #C.
19
+ export const initGoal = (statement: Statement) =>
20
+ instantiate([{ variable: mkVar("A", 0, propT), term: statement.conclusion }], protectI);
21
+
22
+ // Assumption.assume: an assumption in hhf normal form.
23
+ export const getFacts = (limits: Limits, statement: Statement) =>
24
+ statement.assumptions.map((assumption) => normHhf(limits, assume(assumption)));
25
+
26
+ // Method.insert_tac: each fact becomes a premise of the goal, in order.
27
+ export const insertTac = (limits: Limits, facts: readonly Thm[], index: number): Tactic =>
28
+ every(facts.map((fact) => resolveTac(limits, [compIncr(forallIntrVars(fact), revcutRl)])(index)));
@@ -0,0 +1,57 @@
1
+ // Ported from the statement handling of Isabelle2025's Pure/Isar/expression.ML
2
+ // (prep_full_context_statement). Copyright (c) 1986-2025 University of Cambridge, Technische
3
+ // Universitaet Muenchen, and contributors, see LICENSE.
4
+ //
5
+ // Reads a lemma's fixes, assumes and shows: each proposition is parsed with the variables fixed
6
+ // before it, and all of them are type checked together.
7
+
8
+ import { typargsOf } from "../pure/consts";
9
+ import type { Term } from "../pure/term";
10
+ import type { TlaLogic } from "../tla/logic";
11
+ import { parseProp, parseType } from "./inner-syntax";
12
+ import type { TheoryText } from "./theory";
13
+ import { checkProps, type PropToCheck } from "./type-check";
14
+
15
+ export interface Statement {
16
+ readonly assumptions: readonly Term[];
17
+ readonly conclusion: Term;
18
+ }
19
+
20
+ export const readStatement = (logic: TlaLogic, theory: TheoryText): Statement => {
21
+ const theoryConsts = theory.consts.map((constant) => ({
22
+ base: constant.name,
23
+ name: `${theory.name}.${constant.name}`,
24
+ type: parseType(constant.type),
25
+ }));
26
+ const scope = {
27
+ consts: new Map([
28
+ ...logic.consts,
29
+ ...theoryConsts.map(
30
+ (constant) =>
31
+ [
32
+ constant.name,
33
+ { type: constant.type, typargs: typargsOf(constant.type), abbreviation: undefined },
34
+ ] as const,
35
+ ),
36
+ ]),
37
+ constNames: new Map([
38
+ ...logic.constNames,
39
+ ...theoryConsts.map((constant) => [constant.base, constant.name] as const),
40
+ ]),
41
+ };
42
+ const props = theory.elements.reduce<{ fixed: ReadonlySet<string>; props: PropToCheck[] }>(
43
+ (state, element) =>
44
+ element.kind === "fixes"
45
+ ? { fixed: new Set([...state.fixed, ...element.names]), props: state.props }
46
+ : {
47
+ fixed: state.fixed,
48
+ props: [...state.props, { ast: parseProp(element.prop), fixed: state.fixed }],
49
+ },
50
+ { fixed: new Set(), props: [] },
51
+ );
52
+ const checked = checkProps(scope, [
53
+ ...props.props,
54
+ { ast: parseProp(theory.shows), fixed: props.fixed },
55
+ ]);
56
+ return { assumptions: checked.slice(0, -1), conclusion: checked[checked.length - 1] };
57
+ };
@@ -0,0 +1,192 @@
1
+ // Reads the outer syntax of the theories tlapm writes (Isabelle.thy_temp in isabelle.ml): the
2
+ // header, the constants it declares, and one lemma with its proof.
3
+ //
4
+ // theory NAME imports Constant Zenon begin
5
+ // consts "name" :: type ...
6
+ // lemma NAME: fixes ... assumes NAME: "prop" ... shows "prop" (is "PROP ?NAME")
7
+ // proof - show "PROP ?NAME" [using assms] by METHOD [METHOD] qed
8
+ // end
9
+
10
+ import { TlaIsabelleError } from "../../../errors";
11
+
12
+ export type OuterToken =
13
+ | { readonly kind: "word"; readonly text: string }
14
+ | { readonly kind: "string"; readonly text: string }
15
+ | { readonly kind: "symbol"; readonly text: string };
16
+
17
+ export type StatementElement =
18
+ | { readonly kind: "fixes"; readonly names: readonly string[] }
19
+ | { readonly kind: "assumes"; readonly name: string; readonly prop: string };
20
+
21
+ export interface TheoryText {
22
+ readonly name: string;
23
+ readonly consts: readonly { readonly name: string; readonly type: string }[];
24
+ readonly elements: readonly StatementElement[];
25
+ readonly shows: string;
26
+ readonly isUsingAssms: boolean;
27
+ // The method of by, then the terminal method if there is one, as outer tokens.
28
+ readonly method: readonly OuterToken[];
29
+ }
30
+
31
+ const isWordChar = (char: string) => /[A-Za-z0-9_'.]/.test(char);
32
+
33
+ // Outer strings unescape \" and \\; symbols such as \<in> stay as they are.
34
+ const readString = (text: string, start: number): [string, number] => {
35
+ let result = "";
36
+ let position = start + 1;
37
+ while (position < text.length && text[position] !== '"') {
38
+ if (text[position] === "\\" && (text[position + 1] === '"' || text[position + 1] === "\\")) {
39
+ result += text[position + 1];
40
+ position += 2;
41
+ } else {
42
+ result += text[position];
43
+ position += 1;
44
+ }
45
+ }
46
+ if (position >= text.length)
47
+ throw new TlaIsabelleError("ERROR", "Outer lexical error: unterminated string");
48
+ return [result, position + 1];
49
+ };
50
+
51
+ const skipComment = (text: string, start: number) => {
52
+ let depth = 0;
53
+ let position = start;
54
+ do {
55
+ if (text.startsWith("(*", position)) {
56
+ depth += 1;
57
+ position += 2;
58
+ } else if (text.startsWith("*)", position)) {
59
+ depth -= 1;
60
+ position += 2;
61
+ } else if (position >= text.length)
62
+ throw new TlaIsabelleError("ERROR", "Outer lexical error: unterminated comment");
63
+ else position += 1;
64
+ } while (depth > 0);
65
+ return position;
66
+ };
67
+
68
+ const tokenize = (text: string): OuterToken[] => {
69
+ const tokens: OuterToken[] = [];
70
+ let position = 0;
71
+ while (position < text.length) {
72
+ if (/\s/.test(text[position])) position += 1;
73
+ else if (text.startsWith("(*", position)) position = skipComment(text, position);
74
+ else if (text[position] === '"') {
75
+ const [string, end] = readString(text, position);
76
+ tokens.push({ kind: "string", text: string });
77
+ position = end;
78
+ } else if (isWordChar(text[position])) {
79
+ let end = position;
80
+ while (end < text.length && isWordChar(text[end])) end += 1;
81
+ tokens.push({ kind: "word", text: text.slice(position, end) });
82
+ position = end;
83
+ } else {
84
+ tokens.push({ kind: "symbol", text: text[position] });
85
+ position += 1;
86
+ }
87
+ }
88
+ return tokens;
89
+ };
90
+
91
+ const KEYWORDS = new Set([
92
+ "fixes",
93
+ "assumes",
94
+ "shows",
95
+ "lemma",
96
+ "proof",
97
+ "show",
98
+ "using",
99
+ "by",
100
+ "qed",
101
+ "end",
102
+ "consts",
103
+ ]);
104
+
105
+ export const parseTheory = (text: string): TheoryText => {
106
+ const tokens = tokenize(text);
107
+ let position = 0;
108
+ const peek = () => tokens[position];
109
+ const isWord = (word: string) => peek()?.kind === "word" && peek().text === word;
110
+ const syntaxError = () =>
111
+ new TlaIsabelleError(
112
+ "ERROR",
113
+ `Outer syntax error at: ${peek() === undefined ? "end of input" : peek().text}`,
114
+ );
115
+ const expectWord = (word: string) => {
116
+ if (!isWord(word)) throw syntaxError();
117
+ position += 1;
118
+ };
119
+ const expectSymbol = (symbol: string) => {
120
+ if (peek()?.kind !== "symbol" || peek().text !== symbol) throw syntaxError();
121
+ position += 1;
122
+ };
123
+ const name = () => {
124
+ const token = peek();
125
+ if (token?.kind !== "word" || KEYWORDS.has(token.text)) throw syntaxError();
126
+ position += 1;
127
+ return token.text;
128
+ };
129
+ const string = () => {
130
+ const token = peek();
131
+ if (token?.kind !== "string") throw syntaxError();
132
+ position += 1;
133
+ return token.text;
134
+ };
135
+ const nameOrString = () => (peek()?.kind === "string" ? string() : name());
136
+
137
+ expectWord("theory");
138
+ const theoryName = name();
139
+ expectWord("imports");
140
+ while (!isWord("begin")) name();
141
+ expectWord("begin");
142
+ const consts: { name: string; type: string }[] = [];
143
+ if (isWord("consts")) {
144
+ position += 1;
145
+ while (peek()?.kind === "string") {
146
+ const constName = string();
147
+ expectSymbol(":");
148
+ expectSymbol(":");
149
+ consts.push({ name: constName, type: nameOrString() });
150
+ }
151
+ }
152
+ expectWord("lemma");
153
+ name();
154
+ expectSymbol(":");
155
+ const elements: StatementElement[] = [];
156
+ while (isWord("fixes") || isWord("assumes")) {
157
+ if (isWord("fixes")) {
158
+ position += 1;
159
+ const names = [name()];
160
+ while (peek()?.kind === "word" && !KEYWORDS.has(peek().text)) names.push(name());
161
+ elements.push({ kind: "fixes", names });
162
+ } else {
163
+ position += 1;
164
+ const assumption = name();
165
+ expectSymbol(":");
166
+ elements.push({ kind: "assumes", name: assumption, prop: string() });
167
+ }
168
+ }
169
+ expectWord("shows");
170
+ const shows = string();
171
+ expectSymbol("(");
172
+ expectWord("is");
173
+ string();
174
+ expectSymbol(")");
175
+ expectWord("proof");
176
+ expectSymbol("-");
177
+ expectWord("show");
178
+ string();
179
+ const isUsingAssms = isWord("using");
180
+ if (isUsingAssms) {
181
+ position += 1;
182
+ expectWord("assms");
183
+ }
184
+ expectWord("by");
185
+ const methodStart = position;
186
+ while (position < tokens.length && !isWord("qed")) position += 1;
187
+ const method = tokens.slice(methodStart, position);
188
+ expectWord("qed");
189
+ expectWord("end");
190
+ if (position !== tokens.length) throw syntaxError();
191
+ return { name: theoryName, consts, elements, shows, isUsingAssms, method };
192
+ };