Zulip Chat Archive
Stream: mathlib4
Topic: 'theorem' or 'lemma'
Peter Nelson (May 11 2024 at 15:19):
Is there a mathlib style policy on this matter?
Yaël Dillies (May 11 2024 at 15:22):
Not yet, but the idea is to reserve theorem
for named results in the mathematical literature, and call everything lemma
Yaël Dillies (May 11 2024 at 15:23):
Before enforcing this, we need to replace all mathport-induced theorem
with lemma
, and we're putting that off until we have a good programmatic solution
Ruben Van de Velde (May 11 2024 at 15:25):
Alternatively, we could just use one keyword and not have to argue which results should use which keywords
Peter Nelson (May 11 2024 at 15:28):
Based on those two responses, it seems that the intention might not be so clear-cut. Could some maintainers perhaps weigh in on this? When making PRs, it would be nice to have an official source indicating best practice, even if it's not enforced.
Note that it is difficult to search for an answer to this question on Zulip.
Yury G. Kudryashov (May 11 2024 at 15:58):
AFAIK, we don't have any official policy yet.
Kyle Miller (May 11 2024 at 16:15):
There's no official policy (and what Yaël says is an idea that has been suggested, though a reasonable one). My own preference is that theorem
is reserved for what you feel is an important result in the theory. Almost all of mathlib consists of lemma
s.
One of the things that didn't get ported when going from Lean 3 was which results were lemmas. I believe there's still some thought to try to port that eventually...
Damiano Testa (May 11 2024 at 16:19):
I have a script that replaces every theorem
with lemma
. I could adapt it to replace every "theorem
with no doc string" to lemma
. However, this rots very fast and I would only run it if it were certainly merged soon...
Damiano Testa (May 11 2024 at 16:19):
I could also write a linter that would enforce the "theorem must have a doc string".
Kyle Miller (May 11 2024 at 16:21):
It looks like we never made a decision, but I found the thread from September that was the last discussion about this, and somewhere in it was a poll that showed there was support to keep theorem
for important results and to require that it have a docstring.
Peter Nelson (May 11 2024 at 16:23):
I like the sound of that enforced dosctring approach, or less stringently, the use of the keywords that aligns with the way mathematicians talk.
Sometimes though, as a contributor, it is just nice to be told what to do, and not to encounter differing views via PR suggestions (I'm not referring to anything specific recently, but I think I have had comments in the past suggesting lemma -> theorem
for tiny results). Can I take it from this discussion that if I use 'lemma' and 'theorem' as if I were writing a paper, I won't meet any resistance?
Ruben Van de Velde (May 11 2024 at 16:29):
Not from me in any case :)
Eric Wieser (May 12 2024 at 10:08):
Note if you pick "theorem" but don't add a docstring, then it may be auto-replaced with lemma
in future
Damiano Testa (May 14 2024 at 10:41):
I know that there are some strong views in favour and against the presence of lemma
in mathlib. I am personally in favour.
In the meantime, I wrote a linter that warns against doc-less theorem
s in mathlib: #12869.
You can see its effect in #12863.
Note that the replacements theorem
to lemma
were guided by actually parsing the lean syntax. In particular, no doc-string or comment has been affected by the change.
Last updated: May 02 2025 at 03:31 UTC