Zulip Chat Archive
Stream: general
Topic: countable types
Violeta Hernández (Jul 16 2022 at 05:35):
@Yury G. Kudryashov I'm interested in where you're taking the new countable
typeclass and the finite
typeclass. I know that there was very recently a huge refactor with set.finite
, but I wonder if it would be a good idea to redefine set.finite s
as finite ↥s
and set.countable s
as countable ↥s
. Would most likely save us from a lot of API duplication.
Violeta Hernández (Jul 16 2022 at 06:32):
And regarding this same topic: your new files on countable types seem to cause trouble when imported at the same time as the file on countable sets. There's name clashes like countable_iff_exists_surjective
and set.countable_iff_exists_surjective
.
Violeta Hernández (Jul 16 2022 at 06:36):
(deleted)
Violeta Hernández (Jul 16 2022 at 06:53):
Just opened #14515 to adress this
Yaël Dillies (Jul 16 2022 at 09:29):
Prepare to be mindblown: We don't say (s : set α).nonempty
for s : finset α
. Instead, we say s.nonempty
.
Yury G. Kudryashov (Jul 16 2022 at 10:17):
I have more not-yet-PRd stuff about countable
and finite
. I'm going to open some PRs later today.
Violeta Hernández (Jul 16 2022 at 16:16):
Oh, then I hope my attempts at fleshing out the API don't clash with yours
Yury G. Kudryashov (Jul 16 2022 at 16:22):
I'll have a look at your pr once I check in to the hotel (in about 4 hours)
Yury G. Kudryashov (Jul 16 2022 at 17:26):
The pr you mentioned above is not about countable. What's the correct number?
Mauricio Collares (Jul 16 2022 at 17:28):
Matt Diamond (Jul 17 2022 at 03:32):
could be worth adding a proof of countable α ↔ # α ≤ ℵ₀
somewhere... though it's also pretty trivial to prove it from countable_iff_nonempty_embedding
Yury G. Kudryashov (Jul 19 2022 at 03:36):
Please don't add more facts about countable
yet. I have some unpushed stuff that I hope to PR tomorrow or the day after tomorrow.
Violeta Hernández (Jul 19 2022 at 23:04):
Are you planning on refactoring set.countable
soon?
Yury G. Kudryashov (Jul 19 2022 at 23:06):
Yes.
Yury G. Kudryashov (Jul 19 2022 at 23:07):
Yury G. Kudryashov (Jul 20 2022 at 00:47):
What should be the instance priorities for:
encodable X -> countable X
;subtype.countable
;quotient.countable
?
Yury G. Kudryashov (Jul 20 2022 at 00:48):
We also have instances with default (1000) priority for prod.countable
etc.
Violeta Hernández (Jul 20 2022 at 00:54):
Why does this matter? Isn't countable
a Prop
?
Yaël Dillies (Jul 20 2022 at 00:56):
Is there any reason to move away from the general rule? namely:
- 100
- 1000
- 1000
Yury G. Kudryashov (Jul 20 2022 at 01:01):
@Violeta Hernández It affects typeclass search speed.
Yury G. Kudryashov (Jul 20 2022 at 01:02):
@Yaël Dillies I think that we should use something smaller than 1000
for subtype
and quotient
instances so that instances for specific subtypes and quotients get higher priority.
Yaël Dillies (Jul 20 2022 at 01:03):
Will there be that many instances of countable
?
Yury G. Kudryashov (Jul 20 2022 at 01:03):
I don't know.
Yaël Dillies (Jul 20 2022 at 01:03):
I doubt this is all that important.
Yury G. Kudryashov (Jul 20 2022 at 01:04):
In case of finite
(IMHO, we should have the same priorities), we'll definitely have instances for some specific sets.
Yury G. Kudryashov (Jul 20 2022 at 01:04):
E.g., the index set of some
basis.
Yury G. Kudryashov (Jul 20 2022 at 01:04):
(in a finite dimensional space)
Yaël Dillies (Jul 20 2022 at 01:05):
Also, aren't specific subtypes and quotients often being declared as type synonyms? If so, subtype.countable
and quotient.countable
won't even apply to them.
Yury G. Kudryashov (Jul 20 2022 at 01:06):
Some of them are declared as set
s.
Violeta Hernández (Jul 20 2022 at 01:12):
I don't think we even have that many concrete subtypes or quotients
Violeta Hernández (Jul 20 2022 at 01:12):
Much less countable ones
Violeta Hernández (Jul 20 2022 at 01:14):
I can think of pnat
and fin
Yury G. Kudryashov (Jul 20 2022 at 01:16):
pnat
and fin
aren't subtypes from the typeclass search point of view.
Violeta Hernández (Jul 20 2022 at 01:38):
So that's zero examples
Yury G. Kudryashov (Jul 20 2022 at 01:51):
For finite, we have instances for set operations (in particular, an instance for each set of the form {a, b, c, d}
) and instances for some sets like "the index set of an unspecified finite basis in a finite dimensional space".
Yury G. Kudryashov (Jul 20 2022 at 01:51):
(probably, the latter is a noncomputable ... : fintype ...
now)
Violeta Hernández (Jul 20 2022 at 01:54):
These would all be finite
as well, right? How are those priorities set up?
Kyle Miller (Jul 20 2022 at 01:56):
Violeta Hernández said:
I don't think we even have that many concrete subtypes or quotients
Subtypes do appear. I invite you to search for //
in https://leanprover-community.github.io/mathlib_docs/data/fintype/basic.html
Kyle Miller (Jul 20 2022 at 01:58):
Violeta Hernández said:
These would all be
finite
as well, right? How are those priorities set up?
So far we have a priority 900 instance for fintype -> finite
since finite
instances should be faster to synthesize in general. https://github.com/leanprover-community/mathlib/blob/2220b0cbab795e73674b8191170b0cc68c6b54a8/src/data/finite/basic.lean#L50
Kyle Miller (Jul 20 2022 at 02:00):
Yury G. Kudryashov said:
I think that we should use something smaller than
1000
forsubtype
andquotient
instances so that instances for specific subtypes and quotients get higher priority.
Won't specific subtypes and quotients have instances that are defined after subtype.countable
and quotient.countable
? (As in, they'll be in modules that import the instances from the module where these are defined?) Can we rely on typeclass inference trying later instances of the same priority first?
Kyle Miller (Jul 20 2022 at 02:02):
Yury G. Kudryashov said:
(probably, the latter is a
noncomputable ... : fintype ...
now)
(Just wanted to mention that what I'd like to see is that all these noncomputable
instances become finite
instances. I haven't seriously dug in to see how feasible this is -- have you had a chance to?)
Violeta Hernández (Jul 20 2022 at 02:02):
Kyle Miller said:
Subtypes do appear. I invite you to search for
//
in https://leanprover-community.github.io/mathlib_docs/data/fintype/basic.html
I meant concrete as in specific named types that were defined in terms of a subtype. But judging from Yury's later comments, I think I might have misunderstood what sorts of types we were considering here.
Yaël Dillies (Jul 20 2022 at 02:06):
Yes, we're specifically interested in unnamed subtypes here?
Yury G. Kudryashov (Jul 20 2022 at 02:06):
@Kyle Miller Sometimes these noncomputable ... fintype
instances are used for fintype.sum
.
Yury G. Kudryashov (Jul 20 2022 at 02:07):
We're interested in definitions def lalala : set X := _
Yury G. Kudryashov (Jul 20 2022 at 02:07):
With instances on (lalala : Type*)
Yaël Dillies (Jul 20 2022 at 02:08):
Yes, we already override Prop versions by noncomputable Type versions when there's no hope of getting a computable one. This mostly happens for nonempty
and inhabited
.
Yaël Dillies (Jul 20 2022 at 02:09):
So, no, we should not get rid of the noncomputable fintype instances.
Violeta Hernández (Jul 20 2022 at 02:10):
Yury G. Kudryashov said:
Kyle Miller Sometimes these
noncomputable ... fintype
instances are used forfintype.sum
.
Then maybe we should have a finite.sum
to match?
Kyle Miller (Jul 20 2022 at 02:12):
I'd like to see a way to get fintype
instances from finite
instances in a classical context. I believe this should be possible in Lean 4 due to its improved handling of typeclass search loops, but I'm not completely sure.
Violeta Hernández (Jul 20 2022 at 02:12):
This already exists: docs#fintype.of_finite
Kyle Miller (Jul 20 2022 at 02:13):
I'm aware of that function -- I mean automatically when you do classical
or open_locale classical
.
Yaël Dillies (Jul 20 2022 at 02:13):
I'm not sure what you find harmful about having noncomputable instances when no computable one can exist.
Kyle Miller (Jul 20 2022 at 02:18):
If you're in a noncomputable theory
, then that's fine I think, but having any noncomputable fintype
instances means you can't rely on it for computability. I think of it as being like that computable
class I proposed before but specialized for finite
.
Kyle Miller (Jul 20 2022 at 02:19):
inhabited
and nonempty
share a similar relation (by the way, is there a reason we use an inhabited
linter rather than a nonempty
linter?)
Yury G. Kudryashov (Jul 20 2022 at 02:20):
Violeta Hernández said:
Yury G. Kudryashov said:
Kyle Miller Sometimes these
noncomputable ... fintype
instances are used forfintype.sum
.Then maybe we should have a
finite.sum
to match?
We have docs#finsum
Junyan Xu (Jul 20 2022 at 02:34):
Kyle Miller said:
inhabited
andnonempty
share a similar relation (by the way, is there a reason we use aninhabited
linter rather than anonempty
linter?)
Notice that some types are inhabited by 37, for example: docs#polynomial.splitting_field.inhabited
Kyle Miller (Jul 20 2022 at 02:41):
(I guess let's see what happens with a has_nonempty_instance
linter: #15542)
Matt Diamond (Jul 20 2022 at 03:12):
just curious, what's the significance of 37? just a running joke?
Kyle Miller (Jul 20 2022 at 03:19):
It's apparently the most random integer from 1 to 100.
Matt Diamond (Jul 20 2022 at 03:21):
ah ha... alright then
Kyle Miller (Jul 20 2022 at 03:22):
Huh, there's a website full of 37 factoids: http://magliery.com/37/index.html
Matt Diamond (Jul 20 2022 at 03:36):
and of course there's https://en.wikipedia.org/wiki/37_(number)
Last updated: Dec 20 2023 at 11:08 UTC