Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
[Merged by Bors] - chore(data/finset/lattice): remove unneeded assumptions #4020
Changes from 7 commits
16f276b
0df41a6
279f3bd
b3bba44
81a9e45
eb3a5d4
eeca0db
8ebd394
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 hypothesish
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