The Lambda Caclulus is a form method for defining functions.

In a math class we might say `F(x)=x+2`

.

In Lambda Calculus the same function would be `λx.(+ x 2)`

.

In both cases, we can apply a function.

Applying a function in Lambda Calculus means writing

`(λx.(+ x 2))4`

This will simplify to 6.

This means the general form for a lambda expression is

(λ(variable name).(function definition))(inputs)

The inputs are not required, unless we want to evaluate the function.

**Bound Variable:** A bound Variable is a variable that is the input to a funtion.

**Free Variable:** A free variable is an unknown, it is not a function input.

Let us examine the first exercise from the homework.

(λx.((λy.(* 2 y))(+ x y))) y

Now, lets try and parse this expression.

What does the function of x look like?

The function defintion is in blue and the function input is in red. The bound variable is in bold.

(λ**x**.((λy.(* 2 y))(+ **x** y))) y

Now, lets do the same coloring to the y function only.

(λx.((λ**y**.(* 2 **y**))(+ x y))) y

Note that two of the y symbols arent bolded in either of these expressions, that must mean they are free since we can't bound them to either function.

Now, we need to evaluate the expressions. There are two options to do this normal order or applicative order.

**Normal Order:** pass by name or substitute then evaluate.

**Applicative Order:** pass by value or evaluate then substitute.

How to simplify the expression using Normal Order.

Color Coding: Blue for the function of x, red for the funtion of y, and green for free variables.

(λx.(
(λy.(
* 2 y)
)
(+ x y))) y

Step 1: Substitute the outermost function (x).

(λy.(* 2 y))(+ y y)

Step 2: Substitute the new outermost function (y).

(* 2 (+ y y))

How to simplify the expression using Applicative Order.

(λx.(
(λy.(
* 2 y)
)
(+ x y))) y

Step 1: Before Substituting the function of x, we need to evaluate its definition. This means dealing with the function of (y)

(λx.(
* 2 (+ x y)
)) y

Step 2: There is nothing more to be done with the definition or inputs to the x funtion, so we can simplify it.

(* 2 (+ y y ))

For most cases, an easy way to think about this is ** normal means outside-in** and **b applicative means inside-out**.

Now, examine the second homework problem

(λx.λy.(x y))(λz.(z y))

This expression can be clarified as well with some formatting.

Blue: Function in x

Red: Function in y

Green: Free Variables

Purple: Function in z

An underscore, _, will be used to show where a function input would be if one is not provided.

(
λx.
λy.(
x y) ___
)
(λz.(z y)___)

Step 1: For both normal and applicative order, there is only one function with inputs that can be evaluated. Start with the x funtion.

(
λy.(
λz.(z y) y) ___
)

Step 2: The function of z now has an input, so it is still the only option to simplify.

λy.(y y)___

This is really confusing because we have one free and one bound variable. A free variable can never become bound, so we need to keep these seperate. We can rename bound variables, so it is easy to clarify this.

λw.(w y)

If you can't color code your symbols, it would be better to rename before step 1.