Zulip Chat Archive

Stream: mathlib4

Topic: Operator norm


Patrick Massot (Jun 03 2023 at 08:21):

The following mystery is blocking calculus in mathlib4:

import Mathlib.Analysis.Calculus.ContDiffDef
import Mathlib.Analysis.Calculus.Deriv.Inverse
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Analysis.NormedSpace.FiniteDimension
import Mathlib.Data.Nat.Choose.Cast

variable {๐•œ : Type _} [NontriviallyNormedField ๐•œ] {Du Eu Fu Gu : Type u}
    [NormedAddCommGroup Du] [NormedSpace ๐•œ Du] [NormedAddCommGroup Eu] [NormedSpace ๐•œ Eu]
    [NormedAddCommGroup Fu] [NormedSpace ๐•œ Fu] [NormedAddCommGroup Gu] [NormedSpace ๐•œ Gu]

#check (Eu โ†’L[๐•œ] (Du โ†’L[๐•œ] Fu) โ†’L[๐•œ] Du โ†’L[๐•œ] Gu)

#check (Du โ†’L[๐•œ] Fu) โ†’L[๐•œ] Du โ†’L[๐•œ] Gu

set_option trace.Meta.synthInstance true in
#synth Norm (Du โ†’L[๐•œ] Fu)

#synth Norm ((Du โ†’L[๐•œ] Fu) โ†’L[๐•œ] Du โ†’L[๐•œ] Gu)


set_option trace.Meta.synthInstance true in
#synth Norm (Eu โ†’L[๐•œ] ((Du โ†’L[๐•œ] Fu) โ†’L[๐•œ] Du โ†’L[๐•œ] Gu))

Ruben Van de Velde (Jun 03 2023 at 08:22):

Not the operator norm again :see_no_evil:

Patrick Massot (Jun 03 2023 at 08:22):

Lean has no trouble finding the operator norm until (Du โ†’L[๐•œ] Fu) โ†’L[๐•œ] Du โ†’L[๐•œ] Gu but fails with Eu โ†’L[๐•œ] ((Du โ†’L[๐•œ] Fu) โ†’L[๐•œ] Du โ†’L[๐•œ] Gu)

Patrick Massot (Jun 03 2023 at 08:22):

This is the first error in !4#4532.

Patrick Massot (Jun 03 2023 at 08:23):

Ruben, you seem to be a specialist in this issue, it would be very nice to have a fix.

Patrick Massot (Jun 03 2023 at 08:24):

This file is the main remaining roadblock to restoring the calculus chapter in MIL.

Ruben Van de Velde (Jun 03 2023 at 08:26):

I'm not sure any such reputation is deserved, but I'll try to find some time later today

Eric Wieser (Jun 03 2023 at 08:57):

Is it able to find this instance if given the expression to construct it explicitly?

Eric Wieser (Jun 03 2023 at 10:47):

Answer: no :fear:

-- type mismatch
example : Norm (Eu โ†’L[๐•œ] ((Du โ†’L[๐•œ] Fu) โ†’L[๐•œ] Du โ†’L[๐•œ] Gu)) := ContinuousLinearMap.hasOpNorm

Going through the isDefEq trace suggests thar the problem is that itfound stuck MVar.

Eric Wieser (Jun 03 2023 at 10:55):

I think there's some weird universe problem:

set_option pp.universes true in
example : Norm (Eu โ†’L[๐•œ] ((Du โ†’L[๐•œ] Fu) โ†’L[๐•œ] Du โ†’L[๐•œ] Gu)) :=
    let foo : NormedAddCommGroup ((Du โ†’L[๐•œ] Fu) โ†’L[๐•œ] Du โ†’L[๐•œ] Gu) := by infer_instance
    ContinuousLinearMap.hasOpNorm

This has an error on both the last two lines, but the error goes away if you replace the last line with sorry

Kevin Buzzard (Jun 03 2023 at 11:01):

I'm assuming it's just a coincidence that mathlib's longest declaration name is about these objects.

Eric Wieser (Jun 03 2023 at 11:02):

Note that that instance is already a porting hack, so probably this is related

Johan Commelin (Jun 03 2023 at 12:17):

@Eric Wieser Why do you think it is related to universes?

Eric Wieser (Jun 03 2023 at 12:18):

Because the metavariable has an unresolved universe argument

Eric Wieser (Jun 03 2023 at 12:18):

And the error in the above code sample complains about unifying max ? ? with u

Patrick Massot (Jun 03 2023 at 13:05):

I pushed a hack feeding this instance into the first failing proof, but I need to give up on the next proof for now (the issue seems different). But working on this file is almost impossible because everything is so slow. So probably we can't avoid facing that issue for real.

Kevin Buzzard (Jun 03 2023 at 17:12):

   [tryResolve] โŒ RingHomIsometric (RingHom.id ๐•œ) โ‰Ÿ RingHomIsometric (RingHom.id ?m.51913)

:-(

I don't really know what a stuck metavariable is but this shows up a few times in the trace:

          [synthInstance] โŒ SeminormedAddCommGroup ((Du โ†’L[๐•œ] Fu) โ†’L[๐•œ] Du โ†’L[๐•œ] Gu) โ–ถ
          [] โŒ ContinuousLinearMap.topologicalSpace =?= UniformSpace.toTopologicalSpace โ–ผ
            [] โŒ ContinuousLinearMap.strongTopology (RingHom.id ๐•œ) (Du โ†’L[๐•œ] Gu)
                  {S | Bornology.IsVonNBounded ๐•œ S} =?= UniformSpace.toTopologicalSpace โ–ผ
              [] โŒ TopologicalSpace.induced FunLike.coe
                    (UniformOnFun.topologicalSpace (Du โ†’L[๐•œ] Fu) (Du โ†’L[๐•œ] Gu)
                      {S | Bornology.IsVonNBounded ๐•œ S}) =?= UniformSpace.toTopologicalSpace โ–ผ
                [] โŒ { IsOpen := fun s โ†ฆ โˆƒ s', IsOpen s' โˆง FunLike.coe โปยน' s' = s,
                      isOpen_univ := (_ : โˆƒ s', IsOpen s' โˆง FunLike.coe โปยน' s' = Set.univ),
                      isOpen_inter :=
                        (_ :
                          โˆ€ (sโ‚ sโ‚‚ : Set ((Du โ†’L[๐•œ] Fu) โ†’L[๐•œ] Du โ†’L[๐•œ] Gu)),
                            (โˆƒ s', IsOpen s' โˆง FunLike.coe โปยน' s' = sโ‚) โ†’
                              (โˆƒ s', IsOpen s' โˆง FunLike.coe โปยน' s' = sโ‚‚) โ†’
                                (fun s โ†ฆ โˆƒ s', IsOpen s' โˆง FunLike.coe โปยน' s' = s) (sโ‚ โˆฉ sโ‚‚)),
                      isOpen_sUnion :=
                        (_ :
                          โˆ€ (S : Set (Set ((Du โ†’L[๐•œ] Fu) โ†’L[๐•œ] Du โ†’L[๐•œ] Gu))),
                            (โˆ€ (t : Set ((Du โ†’L[๐•œ] Fu) โ†’L[๐•œ] Du โ†’L[๐•œ] Gu)),
                                t โˆˆ S โ†’ (fun s โ†ฆ โˆƒ s', IsOpen s' โˆง FunLike.coe โปยน' s' = s) t) โ†’
                              โˆƒ s', IsOpen s' โˆง FunLike.coe โปยน' s' = โ‹ƒโ‚€ S) } =?= UniformSpace.toTopologicalSpace โ–ผ
                  [] โŒ { IsOpen := fun s โ†ฆ โˆƒ s', IsOpen s' โˆง FunLike.coe โปยน' s' = s,
                        isOpen_univ := (_ : โˆƒ s', IsOpen s' โˆง FunLike.coe โปยน' s' = Set.univ),
                        isOpen_inter :=
                          (_ :
                            โˆ€ (sโ‚ sโ‚‚ : Set ((Du โ†’L[๐•œ] Fu) โ†’L[๐•œ] Du โ†’L[๐•œ] Gu)),
                              (โˆƒ s', IsOpen s' โˆง FunLike.coe โปยน' s' = sโ‚) โ†’
                                (โˆƒ s', IsOpen s' โˆง FunLike.coe โปยน' s' = sโ‚‚) โ†’
                                  (fun s โ†ฆ โˆƒ s', IsOpen s' โˆง FunLike.coe โปยน' s' = s) (sโ‚ โˆฉ sโ‚‚)),
                        isOpen_sUnion :=
                          (_ :
                            โˆ€ (S : Set (Set ((Du โ†’L[๐•œ] Fu) โ†’L[๐•œ] Du โ†’L[๐•œ] Gu))),
                              (โˆ€ (t : Set ((Du โ†’L[๐•œ] Fu) โ†’L[๐•œ] Du โ†’L[๐•œ] Gu)),
                                  t โˆˆ S โ†’ (fun s โ†ฆ โˆƒ s', IsOpen s' โˆง FunLike.coe โปยน' s' = s) t) โ†’
                                โˆƒ s', IsOpen s' โˆง FunLike.coe โปยน' s' = โ‹ƒโ‚€ S) } =?= PseudoMetricSpace.toUniformSpace.1 โ–ผ
                    [] โœ… TopologicalSpace ((Du โ†’L[๐•œ] Fu) โ†’L[๐•œ] Du โ†’L[๐•œ] Gu) =?= TopologicalSpace ((Du โ†’L[๐•œ] Fu) โ†’L[๐•œ] Du โ†’L[๐•œ] Gu) โ–ถ
                    [] โŒ TopologicalSpace.IsOpen =?= fun s โ†ฆ โˆƒ s', IsOpen s' โˆง FunLike.coe โปยน' s' = s โ–ถ
                    [onFailure] โŒ { IsOpen := fun s โ†ฆ โˆƒ s', IsOpen s' โˆง FunLike.coe โปยน' s' = s,
                          isOpen_univ := (_ : โˆƒ s', IsOpen s' โˆง FunLike.coe โปยน' s' = Set.univ),
                          isOpen_inter :=
                            (_ :
                              โˆ€ (sโ‚ sโ‚‚ : Set ((Du โ†’L[๐•œ] Fu) โ†’L[๐•œ] Du โ†’L[๐•œ] Gu)),
                                (โˆƒ s', IsOpen s' โˆง FunLike.coe โปยน' s' = sโ‚) โ†’
                                  (โˆƒ s', IsOpen s' โˆง FunLike.coe โปยน' s' = sโ‚‚) โ†’
                                    (fun s โ†ฆ โˆƒ s', IsOpen s' โˆง FunLike.coe โปยน' s' = s) (sโ‚ โˆฉ sโ‚‚)),
                          isOpen_sUnion :=
                            (_ :
                              โˆ€ (S : Set (Set ((Du โ†’L[๐•œ] Fu) โ†’L[๐•œ] Du โ†’L[๐•œ] Gu))),
                                (โˆ€ (t : Set ((Du โ†’L[๐•œ] Fu) โ†’L[๐•œ] Du โ†’L[๐•œ] Gu)),
                                    t โˆˆ S โ†’ (fun s โ†ฆ โˆƒ s', IsOpen s' โˆง FunLike.coe โปยน' s' = s) t) โ†’
                                  โˆƒ s', IsOpen s' โˆง FunLike.coe โปยน' s' = โ‹ƒโ‚€ S) } =?= PseudoMetricSpace.toUniformSpace.1 โ–ผ
                      [stuckMVar] found stuck MVar ?m.51846 : SeminormedAddCommGroup ((Du โ†’L[๐•œ] Fu) โ†’L[๐•œ] Du โ†’L[๐•œ] Gu)

Eric Wieser (Jun 03 2023 at 17:19):

I think a lot of these traces would become easier to navigate with set_option pp.proofs false or whatever the name is

Kevin Buzzard (Jun 03 2023 at 17:20):

Maybe the problem is this:

/-
[tryResolve] โŒ RingHomIsometric (RingHom.id ๐•œ) โ‰Ÿ RingHomIsometric (RingHom.id ?m.52368) โ–ถ

LHS

@RingHomIsometric ๐•œ ๐•œ DivisionSemiring.toSemiring DivisionSemiring.toSemiring NormedField.toNorm NormedField.toNorm
  (RingHom.id ๐•œ) : Prop

RHS

@RingHomIsometric ?m.52368 ?m.52368 Ring.toSemiring Ring.toSemiring SeminormedRing.toNorm SeminormedRing.toNorm
  (RingHom.id ?m.52368) : Prop

-/

Eric Wieser (Jun 03 2023 at 17:21):

Does setting a default instance on RingHomIsometric for RingHom.id help at all?

Kevin Buzzard (Jun 03 2023 at 17:22):

(The above issue would align with the general picture of Lean 4 being a bit crap at the way we've set up ring theory and now this problem is leaking over to anything which uses fields :-/)

Kevin Buzzard (Jun 03 2023 at 17:28):

Eric Wieser said:

Does setting a default instance on RingHomIsometric for RingHom.id help at all?

Yes, it changes the issue to

              [] โŒ apply smulCommClass_self to SMulCommClass ๐•œ ๐•œ Fu โ–ผ
                [tryResolve] โŒ SMulCommClass ๐•œ ๐•œ Fu โ‰Ÿ SMulCommClass ?m.53239 ?m.53239 ?m.53240

Eric Wieser (Jun 03 2023 at 17:29):

That failure is expected, that's the wrong instance

Kevin Buzzard (Jun 03 2023 at 17:29):

LHS is @SMulCommClass ๐•œ ๐•œ Fu SMulZeroClass.toSMul SMulZeroClass.toSMul : Prop, RHS is @SMulCommClass ?m.53239 ?m.53239 ?m.53240 MulAction.toSMul MulAction.toSMul : Prop

Eric Wieser (Jun 03 2023 at 17:30):

I assume it's stuck because MulAction.toSMul on the RHS has more metavariables?

Eric Wieser (Jun 03 2023 at 17:30):

Is the LHS metavariable-free?

Kevin Buzzard (Jun 03 2023 at 17:31):

Sorry I'm finding it a bit hard to read these traces, ultimately Lean seems to reduce it to IsScalarTower ๐•œ ๐•œ Fu. The "goal" of the traces keeps changing and I have to unfold things to find out where we're going

Kevin Buzzard (Jun 03 2023 at 17:36):

And

              [] โŒ apply IsScalarTower.left to IsScalarTower ๐•œ ๐•œ Fu โ–ผ
                [tryResolve] โŒ IsScalarTower ๐•œ ๐•œ Fu โ‰Ÿ IsScalarTower ?m.53455 ?m.53455 ?m.53456

fails because LHS is @IsScalarTower ๐•œ ๐•œ Fu Algebra.toSMul SMulZeroClass.toSMul SMulZeroClass.toSMul : Prop and RHS is @IsScalarTower ?m.53455 ?m.53455 ?m.53456 MulAction.toSMul MulAction.toSMul MulAction.toSMul : Prop. And at this point it goes back and tries to find another way to make NormedSpace ๐•œ Fu other than _inst_2 :-/

Kevin Buzzard (Jun 03 2023 at 18:37):

Eric Wieser said:

I assume it's stuck because MulAction.toSMul on the RHS has more metavariables?

It does have more metavariables: @MulAction.toSMul ?m.55677 ?m.55678 CommMonoid.toMonoid ?m.55680 : SMul ?m.55677 ?m.55678

Kevin Buzzard (Jun 03 2023 at 18:40):

OK so here's some kind of solution:

import Mathlib.Analysis.Calculus.ContDiffDef
import Mathlib.Analysis.Calculus.Deriv.Inverse
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Analysis.NormedSpace.FiniteDimension
import Mathlib.Data.Nat.Choose.Cast

variable {๐•œ : Type v} [NontriviallyNormedField ๐•œ] {Du Eu Fu Gu : Type u}
    [NormedAddCommGroup Du] [NormedSpace ๐•œ Du] [NormedAddCommGroup Eu] [NormedSpace ๐•œ Eu]
    [NormedAddCommGroup Fu] [NormedSpace ๐•œ Fu] [NormedAddCommGroup Gu] [NormedSpace ๐•œ Gu]

instance : RingHomIsometric (RingHom.id ๐•œ) := inferInstance

instance : SMulCommClass ๐•œ ๐•œ Fu := inferInstance

#synth Norm (Eu โ†’L[๐•œ] ((Du โ†’L[๐•œ] Fu) โ†’L[๐•œ] Du โ†’L[๐•œ] Gu)) -- works

If you comment out either instance then #synth fails. Should that happen? I am only adding instances which typeclass inference can already find. That's a bit weird.

Patrick Massot (Jun 03 2023 at 18:44):

It's not super weird since it probably change the order in which instances are tried.

Kevin Buzzard (Jun 03 2023 at 18:45):

Oh OK. We also do this sort of thing occasionally in Lean 3, e.g. here in data.rat.basic (and I didn't really understand why we had to do that either)

Patrick Massot (Jun 03 2023 at 18:46):

It doesn't mean this isn't a problem. I only meant that it's not paranormal.

Kevin Buzzard (Jun 03 2023 at 18:47):

"Lean does not do magic" -- Kenny Lau

Ruben Van de Velde (Jun 03 2023 at 19:07):

I seem to have it building, but please don't judge how :)


Last updated: Dec 20 2023 at 11:08 UTC