Skip to content

refactor(MultiTape): simulate machines through adapters - #32

Merged
barni120400 merged 8 commits into
mainfrom
refactor/multitape-shared-simulations
Nov 1, 2026
Merged

barni120400 merged 8 commits into
mainfrom
refactor/multitape-shared-simulations

Conversation

@barni120400

@barni120400 barni120400 commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

Lets a machine follow another: it performs each transition of the inner machine through an adapter, which computes what the inner machine reads from the symbols under the outer heads (HeadSymbols) and gives the outer action performing each inner action. Follows.runningStepHom and Follows.stepHom turn a configuration map that agrees with the adapter into a homomorphism of step relations, so it maps run paths.

Defines extendTapes, outputToTape and inputFromTape as the machine run through an adapter (MultiTapeTM.adapt), so their homomorphisms come from follows_adapt. seq and repeatUntilBlank relabel the actions of their inner machines with Action.mapState and follow them by definition, and prependOutputHom follows the machine itself. This replaces the step lemmas of each simulation and the deterministic stepHom and runningStepHom, and shortens the proofs that use them.

Depends on #31 (upstream leanprover#1122). Upstream: leanprover#1151.

Composed with Claude Code.

@barni120400
barni120400 force-pushed the refactor/multitape-shared-simulations branch from 7653687 to e2d87e8 Compare October 11, 2026 13:56
@barni120400
barni120400 force-pushed the refactor/multitape-shared-simulations branch 2 times, most recently from 29e1c83 to 6f1be88 Compare October 13, 2026 20:29
@barni120400
barni120400 added this pull request to stack #34 October 13, 2026 22:10
@barni120400
barni120400 force-pushed the refactor/multitape-shared-simulations branch from 6f1be88 to 222bcc1 Compare October 13, 2026 22:10
@barni120400
barni120400 force-pushed the refactor/multitape-shared-simulations branch from 222bcc1 to 068b321 Compare October 13, 2026 22:23
@barni120400
barni120400 force-pushed the refactor/multitape-shared-simulations branch from 068b321 to 61f42f4 Compare October 13, 2026 22:31
@barni120400
barni120400 force-pushed the refactor/multitape-shared-simulations branch from 61f42f4 to 3398d6f Compare October 14, 2026 13:28
@barni120400
barni120400 force-pushed the refactor/multitape-shared-simulations branch from 3398d6f to 5f98b5a Compare October 14, 2026 16:00
@barni120400
barni120400 removed this pull request from stack #34 October 14, 2026 16:00
@barni120400
barni120400 added this pull request to stack #35 October 14, 2026 16:01
@barni120400
barni120400 removed this pull request from stack #35 October 14, 2026 16:09
@barni120400
barni120400 added this pull request to stack #36 October 14, 2026 16:09
@barni120400
barni120400 force-pushed the refactor/multitape-shared-simulations branch 5 times, most recently from 9b297bb to 0d93c15 Compare October 14, 2026 16:48
@barni120400
barni120400 force-pushed the refactor/multitape-shared-simulations branch from 0d93c15 to d4e415c Compare October 14, 2026 23:08
@barni120400
barni120400 force-pushed the refactor/multitape-shared-simulations branch 2 times, most recently from 5a4c95c to 21b4e08 Compare October 19, 2026 13:46
@barni120400
barni120400 force-pushed the refactor/multitape-shared-simulations branch 2 times, most recently from f33ed1b to 7c214a5 Compare October 21, 2026 08:09
@barni120400
barni120400 removed this pull request from stack #38 October 21, 2026 08:09
@barni120400
barni120400 added this pull request to stack #40 October 21, 2026 08:09
@barni120400
barni120400 force-pushed the refactor/multitape-shared-simulations branch from 7c214a5 to 192855e Compare October 24, 2026 20:50
@barni120400 barni120400 changed the title refactor(MultiTape): share tape simulations with nondeterministic machines refactor(MultiTape): simulate machines through adapters Oct 24, 2026
@barni120400
barni120400 force-pushed the refactor/multitape-shared-simulations branch from 192855e to c2d2b0d Compare October 27, 2026 00:31
@barni120400
barni120400 removed this pull request from stack #40 October 27, 2026 00:31
@barni120400
barni120400 changed the base branch from refactor/multitape-single-space-api to main October 27, 2026 00:32
@barni120400
barni120400 added this pull request to stack #45 October 27, 2026 00:32
Without this change, the bench suite will crash as soon as any part of
`lake build` tries to use a `cc` compiler or other tools required for
compiling: Since we're overriding the toolchain directory lake uses to
provide our own `lean` wrapper, we need to also provide the other tools
lake expects (though without custom wrappers).

I forgot to include this in leanprover#1165 even though the PR description
mentions it, so here it is in a separate PR.
@barni120400
barni120400 force-pushed the refactor/multitape-shared-simulations branch 2 times, most recently from d0bfa21 to 9b2a4eb Compare October 28, 2026 00:03
jessealama and others added 7 commits October 28, 2026 16:28
Take care of the linter messages from the [weekly linting
report](https://leanprover.zulipchat.com/#narrow/channel/513188-CSLib/topic/Weekly.20linting.20log/near/634853991).

Profiling results against `main` (mean of 5 runs):
* `vm_ltsD_ltsND_not_bisim`: 41 ms → 43 ms (1029 → 1110 heartbeats)
* `exists_full_synthesis_finset`: 70 ms → 50 ms (1289 → 1044 heartbeats)

Profiled using `set_option trace.profiler true in`, heartbeats from
`#count_heartbeats in`.
Bump `mathlib` dependency to
[7ed8b09](leanprover-community/mathlib4@7ed8b09):
feat(Topology/Algebra/InfiniteSum): Deprecate generalized ENNReal lemmas
(#38193) (2026-10-27)
Previously at:
[625d891](leanprover-community/mathlib4@625d891):
chore: bump toolchain to v4.36.0-rc1 (#44879) (2026-10-16)

Closes leanprover#1171

Failure log from the validation run:
[download](https://github.com/leanprover-community/downstream-reports/actions/runs/40624676977/artifacts/12791455952)
_(link expires after 1 year)_

---

This PR bumps `mathlib` to an identified incompatible (first-known-bad)
commit (`7ed8b09`) so you can reproduce and fix the incompatibility
locally by checking out this branch.

_Opened automatically by
[downstream-reports/track-incompatibility](https://github.com/leanprover-community/downstream-reports)
via [this workflow
run](https://github.com/leanprover/cslib/actions/runs/40760536941)._

---------

Co-authored-by: mathlib-nightly-testing[bot] <mathlib-nightly-testing[bot]@users.noreply.github.com>
Co-authored-by: Chris Henson <chrishenson.net@gmail.com>
Co-authored-by: Chris Henson <chrishenson.net@gmail.com>
Bump `mathlib` dependency to
[6955275](leanprover-community/mathlib4@6955275):
chore(Data/Nat/Init): rename recursor arguments (#43848) (2026-10-27)
Previously at:
[9d581df](leanprover-community/mathlib4@9d581df):
chore: bump toolchain to v4.36.0-rc2 (#45383) (2026-10-27)

Closes leanprover#1174

Failure log from the validation run:
[download](https://github.com/leanprover-community/downstream-reports/actions/runs/40897888966/artifacts/12908103845)
_(link expires after 1 year)_

---

This PR bumps `mathlib` to an identified incompatible (first-known-bad)
commit (`6955275`) so you can reproduce and fix the incompatibility
locally by checking out this branch.

_Opened automatically by
[downstream-reports/track-incompatibility](https://github.com/leanprover-community/downstream-reports)
via [this workflow
run](https://github.com/leanprover/cslib/actions/runs/40946293027)._

---------

Co-authored-by: mathlib-nightly-testing[bot] <mathlib-nightly-testing[bot]@users.noreply.github.com>
Co-authored-by: Chris Henson <chrishenson.net@gmail.com>
This PR adds Thompson's construction, which converts regular expressions
to ε-NAs: `RegularExpression.toEpsilonNA r : εNA.FinAcc r.State α`, with
`RegularExpression.language_toEpsilonNA : language r.toEpsilonNA =
r.matches'`. It then uses the construction to prove `IsRegular.char`,
`IsRegular.mul`, `IsRegular.kstar` and `IsRegular.regex`.

- `LTS/Simulation.lean`: `IsSimulationMap` (a map of states that sends
transitions to transitions) and `IsSimulationMap.sim_trace` (it sends
runs to runs), as a special case of simulation through
`IsSimulationMap.isSimulation`.
- `LTS/Union.lean`: the transitions and runs of `LTS.unionSum`
(`unionSum_tr_inl_inl`, `unionSum_mTr_inl_iff`, …).
- `LTS/HasTau.lean`: `τSTr_iff_exists_mTr_replicate` and
`sMTr_iff_exists_mTr_filter` (a saturated run along a τ-free list is a
plain run whose labels, once the τs are dropped, are that list).
- `Languages/LanguageHom.lean`: `Language.Hom.reduceOption`, dropping
the `none`s of a list as a language homomorphism.
- `EpsilonNA/Basic.lean`: `εNA.FinAcc.mem_language_iff` (acceptance
through plain runs) and `DecidableEqTau (Option α)`.
- `EpsilonNA/ToSingleStartAccept.lean` (formerly `ToSingleAccept.lean`):
`toSingleStartAccept` adds a start state without incoming transitions
and an accept state without outgoing transitions, on `Bool ⊕ State`. It
replaces `toSingleAccept`.
- `NA/ToEpsilonNA.lean`: `NA.toEpsilonNA` through `LTS.mapHom` and
`Language.Hom.reduceOption`, so its ε-transitions are self-loops, and
`NA.FinAcc.toEpsilonNAFinAcc`, with the same language.
- `EpsilonNA/ThompsonConstruction.lean`: the building blocks and their
languages:
  - `zero`, `epsilon` and `char`;
  - `sum`, both automata side by side through `LTS.unionSum`;
  - `union := (sum a b).toSingleStartAccept`;
- `concat`, with ε-transitions from the accepting states of the first
automaton to the initial states of the second;
  - `star`, with a fresh hub state that is both initial and accepting.
- `EpsilonNA/OfRegularExpression.lean`: `RegularExpression.State` (with
a `Finite` instance), `toEpsilonNA` and `language_toEpsilonNA`.
- `Languages/RegularLanguage.lean`: `IsRegular.iff_epsilon_nfa`.
`IsRegular.char`, `IsRegular.mul` and `IsRegular.kstar` now come from
the blocks above, without a case split on an empty alphabet, and
`IsRegular.regex` from `language_toEpsilonNA`.

Relation to existing code: CSLib has concatenation and star for ε-free
`NA` (`NA.FinAcc.finConcat`, `NA.FinAcc.finLoop`), which need
`[Inhabited Symbol]`. Thompson's construction is a specific ε-NA
instead: every `r.toEpsilonNA` has one initial state and at most one
accepting state, and each constructor of `r` adds at most two states.
NFA-simulation algorithms work on exactly this automaton. Following the
[discussion on
Zulip](https://leanprover.zulipchat.com/#narrow/channel/513188-CSLib/topic/Thompson.27s.20construction.2C.20.CE.B5-NA.20simulation.20and.20repeats.20in.20word/with/631341023),
the union is built on `toSingleStartAccept`. This complements leanprover#887
(Kleene's algorithm, the converse direction), and leanprover#625 named the
construction as a target.

AI disclosure: written with Anthropic's Claude Code Opus 5.5, which
drafted the Lean code under my direction. I chose the design, reviewed
every definition and proof, and ran the checks.

---------

Co-authored-by: Ching-Tsun Chou <chingtsun.chou@gmail.com>
Adds Basic Temporal Logic (BTL), following Blackburn et al.'s
presentation of the basic temporal language.

The PR also shows that BTL is essentially a thin layer to reason about
frames with two operators that have inverse diagonals.

AI disclosure: the BTL tests are largely AI generated.

Depends on leanprover#863.
)

This PR adds adapters, a common way to say that one machine runs another
step by step. An adapter computes what the inner machine reads from the
symbols under the outer heads, and turns each inner action into an outer
one. A configuration map that agrees with the adapter then maps each
step to a step (`Follows.step`), so it maps whole run paths
(`Follows.stepHom`, `Follows.runningStepHom`).

The plumbing is rebuilt on top of this. `extendTapes`, `outputToTape`
and `inputFromTape` now use `adapt`. `seq` and `repeatUntilBlank` use
the new `combine`, which runs two machines on the same tapes. Each
construction loses its hand-written step lemmas, and the proofs that use
them get shorter.

I used Claude Code to help write the Lean code and this description.

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: crei <crei.github@gmail.com>
@barni120400
barni120400 force-pushed the refactor/multitape-shared-simulations branch from 9cca087 to ee99dd3 Compare November 1, 2026 16:53
@barni120400
barni120400 merged commit ee99dd3 into main Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants