问题描述
是否可以在 Isabelle/HOL 中编写递归 lambda 表达式?如果是这样,如何?
例如(一个愚蠢的):
fun thing :: "nat ⇒ nat" where
"thing x = (λx. if x=0 then x else …) x"
所以,而不是……我想写出应用于 x-1 的 λ 函数。
我该怎么做?提前致谢。
解决方法
只有一种情况是必要的:在证明中定义函数时。我已经这样做了,但这远非初学者友好,因为您必须手动推导出简单规则。
解决方案是模仿 fun
在内部所做的事情并根据 rec_nat
表达您的定义:
fun thing :: "nat ⇒ nat" where
"thing x = rec_nat 0 (λ_ x. if x=0 then x else (x-1)) x"
(*simp rules*)
lemma thing_simps[simp]:
‹thing 0 = 0›
‹thing (Suc n) = thing n - Suc 0›
unfolding thing_def
by simp_all
除非不可避免,否则我不建议这样做...