Zulip Chat Archive

Stream: general

Topic: nat.cast diamond


Yaël Dillies (Oct 04 2021 at 12:30):

Yet another diamond involving nat.cast...

import data.nat.cast

example (n : ) : (nat.cast n : ) = n :=
begin
  refl, --fails
end

Yury G. Kudryashov (Oct 04 2021 at 12:31):

AFAIR, we have a simp lemma for this.

Yaël Dillies (Oct 04 2021 at 12:31):

The culprit is docs#int.has_coe. Should we nuke it?

Yury G. Kudryashov (Oct 04 2021 at 12:32):

See docs#nat_cast_eq_coe_nat

Yaël Dillies (Oct 04 2021 at 12:33):

For context, when @Johan Commelin stumbled on the problem with enat, we decided to delete the enat-specific coercion.

Yury G. Kudryashov (Oct 04 2021 at 12:34):

This won't solve

example (n : ) : (n : ) = n := rfl -- fails

Yaël Dillies (Oct 04 2021 at 12:34):

What about we delete ?

Yury G. Kudryashov (Oct 04 2021 at 12:37):

One way to deal with this is to include of_nat into the signature of semiring and restrict nat.cast to semirings.

Johan Commelin (Oct 04 2021 at 12:38):

It's going to be a royal PITA to do that refactor, but it's the logical extension of what we've been doing already.

Yakov Pechersky (Oct 04 2021 at 12:38):

At that point, you might as well use nat.bin_cast since you have all the proofs that they're the same, given your semiring.

Yury G. Kudryashov (Oct 04 2021 at 12:38):

Then we'll loose defeq ↑(n + 1) = ↑n + 1.

Yury G. Kudryashov (Oct 04 2021 at 12:39):

And you can use int.has_coe for integers, id for naturals.

Yaël Dillies (Oct 04 2021 at 12:39):

So no nat.cast for monoids anymore?

Yury G. Kudryashov (Oct 04 2021 at 12:40):

Are there examples of add_monoid + has_one but no semiring where we care about nat.cast?

Yakov Pechersky (Oct 04 2021 at 12:41):

Games?

Yakov Pechersky (Oct 04 2021 at 12:41):

I don't remember if it's pregames or games

Yakov Pechersky (Oct 04 2021 at 12:41):

I just remember proving that nat.bin_cast does the right thing for them was brutal. I don't remember if I even finished that.

Yury G. Kudryashov (Oct 04 2021 at 12:42):

You can have a separate has_coe instance in this case.

Yury G. Kudryashov (Oct 04 2021 at 12:42):

Most properties of nat.cast follow from it being an add_monoid_hom.

Johan Commelin (Oct 04 2021 at 12:45):

Otoh, I don't really care about whether ↑n is defeq to n. What I do care about, is that all the coercions from to are defeq.

Yakov Pechersky (Oct 04 2021 at 12:45):

I understand the reason to put nsmul and gsmul into the typeclass, to make typeclass inference and unification work better, because we can't provide proofs to the TC resolver. But what TC issue is there here?

Yakov Pechersky (Oct 04 2021 at 12:45):

In general, it has seemed that we avoid making things rfl proofs, because that just hides complexity.

Yaël Dillies (Oct 04 2021 at 12:46):

We have a generic coercion from to any unital add_monoidand a specific one from to .

Johan Commelin (Oct 04 2021 at 13:03):

I'm inclined to nuke the specific coe from to . If people want a map ℕ → ℤ that computes well, they can call it by name, instead of using the coe.

Sebastien Gouezel (Oct 04 2021 at 13:03):

Why not just kill the specific one?

Johan Commelin (Oct 04 2021 at 13:03):

But I understand that this is a very mathsy opinion.

Sebastien Gouezel (Oct 04 2021 at 13:04):

You just beat me to it :-)

Johan Commelin (Oct 04 2021 at 13:04):

I think @Mario Carneiro was strongly in favour of keeping the specific coe around.

Mario Carneiro (Oct 04 2021 at 13:07):

The issue with exponential time coes is bad enough already. This would just make that get secretly used all over the place, causing pain and suffering for anyone with lean 3 code that we aren't actively monitoring

Eric Wieser (Oct 04 2021 at 13:18):

We could add of_nat : has_one α → ℕ → α to add_monoid?

Yaël Dillies (Oct 04 2021 at 13:20):

That sounds like a good tradeof.

Yury G. Kudryashov (Oct 04 2021 at 13:25):

@Eric Wieser I think that the better way is to add add_monoid_with_one.

Yury G. Kudryashov (Oct 04 2021 at 13:25):

If you add of_nat : has_one α → ℕ → α with appropriate axioms, then you won't be able to ignore the has_one argument in the case α = int.

Eric Wieser (Oct 04 2021 at 13:29):

Yury G. Kudryashov said:

Eric Wieser I think that the better way is to add add_monoid_with_one.

But then you also might need add_comm_monoid_with_one, add_cancel_comm_monoid_with_one, add_group_with_one, ...


Last updated: Dec 20 2023 at 11:08 UTC