Zulip Chat Archive
Stream: metaprogramming / tactics
Topic: Theorem-level dependency graph
Yury G. Kudryashov (Dec 16 2025 at 15:15):
I've just completed the proof of the main theorem in https://github.com/urkud/SardMoreira/. The repository has a bunch of theorems that I added because they seemed useful, then never used for the final proof. Is there something like lake exe graph for theorems? E.g., I would love to move those unused theorems to a new file Unused.lean, then go through the dependency graph of the rest and PR stuff to Mathlib.
Damiano Testa (Dec 16 2025 at 15:20):
I do not know of any automation, but I found #show_unused very helpful for this kind of process.
Yury G. Kudryashov (Dec 16 2025 at 15:29):
Thanks!
Johan Commelin (Dec 16 2025 at 16:13):
cc @Adam Topaz
Damiano Testa (Dec 16 2025 at 16:19):
Btw, there are rumours of a #mwe producer, which could likely be repurposed into this kind of behaviour.
Adam Topaz (Dec 16 2025 at 16:50):
@Yury G. Kudryashov I'm working on such things now, but nothing is ready yet. In the meantime, you can use Lean.Name.transitivelyUsedConstants to get the transitive dependencies of some constant in the environment.
Adam Topaz (Dec 16 2025 at 16:51):
Give me about 5 mins and I'll tell you what your theorems in MainTheorem.lean depend on.
Adam Topaz (Dec 16 2025 at 16:59):
Here's the list of constants defined in your project which your main theorems depend on:
data
Adam Topaz (Dec 16 2025 at 16:59):
I got this by running the following script at the bottom of your MainTheorem.lean file:
open Lean in
#eval show CoreM Unit from do
let env ← getEnv
let consts : NameSet :=
env.constants.map₂.foldl (init := {}) fun n a _ => n.insert a
let deps ← consts.transitivelyUsedConstants
let mut filteredDeps : NameSet := {}
for dep in deps do
if (← dep.isBlackListed) then continue
let some mod := env.getModuleFor? dep | continue
unless mod.getRoot == `SardMoreira do continue
filteredDeps := filteredDeps.insert dep
IO.FS.withFile "data" .write fun handle => do
for dep in filteredDeps do
handle.putStrLn dep.toString
Yury G. Kudryashov (Dec 16 2025 at 17:09):
Thanks!
Adam Topaz (Dec 16 2025 at 17:09):
I'm making a graph for you too :)
Adam Topaz (Dec 16 2025 at 17:33):
Adam Topaz (Dec 16 2025 at 17:34):
Oops! the arrows should go the other way, one sec.
Adam Topaz (Dec 16 2025 at 17:39):
also, there was a bug causing the graph to be diconnected.
Adam Topaz (Dec 16 2025 at 17:42):
(deleted)
Yury G. Kudryashov (Dec 16 2025 at 17:49):
Could you please generate the list of unused declarations too? Thanks a lot!
Adam Topaz (Dec 16 2025 at 17:50):
Here's a better graph:
output.png
graph.dot
Adam Topaz (Dec 16 2025 at 17:57):
Seems like you have 211 constants which are not used in dimH_image_le_sardMoreiraBound_of_finrank_le:
unused.txt
Adam Topaz (Dec 16 2025 at 17:58):
This assumes everything in the project is imported in SardMoreira.lean
Yury G. Kudryashov (Dec 16 2025 at 19:10):
Thanks a lot! I'll start cleaning up and opening mathlib prs tonight.
Adam Topaz (Dec 16 2025 at 19:11):
no problem! if you have some thoughts about what such commands would be useful to add to mathlib, let me know.
Yury G. Kudryashov (Dec 16 2025 at 20:28):
What command did you use to generate unused.txt?
Adam Topaz (Dec 16 2025 at 20:31):
I wrote a bit of code myself, there isn’t any command as far as I know
Last updated: Dec 20 2025 at 21:32 UTC