Church number to add

I am stuck in the next step. It will be great if someone can help me:

2 = λfx.f(f x)
3 = λfx.f(f(f x))
ADD = λm n f x. m f (n f x)

My steps:

   (λm n f x. m f (n f x)) (λf x.f(f(f x))) (λf x.f(f x))
-> ((λn f x. (λf x.f(f(f x))) f (n f x))) (λf x.f(f x))
-> ((λf x. (λf' x'.f'(f'(f' x'))) f ((λf" x".f"(f" x")) f x)

Is the bracket perfect? I really confuse myself with wildcards and brackets. Is there a formal, simpler way to solve such problems?

+3
source share
3 answers

Try Alligator Eggs!

Here are my steps I got with alligators:

ADD 2 3
-> (λm n f x. m f (n f x)) (λf x.f(f(f x))) (λf x.f(f x))
->   (λn f x. (λf x.f(f(f x))) f (n f x))   (λf x.f(f x))
->     (λf x. (λf x.f(f(f x))) f ((λf x.f(f x)) f x)) 
->     (λf x.   (λx.f(f(f x)))   ((λf x.f(f x)) f x)) 
->     (λf x.       f(f(ff x.f(f x)) f x)))))
->     (λf x.       f(f(fx.f(f x)) x)))))
->     (λf x.       f(f(f     (f(f x))  )))))
+8
source

My advice, based on my limited but recent experience:

:

:

λfx. f (f x) => λgx. g (g x)

(λf x. f x) b => λx. b x

Eta "" , .

λx.f x => f

  1. -, , . f s, . - "

  2. , ! , . ( ). , .

  3. -, . by def, . - :

    add two three 
    (λm n f x. m f (n f x)) two three | by def
    

, , :

two   = λfx. f (f x)
three = λfx. f (f (f x))
add   = λmnfx. m f (n f x)

0  | add two three 
1  | (λm n f x. m f (n f x)) two three           | by def
2  | (λn f x. two f (n f x)) three               | beta
3  | (λf x. two f (three f x))                   | beta
4  | (λf x. two f ((λfx. f (f (f x))) f x))      | by def
5  | (λf x. two f ((λgy. g (g (g y))) f x))      | alpha
6  | (λf x. two f ((λy. f (f (f y))) x))         | beta
7  | (λf x. two f (f (f (f x))))                 | beta
8  | (λf x. (λfx. f (f x)) f (f (f (f x))))      | by def
9  | (λf x. (λgy. g (g y)) f (f (f (f x))))      | alpha
10 | (λf x. (λy. f (f y)) (f (f (f x))))         | beta
11 | (λf x. (λy. f (f (f (f (f x))))))           | beta
+1

, ?

-, . PLT Redex ; , , , .

, .

0
source

Source: https://habr.com/ru/post/1750868/


All Articles