Skip to content

feat(Data/Matrix/Mul): add diagonal and transpose lemmas for vector operations#34851

Open
dennj wants to merge 2 commits intoleanprover-community:masterfrom
dennj:MatMul
Open

feat(Data/Matrix/Mul): add diagonal and transpose lemmas for vector operations#34851
dennj wants to merge 2 commits intoleanprover-community:masterfrom
dennj:MatMul

Conversation

@dennj
Copy link
Copy Markdown
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).

@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
Copy Markdown

github-actions bot commented Feb 4, 2026

PR summary 738faa5527

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
+ dotProduct_vecMul_transpose
+ 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 scripts/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
Copy Markdown
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.

@themathqueen
Copy link
Copy Markdown
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?

…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
(v ᵥ* diagonal w) x = v x * w x :=
dotProduct_diagonal' v w x

theorem vecMul_diagonal_dotProduct [Fintype m] [DecidableEq m]
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.

I still think this and mul_diagonal_mulVec shouldn't be lemmas/theorems.

Comment on lines +1105 to +1107
ext j
simp only [mulVec, dotProduct, mul_diagonal, col_apply, Pi.smul_apply, smul_eq_mul,
Finset.sum_apply, mul_comm, mul_left_comm]
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.

I think they're simple enough to just inline into wherever you need it

Suggested change
ext j
simp only [mulVec, dotProduct, mul_diagonal, col_apply, Pi.smul_apply, smul_eq_mul,
Finset.sum_apply, mul_comm, mul_left_comm]
ext; simp [mulVec, dotProduct, mul_rotate (A _ _)]

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.

5 participants