markdown
無型λ計算の基本md b7d6013
lecture/information/programming-languages/lambda-calculus/lambda-calculus-basics.lecture.n.md
Download PDF

無型むがたλ計算けいさんの基本きほん

informationprogramming-languageslambda-calculuslecture

1導入どうにゅう

この講義こうぎでは、無型むがたλ計算けいさんの構文こうぶんとβ簡約かんやくを説明せつめいする。置換ちかんによる変数捕獲へんすうほかくを回避かいひするため、自由変数じゆうへんすうとα同値どうちをβ簡約かんやくより先さきに確認かくにんする。ここでは型判断かたはんだんを導入どうにゅうしない。

21. 構文こうぶんと結合規則けつごうきそく

変数へんすうの集合しゅうごうを可算無限集合かさんむげんしゅうごうとする。λ項こう t は次つぎの文法ぶんぽうで帰納的きのうてきに定義ていぎする。

t::=x∣λx.t∣tt

λx.t は x を束縛そくばくするλ抽象ちゅうしょう、ts は適用てきようである。適用てきようは左結合ひだりけつごうであり、λ抽象ちゅうしょうの本体ほんたいは可能かのうな限かぎり右みぎへ延長えんちょうする。したがって、tuv=(tu)v、λx.tu=λx.(tu) である。

32. 自由変数じゆうへんすうとα同値どうち

自由変数集合じゆうへんすうしゅうごう FV(t) を次つぎで定義ていぎする。

FV(x)={x},FV(λx.t)=FV(t)∖{x},FV(tu)=FV(t)∪FV(u).

束縛変数そくばくへんすうの一貫いっかんした改名かいめいだけが異ことなる項こうをα同値どうちとする。たとえば、λx.x=αλz.z である。ただし、z が本体ほんたいで自由じゆうに出現しゅつげんする場合ばあい、x を z に改名かいめいできない。

43. 捕獲回避置換ほかくかいひちかん

t[x:=s] は、t における x の自由出現じゆうしゅつげんを s で置換ちかんする項こうである。x∉FV(t) なら t[x:=s]=t とする。変数へんすうと適用てきようでは構造こうぞうに沿そって定義ていぎし、λ抽象ちゅうしょうでは次つぎの条件じょうけんを用もちいる。

(\lambda y.t)[x:=s]= \begin{cases} \lambda y.t & y=x,\\ \lambda y.(t[x:=s]) & y\ne x\ \text{かつ}\ y\notin\mathrm{FV}(s),\\ \lambda z.((t[y:=z])[x:=s]) & y\ne x\ \text{かつ}\ y\in\mathrm{FV}(s), \end{cases}

最後さいごの場合ばあいでは、t と s のどこにも出現しゅつげんせず、x とも異ことなる新あたらしい変数へんすう(fresh variable)z を選択せんたくする。たとえば、(λy.x)[x:=y] をそのまま λy.y とすると、置換項ちかんこうの自由変数じゆうへんすう y が捕獲ほかくされる。先さきにα改名かいめいして、(λy.x)[x:=y]=α(λz.x)[x:=y]=λz.y とする。

54. β簡約かんやくと正規形せいきけい

(λx.t)s という部分項ぶぶんこうをβ簡約基かんやくきといい、捕獲回避置換ほかくかいひちかんによって次つぎのように簡約かんやくする。

(λx.t)s→βt[x:=s].

項こうの任意にんいの位置いちにあるβ簡約基かんやくきを一段いちだん簡約かんやくできる。β簡約基かんやくきを含ふくまない項こうをβ正規形せいきけいという。

(λx.λy.x)ab→β(λy.a)b→βa.

一方いっぽう、Ω=(λx.xx)(λx.xx) のβ簡約基かんやくきは項全体こうぜんたいだけであり、その簡約かんやくは Ω→βΩ に戻もどる。したがって、どの簡約列かんやくれつもβ正規形せいきけいへ到達とうたつしない。無型むがたλ計算けいさんでは停止性ていしせいを一般いっぱんに保証ほしょうできない。

65. 評価戦略ひょうかせんりゃく

β簡約かんやくは簡約基かんやくきの選択順せんたくじゅんを規定きていしない。最左外側さいさひだりそとがわの簡約基かんやくきを選択せんたくする正規順序せいきじゅんじょと、最左内側さいさひだりうちがわの簡約基かんやくきを選択せんたくする適用順序てきようじゅんじょでは、停止挙動ていしきょどうが異ことなりうる。

(λx.a)Ω

正規順序せいきじゅんじょでは外側そとがわを先さきに簡約かんやくして a に到達とうたつする。適用順序てきようじゅんじょでは Ω の簡約かんやくを反復はんぷくするため停止ていししない。これは戦略せんりゃくの停止性ていしせいの差さであり、β簡約規則かんやくきそくそのものの差さではない。β正規形せいきけいが存在そんざいする項こうについて、正規順序せいきじゅんじょはそれに到達とうたつする。

76. η変換へんかんとの区別くべつ

x∉FV(f) のとき、λx.fx=ηf とするη変換へんかんは、関数かんすうの外延的がいえんてきな同一視どういつしを表あらわす。これは関数適用かんすうてきようを実行じっこうするβ簡約かんやくとは別べつの規則きそくである。

8まとめ

無型むがたλ計算けいさんの計算けいさんは、α同値どうちを考慮こうりょした捕獲回避置換ほかくかいひちかんによるβ簡約かんやくである。正規形せいきけいの存在そんざいと、特定とくていの評価戦略ひょうかせんりゃくが停止ていしすることは区別くべつする必要ひつようがある。

data/lecture/information/programming-languages/foundation/substitution-and-alpha-equivalence-basics.lecture.n.md

Basics of the Untyped Lambda Calculus

1Introduction

This lecture explains the syntax and beta-reduction of the untyped lambda calculus. It reviews free variables and alpha-equivalence before beta-reduction because substitution must avoid variable capture. No typing judgment is introduced here.

21. Syntax and association conventions

Let the set of variables be countably infinite. Lambda terms t are defined inductively by

t::=x∣λx.t∣tt.

The term λx.t is a lambda abstraction that binds x, and ts is an application. Application associates to the left, and the body of an abstraction extends as far right as possible. Thus tuv=(tu)v and λx.tu=λx.(tu).

32. Free variables and alpha-equivalence

The set FV(t) of free variables is defined by

FV(x)={x},FV(λx.t)=FV(t)∖{x},FV(tu)=FV(t)∪FV(u).

Terms that differ only by a consistent renaming of bound variables are alpha-equivalent. For example, λx.x=αλz.z. A binder cannot, however, be renamed to z when z occurs free in its body.

43. Capture-avoiding substitution

The term t[x:=s] replaces every free occurrence of x in t with s. If x∉FV(t), then t[x:=s]=t. Its variable and application cases follow the term structure. The abstraction case is

(\lambda y.t)[x:=s]= \begin{cases} \lambda y.t & y=x,\\ \lambda y.(t[x:=s]) & y\ne x\ \text{and}\ y\notin\mathrm{FV}(s),\\ \lambda z.((t[y:=z])[x:=s]) & y\ne x\ \text{and}\ y\in\mathrm{FV}(s), \end{cases}

where the last case chooses a fresh variable z that differs from x and does not occur anywhere in either t or s. For example, directly producing λy.y from (λy.x)[x:=y] would capture the free y of the substituted term. Alpha-renaming first gives (λy.x)[x:=y]=α(λz.x)[x:=y]=λz.y.

54. Beta-reduction and normal forms

A subterm of the form (λx.t)s is a beta-redex. Capture-avoiding substitution contracts it as follows:

(λx.t)s→βt[x:=s].

A beta-redex at any position in a term may be contracted in one step. A term containing no beta-redex is a beta-normal form.

(λx.λy.x)ab→β(λy.a)b→βa.

In contrast, the only beta-redex of Ω=(λx.xx)(λx.xx) is the whole term, and contracting it returns Ω→βΩ. Hence no reduction sequence reaches a beta-normal form. The untyped lambda calculus does not guarantee termination in general.

65. Evaluation strategies

Beta-reduction does not prescribe an order for selecting redexes. Normal order selects the leftmost outermost redex, whereas applicative order selects the leftmost innermost redex; the two strategies can have different termination behavior. Consider

(λx.a)Ω.

Normal order contracts the outer redex first and reaches a. Applicative order repeatedly reduces Ω and does not terminate. This is a difference in strategy termination, not a difference in the beta-reduction rule. If a term has a beta-normal form, normal-order reduction reaches it.

76. Distinguishing eta-conversion

When x∉FV(f), the eta-conversion λx.fx=ηf expresses extensional identification of functions. It is distinct from beta-reduction, which performs function application.

8Summary

Computation in the untyped lambda calculus is beta-reduction by capture-avoiding substitution, considered modulo alpha-equivalence. The existence of a normal form must be distinguished from termination under a particular evaluation strategy.

data/lecture/information/programming-languages/foundation/substitution-and-alpha-equivalence-basics.lecture.n.md
raw .n.md をコピー
loc をコピー (filepath:line ~ line)
copy share link
copy encoded share link
path をコピー
copy share link
copy encoded share link
copy share link
copy encoded share link
タブを全て閉じる