EncounterActivity 1 of 8
Encounter
Imagine a definition loop n = loop (n + 1). It never produces an answer. Worse, in a
proof assistant it would be dangerous: def bad : False := bad would "prove" False, and
then everything would be provable.
So Lean checks that every recursive call is on something smaller:
- Structural recursion: the call is on a piece of the input (
nfromn + 1,xsfromx :: xs). Lean sees this automatically. - Well-founded recursion: the input shrinks by some measure (for example
n / 2 < nwhenn ≥ 2). You name the measure withtermination_byand, if needed, prove it decreases withdecreasing_by.