Zulip Chat Archive

Stream: mathlib4

Topic: Algebra.cast and algebraMap


Daniel Weber (Jul 06 2024 at 03:27):

Currently something which is quite annoying for automation is that simp fails to show algebraMap A B a = (a : B):

import Mathlib

open algebraMap

example (A B : Type*) [CommSemiring A] [Semiring B] [Algebra A B] (a : A) : algebraMap A B a = a := by
  fail_if_success simp
  rfl

What's the best way to solve this? It's possible to just add it as a @[simp] lemma (probability scoped to algebraMap), and I've also thought about making Algebra.cast reducible, but I'm not sure about the exact pros and cons of either

Kevin Buzzard (Jul 06 2024 at 08:36):

I have been working with algebraMap with algebraMap open and am also a bit confused about what the simp normal form is supposed to be. For quotients R/IR/I there's another coercion from RR which exists even without algebraMap open (I asked a question about this recently) (edit: here)

Eric Wieser (Jul 06 2024 at 09:02):

We have two spellings here because the port interrupted a major refactor by @Anne Baanen. I think changes to coercions to lean 4 made the original plan untenable.

Eric Wieser (Jul 06 2024 at 09:02):

My vote would be to drop Algebra.cast until someone finds time to come up with a plan for a replacement refactor.

Kevin Buzzard (Jul 06 2024 at 09:38):

So you're saying "drop the coercion associated to [Algebra A B]"? I'm using this coercion a lot, I love it.

Eric Wieser (Jul 06 2024 at 12:36):

Or make it mean algebraMap

Kevin Buzzard (Jul 06 2024 at 13:32):

My understanding was that Lean 4 does not allow us to have things like algebraMap (whose type is not a function type) as coercions? I thought that this was why we introduced Algebra.cast in the first place?

Eric Wieser (Jul 07 2024 at 00:07):

Arguably they work fine, and it's just the pretty-printing that doesn't

Eric Wieser (Jul 07 2024 at 00:08):

I think the original goal might have been to drop Nat.cast and Int.cast and Rat.cast and use Algebra.cast as the spelling of all of them

Yaël Dillies (Jul 07 2024 at 01:15):

That goes against making Nat/Int/Rat foundational, right?

Eric Wieser (Jul 07 2024 at 09:06):

I don't think so?

Eric Wieser (Jul 07 2024 at 09:08):

It goes against the "every coercion should be a different function" thing that core seems to have designed for, but so does the design of Dfunlike

Eric Wieser (Jul 07 2024 at 09:09):

A data only AlgebraCast type class next to docs#NatCast would do the trick.

Daniel Weber (Jul 10 2024 at 05:27):

I've been experimenting with making Algebra.cast @[reducible] on branch#CommandMaster_castReducible (#14601)


Last updated: May 02 2025 at 03:31 UTC