Zulip Chat Archive
Stream: lean4
Topic: Debuggin Evaluation
Yicheng Qian (Aug 20 2022 at 06:08):
How can I debug evaluation in Lean4? To be specific, after I defined a function f
, I executed #eval (f arg)
and the result res
is incorrect. To find out what's wrong, I wanted to follow the evaluation of f arg
step-by-step. How to do that?
I tried this: First, I declared a theorem f arg = res
and entered tactic mode
theorem foo : f arg = res := by
Then, I used the tactic rw
to reduce f arg
step-by-step. However, the reduction often stucks, for example at expressions like <typeclass-object>.<field-notation>
. What can I do?
Henrik Böving (Aug 20 2022 at 06:11):
The simple answer right now is: You do not do that. You do not follow execution step by step, what you can do though is add little fragments of dbg_trace s!"Fooo {myvar}"
into even pure code to see what is going on.
Yicheng Qian (Aug 20 2022 at 06:16):
Can you further explain how to use the "dbg_trace" command? I'm new to lean and don't know how to use it.
Yicheng Qian (Aug 20 2022 at 06:16):
Is there any documentation which explains it?
Henrik Böving (Aug 20 2022 at 06:16):
def foo (x : Nat) :=
dbg_trace s!"{x}"
Nat.add x 12
Henrik Böving (Aug 20 2022 at 06:17):
Yicheng Qian said:
Is there any documentation which explains it?
Not to my knowledge
Sebastian Ullrich (Aug 20 2022 at 10:06):
https://leanprover.github.io/lean4/doc/dev/debugging.html, additions are welcome
Yicheng Qian (Aug 20 2022 at 12:03):
Thanks. This is very helpful.
Last updated: Dec 20 2023 at 11:08 UTC