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(data/pnat/find): port over nat.find API #12413

Closed
wants to merge 6 commits into from

Conversation

pechersky
Copy link
Collaborator

Didn't port pnat.find_add because I got lost in the proof.


Open in Gitpod

Didn't port `pnat.find_add` because I got lost in the proof.
@pechersky pechersky added awaiting-CI The author would like to see what CI has to say before doing more work. awaiting-review The author would like community review of the PR labels Mar 2, 2022
src/data/pnat/find.lean Outdated Show resolved Hide resolved
src/data/pnat/find.lean Outdated Show resolved Hide resolved
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
src/data/pnat/find.lean Outdated Show resolved Hide resolved
src/data/pnat/find.lean Outdated Show resolved Hide resolved
@github-actions github-actions bot removed the awaiting-CI The author would like to see what CI has to say before doing more work. label Mar 2, 2022
@jcommelin jcommelin added the awaiting-author A reviewer has asked the author a question or requested changes label Mar 4, 2022
@semorrison semorrison removed the awaiting-review The author would like community review of the PR label Mar 9, 2022
@eric-wieser
Copy link
Member

To be clear, what I'm suggesting is:

/-- The `pnat` version of `nat.find_x` -/
protected def find_x : {n // p n ∧ ∀ m : ℕ+, m < n → ¬p m} :=
begin
  have : ∃ (n' : ℕ) (n : ℕ+) (hn' : n' = n), p n, from exists.elim h (λ n hn, ⟨n, n, rfl, hn⟩),
  have n := nat.find_x this,
  refine ⟨⟨n, _⟩, _, λ m hm pm, _⟩,
  { obtain ⟨n', hn', -⟩ := n.prop.1,
    rw hn',
    exact n'.prop },
  { obtain ⟨n', hn', pn'⟩ := n.prop.1,
    simp_rw [hn', subtype.coe_eta],
    exact pn' },
  { exact n.prop.2 m hm ⟨m, rfl, pm⟩, }
end

I don't really understand what you're doing with the opt_params in your version, but this avoids needing them.

@pechersky
Copy link
Collaborator Author

I don't really understand what you're doing with the opt_params in your version, but this avoids needing them.

I've found that when a definition or usage of a definition requires a proof, and we need two such proofs, where one implies the other, having both still as arguments is better, where the implication is stored in an opt_param. This opt_param laundering often works better when the statements interact with rw.

I will work on using your implementation.

@eric-wieser
Copy link
Member

In the case of my definition you should probably never need the rewrite, as all the API for find_x is in its type alone.

Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
@pechersky pechersky 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 Mar 14, 2022
{ simp [←pnat.coe_le_coe, subtype.ext_iff, nat.succ_le_succ_iff, nat.succ_inj'], }
end

lemma lt_add_right (n m : ℕ+) : n < n + m :=
Copy link
Member

Choose a reason for hiding this comment

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

Can you add lt_add_left too for completeness? We have both for nat.

Comment on lines 117 to 120
⟨begin
rintro ⟨a, ha⟩ ⟨b, hb⟩ ⟨c, hc⟩,
simp [←pnat.coe_le_coe]
end⟩
Copy link
Member

Choose a reason for hiding this comment

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

I would guess

Suggested change
begin
rintro ⟨a, ha⟩ ⟨b, hb⟩ ⟨c, hc⟩,
simp [←pnat.coe_le_coe]
end
⟨λ ⟨a, ha⟩ ⟨b, hb⟩ ⟨c, hc⟩, by simp [←pnat.coe_le_coe]⟩

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@[priority 10]
instance : covariant_class ℕ+ ℕ+ ((+)) (≤) :=
⟨λ ⟨a, ha⟩, by { extract_goal, }⟩
example (_x : ℕ+)
  (_fun_match : ∀ (_a : ℕ+) {n₁ n₂ : ℕ+},
                  n₁ ≤ n₂ → _a + n₁ ≤ _a + n₂) (a : ℕ)
  (_mlocal._fresh.304.3605 _mlocal._fresh.304.3606 : ℕ+)
  (ha : 0 < a) :
  __mlocal__fresh_304_3605 ≤ __mlocal__fresh_304_3606 →
  ⟨a, ha⟩ + __mlocal__fresh_304_3605 ≤
    ⟨a, ha⟩ + __mlocal__fresh_304_3606 :=
begin
  admit,
end

I think the destruction notation doesn't work properly with implicit arguments.

Copy link
Member

@eric-wieser eric-wieser left a comment

Choose a reason for hiding this comment

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

bors d+

@bors
Copy link

bors bot commented Mar 15, 2022

✌️ pechersky can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@leanprover-community-bot-assistant leanprover-community-bot-assistant added delegated The PR author may merge after reviewing final suggestions. and removed awaiting-review The author would like community review of the PR labels Mar 15, 2022
@pechersky
Copy link
Collaborator Author

bors r+

bors bot pushed a commit that referenced this pull request Mar 16, 2022
Didn't port `pnat.find_add` because I got lost in the proof.
@bors
Copy link

bors bot commented Mar 16, 2022

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title feat(data/pnat/find): port over nat.find API [Merged by Bors] - feat(data/pnat/find): port over nat.find API Mar 16, 2022
@bors bors bot closed this Mar 16, 2022
@bors bors bot deleted the pechersky/pnat-find branch March 16, 2022 11:53
laurentbartholdi pushed a commit that referenced this pull request Mar 17, 2022
Didn't port `pnat.find_add` because I got lost in the proof.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
delegated The PR author may merge after reviewing final suggestions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants