Zulip Chat Archive

Stream: new members

Topic: Defining a [NormedAlgebra ℂ A] for a Matrix


Bashar Hamade (Jun 29 2025 at 11:50):

Hello , I need to define a NormedAlgebra for my StateMatrix as defined in this code :

variable {R : Type*} [NormedField R]
variable {A : Type*}
variable {n : }



def spectral_radius_less_than_one3 [NormedRing A] [NormedAlgebra  A] (a : A) : Prop :=
  spectralRadius  a < 1

abbrev StateVector (n : ) := Fin n  
abbrev InputVector (p : ) := Fin p  


abbrev StateMatrix (n : ) := CStarMatrix (Fin n) (Fin n) 
abbrev InputMatrix (n p : ) := Matrix (Fin n) (Fin p) 


noncomputable instance (n : ) : Ring (StateMatrix n) := Matrix.instRing


noncomputable instance (n : ) : SeminormedAddCommGroup (StateMatrix n) := Matrix.seminormedAddCommGroup


noncomputable instance (n : ) : NormedRing (StateMatrix n) := Matrix.frobeniusNormedRing

noncomputable instance (n : ) : NormedAlgebra  (StateMatrix n) := sorry

/--
noncomputable instance (n : ℕ) : NormedAlgebra ℂ (StateMatrix n) := CStarMatrix.instNormedAlgebra

Gives the following error:
type mismatch
  CStarMatrix.instNormedAlgebra
has type
  @NormedAlgebra ℂ (CStarMatrix ?m.3869 ?m.3869 ?m.3865) Complex.instNormedField
    (@NormedRing.toSeminormedRing (CStarMatrix ?m.3869 ?m.3869 ?m.3865)
      CStarMatrix.instNormedRing) : Type (max ?u.3864 ?u.3863)
but is expected to have type
  @NormedAlgebra ℂ (StateMatrix n) Complex.instNormedField
    (@NormedRing.toSeminormedRing (StateMatrix n) (instNormedRingStateMatrix n)) : Type
-/


structure DiscreteLinearSystemState (n p : ) where
  a : StateMatrix n             -- State transition matrix (n×n)
  B : InputMatrix n p           -- Input matrix (n×p)
  x₀ : StateVector n            -- Initial state
  x :   StateVector n         -- State sequence
  u :   InputVector p         -- Input sequence

-- System evolution function
def system_evolution {n p : } (sys : DiscreteLinearSystemState n p) :   StateVector n
  | 0 => sys.x₀
  | k + 1 => sys.a.mulVec (system_evolution sys k) + sys.B.mulVec (sys.u k)

-- State system equation
def state_system_equation {n p : } (sys : DiscreteLinearSystemState n p) : Prop :=
   k : , sys.x (k + 1) = sys.a.mulVec (sys.x k) + sys.B.mulVec (sys.u k)

-- Now you can use properties that require NormedRing/NormedAlgebra
def system_is_stable {n p : } (sys : DiscreteLinearSystemState n p) : Prop :=
  spectral_radius_less_than_one3 sys.a

I need to basically make sure everything compiles well and is compatible with the gelfand formula definition,such that the following also compiles :

theorem gelfand_le_one_when_spectral_radius_le_one
    [NormedRing A] [NormedAlgebra  A] [CompleteSpace A] (a : A) :
    spectral_radius_less_than_one3 a 
    Filter.limsup (fun (n : ) => (a ^ n‖₊ : ENNReal) ^ (1 / n : )) Filter.atTop < 1 := by
  intro h_spectral
  unfold spectral_radius_less_than_one3 at h_spectral

  have h_gelfand := spectrum.limsup_pow_nnnorm_pow_one_div_le_spectralRadius a

  convert lt_of_le_of_lt h_gelfand h_spectral

I am trying to use CStarMatrix to get such a NormedAlgebra, but it did not work out completely

Kevin Buzzard (Jun 29 2025 at 12:49):

Can you edit your post to make this a #mwe ? I clicked on the "View in Lean 4 playground" link on your code and I got a screenful of errors.

Bashar Hamade (Jun 29 2025 at 12:59):

Kevin Buzzard said:

Can you edit your post to make this a #mwe ? I clicked on the "View in Lean 4 playground" link on your code and I got a screenful of errors.

here is the full working code :

import Mathlib



variable {R : Type*} [NormedField R]
variable {A : Type*}
variable {n : }



def spectral_radius_less_than_one3 [NormedRing A] [NormedAlgebra  A] (a : A) : Prop :=
  spectralRadius  a < 1




theorem gelfand_le_one_when_spectral_radius_le_one
    [NormedRing A] [NormedAlgebra  A] [CompleteSpace A] (a : A) :
    spectral_radius_less_than_one3 a 
    Filter.limsup (fun (n : ) => (a ^ n‖₊ : ENNReal) ^ (1 / n : )) Filter.atTop < 1 := by
  intro h_spectral
  unfold spectral_radius_less_than_one3 at h_spectral

  have h_gelfand := spectrum.limsup_pow_nnnorm_pow_one_div_le_spectralRadius a

  convert lt_of_le_of_lt h_gelfand h_spectral





abbrev StateVector (n : ) := Fin n  
abbrev InputVector (p : ) := Fin p  


abbrev StateMatrix (n : ) := CStarMatrix (Fin n) (Fin n) 
abbrev InputMatrix (n p : ) := Matrix (Fin n) (Fin p) 


noncomputable instance (n : ) : Ring (StateMatrix n) := Matrix.instRing


noncomputable instance (n : ) : SeminormedAddCommGroup (StateMatrix n) := Matrix.seminormedAddCommGroup


noncomputable instance (n : ) : NormedRing (StateMatrix n) := Matrix.frobeniusNormedRing

noncomputable instance (n : ) : NormedAlgebra  (StateMatrix n) := sorry

/--
noncomputable instance (n : ℕ) : NormedAlgebra ℂ (StateMatrix n) := CStarMatrix.instNormedAlgebra

Gives the following error:
type mismatch
  CStarMatrix.instNormedAlgebra
has type
  @NormedAlgebra ℂ (CStarMatrix ?m.3869 ?m.3869 ?m.3865) Complex.instNormedField
    (@NormedRing.toSeminormedRing (CStarMatrix ?m.3869 ?m.3869 ?m.3865)
      CStarMatrix.instNormedRing) : Type (max ?u.3864 ?u.3863)
but is expected to have type
  @NormedAlgebra ℂ (StateMatrix n) Complex.instNormedField
    (@NormedRing.toSeminormedRing (StateMatrix n) (instNormedRingStateMatrix n)) : Type
-/


structure DiscreteLinearSystemState (n p : ) where
  a : StateMatrix n             -- State transition matrix (n×n)
  B : InputMatrix n p           -- Input matrix (n×p)
  x₀ : StateVector n            -- Initial state
  x :   StateVector n         -- State sequence
  u :   InputVector p         -- Input sequence

-- System evolution function
def system_evolution {n p : } (sys : DiscreteLinearSystemState n p) :   StateVector n
  | 0 => sys.x₀
  | k + 1 => sys.a.mulVec (system_evolution sys k) + sys.B.mulVec (sys.u k)

-- State system equation
def state_system_equation {n p : } (sys : DiscreteLinearSystemState n p) : Prop :=
   k : , sys.x (k + 1) = sys.a.mulVec (sys.x k) + sys.B.mulVec (sys.u k)

-- Now you can use properties that require NormedRing/NormedAlgebra
def system_is_stable {n p : } (sys : DiscreteLinearSystemState n p) : Prop :=
  spectral_radius_less_than_one3 sys.a

Kenny Lau (Jun 29 2025 at 13:09):

@Bashar Hamade I specified the implicit arguments:

noncomputable instance (n : ) : NormedAlgebra  (StateMatrix n) := CStarMatrix.instNormedAlgebra (n := Fin n) (A := )

and then got the error:

failed to synthesize
  PartialOrder 

so that's the reason

Kenny Lau (Jun 29 2025 at 13:11):

and I'm not familiar with this part of the library to tell you further reason, hopefully others will know

Eric Wieser (Jun 29 2025 at 13:39):

open scoped ComplexOrder

Eric Wieser (Jun 29 2025 at 13:39):

But you can't mix and match the frobenius and star and elementwise norm like that

Eric Wieser (Jun 29 2025 at 13:39):

Which norm do you actually want?


Last updated: Dec 20 2025 at 21:32 UTC