Lambda Calculus
A function is generically written
The same function can be written
to apply a function, we need to substitute
for example,
In general if a lambda expression maps
This is a complete programming language, called lambda calculus. We can define variables, which can themselves be functions, and the output of functions can also be functions.
Suppose we wanted to capture the map
Notice we do substitutions from left to right. This method is called currying.
Given two things, True returns the first thing, and false returns the second thing, this encoding works, and one can check it by plugging in True and False for b in the if then. (True and False are functions here as specified in the picture)
Basically, we need to enforce types on the inputs.
Curry - Howard Co-respondence
We can write proofs in simply typed lambda calculus in the following way. suppose A,B are types, then we can think of A and B as propositions. A is true if there exists a variable
Now, the implication
Lambda Calculus Re-write Rules
Lambda calculus is based on a few key re-write rules that help simplify and manipulate lambda expressions. These include beta reduction, alpha conversion, and eta conversion.
1. Beta Reduction (Application)
Beta reduction is the most important re-write rule. It describes how a function (lambda expression) is applied to an argument, by substituting the argument for the function's parameter.
- Explanation:
is a lambda expression (a function) where is the parameter and is the body of the function. is the argument applied to the function. - The result is the body
with replaced by , denoted as (substituting with in ).
Example:
2. Alpha Conversion (Renaming Variables)
Alpha conversion allows renaming of bound variables (variables within the scope of a lambda) to avoid conflicts. It is used to change the name of the bound variable in a lambda expression.
- Explanation:
- You can rename the bound variable
to another variable as long as is not already used in .
- You can rename the bound variable
Example:
3. Eta Conversion (Simplifying Functions)
Eta conversion simplifies functions that return another function. It allows you to remove unnecessary function abstractions.
- Explanation:
- If a function
applies to and does not appear free in , the function can be simplified to .
- If a function
Example: