Reputation: 205
I was reading these notes on lambda calculus, and I am having some trouble reducing / evaluating one of the expressions at the start.
In particular the function (λf.λx.f(f(x)))(λy.y^2)(5).
How exactly do I begin this? He says the answer comes out to be 625. My mathematical intuition says that we proceed like so: (λf.λx.f(f(x)))(5^2) and he said previously that f(x) is the map
x |-> x^2
so f(f(x)) is the composition which would be f o f = (f)^2 = x^4
So further reducing our lambda expression we get
(λf.λx.x^4))(5^2)
But then we would plug 25 into x^4 which gives us 25*25*25*25 = 390,625.
(λf.(390,625))
then when we get here, I have absolutely no idea what this expression represents?
What part of the Lambda Calculus have I misunderstood? Is the way I am reducing expressions correct?
Upvotes: 1
Views: 525
Reputation:
Correct normal-order (leftmost first) beta-reduction to normal form:
(λ f. (λ x. f (f x))) (λ y. y ^ 2) 5
= (λ x. (λ y. y ^ 2) ((λ y. y ^ 2) x)) 5
= (λ x. ((λ y. y ^ 2) x) ^ 2) 5
= (λ x. (x ^ 2) ^ 2) 5
= (5 ^ 2) ^ 2
= 25 ^ 2
= 625
Numerical primitives like 2
, 5
, and ^
, though encodable, are not part of the grammar. Intuitive conventional algebraic reduction rules like exponent multiplication don't apply; only beta- and possibly eta-reduction.
Upvotes: 1
Reputation: 572
I don't know anything about lambda calculus, so feel free to downvote me into oblivion if I'm wrong :) Plus my terminology will be off, so hopefully someone experienced will answer the question. This should probably be posted to math.stackexchange.com anyways.
The
was given earlier as an example and was not meant to carry over to subsequent problems.
First of all, it looks as if you didn't copy the expression correctly. According to the PDF, it is:
Now the order of operations matters (brackets first!).
We start with:
We are providing the lambda term on the left with the argument
. This means that f is replaced by the squared function.
So now we have:
Edit:
The reason why is given as an argument to
is that we could write the whole expression as:
If we look at the first part, it's easier to see that applies to the first argument:
Upvotes: 1