The Internet Encyclopedia of Philosophy defines bound and free variables in lambda calculus as:
In a term $λx.P$, $x$ is a bound variable, as are similarly bound variables in the subterm $P$; variables which are not bound are free.
It also says about substitution in lambda calculus:
We can then define the substitution of $N$ for $x$ in term $M$, denoted $M[x > := N]$, as follows:
- $x[x := N] = N$
- $y[x := N] = y$ (provided that $x$ is a variable different than $y$)
- $(PQ)[x := N] = P[x := N]Q[x := N]$
- $(λx.P)[x := N] = λx.P$
- $(λy.P)[x := N] = λy.P[x := N]$ (provided that $x$ is different than $y$ and $y$ is not free in $N$ or $x$ is not free in $P$)
I understand 1., 2. and 3., but don't quite understand 4. and 5.
Re: 4. $(λx.P)[x := N] = λx.P$:
In 4., we have $M[x:=N]$ where $M=\lambda x.P$, so would we say $x$ is a bound variable in $M$ or in $P$ or both? Why does the fact that $x$ is bound preclude us from substituting $N$ for $x$ in $P$? i.e. why isn't $(λx.P)[x := N]$ not equal to $λx.(P[x:=N])$? If an example, would help explain this better, please provide an example.
Can this be understand from a programming perspective? How would we encode $(λx.P)$ in Python for example? As M = lambda x: P or M = lambda x: P(x)? And if it is possible to encode $(λx.P)$ as either, what effect does the substitution step (i.e. $[x:=N]$ have on the code?
Re: 5. $(λy.P)[x := N] = λy.P[x := N]$ (provided that $x$ is different than $y$ and $y$ is not free in $N$ or $x$ is not free in $P$):
Why are the "$y$ is not free in $N$" and "$x$ is not free in $P$" restrictions imposed?
Again, can this be understand from a programming perspective? How would we encode $(λy.P)$ in Python for example? As M = lambda y: P or M = lambda y: P(y)? And if it is possible to encode $(λy.P)$ as either, what effect does the substitution step (i.e. $[x:=N]$ have on the code?
5.when $N = λy.y$ and $P = λx.x$ which I believe meets all three restrictions of5.. I get to $λy.(λx.x)[x := (λy.y)]$, but not sure how to proceed from there because one of the substitutions is to the variable $x$ that follows a $λ$, which is an invalid step (https://math.stackexchange.com/questions/4303277/in-lambda-calculus-the-%ce%bb-symbol-is-followed-by-a-variable-can-that-variable-be/4303312#4303312) – joseville Nov 11 '21 at 21:04