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: add peel tactic #7685

Closed
wants to merge 35 commits into from
Closed

Conversation

j-loreaux
Copy link
Collaborator

@j-loreaux j-loreaux commented Oct 15, 2023

As requested on Zulip.

Given p q : ℕ → Prop, h : ∀ x, p x, and a goal ⊢ : ∀ x, q x, the tactic peel h with h' x will introduce x : ℕ, h' : p x into the context and the new goal will be ⊢ q x. This works with , as well as ∀ᶠ and ∃ᶠ, and it can even be applied to a sequence of quantifiers.

For a more complex example, given a hypothesis and a goal:

h : ∀ ε > (0 : ℝ), ∃ N : ℕ, ∀ n ≥ N, 1 / (n + 1 : ℝ) < ε
⊢ ∀ ε > (0 : ℝ), ∃ N : ℕ, ∀ n ≥ N, 1 / (n + 1 : ℝ) ≤ ε

(which differ only in </), applying peel h with h_peel ε hε N n hn will yield a tactic state:

h : ∀ ε > (0 : ℝ), ∃ N : ℕ, ∀ n ≥ N, 1 / (n + 1 : ℝ) < ε
ε : ℝ
hε : 0 < ε
N n : ℕ
hn : N ≤ n
h_peel : 1 / (n + 1 : ℝ) < ε
⊢ 1 / (n + 1 : ℝ) ≤ ε

and the goal can be closed with exact h_peel.le.

Co-authored-by: Kyle Miller kmill31415@gmail.com


Note: I am completely open to renaming the tactic if a consensus is reached about a better name.

Open in Gitpod

@j-loreaux j-loreaux added awaiting-review t-meta Tactics, attributes or user commands labels Oct 15, 2023
@j-loreaux j-loreaux added awaiting-author A reviewer has asked the author a question or requested changes and removed awaiting-review labels Oct 18, 2023
@j-loreaux j-loreaux added awaiting-review and removed awaiting-author A reviewer has asked the author a question or requested changes labels Oct 19, 2023
@robertylewis
Copy link
Member

This looks awesome!

Could you add some tests that involve type class arguments?

@j-loreaux
Copy link
Collaborator Author

j-loreaux commented Oct 19, 2023

(EDIT: I have added two examples like the one below to the test suite)

@robertylewis can you give an example of what you're looking for? Several of the tests already have expressions that include type classes (e.g., Add, Sub, TopologicalSpace, etc.).

Maybe something like this is what you mean?

example {α : Type*} [CommRing α] (h : ∀ x : α, ∃ y : α, x + y = 2) :
    ∀ x : α, ∃ y : α, (x + y) ^ 2 = 4 := by
  peel 2 h
  rw [this]
  ring

@robertylewis
Copy link
Member

@j-loreaux your examples are exactly what I meant, thanks 😄

@PatrickMassot mentioned that typeclass-heavy examples have gotten him into trouble in similar situations. To confirm, Patrick, do Jireh's new tests cover what you were thinking?

@PatrickMassot
Copy link
Member

@robertylewis , I think you are referring to the widget issue that was pretty different.

@j-loreaux I think that what is missing are tests that would catch a missing withContext. All your test have peel at the very beginning. We need examples where there are intro before peel and several goals at the time when peel is called.

Copy link
Contributor

@kmill kmill left a comment

Choose a reason for hiding this comment

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

Here are a few comments

Mathlib/Tactic/Peel.lean Show resolved Hide resolved
Mathlib/Tactic/Peel.lean Outdated Show resolved Hide resolved
Mathlib/Tactic/Peel.lean Outdated Show resolved Hide resolved
Mathlib/Tactic/Peel.lean Outdated Show resolved Hide resolved
Mathlib/Tactic/Peel.lean Outdated Show resolved Hide resolved
Mathlib/Tactic/Peel.lean Outdated Show resolved Hide resolved
Mathlib/Tactic/Peel.lean Outdated Show resolved Hide resolved
Mathlib/Tactic/Peel.lean Outdated Show resolved Hide resolved
j-loreaux and others added 2 commits October 25, 2023 16:54
Co-authored-by: Kyle Miller <kmill31415@gmail.com>
Mathlib/Tactic/Peel.lean Outdated Show resolved Hide resolved
@j-loreaux j-loreaux added WIP Work in progress and removed awaiting-review labels Oct 27, 2023
@j-loreaux j-loreaux added awaiting-review and removed WIP Work in progress labels Oct 30, 2023
Copy link
Contributor

@kmill kmill left a comment

Choose a reason for hiding this comment

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

Looks good to me

test/peel.lean Outdated Show resolved Hide resolved
@PatrickMassot
Copy link
Member

Thanks a lot Jireh and Kyle! This is really great.
bors merge

@github-actions github-actions bot added ready-to-merge This PR has been sent to bors. and removed awaiting-review labels Oct 30, 2023
bors bot pushed a commit that referenced this pull request Oct 30, 2023
As requested on [Zulip](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Logical.20congruence.20or.20weakening.20tactic).

Given `p q : ℕ → Prop`, `h : ∀ x, p x`, and a goal `⊢ : ∀ x, q x`, the tactic `peel h with h' x` will introduce `x : ℕ`, `h' : p x` into the context and the new goal will be `⊢ q x`. This works with `∃`, as well as `∀ᶠ` and `∃ᶠ`, and it can even be applied to a sequence of quantifiers.

For a more complex example, given a hypothesis and a goal:
```
h : ∀ ε > (0 : ℝ), ∃ N : ℕ, ∀ n ≥ N, 1 / (n + 1 : ℝ) < ε
⊢ ∀ ε > (0 : ℝ), ∃ N : ℕ, ∀ n ≥ N, 1 / (n + 1 : ℝ) ≤ ε
```
(which differ only in `<`/`≤`), applying `peel h with h_peel ε hε N n hn` will yield a tactic state:
```
h : ∀ ε > (0 : ℝ), ∃ N : ℕ, ∀ n ≥ N, 1 / (n + 1 : ℝ) < ε
ε : ℝ
hε : 0 < ε
N n : ℕ
hn : N ≤ n
h_peel : 1 / (n + 1 : ℝ) < ε
⊢ 1 / (n + 1 : ℝ) ≤ ε
```
and the goal can be closed with `exact h_peel.le`.

Co-authored-by: Kyle Miller <kmill31415@gmail.com>



Co-authored-by: Patrick Massot <patrickmassot@free.fr>
Co-authored-by: Kyle Miller <kmill31415@gmail.com>
@bors
Copy link

bors bot commented Oct 30, 2023

Pull request successfully merged into master.

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot changed the title feat: add peel tactic [Merged by Bors] - feat: add peel tactic Oct 30, 2023
@bors bors bot closed this Oct 30, 2023
@bors bors bot deleted the j-loreaux/peel-tactic branch October 30, 2023 20:20
grunweg pushed a commit that referenced this pull request Nov 1, 2023
As requested on [Zulip](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Logical.20congruence.20or.20weakening.20tactic).

Given `p q : ℕ → Prop`, `h : ∀ x, p x`, and a goal `⊢ : ∀ x, q x`, the tactic `peel h with h' x` will introduce `x : ℕ`, `h' : p x` into the context and the new goal will be `⊢ q x`. This works with `∃`, as well as `∀ᶠ` and `∃ᶠ`, and it can even be applied to a sequence of quantifiers.

For a more complex example, given a hypothesis and a goal:
```
h : ∀ ε > (0 : ℝ), ∃ N : ℕ, ∀ n ≥ N, 1 / (n + 1 : ℝ) < ε
⊢ ∀ ε > (0 : ℝ), ∃ N : ℕ, ∀ n ≥ N, 1 / (n + 1 : ℝ) ≤ ε
```
(which differ only in `<`/`≤`), applying `peel h with h_peel ε hε N n hn` will yield a tactic state:
```
h : ∀ ε > (0 : ℝ), ∃ N : ℕ, ∀ n ≥ N, 1 / (n + 1 : ℝ) < ε
ε : ℝ
hε : 0 < ε
N n : ℕ
hn : N ≤ n
h_peel : 1 / (n + 1 : ℝ) < ε
⊢ 1 / (n + 1 : ℝ) ≤ ε
```
and the goal can be closed with `exact h_peel.le`.

Co-authored-by: Kyle Miller <kmill31415@gmail.com>



Co-authored-by: Patrick Massot <patrickmassot@free.fr>
Co-authored-by: Kyle Miller <kmill31415@gmail.com>
fgdorais pushed a commit that referenced this pull request Nov 1, 2023
As requested on [Zulip](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Logical.20congruence.20or.20weakening.20tactic).

Given `p q : ℕ → Prop`, `h : ∀ x, p x`, and a goal `⊢ : ∀ x, q x`, the tactic `peel h with h' x` will introduce `x : ℕ`, `h' : p x` into the context and the new goal will be `⊢ q x`. This works with `∃`, as well as `∀ᶠ` and `∃ᶠ`, and it can even be applied to a sequence of quantifiers.

For a more complex example, given a hypothesis and a goal:
```
h : ∀ ε > (0 : ℝ), ∃ N : ℕ, ∀ n ≥ N, 1 / (n + 1 : ℝ) < ε
⊢ ∀ ε > (0 : ℝ), ∃ N : ℕ, ∀ n ≥ N, 1 / (n + 1 : ℝ) ≤ ε
```
(which differ only in `<`/`≤`), applying `peel h with h_peel ε hε N n hn` will yield a tactic state:
```
h : ∀ ε > (0 : ℝ), ∃ N : ℕ, ∀ n ≥ N, 1 / (n + 1 : ℝ) < ε
ε : ℝ
hε : 0 < ε
N n : ℕ
hn : N ≤ n
h_peel : 1 / (n + 1 : ℝ) < ε
⊢ 1 / (n + 1 : ℝ) ≤ ε
```
and the goal can be closed with `exact h_peel.le`.

Co-authored-by: Kyle Miller <kmill31415@gmail.com>



Co-authored-by: Patrick Massot <patrickmassot@free.fr>
Co-authored-by: Kyle Miller <kmill31415@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
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants