mathlib4 icon indicating copy to clipboard operation
mathlib4 copied to clipboard

refactor(LinearAlgebra/Matrix/SesquilinearForm): Sesquilinear Maps and Matrices

Open mans0954 opened this issue 1 year ago • 9 comments

Some of the concepts in LinearAlgebra/Matrix/SesquilinearForm can be generalised from Sesquilinear Forms to Sesquilinear Maps with little or no impact on the rest of Mathlib. This PR makes those generalisations.

A number of results in the ToMatrix section relating composition of maps to matrix multiplication could also be generalised, but they require a more genralised notion of matrix multiplication than we currently have available, so they are not included in the scope of this PR. Similarly for most of the results in the Det section.


See also: #9312

Hopefully this will replace #8256, in part at least.

  • [x] depends on: #9475
  • [ ] depends on: #13041
  • [ ] depends on: #13042

Open in Gitpod

mans0954 avatar Dec 29 '23 16:12 mans0954

!bench

mans0954 avatar Jan 06 '24 10:01 mans0954

Here are the benchmark results for commit 1ad926c6a423c7138f5d6b7abec7b4b70ffb2d64. There were significant changes against commit 357e37bbf050a1bf9d5db36bb4ee850e12e3e855:

  Benchmark                                        Metric         Change
  ======================================================================
- ~Mathlib.LinearAlgebra.Matrix.SesquilinearForm   instructions     6.1%

leanprover-bot avatar Jan 06 '24 11:01 leanprover-bot

!bench

mans0954 avatar Jan 16 '24 18:01 mans0954

Here are the benchmark results for commit 478890085040db180ecc9c35e252403f93333df7. There were significant changes against commit b4cd3132fe069277f225fde5e0a5ecba95b9a57f:

  Benchmark                                        Metric         Change
  ======================================================================
- ~Mathlib.LinearAlgebra.Matrix.SesquilinearForm   instructions    13.0%

leanprover-bot avatar Jan 16 '24 19:01 leanprover-bot

File metric master change this branch
Mathlib.LinearAlgebra.Matrix.SesquilinearForm instructions 380.472B 49.57B 13.029 % 430.042B

mans0954 avatar Jan 17 '24 17:01 mans0954

Before:

cumulative profiling times:
        attribute application 39.8ms
        compilation 1.2s
        dsimp 0.453ms
        elaboration 2.2s
        interpretation 0.163ms
        linting 343ms
        parsing 26.6ms
        simp 3s
        tactic execution 1.23s
        type checking 1.21s
        typeclass inference 28.2s

After:

cumulative profiling times:
        attribute application 38ms
        compilation 989ms
        dsimp 0.63ms
        elaboration 2.54s
        interpretation 0.147ms
        linting 322ms
        parsing 24.5ms
        simp 2.89s
        tactic execution 1.37s
        type checking 1.15s
        typeclass inference 30.5s

mans0954 avatar Jan 17 '24 17:01 mans0954

!bench

mans0954 avatar Jan 17 '24 19:01 mans0954

Here are the benchmark results for commit 390083a20bb91595e2baefdb18bcad0995a325a9. There were significant changes against commit b4cd3132fe069277f225fde5e0a5ecba95b9a57f:

  Benchmark                                        Metric         Change
  ======================================================================
- ~Mathlib.LinearAlgebra.Matrix.SesquilinearForm   instructions    11.3%

leanprover-bot avatar Jan 17 '24 20:01 leanprover-bot

Import summary

No significant changes to the import graph

github-actions[bot] avatar Jun 07 '24 06:06 github-actions[bot]

PR summary 867eb130b7

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

No declarations were harmed in the making of this PR! 🐙

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>

github-actions[bot] avatar Jun 07 '24 20:06 github-actions[bot]

This PR/issue depends on:

  • ~~leanprover-community/mathlib4#9475~~
  • ~~leanprover-community/mathlib4#13042~~ By Dependent Issues (🤖). Happy coding!

!bench

mans0954 avatar Jul 13 '24 19:07 mans0954

Here are the benchmark results for commit 7ac91b416290d11ba970ecb1f2fa15b0ff55080e. There were significant changes against commit 98151c27f6edb34c46ed3fdfa25b67c402600ba5:

  Benchmark                                        Metric         Change
  ======================================================================
- ~Mathlib.LinearAlgebra.Matrix.SesquilinearForm   instructions    29.4%

leanprover-bot avatar Jul 13 '24 20:07 leanprover-bot

!bench

mans0954 avatar Jul 15 '24 18:07 mans0954

Here are the benchmark results for commit 6f6a726b5d6f36a678ab71c052f191d88fd44473. There were significant changes against commit 70523677f8db8e24034c887ba807ac9fc88d6103:

  Benchmark                                        Metric         Change
  ======================================================================
- ~Mathlib.LinearAlgebra.Matrix.SesquilinearForm   instructions    31.4%

leanprover-bot avatar Jul 15 '24 19:07 leanprover-bot

@j-loreaux unfortunately the benchmarks look slightly worse (I'm assuming a larger percentage in red is worse?)

mans0954 avatar Jul 15 '24 19:07 mans0954

That's such a small change, and only in a single file, that it's not a big deal. It could even be noise.

j-loreaux avatar Jul 15 '24 20:07 j-loreaux

General information:

lint:                                                  +3.5755 * 10⁹ (+0.0445%)
build:                                                 +49.877 * 10⁹ (+0.0406%)

7 files got slower by at least 10⁹ instructions:

Mathlib.LinearAlgebra.Matrix.SesquilinearForm:         +35.147 * 10⁹ (+31.4%)
Mathlib.LinearAlgebra.Matrix.BilinearForm:             +3.8428 * 10⁹ (+4.73%)
Mathlib.Combinatorics.SimpleGraph.LapMatrix:           +2.9559 * 10⁹ (+12.6%)
Mathlib.LinearAlgebra.Matrix.PosDef:                   +2.1526 * 10⁹ (+4.43%)
Mathlib.LinearAlgebra.QuadraticForm.Basic:             +1.6895 * 10⁹ (+0.926%)
Mathlib.Algebra.Lie.Classical:                         +1.3773 * 10⁹ (+3.76%)
Mathlib.CategoryTheory.Category.Cat.Limit:             +1.3142 * 10⁹ (+1.38%)

2 files got slower by at least 10%:

Mathlib.LinearAlgebra.Matrix.SesquilinearForm:                        +31.4%
Mathlib.Combinatorics.SimpleGraph.LapMatrix:                          +12.6%

No file got faster by at least 10⁹ instructions.

No file got faster by at least 10%.

MichaelStollBayreuth avatar Jul 15 '24 20:07 MichaelStollBayreuth

Thanks @MichaelStollBayreuth I'll let someone else decide. But I'm okay with this. The other option would be to have these general versions, and then more specific ones which are abbrevs of these to help Lean with elaboration. I expect that would help, but I'm not positive without trying it.

maintainer merge

j-loreaux avatar Jul 15 '24 23:07 j-loreaux

🚀 Pull request has been placed on the maintainer queue by j-loreaux.

github-actions[bot] avatar Jul 15 '24 23:07 github-actions[bot]

:v: mans0954 can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

mathlib-bors[bot] avatar Jul 16 '24 10:07 mathlib-bors[bot]

bors r+

mans0954 avatar Jul 16 '24 18:07 mans0954

Pull request successfully merged into master.

Build succeeded:

mathlib-bors[bot] avatar Jul 16 '24 19:07 mathlib-bors[bot]