Theory of Lambda Calculi

Multiple Steps and Normalization


Learning Objectives

  • You understand multi-step reduction as the reflexive transitive closure of single-step reduction.
  • You can distinguish between weak and strong β-reduction and their normal forms.
  • You understand β-equivalence and know that normalization is undecidable in general.
  • You can implement strong β-reduction and parse lambda calculus terms.

Introduction

In the last chapter, our weak 𝛽-reduction couldn’t reduce application subterms in the argument position. For example, the following terms are in weak-head normal form.

𝑓𝑦𝑓((𝜆𝑥.𝑥)𝑦)𝑓((𝜆𝑥.𝑦)𝑥)

In this chapter we will study a stronger notion of 𝛽-reduction which allows reducing every possible subterm. This makes the previous three terms have the same normal form according to the stronger 𝛽-reduction.

Before doing that, let’s explore the concept

Multiple Small Steps

Now that we have a single-step weak/call-by-name reduction, we can extend that to the notion of a multi-step reduction, which let’s us do zero or more reductions in one go. Multi-step reduction is denoted with and is defined as the reflexive transitive closure of .

DefinitionMulti-Step Reduction ()Let be a reduction from Term to Term. If 𝑡 can reach 𝑡 by anynumber of the single-step reductions (including zero), we write𝑡𝑡. is called the multi-step reduction and is defined inductively asfollows:1.Multi-step is reflexive: 𝑡𝑡 for any 𝑡.2.Multi-step is transitive: if 𝑡1𝑡2 and 𝑡2𝑡3 then 𝑡1𝑡3for any 𝑡1,𝑡2,𝑡3.
Loading Exercise...

Termination of Evaluation

Consider the following term.

(𝜆𝑥.𝑥𝑥)(𝜆𝑥.𝑥𝑥)

As 𝜆𝑥.𝑥𝑥 is a value we cannot apply the App1 rule, but we can apply the AppAbs rule to reduce the term to

[𝑥𝜆𝑥.𝑥𝑥](𝑥𝑥)=(𝜆𝑥.𝑥𝑥)(𝜆𝑥.𝑥𝑥)

Which means it reduces to itself!

This term is called the Omega-combinator (Ω=(𝜆𝑥.𝑥𝑥)(𝜆𝑥.𝑥𝑥)) and is an example of a term which has no normal form. Trying to multi-step a term with no normal form in the Rust implementation results in the computation diverging unless we constrain it using a maximum number of steps. Unfortunately this means that the Rust implementation is somewhat faulty as the multistep function is not total, and hence not a mathematical function.

In the next part where we will study typed lambda calculi we will get rid of this issue at the cost of turning our language effectively back to a non Turing-complete calculator. Having a Turing-complete/computationally powerful language comes with the cost of losing normalization of all terms.

Loading Exercise...

Loading Exercise...

Normalization

Our definition of weak 𝛽-reduction focused on reducing the left subterm in an application but left some things to be desired. For instance, if the right subterm is reducible, we should reduce it. This leads to a smaller set of normal forms which are value-like terms.

Reminder: Weak Beta-Reduction Rules
AppAbs(𝜆𝑥.𝑡1)𝑡2[𝑥𝑡2]𝑡1𝑡1𝑡1App1𝑡1𝑡2𝑡1𝑡2

To get to the full “strong” 𝛽-reduction, we add two more rules. We reduce the term in the argument position of application:

𝑡2𝑡2App2𝑡1𝑡2𝑡1𝑡2

And we reduce terms inside abstractions.

𝑡1𝑡1Abs𝜆𝑥.𝑡1𝜆𝑥.𝑡1 DefinitionNormal FormA term in lambda calculus is said to be in normal form if it cannottake further 𝛽-reduction steps. ExampleEach of the following lambda terms reduces in zero or more steps to thecorresponding normal form:(𝜆𝑥.𝑥)𝑦𝑦(𝜆𝑥.𝜆𝑦.𝑥)𝑎𝑏𝑎(𝜆𝑥.𝑥𝑥)(𝜆𝑦.𝑦)𝜆𝑦.𝑦(𝜆𝑓.𝑓(𝜆𝑥.𝑥𝑦))(𝜆𝑔.𝑔𝑥)𝑥𝑦

From now on, when referring to 𝛽-reduction, we mean the strong variant with the four rules: AppAbs, App1, App2 and Abs.

Confluence

As we learned in part 1: Simplification and Normalization, rewriting systems (like 𝛽-reduction) can have the useful property of being confluent. As a reminder, this is the general definition of confluence of a relation.

DefinitionConfluenceLet 𝐴 be a set. A relation 𝑅 on 𝐴 is confluent if given any twodistinct elements 𝑠1,𝑠2𝐴 with a common ancestor, there exists acommon descendant of 𝑠1 and 𝑠2 in 𝐴.

It’s recommended to read through part 1: Simplification and Normalization now to refresh your memory on the subject.

We are naturally interested in the question: is 𝛽-reduction confluent? That is, given any two distinct terms 𝑡1,𝑡2 with a common ancestor (a term 𝑡 such that 𝑡𝑡1 and 𝑡𝑡2), is there a common descendant of 𝑡1 and 𝑡2?

Let’s demonstrate this diagrammatically by looking at the different 𝛽-reductions of (𝜆𝑥.𝑥)((𝜆𝑦.𝑦)𝑧)

AppAbsApp2AppAbsAppAbs(𝜆𝑥.𝑥)((𝜆𝑦.𝑦)𝑧)(𝜆𝑦.𝑦)𝑧(𝜆𝑥.𝑥)𝑧𝑧

As it seems, the answer to the question is in fact yes, 𝛽-reduction is confluent. This statement is also called the Church-Rosser theorem, for which you can find a proof in chapter 4 of Selinger: Lecture Notes on the Lambda Calculus. Although we won’t prove it, let’s write it down into a nice box.

TheoremChurch-Rosser𝛽-reduction of lambda calculus is confluent. Stated more precisely:let 𝑡,𝑡1,𝑡2 be lambda terms such that 𝑡𝑡1 and 𝑡𝑡2. Thereexists a term 𝑢 such that 𝑡1𝑢 and 𝑡2𝑢.

As we learned in part 1, a confluent relation is functional if the relation is also weakly normalizing (i.e. every term has a normal form). But as we know Ω doesn’t have a normal form, so 𝛽-reduction is not weakly normalizing.

However, confluence implies that normal forms are unique when they exists, which gets us to the next subject: 𝛽-equivalence.

Loading Exercise...

Loading Exercise...

Loading Exercise...

When Are Lambda Terms Equal?

When two terms have the same normal form (according to 𝛽-reduction), we call them 𝛽-equivalent. 𝛽-equivalent terms behave in the same way and are practically indistinguishable from their 𝛽-equivalent counterparts. 𝛽-equivalence is a weaker requirement than 𝛼-equivalence but still captures the idea of two terms being the same

The definition of 𝛽-equivalence is simply the reflexive symmetric transitive closure of 𝛽-reduction.

Definition𝛽-equivalence (=𝛽)𝛽-equivalence denoted =𝛽 is the smallest relation with the followingproperties:1.It includes 𝛽-reduction: if 𝑡𝑡, then 𝑡=𝛽𝑡 for any terms 𝑡,𝑡.2.It is reflexive: 𝑡=𝛽𝑡 for any term 𝑡.3.It is symmetric: if 𝑡1=𝛽𝑡2 then 𝑡2=𝛽𝑡1 for any terms 𝑡1,𝑡2.4.It is transitivite: if 𝑡1=𝛽𝑡2 and 𝑡2=𝛽𝑡3, then 𝑡1=𝛽𝑡3 for anyterms 𝑡1,𝑡2,𝑡3.

To test if two normalizing terms are 𝛽-equivalent, it suffices to compare their normal forms.

As it’s undecidable whether a term 𝑡 normalizes or not (for general 𝑡), 𝛽-equivalence is an undecidable relation. However, we are usually not interested in 𝛽-equivalence between non-normalizing terms like Ω.

Let’s look at some examples next.

ExampleThe following statements are true.(𝜆𝑥.𝑥)𝑦=𝛽𝑦(𝜆𝑥.𝑥)𝑦=𝛽(𝜆𝑥.𝑦)𝑥(𝜆𝑥.𝜆𝑦.𝑥)𝑎𝑏=𝛽𝑎(𝜆𝑥.𝑥)((𝜆𝑧.𝑧)𝑤)=𝛽𝑤(𝜆𝑥.𝜆𝑦.𝑥)𝑎𝑏=𝛽(𝜆𝑦.𝑎)𝑏=𝛽(𝜆𝑦.𝑎)((𝜆𝑥.𝑥)𝑏)(𝜆𝑥.𝑓𝑥)𝑓=𝛽𝑓𝑥𝜆𝑥.𝑓𝑥𝛽𝑓

The last statement is an example of how 𝛽-equivalence fails to capture the notion of extensional equality of functions. To learn more about extensional versus intensional equality, read the first chapter in Selinger: Lecture Notes on the Lambda Calculus.

Loading Exercise...

Loading Exercise...

Loading Exercise...

Interaction and Parsing

To make interacting with the language more convenient, a parser implemented in nom is provided in the following code snippet.

No files opened Select a file to edit

Loading Exercise...

Loading Exercise...