[Programming Languages And Lambda calculi] Chapter 4 Lambda Calculus / Lambda Expression 4.1 Function Currying in Calculus

Chapter 4 Lambda Calculus / Lambda Expression

The B language is too restrictive and not very useful for any practical programming tasks. Because it has no abstract ability, that is, it has no ability to define functions, which makes it far inferior to the actual programming language.

In this chapter, we will learn a language called Lambda calculus , which was invented by Church. Although the grammar and convention of Lambda calculus are very small, it is closely related to very useful languages ​​such as Scheme and ML. In these languages, functions not only manipulate Booleans, integers, and pairs, but also other functions. In other words, functions are values. For example, the map function uses a function and a list of elements, and applies the function to each element in the list. Similarly, the derivation function applies a function to real numbers and returns a new function that implements its derivation.

In Lambda calculus, the only type of value is a function, but we will see how other types of values ​​(including Boolean values, integers, and pairs) are defined by functions.

Functions in Lambda Calculus

The rules of Lambda calculus provide a simple and formal way to implement functions for applications and also serve as input and output for other functions. The rules of such functions make Lambda calculus concentrate on the specification from parameters to results, and ignore the naming of functions, the domain of the function, and the scope of the function. For example, when a mathematician specifies an identity function in a certain set:
∀ x ∈ A, f (x) = x \forall x \in A,f(x) = xxA,f(x)=x
或是:
f : { A ⟶ A x ↦ x f:\left\{ \begin{aligned} A &\longrightarrow A \\ x &\mapsto x \\ \end{aligned} \right. f:{ AxAx
In the rules of Lambda calculus, we write:
(λ x. X) (\lambda xx)( λ x . x )
The correct statement of this expression is: "If the parameter is called x, the output of the function is x." In other words, the function outputs the input value it receives.

If you want to write down the application of the function f to the parameter a, the Lambda calculus uses the original mathematical syntax to take the modulo where the parentheses are placed.
(f a) (f \ a)( f a ) For 
example, the expression representing the application of the identity function to a is:
((λ x. x) a) ((\lambda xx)\ a)( ( λ x . x ) a ) 
Another possible parameter of the identity function is the identity function itself:
((λ x. x) (λ x. x)) ((\lambda xx)\ (\lambda xx))( ( λ x . x ) ( λ x . x ) ) The 
following expression indicates that a function receives one parameter, ignores it, and returns the identity function:
(λ y. (λ x. x)) (\lambda y.(\ lambda xx))( λ y . ( λ x . x ) ) The
following expression means that a function receives one parameter and returns a function. The returned function ignores its own parameters and returns the parameters of the original function:
(λ y. (λ x. y )) (\lambda y.(\lambda xy))( λ y . ( λ x . y ) )
Lambda calculus only supports single-parameter functions, but the last example demonstrates how a function can effectively receive two parameters, x and y, first process the first parameter, and then return the other Function and get the second parameter. This technique is calledcurrying.

In traditional mathematical representation, f(a) can be simplified by "taking the expression as the definition of f and replacing the formal parameters of f with a". For example, given f(x) = x, f(a) can be simplified to a. The simplification of Lambda calculus is similar: ((λx.x) a) can be simplified to a, the method is also to replace the function body part (behind the dot) with the actual parameters (the part before the dot).

Here are some examples:
KaTeX parse error: No such environment: align at position 8: \begin{̲a̲l̲i̲g̲n̲}̲ &((\lambda xx…

Guess you like

Origin blog.csdn.net/qq_35714301/article/details/113804433