置換とα同値の基本
informationprogramming-languageslambda-calculuslecture
1導入
この講義では、変数の自由出現だけを項で置換する操作を定義する。単純な文字列置換は自由変数を意図せず束縛するため、束縛変数の改名によって変数捕縛を回避する必要がある。この改名を形式化するα同値も定義する。
2置換と捕縛
M[x:=N] は、M における x の自由出現を項 N で置換した結果を表す。束縛出現は置換の対象ではない。例えば
(\lambda x.x\;y)[x:=N]=\lambda x.x\;y
である。一方、(\lambda y.x)[x:=y] を機械的に \lambda y.y とすると、置換前に自由であった右辺の y が \lambda y に束縛される。この変化が変数捕縛である。正しい結果は、束縛子を先に改名した \lambda z.y である。
3fresh 変数
項の有限集合 S に対し、S に出現するどの変数名とも異なる変数 z を S に対してfreshであるという。\mathcal V は無限であり、有限個の項に出現する変数名は有限個なので、fresh変数は常に選択できる。以下では、改名による混同を避けるため、z を M と N の双方に出現しないように選択する。
4捕縛回避置換
捕縛回避置換を構文に関して再帰的に定義する。
x[x:=N]=N,\qquad y[x:=N]=y\quad(y\ne x),
(M_1\;M_2)[x:=N]=(M_1[x:=N])\;(M_2[x:=N]).
λ抽象には三つの場合がある。
(\lambda x.M)[x:=N]=\lambda x.M,
(\lambda y.M)[x:=N]=\lambda y.(M[x:=N])
\quad(y\ne x,\ y\notin\mathrm{FV}(N)),
(\lambda y.M)[x:=N]=\lambda z.((M[y:=z])[x:=N])
\quad(y\ne x,\ y\in\mathrm{FV}(N)),
ただし、最後の場合の z は M と N に対してfreshである。より厳密には、x\notin\mathrm{FV}(M) なら置換結果は M 自身であり、改名も不要である。上の最後の場合は x\in\mathrm{FV}(M) のときに適用すればよい。
例として、z を x,y と異なるfresh変数に選ぶと、
(\lambda y.x\;y)[x:=y]
=\lambda z.((x\;z)[x:=y])
=\lambda z.y\;z.
挿入された y は結果でも自由である。
5α変換とα同値
束縛子と、それが束縛する出現を一斉にfresh変数へ改名する操作をα変換という。y\notin\mathrm{FV}(M) のとき、
\lambda x.M\;=_\alpha\;\lambda y.(M[x:=y])
とする。ここで右辺の置換は捕縛回避置換である。α同値 =_\alpha は、この基本的な改名を任意の部分項で許し、反射性・対称性・推移性を満たす最小の合同関係である。したがって
\lambda x.x=_\alpha\lambda y.y,
だが、自由変数は改名できないため \lambda x.x\;y\not=_\alpha\lambda x.x\;z である。また \lambda x.\lambda y.x\not=_\alpha\lambda x.\lambda y.y であり、α同値は束縛構造を保存する。
6β簡約への接続
β簡約は
(\lambda x.M)\;N\longrightarrow_\beta M[x:=N]
と定義され、右辺には捕縛回避置換を用いる。例えば
(\lambda x.\lambda y.x)\;y\longrightarrow_\beta\lambda z.y
であり、\lambda y.y ではない。fresh変数の選択によって結果の表記は異なり得るが、いずれの結果もα同値である。
7関連リンク
data/lecture/information/programming-languages/foundation/variable-binding-and-free-variables-basics.lecture.n.md
data/lecture/information/programming-languages/lambda-calculus/lambda-calculus-basics.lecture.n.md
Basics of Substitution and Alpha-Equivalence
1Introduction
This lecture defines the operation that replaces only the free occurrences of a variable by a term. Naive textual replacement may accidentally bind a free variable, so bound variables must sometimes be renamed to avoid variable capture. Alpha-equivalence formalizes these harmless renamings.
2Substitution and capture
M[x:=N] denotes the result of replacing the free occurrences of x in M by the term N. Bound occurrences are not targets of substitution. For example,
(\lambda x.x\;y)[x:=N]=\lambda x.x\;y.
By contrast, mechanically turning (\lambda y.x)[x:=y] into \lambda y.y makes the inserted occurrence of y bound by \lambda y, although it was free before insertion. This change is variable capture. The correct result first renames the binder and is \lambda z.y.
3Fresh variables
For a finite set of terms S, a variable z is fresh for S if its name occurs in none of the terms in S. Because \mathcal V is infinite and finitely many terms contain only finitely many variable names, a fresh variable can always be chosen. Below, z is chosen not to occur in either M or N, avoiding ambiguity during renaming.
4Capture-avoiding substitution
Capture-avoiding substitution is defined recursively on syntax:
x[x:=N]=N,\qquad y[x:=N]=y\quad(y\ne x),
(M_1\;M_2)[x:=N]=(M_1[x:=N])\;(M_2[x:=N]).
There are three abstraction cases:
(\lambda x.M)[x:=N]=\lambda x.M,
(\lambda y.M)[x:=N]=\lambda y.(M[x:=N])
\quad(y\ne x,\ y\notin\mathrm{FV}(N)),
(\lambda y.M)[x:=N]=\lambda z.((M[y:=z])[x:=N])
\quad(y\ne x,\ y\in\mathrm{FV}(N)),
where z in the last clause is fresh for both M and N. More precisely, if x\notin\mathrm{FV}(M), the result is M itself and no renaming is needed; the last clause need only be applied when x\in\mathrm{FV}(M).
For example, choosing z fresh and distinct from x,y gives
(\lambda y.x\;y)[x:=y]
=\lambda z.((x\;z)[x:=y])
=\lambda z.y\;z.
The inserted occurrence of y remains free in the result.
5Alpha-conversion and alpha-equivalence
Alpha-conversion simultaneously renames a binder and the occurrences that it binds to a fresh variable. If y\notin\mathrm{FV}(M), then
\lambda x.M\;=_\alpha\;\lambda y.(M[x:=y]),
where the substitution on the right is capture-avoiding. Alpha-equivalence =_\alpha is the least congruence relation that permits this elementary renaming in any subterm and is reflexive, symmetric, and transitive. Consequently,
\lambda x.x=_\alpha\lambda y.y,
but free variables cannot be renamed, so \lambda x.x\;y\not=_\alpha\lambda x.x\;z. Moreover, \lambda x.\lambda y.x\not=_\alpha\lambda x.\lambda y.y: alpha-equivalence preserves binding structure.
6Connection to beta-reduction
Beta-reduction is defined by
(\lambda x.M)\;N\longrightarrow_\beta M[x:=N],
using capture-avoiding substitution on the right. For example,
(\lambda x.\lambda y.x)\;y\longrightarrow_\beta\lambda z.y,
not \lambda y.y. Different choices of a fresh variable may produce different spellings, but all resulting terms are alpha-equivalent.
7Related links
data/lecture/information/programming-languages/foundation/variable-binding-and-free-variables-basics.lecture.n.md
data/lecture/information/programming-languages/lambda-calculus/lambda-calculus-basics.lecture.n.md