Skip to main content

λ calculus: applying a function

Japanese version

In λ calculus, a function only has one argument. An argument is a parameter of function, or an input of function. We can talk about more than one argument case later.

When the argument value is determined -- this means when the input is determined --, put the value to right to the λ expression (= function), and apply the function to the value. In case of the vending machine, someone just put the money into it. The machine waits the money to be feed, once some money is in, it computes the output. Many of the functions are also similar. They wait an argument. When an argument is determined, the computation starts.

The word ``apply'' seems a big word. I think this ``apply'' is not so far from ``assign'' the value. However, we can assign a non-value, or we can assign another function, so it is better to use to be the word ``apply.''

Let's see an example of applying a function.

f(x) := 2x
λ x. 2 x

These two functions are the same. I wrote them: the first one is the conventional way and the second one is a lambda expression. Let's assign x to 3, or apply the lambda expression to 3.

f(3) := 2 x
= 2 * 3
= 6

(λ x. 2 x) 3
= (λ 3. 2 3)
= 2 * 3
= 6

We got the same result. Both functions are a function which multiply the input by two. So, we input three, then got six.

In lambda calculus, a function can take only one argument. Then how can we handle a two argument function? For example, f(x,y) := x-y. This case, we can make a function which take a function with one argument, and the function returns a new function. This is such a function.

λ y. (λ x. x - y)

First, let's see the (λ x. x - y) part, this is a one argument function, the input is x, and the output is x - y. We can apply this to x = 3, the result is

(λ x. x - y) 3
= 3 - y.

But this is a function with an argument y.

λ y. 3 - y

Assume y = 1,

(λ y. 3 - y) 1
= 3 - 1
= 2

Good. We have computed 3 - 2. As you see, one applying determines one argument, therefore we can repeat this as many as we wish, then, we can handle any number of arguments.

The first function (λ x. x - y)'s result is a function. This might puzzled some people, but this is a powerful tool.

Sirius Cybernetics corporation sells a vending machine, which sells other vending machines. Sirius Cybernetics corp.'s advertisement is ``General purpose vending machine gensym3141! This machine makes you the top manager of your Konzern. You can sell anything.'' Of course Marvin said, ``That's not possible. Even an earthmen knows it is not possible. How depressed.'' But in lambda calculus, these function which returns a function is also a function. A vending machine positively can sell a computer or a car. Then nothing wrong if a vending machine sells a vending machine. If a function gets a function as an input and its output is a function, still it is a function since it gets an input and puts an output, that is a λ.

Comments

spectrumgomas said…
"if a vending machine sells a vending machine" is a great analogy. Thanks from Spain.

Popular posts from this blog

Why parallelogram area is |ad-bc|?

Here is my question. The area of parallelogram is the difference of these two rectangles (red rectangle - blue rectangle). This is not intuitive for me. If you also think it is not so intuitive, you might interested in my slides. I try to explain this for hight school students. Slides:  A bit intuitive (for me) explanation of area of parallelogram  (to my site, external link) . 

Geometric Multiplicity: eignvectors (2)

If eigenvectors of a matrix A are independent, it is a happy property. Because the matrix A can be diagonalized with a matrix S that column vectors are eigenvectors of A . For example, Why this is a happy property of A? Because I can find A's power easily. A^{10} is not a big deal. Because Λ is a diagonal matrix and power of a diagonal matrix is quite simple. A^{10} = SΛ^{10} S^{-1} Then, why if I want to compute power of A ? That is the same reason to find eigenvectors. Eigenvectors are a basis of a matrix. A matrix can be represented by a single scalar. I repeat this again. This is the happy point, a matrix becomes a scalar. What can be simpler than a scalar value. But, this is only possible when the matrix S's columns are independent. Because S^{-1} must be exist. Now I come back to my first question. Is the λ's multiplicity related with the number of eigenvectors? This time I found this has the name. Geometric multiplicity (GM): the number of in...

Gauss's quote for positive, negative, and imaginary number

Recently I watched the following great videos about imaginary numbers by Welch Labs. https://youtu.be/T647CGsuOVU?list=PLiaHhY2iBX9g6KIvZ_703G3KJXapKkNaF I like this article about naming of math by Kalid Azad. https://betterexplained.com/articles/learning-tip-idea-name/ Both articles mentioned about Gauss, who suggested to use other names of positive, negative, and imaginary numbers. Gauss wrote these names are wrong and that is one of the reason people didn't get why negative times negative is positive, or, pure positive imaginary times pure positive imaginary is negative real number. I made a few videos about explaining why -1 * -1 = +1, too. Explanation: why -1 * -1 = +1 by pattern https://youtu.be/uD7JRdAzKP8 Explanation: why -1 * -1 = +1 by climbing a mountain https://youtu.be/uD7JRdAzKP8 But actually Gauss's insight is much powerful. The original is in the Gauß, Werke, Bd. 2, S. 178 . Hätte man +1, -1, √-1) nicht positiv, negative, imaginäre (oder gar um...