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

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...

Tezuka Osamu's Black Jack, "Shrinking"

I like several novel authors. My first favorite author is probably Teduka, Osamu. I still love him. The list grows by adding Hoshi, Shinichi, Agatha Christie, Hermann Hesse, and so forth. My first favorite article of Tezuka was Atom as most of the (boy's) Tezuka fans did. But my favorite is Black Jack. I try to summarize one story, it is still quite vivid in my memory. I first read this story when I was 13 - 15 years old. I re-read it at least several times since Black Jack is composed of many short episodes. The title should be "ちぢむ (SHRINKING)" or it might be "縮む(Shrinking)". (It is not so convenient to translate this to English, since English does not have a system to say the exact same word in several ways. So I just simulate it with capital letters.) Black Jack is a genius surgeon, but he does not have the license. In short, his medical activity is illegal. His skill is top level in the world, but, the fee is also out-of-law expensive. In the story ...

My solution of Google drive hang up at "One moment please"

Today I installed Google drive to my Windows 7 environment to share files with my Linux machines. After sign in, the application window said "processing," then it hanged up. There was a button "you must enable javascript". I pushed it, then "One moment please..." after 5 minutes, I exited the program tried it again. It seems some security setting causes this problem. My solution: set  https://accounts.google.com  as a trusted site. Procedure: Open the control panel Go to network and control Go to Internet Options Open Security Tab Click Trusted sites Click the "site" button copy & paste  https://accounts.google.com  to "Add this website to the zone" and click Add button Now it worked for me. But if I removed this site, it still works. That puzzled me a bit...