One of my homework is to write something about the spring festival.
Summary
The Spring Festival is here, and everyone is setting off fireworks. I see a lot of fireworks every night. After the fireworks explode, some sparks will be blown up. Some sparks are red, some green, some blue, some very bright, some not bright, and there are small sparks that explode and will explode again,and look the same as the original big fireworks after exploding again...
Huh, wait, what?
This reminds me of a very important concept:recursion. Recursion is a function that calls its own procedure. Recursion must have state transitions and underlying conditions.
Speaking of functions, I think of function-centric lambda calculus. So, how do you achieve recursion in the lambda calculus? (Because if there is no recursion, some of the functions are uncomputable, such as the Ackermann function.)
In the lambda calculus, there is no operation to define variables (i.e. you cannot define a function, that is, put the function in a defined variable), and variables can only be passed in through parameters. So what to do? I think, think, think.
Huh, yes, then pass the function as a parameter!
But how can this parameter be filled in with this function?
Can you use a function, take the function to be recursive as an argument, and then pass the function as the first parameter of the function? (The reason why only one parameter can be passed is because there is something called curryization, which probably means to simplify multi-parameter functions to the standard form of nested single-parameter functions)
So I gave it a try. The function described in the previous natural paragraph is denoted by the lambda calculus (λx.xx). What if you put this recursive function with no underlying condition (λfλx.f f x) behind it and add a parameter (λx.x)?
(λx.xx)(λfλx.f f x)(λx.x)
=(λfλx.f f x)(λfλx.f f x)(λx.x)
=(λx.(λfλx.f f x)(λfλx.f f x) x)(λx.x)
=(λfλx.f f x)(λfλx.f f x)(λx.x)
Sure enough, there is no standard form! (It means that recursion is never completed, there are no basic conditions, no wonder)
Try this example again:
(λx.xλx0.λx1.λy.yλx0.λy.x0λx0.λy.yλx0.x0λx1.λx2.λy.yλx1.λy.x1λx1.λy.yλx1.xλg.λh.h(gλf.λx2.x0λg0.λh0.h0(g0f)λu.x2λu.u)λu.x1λu.u) (λf.λx.f(fx))
Forget it, hand it over to the calculator:
=λx.λy.y
That's right! I'm so happy.
I learned a lot of new things during the New Year.
(used google translate,some problems with grammar)
Was the description about the Y combinator correct?