Zulip Chat Archive

Stream: Is there code for X?

Topic: More currying of continuous multilinear maps


Anatole Dedecker (Jul 24 2023 at 19:38):

Just to be sure, we don't have currying of docs#ContinuousMultilinearMap in the following form, right?

import Mathlib.Analysis.NormedSpace.Multilinear
import Mathlib.Analysis.NormedSpace.OperatorNorm

variable [NontriviallyNormedField π•œ] [NormedAddCommGroup E] [NormedAddCommGroup F]
  [NormedSpace π•œ E] [NormedSpace π•œ F]

set_option synthInstance.maxHeartbeats 50000 in
def foo {m n : β„•} : (E [Γ—m]β†’L[π•œ] (E [Γ—n]β†’L[π•œ] F)) ≃ₗᡒ[π•œ] E [Γ—(m+n)]β†’L[π•œ] F := sorry

Anatole Dedecker (Jul 24 2023 at 19:40):

(Yes, even the type causes the typclass system to go nuts. There is something fishy going on with continuous multilinear maps that I'm trying to minimize, I've been fighting with >2s TC synthesis of some CoeFun... -- although in this case it's Module that's taking some time)

Yury G. Kudryashov (Jul 24 2023 at 20:22):

We have docs#ContinuousMultilinearMap.currySumEquiv

Yury G. Kudryashov (Jul 24 2023 at 20:23):

Together with docs#ContinuousMultilinearMap.domDomCongrβ‚—α΅’ it should give what you want.

Yury G. Kudryashov (Jul 24 2023 at 20:24):

Scratch that, we have docs#ContinuousMultilinearMap.curryFinFinset

Yury G. Kudryashov (Jul 24 2023 at 20:24):

To get your version, just take s to be the first m elements of Fin (m + n).

Anatole Dedecker (Jul 24 2023 at 20:25):

Thanks!

Yury G. Kudryashov (Jul 24 2023 at 20:25):

I wonder if #2202 will help with CoeFun synth here and there.

Yury G. Kudryashov (Jul 24 2023 at 20:25):

But this is a big refactor.

Anatole Dedecker (Jul 24 2023 at 20:32):

Leaving the CoeFun example aside for the moment (I'll try to minimize it), I'd be interested if someone understand why the typeclass inference takes such a long time in this example. On my computer it ends up spending .8s to prove that two instances of AddMonoid are equal, which is very fishy.

Anatole Dedecker (Jul 24 2023 at 20:33):

But when I write the corresponding equality and try to prove it by rfl it takes "only" .2s

Eric Wieser (Jul 24 2023 at 20:33):

I think it has a lot of tower problems it has to solve, though I'm not sure

Anatole Dedecker (Jul 24 2023 at 20:34):

To be clear most of the time here is actually spent on defeq-checking, not typeclass synthesis. EDIT: that's a stupid comment, this is always what takes a long time...

Yury G. Kudryashov (Jul 24 2023 at 20:38):

Can we help the defeq checker somehow?

Anatole Dedecker (Jul 24 2023 at 20:40):

I'm wondering wether the fact that docs#ContinuousMultilinearMap.normedAddCommGroup is defined using docs#AddGroupNorm.toNormedAddCommGroup could be a problem

Yury G. Kudryashov (Jul 24 2023 at 20:40):

Why is this a problem?

Anatole Dedecker (Jul 24 2023 at 20:41):

I don't know :sweat_smile: I'm trying to guess why it has to unfold so much things to see that the two AddMonoid instances are equal.

Yury G. Kudryashov (Jul 24 2023 at 20:44):

Will it become faster if you explicitly override toAddCommGroup?

Eric Wieser (Jul 24 2023 at 21:03):

It would likely become faster if you did that inside GroupNorm.toNormedCommGroup

Anatole Dedecker (Jul 25 2023 at 11:45):

Yury G. Kudryashov said:

Will it become faster if you explicitly override toAddCommGroup?

Overriding toAddCommGroup itself does not have a significant impact, but overriding add, nsmul and zero do!

Yury G. Kudryashov (Jul 25 2023 at 14:13):

So, you force Lean to flatten the constructor.

Eric Wieser (Jul 25 2023 at 14:14):

That's the opposite of the behavior I would expect

Eric Wieser (Jul 25 2023 at 14:14):

Did you do this in GroupNorm.toNormedCommGroup or your instance?

Anatole Dedecker (Jul 25 2023 at 14:24):

I did that directly in docs#ContinuousMultilinearMap.normedAddCommGroup

Yury G. Kudryashov (Jul 25 2023 at 14:28):

Maybe, Lean has to unify this instance with some flat instance; then it's easier to do it if both instances are flat. I don't know how to verify this guess.

Eric Wieser (Jul 25 2023 at 14:31):

But there's no such thing as a flat instance

Eric Wieser (Jul 25 2023 at 14:31):

Only nested instances where the nested bits are also nested

Eric Wieser (Jul 25 2023 at 14:32):

Eric Wieser said:

It would likely become faster if you did that inside GroupNorm.toNormedCommGroup

Can you try this and see if it helps?


Last updated: Dec 20 2023 at 11:08 UTC