Free and bounded variables


In Lambda Calculus, variables can be free or bound, which is fundamental for understanding how functions work. Let’s break down what that means.

Definition of Free Variables

A variable is free if it’s not restricted by any function (λ-abstraction). In simpler terms, a free variable is like an independent traveler — it’s not tied to any specific function.

Formal Definition

The set of free variables of a λ-term M, denoted as FV(M), is defined inductively:

  1. For a variable:

    FV(x)={x}

    This means that the variable x is free when it stands alone.

  2. For an application:

    FV(MN)=FV(M)FV(N)

    The free variables of an application are the union of the free variables in both M and N.

  3. For an abstraction:

    FV(λx.M)=FV(M){x}

    Here, the variable x becomes bound by the λ, so it’s no longer free within M.


Definition of Bound Variables

A variable is bound if it falls under the scope of a λ-abstraction. It’s like a worker bound to a contract — they can’t act freely outside the company’s rules.

Example:


Examples to Illustrate Free and Bound Variables

Example 1: Simple Abstraction

Here, x is bound inside the lambda function.


Example 2: Mixed Free and Bound Variables


Example 3: Nested Abstraction


Closed λ-terms (Combinators)

A λ-term is closed if it has no free variables. These are also known as combinators.

Definition:

FV(M)=M is closed

The set of all closed λ-terms is denoted by Λ0.

Example:


Standard Combinators

In Lambda Calculus, combinators are special λ-terms with no free variables — they’re entirely self-contained. These combinators act as the foundational "building blocks" for constructing complex expressions. The three most important combinators are:

  1. Identity Combinator (I)
  2. Constant Combinator (K)
  3. Substitution Combinator (S)

Let’s break down each of these with detailed explanations and Python equivalents.


1. Identity Combinator (I)

Definition:

I=λx.x

The Identity Combinator simply returns whatever you give it. It’s like holding up a mirror — the output is exactly the same as the input.

Step-by-Step:

Python Equivalent:

# Identity function
I = lambda x: x
print(I(42))       # Output: 42
print(I("Lambda")) # Output: Lambda

2. Constant Combinator (K)

Definition:

K=λx.λy.x

or more compactly:

K=λxy.x

The Constant Combinator takes two arguments but always returns the first one, completely ignoring the second. It’s like asking someone their favorite food, and they always answer "Pizza," no matter what else you offer.

Step-by-Step:

Python Equivalent:

# Constant combinator
K = lambda x: (lambda y: x)
print(K(10)(20))    # Output: 10
print(K("First")("Second"))  # Output: First

3. Substitution Combinator (S)

Definition:

S=λx.λy.λz.(xz)(yz)

or:

S=λxyz.(x(z))(y(z))

The Substitution Combinator is more complex. It:

  1. Applies the same argument z to both functions x and y.
  2. Then applies the result of x(z) to the result of y(z).

Think of it like:

Step-by-Step:

Python Equivalent:

# Substitution combinator
S = lambda x: (lambda y: (lambda z: x(z)(y(z))))

# Example functions:
x = lambda z: (lambda w: z + w)  # Returns a function that adds z to w
y = lambda z: z * 2              # Doubles z
z = 5

# Apply the substitution combinator
result = S(x)(y)(z)
print(result)  # Output: 15

How This Works:

  1. First Application:
    x(5) → lambda w: 5 + w
    
  2. Second Application:
    y(5) → 10
    
  3. Final Application:
    (lambda w: 5 + w)(10) → 15
    

Substitution Rules

Substitution is the process of replacing a variable in a λ-term with another term. This is fundamental for reducing and evaluating λ-expressions.

Formal Substitution Notation:

[N/x]M

Substitution Rules:

  1. Direct Substitution:

    [N/x]x=N
    • Replace x with N directly.
  2. Irrelevant Variable:

    [N/x]a=a(if ax)
    • If a is not x, leave it unchanged.
  3. Application Rule:

    [N/x](PQ)=([N/x]P)([N/x]Q)
    • Apply substitution to both P and Q.
  4. Abstraction (Bound Variable is the Same):

    [N/x](λx.P)=λx.P
    • No substitution occurs because x is bound in λx.P.
  5. Abstraction (Bound Variable is Different):

    [N/x](λy.P)=λy.[N/x]Pif yx
    • Apply substitution inside the abstraction if it doesn’t bind x.

Example: Substitution in Action

Lambda Calculus Example

Substitute y for x in:

[y/x](λx.(x+z))=λx.(x+z)

Python Equivalent:

# Bound variable: substitution doesn't affect 'x'
z = 5
func = lambda x: x + z  # x is bound inside the lambda
print(func(10))         # Output: 15

Substitution with Free Variables

Now, substituting outside the scope:

[y/x](λw.(x+w))=λw.(y+w)

Python Equivalent:

# Free variable: substitution affects 'x'
x = 7  # Free variable
expr = lambda y: x + y  # 'x' is free here
print(expr(3))          # Output: 10

Final Thoughts

  1. Identity Combinator (I): Returns its argument unchanged.

    • Python: lambda x: x
  2. Constant Combinator (K): Always returns the first argument, ignoring the second.

    • Python: lambda x: (lambda y: x)
  3. Substitution Combinator (S): Applies the same argument to two functions and combines the results.

    • Python: lambda x: (lambda y: (lambda z: x(z)(y(z))))

Key Concepts:


This foundation prepares you for more advanced topics like α-conversion (renaming variables) and β-reduction (applying functions). 🚀