Zulip Chat Archive

Stream: mathlib4

Topic: LinearMap.ker / range not taking FunLike


Alex Meiburg (Dec 20 2025 at 18:04):

In response #33107, @Monica Omar suggested that LinearMap.ker and LinearMap.range should be changed to take a LinearMap itself instead of a SemilinearMapClass -- and that we should start a thread on Zulip.

I seem to recall a larger conversation about avoiding the use of functions taking these bundled FunLike and FooHomClass things, but I can't find it now...?

Monica Omar (Dec 20 2025 at 18:09):

here’s another related recent thread I just found: https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/LinearMap.2Erange.20for.20ContinuousLinearMap/with/564194232

Artie Khovanov (Dec 20 2025 at 18:25):

@Yaël Dillies

Aaron Liu (Dec 20 2025 at 18:30):

#mathlib4 > Mathlib's morphism hierarchy

Yaël Dillies (Dec 20 2025 at 18:48):

Please do so!

Yury G. Kudryashov (Dec 20 2025 at 19:06):

I wonder if Lean will simplify inside (LinearMap.ker (ContinuousLinearMap.toLinearMap f) : Type _) to {x | f x = 0}.

Yury G. Kudryashov (Dec 20 2025 at 19:07):

See also #mathlib4 > Coercion of SetLike to Type*

Yury G. Kudryashov (Dec 23 2025 at 17:59):

I've tried to give it a go. So far, the main inconvenience is that Lean can't automatically coerce f : M →L[R] N to an unknown semilinear map, so p.map f requires an explicit type annotation.

Yury G. Kudryashov (Dec 23 2025 at 18:00):

Can we change Coe* instances somehow to make it "just work"?

Yaël Dillies (Dec 23 2025 at 18:05):

This is the "functorial coercion" business we have been talking about for a while, no?

Yury G. Kudryashov (Dec 23 2025 at 18:18):

I think I've missed the discussions because of my day job.

Yury G. Kudryashov (Dec 23 2025 at 18:23):

Is there any consensus about what should we do?

Yaël Dillies (Dec 23 2025 at 18:24):

Once #mathlib4 > Mathlib's morphism hierarchy is done, you will be able to write f.toLinearMap without fearing for simp normal form. For coercions however, no concrete plan was ever given.

Monica Omar (Dec 23 2025 at 18:25):

I'm confused, is this about LinearMap.ker/range? or something else?

Yury G. Kudryashov (Dec 23 2025 at 18:29):

More specifically, it's about Submodule.map. I don't want to write p.map f.toLinearMap. I want to write p.map f and let Lean find *.toLinearMap as a coercion.

Yury G. Kudryashov (Dec 23 2025 at 18:31):

I've redefined LinearMap.ker, LinearMap.range, Submodule.map, and Submodule.comap to take LinearMaps, and I'm gettings lots of these errors.

Monica Omar (Dec 23 2025 at 18:32):

Let's start with ker and range for now. We can deal with Submodule.co(map) separately?

Monica Omar (Dec 23 2025 at 18:33):

Specifically for the range and kernel, I don't think we mind doing .toLinearMap.ker/range do we?

Monica Omar (Dec 23 2025 at 18:34):

it's basically the same amount of effort as LinearMap.range f

Yury G. Kudryashov (Dec 23 2025 at 18:34):

For ker and range, we can write f.ker.

Yury G. Kudryashov (Dec 23 2025 at 18:35):

If we don't do Submodule.map/comap in the same PR, then we need to do map_top and comap_bot for different types.

Monica Omar (Dec 23 2025 at 18:37):

Ah, I see. Okay, obviously in the same PR then.

Monica Omar (Dec 23 2025 at 18:39):

for continuous linear maps, do you also need to do p.map f.toLinearMap or does p.map f work? nvm, I just reread the first message

Yury G. Kudryashov (Dec 23 2025 at 18:57):

I need f.toLinearMap or (f : explicit_type).

Yury G. Kudryashov (Dec 23 2025 at 19:00):

f.ker works because Lean allows us to call methods of a parent structure from an instance of a child structure via dot notation.

Monica Omar (Dec 23 2025 at 19:01):

If we don't do Submodule.map/comap in the same PR, then we need to do map_top and comap_bot for different types.

Can you not just use docs#LinearMapClass.linearMap?

Monica Omar (Dec 23 2025 at 19:10):

Can you draft-PR what you got so far so we can all have a look?

Eric Wieser (Dec 23 2025 at 19:11):

Monica Omar said:

Can you not just use docs#LinearMapClass.linearMap?

This is precisely the thing that we were converging on declaring a bad design, I think

Yury G. Kudryashov (Dec 23 2025 at 19:36):

#33241

Eric Wieser (Dec 23 2025 at 19:44):

Yury G. Kudryashov said:

I need f.toLinearMap or (f : explicit_type).

I wonder if we can use unification hints or extra coercion instances to make this better-behaved

Monica Omar (Dec 23 2025 at 19:58):

This is precisely the thing that we were converging on declaring a bad design, I think

The coercion from LinearMapClass to LinearMap is also bad design, right?

Yury G. Kudryashov (Dec 23 2025 at 19:58):

I guess that Eric missed "not" in your message. At least, I did first time I've read it.

Yury G. Kudryashov (Dec 23 2025 at 19:59):

Note that we can no longer have generic span_image etc lemmas.

Yury G. Kudryashov (Dec 23 2025 at 20:09):

Eric Wieser said:

Yury G. Kudryashov said:

I need f.toLinearMap or (f : explicit_type).

I wonder if we can use unification hints or extra coercion instances to make this better-behaved

I'm bad at this kind of metaprogramming (at least, for now).

Aaron Liu (Dec 23 2025 at 20:37):

Eric Wieser said:

Monica Omar said:

Can you not just use docs#LinearMapClass.linearMap?

This is precisely the thing that we were converging on declaring a bad design, I think

I thought this was fine, taking the morphism class into the concrete morphism

Eric Wieser (Dec 23 2025 at 21:15):

Yury G. Kudryashov said:

I guess that Eric missed "not" in your message. At least, I did first time I've read it.

"Can you not just use X?" to me means "let's use X it should be fine?". I guess what was meant was "Can you just not use X at all".

Eric Wieser (Dec 23 2025 at 21:16):

It's fine to have that helper definition to use in proofs, but it isn't the preferred form and so doesn't belong in theorem statements.

Yury G. Kudryashov (Dec 23 2025 at 22:30):

So, not only I misread this, but also failed to understand when I saw all the words :man_facepalming:

Andrew Yang (Dec 23 2025 at 22:32):

cc @Christian Merten who has a PR on this as well.

Monica Omar (Dec 23 2025 at 22:35):

That PR is about RingHom not LinearMap right?

Monica Omar (Dec 23 2025 at 22:36):

Yeah it is: #25138

Yury G. Kudryashov (Dec 24 2025 at 03:17):

I've fixed compile issues.


Last updated: Feb 28 2026 at 14:05 UTC