Reading Notes of SICP_02 Episode on Church Numerals

来源:互联网 发布:php中文网有手机版吗 编辑:程序博客网 时间:2024/06/05 15:23

Here comes the exercise 2.6 from SICP,about Church Numerals--really make numbers into functions amazingly and beautifully !

In case representing pairs as procedures wasn't mind-boggling enough, consider that, in a language that can manipulate procedures, we can get by without numbers (at least insofar as non-negative integers are concerned) by implementing 0 and the operation of adding 1 as

(define zero (lambda (f) (lambda (x) x))) (define (add-1 n)   (lambda (f) (lambda (x) (f ((n f) x)))))

This representation is known as Church numerals, after its inventor, Alonzo Church, the logician who invented the <math>\lambda</math> calculus.

Define one and two directly (not in terms of zero and add-1). (Hint: Use substitution to evaluate (add-1 zero)). Give a direct definition of the addition procedure + (not in terms of repeated application of add-1).

First time I work on this problem,I was really confused,even if I got couple answers of this problem,so I took a note to analyse :


church数:

(数字是函数)

zero:
zero是一个函数 F1。
F1需要参数 f ~~so~~-->问题的关键在于参数 f~~
F1:
只包含了一个返回自己的函数

add-1:
是一个需要参数 n 的函数-->n也是一个函数
里面包含了一个函数  F1
F1需要参数 f-->是一个函数
包含一个函数F2
F2 需要参数 x
F2 调用函数 f--调用了上面的参数 x,n
f 的参数是 【(n f) x】-->这是一个以 x 为参数的复合函数

~~so~~ add-1 是需要函数 f 和函数 n 的函数
-->函数 f 是关键~~

key of all:把 f 当成黑箱处理以上问题~~


then,when looking at other guy's answers ,this thing become easier~~

They define the fuction f first~~

and the real thing about Church Numerals is how many times your number execute f~~


the following things about this theory is clearly discussed on other master's page ,like

http://jlongster.com/2011/12/16/sicp-26-church-notation.html

and an amazing guy named GenWang goes deep into this theory and discussed more about it

http://docs.huihoo.com/homepage/shredderyin/wiki/ChurchNumber.html


原创粉丝点击