views:

115

answers:

2

All,

Below is the lambda expression which I am finding difficult to reduce i.e. I am not able to understand how to go about this problem.

(λm λn λa λb . m (n a b) b) (λ f x. x) (λ f x. f x)

This is what I tried, but I am stuck:

Considering the above expression as : (λm.E) M equates to
E= (λn λa λb. m (n a b) b)
M = (λf x. x)(λ f x. f x)

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

Considering the above expression as (λn. E)M equates to
E = (λa λb. (λ f x. x) (λ f x. f x) (n a b) b)
M = ??

.. and I am lost!!

Can anyone please help me understand that, for ANY lambda calculus expression, what should be the steps to perform reduction?

+2  A: 

Where you're going wrong is that in the first step, you can't have

M = (λf x. x)(λ f x. f x)   

because the original expression doesn't include that application expression. To make this clear, you can put in the implicit parentheses following the rule that application is left-associative (using [ and ] for the new parens and putting in some missing "."s):

[ (λm . λn . λa . λb . m (n a b) b) (λ f x. x) ] (λ f x. f x)

From here, find an expression of the form (λv.E) M some where inside and reduce it by replacing v with M in E. Be careful that it really is an application of the function to M: it isn't if you have something like N (λv.E) M, since then N is applied to the function and M as two arguments.

If you're still stuck, try putting in the parens for each lambda also - basically a new "(" after each ".", and a matching ")" that goes as far to the right as possible while still matching the new "(". As an example, I've done one here (using [ and ] to make them stand out):

( (λm . λn . λa . [λb . m (n a b) b]) (λ f x. x) ) (λ f x. f x)
RD1
+3  A: 

You can follow the following steps to reduce lambda expressions:

  1. Fully parenthesize the expression to avoid mistakes and make it more obvious where function application takes place.
  2. Find a function application, i.e. find an occurrence of the pattern (λX. e1) e2 where X can be any valid identifier and e1 and e2 can be any valid expressions.
  3. Apply the function by replacing (λx. e1) e2 with e1' where e1' is the result of replacing each free occurrence of x in e1 with e2.
  4. Repeat 2 and 3 until the pattern no longer occurs. Note that this can lead to an infinite loop for non-normalizing expressions, so you should stop after 1000 iterations or so ;-)

So for your example we start with the expression

((λm. (λn. (λa. (λb. (m ((n a) b)) b)))) (λf. (λx. x))) (λf. (λx. (f x)))

Here the subexpression (λm. (λn. (λa. (λb. (m ((n a) b)) b)))) (λf. (λx. x)) fits our pattern with X = m, e1 = (λn. (λa. (λb. (m ((n a) b)) b)))) and e2 = (λf. (λx. x)). So after substitution we get (λn. (λa. (λb. ((λf. (λx. x)) ((n a) b)) b))), which makes our whole expression:

(λn. (λa. (λb. ((λf. (λx. x)) ((n a) b)) b))) (λf. (λx. (f x)))

Now we can apply the pattern to the whole expression with X = n, e1 = (λa. (λb. ((λf. (λx. x)) ((n a) b)) b)) and e2 = (λf. (λx. (f x))). So after substituting we get:

(λa. (λb. ((λf. (λx. x)) (((λf. (λx. (f x))) a) b)) b))

Now ((λf. (λx. (f x))) a) fits our pattern and becomes (λx. (a x)), which leads to:

(λa. (λb. ((λf. (λx. x)) ((λx. (a x)) b)) b))

This time we can apply the pattern to ((λx. (a x)) b), which reduces to (a b), leading to:

(λa. (λb. ((λf. (λx. x)) (a b)) b))

Now apply the pattern to ((λf. (λx. x)) (a b)), which reduces to (λx. x) and get:

(λa. (λb. b))

Now we're done.

sepp2k
Awesome ! Thanks sepp2k
darkie15
sepp2k: I have a question, should the reduction be done from left to right or the other way round? Or does it not matter?
darkie15
You can't get different answers by reducing in a different order. However, doing it one way might keep reducing forever. To avoid this you can use "normal-order reduction" which reduces the left most first. (Or, more precisely left most and outer most - basically the one that starts the furthest to the left.) This is guaranteed to give an answer if one exists.
RD1
Thanks RD1 .. That helps. Also, I am working on the reduction ISZERO 2 where ISZERO = `λn. n (λx. FALSE) TRUE` and 2 = `λg λy. g (g y)`. I have reached the step = `( (λx. FALSE) ((λx. FALSE) TRUE) )` . Now this should return a FALSE right because there are no free `x` in the body of the outer function?
darkie15
Yes, exactly. It's a function that ignores the argument x and always returns FALSE.
RD1