Zulip Chat Archive
Stream: lean4
Topic: Sigma type for proposition and its proof
Leni Aniva (Sep 07 2023 at 21:04):
Is there a way to express the type (Prop, proof of .0)
? For example I can do this:
#check Sigma.mk Nat 4
but I cannot do this
#check Sigma.mk (∀ (a b: Nat), a + b = b + a) Nat.add_comm
The closest thing I can think of is the Std.HashMap
type:
def _root_.Std.HashMap (α : Type u) (β : Type v) [BEq α] [Hashable α] := {m : Imp α β // m.WF}
which couples an object along with a proposition about the object. Why is this use case ok while the one I contrived doesn't typecheck?
Yaël Dillies (Sep 07 2023 at 21:08):
Is docs#PSigma what you want?
Leni Aniva (Sep 07 2023 at 21:14):
Yaël Dillies said:
Is docs#PSigma what you want?
This still doesn't typecheck:
#check PSigma.mk (∀ (a b: Nat), a + b = b + a) Nat.add_comm
Kevin Buzzard (Sep 07 2023 at 21:14):
The reason your original code doesn't typecheck is that Prop
isn't Type u
for any u
, Prop
is something like "Type -1" but that doesn't actually make sense. The type of Sigma.mk
is Sigma.mk.{u, v} {α : Type u} {β : α → Type v} (fst : α) (snd : β fst) : Sigma β
so it's demanding Type u
. The point of PSigma
is that it avoids this.
Leni Aniva (Sep 07 2023 at 21:15):
but I've replaced Sigma
with PSigma
and it still doesn't typecheck
Kevin Buzzard (Sep 07 2023 at 21:17):
The type of PSigma.mk
is PSigma.mk.{u, v} {α : Sort u} {β : α → Sort v} (fst : α) (snd : β fst) : PSigma β
. What do you want beta to be here? It's supposed to be a function.
Leni Aniva (Sep 07 2023 at 21:17):
Can it just be the identity function?
Leni Aniva (Sep 07 2023 at 21:18):
I want snd
to typecheck to fst
Kevin Buzzard (Sep 07 2023 at 21:18):
I am not the best at this sort of foundational stuff but Lean needs to be able to guess alpha and beta and right now I'm not sure what you have in mind for these.
Eric Wieser (Sep 07 2023 at 21:19):
This works:
#check (⟨∀ (a b: Nat), a + b = b + a, Nat.add_comm⟩ : Σ' p : Prop, p)
as does
#check (⟨_, Nat.add_comm⟩ : Σ' p : Prop, p)
Henrik Böving (Sep 07 2023 at 21:20):
The simple approach to this would be to just ship it yourself without thinking^^
structure Simple where
p : Prop
h : p
since there isn't really much interesting API for PSigma anyways.
Eric Wieser (Sep 07 2023 at 21:21):
I think the takeaway here is that Sigma.mk
and PSigma.mk
don't really work unless you also write out the type you expect, as Lean can't infer the family. You wrote the type in your question here though, you just forgot to tell it to Lean!
Leni Aniva (Sep 07 2023 at 21:21):
Thanks!
Leni Aniva (Sep 07 2023 at 21:22):
Does the { .. // .. }
thing from Std.HashMap
work the same way?
Leni Aniva (Sep 07 2023 at 21:23):
Std.HashMap
uses this expression {m : Imp α β // m.WF}
which couples a propositon about an object with the object itself and I couldn't find out about how the //
operator works
Kevin Buzzard (Sep 07 2023 at 21:23):
That's notation for docs#Subtype
Henrik Böving (Sep 07 2023 at 21:23):
That's a subtype, it works a bit different as the left hand side is data and the right hand side is proof about the data
Leni Aniva (Sep 07 2023 at 21:25):
Is Subtype
just a special case for PSigma
?
Henrik Böving (Sep 07 2023 at 21:26):
One could say that yes.
Last updated: Dec 20 2023 at 11:08 UTC