Skip to content

feat: prove that omega-regularity is closed under union and is universe-polymorphic#168

Merged
fmontesi merged 10 commits into
leanprover:mainfrom
ctchou:na-sum
Nov 20, 2025
Merged

feat: prove that omega-regularity is closed under union and is universe-polymorphic#168
fmontesi merged 10 commits into
leanprover:mainfrom
ctchou:na-sum

Conversation

@ctchou

@ctchou ctchou commented Nov 19, 2025

Copy link
Copy Markdown
Collaborator

This patch proves that:
(1) omega-regular languages are closed under finite union, and
(2) the definition of omega-regular languages is universe-polymorphic.
The iSum construction used to prove (1) actually works over an arbitrary indexed family of NA.Buchi automata.

@chenson2018 chenson2018 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly small comments. Are there other examples in Mathlib of this pattern of using existentials with types and typeclasses? It might be fine, I've just never seen this before.

Comment thread Cslib/Computability/Automata/NABuchiEquiv.lean Outdated
grind [reindex_run_iff]
· rintro ⟨ss, h_run, h_acc⟩
use ss.map f
constructor <;> grind [reindex_run_iff']

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needing to explicitly split this conjunction a single time to make grind work seems like an indicator that the annotations need some refinement.

I think the problem is that the = annotation on NA.Run eagerly splits it into the underlying conjunction, so then further API around NA.Run is not useful. I'm not sure, but could you try removing that annotation and seeing if that's an improvement?

A theorem (does this exist already?)

theorem foo (na : NA State Symbol) (xs : ωSequence Symbol) (ss : ωSequence State)
    (h₁ : ss 0 ∈ na.start) (h₂ : ∀ n, na.Tr (ss n) (xs n) (ss (n + 1))) : Run na xs ss := ⟨h₁, h₂⟩

with maybe annotation [grind =>] or [grind <=] could be helpful.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you take a look at the commit I just pushed? (Not meant to be the final word, just experimenting). Regardless of grind, I think that if you are defining a type Run, it is good to have API theorems that construct and deconstruct it.

Adding grind annotations to these happens to help a little bit as a replacement for the annotation on NA.Run, but is still not perfect. The tradeoff is there are a few places where you need to know to specify grind [NA.Run], and I don't understand yet why this is the case.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reorganized the code a little bit: renaming Run.trace to Run.trans and putting the grind lemmas in a section with a comment. We should get more data as I develop the theory of NA.Buchi more.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also did some comparisons of the old and the new grind annotations. It seems that the new annotations sped up Sum.lean by quite a bit, although both runs are on the new version of Sum.lean.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm interesting. Soon we should have some benchmarking in place that makes these performance aspects easier to identify.

Comment thread Cslib/Computability/Automata/Sum.lean Outdated
Comment thread Cslib/Computability/Automata/Sum.lean
Comment thread Cslib/Computability/Automata/Sum.lean Outdated
Comment thread Cslib/Computability/Languages/OmegaRegularLanguage.lean Outdated
Comment thread Cslib/Computability/Languages/OmegaRegularLanguage.lean Outdated
@ctchou

ctchou commented Nov 19, 2025

Copy link
Copy Markdown
Collaborator Author

Merge in the new upstream/main and fix an import error caused by it.

@ctchou

ctchou commented Nov 19, 2025

Copy link
Copy Markdown
Collaborator Author

@chenson2018 About your question about NABuchiEquiv above: I basically copied the code, mutatis mutandis, from:
https://leanprover-community.github.io/mathlib4_docs/Mathlib/Computability/DFA.html
See the last part of the file. The issue here is that if you change the definition of ωLanguage.IsRegular to quantify over a polymorphic State type, many things will break. (You can give it a try in OmegaRegularLanguage.lean.). So the definition of IsRegular quantifies over only Type 0 and a separate theorem isRegular_iff is proved to show that there is no loss of generality. The issue was discussed here:
https://leanprover.zulipchat.com/#narrow/channel/513188-CSLib/topic/Language.2EIsRegular.20in.20mathlib/with/548165505

@chenson2018 chenson2018 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, we can iterate on the grind annotations as we have more usage to see what works and doesn't.

@fmontesi

Copy link
Copy Markdown
Collaborator

Very nice!!

@fmontesi fmontesi merged commit 94f2a4f into leanprover:main Nov 20, 2025
3 of 4 checks passed
@ctchou ctchou deleted the na-sum branch December 10, 2025 22:07
thomaskwaring pushed a commit to thomaskwaring/cslib_SKI that referenced this pull request Apr 6, 2026
…se-polymorphic (leanprover#168)

This patch proves that:
(1) omega-regular languages are closed under finite union, and
(2) the definition of omega-regular languages is universe-polymorphic.
The `iSum` construction used to prove (1) actually works over an
arbitrary indexed family of NA.Buchi automata.

---------

Co-authored-by: Chris Henson <chrishenson.net@gmail.com>
benbrastmckie pushed a commit to benbrastmckie/cslib that referenced this pull request Jun 14, 2026
…se-polymorphic (leanprover#168)

This patch proves that:
(1) omega-regular languages are closed under finite union, and
(2) the definition of omega-regular languages is universe-polymorphic.
The `iSum` construction used to prove (1) actually works over an
arbitrary indexed family of NA.Buchi automata.

---------

Co-authored-by: Chris Henson <chrishenson.net@gmail.com>
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.

3 participants