Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

2
  • $\begingroup$ Interesting! Can we make sense of the generated code? I imagine that it has to find a well founded relation > on natural numbers, together with its well-foundedness proof, and then do some algebra to show that (1 + m) + n > n + m, but I can't see much evidence of the last step. And, not knowing the library definitions, I don't know which relation it is finding. $\endgroup$
    – James Wood
    Commented Sep 1, 2023 at 15:53
  • 1
    $\begingroup$ I'm short on time, and will be for the next month or so, but here's a sketch. The type class WellFoundedRelation is used to find a default well-founded relation for the type to the right of the => in the termination_by clause. The tactic decreasing_tactic is used to actually show that the relation holds for the recursive call in question, unless this tactic is overridden by a separate decreasing_by clause. Lean tactics are extensible with extra fallback cases. You can read more at leanprover.github.io/theorem_proving_in_lean4/… $\endgroup$ Commented Sep 2, 2023 at 17:05