tla-ts 0.0.4-dev.0be9567 → 0.0.4-dev.2a873ee

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 (320) hide show
  1. package/README.md +37 -126
  2. package/dist/deciders.cjs +366 -0
  3. package/dist/deciders.js +366 -0
  4. package/dist/index.cjs +1 -1
  5. package/dist/index.d.cts +33 -1
  6. package/dist/index.d.ts +33 -1
  7. package/dist/index.js +1 -1
  8. package/dist/parallel-worker.cjs +1 -4
  9. package/dist/parallel-worker.js +1 -4
  10. package/dist/prove-worker.cjs +9 -0
  11. package/dist/prove-worker.d.cts +9 -0
  12. package/dist/prove-worker.d.ts +9 -0
  13. package/dist/prove-worker.js +9 -0
  14. package/dist/prove.cjs +996 -0
  15. package/dist/prove.js +996 -0
  16. package/dist/run-cli.cjs +37 -47
  17. package/dist/run-cli.js +37 -47
  18. package/dist/tlapm.cjs +10 -0
  19. package/dist/tlapm.js +10 -0
  20. package/dist/transfer.cjs +38 -44
  21. package/dist/transfer.js +38 -44
  22. package/dist/worker.cjs +21 -0
  23. package/dist/worker.js +21 -0
  24. package/package.json +21 -12
  25. package/src/ast.ts +2 -2
  26. package/src/check.ts +1 -0
  27. package/src/cli-options.ts +1 -1
  28. package/src/errors.ts +88 -29
  29. package/src/evaluate.ts +56 -21
  30. package/src/index.ts +10 -0
  31. package/src/live-check.ts +1 -1
  32. package/src/{obligation-action.ts → obligations/action.ts} +247 -69
  33. package/src/{obligation-anon.ts → obligations/anon.ts} +49 -47
  34. package/src/obligations/ctx.ts +64 -0
  35. package/src/{obligation-deref.ts → obligations/deref.ts} +51 -92
  36. package/src/{obligation-expression.ts → obligations/expression.ts} +117 -57
  37. package/src/{obligation-format.ts → obligations/format.ts} +7 -8
  38. package/src/{obligation-generate.ts → obligations/generate.ts} +170 -192
  39. package/src/{obligations.ts → obligations/index.ts} +32 -16
  40. package/src/{obligation-levels.ts → obligations/levels.ts} +26 -28
  41. package/src/{obligation-module.ts → obligations/module.ts} +113 -121
  42. package/src/obligations/pickle.ts +98 -0
  43. package/src/obligations/pragma.ts +189 -0
  44. package/src/{obligation-printer.ts → obligations/printer.ts} +22 -80
  45. package/src/{obligation-proof.ts → obligations/proof.ts} +7 -2
  46. package/src/{obligation-source.ts → obligations/source.ts} +154 -99
  47. package/src/obligations/temporal.ts +321 -0
  48. package/src/{obligation-tuples.ts → obligations/tuples.ts} +38 -54
  49. package/src/ocaml-marshal.ts +166 -0
  50. package/src/parallel-worker.ts +2 -18
  51. package/src/parallel.ts +10 -43
  52. package/src/prove/decide-pool.ts +95 -0
  53. package/src/prove/deciders.ts +33 -0
  54. package/src/prove/first-order.ts +78 -0
  55. package/src/prove/isabelle/LICENSE +36 -0
  56. package/src/prove/isabelle/LICENSE-tlapm +26 -0
  57. package/src/prove/isabelle/decide.ts +47 -0
  58. package/src/prove/isabelle/encode.ts +446 -0
  59. package/src/prove/isabelle/isar/inner-syntax.ts +579 -0
  60. package/src/prove/isabelle/isar/method.ts +367 -0
  61. package/src/prove/isabelle/isar/proof.ts +28 -0
  62. package/src/prove/isabelle/isar/statement.ts +57 -0
  63. package/src/prove/isabelle/isar/theory.ts +192 -0
  64. package/src/prove/isabelle/isar/type-check.ts +278 -0
  65. package/src/prove/isabelle/provers/blast/blast.ts +258 -0
  66. package/src/prove/isabelle/provers/blast/branch.ts +322 -0
  67. package/src/prove/isabelle/provers/blast/prove.ts +347 -0
  68. package/src/prove/isabelle/provers/blast/rules.ts +330 -0
  69. package/src/prove/isabelle/provers/blast/state.ts +180 -0
  70. package/src/prove/isabelle/provers/blast/term.ts +546 -0
  71. package/src/prove/isabelle/provers/clasimp.ts +150 -0
  72. package/src/prove/isabelle/provers/classical.ts +389 -0
  73. package/src/prove/isabelle/provers/hypsubst.ts +433 -0
  74. package/src/prove/isabelle/pure/bicompose.ts +174 -0
  75. package/src/prove/isabelle/pure/consts.ts +32 -0
  76. package/src/prove/isabelle/pure/conv.ts +79 -0
  77. package/src/prove/isabelle/pure/drule.ts +264 -0
  78. package/src/prove/isabelle/pure/envir.ts +331 -0
  79. package/src/prove/isabelle/pure/goal.ts +53 -0
  80. package/src/prove/isabelle/pure/interrupt.ts +16 -0
  81. package/src/prove/isabelle/pure/list.ts +12 -0
  82. package/src/prove/isabelle/pure/logic.ts +330 -0
  83. package/src/prove/isabelle/pure/name.ts +98 -0
  84. package/src/prove/isabelle/pure/net.ts +215 -0
  85. package/src/prove/isabelle/pure/object-logic.ts +41 -0
  86. package/src/prove/isabelle/pure/pattern.ts +631 -0
  87. package/src/prove/isabelle/pure/raw-simplifier.ts +338 -0
  88. package/src/prove/isabelle/pure/rewriter.ts +602 -0
  89. package/src/prove/isabelle/pure/search.ts +68 -0
  90. package/src/prove/isabelle/pure/seq.ts +133 -0
  91. package/src/prove/isabelle/pure/simplifier.ts +106 -0
  92. package/src/prove/isabelle/pure/table.ts +201 -0
  93. package/src/prove/isabelle/pure/tactic.ts +168 -0
  94. package/src/prove/isabelle/pure/tactical.ts +264 -0
  95. package/src/prove/isabelle/pure/term-ord.ts +105 -0
  96. package/src/prove/isabelle/pure/term.ts +688 -0
  97. package/src/prove/isabelle/pure/thm.ts +783 -0
  98. package/src/prove/isabelle/pure/type.ts +121 -0
  99. package/src/prove/isabelle/pure/unify.ts +753 -0
  100. package/src/prove/isabelle/pure/variable.ts +25 -0
  101. package/src/prove/isabelle/tla/classical-setup.ts +101 -0
  102. package/src/prove/isabelle/tla/context.ts +74 -0
  103. package/src/prove/isabelle/tla/logic-data.ts +5 -0
  104. package/src/prove/isabelle/tla/logic.ts +215 -0
  105. package/src/prove/isabelle/tla/simpdata.ts +241 -0
  106. package/src/prove/isabelle/tools/intuitionistic.ts +132 -0
  107. package/src/prove/ocaml.ts +22 -0
  108. package/src/prove/prep/action.ts +508 -0
  109. package/src/prove/prep/defs.ts +33 -0
  110. package/src/prove/prep/elab.ts +156 -0
  111. package/src/prove/prep/enabled-axioms.ts +189 -0
  112. package/src/prove/prep/enabled.ts +43 -0
  113. package/src/prove/prep/fingerprint.ts +388 -0
  114. package/src/prove/prep/flatten.ts +70 -0
  115. package/src/prove/prep/level-comparison.ts +529 -0
  116. package/src/prove/prep/md5.ts +67 -0
  117. package/src/prove/prep/pragma.ts +221 -0
  118. package/src/prove/prep/trivial.ts +22 -0
  119. package/src/prove/prove-worker.ts +22 -0
  120. package/src/prove/prove.ts +498 -0
  121. package/src/prove/ptl/decide.ts +68 -0
  122. package/src/prove/ptl/encode.ts +255 -0
  123. package/src/prove/ptl/sat.ts +151 -0
  124. package/src/prove/ptl/tableau.ts +276 -0
  125. package/src/prove/smt/axiomatize.ts +69 -0
  126. package/src/prove/smt/axioms.ts +209 -0
  127. package/src/prove/smt/context.ts +108 -0
  128. package/src/prove/smt/data.ts +636 -0
  129. package/src/prove/smt/encode.ts +164 -0
  130. package/src/prove/smt/extensionality.ts +65 -0
  131. package/src/prove/smt/flatten.ts +112 -0
  132. package/src/prove/smt/format.ts +154 -0
  133. package/src/prove/smt/instances.ts +181 -0
  134. package/src/prove/smt/rewrite.ts +772 -0
  135. package/src/prove/smt/simplify.ts +57 -0
  136. package/src/prove/smt/solver/act-cache.ts +265 -0
  137. package/src/prove/smt/solver/arith-rewriter.ts +962 -0
  138. package/src/prove/smt/solver/array.ts +22 -0
  139. package/src/prove/smt/solver/asserted-formulas.ts +469 -0
  140. package/src/prove/smt/solver/ast-lt.ts +157 -0
  141. package/src/prove/smt/solver/ast-util.ts +91 -0
  142. package/src/prove/smt/solver/ast.ts +1315 -0
  143. package/src/prove/smt/solver/auf-solver.ts +572 -0
  144. package/src/prove/smt/solver/case-split-queue.ts +178 -0
  145. package/src/prove/smt/solver/cg-table.ts +175 -0
  146. package/src/prove/smt/solver/clause.ts +276 -0
  147. package/src/prove/smt/solver/conflict-resolution.ts +343 -0
  148. package/src/prove/smt/solver/context.ts +1292 -0
  149. package/src/prove/smt/solver/ctx-simplify.ts +334 -0
  150. package/src/prove/smt/solver/der.ts +224 -0
  151. package/src/prove/smt/solver/dyn-ack.ts +141 -0
  152. package/src/prove/smt/solver/e-matching.ts +659 -0
  153. package/src/prove/smt/solver/enode.ts +259 -0
  154. package/src/prove/smt/solver/expr-ref.ts +21 -0
  155. package/src/prove/smt/solver/expr-safe-replace.ts +172 -0
  156. package/src/prove/smt/solver/fingerprints.ts +92 -0
  157. package/src/prove/smt/solver/flat-literals.ts +51 -0
  158. package/src/prove/smt/solver/goal.ts +138 -0
  159. package/src/prove/smt/solver/hash.ts +173 -0
  160. package/src/prove/smt/solver/hashtable.ts +166 -0
  161. package/src/prove/smt/solver/internalizer.ts +1381 -0
  162. package/src/prove/smt/solver/lbool.ts +5 -0
  163. package/src/prove/smt/solver/literal.ts +24 -0
  164. package/src/prove/smt/solver/lp/bound-propagator.ts +391 -0
  165. package/src/prove/smt/solver/lp/constraints.ts +78 -0
  166. package/src/prove/smt/solver/lp/containers.ts +296 -0
  167. package/src/prove/smt/solver/lp/core-solver.ts +504 -0
  168. package/src/prove/smt/solver/lp/cross-nested.ts +224 -0
  169. package/src/prove/smt/solver/lp/dep-intervals.ts +642 -0
  170. package/src/prove/smt/solver/lp/dependency.ts +51 -0
  171. package/src/prove/smt/solver/lp/dioph-eq.ts +1181 -0
  172. package/src/prove/smt/solver/lp/explanation.ts +46 -0
  173. package/src/prove/smt/solver/lp/gomory.ts +255 -0
  174. package/src/prove/smt/solver/lp/hnf-cutter.ts +125 -0
  175. package/src/prove/smt/solver/lp/hnf.ts +281 -0
  176. package/src/prove/smt/solver/lp/int-cube.ts +295 -0
  177. package/src/prove/smt/solver/lp/int-solver.ts +514 -0
  178. package/src/prove/smt/solver/lp/lar-solver.ts +816 -0
  179. package/src/prove/smt/solver/lp/lar-term.ts +62 -0
  180. package/src/prove/smt/solver/lp/lp-settings.ts +91 -0
  181. package/src/prove/smt/solver/lp/maximize-term.ts +347 -0
  182. package/src/prove/smt/solver/lp/nex-creator.ts +381 -0
  183. package/src/prove/smt/solver/lp/nex.ts +120 -0
  184. package/src/prove/smt/solver/lp/nla-backoff.ts +43 -0
  185. package/src/prove/smt/solver/lp/nla-basics.ts +398 -0
  186. package/src/prove/smt/solver/lp/nla-core.ts +968 -0
  187. package/src/prove/smt/solver/lp/nla-divisions.ts +332 -0
  188. package/src/prove/smt/solver/lp/nla-emonics.ts +373 -0
  189. package/src/prove/smt/solver/lp/nla-factorization.ts +30 -0
  190. package/src/prove/smt/solver/lp/nla-grobner.ts +904 -0
  191. package/src/prove/smt/solver/lp/nla-horner.ts +126 -0
  192. package/src/prove/smt/solver/lp/nla-intervals.ts +265 -0
  193. package/src/prove/smt/solver/lp/nla-monomial-bounds.ts +715 -0
  194. package/src/prove/smt/solver/lp/nla-monotone.ts +59 -0
  195. package/src/prove/smt/solver/lp/nla-order.ts +307 -0
  196. package/src/prove/smt/solver/lp/nla-patcher.ts +112 -0
  197. package/src/prove/smt/solver/lp/nla-tangents.ts +251 -0
  198. package/src/prove/smt/solver/lp/nla-throttle.ts +85 -0
  199. package/src/prove/smt/solver/lp/nla-types.ts +124 -0
  200. package/src/prove/smt/solver/lp/nla-var-eqs.ts +141 -0
  201. package/src/prove/smt/solver/lp/nra-solver.ts +440 -0
  202. package/src/prove/smt/solver/lp/numeric-pair.ts +65 -0
  203. package/src/prove/smt/solver/lp/pdd-interval.ts +31 -0
  204. package/src/prove/smt/solver/lp/pdd-simplifier.ts +184 -0
  205. package/src/prove/smt/solver/lp/pdd-solver.ts +408 -0
  206. package/src/prove/smt/solver/lp/pdd.ts +971 -0
  207. package/src/prove/smt/solver/lp/random-updater.ts +138 -0
  208. package/src/prove/smt/solver/lp/static-matrix.ts +246 -0
  209. package/src/prove/smt/solver/lp/union-find.ts +96 -0
  210. package/src/prove/smt/solver/mam-compiler.ts +847 -0
  211. package/src/prove/smt/solver/mam-interpreter.ts +400 -0
  212. package/src/prove/smt/solver/maximize-ac-sharing.ts +118 -0
  213. package/src/prove/smt/solver/model-checker.ts +347 -0
  214. package/src/prove/smt/solver/model-evaluator.ts +262 -0
  215. package/src/prove/smt/solver/model-finder.ts +155 -0
  216. package/src/prove/smt/solver/model-generator.ts +97 -0
  217. package/src/prove/smt/solver/model-macro-solver.ts +728 -0
  218. package/src/prove/smt/solver/nlsat/algebraic.ts +1161 -0
  219. package/src/prove/smt/solver/nlsat/atoms.ts +238 -0
  220. package/src/prove/smt/solver/nlsat/evaluator.ts +303 -0
  221. package/src/prove/smt/solver/nlsat/explain.ts +607 -0
  222. package/src/prove/smt/solver/nlsat/interval-set.ts +351 -0
  223. package/src/prove/smt/solver/nlsat/levelwise.ts +737 -0
  224. package/src/prove/smt/solver/nlsat/mpbq.ts +161 -0
  225. package/src/prove/smt/solver/nlsat/polynomial.ts +1722 -0
  226. package/src/prove/smt/solver/nlsat/solver.ts +911 -0
  227. package/src/prove/smt/solver/nlsat/types.ts +43 -0
  228. package/src/prove/smt/solver/nlsat/upolynomial-factorization.ts +648 -0
  229. package/src/prove/smt/solver/nlsat/upolynomial.ts +996 -0
  230. package/src/prove/smt/solver/nnf.ts +469 -0
  231. package/src/prove/smt/solver/pattern-inference.ts +351 -0
  232. package/src/prove/smt/solver/poly-rewriter.ts +477 -0
  233. package/src/prove/smt/solver/propagate-values.ts +83 -0
  234. package/src/prove/smt/solver/proto-model.ts +551 -0
  235. package/src/prove/smt/solver/pull-quant.ts +139 -0
  236. package/src/prove/smt/solver/qe-lite-der.ts +526 -0
  237. package/src/prove/smt/solver/qe-lite-fm.ts +576 -0
  238. package/src/prove/smt/solver/qe-lite.ts +381 -0
  239. package/src/prove/smt/solver/qi-queue.ts +362 -0
  240. package/src/prove/smt/solver/quant-tactics.ts +117 -0
  241. package/src/prove/smt/solver/quantifier-analyzer.ts +562 -0
  242. package/src/prove/smt/solver/quantifier-manager.ts +186 -0
  243. package/src/prove/smt/solver/random-gen.ts +10 -0
  244. package/src/prove/smt/solver/rational.ts +165 -0
  245. package/src/prove/smt/solver/ref-vector.ts +62 -0
  246. package/src/prove/smt/solver/relevancy.ts +247 -0
  247. package/src/prove/smt/solver/rewriter-tpl.ts +1159 -0
  248. package/src/prove/smt/solver/rewriter.ts +843 -0
  249. package/src/prove/smt/solver/rlimit.ts +79 -0
  250. package/src/prove/smt/solver/smtlib-parser.ts +526 -0
  251. package/src/prove/smt/solver/solver.ts +71 -0
  252. package/src/prove/smt/solver/sort.ts +35 -0
  253. package/src/prove/smt/solver/sticky-generations.ts +69 -0
  254. package/src/prove/smt/solver/theory-lra-axioms.ts +340 -0
  255. package/src/prove/smt/solver/theory-lra-bounds.ts +226 -0
  256. package/src/prove/smt/solver/theory-lra-final-check.ts +252 -0
  257. package/src/prove/smt/solver/theory-lra-internalize.ts +476 -0
  258. package/src/prove/smt/solver/theory-lra-model.ts +243 -0
  259. package/src/prove/smt/solver/theory-lra-propagate.ts +405 -0
  260. package/src/prove/smt/solver/theory-lra-state.ts +43 -0
  261. package/src/prove/smt/solver/theory-lra.ts +56 -0
  262. package/src/prove/smt/solver/var-subst.ts +258 -0
  263. package/src/prove/smt/solver/z3-license.txt +10 -0
  264. package/src/prove/smt/table.ts +170 -0
  265. package/src/prove/tlapm/tlapm.ts +96 -0
  266. package/src/prove/tlaps-module.ts +510 -0
  267. package/src/prove/verdict.ts +18 -0
  268. package/src/prove/zenon/LICENSE +32 -0
  269. package/src/prove/zenon/check/check.ts +105 -0
  270. package/src/prove/zenon/check/definitions.ts +144 -0
  271. package/src/prove/zenon/check/equality.ts +182 -0
  272. package/src/prove/zenon/check/functions.ts +62 -0
  273. package/src/prove/zenon/check/keys.ts +125 -0
  274. package/src/prove/zenon/check/propositional.ts +104 -0
  275. package/src/prove/zenon/check/records.ts +188 -0
  276. package/src/prove/zenon/check/relations.ts +121 -0
  277. package/src/prove/zenon/check/rewrites.ts +224 -0
  278. package/src/prove/zenon/check/sets.ts +302 -0
  279. package/src/prove/zenon/check/terms.ts +127 -0
  280. package/src/prove/zenon/check/tla.ts +126 -0
  281. package/src/prove/zenon/decide.ts +113 -0
  282. package/src/prove/zenon/encode.ts +379 -0
  283. package/src/prove/zenon/eqrel.ts +300 -0
  284. package/src/prove/zenon/equality-rules.ts +435 -0
  285. package/src/prove/zenon/expr.ts +551 -0
  286. package/src/prove/zenon/index-table.ts +350 -0
  287. package/src/prove/zenon/isar-case.ts +513 -0
  288. package/src/prove/zenon/isar.ts +1249 -0
  289. package/src/prove/zenon/limits.ts +15 -0
  290. package/src/prove/zenon/llproof.ts +173 -0
  291. package/src/prove/zenon/mltoll.ts +1566 -0
  292. package/src/prove/zenon/node.ts +297 -0
  293. package/src/prove/zenon/ocaml.ts +169 -0
  294. package/src/prove/zenon/parse.ts +247 -0
  295. package/src/prove/zenon/phrase.ts +191 -0
  296. package/src/prove/zenon/proof.ts +198 -0
  297. package/src/prove/zenon/propositional-rules.ts +387 -0
  298. package/src/prove/zenon/rules.ts +94 -0
  299. package/src/prove/zenon/search.ts +288 -0
  300. package/src/prove/zenon/tla/functions.ts +151 -0
  301. package/src/prove/zenon/tla/llproof.ts +480 -0
  302. package/src/prove/zenon/tla/records.ts +225 -0
  303. package/src/prove/zenon/tla/rewrites.ts +447 -0
  304. package/src/prove/zenon/tla/sets.ts +304 -0
  305. package/src/prove/zenon/tla/terms.ts +162 -0
  306. package/src/prove/zenon/tla/tla.ts +506 -0
  307. package/src/resolve.ts +1 -1
  308. package/src/run-cli.ts +283 -81
  309. package/src/sany-generator.ts +1 -1
  310. package/src/sany-report.ts +1 -1
  311. package/src/successors.ts +24 -5
  312. package/src/tlapm-cache.ts +236 -0
  313. package/src/tlc-random.ts +55 -32
  314. package/src/tlc-replay.ts +1 -1
  315. package/src/tlc-version.ts +8 -7
  316. package/src/values.ts +47 -4
  317. package/src/worker.ts +65 -0
  318. package/dist/parallel.cjs +0 -12
  319. package/dist/parallel.js +0 -12
  320. package/src/value-sources.ts +0 -29
@@ -0,0 +1,133 @@
1
+ // Ported from Isabelle2025's Pure/General/seq.ML. Copyright (c) 1986-2025 University of
2
+ // Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
3
+ //
4
+ // Lazy sequences. As in Isabelle, pulling a sequence twice computes its head twice.
5
+
6
+ export type Cell<Item> = readonly [Item, Seq<Item>] | undefined;
7
+
8
+ type Step<Item> = Cell<Item> | Seq<Item>;
9
+
10
+ export interface Seq<Item> {
11
+ readonly pull: () => Cell<Item>;
12
+ readonly step?: () => Step<Item>;
13
+ }
14
+
15
+ export const makeSeq = <Item>(pull: () => Cell<Item>): Seq<Item> => ({ pull });
16
+
17
+ // A sequence whose step may hand over to another sequence where Isabelle would pull it in tail
18
+ // position. Pulling follows the hand-overs in a loop, so a long run of empty alternatives, which
19
+ // Poly/ML's growing stack absorbs, doesn't exhaust this one. A class, so that pull is shared
20
+ // rather than a new closure for every sequence.
21
+ class DeferredSeq<Item> implements Seq<Item> {
22
+ readonly step: () => Step<Item>;
23
+
24
+ constructor(step: () => Step<Item>) {
25
+ this.step = step;
26
+ }
27
+
28
+ pull(): Cell<Item> {
29
+ let result = this.step();
30
+ while (result !== undefined && "pull" in result)
31
+ result = result.step === undefined ? result.pull() : result.step();
32
+ return result;
33
+ }
34
+ }
35
+
36
+ export const deferSeq = <Item>(step: () => Step<Item>): Seq<Item> => new DeferredSeq(step);
37
+
38
+ export const emptySeq: Seq<never> = makeSeq(() => undefined);
39
+
40
+ export const consSeq = <Item>(item: Item, rest: Seq<Item>): Seq<Item> =>
41
+ makeSeq(() => [item, rest]);
42
+
43
+ export const singleSeq = <Item>(item: Item): Seq<Item> => consSeq(item, emptySeq);
44
+
45
+ export const ofCell = <Item>(cell: Cell<Item>): Seq<Item> => makeSeq(() => cell);
46
+
47
+ export const seqOfList = <Item>(items: readonly Item[]): Seq<Item> =>
48
+ items.reduceRight<Seq<Item>>((rest, item) => consSeq(item, rest), emptySeq);
49
+
50
+ export const seqHead = <Item>(seq: Seq<Item>): Item | undefined => seq.pull()?.[0];
51
+
52
+ // Seq.chop: the first count elements and the rest of the sequence.
53
+ export const chopSeq = <Item>(count: number, seq: Seq<Item>): [Item[], Seq<Item>] => {
54
+ const items: Item[] = [];
55
+ let current = seq;
56
+ while (items.length < count) {
57
+ const cell = current.pull();
58
+ if (cell === undefined) return [items, current];
59
+ items.push(cell[0]);
60
+ current = cell[1];
61
+ }
62
+ return [items, current];
63
+ };
64
+
65
+ export const listOfSeq = <Item>(seq: Seq<Item>): Item[] => {
66
+ const items: Item[] = [];
67
+ let cell = seq.pull();
68
+ while (cell !== undefined) {
69
+ items.push(cell[0]);
70
+ cell = cell[1].pull();
71
+ }
72
+ return items;
73
+ };
74
+
75
+ export const appendSeq = <Item>(first: Seq<Item>, second: Seq<Item>): Seq<Item> =>
76
+ deferSeq(() => {
77
+ const cell = first.pull();
78
+ return cell === undefined ? second : [cell[0], appendSeq(cell[1], second)];
79
+ });
80
+
81
+ export const mappSeq = <Item, Result>(
82
+ map: (item: Item) => Result,
83
+ first: Seq<Item>,
84
+ second: Seq<Result>,
85
+ ): Seq<Result> => {
86
+ const copy = (current: Seq<Item>): Seq<Result> =>
87
+ deferSeq(() => {
88
+ const cell = current.pull();
89
+ return cell === undefined ? second : [map(cell[0]), copy(cell[1])];
90
+ });
91
+ return copy(first);
92
+ };
93
+
94
+ export const filterSeq = <Item>(predicate: (item: Item) => boolean, seq: Seq<Item>): Seq<Item> => {
95
+ const copy = (current: Seq<Item>): Seq<Item> =>
96
+ makeSeq(() => {
97
+ let cell = current.pull();
98
+ while (cell !== undefined && !predicate(cell[0])) cell = cell[1].pull();
99
+ return cell === undefined ? undefined : [cell[0], copy(cell[1])];
100
+ });
101
+ return copy(seq);
102
+ };
103
+
104
+ export const flatSeq = <Item>(seqs: Seq<Seq<Item>>): Seq<Item> => mapsSeq((seq) => seq, seqs);
105
+
106
+ export const mapSeq = <Item, Result>(map: (item: Item) => Result, seq: Seq<Item>): Seq<Result> =>
107
+ makeSeq(() => {
108
+ const cell = seq.pull();
109
+ return cell === undefined ? undefined : [map(cell[0]), mapSeq(map, cell[1])];
110
+ });
111
+
112
+ export const mapsSeq = <Item, Result>(
113
+ map: (item: Item) => Seq<Result>,
114
+ seq: Seq<Item>,
115
+ ): Seq<Result> =>
116
+ deferSeq(() => {
117
+ const cell = seq.pull();
118
+ return cell === undefined ? undefined : appendSeq(map(cell[0]), mapsSeq(map, cell[1]));
119
+ });
120
+
121
+ // Seq.it_right: accumulates lazily from the right.
122
+ export const itRightSeq = <Item, Result>(
123
+ combine: (item: Item, rest: Seq<Result>) => Seq<Result>,
124
+ seq: Seq<Item>,
125
+ tail: Seq<Result>,
126
+ ): Seq<Result> => {
127
+ const its = (current: Seq<Item>): Seq<Result> =>
128
+ deferSeq(() => {
129
+ const cell = current.pull();
130
+ return cell === undefined ? tail : combine(cell[0], its(cell[1]));
131
+ });
132
+ return its(seq);
133
+ };
@@ -0,0 +1,106 @@
1
+ // Ported from Isabelle2025's Pure/simplifier.ML and the PREFER_GOAL of Pure/goal.ML, the
2
+ // simplification tactics. Copyright (c) 1986-2025 University of Cambridge, Technische Universitaet
3
+ // Muenchen, and contributors, see LICENSE.
4
+
5
+ import { genAll, isNormHhf, normHhfEq } from "./drule";
6
+ import { preferGoal } from "./goal";
7
+ import { addSimps, emptySimpset, type SimpContext, type Solver } from "./raw-simplifier";
8
+ import { fconvRule } from "./conv";
9
+ import {
10
+ genericRewriteGoalTac,
11
+ rewriteCterm,
12
+ simpleProver,
13
+ type Prover,
14
+ type RewriteMode,
15
+ } from "./rewriter";
16
+ import {
17
+ depthSolve,
18
+ firstGoal,
19
+ noTac,
20
+ orElse,
21
+ thenAllNew,
22
+ thenTac,
23
+ tryTac,
24
+ type GoalTactic,
25
+ type Tactic,
26
+ } from "./tactical";
27
+ import type { Limits } from "./interrupt";
28
+ import type { Thm } from "./thm";
29
+
30
+ const withSolvers = (context: SimpContext, solvers: readonly Solver[]): SimpContext => ({
31
+ ...context,
32
+ simpset: { ...context.simpset, unsafeSolvers: solvers, safeSolvers: solvers },
33
+ });
34
+
35
+ // solve_all_tac: solves goal 1 completely with the subgoaler.
36
+ const solveAllTac = (solvers: readonly Solver[], context: SimpContext): Tactic => {
37
+ const inner = withSolvers(context, solvers);
38
+ const solveTac = thenAllNew(inner.simpset.subgoalTac(inner), () => noTac);
39
+ return depthSolve(solveTac(1));
40
+ };
41
+
42
+ const loopTac = (context: SimpContext): GoalTactic =>
43
+ firstGoal([...context.simpset.loopTacs].reverse().map((loop) => loop.tactic(context)));
44
+
45
+ const singleProver =
46
+ (solvers: readonly Solver[]): Prover =>
47
+ (context, thm) =>
48
+ solveAllTac(solvers, context)(thm).pull()?.[0];
49
+
50
+ // generic_simp_tac
51
+ const genericSimpTac =
52
+ (isSafe: boolean, mode: RewriteMode) =>
53
+ (context: SimpContext): GoalTactic =>
54
+ (index) => {
55
+ const loop = loopTac(context);
56
+ const solvers = isSafe ? context.simpset.safeSolvers : context.simpset.unsafeSolvers;
57
+ const solveTac = firstGoal([...solvers].reverse().map((solver) => solver.tactic(context)));
58
+ const simpLoopTac: GoalTactic = (goal) =>
59
+ thenTac(
60
+ genericRewriteGoalTac(mode, singleProver(context.simpset.unsafeSolvers), context, goal),
61
+ orElse(solveTac(goal), tryTac(thenAllNew(loop, simpLoopTac)(goal))),
62
+ );
63
+ return preferGoal(simpLoopTac(1))(index);
64
+ };
65
+ export const asmSimpTac = genericSimpTac(false, { simprem: false, useprem: true, mutsimp: false });
66
+ export const asmLrSimpTac = genericSimpTac(false, { simprem: true, useprem: true, mutsimp: false });
67
+ export const asmFullSimpTac = genericSimpTac(false, {
68
+ simprem: true,
69
+ useprem: true,
70
+ mutsimp: true,
71
+ });
72
+ export const safeAsmFullSimpTac = genericSimpTac(true, {
73
+ simprem: true,
74
+ useprem: true,
75
+ mutsimp: true,
76
+ });
77
+
78
+ // Simplifier.simp_thm: simplifies a theorem's proposition.
79
+ const simpThm = (mode: RewriteMode, context: SimpContext, thm: Thm): Thm => {
80
+ const prover = singleProver([...context.simpset.unsafeSolvers].reverse());
81
+ return fconvRule((term) => rewriteCterm(mode, prover, context, term), thm);
82
+ };
83
+
84
+ export const simplify = (context: SimpContext, thm: Thm) =>
85
+ simpThm({ simprem: false, useprem: false, mutsimp: false }, context, thm);
86
+
87
+ // Raw_Simplifier.norm_hhf: moves the quantifiers of a theorem left of its implications, then makes
88
+ // the outermost ones schematic. Drule.sort_constraint_eq, the other rule of hhf_ss, never applies:
89
+ // tlapm's terms carry no sort constraints.
90
+ export const normHhf = (limits: Limits, thm: Thm): Thm => {
91
+ if (isNormHhf(false, thm.prop)) return genAll(thm);
92
+ const empty = { limits, simpset: emptySimpset, bounds: 0 };
93
+ const context = { ...empty, simpset: addSimps(empty, [normHhfEq]) };
94
+ return genAll(
95
+ fconvRule(
96
+ (term) =>
97
+ rewriteCterm(
98
+ { simprem: true, useprem: false, mutsimp: false },
99
+ simpleProver,
100
+ context,
101
+ term,
102
+ ),
103
+ thm,
104
+ ),
105
+ );
106
+ };
@@ -0,0 +1,201 @@
1
+ // Ported from Isabelle2025's Pure/General/table.ML. Copyright (c) 1986-2025 University of
2
+ // Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
3
+ //
4
+ // Persistent tables ordered by a comparison function. Isabelle's tables are 2-3 trees; any
5
+ // balanced search tree visits keys in the same order, which is all that the ports rely on.
6
+
7
+ export type Compare<Key> = (left: Key, right: Key) => number;
8
+
9
+ type Node<Key, Value> =
10
+ | undefined
11
+ | {
12
+ readonly key: Key;
13
+ readonly value: Value;
14
+ readonly left: Node<Key, Value>;
15
+ readonly right: Node<Key, Value>;
16
+ readonly height: number;
17
+ };
18
+
19
+ export interface Table<Key, Value> {
20
+ readonly compare: Compare<Key>;
21
+ readonly root: Node<Key, Value>;
22
+ }
23
+
24
+ const getHeight = <Key, Value>(node: Node<Key, Value>) => (node ? node.height : 0);
25
+
26
+ const makeNode = <Key, Value>(
27
+ key: Key,
28
+ value: Value,
29
+ left: Node<Key, Value>,
30
+ right: Node<Key, Value>,
31
+ ): Node<Key, Value> => ({
32
+ key,
33
+ value,
34
+ left,
35
+ right,
36
+ height: Math.max(getHeight(left), getHeight(right)) + 1,
37
+ });
38
+
39
+ const balance = <Key, Value>(
40
+ key: Key,
41
+ value: Value,
42
+ left: Node<Key, Value>,
43
+ right: Node<Key, Value>,
44
+ ): Node<Key, Value> => {
45
+ const difference = getHeight(left) - getHeight(right);
46
+ if (difference > 1 && left) {
47
+ if (getHeight(left.left) >= getHeight(left.right))
48
+ return makeNode(left.key, left.value, left.left, makeNode(key, value, left.right, right));
49
+ const middle = left.right;
50
+ if (!middle) return makeNode(key, value, left, right);
51
+ return makeNode(
52
+ middle.key,
53
+ middle.value,
54
+ makeNode(left.key, left.value, left.left, middle.left),
55
+ makeNode(key, value, middle.right, right),
56
+ );
57
+ }
58
+ if (difference < -1 && right) {
59
+ if (getHeight(right.right) >= getHeight(right.left))
60
+ return makeNode(right.key, right.value, makeNode(key, value, left, right.left), right.right);
61
+ const middle = right.left;
62
+ if (!middle) return makeNode(key, value, left, right);
63
+ return makeNode(
64
+ middle.key,
65
+ middle.value,
66
+ makeNode(key, value, left, middle.left),
67
+ makeNode(right.key, right.value, middle.right, right.right),
68
+ );
69
+ }
70
+ return makeNode(key, value, left, right);
71
+ };
72
+
73
+ export const emptyTable = <Key, Value>(compare: Compare<Key>): Table<Key, Value> => ({
74
+ compare,
75
+ root: undefined,
76
+ });
77
+
78
+ export const isEmptyTable = <Key, Value>(table: Table<Key, Value>) => table.root === undefined;
79
+
80
+ export const lookupTable = <Key, Value>(table: Table<Key, Value>, key: Key): Value | undefined => {
81
+ let node = table.root;
82
+ while (node) {
83
+ const order = table.compare(key, node.key);
84
+ if (order === 0) return node.value;
85
+ node = order < 0 ? node.left : node.right;
86
+ }
87
+ return undefined;
88
+ };
89
+
90
+ export const hasKey = <Key, Value>(table: Table<Key, Value>, key: Key) => {
91
+ let node = table.root;
92
+ while (node) {
93
+ const order = table.compare(key, node.key);
94
+ if (order === 0) return true;
95
+ node = order < 0 ? node.left : node.right;
96
+ }
97
+ return false;
98
+ };
99
+
100
+ const insertNode = <Key, Value>(
101
+ compare: Compare<Key>,
102
+ key: Key,
103
+ value: Value,
104
+ node: Node<Key, Value>,
105
+ ): Node<Key, Value> => {
106
+ if (!node) return makeNode(key, value, undefined, undefined);
107
+ const order = compare(key, node.key);
108
+ if (order === 0) return makeNode(key, value, node.left, node.right);
109
+ return order < 0
110
+ ? balance(node.key, node.value, insertNode(compare, key, value, node.left), node.right)
111
+ : balance(node.key, node.value, node.left, insertNode(compare, key, value, node.right));
112
+ };
113
+
114
+ export const updateTable = <Key, Value>(
115
+ table: Table<Key, Value>,
116
+ key: Key,
117
+ value: Value,
118
+ ): Table<Key, Value> => ({
119
+ compare: table.compare,
120
+ root: insertNode(table.compare, key, value, table.root),
121
+ });
122
+
123
+ const removeMin = <Key, Value>(
124
+ node: NonNullable<Node<Key, Value>>,
125
+ ): [NonNullable<Node<Key, Value>>, Node<Key, Value>] => {
126
+ if (!node.left) return [node, node.right];
127
+ const [minimum, left] = removeMin(node.left);
128
+ return [minimum, balance(node.key, node.value, left, node.right)];
129
+ };
130
+
131
+ export const deleteTable = <Key, Value>(table: Table<Key, Value>, key: Key): Table<Key, Value> => {
132
+ const remove = (node: Node<Key, Value>): Node<Key, Value> => {
133
+ if (!node) return undefined;
134
+ const order = table.compare(key, node.key);
135
+ if (order < 0) return balance(node.key, node.value, remove(node.left), node.right);
136
+ if (order > 0) return balance(node.key, node.value, node.left, remove(node.right));
137
+ if (!node.right) return node.left;
138
+ const [minimum, right] = removeMin(node.right);
139
+ return balance(minimum.key, minimum.value, node.left, right);
140
+ };
141
+ return { compare: table.compare, root: remove(table.root) };
142
+ };
143
+
144
+ export const minTable = <Key, Value>(table: Table<Key, Value>): [Key, Value] | undefined => {
145
+ let node = table.root;
146
+ if (!node) return undefined;
147
+ while (node.left) node = node.left;
148
+ return [node.key, node.value];
149
+ };
150
+
151
+ const foldNode = <Key, Value, State>(
152
+ visit: (key: Key, value: Value, state: State) => State,
153
+ node: Node<Key, Value>,
154
+ state: State,
155
+ ): State =>
156
+ node
157
+ ? foldNode(visit, node.right, visit(node.key, node.value, foldNode(visit, node.left, state)))
158
+ : state;
159
+
160
+ // Table.fold: visits the entries in key order.
161
+ export const foldTable = <Key, Value, State>(
162
+ visit: (key: Key, value: Value, state: State) => State,
163
+ table: Table<Key, Value>,
164
+ state: State,
165
+ ) => foldNode(visit, table.root, state);
166
+
167
+ // The entries in key order, as Table.dest lists them.
168
+ export const tableEntries = <Key, Value>(table: Table<Key, Value>) =>
169
+ foldTable<Key, Value, [Key, Value][]>(
170
+ (key, value, entries) => {
171
+ entries.push([key, value]);
172
+ return entries;
173
+ },
174
+ table,
175
+ [],
176
+ );
177
+
178
+ // fast_string_ord: shorter strings first, then by code units.
179
+ export const fastStringOrd = (left: string, right: string) =>
180
+ left === right
181
+ ? 0
182
+ : left.length !== right.length
183
+ ? left.length - right.length
184
+ : left < right
185
+ ? -1
186
+ : 1;
187
+
188
+ const stringOrd = (left: string, right: string) => (left === right ? 0 : left < right ? -1 : 1);
189
+
190
+ export interface IndexKey {
191
+ readonly name: string;
192
+ readonly index: number;
193
+ }
194
+
195
+ // Term_Ord.fast_indexname_ord: by index, then by fast_string_ord on the name.
196
+ export const fastIndexnameOrd = (left: IndexKey, right: IndexKey) =>
197
+ left.index !== right.index ? left.index - right.index : fastStringOrd(left.name, right.name);
198
+
199
+ // Term_Ord.indexname_ord: by index, then by string_ord on the name.
200
+ export const indexnameOrd = (left: IndexKey, right: IndexKey) =>
201
+ left.index !== right.index ? left.index - right.index : stringOrd(left.name, right.name);
@@ -0,0 +1,168 @@
1
+ // Ported from Isabelle2025's Pure/tactic.ML, the basic resolution tactics. Copyright (c) 1986-2025
2
+ // University of Cambridge, Technische Universitaet Muenchen, and contributors, see LICENSE.
3
+
4
+ import { makeElim } from "./drule";
5
+ import { checkInterrupt, type Limits } from "./interrupt";
6
+ import { stripAssumsConcl, stripAssumsHyp } from "./logic";
7
+ import { insertTermNet, unifyTermNet, type Net } from "./net";
8
+ import {
9
+ assumption,
10
+ bicompose,
11
+ biresolution,
12
+ conclOf,
13
+ eqAssumption,
14
+ flexflexRule,
15
+ majorPremOf,
16
+ nprems,
17
+ rotateRule,
18
+ type BiresRule,
19
+ type Thm,
20
+ } from "./thm";
21
+ import { allTac, primitive, primSeq, subgoal, type GoalTactic, type Tactic } from "./tactical";
22
+
23
+ export const assumeTac =
24
+ (limits: Limits): GoalTactic =>
25
+ (index) =>
26
+ primSeq((state) => {
27
+ checkInterrupt(limits);
28
+ return assumption(limits, index, state);
29
+ });
30
+
31
+ export const eqAssumeTac: GoalTactic = (index) => primitive((state) => eqAssumption(index, state));
32
+
33
+ export const composeTac =
34
+ (limits: Limits, isElim: boolean, rule: Thm, subgoals: number): GoalTactic =>
35
+ (index) =>
36
+ primSeq((state) =>
37
+ bicompose(
38
+ limits,
39
+ { flatten: true, match: false, incremented: false },
40
+ { isElim, rule, subgoals },
41
+ index,
42
+ state,
43
+ ),
44
+ );
45
+
46
+ const biresolveTac =
47
+ (limits: Limits, rules: readonly BiresRule[]): GoalTactic =>
48
+ (index) =>
49
+ primSeq((state) => {
50
+ checkInterrupt(limits);
51
+ return biresolution(limits, false, rules, index, state);
52
+ });
53
+
54
+ export const resolveTac = (limits: Limits, rules: readonly Thm[]) =>
55
+ biresolveTac(
56
+ limits,
57
+ rules.map((rule) => ({ isElim: false, rule })),
58
+ );
59
+
60
+ export const eresolveTac = (limits: Limits, rules: readonly Thm[]) =>
61
+ biresolveTac(
62
+ limits,
63
+ rules.map((rule) => ({ isElim: true, rule })),
64
+ );
65
+
66
+ export const dresolveTac = (limits: Limits, rules: readonly Thm[]) =>
67
+ eresolveTac(limits, rules.map(makeElim));
68
+
69
+ const bimatchTac =
70
+ (limits: Limits, rules: readonly BiresRule[]): GoalTactic =>
71
+ (index) =>
72
+ primSeq((state) => {
73
+ checkInterrupt(limits);
74
+ return biresolution(limits, true, rules, index, state);
75
+ });
76
+
77
+ export const matchTac = (limits: Limits, rules: readonly Thm[]) =>
78
+ bimatchTac(
79
+ limits,
80
+ rules.map((rule) => ({ isElim: false, rule })),
81
+ );
82
+
83
+ export const ematchTac = (limits: Limits, rules: readonly Thm[]) =>
84
+ bimatchTac(
85
+ limits,
86
+ rules.map((rule) => ({ isElim: true, rule })),
87
+ );
88
+
89
+ export const flexflexTac = (limits: Limits): Tactic =>
90
+ primSeq((state) => flexflexRule(limits, state));
91
+
92
+ export interface TaggedRule {
93
+ readonly tag: number;
94
+ readonly isElim: boolean;
95
+ readonly rule: Thm;
96
+ }
97
+
98
+ export interface NetPair<Tagged> {
99
+ readonly intro: Net<Tagged>;
100
+ readonly elim: Net<Tagged>;
101
+ }
102
+
103
+ // Tactic.insert_tagged_brl
104
+ export const insertTaggedBrl = <Tagged extends { isElim: boolean; rule: Thm }>(
105
+ tagged: Tagged,
106
+ netpair: NetPair<Tagged>,
107
+ ): NetPair<Tagged> =>
108
+ tagged.isElim
109
+ ? { intro: netpair.intro, elim: insertTermNet(majorPremOf(tagged.rule), tagged, netpair.elim) }
110
+ : { intro: insertTermNet(conclOf(tagged.rule), tagged, netpair.intro), elim: netpair.elim };
111
+
112
+ // Library.order_list: by tag, dropping all but the last item with each tag. The lists are short,
113
+ // so this sorts them by insertion, which keeps items with equal tags in order as Isabelle's sort.
114
+ export const orderList = <Item>(items: readonly { tag: number; item: Item }[]): Item[] => {
115
+ const sorted = [...items];
116
+ for (let index = 1; index < sorted.length; index += 1) {
117
+ const entry = sorted[index];
118
+ let position = index;
119
+ for (; position > 0 && sorted[position - 1].tag > entry.tag; position -= 1)
120
+ sorted[position] = sorted[position - 1];
121
+ sorted[position] = entry;
122
+ }
123
+ const result: Item[] = [];
124
+ for (let index = 0; index < sorted.length; index += 1)
125
+ if (index + 1 === sorted.length || sorted[index + 1].tag !== sorted[index].tag)
126
+ result.push(sorted[index].item);
127
+ return result;
128
+ };
129
+
130
+ // Tactic.biresolution_from_nets_tac
131
+ export const biresolutionFromNetsTac = <Tagged extends { isElim: boolean; rule: Thm }>(
132
+ limits: Limits,
133
+ order: (rules: Tagged[]) => BiresRule[],
134
+ match: boolean,
135
+ netpair: NetPair<Tagged>,
136
+ ): GoalTactic =>
137
+ subgoal((goal, index) => {
138
+ const hyps = stripAssumsHyp(goal);
139
+ const concl = stripAssumsConcl(goal);
140
+ const rules = [
141
+ ...unifyTermNet(netpair.intro, concl),
142
+ ...hyps.flatMap((hyp) => unifyTermNet(netpair.elim, hyp)),
143
+ ];
144
+ return primSeq((state) => {
145
+ checkInterrupt(limits);
146
+ return biresolution(limits, match, order(rules), index, state);
147
+ });
148
+ });
149
+
150
+ export const orderTagged = (rules: readonly TaggedRule[]): BiresRule[] =>
151
+ orderList(
152
+ rules.map((rule) => ({ tag: rule.tag, item: { isElim: rule.isElim, rule: rule.rule } })),
153
+ );
154
+
155
+ export const biresolveFromNetsTac = (limits: Limits, netpair: NetPair<TaggedRule>) =>
156
+ biresolutionFromNetsTac(limits, orderTagged, false, netpair);
157
+
158
+ export const bimatchFromNetsTac = (limits: Limits, netpair: NetPair<TaggedRule>) =>
159
+ biresolutionFromNetsTac(limits, orderTagged, true, netpair);
160
+
161
+ // The number of new subgoals of a rule.
162
+ export const subgoalsOfBrl = (brule: { isElim: boolean; rule: Thm }) =>
163
+ brule.isElim ? nprems(brule.rule) - 1 : nprems(brule.rule);
164
+
165
+ export const rotateTac =
166
+ (count: number): GoalTactic =>
167
+ (index) =>
168
+ count === 0 ? allTac : primitive((state) => rotateRule(count, index, state));