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
Conversation
jcommelin
commented
Sep 1, 2020
bors r+ |
Co-authored-by: sgouezel <sebastien.gouezel@univ-rennes1.fr>
Canceled. |
Hopefully I should have fixed the build. If you're happy with my fix, you can merge this. bors d+ |
✌️ jcommelin can now approve this pull request. To approve and merge a pull request, simply reply with |
@sgouezel thanks for fixing the build... I was busy with other stuff tonight. bors merge |
Co-authored-by: sgouezel <sebastien.gouezel@univ-rennes1.fr>
Canceled. |
Sorry, but I noticed other arguments that could be removed. You can merge if you're happy with the changes. |
src/data/finset/sort.lean
Outdated
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) := |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
I'm in favour of kicking this on the queue. |
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. |
I'll be gone till after the weekend. If someone wants to follow-up on Mario's comments, that would be great. |
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? |
sure, that works. |
Great. Johan, you can merge this if you're happy with my changes. bors d+ |
✌️ jcommelin can now approve this pull request. To approve and merge a pull request, simply reply with |
bors bingo eeh, I mean bors merge |
Co-authored-by: sgouezel <sebastien.gouezel@univ-rennes1.fr>
Pull request successfully merged into master. Build succeeded: |