Zulip Chat Archive

Stream: new members

Topic: Rayleigh quotient of a matrix


Adrian Wüthrich (Feb 27 2024 at 13:34):

I would like to use the Rayleigh quotient of a matrix in a theorem, I tried

variable (M : Matrix E' E' ) [Fintype E'] [DecidableEq E']

#check ContinuousLinearMap.rayleighQuotient (LinearMap.toContinuousLinearMap (Matrix.toLin' M))

This raises the following error

application type mismatch
  ContinuousLinearMap.rayleighQuotient (LinearMap.toContinuousLinearMap (toLin' M))
argument
  LinearMap.toContinuousLinearMap (toLin' M)
has type
  @ContinuousLinearMap   DivisionSemiring.toSemiring DivisionSemiring.toSemiring (RingHom.id ) (E'  )
    Pi.topologicalSpace (@AddCommGroup.toAddCommMonoid (E'  ) Pi.addCommGroup) (E'  ) Pi.topologicalSpace
    (@AddCommGroup.toAddCommMonoid (E'  ) Pi.addCommGroup) (Pi.module E' (fun a  ) )
    (Pi.module E' (fun a  ) ) : Type u_5
but is expected to have type
  @ContinuousLinearMap   DivisionSemiring.toSemiring DivisionSemiring.toSemiring (RingHom.id ) (E'  )
    UniformSpace.toTopologicalSpace (@AddCommGroup.toAddCommMonoid (E'  ) NormedAddCommGroup.toAddCommGroup) (E'  )
    UniformSpace.toTopologicalSpace (@AddCommGroup.toAddCommMonoid (E'  ) NormedAddCommGroup.toAddCommGroup)
    NormedSpace.toModule NormedSpace.toModule : Type u_5

To find the issue I tried

variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace  E] (T : E L[] E)
variable {E' : Type*} [NormedAddCommGroup (E'  )] [InnerProductSpace  (E'  )] (T' : (E'  ) L[] E'  )

#check ContinuousLinearMap.rayleighQuotient T --This works
#check ContinuousLinearMap.rayleighQuotient T' --This does not

which raises a similar error. How can this be when both E and E' → ℝ fulfill the same assumptions?

Thanks in advance for any help.

Eric Wieser (Feb 27 2024 at 13:51):

You want

#check ContinuousLinearMap.rayleighQuotient (Matrix.toEuclideanCLM (𝕜 := ) M)

Eric Wieser (Feb 27 2024 at 13:51):

Your second code block is interesting but a distraction from the problem in your first one

Eric Wieser (Feb 27 2024 at 13:52):

Your first problem is caused by E' → ℝ not being an inner product space, because it has the wrong norm

Eric Wieser (Feb 27 2024 at 13:52):

Using docs#Matrix.toEuclideanCLM gives you the L2 norm, which is an inner product space

Adrian Wüthrich (Feb 27 2024 at 14:18):

Thanks a lot, it's working now. Just out of curiosity what could be the issue in the second block?

Eric Wieser (Feb 27 2024 at 15:05):

The issue in the second block is that NormedAddCommGroup (E' → ℝ) means "assume some random normed structure on the type of vectors", but Mathlib already has an existing norm structure (the sup-norm) that is not apriori equal to this one

Adrian Wüthrich (Feb 27 2024 at 18:05):

Thank you for clarifying

Adrian Wüthrich (Mar 01 2024 at 12:37):

I have a question which I think relates to the same issue. I want to get the orthogonal complement of a vector E → ℝ, this is what I tried:

variable {E : Type*} [Fintype E] [InnerProductSpace  (E  )] [Fintype (E  )]

#check (  (fun _  1 : E  ))

which raises the error

synthesized type class instance is not definitionally equal to expression inferred by typing rules, synthesized
  Pi.module E (fun x  ) 
inferred
  NormedSpace.toModule

What I understan is that Submodule.orthogonal implicitly infers InnerProductSpace. In this case it tries to build the inner product space using the sup norm which of course doesn't work. Now when i define the variable [InnerProductSpace ℝ (E → ℝ)] , its norm might not agree with the NormedAddCommGroup implicitly infered. I would like lean to use the L2 norm and InnerProductSpace ℝ (EuclideanSpace ℝ (E → ℝ)) instead. How do I tell lean to do so?

Eric Wieser (Mar 01 2024 at 12:40):

You want

#check (  ((WithLp.equiv 2 _).symm <| fun _  1 : E  ))

You have fun _ ↦ 1 : E → ℝ, but you want a term of type EuclideanSpace ℝ E, which WithLp.equiv 2 _ converts to

Eric Wieser (Mar 01 2024 at 12:41):

You should never write [InnerProductSpace ℝ (E → ℝ)], because this conflicts with the norm that mathlib already equips functions with

Eric Wieser (Mar 01 2024 at 12:43):

Note that [Fintype (E → ℝ)] is false unless IsEmpty E

Adrian Wüthrich (Mar 01 2024 at 12:47):

Wow, thank you for the instant response. [Fintype (E → ℝ)] is silly , I put that there without thinking trying to fix things.

Eric Wieser (Mar 01 2024 at 12:51):

Generally speaking, if lean says it can't find an instance for something involving a concrete type (like ), adding [...] is the wrong fix

Eric Wieser (Mar 01 2024 at 12:52):

A better strategy in that case is to try adding

instance : InnerProductSpace  (E  ) := sorry

and see if you can fill the sorry

Eric Wieser (Mar 01 2024 at 12:52):

(in this case you'd find it impossible, because the inner product induces the wrong norm)

Adrian Wüthrich (Mar 01 2024 at 12:57):

Got it, i'll try that in the future.


Last updated: May 02 2025 at 03:31 UTC