User:Thepigdog/Lambda Calculus conversion to let expression

Let expressions
A lambda abstraction represents a function without a name. However lambda abstractions may be composed to represent a function with a name. The lambda term,
 * $$ (\lambda f.z)\ (\lambda x.y) $$

is equivalent to defining the function $$f$$ by $$f\ x = y$$ in the expression $$z$$. The let expression is understandable as a natural language expression. It is a simple construct, but what is the mathematical representation.

The let expression represents the substitution of a variable for a value. The substitution rule describes the implications of equality as substitution. The let expression is the conjunction of two expressions, with the substitution rule from one expression applied the other.

Let definition
The let expression is the conjunction of expressions. In functional languages the let expression is also used to limit scope. In mathematics this is described by quantifiers. The let expression is a conjunction within an existential quantifier.


 * $$ (\exists x A \land B) \iff \operatorname{let} x ; A \operatorname{in} B $$

The meaning of the let expression allows the substitution to be applied to another expression. This substitution may be applied within a restricted scope, to a sub expression. The nature of the let expression is it application to a restricted scope. these definitions describe how the scope may be restricted;


 * $$ x \not \in \operatorname{FV}(C) \land x \in \operatorname{FV}(D) \to \operatorname{let} x ; A \operatorname{in} C\ D = C\ (\operatorname{let} x ; A \operatorname{in} D)$$
 * $$ x \not \in \operatorname{FV}(C) \land x \not \in \operatorname{FV}(D) \to \operatorname{let} x ; A \operatorname{in} C\ D = (\operatorname{let} x ; A \operatorname{in} C)\ D$$
 * $$ x \not \in \operatorname{FV}(C) \land x \not \in \operatorname{FV}(D) \to \operatorname{let} x ; A \operatorname{in} C\ D = C\ D$$

From this definition the following standard definition of a let expression, as used in a functional language may be derived.
 * $$ x \not \in \operatorname{FV}(y) \to (\operatorname{let} x ; x = y \operatorname{in} z) = z[x := y] = \lambda x.z\ y $$

This result is represented in a functional language in an abbreviated form, where the meaning is unambiguous;
 * $$ x \not \in \operatorname{FV}(y) \to (\operatorname{let} x = y \operatorname{in} z) = z[x := y] = \lambda x.z\ y $$

Here the variable x is implicitly recognised as both part of the equation defining x, and variable in the existential quantifier.

To derive this result, first assume,
 * $$ x \not \in \operatorname{FV}(L) $$

then
 * $$ L\ (\operatorname{let} x ; x = y \operatorname{in} z) $$
 * $$ \iff (\operatorname{let} x ; x = y \operatorname{in} L\ z) $$
 * $$ \iff x = y \land L\ z $$

Using the rule of substitution,
 * $$ \iff x = y \land(L\ z)[x :=y]$$
 * $$ \iff x = y \land(L[x :=y]\ z[x :=y])$$
 * $$ \iff x = y \land L\ z[x :=y]$$
 * $$ \implies L\ z[x :=y]$$

so for all L,
 * $$ L \operatorname{let} x ; x = y \operatorname{in} z \implies L\ z[x :=y]$$

Let $$ L\ X = X = K $$,
 * $$ (\operatorname{let} x ; x = y) = K \operatorname{in} z \implies z[x :=y] = K $$

So,
 * $$ \operatorname{let} x ; x = y \operatorname{in} z = z[x :=y]$$

But from the mathematical interpretation of a beta reduction,
 * $$ \lambda x.z\ y = z[x :=y]$$

Here if y is a function of a variable x, it is not the same x as in z. Alpha renaming may be applied. So we must have,
 * $$ x \not \in \operatorname{FV}(y) $$

so,
 * $$ x \not \in \operatorname{FV}(y) \to \operatorname{let} x ; x = y \operatorname{in} z = \lambda x.z\ y$$