#46289 chore(Matrix): generalize some AlgEquiv stuff now that it's nonunital
PR description
Now that AlgEquiv is nonunital, we can generalize a lot of things!
Conversation on GitHub 8
PR summary bd6ae2c5ed
Import changes for modified files
No significant changes to the import graph
<details><summary>Import changes for all files</summary>
|Files|Import difference| |-|-|
</details>
<details><summary>
Declarations diff (regex)
</summary>
+ coe_toNonUnitalRingHom
+ toAddEquiv_mapMatrix
+ toAddMonoidHom_mapMatrix
+ toNonUnitalAlgHom_mapMatrix
+ toNonUnitalRingHom
+ toRingEquiv_mapMatrix
+ toRingHom_mapMatrix
++ mapMatrix
++ mapMatrix_comp_mapMatrix
++ mapMatrix_id
+++ toNonUnitalRingHom_mapMatrix
<details>
<summary>You can run this locally as follows</summary>
## 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>
</details>
The doc-module for scripts/pr_summary/declarations_diff.sh in the undefined repository contains some details about this script.
</details>
<details><summary>
Declarations diff (Lean)
</summary>
✅ Lean-aware diff — post-build, computed from the Lean environment (commit
bd6ae2c).
- +18 new declarations
- −0 removed declarations
+AlgEquiv.toRingEquiv_mapMatrix
+AlgHom.toNonUnitalAlgHom_mapMatrix
+AlgHom.toRingHom_mapMatrix
+NonUnitalAlgHom.coe_toNonUnitalRingHom
+NonUnitalAlgHom.mapMatrix
+NonUnitalAlgHom.mapMatrix_apply
+NonUnitalAlgHom.mapMatrix_comp_mapMatrix
+NonUnitalAlgHom.mapMatrix_id
+NonUnitalAlgHom.toNonUnitalRingHom
+NonUnitalAlgHom.toNonUnitalRingHom_mapMatrix
+NonUnitalRingHom.mapMatrix
+NonUnitalRingHom.mapMatrix_apply
+NonUnitalRingHom.mapMatrix_comp_mapMatrix
+NonUnitalRingHom.mapMatrix_id
+NonUnitalRingHom.toAddMonoidHom_mapMatrix
+RingEquiv.toAddEquiv_mapMatrix
+RingEquiv.toNonUnitalRingHom_mapMatrix
+RingHom.toNonUnitalRingHom_mapMatrix
</details>
No changes to strong technical debt. No changes to weak technical debt.
Current commit bd6ae2c5ed Reference commit 7ac3ecc3ed
This script lives in the undefined 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
relativevalue is the weighted sum of the differences with weight given by the inverse of the current value of the statistic. - The
absolutevalue is therelativevalue divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).
Oh nice I was just about to do that, thanks! (this code is why I stumbled upon your original PR in the first place :)
I think there's a lot more places to generalize stuff now, feel free to go ahead and open PRs. I'll stop with matrices (so just this PR) if you want :)
Oh no don't let me stop you, I only knew about the matrix equivs
!radar
Benchmark results for cee3cfec10712f4ea628d1ec48bbd5aae7a1fe61 against 66f20c74af93380e30c6f16bad25e5ea77dd19c5 are in. No significant results found. @themathqueen
- ✅
build//instructions: -796.9M (-0.00%)
Small changes (13✅, 13🟥)
- 26 hidden
Looks good. I won't force the NonUnital{Ring,Alg}Hom.mapMatrix (+ generalizing RingEquiv.mapMatrix) to be part of this PR, or for this to depend on a PR implementing it, but I would slightly prefer it if you add those here.
bors d+
:v: themathqueen can now approve this pull request until 2026-12-15 21:39 UTC (in 2 weeks). To approve and merge, reply with bors r+. More detailed instructions are available here.
:warning: This delegation only covers changes within Archive/**, Counterexamples/**, docs/**, DownstreamTest/**, Mathlib/**, MathlibTest/**, Wanted/**, widget/**, Archive.lean, Counterexamples.lean, docs.lean, Mathlib.lean, Wanted.lean; an author commit touching anything else will revoke it. Bors also revokes it if a later push changes too many files for it to check the full list — even if it stays within scope.
Mathlib/Algebra/Algebra/NonUnitalHom.lean +5 −0
Mathlib/Analysis/CStarAlgebra/CStarMatrix.lean +4 −3
instance instRing [Fintype n] [DecidableEq n] [Ring A] : Ring (CStarMatrix n n AThis seems a bit spurious (i.e., not particularly useful to go weaker the NonUnitalNonAssocSemiring A). But given that everything is fine is terms of benchmarking, I guess I don't really care.
instance instAlgebra [Fintype n] [DecidableEq n] [CommSemiring R] [Semiring A] [Mathlib/Data/Matrix/Basic.lean +93 −29
lemma entryLinearMap_comp_mapMatrix (f : α ≃ₛₗ[σᵣₛ] β) (i : m) (j :variable [NonAssocSemiring α] [NonAssocSemiring β] [NonAssocSemiring γ]protected lemma _root_.Matrix.map_pow {α β : Type*} [Semiring α] [Semiring βtheorem mapMatrix_trans (f : α ≃+* β) (g : β ≃+* γ) :theorem MulOpposite.isStablyFiniteRing_iff (α) [MulOne α] [AddCommMonoid α] :RingEquiv.mapMatrix should probably be generalized to nonunital too?
Yes, but for that (to do it properly) we need the aforementioned NonUnitalRingHom.mapMatrix.
I'm starting to lean to just doing it in this PR.
We're also missing NonUnitalAlgHom.mapMatrix.
I didn't change the definition here, because f.toNonUnitalAlgHom would require more hypotheses on R.
theorem mapMatrix_comp (f : β →ₐ[R] γ) (g : α →ₐ[R] β) :theorem mapMatrix_trans (f : α ≃ₐ[R] β) (g : β ≃ₐ[R] γ) :variable [Fintype n]This is available in bundled forms as:Mathlib/Data/Matrix/Composition.lean +4 −3
end LinearMaptheorem compAlgEquiv_symm_apply (M : Matrix (I × J) (I × J) R) :Mathlib/LinearAlgebra/Matrix/ConjTranspose.lean +4 −5
theorem conjTranspose_list_prod [Semiring α] [StarRing α] [Fintype m] [DecidabMathlib/LinearAlgebra/Matrix/Reindex.lean +8 −9
end Semiringtheorem toRingEquiv_reindexAlgEquiv (e : m ≃ n) : reindexAlgEquiv R A e = reintheorem reindexAlgEquiv_refl : reindexAlgEquiv R A (Equiv.refl m) = AlgEquiv.refend Algebratheorem reindexStarAlgEquiv_trans_reindexStarAlgEquiv (e : m ≃ n) (e' : n ≃Mathlib/LinearAlgebra/Matrix/Unique.lean +1 −1
def uniqueRingEquiv [NonUnitalNonAssocSemiring A] : Matrix m m A ≃+* A where