Skip to content

Conversation

@dennj
Copy link
Contributor

@dennj dennj commented Feb 4, 2026

This adds three lemmas for matrix-vector operations that serve as foundational support for future ML formalization:

  • vecMul_diagonal_dotProduct: weighted inner product x ᵥ* diagonal d ⬝ᵥ y = ∑ i, d i * x i * y i
  • dotProduct_transpose_mulVec: bilinear form symmetry x ⬝ᵥ Aᵀ *ᵥ y = y ⬝ᵥ A *ᵥ x
  • mul_diagonal_mulVec: column-weighted sum (A * diagonal d) *ᵥ x = ∑ i, (d i * x i) • A.col i

These are basic linear algebra identities involving diagonal matrices and vector operations that appear frequently in machine learning contexts (weighted inner products, attention mechanisms, feature scaling, diagonal preconditioning).

…perations

Add three lemmas for matrix-vector operations:
- `vecMul_diagonal_dotProduct`: weighted inner product identity
- `dotProduct_transpose_mulVec`: bilinear form symmetry
- `mul_diagonal_mulVec`: column-weighted sum expansion
@github-actions github-actions bot added the new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! label Feb 4, 2026
@github-actions
Copy link

github-actions bot commented Feb 4, 2026

PR summary 30e22ac079

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

+ dotProduct_transpose_mulVec
+ mul_diagonal_mulVec
+ vecMul_diagonal_dotProduct

You can run this locally as follows
## summary with just the declaration names:
./scripts/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/declarations_diff.sh long <optional_commit>

The doc-module for script/declarations_diff.sh contains some details about this script.


No changes to technical debt.

You can run this locally as

./scripts/technical-debt-metrics.sh 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).

@github-actions github-actions bot added the t-data Data (lists, quotients, numbers, etc) label Feb 4, 2026
Copy link
Member

@eric-wieser eric-wieser left a comment

Choose a reason for hiding this comment

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

I'm not yet convinced by these lemmas; they're pretty trivial consequences of existing lemmas, and without choosing a preferred side of Matrix.dotProduct_mulVec, it's not clear to me whether we should write the dot product or matrix product on the left.

Comment on lines +749 to +752
/-- The dot product of `x ᵥ* diagonal d` with `y` equals `∑ i, d i * x i * y i`. -/
theorem vecMul_diagonal_dotProduct [Fintype m] [DecidableEq m] [NonUnitalCommSemiring R]
(d x y : m → R) : x ᵥ* diagonal d ⬝ᵥ y = ∑ i, d i * x i * y i := by
simp only [dotProduct, vecMul_diagonal, mul_comm (x _) (d _), mul_assoc]
Copy link
Member

Choose a reason for hiding this comment

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

I would expect

Suggested change
/-- The dot product of `x ᵥ* diagonal d` with `y` equals `∑ i, d i * x i * y i`. -/
theorem vecMul_diagonal_dotProduct [Fintype m] [DecidableEq m] [NonUnitalCommSemiring R]
(d x y : m → R) : x ᵥ* diagonal d ⬝ᵥ y = ∑ i, d i * x i * y i := by
simp only [dotProduct, vecMul_diagonal, mul_comm (x _) (d _), mul_assoc]
theorem vecMul_diagonal_dotProduct [Fintype m] [DecidableEq m] [NonUnitalSemiring R]
(d x y : m → R) : x ᵥ* diagonal d ⬝ᵥ y = ∑ i, x i * d i * y i := by
simp only [dotProduct, vecMul_diagonal, mul_assoc]

which holds more generally; or even

Suggested change
/-- The dot product of `x ᵥ* diagonal d` with `y` equals `∑ i, d i * x i * y i`. -/
theorem vecMul_diagonal_dotProduct [Fintype m] [DecidableEq m] [NonUnitalCommSemiring R]
(d x y : m → R) : x ᵥ* diagonal d ⬝ᵥ y = ∑ i, d i * x i * y i := by
simp only [dotProduct, vecMul_diagonal, mul_comm (x _) (d _), mul_assoc]
theorem vecMul_diagonal_dotProduct [Fintype m] [DecidableEq m]
(d x y : m → α) : x ᵥ* diagonal d ⬝ᵥ y = ∑ i, (x i * d i) * y i := by
simp only [dotProduct, vecMul_diagonal, mul_assoc]

@themathqueen
Copy link
Collaborator

I think these lemmas should just be inlined into whatever you're trying to prove. Like Eric said, they're pretty trivial from previous lemmas. Maybe dotProduct_transpose_mulVec is fine to keep though?

Comment on lines +1085 to +1088
/-- Bilinear form identity: `x ⬝ᵥ Aᵀ *ᵥ y = y ⬝ᵥ A *ᵥ x` for commutative semirings. -/
theorem dotProduct_transpose_mulVec [Fintype m] (A : Matrix m m α) (x y : m → α) :
x ⬝ᵥ Aᵀ *ᵥ y = y ⬝ᵥ A *ᵥ x := by
rw [dotProduct_mulVec, dotProduct_comm, vecMul_transpose]
Copy link
Member

@eric-wieser eric-wieser Feb 6, 2026

Choose a reason for hiding this comment

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

As @themathqueen says, this lemmas is probably the most useful and worth keeping.

Since right now I don't think we declare a preferred spelling, I'd suggest additionally adding the statement that (x ᵥ* Aᵀ) ⬝ᵥ y = (y *ᵥ A) ⬝ᵥ x.

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

Labels

new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! t-data Data (lists, quotients, numbers, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants