tla-ts 0.0.9 → 0.0.10-dev.28c823e4b

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 (390) hide show
  1. package/README.md +29 -1
  2. package/dist/compile.cjs +23 -0
  3. package/dist/compile.js +23 -0
  4. package/dist/deciders.cjs +28 -28
  5. package/dist/deciders.js +43 -43
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +106 -10
  8. package/dist/index.d.ts +106 -10
  9. package/dist/index.js +1 -1
  10. package/dist/parallel-worker.cjs +1 -1
  11. package/dist/parallel-worker.js +1 -1
  12. package/dist/prove-worker.cjs +1 -1
  13. package/dist/prove-worker.js +1 -1
  14. package/dist/prove.cjs +116 -36
  15. package/dist/prove.js +116 -36
  16. package/dist/run.cjs +143 -31
  17. package/dist/run.js +143 -31
  18. package/dist/tlapm.cjs +2 -2
  19. package/dist/tlapm.js +2 -2
  20. package/dist/transfer.cjs +129 -104
  21. package/dist/transfer.js +129 -104
  22. package/dist/worker.cjs +7 -7
  23. package/dist/worker.js +7 -7
  24. package/package.json +3 -1
  25. package/src/ast.ts +4 -23
  26. package/src/bags.ts +99 -102
  27. package/src/builtins.ts +40 -78
  28. package/src/bundled-modules.ts +1 -8
  29. package/src/check.ts +599 -388
  30. package/src/cli/options.ts +11 -6
  31. package/src/cli/run.ts +0 -2
  32. package/src/cli/runtime-invariants.ts +136 -0
  33. package/src/cli/shared.ts +18 -11
  34. package/src/cli/tlapm.ts +0 -12
  35. package/src/cli/tlc-arguments.ts +640 -0
  36. package/src/cli/tlc-usage.ts +361 -0
  37. package/src/cli/tlc.ts +538 -220
  38. package/src/cli/typescript.ts +23 -0
  39. package/src/cli/xml-exporter.ts +4 -16
  40. package/src/cli.ts +0 -1
  41. package/src/codegen.ts +191 -64
  42. package/src/config.ts +140 -109
  43. package/src/coverage.ts +837 -0
  44. package/src/dependencies.ts +6 -40
  45. package/src/dfid.ts +618 -0
  46. package/src/environment.ts +240 -118
  47. package/src/errors.ts +70 -55
  48. package/src/evaluate.ts +596 -339
  49. package/src/exit-codes.ts +37 -3
  50. package/src/fingerprints.ts +10 -10
  51. package/src/index.ts +3 -0
  52. package/src/instances.ts +79 -11
  53. package/src/java-overrides.ts +4 -19
  54. package/src/json-reader.ts +455 -0
  55. package/src/json.ts +255 -139
  56. package/src/levels.ts +8 -17
  57. package/src/lexer.ts +80 -100
  58. package/src/liveness-checker.ts +82 -119
  59. package/src/liveness.ts +112 -64
  60. package/src/obligations/action.ts +4 -28
  61. package/src/obligations/anonymize.ts +84 -80
  62. package/src/obligations/equality.ts +1 -1
  63. package/src/obligations/expression.ts +2 -19
  64. package/src/obligations/format.ts +1 -9
  65. package/src/obligations/generate.ts +1 -11
  66. package/src/obligations/index.ts +0 -11
  67. package/src/obligations/levels.ts +4 -8
  68. package/src/obligations/module.ts +1 -15
  69. package/src/obligations/normalize.ts +5 -24
  70. package/src/obligations/operators.ts +1 -2
  71. package/src/obligations/pragma.ts +1 -10
  72. package/src/obligations/printer.ts +47 -46
  73. package/src/obligations/proof.ts +1 -5
  74. package/src/obligations/regroup.ts +1 -4
  75. package/src/obligations/simplify.ts +3 -14
  76. package/src/obligations/source.ts +1 -21
  77. package/src/obligations/subexpression.ts +5 -11
  78. package/src/obligations/substitution.ts +1 -3
  79. package/src/obligations/temporal.ts +8 -14
  80. package/src/obligations/tuples.ts +3 -9
  81. package/src/parallel-worker.ts +29 -39
  82. package/src/parallel.ts +53 -44
  83. package/src/parser.ts +565 -282
  84. package/src/pcal/ast.ts +53 -86
  85. package/src/pcal/parse.ts +144 -219
  86. package/src/pcal/tokenize.ts +91 -131
  87. package/src/pcal/translate.ts +83 -130
  88. package/src/pcal/validate.ts +48 -68
  89. package/src/pretty-print.ts +7 -8
  90. package/src/prover/decide-pool.ts +5 -10
  91. package/src/prover/deciders.ts +0 -4
  92. package/src/prover/first-order.ts +0 -11
  93. package/src/prover/isabelle/decide.ts +0 -6
  94. package/src/prover/isabelle/encode.ts +11 -23
  95. package/src/prover/isabelle/isar/inner-syntax.ts +108 -114
  96. package/src/prover/isabelle/isar/method.ts +25 -38
  97. package/src/prover/isabelle/isar/proof.ts +1 -10
  98. package/src/prover/isabelle/isar/statement.ts +1 -6
  99. package/src/prover/isabelle/isar/theory.ts +15 -26
  100. package/src/prover/isabelle/isar/type-check.ts +11 -25
  101. package/src/prover/isabelle/provers/blast/blast.ts +10 -41
  102. package/src/prover/isabelle/provers/blast/branch.ts +1 -32
  103. package/src/prover/isabelle/provers/blast/prove.ts +1 -35
  104. package/src/prover/isabelle/provers/blast/rules.ts +6 -44
  105. package/src/prover/isabelle/provers/blast/state.ts +2 -28
  106. package/src/prover/isabelle/provers/blast/term.ts +9 -36
  107. package/src/prover/isabelle/provers/clasimp.ts +1 -13
  108. package/src/prover/isabelle/provers/classical.ts +14 -42
  109. package/src/prover/isabelle/provers/hypsubst.ts +11 -25
  110. package/src/prover/isabelle/pure/bicompose.ts +16 -13
  111. package/src/prover/isabelle/pure/consts.ts +1 -7
  112. package/src/prover/isabelle/pure/conv.ts +1 -9
  113. package/src/prover/isabelle/pure/drule.ts +24 -40
  114. package/src/prover/isabelle/pure/envir.ts +3 -52
  115. package/src/prover/isabelle/pure/goal.ts +1 -7
  116. package/src/prover/isabelle/pure/interrupt.ts +0 -5
  117. package/src/prover/isabelle/pure/list.ts +0 -3
  118. package/src/prover/isabelle/pure/logic.ts +1 -14
  119. package/src/prover/isabelle/pure/name.ts +2 -9
  120. package/src/prover/isabelle/pure/net.ts +3 -59
  121. package/src/prover/isabelle/pure/object-logic.ts +3 -10
  122. package/src/prover/isabelle/pure/pattern.ts +2 -19
  123. package/src/prover/isabelle/pure/raw-simplifier.ts +13 -49
  124. package/src/prover/isabelle/pure/rewriter.ts +26 -58
  125. package/src/prover/isabelle/pure/search.ts +3 -10
  126. package/src/prover/isabelle/pure/seq.ts +1 -10
  127. package/src/prover/isabelle/pure/simplifier.ts +4 -12
  128. package/src/prover/isabelle/pure/table.ts +1 -31
  129. package/src/prover/isabelle/pure/tactic.ts +12 -22
  130. package/src/prover/isabelle/pure/tactical.ts +6 -12
  131. package/src/prover/isabelle/pure/term-ord.ts +2 -6
  132. package/src/prover/isabelle/pure/term.ts +2 -43
  133. package/src/prover/isabelle/pure/thm.ts +13 -36
  134. package/src/prover/isabelle/pure/type.ts +2 -15
  135. package/src/prover/isabelle/pure/unify.ts +20 -30
  136. package/src/prover/isabelle/pure/variable.ts +3 -7
  137. package/src/prover/isabelle/tla/classical-setup.ts +9 -19
  138. package/src/prover/isabelle/tla/context.ts +8 -16
  139. package/src/prover/isabelle/tla/logic.ts +4 -11
  140. package/src/prover/isabelle/tla/simpdata.ts +46 -34
  141. package/src/prover/isabelle/tools/intuitionistic.ts +1 -10
  142. package/src/prover/ocaml.ts +0 -6
  143. package/src/prover/prep/action.ts +4 -36
  144. package/src/prover/prep/enabled-axioms.ts +12 -19
  145. package/src/prover/prep/fingerprint.ts +0 -16
  146. package/src/prover/prep/level-comparison.ts +8 -12
  147. package/src/prover/prep/md5.ts +0 -2
  148. package/src/prover/prep/methods.ts +9 -36
  149. package/src/prover/prep/normalize.ts +4 -28
  150. package/src/prover/prove-worker.ts +0 -2
  151. package/src/prover/prove.ts +0 -36
  152. package/src/prover/ptl/decide.ts +7 -12
  153. package/src/prover/ptl/encode.ts +14 -36
  154. package/src/prover/ptl/sat.ts +24 -32
  155. package/src/prover/ptl/tableau.ts +12 -26
  156. package/src/prover/smt/axioms.ts +0 -7
  157. package/src/prover/smt/context.ts +19 -26
  158. package/src/prover/smt/data.ts +51 -54
  159. package/src/prover/smt/encode.ts +14 -35
  160. package/src/prover/smt/extensionality.ts +0 -10
  161. package/src/prover/smt/flatten.ts +3 -22
  162. package/src/prover/smt/format.ts +5 -10
  163. package/src/prover/smt/instances.ts +0 -10
  164. package/src/prover/smt/rewrite.ts +66 -101
  165. package/src/prover/smt/solver/act-cache.ts +0 -15
  166. package/src/prover/smt/solver/arith-rewriter.ts +3 -48
  167. package/src/prover/smt/solver/array.ts +1 -3
  168. package/src/prover/smt/solver/asserted-formulas.ts +1 -43
  169. package/src/prover/smt/solver/ast-lt.ts +1 -11
  170. package/src/prover/smt/solver/ast-util.ts +1 -6
  171. package/src/prover/smt/solver/ast.ts +1 -143
  172. package/src/prover/smt/solver/auf-solver.ts +6 -39
  173. package/src/prover/smt/solver/case-split-queue.ts +1 -9
  174. package/src/prover/smt/solver/cg-table.ts +1 -18
  175. package/src/prover/smt/solver/clause.ts +1 -27
  176. package/src/prover/smt/solver/conflict-resolution.ts +0 -9
  177. package/src/prover/smt/solver/context.ts +4 -61
  178. package/src/prover/smt/solver/ctx-simplify.ts +14 -41
  179. package/src/prover/smt/solver/der.ts +2 -21
  180. package/src/prover/smt/solver/dyn-ack.ts +1 -11
  181. package/src/prover/smt/solver/e-matching.ts +3 -34
  182. package/src/prover/smt/solver/enode.ts +1 -21
  183. package/src/prover/smt/solver/expr-ref.ts +1 -5
  184. package/src/prover/smt/solver/expr-safe-replace.ts +0 -5
  185. package/src/prover/smt/solver/fingerprints.ts +1 -12
  186. package/src/prover/smt/solver/flat-literals.ts +1 -9
  187. package/src/prover/smt/solver/goal.ts +2 -14
  188. package/src/prover/smt/solver/hash.ts +0 -8
  189. package/src/prover/smt/solver/hashtable.ts +1 -12
  190. package/src/prover/smt/solver/internalizer.ts +6 -98
  191. package/src/prover/smt/solver/lbool.ts +1 -2
  192. package/src/prover/smt/solver/literal.ts +0 -3
  193. package/src/prover/smt/solver/lp/bound-propagator.ts +8 -26
  194. package/src/prover/smt/solver/lp/constraints.ts +2 -8
  195. package/src/prover/smt/solver/lp/containers.ts +12 -30
  196. package/src/prover/smt/solver/lp/core-solver.ts +10 -31
  197. package/src/prover/smt/solver/lp/cross-nested.ts +6 -20
  198. package/src/prover/smt/solver/lp/dep-intervals.ts +7 -22
  199. package/src/prover/smt/solver/lp/dependency.ts +1 -4
  200. package/src/prover/smt/solver/lp/dioph-eq.ts +12 -98
  201. package/src/prover/smt/solver/lp/explanation.ts +1 -6
  202. package/src/prover/smt/solver/lp/gomory.ts +9 -22
  203. package/src/prover/smt/solver/lp/hnf-cutter.ts +17 -23
  204. package/src/prover/smt/solver/lp/hnf.ts +11 -26
  205. package/src/prover/smt/solver/lp/int-cube.ts +15 -36
  206. package/src/prover/smt/solver/lp/int-solver.ts +4 -34
  207. package/src/prover/smt/solver/lp/lar-solver.ts +32 -81
  208. package/src/prover/smt/solver/lp/lar-term.ts +1 -5
  209. package/src/prover/smt/solver/lp/lp-settings.ts +1 -14
  210. package/src/prover/smt/solver/lp/maximize-term.ts +20 -45
  211. package/src/prover/smt/solver/lp/nex-creator.ts +5 -28
  212. package/src/prover/smt/solver/lp/nex.ts +1 -6
  213. package/src/prover/smt/solver/lp/nla-backoff.ts +1 -4
  214. package/src/prover/smt/solver/lp/nla-basics.ts +5 -30
  215. package/src/prover/smt/solver/lp/nla-core.ts +35 -130
  216. package/src/prover/smt/solver/lp/nla-divisions.ts +32 -42
  217. package/src/prover/smt/solver/lp/nla-emonics.ts +4 -21
  218. package/src/prover/smt/solver/lp/nla-factorization.ts +1 -4
  219. package/src/prover/smt/solver/lp/nla-grobner.ts +15 -69
  220. package/src/prover/smt/solver/lp/nla-horner.ts +3 -11
  221. package/src/prover/smt/solver/lp/nla-intervals.ts +2 -12
  222. package/src/prover/smt/solver/lp/nla-monomial-bounds.ts +16 -41
  223. package/src/prover/smt/solver/lp/nla-monotone.ts +2 -6
  224. package/src/prover/smt/solver/lp/nla-order.ts +2 -13
  225. package/src/prover/smt/solver/lp/nla-patcher.ts +4 -7
  226. package/src/prover/smt/solver/lp/nla-tangents.ts +1 -9
  227. package/src/prover/smt/solver/lp/nla-throttle.ts +1 -6
  228. package/src/prover/smt/solver/lp/nla-types.ts +1 -11
  229. package/src/prover/smt/solver/lp/nla-var-eqs.ts +4 -25
  230. package/src/prover/smt/solver/lp/nra-solver.ts +5 -52
  231. package/src/prover/smt/solver/lp/numeric-pair.ts +1 -4
  232. package/src/prover/smt/solver/lp/pdd-interval.ts +1 -3
  233. package/src/prover/smt/solver/lp/pdd-simplifier.ts +2 -14
  234. package/src/prover/smt/solver/lp/pdd-solver.ts +4 -33
  235. package/src/prover/smt/solver/lp/pdd.ts +7 -70
  236. package/src/prover/smt/solver/lp/random-updater.ts +1 -8
  237. package/src/prover/smt/solver/lp/static-matrix.ts +9 -19
  238. package/src/prover/smt/solver/lp/union-find.ts +1 -6
  239. package/src/prover/smt/solver/mam-compiler.ts +14 -56
  240. package/src/prover/smt/solver/mam-interpreter.ts +1 -21
  241. package/src/prover/smt/solver/maximize-ac-sharing.ts +2 -17
  242. package/src/prover/smt/solver/model-checker.ts +2 -36
  243. package/src/prover/smt/solver/model-evaluator.ts +3 -29
  244. package/src/prover/smt/solver/model-finder.ts +3 -15
  245. package/src/prover/smt/solver/model-generator.ts +1 -12
  246. package/src/prover/smt/solver/model-macro-solver.ts +12 -69
  247. package/src/prover/smt/solver/nlsat/algebraic.ts +55 -151
  248. package/src/prover/smt/solver/nlsat/atoms.ts +5 -19
  249. package/src/prover/smt/solver/nlsat/evaluator.ts +17 -22
  250. package/src/prover/smt/solver/nlsat/explain.ts +3 -47
  251. package/src/prover/smt/solver/nlsat/interval-set.ts +9 -50
  252. package/src/prover/smt/solver/nlsat/levelwise.ts +48 -129
  253. package/src/prover/smt/solver/nlsat/mpbq.ts +3 -14
  254. package/src/prover/smt/solver/nlsat/polynomial.ts +17 -156
  255. package/src/prover/smt/solver/nlsat/solver.ts +7 -67
  256. package/src/prover/smt/solver/nlsat/types.ts +1 -8
  257. package/src/prover/smt/solver/nlsat/upolynomial-factorization.ts +1 -44
  258. package/src/prover/smt/solver/nlsat/upolynomial.ts +11 -92
  259. package/src/prover/smt/solver/nnf.ts +3 -38
  260. package/src/prover/smt/solver/pattern-inference.ts +2 -15
  261. package/src/prover/smt/solver/poly-rewriter.ts +3 -23
  262. package/src/prover/smt/solver/propagate-values.ts +1 -10
  263. package/src/prover/smt/solver/proto-model.ts +3 -48
  264. package/src/prover/smt/solver/pull-quant.ts +1 -12
  265. package/src/prover/smt/solver/qe-lite-der.ts +1 -29
  266. package/src/prover/smt/solver/qe-lite-fm.ts +2 -25
  267. package/src/prover/smt/solver/qe-lite.ts +3 -33
  268. package/src/prover/smt/solver/qi-queue.ts +1 -16
  269. package/src/prover/smt/solver/quant-tactics.ts +5 -22
  270. package/src/prover/smt/solver/quantifier-analyzer.ts +17 -37
  271. package/src/prover/smt/solver/quantifier-manager.ts +1 -8
  272. package/src/prover/smt/solver/random-gen.ts +1 -2
  273. package/src/prover/smt/solver/rational.ts +1 -8
  274. package/src/prover/smt/solver/ref-vector.ts +1 -6
  275. package/src/prover/smt/solver/relevancy.ts +2 -15
  276. package/src/prover/smt/solver/rewriter-tpl.ts +3 -147
  277. package/src/prover/smt/solver/rewriter.ts +3 -85
  278. package/src/prover/smt/solver/rlimit.ts +2 -20
  279. package/src/prover/smt/solver/smtlib-parser.ts +2 -37
  280. package/src/prover/smt/solver/solver.ts +23 -34
  281. package/src/prover/smt/solver/sort.ts +1 -5
  282. package/src/prover/smt/solver/sticky-generations.ts +0 -5
  283. package/src/prover/smt/solver/theory-lra-axioms.ts +3 -24
  284. package/src/prover/smt/solver/theory-lra-bounds.ts +0 -5
  285. package/src/prover/smt/solver/theory-lra-final-check.ts +4 -22
  286. package/src/prover/smt/solver/theory-lra-internalize.ts +1 -27
  287. package/src/prover/smt/solver/theory-lra-model.ts +4 -19
  288. package/src/prover/smt/solver/theory-lra-propagate.ts +1 -15
  289. package/src/prover/smt/solver/theory-lra-state.ts +3 -8
  290. package/src/prover/smt/solver/theory-lra.ts +1 -8
  291. package/src/prover/smt/solver/var-subst.ts +2 -26
  292. package/src/prover/smt/table.ts +0 -8
  293. package/src/prover/tlapm/cache.ts +20 -25
  294. package/src/prover/tlapm/ocaml-marshal.ts +19 -21
  295. package/src/prover/tlapm/tlapm.ts +12 -17
  296. package/src/prover/verdict.ts +0 -2
  297. package/src/prover/zenon/check/check.ts +0 -9
  298. package/src/prover/zenon/check/definitions.ts +5 -15
  299. package/src/prover/zenon/check/equality.ts +0 -8
  300. package/src/prover/zenon/check/functions.ts +0 -4
  301. package/src/prover/zenon/check/keys.ts +0 -7
  302. package/src/prover/zenon/check/propositional.ts +0 -3
  303. package/src/prover/zenon/check/records.ts +0 -5
  304. package/src/prover/zenon/check/relations.ts +0 -13
  305. package/src/prover/zenon/check/rewrites.ts +0 -6
  306. package/src/prover/zenon/check/sets.ts +0 -3
  307. package/src/prover/zenon/check/terms.ts +0 -17
  308. package/src/prover/zenon/check/tla.ts +0 -6
  309. package/src/prover/zenon/decide.ts +0 -12
  310. package/src/prover/zenon/encode.ts +1 -8
  311. package/src/prover/zenon/eqrel.ts +0 -13
  312. package/src/prover/zenon/equality-rules.ts +0 -4
  313. package/src/prover/zenon/expr.ts +1 -26
  314. package/src/prover/zenon/index-table.ts +17 -38
  315. package/src/prover/zenon/isar-case.ts +9 -19
  316. package/src/prover/zenon/isar.ts +1 -29
  317. package/src/prover/zenon/limits.ts +0 -4
  318. package/src/prover/zenon/llproof.ts +0 -9
  319. package/src/prover/zenon/mltoll.ts +54 -76
  320. package/src/prover/zenon/node.ts +1 -11
  321. package/src/prover/zenon/ocaml.ts +1 -17
  322. package/src/prover/zenon/parse.ts +2 -7
  323. package/src/prover/zenon/phrase.ts +1 -11
  324. package/src/prover/zenon/proof.ts +0 -9
  325. package/src/prover/zenon/propositional-rules.ts +0 -5
  326. package/src/prover/zenon/rules.ts +2 -6
  327. package/src/prover/zenon/search.ts +1 -17
  328. package/src/prover/zenon/tla/functions.ts +57 -29
  329. package/src/prover/zenon/tla/llproof.ts +63 -70
  330. package/src/prover/zenon/tla/records.ts +56 -27
  331. package/src/prover/zenon/tla/rewrites.ts +12 -19
  332. package/src/prover/zenon/tla/sets.ts +68 -39
  333. package/src/prover/zenon/tla/terms.ts +0 -6
  334. package/src/prover/zenon/tla/tla.ts +59 -58
  335. package/src/randomization.ts +81 -35
  336. package/src/resolve.ts +12 -112
  337. package/src/runtime.ts +22 -22
  338. package/src/sany/builtins.ts +2 -5
  339. package/src/sany/generator.ts +149 -252
  340. package/src/sany/levels.ts +6 -34
  341. package/src/sany/lexer.ts +41 -61
  342. package/src/sany/linter.ts +1 -9
  343. package/src/sany/modules.ts +1 -5
  344. package/src/sany/nodes.ts +0 -31
  345. package/src/sany/parse-error.ts +39 -117
  346. package/src/sany/report.ts +29 -63
  347. package/src/sany/selectors.ts +15 -39
  348. package/src/sany/source.ts +1 -17
  349. package/src/sany/xml.ts +13 -63
  350. package/src/search.ts +495 -155
  351. package/src/simulate.ts +685 -0
  352. package/src/spec-description.ts +176 -69
  353. package/src/standard-definitions.ts +0 -4
  354. package/src/standard-modules.ts +254 -69
  355. package/src/state-graph.ts +50 -24
  356. package/src/subexpressions.ts +69 -52
  357. package/src/substitution-levels.ts +2 -3
  358. package/src/successors.ts +263 -94
  359. package/src/symmetry.ts +33 -25
  360. package/src/tableau.ts +27 -24
  361. package/src/tlc/fingerprint.ts +183 -67
  362. package/src/tlc/jar-data.ts +112 -6
  363. package/src/tlc/messages.ts +110 -44
  364. package/src/tlc/order.ts +37 -60
  365. package/src/tlc/random.ts +33 -45
  366. package/src/tlc/replay.ts +549 -217
  367. package/src/tlc/summary.ts +36 -47
  368. package/src/tlc/tlc-operators.ts +76 -41
  369. package/src/tlc/tlcext-operators.ts +139 -122
  370. package/src/tlc/trace-spec.ts +269 -0
  371. package/src/tlc/value-stream.ts +139 -0
  372. package/src/tlc/version.ts +1 -4
  373. package/src/transfer.ts +22 -25
  374. package/src/typescript/actions.ts +481 -0
  375. package/src/typescript/collections.ts +600 -0
  376. package/src/typescript/compile.ts +65 -0
  377. package/src/typescript/context.ts +94 -0
  378. package/src/typescript/emit.ts +121 -0
  379. package/src/typescript/expressions.ts +496 -0
  380. package/src/typescript/formula.ts +152 -0
  381. package/src/typescript/functions.ts +284 -0
  382. package/src/typescript/model.ts +163 -0
  383. package/src/typescript/names.ts +114 -0
  384. package/src/typescript/program.ts +48 -0
  385. package/src/typescript/properties.ts +139 -0
  386. package/src/typescript/scope.ts +112 -0
  387. package/src/typescript/steps.ts +165 -0
  388. package/src/typescript/types.ts +171 -0
  389. package/src/values.ts +780 -337
  390. package/src/worker.ts +7 -8
@@ -1,10 +1,4 @@
1
- // Ported from Isabelle2025's Provers/blast.ML. Copyright (c) 1986-2025 University of Cambridge,
2
- // Technische Universitaet Muenchen, and contributors, see LICENSE.
3
- //
4
- // The tableau prover, based on leanTaP. It works on a list of branches, each with its unexpanded
5
- // formulae, its literals and a bound on unsafe expansions. Every inference records the tactic
6
- // that replays it; once all branches close, the continuation reconstructs the proof. Each
7
- // recursion level that can be backtracked to owns a token, and a choice point raises it.
1
+ // Ported from Isabelle2025's Provers/blast.ML. Copyright (c) 1986-2025 University of Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
8
2
 
9
3
  import type { Seq } from "../../pure/seq";
10
4
  import type { GoalTactic } from "../../pure/tactical";
@@ -46,13 +40,10 @@ import {
46
40
  type VarRef,
47
41
  } from "./term";
48
42
 
49
- // The tactics that replay the inferences so far, latest first.
50
43
  type Tactics = List<GoalTactic> | undefined;
51
44
 
52
45
  export type Continuation = (tactics: Tactics, choices: Choices) => Seq<Thm>;
53
46
 
54
- // A step either finishes the search or continues the same branches without a choice point, which
55
- // blast.ML does by a tail call. prv loops on the latter, so a long search can't exhaust the stack.
56
47
  type Step =
57
48
  | { readonly kind: "done"; readonly result: Seq<Thm> }
58
49
  | {
@@ -76,7 +67,6 @@ export const prove = (
76
67
  const safeList = [context.claset.safe0, context.claset.safep];
77
68
  const unsafeList = [context.claset.unsafe];
78
69
 
79
- // Applies a safe rule only, possibly allowing instantiation; defers any unsafe formulae.
80
70
  const safeStep = (tactics: Tactics, choices: Choices, brs: readonly Branch[]): Step => {
81
71
  const token = {};
82
72
  const branch = brs[0];
@@ -90,7 +80,6 @@ export const prove = (
90
80
  const nxtVars = nextVars(rest);
91
81
  const formula = norm(head.safe[0].term);
92
82
  const rules = netMkRules(state, formula, branch.vars, safeList);
93
- // Makes the new branches, decrementing lim if instantiations occur.
94
83
  const newBr = (vars: readonly VarRef[], lim: number, prems: TableauRule["prems"]): Branch[] => [
95
84
  ...prems.map((prem): Branch => {
96
85
  const level = { safe: joinMd(md, prem), unsafe: [] };
@@ -105,14 +94,11 @@ export const prove = (
105
94
  }),
106
95
  ...rest,
107
96
  ];
108
- // Seeks a matching rule; if unifiable, adds its premises to the branch. Undefined is
109
- // NEWBRANCHES.
110
97
  const deeper = (): Seq<Thm> | undefined => {
111
98
  for (let position = 0; position < rules.length; position += 1) {
112
99
  const rule = rules[position];
113
100
  if (!unify(state, addTermVars(rule.major, []), rule.major, formula)) continue;
114
101
  const isUpdated = ntrl < state.trail.length;
115
- // Discourages branching updates.
116
102
  const lim = isUpdated ? branch.lim - (1 + log4(rules.length)) : branch.lim;
117
103
  const vars = addPremsVars(rule.prems, varsInVars(branch.vars));
118
104
  const nextChoices = cons({ ntrl, nbrs, token }, choices);
@@ -120,7 +106,6 @@ export const prove = (
120
106
  try {
121
107
  if (rule.prems.length === 0)
122
108
  return prv(nextTactics, prune(state, nbrs, nxtVars, nextChoices), rest);
123
- // Faster to kill all the alternatives.
124
109
  if (lim < 0) {
125
110
  clearTo(state, ntrl);
126
111
  return undefined;
@@ -128,15 +113,12 @@ export const prove = (
128
113
  return prv(nextTactics, nextChoices, newBr(vars, lim, rule.prems));
129
114
  } catch (error) {
130
115
  if (!isBacktrackTo(error, token)) throw error;
131
- // Backtracks at this level, resetting variables and trying another rule, or to the
132
- // previous level.
133
116
  if (!isUpdated) return backtrack(choices);
134
117
  clearTo(state, ntrl);
135
118
  }
136
119
  }
137
120
  return undefined;
138
121
  };
139
- // Tries to close the branch by unifying the formula with a literal. Undefined is CLOSEF.
140
122
  const closeF = (literals: readonly BlastTerm[]): Seq<Thm> | undefined => {
141
123
  for (const literal of literals) {
142
124
  const tactic = tryClose(state, formula, literal);
@@ -151,7 +133,6 @@ export const prove = (
151
133
  }
152
134
  return undefined;
153
135
  };
154
- // Tries to unify a queued formula, safe or unsafe, with the formula.
155
136
  const closeFl = (levels: readonly Level[]): Seq<Thm> | undefined => {
156
137
  for (const level of levels) {
157
138
  const closed =
@@ -173,7 +154,6 @@ export const prove = (
173
154
  const closed = closeF(branch.lits) ?? closeFl(pairs) ?? deeper();
174
155
  if (closed !== undefined) return done(closed);
175
156
  if (netMkRules(state, formula, branch.vars, unsafeList).length === 0)
176
- // There are no plausible unsafe rules: the formula becomes a literal.
177
157
  return {
178
158
  kind: "next",
179
159
  tactics,
@@ -183,7 +163,6 @@ export const prove = (
183
163
  ...rest,
184
164
  ],
185
165
  };
186
- // The formula admits some unsafe rules: try them later.
187
166
  const deferred: Formula = { term: negOfGoal(state, formula), md };
188
167
  return {
189
168
  kind: "next",
@@ -201,7 +180,6 @@ export const prove = (
201
180
  };
202
181
  };
203
182
 
204
- // No safe steps are possible at any level: applies an unsafe rule.
205
183
  const unsafeStep = (tactics: Tactics, choices: Choices, brs: readonly Branch[]): Step => {
206
184
  const token = {};
207
185
  const branch = brs[0];
@@ -212,7 +190,6 @@ export const prove = (
212
190
  const formula = norm(queued[0].term);
213
191
  const ntrl = state.trail.length;
214
192
  const rules = netMkRules(state, formula, branch.vars, unsafeList);
215
- // The new premises of unsafe rules may not be duplicated.
216
193
  const newPrem = (
217
194
  vars: readonly VarRef[],
218
195
  pattern: BlastTerm,
@@ -223,8 +200,6 @@ export const prove = (
223
200
  const safe = prem.map((term) => ({ term, md: false }));
224
201
  const unsafe = isDup ? [...others, { term: negOfGoal(state, formula), md }] : others;
225
202
  return {
226
- // A premise recursive in the rule makes no new stack frame: its unsafe premises end up at
227
- // the back of the queue, preventing the exclusion of others.
228
203
  pairs: prem.some((term) => match(state, pattern, term))
229
204
  ? [{ safe, unsafe }]
230
205
  : [
@@ -243,16 +218,10 @@ export const prove = (
243
218
  const isUpdated = ntrl < state.trail.length;
244
219
  const vars = varsInVars(branch.vars);
245
220
  const newVars = addPremsVars(rule.prems, vars);
246
- // Duplicates the formula if md permits.
247
221
  const isDup = md;
248
- // Decrements lim extra if updates occur.
249
222
  const lim = isUpdated ? branch.lim - (1 + log4(rules.length)) : branch.lim - 1;
250
- // Allows backtracking from a rule application if other matching rules exist, if the rule
251
- // updated variables, or if it introduced no new variables, so that it is not a standard
252
- // gamma-rule. This emulates fast_tac, which allows all unsafe steps to be undone.
253
223
  const mayUndo = position + 1 < rules.length || isUpdated || sameVars(vars, newVars);
254
224
  const tactic = rule.tactic(isUpdated, isDup, true);
255
- // Faster to kill all the alternatives.
256
225
  if (lim < 0 && rule.prems.length > 0) {
257
226
  clearTo(state, ntrl);
258
227
  return undefined;
@@ -273,7 +242,6 @@ export const prove = (
273
242
  if (branch.lim < 1) return backtrack(choices);
274
243
  const closed = deeper();
275
244
  if (closed !== undefined) return done(closed);
276
- // If no rule closes the branch, the formula becomes a literal.
277
245
  return {
278
246
  kind: "next",
279
247
  tactics,
@@ -300,7 +268,6 @@ export const prove = (
300
268
  let brs = branches;
301
269
  for (;;) {
302
270
  checkInterrupt(context.limits);
303
- // All branches closed.
304
271
  if (brs.length === 0) return cont(tactics, choices);
305
272
  const branch = brs[0];
306
273
  const head = branch.pairs[0];
@@ -319,7 +286,6 @@ export const prove = (
319
286
  continue;
320
287
  }
321
288
  if (branch.pairs.length > 1) {
322
- // No more safe formulae: transfers the unsafe ones down a level.
323
289
  const below = branch.pairs[1];
324
290
  brs = [
325
291
  {
@@ -1,8 +1,4 @@
1
- // Ported from Isabelle2025's Provers/blast.ML. Copyright (c) 1986-2025 University of Cambridge,
2
- // Technische Universitaet Muenchen, and contributors, see LICENSE.
3
- //
4
- // Conversion of the classical rules to tableau operations, each with the Isabelle tactic that
5
- // replays it during proof reconstruction.
1
+ // Ported from Isabelle2025's Provers/blast.ML. Copyright (c) 1986-2025 University of Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
6
2
 
7
3
  import { TlaIsabelleError } from "../../../../errors";
8
4
  import { revcutRl, zeroVarIndexes } from "../../pure/drule";
@@ -33,6 +29,7 @@ import {
33
29
  mkBlastSkolem,
34
30
  mkBlastVar,
35
31
  mkGoal,
32
+ splitGoalPrems,
36
33
  stripBlastImpConcl,
37
34
  stripBlastImpPrems,
38
35
  toTemplate,
@@ -42,19 +39,12 @@ import {
42
39
  type VarRef,
43
40
  } from "./term";
44
41
 
45
- // A tableau rule: the formula it applies to, the formulae of each new branch, and the tactic
46
- // for the flags upd (the inference updated the branch), dup (duplicate the formula) and rot
47
- // (rotate the new hypotheses).
48
42
  export interface TableauRule {
49
43
  readonly major: BlastTerm;
50
44
  readonly prems: readonly (readonly BlastTerm[])[];
51
45
  readonly tactic: (isUpdated: boolean, isDup: boolean, isRotated: boolean) => GoalTactic;
52
46
  }
53
47
 
54
- // Blast converts each rule it looks up afresh, with fresh variables and Skolem terms. This
55
- // converts each rule once, numbering them: concl is the conclusion's variable, which conversion
56
- // sets to *False*, and skolems counts the Skolem terms, which take fresh names in this order. An
57
- // ill-formed rule has no major premise, but still takes the names its conversion took.
58
48
  export interface RuleTemplate {
59
49
  readonly count: number;
60
50
  readonly concl: number | undefined;
@@ -63,8 +53,6 @@ export interface RuleTemplate {
63
53
  readonly prems: readonly (readonly Template[])[];
64
54
  }
65
55
 
66
- // The conclusion becomes the goal or the negated assumption *False*: delete it. A premise without
67
- // it is ill-formed and could make reconstruction fail.
68
56
  const deleteConcl = (state: BlastState, prems: readonly BlastTerm[]): BlastTerm[] | undefined => {
69
57
  const position = prems.findIndex((prem) => {
70
58
  if (prem.kind !== "App" || prem.fun.kind !== "Const") return false;
@@ -79,8 +67,6 @@ const deleteConcl = (state: BlastState, prems: readonly BlastTerm[]): BlastTerm[
79
67
  return position === -1 ? undefined : [...prems.slice(0, position), ...prems.slice(position + 1)];
80
68
  };
81
69
 
82
- // Skolemizes a premise with placeholder Skolem terms, adding them to skolems in the order that
83
- // blast names them.
84
70
  const skoPrem = (skolems: BlastTerm[], prem: BlastTerm): BlastTerm => {
85
71
  const body = destConstApp(prem, "Pure.all");
86
72
  if (body?.kind !== "Abs") return prem;
@@ -97,8 +83,6 @@ const illFormed = (skolems: number): RuleTemplate => ({
97
83
  prems: [],
98
84
  });
99
85
 
100
- // fromRule's convertRule, which expects an elimination rule to have a formula variable as its
101
- // conclusion.
102
86
  const makeElimTemplate = (state: BlastState, rule: Thm): RuleTemplate => {
103
87
  const trueprop = state.context.data.trueprop;
104
88
  const term = fromTerm(state.context.consts, rule.prop);
@@ -111,11 +95,7 @@ const makeElimTemplate = (state: BlastState, rule: Thm): RuleTemplate => {
111
95
  const skolems: BlastTerm[] = [];
112
96
  const converted: BlastTerm[][] = [];
113
97
  for (const prem of prems.slice(1)) {
114
- const skolemized = skoPrem(skolems, prem);
115
- const deleted = deleteConcl(state, [
116
- mkGoal(stripBlastImpConcl(trueprop, skolemized)),
117
- ...stripBlastImpPrems(trueprop, skolemized),
118
- ]);
98
+ const deleted = deleteConcl(state, splitGoalPrems(trueprop, skoPrem(skolems, prem)));
119
99
  if (deleted === undefined) return illFormed(skolems.length);
120
100
  converted.push(deleted);
121
101
  }
@@ -128,20 +108,15 @@ const makeElimTemplate = (state: BlastState, rule: Thm): RuleTemplate => {
128
108
  };
129
109
  };
130
110
 
131
- // fromIntrRule's conversion.
132
111
  const makeIntroTemplate = (state: BlastState, rule: Thm): RuleTemplate => {
133
112
  const trueprop = state.context.data.trueprop;
134
113
  const term = fromTerm(state.context.consts, rule.prop);
135
114
  const refs: VarRef[] = [];
136
115
  toTemplate(refs, [], term);
137
116
  const skolems: BlastTerm[] = [];
138
- const converted = stripBlastImpPrems(trueprop, term).map((prem) => {
139
- const skolemized = skoPrem(skolems, prem);
140
- return [
141
- mkGoal(stripBlastImpConcl(trueprop, skolemized)),
142
- ...stripBlastImpPrems(trueprop, skolemized),
143
- ];
144
- });
117
+ const converted = stripBlastImpPrems(trueprop, term).map((prem) =>
118
+ splitGoalPrems(trueprop, skoPrem(skolems, prem)),
119
+ );
145
120
  return {
146
121
  count: refs.length,
147
122
  concl: undefined,
@@ -151,7 +126,6 @@ const makeIntroTemplate = (state: BlastState, rule: Thm): RuleTemplate => {
151
126
  };
152
127
  };
153
128
 
154
- // Like dup_elim, but puts the duplicated major premise first.
155
129
  const revDupElim = (rule: Thm) => {
156
130
  const result = seqHead(assumption(undefined, 2, rsn(rule, 2, revcutRl)));
157
131
  if (result === undefined) throw new TlaIsabelleError("ERROR", "rev_dup_elim: Seq.hd");
@@ -161,7 +135,6 @@ const revDupElim = (rule: Thm) => {
161
135
  const countNewHyps = (prem: readonly BlastTerm[]) =>
162
136
  prem.filter((term) => destConstApp(term, GOAL_NAME) === undefined).length;
163
137
 
164
- // Rotates the assumptions in all new subgoals for the LIFO discipline.
165
138
  const rotSubgoalsTac =
166
139
  (isRotated: boolean, prems: readonly (readonly BlastTerm[])[]): GoalTactic =>
167
140
  (index) =>
@@ -174,8 +147,6 @@ const rotSubgoalsTac =
174
147
  ),
175
148
  );
176
149
 
177
- // Resolution or matching: if the inference updated the branch, the proof state may be updated.
178
- // Matching keeps the tactics more deterministic in the presence of variables.
179
150
  const emtac = (state: BlastState, isUpdated: boolean, rule: Thm): GoalTactic =>
180
151
  isUpdated ? eresolveTac(state.context.limits, [rule]) : ematchTac(state.context.limits, [rule]);
181
152
 
@@ -204,9 +175,6 @@ const intrRuleTactic =
204
175
  rotSubgoalsTac(isRotated, prems)(index),
205
176
  );
206
177
 
207
- // A tableau rule from a rule's template. Blast tries the rules in order until one's major premise
208
- // unifies, and often only checks that a rule exists, so this instantiates the template with fresh
209
- // variables only when the major premise is used, and the premises only when they are.
210
178
  class InstantiatedRule implements TableauRule {
211
179
  private readonly state: BlastState;
212
180
  private readonly rule: Thm;
@@ -234,7 +202,6 @@ class InstantiatedRule implements TableauRule {
234
202
  this.skolems = skolems;
235
203
  }
236
204
 
237
- // Fresh variables for the template's, with the conclusion's set to *False*.
238
205
  private getVars() {
239
206
  if (this.vars !== undefined) return this.vars;
240
207
  const vars: BlastTerm[] = [];
@@ -264,7 +231,6 @@ class InstantiatedRule implements TableauRule {
264
231
  return this.instantiatedPrems;
265
232
  }
266
233
 
267
- // Since unsafe rules are delayed, dup is always false for introduction rules.
268
234
  tactic(isUpdated: boolean, isDup: boolean, isRotated: boolean) {
269
235
  return (this.isIntro ? intrRuleTactic : elimRuleTactic)(this.state, this.rule, this.prems)(
270
236
  isUpdated,
@@ -274,8 +240,6 @@ class InstantiatedRule implements TableauRule {
274
240
  }
275
241
  }
276
242
 
277
- // fromRule or fromIntrRule: undefined for an ill-formed rule. Its Skolem terms take their names
278
- // now, as blast converts all the rules it looks up at once.
279
243
  const instantiateRule = (
280
244
  state: BlastState,
281
245
  vars: readonly VarRef[],
@@ -295,7 +259,6 @@ const instantiateRule = (
295
259
  : new InstantiatedRule(state, rule, isIntro, template, template.major, skolems);
296
260
  };
297
261
 
298
- // Too flexible assertions or goals, such as those of (!!P. ~P) ==> 0 == 1.
299
262
  const isVarForm = (state: BlastState, term: BlastTerm) =>
300
263
  term.kind === "Var" || destConstApp(term, state.context.data.notName)?.kind === "Var";
301
264
 
@@ -325,6 +288,5 @@ export const netMkRules = (
325
288
  return rules;
326
289
  };
327
290
 
328
- // Converts *Goal* to a negated assumption in first position.
329
291
  export const negOfGoalTac = (state: BlastState): GoalTactic =>
330
292
  thenGoal(resolveTac(state.context.limits, [state.context.data.ccontr]), rotateTac(-1));
@@ -1,8 +1,4 @@
1
- // Ported from Isabelle2025's Provers/blast.ML. Copyright (c) 1986-2025 University of Cambridge,
2
- // Technische Universitaet Muenchen, and contributors, see LICENSE.
3
- //
4
- // The object logic's data for blast, and the state of one search: the names of its Skolem
5
- // constants and the trail of variable assignments that backtracking undoes.
1
+ // Ported from Isabelle2025's Provers/blast.ML. Copyright (c) 1986-2025 University of Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
6
2
 
7
3
  import { bumpInit, bumpString } from "../../pure/name";
8
4
  import type { GoalTactic } from "../../pure/tactical";
@@ -13,19 +9,14 @@ import type { Claset } from "../classical";
13
9
  import type { RuleTemplate } from "./rules";
14
10
  import { blastAconv, varOccur, wkNorm, type BlastTerm, type ConstType, type VarRef } from "./term";
15
11
 
16
- // BLAST_DATA, with the two rules of other structures that blast uses.
17
12
  export interface BlastData {
18
13
  readonly trueprop: string;
19
14
  readonly equalityName: string;
20
15
  readonly notName: string;
21
- // ~P ==> P ==> R
22
16
  readonly notE: Thm;
23
- // (~P ==> False) ==> P
24
17
  readonly ccontr: Thm;
25
18
  readonly hypSubstTac: (limits: Limits) => GoalTactic;
26
- // The classical reasoner's (~P ==> P) ==> P, which Classical.dup_intr resolves with.
27
19
  readonly classical: Thm;
28
- // The atomize rules of Object_Logic, newest first, for atomize_prems_tac.
29
20
  readonly atomize: readonly Thm[];
30
21
  }
31
22
 
@@ -33,20 +24,16 @@ export interface BlastContext {
33
24
  readonly limits: Limits;
34
25
  readonly claset: Claset;
35
26
  readonly data: BlastData;
36
- // The constants' declared types, for Sign.const_typargs.
37
27
  readonly consts: ReadonlyMap<string, ConstType>;
38
- // The elimination and introduction rules converted to tableau rules so far.
39
28
  readonly elimTemplates: WeakMap<Thm, RuleTemplate>;
40
29
  readonly introTemplates: WeakMap<Thm, RuleTemplate>;
41
30
  }
42
31
 
43
- // A formula pending on a branch, with its may-duplicate flag.
44
32
  export interface Formula {
45
33
  readonly term: BlastTerm;
46
34
  readonly md: boolean;
47
35
  }
48
36
 
49
- // The safe and unsafe formulae of one level of a branch.
50
37
  export interface Level {
51
38
  readonly safe: readonly Formula[];
52
39
  readonly unsafe: readonly Formula[];
@@ -54,16 +41,11 @@ export interface Level {
54
41
 
55
42
  export interface Branch {
56
43
  readonly pairs: readonly Level[];
57
- // Literals: irreducible formulae.
58
44
  readonly lits: readonly BlastTerm[];
59
- // The variables occurring in the branch.
60
45
  readonly vars: readonly VarRef[];
61
- // The resource limit.
62
46
  readonly lim: number;
63
47
  }
64
48
 
65
- // A choice point: the trail length and branch count when it was made, and the token its handler
66
- // catches. The token is undefined for PROVE, the end of the search.
67
49
  export interface Choice {
68
50
  readonly ntrl: number;
69
51
  readonly nbrs: number;
@@ -72,14 +54,11 @@ export interface Choice {
72
54
 
73
55
  export interface BlastState {
74
56
  readonly context: BlastContext;
75
- // The used names with their latest renaming, a Name.context updated in place.
76
57
  readonly names: Map<string, string | undefined>;
77
- // The assigned variables, latest last, so that the trail's length is ntrail.
78
58
  readonly trail: VarRef[];
79
59
  }
80
60
 
81
- // Raising the exception of a choice point: unwinds to the handler that owns the token. Not an
82
- // Error, since backtracking is frequent and needs no stack trace.
61
+ // Not an Error: backtracking is frequent and needs no stack trace.
83
62
  class Backtrack {
84
63
  readonly token: object | undefined;
85
64
  constructor(token: object | undefined) {
@@ -87,7 +66,6 @@ class Backtrack {
87
66
  }
88
67
  }
89
68
 
90
- // The choice points, latest first. The last is PROVE's.
91
69
  export type Choices = List<Choice> | undefined;
92
70
 
93
71
  export const isBacktrackTo = (error: unknown, token: object | undefined) =>
@@ -97,7 +75,6 @@ export const backtrack = (choices: Choices): never => {
97
75
  throw new Backtrack(choices?.head.token);
98
76
  };
99
77
 
100
- // Name.variant on the state's names, for names without trailing underscores.
101
78
  export const gensym = (state: BlastState, name: string) => {
102
79
  const names = state.names;
103
80
  if (!names.has(name)) {
@@ -112,7 +89,6 @@ export const gensym = (state: BlastState, name: string) => {
112
89
  return current;
113
90
  };
114
91
 
115
- // Restores the trail to a previous length, for backtracking.
116
92
  export const clearTo = (state: BlastState, count: number) => {
117
93
  while (state.trail.length > count) {
118
94
  const ref = state.trail.pop();
@@ -120,8 +96,6 @@ export const clearTo = (state: BlastState, count: number) => {
120
96
  }
121
97
  };
122
98
 
123
- // First-order unification with bound variables. The variables of vars are local to a rule: their
124
- // assignments are not trailed.
125
99
  const updateVar = (
126
100
  state: BlastState,
127
101
  vars: readonly VarRef[],
@@ -1,9 +1,4 @@
1
- // Ported from Isabelle2025's Provers/blast.ML. Copyright (c) 1986-2025 University of Cambridge,
2
- // Technische Universitaet Muenchen, and contributors, see LICENSE.
3
- //
4
- // Blast's prototerms: untyped terms whose variables are mutable references, so that unification
5
- // updates them in place and backtracking resets them from the trail. Constants carry their type
6
- // arguments as terms, so that overloading is tracked faithfully.
1
+ // Ported from Isabelle2025's Provers/blast.ML. Copyright (c) 1986-2025 University of Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
7
2
 
8
3
  import { typargs, type TypargPosition } from "../../pure/consts";
9
4
  import {
@@ -17,14 +12,11 @@ import {
17
12
  type Typ,
18
13
  } from "../../pure/term";
19
14
 
20
- // A variable's assignment: term option Unsynchronized.ref, compared by identity.
21
15
  export interface VarRef {
22
16
  value: BlastTerm | undefined;
23
17
  }
24
18
 
25
- // The fields of every kind of prototerm. A prototerm has all of them, with the ones its kind
26
- // doesn't use undefined, and the constructors below list them in this order. So all prototerms
27
- // share one object layout, and V8 compiles the many switches on kind to monomorphic loads.
19
+ // Every prototerm lists every field in this order, unused ones undefined, so V8 sees one object layout.
28
20
  interface Fields {
29
21
  readonly name: string;
30
22
  readonly typargs: readonly BlastTerm[];
@@ -140,7 +132,6 @@ export const mkBlastApp = (fun: BlastTerm, arg: BlastTerm): BlastTerm => ({
140
132
  export const listBlastComb = (head: BlastTerm, args: readonly BlastTerm[]) =>
141
133
  args.reduce((result, arg) => mkBlastApp(result, arg), head);
142
134
 
143
- // Const (c, _) $ t: the argument of a constant applied to one term, if the term is one.
144
135
  export const destConstApp = (term: BlastTerm, name: string): BlastTerm | undefined =>
145
136
  term.kind === "App" && term.fun.kind === "Const" && term.fun.name === name ? term.arg : undefined;
146
137
 
@@ -148,7 +139,6 @@ export const mkGoal = (term: BlastTerm) => mkBlastApp(mkBlastConst(GOAL_NAME), t
148
139
 
149
140
  export const isGoal = (term: BlastTerm) => destConstApp(term, GOAL_NAME) !== undefined;
150
141
 
151
- // Tests whether two terms are alpha-convertible, chasing instantiations.
152
142
  export const blastAconv = (left: BlastTerm, right: BlastTerm): boolean => {
153
143
  if (left === right) return true;
154
144
  if (left.kind === "Const" && right.kind === "Const")
@@ -169,21 +159,15 @@ export const blastAconv = (left: BlastTerm, right: BlastTerm): boolean => {
169
159
  const blastAconvs = (lefts: readonly BlastTerm[], rights: readonly BlastTerm[]) =>
170
160
  lefts.length === rights.length && lefts.every((left, index) => blastAconv(left, rights[index]));
171
161
 
172
- const memTerm = (term: BlastTerm, terms: readonly BlastTerm[]) =>
173
- terms.some((other) => blastAconv(term, other));
174
-
175
162
  export const insTerm = (term: BlastTerm, terms: readonly BlastTerm[]) =>
176
- memTerm(term, terms) ? terms : [term, ...terms];
163
+ terms.some((other) => blastAconv(term, other)) ? terms : [term, ...terms];
177
164
 
178
165
  export const sameVars = (left: readonly VarRef[], right: readonly VarRef[]) =>
179
166
  left.length === right.length && left.every((ref, index) => ref === right[index]);
180
167
 
181
- const memVar = (ref: VarRef, refs: readonly VarRef[]) => refs.includes(ref);
182
-
183
168
  const insVar = (ref: VarRef, refs: readonly VarRef[]) =>
184
- memVar(ref, refs) ? refs : [ref, ...refs];
169
+ refs.includes(ref) ? refs : [ref, ...refs];
185
170
 
186
- // Accumulates the unassigned variables of a term, suppressing duplicates.
187
171
  export const addTermVars = (term: BlastTerm, refs: readonly VarRef[]): readonly VarRef[] => {
188
172
  switch (term.kind) {
189
173
  case "Skolem":
@@ -213,7 +197,6 @@ const addVarsVars = (vars: readonly VarRef[], refs: readonly VarRef[]) =>
213
197
  refs,
214
198
  );
215
199
 
216
- // Chases the assignments of the variables, returning the unassigned ones.
217
200
  export const varsInVars = (refs: readonly VarRef[]) => addVarsVars(refs, []);
218
201
 
219
202
  const incrBv = (increment: number, level: number, term: BlastTerm): BlastTerm => {
@@ -232,7 +215,6 @@ const incrBv = (increment: number, level: number, term: BlastTerm): BlastTerm =>
232
215
  export const incrBlastBoundvars = (increment: number, term: BlastTerm) =>
233
216
  increment === 0 ? term : incrBv(increment, 0, term);
234
217
 
235
- // member (op =) (loose_bnos term) 0, which does not chase variables.
236
218
  export const hasLooseBound0 = (term: BlastTerm, level = 0): boolean => {
237
219
  switch (term.kind) {
238
220
  case "Bound":
@@ -262,8 +244,6 @@ const substBoundAt = (arg: BlastTerm, level: number, term: BlastTerm): BlastTerm
262
244
 
263
245
  export const blastSubstBound = (arg: BlastTerm, body: BlastTerm) => substBoundAt(arg, 0, body);
264
246
 
265
- // Normalizes, but not the bodies of abstractions. Returns the very same term where nothing
266
- // changes, so normalizing a normal formula allocates nothing.
267
247
  export const norm = (term: BlastTerm): BlastTerm => {
268
248
  switch (term.kind) {
269
249
  case "Skolem": {
@@ -319,7 +299,6 @@ const wkNormAux = (term: BlastTerm): BlastTerm => {
319
299
  }
320
300
  };
321
301
 
322
- // Weak, one-level normalization for unification; eta-contracts where it can.
323
302
  export const wkNorm = (term: BlastTerm): BlastTerm => {
324
303
  const head = blastHeadOf(term);
325
304
  return head.kind === "Const" || head.kind === "Skolem" || head.kind === "Free"
@@ -327,7 +306,6 @@ export const wkNorm = (term: BlastTerm): BlastTerm => {
327
306
  : wkNormAux(term);
328
307
  };
329
308
 
330
- // Does variable ref occur in term? Dangling bound variables count as occurrences too.
331
309
  const occurs = (ref: VarRef, level: number, term: BlastTerm): boolean => {
332
310
  switch (term.kind) {
333
311
  case "Var":
@@ -351,14 +329,12 @@ const occurs = (ref: VarRef, level: number, term: BlastTerm): boolean => {
351
329
 
352
330
  export const varOccur = (ref: VarRef, term: BlastTerm) => occurs(ref, 0, term);
353
331
 
354
- // An entry of the association lists from schematic variables to prototerms that fromTerm keeps.
355
332
  export interface VarEntry {
356
333
  readonly name: string;
357
334
  readonly index: number;
358
335
  readonly term: BlastTerm;
359
336
  }
360
337
 
361
- // AList.lookup, adding a fresh variable for a new one.
362
338
  const lookupVar = (entries: VarEntry[], name: string, index: number): BlastTerm => {
363
339
  const known = entries.find((entry) => entry.index === index && entry.name === name);
364
340
  if (known !== undefined) return known.term;
@@ -384,7 +360,6 @@ export const fromConst = (
384
360
  type: Typ,
385
361
  ) => {
386
362
  const declared = consts.get(name);
387
- // Sign.const_typargs. Constants the map lacks are the ones a theory declares, which have none.
388
363
  return declared === undefined || declared.typargs.length === 0
389
364
  ? mkBlastConst(name)
390
365
  : mkBlastConst(
@@ -425,12 +400,9 @@ const fromTermAux = (
425
400
  }
426
401
  };
427
402
 
428
- // Converts a real term to a prototerm, eta-contracting it.
429
403
  export const fromTerm = (consts: ReadonlyMap<string, ConstType>, term: Term): BlastTerm =>
430
404
  fromTermAux(consts, [], [], term);
431
405
 
432
- // A prototerm with its variables and Skolem terms numbered, so that instantiating it with fresh
433
- // ones gives a copy that shares the parts without them, which blast never updates.
434
406
  export type Template =
435
407
  | { readonly kind: "ground"; readonly term: BlastTerm }
436
408
  | { readonly kind: "var"; readonly index: number }
@@ -441,7 +413,6 @@ export type Template =
441
413
 
442
414
  const isGround = (template: Template) => template.kind === "ground";
443
415
 
444
- // Numbers the variables in refs, adding new ones, and the Skolem terms by their place in skolems.
445
416
  export const toTemplate = (
446
417
  refs: VarRef[],
447
418
  skolems: readonly BlastTerm[],
@@ -507,7 +478,6 @@ export const instantiateTemplate = (
507
478
 
508
479
  const dummyVar = mkVar("etc", 0, dummyT);
509
480
 
510
- // Converts a prototerm to a real term with dummy types for net lookup, stopping at depth.
511
481
  export const toTerm = (depth: number, term: BlastTerm): Term => {
512
482
  if (depth === 0) return dummyVar;
513
483
  switch (term.kind) {
@@ -527,7 +497,6 @@ export const toTerm = (depth: number, term: BlastTerm): Term => {
527
497
 
528
498
  const stripTrueprop = (trueprop: string, term: BlastTerm) => destConstApp(term, trueprop) ?? term;
529
499
 
530
- // A1 ==> ... ==> An ==> B goes to [A1, ..., An], where B is not an implication.
531
500
  export const stripBlastImpPrems = (trueprop: string, term: BlastTerm): BlastTerm[] =>
532
501
  term.kind === "App" &&
533
502
  term.fun.kind === "App" &&
@@ -536,7 +505,6 @@ export const stripBlastImpPrems = (trueprop: string, term: BlastTerm): BlastTerm
536
505
  ? [stripTrueprop(trueprop, term.fun.arg), ...stripBlastImpPrems(trueprop, term.arg)]
537
506
  : [];
538
507
 
539
- // A1 ==> ... ==> An ==> B goes to B, where B is not an implication.
540
508
  export const stripBlastImpConcl = (trueprop: string, term: BlastTerm): BlastTerm =>
541
509
  term.kind === "App" &&
542
510
  term.fun.kind === "App" &&
@@ -544,3 +512,8 @@ export const stripBlastImpConcl = (trueprop: string, term: BlastTerm): BlastTerm
544
512
  term.fun.fun.name === "Pure.imp"
545
513
  ? stripBlastImpConcl(trueprop, term.arg)
546
514
  : stripTrueprop(trueprop, term);
515
+
516
+ export const splitGoalPrems = (trueprop: string, term: BlastTerm): BlastTerm[] => [
517
+ mkGoal(stripBlastImpConcl(trueprop, term)),
518
+ ...stripBlastImpPrems(trueprop, term),
519
+ ];