Skip to content

[Merged by Bors] - feat: refactor of solve_by_elim#856

Closed
kim-em wants to merge 43 commits intomasterfrom
solve_by_elim_refactor
Closed

[Merged by Bors] - feat: refactor of solve_by_elim#856
kim-em wants to merge 43 commits intomasterfrom
solve_by_elim_refactor

Conversation

@kim-em
Copy link
Copy Markdown
Contributor

@kim-em kim-em commented Dec 5, 2022

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

@kim-em kim-em added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jan 4, 2023
@hrmacbeth hrmacbeth force-pushed the solve_by_elim_refactor branch from 117af73 to 21e2682 Compare January 4, 2023 21:57
@hrmacbeth
Copy link
Copy Markdown
Member

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

@kim-em kim-em removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jan 5, 2023
@kim-em kim-em added merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) and removed help-wanted The author needs attention to resolve issues labels Jan 6, 2023
@kim-em kim-em removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jan 9, 2023
@hrmacbeth
Copy link
Copy Markdown
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 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
Copy Markdown

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>
kim-em 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.

5 participants