Zulip Chat Archive
Stream: general
Topic: singleton / unique
Johan Commelin (Jan 18 2019 at 06:42):
It has been remarked before that we need a class that is nonempty
+ subsingleton
. I guess the canonical name would be singleton
. How would people want to define it?
class singleton (X : Type u) := (elem : X) (uniq : \Pi (x,y : X), x = y)
Nicholas Scheel (Jan 18 2019 at 07:03):
why not just take nonempty and subsingleton as assumptions together?
Johan Commelin (Jan 18 2019 at 07:17):
I guess there are two options: either we make an inductive Prop
, or we make a thing that lives in Type*
but has an easy projector to the element.
Johan Commelin (Jan 18 2019 at 07:17):
I'm not sure what is best.
Johan Commelin (Jan 18 2019 at 07:34):
@Johannes Hölzl There is probably common wisdom on this in the wider community. What would you suggest?
Johannes Hölzl (Jan 18 2019 at 07:36):
Hm, this is a case which is not often used. But I would guess the Type*
variant could be more helpful.
Johan Commelin (Jan 18 2019 at 07:36):
It is not? Ooh, that surprises me.
Johannes Hölzl (Jan 18 2019 at 07:37):
Up to now we didn't need it in mathlib...
Johan Commelin (Jan 18 2019 at 07:38):
Where would you put it?
Johan Commelin (Jan 18 2019 at 07:38):
Somewhere in data/
?
Johannes Hölzl (Jan 18 2019 at 07:41):
Maybe even in logic/basic.lean
? Plus the unit
instance.
Johan Commelin (Jan 18 2019 at 07:41):
Is it ok to extend inhabited
?
Johan Commelin (Jan 18 2019 at 07:41):
Or is that wrong for semantic reasons?
Johan Commelin (Jan 18 2019 at 07:42):
I still don't know the semantics of all those types like inhabited
, default
, etc...
Johannes Hölzl (Jan 18 2019 at 07:45):
Yes, extend inhabited
and derive subsingleton
Johan Commelin (Jan 18 2019 at 08:05):
Ooop :see_no_evil: the name singleton
is of course already taken by singleton sets...
Johan Commelin (Jan 18 2019 at 08:06):
@Kenny Lau Do you have a good suggestion for a name?
Kenny Lau (Jan 18 2019 at 08:06):
nope
Johan Commelin (Jan 18 2019 at 08:16):
Aahrg, punit.inhabited
is only for Type
, not Type u
.
Johan Commelin (Jan 18 2019 at 08:23):
I guess the name contractible
is to HoTT, right?
Reid Barton (Jan 18 2019 at 08:24):
Maybe unique
?
Johan Commelin (Jan 18 2019 at 08:24):
Yes, that might work. But I'dd like to also emphasise the existence.
Johan Commelin (Jan 18 2019 at 08:25):
People might think that unique
is a variant on subsingleton
.
Johan Commelin (Jan 18 2019 at 08:39):
#605 @Johannes Hölzl
Mario Carneiro (Jan 18 2019 at 08:42):
what's wrong with just inhabited
+ subsingleton
or nonempty
+ subsingleton
?
Johan Commelin (Jan 18 2019 at 08:43):
That it's longer to write?
Mario Carneiro (Jan 18 2019 at 08:43):
not good enough, definitions are worth more than that
Johan Commelin (Jan 18 2019 at 08:44):
When I'm pulling a limit cone through and adjoint functor I want to spend as little time with these stupid classes...
Mario Carneiro (Jan 18 2019 at 08:44):
aha, okay sure I've seen this. Are you perhaps saying this about a subtype?
Johan Commelin (Jan 18 2019 at 08:44):
No...
Johan Commelin (Jan 18 2019 at 08:44):
Why do you think that?
Mario Carneiro (Jan 18 2019 at 08:45):
That's the way it usually goes with universal properties
Mario Carneiro (Jan 18 2019 at 08:45):
there exists a unique map satisfying such and such property
Johan Commelin (Jan 18 2019 at 08:45):
Ok, maybe. I haven't thought of it like that. But there are no subtypes in sight with what I'm doing right now.
Johan Commelin (Jan 18 2019 at 08:45):
Aah, but that's all packaged into cone_morphism
Johan Commelin (Jan 18 2019 at 08:46):
I want to say that c
is a limit cone if \Pi t, unique (cone_morphism c t)
Mario Carneiro (Jan 18 2019 at 08:46):
why not say that in two conditions?
Mario Carneiro (Jan 18 2019 at 08:47):
you have a morphism and a proof of uniqueness
Johan Commelin (Jan 18 2019 at 08:47):
And then adjunctions give me equiv
s, and equiv.unique_of_equiv
will let me easily manipulate it.
Johan Commelin (Jan 18 2019 at 08:47):
It's too unbundled.
Johan Commelin (Jan 18 2019 at 08:47):
I agree that that is also useful. And it is what we have right now in the library.
Johan Commelin (Jan 18 2019 at 08:48):
It's good when you are applying these things in concrete cases.
Johan Commelin (Jan 18 2019 at 08:48):
But for abstract category theory, I think it becomes a lot easier to manipulate these things when they are bundled.
Mario Carneiro (Jan 18 2019 at 08:49):
I take it you don't want to use this like a typeclass then?
Johan Commelin (Jan 18 2019 at 08:50):
Uuuh, I don't know?
Mario Carneiro (Jan 18 2019 at 08:50):
what does equiv.unique_of_equiv
say?
Johan Commelin (Jan 18 2019 at 08:51):
If X \equiv Y
and you know unique Y
then you get unique X
.
Johan Commelin (Jan 18 2019 at 08:51):
But you knew that.
Johan Commelin (Jan 18 2019 at 08:51):
You want code.
Mario Carneiro (Jan 18 2019 at 08:51):
and that's all you intend to do with unique
, besides using the projections directly?
Johan Commelin (Jan 18 2019 at 08:51):
https://github.com/leanprover/mathlib/pull/605/files#diff-a714d761eac2ec5a2e4b0ed4592f9c46R474
Johan Commelin (Jan 18 2019 at 08:52):
Eehm, yes, for the time being.
Mario Carneiro (Jan 18 2019 at 08:52):
By the way, you can define unique
in a simpler way, with only one quantifier
Mario Carneiro (Jan 18 2019 at 08:52):
there is x : A
and \forall y, x = y
Johan Commelin (Jan 18 2019 at 08:53):
Yes, I've derived those versions. But I wanted to be as symmetric as possible.
Johan Commelin (Jan 18 2019 at 08:53):
Or is that not useful?
Mario Carneiro (Jan 18 2019 at 08:54):
For the structure you want the axiom to be easy to prove. Probably when one picks a default it will be easy to work with
Mario Carneiro (Jan 18 2019 at 08:54):
like how one shows a zero ring is unique
, you show every element is 0, and hence every element is equal
Mario Carneiro (Jan 18 2019 at 08:54):
saves you a step
Johan Commelin (Jan 18 2019 at 08:55):
Ok, fine. I'll rewrite that.
Mario Carneiro (Jan 18 2019 at 08:55):
besides, the two quantifier version is available as subsingleton.eq
Johan Commelin (Jan 18 2019 at 08:59):
Ok, sure.
Mario Carneiro (Jan 18 2019 at 08:59):
I don't have any better suggestions for the name than unique
Mario Carneiro (Jan 18 2019 at 09:00):
but I think it might be usable as a regular type
Johan Commelin (Jan 18 2019 at 09:02):
Ok, so structure
instead of class
?
Mario Carneiro (Jan 18 2019 at 09:03):
maybe a class
on some days? If you use attribute [class] unique
after the definition you can use it as a class when you feel like it but the projections won't have inst implicit
Johan Commelin (Jan 18 2019 at 09:03):
Aah, maybe that helps.
Johan Commelin (Jan 18 2019 at 09:04):
I guess I should make some simp-lemmas. And then hopefully tidy
can work with this nicely.
Mario Carneiro (Jan 18 2019 at 09:04):
Here are some interesting facts: subsingleton (unique A)
, and unique (unique A) <-> unique A
, unique A -> unique B
if f : A -> B
is a surjection (not required to be a bijection)
Johan Commelin (Jan 18 2019 at 09:05):
Yep... would you like all of those?
Mario Carneiro (Jan 18 2019 at 09:05):
if you are going to define a thing you should prove all the basic theorems
Johan Commelin (Jan 18 2019 at 09:06):
Where should those go?
Johan Commelin (Jan 18 2019 at 09:06):
logic/basic
?
Mario Carneiro (Jan 18 2019 at 09:08):
how about logic/unique
unless there is a reason to merge it
Mario Carneiro (Jan 18 2019 at 09:08):
I don't think there are currently any new definitions in logic/basic
Mario Carneiro (Jan 18 2019 at 09:09):
but logic/basic
probably needs a refactor, it's a bit of a grab bag
Mario Carneiro (Jan 18 2019 at 09:09):
it literally has a miscellaneous
section, that's never a good sign
Johan Commelin (Jan 18 2019 at 09:10):
Ok, I can start logic/unique
Johan Commelin (Jan 18 2019 at 09:11):
If I do the attribute [class]
thing, and I assume [unique X]
then it still doesn't infer inhabited X
. So I have to state those inferences by hand?
Johan Commelin (Jan 18 2019 at 09:17):
@Mario Carneiro Should I include simp-lemmas like this?
instance : inhabited α := to_inhabited ‹unique α› @[simp] lemma eq_default (a : α) : a = default α := uniq _ a
Mario Carneiro (Jan 18 2019 at 09:18):
you have to mark unique.to_inhabited
as instance
Mario Carneiro (Jan 18 2019 at 09:18):
eq_default
won't work
Mario Carneiro (Jan 18 2019 at 09:19):
neither will default_eq
Johan Commelin (Jan 18 2019 at 09:19):
Why not?
Johan Commelin (Jan 18 2019 at 09:20):
It would be cool if simp
would just simplify every element to the default.
Mario Carneiro (Jan 18 2019 at 09:20):
simp lemmas with a variable on the left trigger on anything
Mario Carneiro (Jan 18 2019 at 09:20):
at least that's what lean says; I don't see why that's a problem but it's explicitly rejected by simp
Johan Commelin (Jan 18 2019 at 09:20):
Aah, and simp doesn't know yet if the unique X
instance will be found or not.
Mario Carneiro (Jan 18 2019 at 09:21):
well, it could just try to apply it on every term... you know I think this is a bad idea
Johan Commelin (Jan 18 2019 at 09:22):
you have to mark
unique.to_inhabited
asinstance
Like so: attribute [instance] unique.to_inhabited
?
Mario Carneiro (Jan 18 2019 at 09:22):
yes
Johan Commelin (Jan 18 2019 at 09:22):
But then
variables {α : Sort u} [unique α] instance : inhabited α := by apply_instance
still fails.
Mario Carneiro (Jan 18 2019 at 09:30):
oh, I guess that's because the unique
is explicit in unique.to_inhabited
. So you will have to make an instance like you did
Johan Commelin (Jan 18 2019 at 10:00):
@Mario Carneiro Should the following be done with instances or not?
def of_surjective (f : α → β) (hf : surjective f) (h : inhabited α) : inhabited β := { default := f h.default }
Johannes Hölzl (Jan 18 2019 at 10:16):
hf
is not required...
Johan Commelin (Jan 18 2019 at 10:18):
Lol... I've been thinking too much about unique
:grinning:
Johan Commelin (Jan 18 2019 at 10:19):
@Johannes Hölzl @Mario Carneiro I pushed an update to #605
Johan Commelin (Jan 18 2019 at 10:26):
Woops, forgot to git add
the new file.
Last updated: Dec 20 2023 at 11:08 UTC