Skip to content

feat(LinearAlgebra): accretive matrices - #46486

Open
Rida-Hamadani wants to merge 1 commit into
leanprover-community:masterfrom
Rida-Hamadani:accretive-matrix-new
Open

Rida-Hamadani wants to merge 1 commit into
leanprover-community:masterfrom
Rida-Hamadani:accretive-matrix-new

Conversation

@Rida-Hamadani

@Rida-Hamadani Rida-Hamadani commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

This is the positive semi-definite condition with the symmetry condition dropped. Strict version is also supplied. Discussion at #mathlib4 > Accretive matrices.


@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

PR summary 42f7d3d58a

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.LinearAlgebra.Matrix.Accretive (new file) 1720

Declarations diff (regex)

+ IsAccretive
+ IsAccretive.diagonal
+ IsStrictlyAccretive
+ _root_.Matrix.isAccretive_iff_submatrix_finset
+ _root_.Matrix.isAccretive_iff_submatrix_of_forall_finset
+ _root_.Matrix.isAccretive_intCast_iff
+ _root_.Matrix.isAccretive_transpose_iff
+ _root_.Matrix.isStrictlyAccretive_diagonal_iff
+ _root_.Matrix.isStrictlyAccretive_iff_submatrix_finset
+ _root_.Matrix.isStrictlyAccretive_iff_submatrix_of_forall_finset
+ _root_.Matrix.isStrictlyAccretive_intCast_iff
+ _root_.Matrix.isStrictlyAccretive_natCast_iff
+ _root_.Matrix.isStrictlyAccretive_sum
+ addSubmonoid
+ add_isAccretive
+ det_pos
+ diag_nonneg
+ diag_pos
+ diagonal
+ dotProduct_mulVec_pos
+ inv
+ isAccretive
+ isAccretive_add
+ isAccretive_diagonal_iff
+ isAccretive_iff_dotProduct_mulVec
+ isAccretive_submatrix_equiv
+ isAccretive_sum
+ isStrictlyAccretive_iff_dotProduct_mulVec
+ mem_addSubmonoid
+ mulVec_injective
+ of_subsingleton
+ trace_nonneg
+ trace_pos
+ transpose_iff
+ zero
++ add
++ intCast
++ natCast
++ ofNat
++ one
++ smul
++ submatrix
++ transpose

You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.

Declarations diff (Lean)

✅ Lean-aware diff — post-build, computed from the Lean environment (commit 42f7d3d).

  • +52 new declarations
  • −0 removed declarations
+Matrix.IsAccretive
+Matrix.IsAccretive.add
+Matrix.IsAccretive.addSubmonoid
+Matrix.IsAccretive.coe_addSubmonoid
+Matrix.IsAccretive.diag_nonneg
+Matrix.IsAccretive.diagonal
+Matrix.IsAccretive.intCast
+Matrix.IsAccretive.inv
+Matrix.IsAccretive.mem_addSubmonoid
+Matrix.IsAccretive.natCast
+Matrix.IsAccretive.ofNat
+Matrix.IsAccretive.one
+Matrix.IsAccretive.smul
+Matrix.IsAccretive.submatrix
+Matrix.IsAccretive.trace_nonneg
+Matrix.IsAccretive.transpose
+Matrix.IsAccretive.zero
+Matrix.IsStrictlyAccretive
+Matrix.IsStrictlyAccretive.add
+Matrix.IsStrictlyAccretive.add_isAccretive
+Matrix.IsStrictlyAccretive.det_pos
+Matrix.IsStrictlyAccretive.diag_pos
+Matrix.IsStrictlyAccretive.diagonal
+Matrix.IsStrictlyAccretive.dotProduct_mulVec_pos
+Matrix.IsStrictlyAccretive.intCast
+Matrix.IsStrictlyAccretive.isAccretive
+Matrix.IsStrictlyAccretive.isAccretive_add
+Matrix.IsStrictlyAccretive.mulVec_injective
+Matrix.IsStrictlyAccretive.natCast
+Matrix.IsStrictlyAccretive.ofNat
+Matrix.IsStrictlyAccretive.of_subsingleton
+Matrix.IsStrictlyAccretive.one
+Matrix.IsStrictlyAccretive.smul
+Matrix.IsStrictlyAccretive.submatrix
+Matrix.IsStrictlyAccretive.trace_pos
+Matrix.IsStrictlyAccretive.transpose
+Matrix.IsStrictlyAccretive.transpose_iff
+Matrix.isAccretive_diagonal_iff
+Matrix.isAccretive_iff_dotProduct_mulVec
+Matrix.isAccretive_iff_submatrix_finset
+Matrix.isAccretive_iff_submatrix_of_forall_finset
+Matrix.isAccretive_intCast_iff
+Matrix.isAccretive_submatrix_equiv
+Matrix.isAccretive_sum
+Matrix.isAccretive_transpose_iff
+Matrix.isStrictlyAccretive_diagonal_iff
+Matrix.isStrictlyAccretive_iff_dotProduct_mulVec
+Matrix.isStrictlyAccretive_iff_submatrix_finset
+Matrix.isStrictlyAccretive_iff_submatrix_of_forall_finset
+Matrix.isStrictlyAccretive_intCast_iff
+Matrix.isStrictlyAccretive_natCast_iff
+Matrix.isStrictlyAccretive_sum

No changes to strong technical debt.

Increase in weak tech debt: (relative, absolute) = (1.00, 0.00)
Current number Change Type (weak)
5153 1 exposed public sections

Current commit 42f7d3d58a
Reference commit 4694f18024

This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/technical-debt-metrics.py pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).


A matrix `M` is accretive if `xᴴMx` is non-negative for all `x`, and strictly accretive if `xᴴMx`
is positive for all non-zero `x`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe mention here that we can use this when positive (semi-)definiteness is too strong and when we don't need the matrix to be Hermitian?

Comment on lines +52 to +57
theorem submatrix {M : Matrix n n R} (hM : M.IsAccretive) (e : m → n) :
(M.submatrix e e).IsAccretive := by
intro x
simpa [Finsupp.sum_mapDomain_index, add_mul, mul_add] using hM <| x.mapDomain e

theorem transpose {M : Matrix n n R'} (hM : M.IsAccretive) : Mᵀ.IsAccretive := by

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should be protected


/-- A finite matrix `M : Matrix n n R` is accretive iff it is `xᴴ * M * x` is non-negative for
all `x`. -/
@[simp] theorem isAccretive_iff_dotProduct_mulVec {M : Matrix n n R} :

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be simp?

simpa [Finsupp.sum_mapDomain_index, add_mul, mul_add] using hM <| x.mapDomain e

theorem transpose {M : Matrix n n R'} (hM : M.IsAccretive) : Mᵀ.IsAccretive := by
have (a b c : R') : a * b * c = c * b * a := by ring

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does by exact? return anything, by pure chance? Sometimes these theorems happen to have names.

IsAccretive (ofNat(d) : Matrix n n R) :=
.natCast d

protected theorem intCast [StarOrderedRing R] [DecidableEq n] (d : ℤ) (hd : 0 ≤ d) :

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this not follow immediately from d = diagonal d?

Comment on lines +79 to +90
protected lemma one [StarOrderedRing R] [DecidableEq n] : IsAccretive (1 : Matrix n n R) :=
fun _ ↦ Finsupp.sum_nonneg fun i _ ↦ Finsupp.sum_nonneg fun j _ ↦ by
obtain rfl | hij := eq_or_ne i j <;> simp [*]

protected theorem natCast [StarOrderedRing R] [DecidableEq n] (d : ℕ) :
IsAccretive (d : Matrix n n R) :=
fun _ ↦ Finsupp.sum_nonneg fun i _ ↦ Finsupp.sum_nonneg fun j _ ↦ by
obtain rfl | hij := eq_or_ne i j <;> simp [← diagonal_natCast', star_left_conjugate_nonneg, *]

protected theorem ofNat [StarOrderedRing R] [DecidableEq n] (d : ℕ) [d.AtLeastTwo] :
IsAccretive (ofNat(d) : Matrix n n R) :=
.natCast d

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are all corollaries of the intCast theorem, right?

end IsAccretive

@[simp]
theorem isAccretive_submatrix_equiv {M : Matrix n n R} (e : m ≃ n) :

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move this right after IsAccretive.submatrix?

(M.submatrix e e).IsAccretive ↔ M.IsAccretive :=
⟨fun h ↦ by simpa using h.submatrix e.symm, fun h ↦ h.submatrix _⟩

theorem isAccretive_sum {ι : Type*} [AddLeftMono R]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can prove this almost immediately with AddSubmonoid.sum_mem.

IsStrictlyAccretive (diagonal d) ↔ ∀ i, 0 < d i :=
⟨fun h i ↦ by simpa using h (x := .single i 1), .diagonal⟩

@[simp, nontriviality]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't imagine this is very performant as a simp lemma, because it will fire often and fail often.

Comment on lines +243 to +247
rw [Finset.sum_insert hins]
by_cases h : ¬ hi.Nonempty
· simp_all
· exact IsStrictlyAccretive.add (hA _ <| Finset.mem_insert_self i hi) <|
H (not_not.mp h) fun _ _hi => hA _ (Finset.mem_insert_of_mem _hi)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rw [Finset.sum_insert hins]
by_cases h : ¬ hi.Nonempty
· simp_all
· exact IsStrictlyAccretive.add (hA _ <| Finset.mem_insert_self i hi) <|
H (not_not.mp h) fun _ _hi => hA _ (Finset.mem_insert_of_mem _hi)
rw [Finset.sum_insert hins]
by_cases h : ¬ hi.Nonempty
· simp_all
· exact IsStrictlyAccretive.add (hA _ <| Finset.mem_insert_self i hi) <|
H (not_not.mp h) fun _ _hi => hA _ (Finset.mem_insert_of_mem _hi)

namespace IsAccretive

omit [Fintype n] in
/-- A matrix `M : Matrix n n R` is accretive iff every finite principal submatrix is accretive. -/

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"principal" seems extraneous.

omit [Fintype n] in
/-- A matrix `M : Matrix n n R` is accretive iff every finite principal submatrix is accretive. -/
theorem _root_.Matrix.isAccretive_iff_submatrix_finset {M : Matrix n n R} :
M.IsAccretive ↔ ∀ s : Finset n, (M.submatrix (↑) (↑) : Matrix s s R).IsAccretive := by

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a very useful theorem in practice? The implication follows from IsAccretive.submatrix, and doesn't the converse follow from just plugging in s = univ?

Is this theorem true without the Fintype assumption?

0 < star x ⬝ᵥ (M *ᵥ x) := isStrictlyAccretive_iff_dotProduct_mulVec.mp hM hx

omit [Fintype n] in
/-- A matrix `M : Matrix n n R` is strictly accretive iff every finite principal submatrix is

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, "principal" seems extraneous.

@Rida-Hamadani Rida-Hamadani added awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. awaiting-zulip There is a Zulip discussion; the author should await and report/implement the decision reached there and removed awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. labels Nov 25, 2026
@ocfnash

ocfnash commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Having just read the Zulip thread, it seems that this PR is blocked because the current definition:

def IsAccretive (M : Matrix n n R) : Prop :=
  ∀ x : n →₀ R, 0 ≤ x.sum fun i xi ↦ x.sum fun j xj ↦ star xi * M i j * xj

does not correspond to the definition of an accretive matrix in the informal literature in the case that R = ℂ, and there is no trivial way to make it do this without specialising to just ℝ and ℂ via RCLike which is particularly undesirable given that part of the motivation here is to support R = ℤ.

If I've got that right, then I suppose one way to unblock things without a refactor would be to demand the "real part" function as a parameter in the base definition. E.g., something like:

def IsAccretiveFor {R S : Type*} [CommRing S] [Ring R] [Algebra S R] [StarRing R] [PartialOrder S]
    (re : R → S) (M : Matrix n n R) : Prop :=
  ∀ x : n →₀ R, 0 ≤ re (x.sum fun i xi ↦ x.sum fun j xj ↦ star xi * M i j * xj)

Probably this is not worth it but I just thought I'd mention this.

@themathqueen

Copy link
Copy Markdown
Member

Or ∀ x : ι →₀ R, 0 ≤ (x.sum fun i xi ↦ x.sum fun j xj ↦ star xi * M i j * xj + star (star xi * M i j * xj))

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-zulip There is a Zulip discussion; the author should await and report/implement the decision reached there t-algebra Algebra (groups, rings, fields, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants