Zulip Chat Archive

Stream: lean4

Topic: Piling structures


Sophie Morel (Jul 29 2023 at 15:21):

When introducing a structure of type S that extends another structure of type S', if I already have a structure of type S', how do I tell Lean that I want to use it for the structure of type S ? Here is a toy example:

import Mathlib

universe U

structure test1 :=
(arbitrary : βˆ€ (π•œ : Type U) [NontriviallyNormedField π•œ], π•œ)
(arbitrary_nonzero : βˆ€ (π•œ : Type U) [NontriviallyNormedField π•œ], arbitrary π•œ β‰  0)

variable (t : test1)

lemma test2 (π•œ : Type U) [Field π•œ] (p : NontriviallyNormedField π•œ) (q : NontriviallyNormedField π•œ) :
(@test1.arbitrary t π•œ p) * (@test1.arbitrary t π•œ q) β‰  0 := by
  simp only [ne_eq, mul_eq_zero]
  push_neg
  constructor
  . exact @test1.arbitrary_nonzero t π•œ p    -- type mismatch
  . sorry

Full error message:

type mismatch
  test1.arbitrary_nonzero t π•œ
has type
  test1.arbitrary t π•œ β‰ 
    @OfNat.ofNat π•œ 0
      (@Zero.toOfNat0 π•œ
        (@ExteriorAlgebra.instZero π•œ
          (@NonUnitalNonAssocSemiring.toMulZeroClass π•œ
            (@NonUnitalNonAssocRing.toNonUnitalNonAssocSemiring π•œ
              (@NonAssocRing.toNonUnitalNonAssocRing π•œ
                (@Ring.toNonAssocRing π•œ
                  (@NormedRing.toRing π•œ
                    (@NormedCommRing.toNormedRing π•œ
                      (@NormedField.toNormedCommRing π•œ (@NontriviallyNormedField.toNormedField π•œ p)))))))))) : Prop
but is expected to have type
  test1.arbitrary t π•œ β‰ 
    @OfNat.ofNat π•œ 0
      (@Zero.toOfNat0 π•œ
        (@MulZeroClass.toZero π•œ
          (@NonUnitalNonAssocSemiring.toMulZeroClass π•œ
            (@NonUnitalNonAssocRing.toNonUnitalNonAssocSemiring π•œ
              (@NonAssocRing.toNonUnitalNonAssocRing π•œ
                (@Ring.toNonAssocRing π•œ
                  (@NormedRing.toRing π•œ
                    (@NormedCommRing.toNormedRing π•œ
                      (@NormedField.toNormedCommRing π•œ (@NontriviallyNormedField.toNormedField π•œ q)))))))))) : Prop

Here the variable t of type test1 is supposed to pick a nonzero element in every nontrivially normed field. (Auxiliary question: is putting instance arguments in the fields of a structure a Bad Idea ?)

Then I am playing around with a type π•œ that has two structures of nontrivially normed field called p and q, and I want to prove that the product of the nonzero elements is nonzero. Of course this should not work, because I have not told Lean that the two underlying field structures are the same, and my problem is that I don't know how to do that; I mean, I can probably tell Lean that p.toField = q.toField or something like that, but it seems like it would force me to do a huge amount of rewrites later; much better if p and q were just known to extend the same Field structure on π•œ.
You can see how I tried by putting a Field instance on π•œ first, but it didn't work and Lean is using the field structure coming from q to in the simp step, if I am following well, and doesn't know that it has the same 0 as the other field structure. (Why there is an ExteriorAlgebra in the middle of all this, I am not sure.)

Notification Bot (Jul 29 2023 at 15:21):

Sophie Morel has marked this topic as resolved.

Notification Bot (Jul 29 2023 at 15:21):

Sophie Morel has marked this topic as unresolved.

James Gallicchio (Jul 29 2023 at 15:58):

I think having a hypothesis that they are equal might be the only reasonable approach here? but i'm not sure how that would interact with typeclass inference -- if you name the two instances and deconstruct them (to eliminate the field equality hypothesis) I don't know whether typeclass inference still knows that there's a NontriviallyNormedField there

James Gallicchio (Jul 29 2023 at 16:00):

is there a non-toy example where this is coming up? seems vaguely like abuse of typeclasses, but I don't know enough to say this is a bad idea >_<

Patrick Massot (Jul 29 2023 at 16:59):

Sophie, your issue is that in the statement it isn't clear what zero means since you have two completely unrelated field structures on k\mathbb k.

Patrick Massot (Jul 29 2023 at 16:59):

Probably Lean picks one and then half of your goals become unprovable.

Patrick Massot (Jul 29 2023 at 17:00):

And see docs#mul_ne_zero

James Gallicchio (Jul 29 2023 at 17:01):

but the question is whether there is a clean way to say "i have two different NontriviallyNormedFields that are extensions of the same Field structure" (which might be an XY problem)

Patrick Massot (Jul 29 2023 at 17:03):

Oh, I actually didn't read Sophie's message at all. I saw she had a question, I copy-pasted the code and tried to guess the question...

Patrick Massot (Jul 29 2023 at 17:10):

I don't think there is any nice way to do that with those type class. You should probably try to use docs#IsAbsoluteValue.

Yury G. Kudryashov (Jul 30 2023 at 04:23):

I would consider two NontriviallyNormedFields with a RingEquiv between them. Answering wrong question too.

Yury G. Kudryashov (Jul 30 2023 at 04:25):

There is no way to say that you have 2 structures and their projections to a substructure agree. More precisely, you can create a new typeclass that extends both, then ask for it.

Yury G. Kudryashov (Jul 30 2023 at 04:25):

What do you actually want to do?

YaΓ«l Dillies (Jul 30 2023 at 14:34):

This is a problem @MarΓ­a InΓ©s de Frutos FernΓ‘ndez and I encountered. docs3#normed_ring is not quite the type of normed structures on a
ring since it includes the ring part, so instead we defined docs3#ring_norm

Sophie Morel (Jul 30 2023 at 18:49):

Thanks for all your answers. In the non-toy example, I want to talk about several semi-norms (and the associated topologies, which might be different) on a fixed vector space. I tried using the NormedSpace structure and ran into the problem that the vector space structures had no reason to be equal.

Sophie Morel (Jul 30 2023 at 18:51):

I might have to do something similar to what @YaΓ«l Dillies mentioned, since I don't just want to have the semi-norms, I also need the induced topologies (probably uniform structures, actually) and all the stuff that comes with it. Yay...

Sophie Morel (Jul 30 2023 at 18:54):

(Another solution would be to have two NormedSpace structures with an isomorphism of vector fields between them. It might be easier in this case, I need to think about it.)

Yury G. Kudryashov (Jul 30 2023 at 20:57):

We have docs#Seminorm

Sophie Morel (Jul 31 2023 at 19:38):

Thanks! So this is another possibility. Does there also exist a way to make a space with a Seminorm into a NormedSpace ? (I am trying to use constructions that I can only find for NormedSpace.) If not, I guess I could write it myself, in case my other approach does not work well.

Yury G. Kudryashov (Jul 31 2023 at 23:41):

We have docs#AddGroupSeminorm.toSeminormedAddGroup
Not sure about a NormedSpace version.

Sophie Morel (Aug 01 2023 at 10:04):

Thanks! This is most of the way to NormedSpace already.

Sophie Morel (Aug 06 2023 at 16:23):

Well, I ended up writing a Seminorm.toNormedSpace definition, and I have to mix it with NormedSpace instances to make stuff work. Thanks again to everybody who helped!

Also, I needed a corollary of Hahn-Banach that was lightly more general than https://leanprover-community.github.io/mathlib4_docs/Mathlib/Analysis/NormedSpace/HahnBanach/Extension.html#exists_dual_vector, because my space only had a semi-norm, so I had a SeminormedAddCommGroup instance and that result requires a NormedAddCommGroup instance. More precisely, the result was this:

exists_dual_vector''_sn.{U} (π•œ : Type U) [inst✝ : IsROrC π•œ] {E : Type U} [inst✝¹ : SeminormedAddCommGroup E]
  [inst✝² : NormedSpace π•œ E] (x : E) : βˆƒ g, β€–gβ€– ≀ 1 ∧ ↑g x = ↑‖xβ€–

which I deduced from this:

exists_dual_vector_sn.{U} (π•œ : Type U) [inst✝ : IsROrC π•œ] {E : Type U} [inst✝¹ : SeminormedAddCommGroup E]
  [inst✝² : NormedSpace π•œ E] (x : E) (h : β€–xβ€– β‰  0) : βˆƒ g, β€–gβ€– = 1 ∧ ↑g x = ↑‖xβ€–

I proved it by very slightly generalizing a bunch of results like ContinuousLinearEquiv.coord from NormedAddCommGroups to SeminormedAddCommGroups by replacing conditions like x β‰  0 with β€–xβ€– β‰  0, which was not hard but a bit longuish. A more natural approach for a mathematician would be to go through the quotient of the space by the kernel of the semi-norm, but I don't know if that's in mathlib. So my question:

(1) Is the construction of a normed space (or module/group/etc) from a seminormed one by taking the quotient by the kernel of the seminorm in mathlib ?

(2) Would it be worth having the slightly more general Hahn-Banach corollary in mathlib ?

Kevin Buzzard (Aug 06 2023 at 16:31):

For (2) -- if you needed it, that's evidence that it should be in the library, and mathlib4 is now open for business!

Sophie Morel (Aug 06 2023 at 16:45):

@Kevin Buzzard But then I also need to answer (1), so I can decide what the "best" proof is. (I found Mathlib.Analysis.Normed.Group.Quotient so seminorms on quotients exist, but I did not find the norm on the separation yet.)


Last updated: Dec 20 2023 at 11:08 UTC