Loading [MathJax]/jax/output/HTML-CSS/jax.js
Close
Close Window

Programming Languages

Chapter 3 Lambda Calculus

Show Source |    | About   «  3.5. The Substitution-Based Model of Evaluation   ::   Contents   ::   3.7. Reduction Strategies  »

3.6. Beta-Reduction

3.6.1. Beta-Redexes

Now that we have rigorously defined substitution in the previous section, we can define a rule for evaluating a function application, which is the main operation for any λ calculus interpreter. This rule is called β-reduction. An expression to which the rule can be applied is called a β-redex (short for β-reduction expression). So, a β-redex is formally defined as a λ expression of a specific form, namely, an application in which the first term is a function abstraction.

For example, (λx.(xv)(z(vu))) is a β-redex because λx.(xv) is a function abstraction. On the other hand, ((λx.(xv)y)(z(vu))) is not because its first term is a function application and not a function abstraction. However, the application that comprises the first term of this expression is a β-redex. This illustrates that it is possible for expressions that may not themselves be β-redexes to contain sub-expressions that are.

A critical part of analyzing how any language evaluates function calls is to examine its semantics from the perspective of β-reduction.

3.6.2. Identifying Beta-Redexes

The following randomized problem will help you identify β-redexes. To earn credit for it, you will have to solve it correctly three times in a row.

3.6.3. Beta-Reduction is a Substitution

If we have a β-redex of the form (λx.EE), then to β-reduce this expression means to substitute E for x in E using the substitution algorithm developed in the preceding section.

In other words, to evaluate a β-redex of the form

(λx.EE)

simply means to perform the following substitution:

subst(E,x,E)

Again, this is just the algorithm that you learned in Substitution Algorithm. Note that the result of a β-reduction is what you get by first stripping off the binding occurrence of the λ-abstraction, leaving just its body, and then substituting E for x in that body.

For example, to β-reduce (λx.(xv)(z(vu))), you would first strip off λx. to get (xv) (that is, the body of the λ-abstraction), and then substitute (z(vu)) for x in that body, yielding the expression ((z(vu))v).

3.6.4. Some Beta-Reductions Require Alpha-Conversion

The following randomized problem will help you identify β-redexes and prepare to reduce them by determining whether an α-conversion is needed. To earn credit for it, you will have to solve it correctly three times in a row.

3.6.5. Performing Beta-Reductions

The following randomized problem will provide practice performing β-reductions. To earn credit for it, you will have to solve it correctly three times in a row. Be Careful: remember that, because β-reducing uses the substitution algorithm, it may be necessary to perform an α-conversion. For example, β-reducing (λx.λu.(ux)(vu)) yields λa.(a(vu)), where we must do an α-conversion to avoid capturing the free variable u.

   «  3.5. The Substitution-Based Model of Evaluation   ::   Contents   ::   3.7. Reduction Strategies  »

Close Window