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
refactor(data/set/finite): use finite
#15034
Conversation
This is a surprising change to see appear in the queue -- it would be nice to have some design discussion about this somewhere, for example at the Zulip threads where I've explained how I'd been thinking about redesigning finiteness. I'd like to get a chance to review this before it's merged. |
I'm sorry for not discussing it with you first. Could you please tag me in a thread about this? I'm on a phone, and it's less convenient to search from phone. |
Sure, I'll do so once I have a chance to think through these changes. In principle, I think it's good to make |
I have |
@kmill Will you have time to look at it soon? I'm afraid that it'll rot. |
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'm on board with the changes now -- thanks for doing this reorganizational work!
The one thing I feel strongly about is getting a good name for set.finite_of_subtype
. I previously had set.finite_of_finite
for this, which admittedly sounds silly, but here are some other options:
set.mk_finite
set.finite_of
set.to_finite
I think set.finite_of
is the strongest of these.
src/data/set/finite.lean
Outdated
@@ -17,7 +18,7 @@ about finite sets and gives ways to manipulate `set.finite` expressions. | |||
|
|||
* `set.finite : set α → Prop` | |||
* `set.infinite : set α → Prop` | |||
* `set.finite_of_fintype` to prove `set.finite` for a `set` from a `fintype` instance. | |||
* `set.finite_of_subtype` to prove `set.finite` for a `set` from a `fintype` instance. |
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.
* `set.finite_of_subtype` to prove `set.finite` for a `set` from a `fintype` instance. | |
* `set.finite_of_subtype` to prove `set.finite` for a `set` from a `finite` instance. |
src/data/set/finite.lean
Outdated
/-- Constructor for `set.finite` with the `fintype` as an instance argument. -/ | ||
theorem finite_of_fintype (s : set α) [h : fintype s] : s.finite := ⟨h⟩ | ||
/-- Constructor for `set.finite` with the `finite` as an instance argument. -/ | ||
theorem finite_of_subtype (s : set α) [h : finite s] : s.finite := ⟨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 name is passable, but I feel like set.finite_of_subtype
isn't self-explanatory enough for such an important function. I had used set.finite_of_finite
for this in the deleted src/data/finite/set.lean
, but maybe set.mk_finite
or set.to_finite
instead?
src/data/finite/set.lean
Outdated
|
||
example {s : set α} [finite α] : finite s := infer_instance | ||
example : finite (∅ : set α) := infer_instance | ||
example (a : α) : finite ({a} : set α) := infer_instance |
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.
Could you please move these examples too? They're partly a sanity check and partly documentation to let mathlib users know what to expect should work.
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.
Should they go to test/
?
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'm more interested in the documentation part than the test part, which is why I had included them in this file in the first place. One thing they help with is that when you're refactoring they quickly answer the question of whether these instances exist. There are plenty of example
s within mathlib that check instances like this, too.
finite (s \ t : set α) := finite.set.subset s (diff_subset s t) | ||
|
||
instance finite_range (f : ι → α) [finite ι] : finite (range f) := | ||
by { haveI := fintype.of_finite (plift ι), apply_instance } |
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 see why this moved up, but it'd make reviewing easier if proof simplifications, large-scale code motion, and file deletions weren't all happening all at the same time.)
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.
AFAIR, when I started, this was still in data.finite.set
. I'll try to split this PR tonight.
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.
Right, it used to be in data.finite.set
, but then the move got composed with a permutation.
I think splitting this PR into two will just cause more work for everyone with little benefit by this point. I was just complaining 😉
src/data/finite/set.lean
Outdated
begin | ||
refine finite.of_injective (set.range_factorization f) (λ x y h, hf _), | ||
simpa only [range_factorization_coe] using congr_arg (coe : range f → β) h, | ||
end |
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.
All four of these lemmas seem to have disappeared.
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.
They were added after I created my branch. I'm not sure that we should duplicate lots of API about finite sets with [finite s]
assumptions. I'm adding set.finite
versions of these lemmas. In particular, function.injective.finite_range_iff
works for a function from a Sort*
.
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 first three had been there since the beginning, but finite.of_injective_finite_range
is new. The finite.set.finite_of_finite_image
lemma has simpler hypotheses than the fintype
version since it doesn't need to try to be computable.
I haven't thought too much about whether finite.of_injective_finite_range
should exist, but I'm not comfortable deleting a lemma that had just been merged four days ago... At least we can delete it in a simpler PR.
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 that it should exist but it should take a set.finite
argument, not a [finite _]
argument.
by simpa [← @exists_finite_iff_finset α (λ t, t ⊆ a ∧ t = s), subset_to_finset_iff, | ||
← and.assoc] using h.subset⟩ | ||
begin | ||
convert (h.to_finset.powerset.map finset.coe_emb.1).finite_to_set using 1, |
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 is meant to be the application of the deleted set.finite.of_finset
(from src/data/finite/set.lean
)
I don't care about the name. Should we run a zulip poll? Or just let you choose one of these options? |
Thinking about it more, |
…ib into YK-set-finite-new
set.finite
in terms offinite
;data.finite.set
todata.set.finite
, use these instances to prove properties ofset.finite
;finite
instead offintype
in some lemmas outside of these files.