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] - chore(data/finset/lattice): remove unneeded assumptions #4020

Closed
wants to merge 8 commits into from

Conversation

jcommelin
Copy link
Member


@jcommelin jcommelin added the awaiting-review The author would like community review of the PR label Sep 1, 2020
@sgouezel
Copy link
Collaborator

sgouezel commented Sep 1, 2020

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 Sep 1, 2020
bors bot pushed a commit that referenced this pull request Sep 1, 2020
Co-authored-by: sgouezel <sebastien.gouezel@univ-rennes1.fr>
@bors
Copy link

bors bot commented Sep 1, 2020

Canceled.

@bryangingechen bryangingechen removed the ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.) label Sep 1, 2020
@sgouezel
Copy link
Collaborator

sgouezel commented Sep 1, 2020

Hopefully I should have fixed the build. If you're happy with my fix, you can merge this.

bors d+

@bors
Copy link

bors bot commented Sep 1, 2020

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

@jcommelin
Copy link
Member Author

@sgouezel thanks for fixing the build... I was busy with other stuff tonight.

bors merge

@github-actions github-actions bot added the ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.) label Sep 1, 2020
bors bot pushed a commit that referenced this pull request Sep 1, 2020
Co-authored-by: sgouezel <sebastien.gouezel@univ-rennes1.fr>
@bors
Copy link

bors bot commented Sep 1, 2020

Canceled.

@sgouezel sgouezel removed the ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.) label Sep 1, 2020
@sgouezel
Copy link
Collaborator

sgouezel commented Sep 1, 2020

Sorry, but I noticed other arguments that could be removed. You can merge if you're happy with the changes.

lemma sorted_zero_eq_min' (s : finset α) (h : 0 < (s.sort (≤)).length) (H : s.nonempty) :
(s.sort (≤)).nth_le 0 h = s.min' H :=
lemma sorted_zero_eq_min' (s : finset α) (h : 0 < s.card) :
(s.sort (≤)).nth_le 0 (by rwa length_sort) = s.min' (by rwa card_pos at h) :=
Copy link
Collaborator

Choose a reason for hiding this comment

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

This might just be my inexperience, but are lemmas that use tactics in their statements easy to use?

Copy link
Member

Choose a reason for hiding this comment

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

the presence of tactics is not the problem so much as the choice of a particular proof to go in that slot. Most tactics will ignore the hypothesis argument when matching up to defeq but occasionally it helps to have a free variable for the hypothesis. Having free variables on both sides of a rewrite can be a problem, though, since it doesn't actually pin down what the hypothesis in the RHS is, and so you get an extra subgoal you didn't want. So it's sometimes helpful to have both versions, or a version where the LHS has a variable and the RHS is concrete (if it is to be used for left to right rewrites or simps).

Copy link
Member Author

Choose a reason for hiding this comment

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

@digama0 So, what do you suggest? Should we revert, or continue?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since the tactic is used to prove a Prop, it will match any Prop that is given to the lemma if you rewrite from left to right or from right to left, by proof irrelevance, and it will provide the required prop on the output of the rewrite. So, to me, this is an improvement over the previous situation, where the user had to provide more data. In all uses of this lemma, the outcome of the change is that we can remove one of the arguments to the call.

Mario, you say that occasionally it helps to have a free variable for the hypothesis. Do you have an example of this behavior?

Copy link
Member

Choose a reason for hiding this comment

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

I agree that the original form with two variables is not good for anyone, except in the case where you are matching an equality in the goal. But the new version of the lemma can never prove h by unification, while the original could, which means you are always going to have to prove the hypothesis h as a subgoal when you apply the new lemma.

Is there a definite common rewrite direction? If so, (say l-t-r) you can put the free hypothesis on the LHS (as is), and prove the RHS hypothesis using two rewrites on the LHS hypothesis. That way if you rewrite the hypothesis will be proven by unification, and you don't get any subgoal for the RHS because it's been proven in the theorem. 0 subgoals is better than 1, no?

If you don't know how the lemma will be used, I suggest providing both the original over-general theorem (this one getting a prime) and the present constrained theorem, and then users can use an appropriate version for the application. There are a few list lemmas like this.

Copy link
Collaborator

@agjftucker agjftucker Sep 3, 2020

Choose a reason for hiding this comment

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

I think only a couple of these are used, and then only left-to-right. But if you are already considering two versions of each, then maybe one could work left-to-right and one right-to-left? Something like this:

lemma sorted_zero_eq_inf' (s : finset α) (h : 0 < (s.sort (≤)).length) : (s.sort (≤)).nth_le 0 h = s.1.inf' (by rwa [length_sort, card_pos] at h) := begin ... end

lemma inf'_eq_sorted_zero (s : finset α) (H : s.nonempty) : s.1.inf' H = (s.sort (≤)).nth_le 0 (by rwa [length_sort, card_pos]) := by rw sorted_zero_eq_inf'

lemma sorted_last_eq_sup' (s : finset α) (h : (s.sort (≤)).length - 1 < (s.sort (≤)).length) : (s.sort (≤)).nth_le ((s.sort (≤)).length - 1) h = s.1.sup' (by simpa [card_pos] using lt_of_le_of_lt (nat.zero_le _) h) := begin ... end

lemma sup'_eq_sorted_last (s : finset α) (H : s.nonempty) : s.1.sup' H = (s.sort (≤)).nth_le ((s.sort (≤)).length - 1) (by simpa using sub_lt (card_pos.mpr H) zero_lt_one) := by rw sorted_last_eq_sup'

lemma mono_of_fin_zero_eq_inf' {s : finset α} {k : ℕ} (h : s.card = k) (hz : 0 < k) : mono_of_fin s h ⟨0, hz⟩ = s.1.inf' (card_pos.1 (h.symm ▸ hz)) := begin ... end

lemma inf'_eq_mono_of_fin_zero {s : finset α} (hs : s.nonempty) : s.1.inf' hs = mono_of_fin s rfl ⟨0, card_pos.2 hs⟩ := by rw mono_of_fin_zero_eq_inf'

lemma mono_of_fin_last_eq_sup' {s : finset α} {k : ℕ} (h : s.card = k) (hz : 0 < k) : mono_of_fin s h ⟨k-1, sub_lt hz zero_lt_one⟩ = s.1.sup' (card_pos.1 (h.symm ▸ hz)) := begin ... end

lemma sup'_eq_mono_of_fin_last {s : finset α} (hs : s.nonempty) : s.1.sup' hs = mono_of_fin s rfl ⟨s.card - 1, sub_lt (card_pos.2 hs) zero_lt_one⟩ := by rw mono_of_fin_last_eq_sup' rfl (card_pos.2 hs)

lemma mono_of_fin_singleton_eq (a : α) (i : fin 1) {h} : mono_of_fin {a} h i = a := begin ... end

lemma eq_mono_of_fin_singleton (a : α) (i : fin 1) : a = mono_of_fin {a} (card_singleton a) i := by rw mono_of_fin_singleton_eq

@jcommelin
Copy link
Member Author

I'm in favour of kicking this on the queue.

@agjftucker
Copy link
Collaborator

I brought it up on Zulip but I'll mention it again here: another unnecessarily strong assumption for several of these definitions/theorems is of decidable_linear_order.

@bryangingechen bryangingechen added the awaiting-author A reviewer has asked the author a question or requested changes label Sep 2, 2020
@jcommelin jcommelin added the please-adopt This PR/issue may have been abandoned by the original contributor. You are welcome to take it over. label Sep 3, 2020
@jcommelin
Copy link
Member Author

I'll be gone till after the weekend. If someone wants to follow-up on Mario's comments, that would be great.

@sgouezel sgouezel 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 please-adopt This PR/issue may have been abandoned by the original contributor. You are welcome to take it over. labels Sep 3, 2020
@sgouezel
Copy link
Collaborator

sgouezel commented Sep 3, 2020

For the lemmas that could be used as rewrites in either direction, I have added two versions, one for each direction without any extra assumption. @digama0 , were you thinking of something like that?

agjftucker added a commit to agjftucker/mathlib that referenced this pull request Sep 3, 2020
@digama0
Copy link
Member

digama0 commented Sep 3, 2020

sure, that works.

@sgouezel
Copy link
Collaborator

sgouezel commented Sep 4, 2020

Great. Johan, you can merge this if you're happy with my changes.

bors d+

@bors
Copy link

bors bot commented Sep 4, 2020

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

@ChrisHughes24 ChrisHughes24 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 Sep 4, 2020
@jcommelin
Copy link
Member Author

bors bingo

eeh, I mean

bors merge

@github-actions github-actions bot added the ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.) label Sep 6, 2020
bors bot pushed a commit that referenced this pull request Sep 6, 2020
Co-authored-by: sgouezel <sebastien.gouezel@univ-rennes1.fr>
@bors
Copy link

bors bot commented Sep 6, 2020

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title chore(data/finset/lattice): remove unneeded assumptions [Merged by Bors] - chore(data/finset/lattice): remove unneeded assumptions Sep 6, 2020
@bors bors bot closed this Sep 6, 2020
@bors bors bot deleted the finset-min-max branch September 6, 2020 06:48
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. 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