Zulip Chat Archive

Stream: mathlib4

Topic: notation for coercion to completion


Kevin Buzzard (May 20 2024 at 12:11):

These lines (with (α : Type*) [UniformSpace α])

/-- The map from a uniform space to its completion.

porting note: this was added to create a target for the `@[coe]` attribute. -/
@[coe] def coe' : α  Completion α := SeparationQuotient.mk  pureCauchy

/-- Automatic coercion from `α` to its completion. Not always injective. -/
instance : Coe α (Completion α) :=
  coe' α

in Mathlib.Topology.UniformSpace.Completion cause the coercion of k : K (a number field) to its completion wrt a valuation (a p-adic field) to be written as ↑K k. Is this intended? I stared at ↑K trying to figure out what K was being coerced to for a bit before it dawned on me what was going on. Is everyone else used to this and I only just noticed it?

Yaël Dillies (May 20 2024 at 12:29):

That looks like a bug in the delaborator

Ruben Van de Velde (May 20 2024 at 12:35):

I noticed it during the port (and haven't been touching anything that triggers it since then)

Ruben Van de Velde (May 20 2024 at 12:35):

Maybe someone should file an issue

Kevin Buzzard (May 20 2024 at 12:45):

I'm on a train but will do it later if nobody else does it first.

Kyle Miller (May 20 2024 at 16:26):

It's not a bug in the delaborator, it's a misapplied @[coe] attribute. The assumption with @[coe] is that the first explicit argument is the value being coerced. However, the first explicit argument of coe' is the type of the value being coerced.

Kyle Miller (May 20 2024 at 16:31):

This seems to work:

protected def coe : α  Completion α := SeparationQuotient.mk  pureCauchy

run_cmd Lean.Elab.Command.liftTermElabM do
  Lean.Meta.registerCoercion ``Completion.coe
    (some { numArgs := 3, coercee := 2, type := .coe })

/-- Automatic coercion from `α` to its completion. Not always injective. -/
instance : Coe α (Completion α) :=
  Completion.coe α

Patrick Massot (May 20 2024 at 16:50):

Having an explicit argument here is weird. One could also argue this should not be a coercion but this is another debate.

Kyle Miller (May 20 2024 at 16:58):

Assuming it's a good idea for it to be a coercion, a benefit to having the type being explicit here is that ((↑) : α → Completion α), which appears frequently in the file, appears as Completion.coe α, which is more readable than just Completion.coe.

Patrick Massot (May 20 2024 at 17:17):

I think that ((↑) : α → Completion α) is more explicit than Completion.coe α.

Anatole Dedecker (May 20 2024 at 17:18):

I agree, although I think I would also like if we had a cleaner canonical notation for "the coercion map between foo and bar".

Patrick Massot (May 20 2024 at 17:19):

I have a hard time imagining how it could be more concise and explicit than the above spelling.

Anatole Dedecker (May 20 2024 at 17:20):

At least by removing some parentheses ?

Patrick Massot (May 20 2024 at 17:21):

Indeed that would be nice.

Kyle Miller (May 20 2024 at 17:26):

@Patrick Massot I meant the way it pretty prints. There's no mechanism for pretty printing as ((↑) : α → Completion α) yet.

Patrick Massot (May 20 2024 at 17:27):

Oh, I see.

Kyle Miller (May 20 2024 at 17:27):

The module consistently uses this notation in the source code at least.

Mitchell Lee (May 20 2024 at 17:30):

The name for this map is very inconsistent. If it's a uniformly continuous function it's called docs#UniformSpace.Completion.coe'. If it's a uniform additive group homomorphism it's called docs#UniformSpace.Completion.toCompl. If it's a uniform ring homomorphism it's called docs#UniformSpace.Completion.coeRingHom.

Kevin Buzzard (Jan 06 2025 at 12:20):

#20514 makes alpha implicit. Mathlib still compiles fine.


Last updated: May 02 2025 at 03:31 UTC