Day 4 - Lambda Calculus

is that the half-life logo?
29 Apr 2025

Introduced by Alonzo Church in the 1930s, λ-Calculus is a formal system in mathematical logic that expresses computation based on function abstraction and application based on variable binding and substitution.

For example, a function in standard mathematical notation would be written as:

f(x)=Mf(x) = M

In Lambda Notation, this is expressed using abstraction as:

λx. M\lambda x.\ M

This is defined as an anonymous function that takes one input xx and returns the result of expression MM.

To apply a lambda function to an argument NN, we write:

(λx. M)N(\lambda x.\ M)N

This expression is reduced using beta-reduction (β-reduction), which substitutes the input NN for every instance of xx in MM:

M[x:=N]M[x:=N]

Lets use a square function as an example:

(λx. x2) 2βx2[x:=2]=22=4(\lambda x.\ x^{2})\ 2 \longrightarrow_\beta x^2[x := 2] = 2^2 = 4

Currying

Now what if we want to take in two arguments? The Lambda Notation would not allow this, as it only allows a single argument. Instead, Lambda Functions are first-class, meaning they themselves could be passed in as variables. So in Lambda Calculus, functions and values are essentially equivalent, which is kinda trippy. We can use a method called currying to essentially do this.

Lets use the sum of two squares as an example. The lambda statement can be written as such:

(λx. λy. x2+y2) 4 5(\lambda x.\ \lambda y.\ x^2 + y^2)\ 4\ 5

Using β-reduction, we can first take in the variable x=4x = 4, yielding a new one argument function:

(λx. λy. x2+y2) 4 5β(λy. 42+y2) 5(\lambda x.\ \lambda y.\ x^{2} + y^{2})\ 4\ 5 \longrightarrow_{\beta} (\lambda y.\ 4^{2} + y^{2})\ 5

And then we substitute y=5y = 5.

(λy. 42+y2) 5β42+52=16+25=41(\lambda y.\ 4^2 + y^2)\ 5 \longrightarrow_\beta 4^2 + 5^2 = 16 + 25 = 41