Programming Languages (CS 328) Lecture on 2000-01-07 Computer Science and Engineering Sunil Pandey Indian Institute of Technology Bombay

1 Grammar for λ-Calculus

                                  T ::=  I  (1)

|   (T_{1} T_{2})  (2)
|   (λ I T)  (3)

(1) is a variable reference, (2) is an application, and (3) is an abstraction.

2 Free and Bound variables

Following is a method of finding the sets of free and bound variables of any given λ-expression using Structural Induction

• FV[[I]] = {I}

• FV[[(T_{1} T_{2})]] = FV[[T_{1}]] ∪ FV[[T_{2}]]

• FV[[(λ I T)]] = FV[[T]] \ {I}

• BV[[I]] = ∅

• BV[[(T_{1} T_{2})]] = BV[[T_{1}]] ∪ BV[[T_{2}]]

• BV[[(λ I T)]] = BV[[T]] ∪ {I}

3 Renaming

3.1 Internal Variable Capture

This happens when a variable that was earlier bound to an outer variable is now bound to an internal variable. eg. consider (λ a (λ b (a c))) now, applying a → b gives (λ b (λ b (b c)))

3.2 External Variable Capture

External variable capture occurs when a variable that was free is now bound to an external variable. eg. consider (λ a (λ b (a c))) applying the renaming a → c gives (λ c (λ b (c c)))

3.3 Meaning Preserving Substition

The last two examples have illustrated that renaming can be tricky. Any renaming done on the λ-expressions must preserve its Stoy diagram. There might be some local changes, in case the substituting λ-expression is complicated but the overall structure of the Stoy diagram must not change. Following are the rules for substitution which preserve the meaning of the λ-expression:

1. [T/I] = T

2. [T/I′] = I ; if I’≠I

3. [T/I](T_{op} T_{arg}) = ([T/I] T_{op} [T/I] T_{arg})

4. [T/I](λ I T_{body}) = (λ I T_{body})

5. [T_{new}/I_{substituant}](λ I_{bound} T_{body}) = (λ I_{bound} T_{body})

if I_{substituant} ∉ F V [T_{body}]

6. [T_{new}/I_{substituant}](λ I_{bound} T_{body}) = (λ I_{bound} [T_{new}/I_{substituant}]T_{body})

if I_{bound} ∉ F V [T_{new}]

7. [T_{new}/I_{substituant}](λ I_{bound} T_{body}) = (λ I_{fresh} [T_{new}/I_{substituant}][I_{fresh}/I_{bound}]T_{body}) if none of the previous conditions hold.