Zulip Chat Archive
Stream: lean4
Topic: Print equations related to a definition
Bhavik Mehta (Feb 18 2025 at 01:20):
Here's my example:
import Batteries.Tactic.PrintPrefix
def myDef : Nat → Nat := fun x ↦ x + 1
I'd like to see which equational lemmas Lean generates for this definition. Here's what I tried:
#print prefix myDef
#print prefix +internals myDef
#print eqns myDef
#print equations myDef
#print myDef
but none of these told me about myDef.eq_def
. How can I see the _full_ list of declarations with a given prefix, without things like this being hidden?
Eric Wieser (Feb 18 2025 at 01:24):
whatsnew in
might do what you want here
Bhavik Mehta (Feb 18 2025 at 01:25):
It doesn't, it just outputs a subset of the above.
Aaron Liu (Feb 18 2025 at 01:25):
Note that myDef.eq_def
is generated on first use, and then cached. If you don't have anything that uses myDef.eq_def
then it doesn't exist.
Bhavik Mehta (Feb 18 2025 at 01:28):
Can you explain this some more? #check myDef.eq_def
seems to tell me it exists before I use it. Or are you saying that me typing this in is using it? Even after that check, all the above don't show me this lemma
Eric Wieser (Feb 18 2025 at 01:29):
import Batteries.Tactic.PrintPrefix
def myDef : Nat → Nat := fun x ↦ x + 1
-- #print myDef.eq_def -- uncomment for magic
-- def foo := myDef.eq_def -- uncomment for magic
#print prefix myDef
Eric Wieser (Feb 18 2025 at 01:30):
Weirdly, #check
has no side effect but #print
does
Aaron Liu (Feb 18 2025 at 01:30):
#check
erases its side effects
Eric Wieser (Feb 18 2025 at 01:30):
In that case I'm surprised that #print
does not
Bhavik Mehta (Feb 18 2025 at 01:32):
Okay, that makes sense. But this is still pretty weird right, why do we have lemmas which behave like this: it doesn't exist until I use it, and then it does exist
Aaron Liu (Feb 18 2025 at 01:34):
What if you have this huge function, like docs#Lean.Meta.kabstract, but never unfold it in a proof? Then it would be a waste to have the equational lemma.
Bhavik Mehta (Feb 18 2025 at 01:36):
Hmm, okay
Bhavik Mehta (Feb 18 2025 at 01:36):
One more surprise (to me): if I use myDef.eq_unfold
and don't use myDef.eq_def
, then Lean also generates the eq_def
lemma. (This is documented in docs#Lean.Meta.getConstUnfoldEqnFor?)
Aaron Liu (Feb 18 2025 at 01:43):
Also see #new members > ✔ Can I know exactly what collaterals are added by commands?
Last updated: May 02 2025 at 03:31 UTC