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: refactor of solve_by_elim #856

Closed
wants to merge 43 commits into from

Conversation

semorrison
Copy link
Contributor

This is a thorough refactor of solve_by_elim.

  • Bug fixes and additional tests.
  • Support for removing local hypotheses using solve_by_elim [-h].
  • Use symm on hypotheses and exfalso on the goal, as needed.
  • To support that, MetaM level tooling for the symm tactic. (rfl and trans deserve the same treatment at some point.)
  • Additional hooks for flow control in solve_by_elim (suspending goals to return to the user, rejecting branches, running arbitrary procedures on the goals).
  • Using those hooks, reimplement apply_assumption and apply_rules as thin wrappers around solve_by_elim, allowing access to new features (removing hypotheses, symm and exfalso) for free.
  • Using those hooks, fix library_search using so
    example (P Q : List ℕ) (h : ℕ) : List ℕ := by library_search using P, Q -- exact P ∩ Q

test/SolveByElim.lean Outdated Show resolved Hide resolved
@semorrison semorrison added the awaiting-review The author would like community review of the PR label Dec 6, 2022
@semorrison semorrison added the merge-conflict The PR has a merge conflict with master, and needs manual merging. label Jan 4, 2023
@hrmacbeth
Copy link
Member

I got rid of the merge commit, should be back to previous state.

@semorrison semorrison removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. label Jan 5, 2023
@semorrison semorrison added merge-conflict The PR has a merge conflict with master, and needs manual merging. and removed help-wanted The author needs attention to resolve issues labels Jan 6, 2023
@semorrison semorrison removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. label Jan 9, 2023
@hrmacbeth
Copy link
Member

This has had plenty of review and keeps getting conflicts. I'm going to go ahead and merge. Thanks!

bors r+

@github-actions github-actions bot added ready-to-merge This PR has been sent to bors. and removed awaiting-review The author would like community review of the PR labels Jan 9, 2023
bors bot pushed a commit that referenced this pull request Jan 9, 2023
This is a thorough refactor of `solve_by_elim`.

* Bug fixes and additional tests.
* Support for removing local hypotheses using `solve_by_elim [-h]`.
* Use `symm` on hypotheses and `exfalso` on the goal, as needed.
* To support that, `MetaM` level tooling for the `symm` tactic. (`rfl` and `trans` deserve the same treatment at some point.)
* Additional hooks for flow control in `solve_by_elim` (suspending goals to return to the user, rejecting branches, running arbitrary procedures on the goals).
* Using those hooks, reimplement `apply_assumption` and `apply_rules` as thin wrappers around `solve_by_elim`, allowing access to new features (removing hypotheses, symm and exfalso) for free.
* Using those hooks, fix `library_search using` so 
```example (P Q : List ℕ) (h : ℕ) : List ℕ := by library_search using P, Q -- exact P ∩ Q```

Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
@bors
Copy link

bors bot commented Jan 9, 2023

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title feat: refactor of solve_by_elim [Merged by Bors] - feat: refactor of solve_by_elim Jan 9, 2023
@bors bors bot closed this Jan 9, 2023
@bors bors bot deleted the solve_by_elim_refactor branch January 9, 2023 15:30
jcommelin pushed a commit that referenced this pull request Jan 23, 2023
This is a thorough refactor of `solve_by_elim`.

* Bug fixes and additional tests.
* Support for removing local hypotheses using `solve_by_elim [-h]`.
* Use `symm` on hypotheses and `exfalso` on the goal, as needed.
* To support that, `MetaM` level tooling for the `symm` tactic. (`rfl` and `trans` deserve the same treatment at some point.)
* Additional hooks for flow control in `solve_by_elim` (suspending goals to return to the user, rejecting branches, running arbitrary procedures on the goals).
* Using those hooks, reimplement `apply_assumption` and `apply_rules` as thin wrappers around `solve_by_elim`, allowing access to new features (removing hypotheses, symm and exfalso) for free.
* Using those hooks, fix `library_search using` so 
```example (P Q : List ℕ) (h : ℕ) : List ℕ := by library_search using P, Q -- exact P ∩ Q```

Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
bors bot pushed a commit that referenced this pull request Feb 15, 2023
…2302)

Fixes a bug introduced in #856.
If `solveByElim` succeeds, then we should return early. Otherwise, we look through all lemmas in the environment and find something like `namedPattern` or `Eq.mp` and unnecessarily wrap the result in that.

See #2276 for an example bad output caused by this bug.

Another example is this test: https://github.com/leanprover-community/mathlib4/blob/4ed65899eca4909e9b8f23a113b52ff8cb3f5d41/test/librarySearch.lean#L15
On master, it emits `exact namedPattern p p rfl`, and after this PR it correctly emits `exact p`.
mo271 pushed a commit that referenced this pull request Feb 18, 2023
…2302)

Fixes a bug introduced in #856.
If `solveByElim` succeeds, then we should return early. Otherwise, we look through all lemmas in the environment and find something like `namedPattern` or `Eq.mp` and unnecessarily wrap the result in that.

See #2276 for an example bad output caused by this bug.

Another example is this test: https://github.com/leanprover-community/mathlib4/blob/4ed65899eca4909e9b8f23a113b52ff8cb3f5d41/test/librarySearch.lean#L15
On master, it emits `exact namedPattern p p rfl`, and after this PR it correctly emits `exact p`.
bors bot pushed a commit that referenced this pull request Apr 21, 2023
We had some unfortunate spaghetti code in `solve_by_elim`. When @hrmacbeth had requested additional features for `apply_rules`, the easiest way to provide them was to re-use `solve_by_elim`'s parsing and lemma handling. (See #856.) However `apply_rules` doesn't to backtracking, and `solve_by_elim` is all about it. At the time, `solve_by_elim` didn't have clean separation between its "lemma application" and "backtracking" considerations, so the solution was to add some hacks the prevented the backtracking from actually occurring, in the backtracking code...

Since #2920, those considerations have been cleanly separated out. Thus it's possible to greatly simplify how we don't backtrack when we don't want to (in `apply_rules`). This PR does that.



Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
kbuzzard pushed a commit that referenced this pull request Apr 22, 2023
We had some unfortunate spaghetti code in `solve_by_elim`. When @hrmacbeth had requested additional features for `apply_rules`, the easiest way to provide them was to re-use `solve_by_elim`'s parsing and lemma handling. (See #856.) However `apply_rules` doesn't to backtracking, and `solve_by_elim` is all about it. At the time, `solve_by_elim` didn't have clean separation between its "lemma application" and "backtracking" considerations, so the solution was to add some hacks the prevented the backtracking from actually occurring, in the backtracking code...

Since #2920, those considerations have been cleanly separated out. Thus it's possible to greatly simplify how we don't backtrack when we don't want to (in `apply_rules`). This PR does that.



Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
semorrison added a commit that referenced this pull request May 10, 2023
We had some unfortunate spaghetti code in `solve_by_elim`. When @hrmacbeth had requested additional features for `apply_rules`, the easiest way to provide them was to re-use `solve_by_elim`'s parsing and lemma handling. (See #856.) However `apply_rules` doesn't to backtracking, and `solve_by_elim` is all about it. At the time, `solve_by_elim` didn't have clean separation between its "lemma application" and "backtracking" considerations, so the solution was to add some hacks the prevented the backtracking from actually occurring, in the backtracking code...

Since #2920, those considerations have been cleanly separated out. Thus it's possible to greatly simplify how we don't backtrack when we don't want to (in `apply_rules`). This PR does that.



Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
hrmacbeth pushed a commit that referenced this pull request May 10, 2023
We had some unfortunate spaghetti code in `solve_by_elim`. When @hrmacbeth had requested additional features for `apply_rules`, the easiest way to provide them was to re-use `solve_by_elim`'s parsing and lemma handling. (See #856.) However `apply_rules` doesn't to backtracking, and `solve_by_elim` is all about it. At the time, `solve_by_elim` didn't have clean separation between its "lemma application" and "backtracking" considerations, so the solution was to add some hacks the prevented the backtracking from actually occurring, in the backtracking code...

Since #2920, those considerations have been cleanly separated out. Thus it's possible to greatly simplify how we don't backtrack when we don't want to (in `apply_rules`). This PR does that.



Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
hrmacbeth pushed a commit that referenced this pull request May 11, 2023
We had some unfortunate spaghetti code in `solve_by_elim`. When @hrmacbeth had requested additional features for `apply_rules`, the easiest way to provide them was to re-use `solve_by_elim`'s parsing and lemma handling. (See #856.) However `apply_rules` doesn't to backtracking, and `solve_by_elim` is all about it. At the time, `solve_by_elim` didn't have clean separation between its "lemma application" and "backtracking" considerations, so the solution was to add some hacks the prevented the backtracking from actually occurring, in the backtracking code...

Since #2920, those considerations have been cleanly separated out. Thus it's possible to greatly simplify how we don't backtrack when we don't want to (in `apply_rules`). This PR does that.



Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge This PR has been sent to bors. t-meta Tactics, attributes or user commands
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants