-
Notifications
You must be signed in to change notification settings - Fork 44
NFA empty language check #208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
luc-edixhoven
wants to merge
1
commit into
leanprover:main
Choose a base branch
from
luc-edixhoven:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,6 +79,69 @@ instance : Acceptor (FinAcc State Symbol) Symbol where | |
| Accepts (a : FinAcc State Symbol) (xs : List Symbol) := | ||
| ∃ s ∈ a.start, ∃ s' ∈ a.accept, a.MTr s xs s' | ||
|
|
||
| /-- The language of an NFA is empty iff there are no final states | ||
| reachable from the initial state [Hopcroft2006]. -/ | ||
| theorem is_empty (a : FinAcc State Symbol) : | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably call this |
||
| -- a.IsEmpty ↔ Acceptor.language.IsEmpty a := by | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Erase the comment. |
||
| Acceptor.language.IsEmpty a ↔ | ||
| ¬∃ s1 s2, a.CanReach s1 s2 ∧ s1 ∈ a.start ∧ s2 ∈ a.accept | ||
| := by | ||
| apply Iff.intro <;> intro h1 | ||
| -- If language empty, then no reachable accepting states. | ||
| case mp => | ||
| rw [Acceptor.language.IsEmpty, not_exists] at h1 | ||
| -- Assume that there is a reachable accepting state. | ||
| apply by_contradiction | ||
| intro h2 | ||
| rw [not_not] at h2 | ||
| -- Then concrete start and accepting states s1 and s2, resp. | ||
| cases h2 with | ||
| | intro s1 h2 | ||
| cases h2 with | ||
| | intro s2 h2 | ||
| rw [LTS.CanReach] at h2 | ||
| cases h2 with | ||
| | intro h2 _ | ||
| -- And concrete trace xs from s1 to s2. | ||
| cases h2 with | ||
| | intro xs h2 | ||
| -- Then xs must be in the language. | ||
| have h3 : Acceptor.Accepts a xs := by | ||
| simp only [instAcceptor] | ||
| grind | ||
| rw [← Acceptor.mem_language] at h3 | ||
| -- But also not in the language. | ||
| have h4 : xs ∉ Acceptor.language a := by exact h1 xs | ||
| -- Which is contradictory. | ||
| exact h4 h3 | ||
| -- If no reachable accepting states, then language empty. | ||
| case mpr => | ||
| -- rw [IsEmpty] at h1 | ||
| simp only [not_exists, not_and] at h1 | ||
| -- Assume that the language is not empty. | ||
| apply by_contradiction | ||
| intro h2 | ||
| rw [Acceptor.language.IsEmpty, not_not] at h2 | ||
| -- Then concrete accepted trace xs. | ||
| cases h2 with | ||
| | intro xs h2 | ||
| -- Then concrete start and accepting states s1 and s2, resp., | ||
| -- and s2 reachable from s1. | ||
| have h3 : ∃ s1 s2, s1 ∈ a.start ∧ s2 ∈ a.accept ∧ a.MTr s1 xs s2 := by | ||
| simp at h2 | ||
| grind | ||
| cases h3 with | ||
| | intro s1 h3 | ||
| cases h3 with | ||
| | intro s2 h3 | ||
| have h4 : a.CanReach s1 s2 := by | ||
| rw [LTS.CanReach] | ||
| grind | ||
| -- Premise implies that s2 should not be an accepting state. | ||
| have h5 := h1 s1 s2 h4 h3.left | ||
| -- Which is contradictory. | ||
| exact h5 h3.right.left | ||
|
|
||
| end FinAcc | ||
|
|
||
| /-- Nondeterministic Buchi automaton. -/ | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd make this a def of
Language. Surprisingly, I cannot find such a def in mathlib already. @chenson2018 @ctchou Are you aware of an existing def for 'empty Language'?We can put this in Computability/Languages/Language.lean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I initially tried
Acceptor.language a = \empty, which didn't work --- if I understand it correctly, because the lhs is a language and the rhs is a set. I then had a look at https://leanprover-community.github.io/mathlib4_docs/Mathlib/Computability/Language.html#Language.instZero. I couldn't figure out how to use it, but perhaps that's what you're looking for.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0works for the empty language; see #208 (comment) (thanks to ctchou).