#compsci #swe #cmpsc461

The λ -Calculus

11-1-2025 Lambda calculus -1762036267517.png|Alonzo Church|100x200
Here is a complete conversion of all the slides from your document into Markdown format.


CMPSC 461 Programming Language Concepts

λ -Calculus

Professor: Suman Saha
Penn State College of Engineering
ELECTRICAL ENGINEERING AND COMPUTER SCIENCE


The λ -Calculus

Alonzo Church, 1930s

A pure λ -term is defined inductively as follows:

Analogy in C:


The λ -Calculus Syntax

t::=x [Identifier]
λx.t [abstraction]
t1t2 [application]
(t) [grouping]


The λ -Calculus to Programming Language

This slide illustrates the relationship between foundational computation models and modern programming languages.


Anonymous Functions

In C, we write:

int id (int x) {return x}

In λ -calculus, we write:
λx.x


λ -Term Example

How to parse a λ -term

  1. λ -binding extends to the rightmost part

    • λx.xλy.yz
    • is parsed as (λx.(x(λy.(yz))))
  2. Applications are left-associative

    • t1t2t3
    • is parsed as ((t1t2)t3)

λ -Term Example

How to parse a λ -term

  1. λ -binding extends to the rightmost part

    • λx.xλy.yz is parsed as λx.(x(λy.(yz)))
  2. Applications are left-associative

    • t1t2t3 is parsed as ((t1t2)t3)

Questions:


λ -Term Example (Parsing)

This diagram shows the parse tree for (λx.(x((λy.y)z)))

graph TD
    subgraph (λx.(x ((λy.y) z)))
        Abs1(λx.t)
        Abs1 --> App1(t₁ t₂)
        App1 -- "t₁" --> Var1(x)
        App1 -- "t₂" --> App2(t₁ t₂)
        App2 -- "t₁" --> Abs2(λy.t)
        Abs2 -- "t" --> Var2(y)
        App2 -- "t₂" --> Var3(z)
    end

Number of Parameters


The λ -Calculus

A pure λ -term t is defined inductively as follows:

graph TD
    subgraph t (λ-term)
        direction TB
        t --> Var(x)
        t --> Abs(λx.t)
        Abs --> t_body(t)
        t --> App(t₁ t₂)
        App -- "t₁" --> t1(t)
        App -- "t₂" --> t2(t)
    end

We use x,y,z,... for variables
The definition above defines an infinite set, named t.


Syntax vs. Semantics


Capture-Avoiding Substitution

Example:

Analogy in C:

int f (int x) {return x} // 'x' is bound
print(x)                 // 'x' is free

Capture-Avoiding Substitution (Example)

Let's look at a different example from the slide:


Bound vs. Free Variables

Examples:


More Formally

In (λx.t), all free variables x in t are bound to λx.
A variable is free if it is not bound to any λ.

Systematically, we define free variables as follows:

Let Var(t) be all variables used in t, the bound variables in t (written BD(t)) are:
BD(t)=Var(t)FV(t)


Free Variables: Examples


Free Variables: Example


Free Variables: Example


α -Reduction (Informal)

Analogy in C:

int f (int x) {return x}

Is same as

int f (int y) {return y}

Is same as

int f (int z) {return z}

α -Reduction (formal)

λx.t=λy.(t{y/x}) when yFV(t)
where t{y/x} is capture-avoiding substitution

Subtle point: what if y is captured in t? Use α -reduction to rename the captured y in t first.


β -Reduction (Informal)

Analogy in C:


β -Reduction

The key reduction rule in λ -calculus

(λx.t1)t2=t1{t2/x}

(Capture-avoiding substitution)


β -Reduction Example

Example 1: (λx.xx)y


β -Reduction Example

Example 1: (λx.(xx))y


β -Reduction Example

Example 2: (λf.(f(f(λx.x))))(λx.x)


β -Reduction Example

Example 3: (λx.(xx))(λx.(xx))