This will be a quick introduction to the lambda calculus syntax, alpha (α) equivalence and beta (β) reduction.

What does a lambda look like?

I am going to use the identity function as an example for the simplicity it provides. This can be expressed as a lambda function with the notation λx.x. It is a function that when given an argument outputs that argument as its return value. You can also have multiple arguments with a lambda like λxy.xy.

A lambda is comprised of a head, argument and body.

diagram illustrating the parts of a lambda function - head(argument).body
diagram illustrating the parts of a lambda function - head(argument).body

The head of the lambda begins with the lambda character (λ), which indicates the start of a function. This is immediately followed by the argument that is separated from the body of the function by a dot/period (.).

Applying a lambda

The identity function can be applied to any argument passed to it. Here it is when applied to the digit two (2).

The steps to arrive at the final answer can be further broken down and illustrated.

the application of the identity lambda against the digit 2 as a diagram
the application of the identity lambda against the digit 2 as a diagram

We have just completed the simplest of beta reductions. This is the process of reducing all expressions to their normal form or smallest unit - to the point where you can do no more reduction. In this case we can reduce all the way to a single value, but this is not always the case as you’ll see further on.

In a programming language you may already know

In JavaScript this would be written as

and in PHP

and Python

and Ruby

and Haskell

Some more simple examples

Free variables

A free variable is one that is not mentioned in the head of a lambda - y is a free variable in the expression λx.xy. This does not prevent the expression from being reduced though.

The opposite of a free variable is a bound variable - it is bound to an argument specified in the head of the lambda.

Higher order

The lambda calculus can also encode higher order operations - that is lambdas that can accept lambdas as arguments and/or return lambdas. To make it easier to keep track of this process I will use “notes to self” inside square brackets ([]) that illustrate the value an argument was substituted with.

For reference here is the identity example again with the additional substitution notation.

Now for the first higher order lambda expression - the identity lambda applied to itself.

This is a good time to mention that the lambda calculus is left associative during beta reduction. We start with the leftmost expression and apply the left most argument to it. In the following example I’ve added an extra initial step to wrap the first reduction inside parentheses (()) so as to make this association explicit

α-equivalence

This refers to two different expressions that when given the same argument would return the same result. They are functionally equivalent to each other and you could substitute one for the other.

conversely, due to different ordering in the body the following is not equivalent.

Importantly, this property gives you the opportunity to rename variables where there may be clashes in an expression.

Where there are free variables in the expression it is not possible to establish equivalence, but you can still rename those that are bound (x in the following example).

If you wanted to avoid a variable name collision in the aforementioned expression you could rename x.

Multiple arguments and currying

The same basic reduction rules apply when dealing with lambdas that have multiple arguments, but there is a little additional rule. Each argument is actually a lambda and they are nested - this is currying.

is actually more like the following when considered in its most explicit form.

The more arguments you have the more nested lambdas you’ll have.

This is to say that the first notation is shorthand for each argument being the application of a lambda function.

Now for a multi-argument reduction

and again for a higher order example.

Worth noting here that the z is not used in the lambda body so the value 1 simply evaporates (dropped from the expression/result).

It is, of course, possible to work through more complex problems like the following expression - remembering we start with the left most expression first.

So after all that we land up with the identity function at the end.

Combinators

A lambda term with no free variables (all variables are bound), which serves to combine values.

As opposed to those that contain free variables - in this case y.

There is a very famous combinator called the Y combinator that looks like this.

Divergence

Not all expressions can be considered to converge because they lead to replication and the beta reduction process never ends. Consider the Ω (Omega) divergence below.

Some exercises for you

The worked answers to these exercises are available after the summary.

Combinator exercises

For each of the following determine if they are combinators or not.

  1. λq.qq
  2. λts.stp
  3. λz.fg
  4. λxy.yx
  5. λrgf.f (ri) g

α-equivalence exercises

Are these terms α-equivalent?

  1. λz.z and λa.a
  2. λbq.qb and λzt.zt
  3. λz.zg and λp.pg
  4. λb.λa.a and λa.λb.b
  5. λd.λxy.y and λf.λyx.x

β-reduction exercises

Reduce the following to their β-normal forms. It will be a lot easier if you use a pen and paper or even a text document in your editor to work through these.

  1. (λa.ab) (λq.q)
  2. (λf.(λg.fgg)) (λn.n) m
  3. (λs.(λp.(sp) s)) (λt.q)
  4. (λb.(λm.(bb) m) (λq.vq)) (λx.(λe.e))
  5. λf.((λx.f (x x)) (λx.f (x x)))
  6. (λq.qg) (λp.(λs.ss)) (λt.t) z
  7. (λfg.gf) (λba.a) (λz.z) pq
  8. (λpt.pt) (λx.xx) (λf.ff)
  9. (λpt.t) g (λq.(λv.vv)) o (λu.uu) (λpf.fz)

Summary

Lambda expressions are:

Answers

Combinator answers

  1. Yes
  2. No (p is free)
  3. No (fg are free)
  4. Yes
  5. No (i is free)

α-equivalence answers

  1. Yes
  2. No
  3. No
  4. Yes
  5. Yes

β-reduction answers

1

2

3

4

5

6

7

8

9