Zulip Chat Archive
Stream: new members
Topic: definition vs theorem
Holly Liu (Jun 16 2021 at 00:01):
hi! i was wondering what the difference between definition and theorem is, and when to use one over the other? i'm reading about the pragmatic differences in the documentation but i'm still not understanding it.
Mario Carneiro (Jun 16 2021 at 00:04):
The rule used in mathlib is: if it's a proof (something whose type has type Prop), then use theorem or lemma, otherwise use def
Holly Liu (Jun 16 2021 at 00:05):
thanks!
Mario Carneiro (Jun 16 2021 at 00:07):
as for the technical differences:
defs are elaborated synchronously, and can add additional local definitions to the environmenttheoremis opaque by default and you have to use some heavyweight tactics to get at the definition of the theorem after the fact- The type of a
defcan depend on / be inferred from the term, whiletheoremrequires that the type typecheck without looking at the term. So in particulardef foo := barworks buttheorem foo := bardoesn't, it always has to betheorem foo : type := bar
Holly Liu (Jun 16 2021 at 00:11):
what is the definition of the theorem?
Mario Carneiro (Jun 16 2021 at 00:11):
it checks the type of bar and that becomes the type of foo too
Mario Carneiro (Jun 16 2021 at 00:12):
for example:
def foo := 1 -- foo : nat
def bar := foo -- bar : nat
Mario Carneiro (Jun 16 2021 at 00:13):
Actually maybe that's not your question. def and theorem are both lean built-ins
Holly Liu (Jun 16 2021 at 00:15):
so is the definition of the theorem something you use to check the type of sorry nevermind i think i understand. thanksbar, something like using #check?
Mario Carneiro (Jun 16 2021 at 00:21):
I don't know what you mean by the definition of the theorem. The theorem is defined by the theorem foo : type := bar line
Mario Carneiro (Jun 16 2021 at 00:22):
you can see a definition after the fact (even for autogenerated definitions) using #print foo
Mario Carneiro (Jun 16 2021 at 00:22):
that will show you what lean inferred for all the missing bits
Holly Liu (Jun 16 2021 at 00:26):
yes i was getting confused about the semantics. that clears it up a lot.
Last updated: May 02 2025 at 03:31 UTC