What is beta reduction in lambda calculus?

Beta reduction, essentially a substitution, is a process in lambda calculus for reducing lambda expressions.

Note: Lambda calculus is a computation model that works with lambda expressions. It lays down the foundation of every functional programming language.

Understanding the notation for a lambda expression

The following is a sample lambda expression:

(λx.xy)z(\lambda x.xy )z

Every lambda expression is interpreted as the following:

(λ parameter . output) input(\lambda\ parameter\ .\ output)\ input

Beta reduction works by finding all the occurrences of the parameter (xx) in the output (xyxy) and substituting the input (zz) for that parameter (xx) in the output (xyxy) that gives us the reduced result (zyzy).

Structure of a lambda function

A lambda function (λ\lambda) takes a function as input and outputs a new function. Intuitively, it can be interpreted as the following equation:

f(x)={xy  x=z}f(x) = \{xy\ |\ x=z \}

Here, ff is the function name, xx is the function parameter, and xyxy is the expression to be solved by substituting the value of xx that is zz.

In a programming language, it can be mapped to the following function:

## Function declaration and definition
def f(x):
return xy
## Function call
f(z)

The notation for lambda expression doesn’t require function names. It represents the function with lambda (λ\lambda).

Beta reduction demonstration

Let's reduce the following lambda expression using beta reduction.

Notation and rules for beta reduction

  • Parameters λmno\lambda mno can also be written as λm.λn.λo\lambda m.\lambda n. \lambda o.
  • The substitution expression for (λm.m)(λx.xx)(\lambda m.m)(\lambda x.xx) is written as (m)(m:=λx.xx)(m)(m:= \lambda x.xx). We remove the parameter λm\lambda m and write the substitution for mm in notation (m:=λx.xx)(m:= \lambda x.xx).
  • (m)(m:=λx.xx)(m)(m:=λx.xx) is evaluated as λx.xxλx.xx. We substituted the value of mm in place of all the occurrences of mm in the output (a single occurrence of mm in the output in this case).

The beta reduction simplifies the expression by substituting input into the function. The reduction process for the above lambda expression is demonstrated in the following slide.

We have a lambda function with three parameters, and three inputs/function arguments
1 of 25

Alpha conversion

Alpha conversion is just about changing the names of the same name variables while applying multiple lambda expressions with the same variable name. For example, (λy.y)(λyz.y)(λy.y)(λyz.y) changes to (λy.yy)(λy1z.y1)λy.yy)(λy_{1}z.y_1). We perform this step before beta reduction if the lambda expressions have the same name and cause name conflict.

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved