Skip to content

feat(Computability/Languages): regular languages have matching regular expressions through Kleene’s Algorithm - #887

Open
chiyunhsu wants to merge 124 commits into
leanprover:mainfrom
chiyunhsu:IsRegularIffRegex
Open

chiyunhsu wants to merge 124 commits into
leanprover:mainfrom
chiyunhsu:IsRegularIffRegex

Conversation

@chiyunhsu

@chiyunhsu chiyunhsu commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

We introduce IsRegular.iff_regex, a language is regular if and only if it matches a regular expression. It is a combination of the existing IsRegular.regex, a language matching a regular expression is regular and our new direction. The new direction is proven through Kleene’s algorithm.

It is the result that was anticipated in PR#846 by @ctchou.       

The pull request introduces a new file, KleeneAlgorithm.lean. In it, we proved a language defined by a DFA on Fin n with one accepting state has a matching regular expression. The algorithm applies induction on a bound which restricts which interior states that a run may pass through.  

Implemented collaboratively by Brooke Gill and Chi-Yun Hsu

@chiyunhsu
chiyunhsu requested a review from ctchou October 13, 2026 02:31

@ctchou ctchou 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.

The new code looks good. I just pushed a commit containing some additional golfing. Some general remarks:

  • We prefer lia over grind over omega
  • Please always put the proof on a new line, even if it is short.
  • Instead of writing (by lia : <some proposition>), write show <some proposition> by lia.
  • A lot of the proofs can probably be simplified using grind, but I didn't attempt any of that.

Comment thread Cslib/Computability/Languages/RegularLanguage.lean Outdated
@chiyunhsu
chiyunhsu requested a review from ctchou October 20, 2026 04:28

@ctchou ctchou 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.

This is probably the last batch of my comments.

Note that I pushed a commit to lowercase some identifier names.

Comment thread Cslib/Computability/Languages/KleeneAlgorithm.lean Outdated
Comment thread Cslib/Computability/Languages/KleeneAlgorithm.lean Outdated
Comment thread Cslib/Computability/Languages/KleeneAlgorithm.lean Outdated
@chiyunhsu

Copy link
Copy Markdown
Contributor Author

I have two last questions for the structure of the code:

  • Should the theorems in section reindex remain in KleeneAlgorithm.lean, or should they be moved to for example LTS/Basic.lean or other suitable files.
  • Should language_nfa_eq_regex_of_singleton_start_accept also have namespace NA.FinAcc? On the other hand, I think bddLang_eq_language_nfa should indeed stay in the namespace LTS.

@ctchou

ctchou commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

I've moved the reindexing stuff to LTS/Bisimulation.lean, got rid of all Fintype, and did some other cleanups.

@ctchou

ctchou commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

@chiyunhsu I did some further golfing. I'm now satisfied with it. Do you have any more changes you want to do?

ctchou and others added 3 commits October 21, 2026 21:09
- AllButFirstLast is Prop, so revert allButFirstLast back to AllButFirstLast
- rename `bddLang_eq_language_nfa` as `bddLang_eq_nfa`
- syntax change for NA.FinAcc.mk in nfa’ so that it is consistent with others

@ctchou ctchou 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.

I'm satisfied with the code now.

@ctchou

ctchou commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

CC @fmontesi

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