March 26th Monday (三月 二十六日 月曜日)
2007-03-22 12:17
375 查看
(define (f x) (cons 'x x))
(define (zero f)
(lambda (x)
x))
(define (one f)
(lambda (x)
(f x)))
(define (two f)
(lambda (x)
(f (f x))))
(define (three f)
(lambda (x)
(f (f (f x)))))
(define (add-one n)
(lambda (f)
(lambda (x)
(f ((n f) x)))))
(define (add a b)
(lambda (f)
(lambda (x)
((a f) ((b f) x)))))
(define (mul a b)
(lambda (f) (lambda (x) ((a (b f)) x))))
The above list are all Church Numbers. Yes, it is so famous. At the begin of learning them, I
was confused. Having gong over the comprehension I found it is so simple. I thought I know how
to Church invent those interesting numbers. In fact, he just found it.
Let's look at "one", "two", "three", and "zero". As a matter of fact, those numbers all are
high order operators. That is to say, they like "map", "for-each", they take a function and one
parameter. What is the discrepancy between "map" and them? Look inside of them!
The "zero" is just return its argument and not call the function taken; the "one" just call its
function to its argument taken one time; the "two" call the function to its argument only two
times. From them, we know a new way to counter -- composing a function with a parameter.
((two f) 'z) => (x x . 'z)
So, the "add-one" is also simple. Firstly, let's look at the above statement how to use "two".
The "(two f)" is the key to understand "add-one", "add". The "((n f) x)" is alike the "((two f) 'z)".
Yes, it will compose "f" with "x". Finally, compose "f" again. In other words, call "f" with a result
returned from "((n f) x)". Now the "add" is easy to understand! Having composing "f" "b" times with "x",
call the result function from "(a f)" with result returned from "((b f) x)".
Now we know it is so important for Church numbers or related operators to make a correct composite
function. So, the "mul" is also not hard to understand. The "(two f)" will make a composite function
like "(f (f (f ...)))". The "(a (b f))" is mean to compose "f" "(a - 1) * (b - 1)" times. For example,
if "a" is three and "b" is two, the number of composing "f" is (3-1) * (2-1) = 2. "(f (f ...))" resulted
from "(two f)", "(p (p (p ...)" resulted from "(three p)". Having substituted "(f (f ...))" for "p". The
final composite result is "(f (f (f (f (f (f ...))))))". OK, our goal reached at.
(define (zero f)
(lambda (x)
x))
(define (one f)
(lambda (x)
(f x)))
(define (two f)
(lambda (x)
(f (f x))))
(define (three f)
(lambda (x)
(f (f (f x)))))
(define (add-one n)
(lambda (f)
(lambda (x)
(f ((n f) x)))))
(define (add a b)
(lambda (f)
(lambda (x)
((a f) ((b f) x)))))
(define (mul a b)
(lambda (f) (lambda (x) ((a (b f)) x))))
The above list are all Church Numbers. Yes, it is so famous. At the begin of learning them, I
was confused. Having gong over the comprehension I found it is so simple. I thought I know how
to Church invent those interesting numbers. In fact, he just found it.
Let's look at "one", "two", "three", and "zero". As a matter of fact, those numbers all are
high order operators. That is to say, they like "map", "for-each", they take a function and one
parameter. What is the discrepancy between "map" and them? Look inside of them!
The "zero" is just return its argument and not call the function taken; the "one" just call its
function to its argument taken one time; the "two" call the function to its argument only two
times. From them, we know a new way to counter -- composing a function with a parameter.
((two f) 'z) => (x x . 'z)
So, the "add-one" is also simple. Firstly, let's look at the above statement how to use "two".
The "(two f)" is the key to understand "add-one", "add". The "((n f) x)" is alike the "((two f) 'z)".
Yes, it will compose "f" with "x". Finally, compose "f" again. In other words, call "f" with a result
returned from "((n f) x)". Now the "add" is easy to understand! Having composing "f" "b" times with "x",
call the result function from "(a f)" with result returned from "((b f) x)".
Now we know it is so important for Church numbers or related operators to make a correct composite
function. So, the "mul" is also not hard to understand. The "(two f)" will make a composite function
like "(f (f (f ...)))". The "(a (b f))" is mean to compose "f" "(a - 1) * (b - 1)" times. For example,
if "a" is three and "b" is two, the number of composing "f" is (3-1) * (2-1) = 2. "(f (f ...))" resulted
from "(two f)", "(p (p (p ...)" resulted from "(three p)". Having substituted "(f (f ...))" for "p". The
final composite result is "(f (f (f (f (f (f ...))))))". OK, our goal reached at.
相关文章推荐
- 2008 March 26th Wednesday (三月 二十六日 水曜日)
- 2009 March 26th Thursday (三月 二十六日 木曜日)
- March 19th Monday (三月 十九日 月曜日)
- 2008 March 17th Monday (三月 十七日 月曜日)
- 2009 March 30th Monday (三月 三十日 月曜日)
- 2008 March 31th Monday (三月 三十一日 月曜日)
- 2009 March 23th Monday (三月 二十三日 月曜日)
- March 12th Monday (三月 十二日 月曜日)
- 2008 May 26th Monday (五月 二十六日 月曜日)
- 2009 March 9th Monday (三月 九日 月曜日)
- Februray 26th Monday (一月 二十六日 月曜日)
- 2008 March 10th Monday (三月 十日 月曜日)
- 2008 March 24th Monday (三月 二十四日 月曜日)
- 2009 March 2nd Monday (三月 二日 月曜日)
- 2009 March 16th Monday (三月 十六日 月曜日)
- March 5th Monday (三月 五日 月曜日)
- 2008 March 3td Monday (三月 三日 月曜日)
- Aprial 26th Thursday (四月 二十六日 木曜日)
- July 23th Monday (七月 二十三日 月曜日)
- October 22th Monday (十月 二十二日 月曜日)