我知道使用lambda表达式,我们可以编写succ = λnfx • f (n f x )
和twice = λfn • f f(n )
。我现在的目标是使用这两个来编写add4,它为教堂数字增加了4个。
如何为此编写beta减少步骤?
先谢谢你的帮助......
答案 0 :(得分:3)
好吧,twice succ
是一个应用succ
两次的函数,因此twice (twice succ)
是一个两次应用twice succ
的函数,因此应用succ
四次。所以它应该是add4 = twice (twice succ)
。
twice = λf.λn.(f (f n))
twice (twice succ)
=> twice (λf.λn.(f (f n)) succ)
=> twice λn.(succ (succ n))
=> λf.λn.(f (f n)) λn.(succ (succ n))
=> λf.λn.(f (f n)) λx.(succ (succ x))
=> λn.(λx.(succ (succ x)) (λx.(succ (succ x)) n))
=> λn.(λx.(succ (succ x)) (succ (succ n)))
=> λn.(succ (succ (succ (succ n))))
=> λn.(succ (succ (succ (succ n))))