Zulip Chat Archive

Stream: Is there code for X?

Topic: Set.matrix


Kevin Buzzard (Jul 09 2025 at 07:48):

We have docs#Set.prod which enables me to take the product of two subsets as a subset of the product. But we don't seem to have

import Mathlib

def Set.matrix {X : Type*} {ι₁ ι₂ : Type*} (S : Set X) :
    Set (Matrix ι₁ ι₂ X) := {m |  i j, m i j  S}

(is that the way to spell it?). Or did I miss it?

My set-up is that I have a topological ring KK (e.g. the p-adic numbers) and a compact open subring RR (e.g. the p-adic integers, of type Subring K) and I want to (idiomatically) say things like "M2(R)M_2(R) is a compact open subring of M2(K)M_2(K)" but right now I'm not sure I can even build the subring from what we have. I am envisaging something like this:

import Mathlib

def Set.matrix {X : Type*} (ι₁ ι₂ : Type*) (S : Set X) :
    Set (Matrix ι₁ ι₂ X) := {m |  i j, m i j  S}

def Setlike.matrix {X : Type*} (ι₁ ι₂ : Type*) {T : Type*} [SetLike T X] (S : T) :
    Set (Matrix ι₁ ι₂ X) := {m |  i j, m i j  S}

def AddSubmonoidClass.matrix {A : Type*} [AddMonoid A] (ι₁ ι₂ : Type*)
    {T : Type*} [SetLike T A] [AddSubmonoidClass T A] (S : T) :
    AddSubmonoid (Matrix ι₁ ι₂ A) where
      carrier := Set.matrix _ _ S
      add_mem' hm hn i j := add_mem (hm i j) (hn i j)
      zero_mem' _ _ := zero_mem _

def AddSubgroupClass.matrix {A : Type*} [AddGroup A] (ι₁ ι₂ : Type*)
    {T : Type*} [SetLike T A] [AddSubgroupClass T A] (S : T) :
    AddSubgroup (Matrix ι₁ ι₂ A) where
      __ := AddSubmonoidClass.matrix _ _ S
      neg_mem' hm i j := neg_mem (hm i j)

def SubringClass.matrix {X : Type*} [Ring X] (ι : Type*) [Fintype ι] [DecidableEq ι]
    {T : Type*} [SetLike T X] [SubringClass T X] (S : T) :
    Subring (Matrix ι ι X) where
      __ := AddSubgroupClass.matrix ι ι S
      mul_mem' ha hb := sorry
      one_mem' := sorry

def Set.matrix_isOpen {X : Type*} [TopologicalSpace X] {ι₁ ι₂ : Type*} [Fintype ι₁]
    [Fintype ι₂] {S : Set X} (hS : IsOpen S) :
    IsOpen (S.matrix ι₁ ι₂) := by
  rw [isOpen_pi_iff']
  intro f hf
  use fun i  {g |  j, g j  S}
  refine fun i  ⟨?_, hf i, fun f hf  by simpa using hf
  rw [isOpen_pi_iff']
  intro g hg
  use fun j  S
  exact fun j  hS, hg j, fun g hg  by simp_all

Does this sound like a sensible way to do things?

Kenny Lau (Jul 09 2025 at 07:53):

the last def is a theorem; don't you have a different topology than the product topology?

Eric Wieser (Jul 09 2025 at 09:42):

I think the use of Classes here is a bad idea, and you should just write these for the direct subobjects

Kevin Buzzard (Jul 09 2025 at 15:12):

Aha, because it's not that difficult in practice to turn a subring into an additive subgroup

Eric Wieser (Jul 09 2025 at 15:26):

Yeah, and if you don't force the user to do it when using the definition, they're going to suffer with the theorems instead

Bryan Wang (Jul 10 2025 at 03:08):

I just found out there is Ideal.matricesOver which is basically the same thing but for ideals of rings instead of subrings of rings; would it make sense then to place the above in something like Mathlib.LinearAlgebra.Matrix.Subring and have Subring.matricesOver?

Kevin Buzzard (Jul 10 2025 at 07:25):

That looks like an odd naming convention to me. Do we have Over anywhere else? On the other hand if it's there already should we stick with it?

Bryan Wang (Jul 10 2025 at 07:54):

Very different meaning of the word 'over', but I can only think of Ideal.primesOver that's similar

Bryan Wang (Jul 10 2025 at 07:57):

But yeah matricesOver is used pretty heavily in Mathlib.LinearAlgebra.Matrix.Ideal, so I'm slightly inclined to stick with it

Kevin Buzzard (Jul 10 2025 at 09:26):

I really want to stress that I think "matricesOver" stinks has a name. It doesn't matter how heavily it's used, we have search/replace. I think Subring.matrix and Ideal.matrix are both immediately guessable, and independent of that I cannot imagine how we let "matrices" in when everything else is "matrix".

Kevin Buzzard (Jul 10 2025 at 09:28):

Oh I tell a lie there is also docs#pairSelfAdjointMatricesSubmodule

I am in two minds about whether to argue for Subring.matrix or Subring.matricesOver. Having said that, if Ideal.matricesOver didn't exist yet then I am 100% sure what I would be arguing for :-)

Eric Wieser (Jul 10 2025 at 09:30):

I agree that .matrix is clearly better than .matricesOver, as it matches docs#Submodule.pi etc

Eric Wieser (Jul 10 2025 at 09:32):

I think what probably happens is that someone notices the bad name in a PR using matricesOver, then gets told "I agree, but renaming it is out of scope" (which is true), and then neither the reviewer or the contributor follow up by trying to snipe someone on Zulip to do the rename.

Kevin Buzzard (Jul 10 2025 at 09:35):

@Bryan Wang why don't you make a PR defining AddSubgroup.matrix, Subring.matrix etc on the basis that it conforms with most of the mathlib naming convention (e.g. docs#AddSubgroup.prod , docs#AddSubgroup.pi etc) and then if you really want to be heroic you could (in another PR!) attempt the refactor of .matricesOver to .matrix, although I suspect that right now this will involve a lot of manual deprecations.

Bryan Wang (Jul 10 2025 at 09:47):

Sure! Yeah .matrix is for sure the better name if .matricesOver didn't exist

Eric Wieser (Jul 27 2025 at 11:10):

Now that we have docs#Set.matrix I guess it's time to deprecate docs#Ideal.matricesOver

Bryan Wang (Jul 27 2025 at 11:16):

yep, I can take care of that sometime this week!

Bryan Wang (Jul 28 2025 at 04:30):

Eric Wieser said:

Now that we have docs#Set.matrix I guess it's time to deprecate docs#Ideal.matricesOver

this is #27575!


Last updated: Dec 20 2025 at 21:32 UTC