Zulip Chat Archive

Stream: general

Topic: enat pain


Johan Commelin (Sep 03 2021 at 19:02):

Is this a known bug?

example (n : ) :
  @eq enat
    (@coe nat enat (@coe_to_lift nat enat (@nat.cast_coe enat (@add_zero_class.to_has_zero enat
      (@add_monoid.to_add_zero_class enat (@add_comm_monoid.to_add_monoid enat enat.add_comm_monoid)))
        enat.has_one (@add_zero_class.to_has_add enat (@add_monoid.to_add_zero_class enat
          (@add_comm_monoid.to_add_monoid enat enat.add_comm_monoid))))) n)
    (@coe nat enat (@coe_to_lift nat enat (@coe_base nat enat enat.has_coe)) n) := rfl -- fails

Johan Commelin (Sep 03 2021 at 19:46):

lemma enat.coe_eq_coe (n : ) :
  @eq enat
    (@coe nat enat (@coe_to_lift nat enat (@nat.cast_coe enat (@add_zero_class.to_has_zero enat
      (@add_monoid.to_add_zero_class enat (@add_comm_monoid.to_add_monoid enat enat.add_comm_monoid)))
        enat.has_one (@add_zero_class.to_has_add enat (@add_monoid.to_add_zero_class enat
          (@add_comm_monoid.to_add_monoid enat enat.add_comm_monoid))))) n)
    (@coe nat enat (@coe_to_lift nat enat (@coe_base nat enat enat.has_coe)) n) :=
begin
  induction n with n ih, { refl },
  simp only [nat.succ_eq_add_one, enat.coe_one, enat.coe_add, nat.cast_add, nat.cast_one, ih],
end

Johan Commelin (Sep 04 2021 at 06:39):

Can some coercion expert please explain how to fix this issue?

Johan Commelin (Sep 04 2021 at 06:56):

I need this for #8994

Yaël Dillies (Sep 04 2021 at 07:35):

I'm not an expert, but I figured out it was because coe_base isn't defeq to nat.cast

Yaël Dillies (Sep 04 2021 at 07:37):

coe_base uses part.some (because enat is part ℕ...) and nat.cast uses the semiring structure.

Yaël Dillies (Sep 04 2021 at 07:39):

I'm of the opinion that the current enat is a pile of pain. I would redefine it as with_top ℕ, because that's what it is. The reason to have it as part ℕ is to have a computable enat.find

Kevin Buzzard (Sep 04 2021 at 07:40):

I would imagine you can have the same diamond with with_top nat

Yaël Dillies (Sep 04 2021 at 07:41):

Yeah, but this time we already thought about it, as many more things are with_top R than part R

Yaël Dillies (Sep 04 2021 at 07:43):

Long answer short: burn coe_base :smiling_imp:

Johan Commelin (Sep 04 2021 at 07:56):

It is important the the coercion is computable? I would think that we can just have the computable version as a plain function, ready to use if someone needs it, and let the coe be whatever is automatically infered.

Yaël Dillies (Sep 04 2021 at 07:57):

Yes, exactly what I'm thinking. But maybe computabilists want to have their say.

Yaël Dillies (Sep 04 2021 at 07:58):

Note that:

  1. It's already a plain function: part.some (maybe there's even an enat specialization?)
  2. Many lemmas will need changing

Johan Commelin (Sep 04 2021 at 12:53):

I will try to fix this

Johan Commelin (Sep 04 2021 at 15:12):

enat.lean compiles again. Let's see about the rest of mathlib.

Yakov Pechersky (Sep 05 2021 at 01:45):

src#enat.has_coe, src#nat.cast_coe

Johan Commelin (Sep 06 2021 at 05:54):

#9023 refactors the coercion.

Johan Commelin (Sep 06 2021 at 12:39):

From the PR description:

The coercion from nat to enat was defined to be enat.some. But another
coercion could be inferred from the additive structure on enat, leading to
confusing goals of the form
↑n = ↑n where the two sides were not defeq.

We now make the coercion inferred from the additive structure the default,
even though it is not computable.

A dedicated function enat.some is introduced, to be used whenever
computability is important.

CI is happy with the PR.

Yury G. Kudryashov (May 16 2022 at 07:38):

Unless someone objects, I'm going to redefine docs#enat as with_top nat. This way we get

  • definitions using pattern matching;
  • various instances (e.g., canonically_ordered_comm_semiring) for free.

Yury G. Kudryashov (May 16 2022 at 07:40):

And now I have an objection: there are two natural coercions nat → with_top nat...

Yury G. Kudryashov (May 16 2022 at 07:40):

How can we resolve this?

Yury G. Kudryashov (May 16 2022 at 07:43):

Add nat_cast field to some algebraic class?

Kevin Buzzard (May 16 2022 at 07:44):

We have 0 * top = 0?

Eric Wieser (May 16 2022 at 07:47):

Yury G. Kudryashov said:

Add nat_cast field to some algebraic class?

@Gabriel Ebner already has an open PR to do this (#12182), which I think is necessary for lean4 anyway

Violeta Hernández (May 16 2022 at 07:56):

I was wondering why this wasn't the case before

Yury G. Kudryashov (May 16 2022 at 07:57):

Kevin Buzzard said:

We have 0 * top = 0?

Yes, see docs#with_top.mul_zero_class

Yaël Dillies (May 16 2022 at 08:57):

Yury G. Kudryashov said:

And now I have an objection: there are two natural coercions nat → with_top nat...

Note that this is already the case for int. We have the custom coercion docs#int.has_coe

Violeta Hernández (Jun 28 2022 at 15:21):

Why exactly is enat not defined as with_top ℕ?

Violeta Hernández (Jun 28 2022 at 15:22):

Oh wait, this thread discusses exactly this

Violeta Hernández (Jun 28 2022 at 15:22):

I was just lamenting the lack of a succ_order instance on enat.

Yaël Dillies (Jun 28 2022 at 15:22):

See https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/enat.20pain/near/251981337

Violeta Hernández (Jun 28 2022 at 15:58):

Hmm

Violeta Hernández (Jun 28 2022 at 15:59):

We recently refactored the whole API for coercions from

Violeta Hernández (Jun 28 2022 at 15:59):

How does that impact this?

Yaël Dillies (Jun 28 2022 at 15:59):

It makes such a refactor actually doable.

Violeta Hernández (Jun 28 2022 at 16:11):

I already have 2 or 3 large refactors on my hands :sweat_smile:

Violeta Hernández (Jun 28 2022 at 16:11):

If nobody takes this in a month or two, I'll do it myself

Yury G. Kudryashov (Jun 29 2022 at 17:56):

For me, this is one of the things I want to have done but too lazy to do.


Last updated: Dec 20 2023 at 11:08 UTC