Zulip Chat Archive
Stream: new members
Topic: how to show termination of McCarthy `M`
Asei Inoue (Jun 03 2024 at 08:34):
/-- McCarthy's 91 function -/
def M (n : Nat) : Nat :=
if n > 100 then
n - 10
else
M (M (n + 11))
Asei Inoue (Jun 03 2024 at 08:35):
I don't even know what to specify for termination_by
.
Timo Carlin-Burns (Jun 03 2024 at 09:35):
Here's my attempt
/-- McCarthy's 91 function -/
def M (n : Nat) : { m : Nat // m ≥ n - 10 } :=
if h : n > 100 then
⟨n - 10, Nat.le_refl (n - 10)⟩
else
have := (M (n + 11)).property
have :=
calc n - 10
_ ≤ (n + 11) - 10 - 10 := by omega
_ ≤ (M (n + 11)).val - 10 := Nat.sub_le_sub_right this 10
_ ≤ (M (M (n + 11)).val).val := (M (M (n + 11)).val).property
⟨(M (M (n + 11)).val).val, this⟩
termination_by 101 - n
Timo Carlin-Burns (Jun 03 2024 at 09:36):
To show that the outer recursive call terminates you need some properties of M
, and you're not allowed to unfold M
while defining it, so my workaround was to have M
return a subtype with the necessary properties.
Asei Inoue (Jun 03 2024 at 15:37):
@Timo Carlin-Burns Thank you. It's a nice solution!!
Last updated: May 02 2025 at 03:31 UTC