Zulip Chat Archive
Stream: PR reviews
Topic: PR #31821 Singular Value Decomposition
Levi G (Nov 19 2025 at 20:51):
PR #31821 has definitions and proofs for Singular Value Decompositon. PR #31821
Here is the code designed for lean 4.25.0
SVD.txt
Jireh Loreaux (Nov 19 2025 at 21:30):
@Levi G did you work with @Niels Voss on this? It seems likely not.
Kenny Lau (Nov 19 2025 at 21:34):
@Jireh Loreaux no, he worked with GPT on this;
@Levi G your file needs to end in .lean for it to be a proper lean file
Kenny Lau (Nov 19 2025 at 21:35):
and you'll also need to do lake exe mk_all but you can do this later
Jireh Loreaux (Nov 19 2025 at 21:35):
Kenny, the PR passes CI (technically, but whatever)
Jireh Loreaux (Nov 19 2025 at 21:35):
(although I haven't looked at it past that)
Jireh Loreaux (Nov 19 2025 at 21:35):
oh, it passes CI because it's .txt
Kenny Lau (Nov 19 2025 at 21:35):
of course it passes CI, without .lean it isn't even a lean file (maybe that's how it works?)
Damiano Testa (Nov 19 2025 at 21:36):
Does lake exe mk_all work with the module system? At best, it will add "plain" imports, I guess.
Kenny Lau (Nov 19 2025 at 21:36):
Jireh Loreaux said:
Kevin, the PR passes CI
I don't see why that's a response to what i said, passing CI or not he still worked with GPT on this
Jireh Loreaux (Nov 19 2025 at 21:40):
Indeed, I've just closed the PR.
Weiyi Wang (Nov 19 2025 at 22:05):
Damiano Testa said:
Does
lake exe mk_allwork with the module system? At best, it will add "plain"imports, I guess.
It worked for me today after the module migration
Levi G (Nov 19 2025 at 22:11):
The code works though. Pls at least try it.
Levi G (Nov 19 2025 at 22:13):
@Jireh Loreaux I did not work with @Niels Voss
Levi G (Nov 19 2025 at 22:20):
@Jireh Loreaux Here is the file ending in .lean
I apologise for the confusion. I promise this ain't ai slop.
SVD.lean
@Kenny Lau Pls check and confirm.
Anthony Wang (Nov 19 2025 at 22:27):
The file you sent seems to have mangled Unicode characters, but I tried compiling your PR and surprisingly it does actually type check even though it's low quality AI slop.
Levi G (Nov 19 2025 at 22:32):
Wdym it's low quality AI slop? Maybe it is not well-written like a professional mathematician but doesn't it do the job and prove SVD for all complex matrices? It seems to work.
Levi G (Nov 19 2025 at 22:39):
Sorry and I apologise for the confusion about the whole txt thing. Lemme open another pr with the correct file extension.
Levi G (Nov 19 2025 at 22:53):
My new PR with the code using the right file extension ( .lean)
feat(Mathlib/Analysis): Existence of Singular Value Decomposition #31830
Pls @Jireh Loreaux and @Kenny Lau confirm.
Aaron Liu (Nov 19 2025 at 23:07):
You put lake exe mk_all at the top of the file
Aaron Liu (Nov 19 2025 at 23:08):
you were supposed to run it in the command line after saving the file, and then after it's done running commit the result
Aaron Liu (Nov 19 2025 at 23:08):
try deleting it from the file and run it in the command line instead
Levi G (Nov 19 2025 at 23:18):
Aaron Liu said:
you were supposed to run it in the command line after saving the file, and then after it's done running commit the result
Ahh ok thanks
Levi G (Nov 19 2025 at 23:19):
Aaron Liu said:
try deleting it from the file and run it in the command line instead
Thanks ... lemme do that
Yan Yablonovskiy 🇺🇦 (Nov 19 2025 at 23:24):
Levi G said:
Wdym it's low quality AI slop? Maybe it is not well-written like a professional mathematician but doesn't it do the job and prove SVD for all complex matrices? It seems to work.
Simply doing the job is more relevant for your own purposes, but contributing to a repository is a lot more nuanced than that.
Levi G (Nov 20 2025 at 00:34):
(deleted)
Jireh Loreaux (Nov 20 2025 at 03:32):
@Levi G I did examine the PR before closing it. It may compile (which is more than can be said for a lot of the AI output we get here), but that's not nearly a high enough bar to qualify as a contribution to Mathlib.
However, I'll apologize for the way I handled it. I should have provided more of an explanation for why I was closing the PR. Let me do that now. I'll list a few of the more significant issues with this PR (although there are many more besides):
- It only works for
ℂ-valued matrices - It only works for matrices and not linear maps.
- Your index sets are
Fin ninstead of arbitraryFintypes - You don't link any of this to existing API (execpt for
PosDef) in statements (e.g. you writeV * Vᴴ = 1 ∧ Vᴴ * V =1). You don't use docs#Matrix.diagonal, docs#unitary, etc. in statements. - Your ratio of
defs tolemmas is pretty high. Each definition introduced into the library needs sufficient API so that it is usable. Moreover, many of these are definitions we don't want, at least not in this form. - Your
set_options andlocal instances at the top of the file are no good. - In part because of the above issues, the proofs of some key results are monstrously huge.
If you want to contribute to Mathlib, chat about your project on Zulip first, learn a lot, learn what's needed and how to go about things. After those steps, you'll be in a better state to contribute. I suggest not using an LLM, at least not to start, as it can prevent you from learning well.
Moritz Doll (Nov 20 2025 at 03:49):
As for 7: the proofs are also huge because they prove a things in a very roundabout way that no human would ever come up with. For example
have hmem : ∃ j₀, Fin.castLE h j = Fin.castLE h j₀ := ⟨j, rfl⟩
simp only [hmem, dif_pos]
congr 1
ext k
have h_spec : Classical.choose hmem = j := by
have : Fin.castLE h (Classical.choose hmem) = Fin.castLE h j := (Classical.choose_spec hmem).symm
exact Fin.castLE_injective h this
rw [h_spec]
at around line 707 in your current PR. Without even trying to understand what is going on here, I can tell that this is bad.
Levi G (Nov 20 2025 at 06:54):
Jireh Loreaux said:
Levi G I did examine the PR before closing it. It may compile (which is more than can be said for a lot of the AI output we get here), but that's not nearly a high enough bar to qualify as a contribution to Mathlib.
However, I'll apologize for the way I handled it. I should have provided more of an explanation for why I was closing the PR. Let me do that now. I'll list a few of the more significant issues with this PR (although there are many more besides):
- It only works for
ℂ-valued matrices- It only works for matrices and not linear maps.
- Your index sets are
Fin ninstead of arbitraryFintypes- You don't link any of this to existing API (execpt for
PosDef) in statements (e.g. you writeV * Vᴴ = 1 ∧ Vᴴ * V =1). You don't use docs#Matrix.diagonal, docs#unitary, etc. in statements.- Your ratio of
defs tolemmas is pretty high. Each definition introduced into the library needs sufficient API so that it is usable. Moreover, many of these are definitions we don't want, at least not in this form.- Your
set_options andlocal instances at the top of the file are no good.- In part because of the above issues, the proofs of some key results are monstrously huge.
If you want to contribute to Mathlib, chat about your project on Zulip first, learn a lot, learn what's needed and how to go about things. After those steps, you'll be in a better state to contribute. I suggest not using an LLM, at least not to start, as it can prevent you from learning well.
@Jireh Loreaux Thank you for your feedback and response. Feedback noted. I have a lot to learn. For this new PR I'll make the necessary changes based on your highlighted points.
Levi G (Nov 20 2025 at 11:17):
I have made quite a few extensive changes to my code, should be much better. Now my .lean code on github now passes all the tests. Please have a look. @Weiyi Wang @Aaron Liu @Jireh Loreaux
Kenny Lau (Nov 20 2025 at 11:26):
where?
Levi G (Nov 20 2025 at 11:28):
Kenny Lau said:
where?
Here: https://github.com/leanprover-community/mathlib4/pull/31830
feat(Mathlib/Analysis): Existence of Singular Value Decomposition #31830
Kenny Lau (Nov 20 2025 at 11:31):
did you (not gpt) even read through any of the points that Jireh presented above?
Levi G (Nov 20 2025 at 11:33):
Kenny Lau said:
did you (not gpt) even read through any of the points that Jireh presented above?
I have not finished everything especially the linear map instead of matrix and fintype S
Levi G (Nov 20 2025 at 11:35):
I wanted to get a minimal working clean version of the one with Complex Matrices before generalizing further because the previous had a boat load of issues even if it compiled.
Kenny Lau (Nov 20 2025 at 11:37):
that's great to hear, i look forward to it
Michael Rothgang (Nov 20 2025 at 11:38):
At the very least, let me mark your PR as awaiting-author then: this tells other reviewers that you're still working on it.edit: it already was
If you're done, you want write a comment with just the words -awaiting-author to remove that label.
Levi G (Nov 20 2025 at 11:38):
In particular I was handling points 4 to 7
Levi G said:
I wanted to get a minimal working clean version of the one with Complex Matrices before generalizing further because the previous had a boat load of issues even if it compiled.
Michael Rothgang (Nov 20 2025 at 11:39):
The current code still has a number of instances of (4) - while you're claiming they're solved. For me, that does not inspire confidence.
Levi G (Nov 20 2025 at 11:40):
Michael Rothgang said:
At the very least, let me mark your PR as awaiting-author then: this tells other reviewers that you're still working on it. If you're done, you want write a comment with just the words
-awaiting-authorto remove that label.
Ok thanks. Though it had been already marked.
Levi G (Nov 20 2025 at 11:42):
Michael Rothgang said:
The current code still has a number of instances of (4) - while you're claiming they're solved. For me, that does not inspire confidence.
Sorry still needs some work.
Jireh Loreaux (Nov 20 2025 at 15:22):
@Levi G please give up on this PR (and SVD) for now. I'm not saying you can't be a contributor to Mathlib, but it's going to take time to get there.
This is especially true for this material, as there is already someone (Niels Voss, which is why I asked about him earlier) who is working on this, and with whom we have had extensive discussions about design for singular values and the singular value decomposition. For example, one thing I didn't mention above is that your singular values only work for finite dimensional objects, but ultimately we'd like the entire singular value list even for compact operators in infinite dimensions.
If you honestly want to contribute to Mathlib, pick a small thing to do (let's say that the total code included in the PR for it should be < 75 lines or so). Mention it on Zulip before creating the PR and get feedback to make sure the contribution is welcome and your approach is a good idea. Then create the PR, get reviews, and pay careful attention to the feedback so you can learn for next time.
Jireh Loreaux (Nov 20 2025 at 15:25):
The extensive discussions I mentioned are here: #Is there code for X? > Singular Value Decomposition . I encourage you to read that thread, not so that you can be ready to contribute SVD, but so that you can learn the kinds of considerations that go into curating material for Mathlib, and see an example of how to ask on Zulip for feedback before creating a PR.
Levi G (Nov 20 2025 at 15:29):
Ok, understood. Thanks, Lemme close the PR on github.
Jireh Loreaux (Nov 20 2025 at 15:31):
Thanks for responding appropriately and taking the feedback constructively.
Levi G (Nov 20 2025 at 15:32):
Jireh Loreaux said:
The extensive discussions I mentioned are here: #Is there code for X? > Singular Value Decomposition . I encourage you to read that thread, not so that you can be ready to contribute SVD, but so that you can learn the kinds of considerations that go into curating material for Mathlib, and see an example of how to ask on Zulip for feedback before creating a PR.
Thank you for linking the thread. I will definitely go through it.
Levi G (Nov 22 2025 at 14:32):
Hello. I know we are supposed to discuss and come up with proofs in small chunks but right I have something significantly better than what I had before - a basis-free SVD for LinearMap over Real or Complex field. I would like to share that progress. But it’s for finite dimensional inner product spaces not the infinite dimensional case. Would that be of use/interest? I would like to hear your feedback. @Jireh Loreaux @Michael Rothgang @Weiyi Wang @Kenny Lau @Moritz Doll @Aaron Liu @Yan Yablonovskiy 🇺🇦
Levi G (Nov 22 2025 at 19:40):
Here it is. I would like to hear your feedback.
finite dimensional Basis-Free SVD-2.lean
Levi G (Nov 24 2025 at 06:38):
Any feedback? I know discussions are going on in other SVD thread but I just need some feedback.
Johan Commelin (Nov 24 2025 at 08:05):
@Levi G Let me put this bluntly: it is time to stop working on formalizing SVD now, and first take on smaller projects.
People have kindly invested time and energy into your earlier PRs, and have given you constructive feedback.
They also made clear that formalizing SVD is a minefield. Take that to heart.
Levi G (Nov 24 2025 at 08:13):
Johan Commelin said:
Levi G Let me put this bluntly: it is time to stop working on formalizing SVD now, and first take on smaller projects.
People have kindly invested time and energy into your earlier PRs, and have given you constructive feedback.
They also made clear that formalizing SVD is a minefield. Take that to heart.
@Johan Commelin Understood. It's just that I was hoping for some more feedback because this latest version is significantly better than anything that I had given before and also attempted to address their feedback. I hope you can at least take a look at this one. However, I have understood your point, it is a minefield so I will just stop pressing on this matter, hold-off completely and move on to other projects. Thank you for your feedback.
Michael Rothgang (Nov 24 2025 at 09:08):
I appreciate you trying to learn from feedback, and understand your wish for confirmation if you addressed it well! That said: at least I personally prefer giving feedback where it's directly useful --- by which I mean "I'd rather give you feedback on a different PR that's useful than on this one". As said above, #31821 will not get merged into mathlib, so any comments there would be only for your learning.
Commenting on a future PR of yours that has chances of making it to mathlib is a much better use of everybody's time. If you show willingness to learn, people are usually very happy to provide feedback.
Nick_adfor (Dec 15 2025 at 16:51):
Is there any Jordan decomposition in linear algebra? I search it and there's only Jordan decomposition in measure theory. Is it another minefield?
Last updated: Dec 20 2025 at 21:32 UTC