Skip to content
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

[Merged by Bors] - feat(computability/regular_expressions): define regular expressions #5036

Closed
wants to merge 46 commits into from

Conversation

foxthomson
Copy link
Collaborator

@foxthomson foxthomson commented Nov 18, 2020

Very basic definitions for regular expressions


@foxthomson foxthomson added the awaiting-review The author would like community review of the PR label Nov 18, 2020
@jcommelin jcommelin changed the title feat(computability/regex) - defined regular expressions feat(computability/regex): defined regular expressions Nov 19, 2020
foxthomson and others added 2 commits November 19, 2020 13:03
Co-authored-by: Johan Commelin <johan@commelin.net>
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
@bryangingechen bryangingechen changed the title feat(computability/regex): defined regular expressions feat(computability/regular_expressions): defined regular expressions Nov 19, 2020
@eric-wieser
Copy link
Member

eric-wieser commented Nov 19, 2020

Lifting this from a "resolved" comment so that it doesn't get lost...


You'll find when you try to prove (a + b) + c = a + (b + c) to form a monoid instance, as the page on Kleene algebras suggests is sensible notation, that you can't; you can only prove ∀ x, ((a + b) + c).rmatch x ↔ (a + (b + c)).rmatch x, which can't be put in a monoid instance.

If you instead work with quot (λ r s, ∀ l, r.rmatch l = s.rmatch l) or perhaps quotient if you fancy building a setoid, then you can prove that lemma.

Copy link
Member

@gebner gebner left a comment

Choose a reason for hiding this comment

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

I feel like the definitions go completely the wrong way here. First you define the Brzozowski derivative, and only at the end show that the algorithm matches the expected language.

I think it would be better to have it be the other way around, with the more fundamental definition first. First define the language of the regular expression, and only then show that it can be computed using the derivative:

def matches : regular_expression α → set (list α)
| zero := ∅
| null := {[]}
| (char x) = {[x]}
| (comp r1 r2) = r1.matches ∪ r2.matches
...

def deriv : regular_expression α → α → regular_expression α
...

def rmatch : regular_expression α → list α → bool
...

lemma rmatch_correct (r : regular_expression α) (xs : list α) :
  r.rmatch xs ↔ r.match xs :=
...

It might also be a good idea to introduce an explicit language type:

@[derive has_union, derive has_emptyc]
def language (α) := set (list α)

namespace language

instance : has_mul (language α) := -- composition

def star (l : language α) : language α := ...

end language

Then you can state properties about star more easily, like (star r).matches = r.matches.star (also makes for nice simp lemmas!).

You could also define the derivative on languages first, but I'm not sure how much this would help with the long proofs here.

src/computability/regular_expressions.lean Outdated Show resolved Hide resolved
src/computability/regular_expressions.lean Outdated Show resolved Hide resolved
src/computability/regular_expressions.lean Outdated Show resolved Hide resolved
src/computability/regular_expressions.lean Outdated Show resolved Hide resolved
src/computability/regular_expressions.lean Outdated Show resolved Hide resolved
src/computability/regular_expressions.lean Outdated Show resolved Hide resolved
src/computability/regular_expressions.lean Outdated Show resolved Hide resolved
src/computability/regular_expressions.lean Outdated Show resolved Hide resolved
@gebner gebner added awaiting-author A reviewer has asked the author a question or requested changes and removed awaiting-review The author would like community review of the PR labels Dec 1, 2020
@foxthomson foxthomson added blocked-by-other-PR This PR depends on another PR which is still in the queue. A bot manages this label via PR comment. and removed awaiting-author A reviewer has asked the author a question or requested changes labels Dec 9, 2020
@github-actions github-actions bot added blocked-by-other-PR This PR depends on another PR which is still in the queue. A bot manages this label via PR comment. and removed blocked-by-other-PR This PR depends on another PR which is still in the queue. A bot manages this label via PR comment. labels Dec 9, 2020
bors bot pushed a commit that referenced this pull request Dec 14, 2020
Lifted from #5036 in order to include in #5038 as well.



Co-authored-by: foxthomson <11833933+foxthomson@users.noreply.github.com>
@github-actions github-actions bot removed the blocked-by-other-PR This PR depends on another PR which is still in the queue. A bot manages this label via PR comment. label Dec 14, 2020
@github-actions
Copy link

🎉 Great news! Looks like all the dependencies have been resolved:

💡 To add or remove a dependency please update this issue/PR description.

Brought to you by Dependent Issues (:robot: ). Happy coding!

@bryangingechen bryangingechen added the awaiting-author A reviewer has asked the author a question or requested changes label Dec 16, 2020
@foxthomson foxthomson added awaiting-review The author would like community review of the PR and removed awaiting-author A reviewer has asked the author a question or requested changes labels Dec 23, 2020
@gebner
Copy link
Member

gebner commented Jan 6, 2021

bors r+

@github-actions github-actions bot added ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.) and removed awaiting-review The author would like community review of the PR labels Jan 6, 2021
bors bot pushed a commit that referenced this pull request Jan 6, 2021
…5036)

Very basic definitions for regular expressions



Co-authored-by: foxthomson <11833933+foxthomson@users.noreply.github.com>
@bors
Copy link

bors bot commented Jan 6, 2021

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title feat(computability/regular_expressions): define regular expressions [Merged by Bors] - feat(computability/regular_expressions): define regular expressions Jan 6, 2021
@bors bors bot closed this Jan 6, 2021
@bors bors bot deleted the regular branch January 6, 2021 13:54
pglutz pushed a commit that referenced this pull request Jan 6, 2021
…5036)

Very basic definitions for regular expressions



Co-authored-by: foxthomson <11833933+foxthomson@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants