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.ttt

λx.tx束縛そくばくするλ抽象ちゅうしょう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本体ほんたい自由じゆう出現しゅつげんする場合ばあいxz改名かいめいできない。

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

t[x:=s] は、t における x自由出現じゆうしゅつげんs置換ちかんするこうである。xFV(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}

最後さいご場合ばあいでは、ts のどこにも出現しゅつげんせず、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. η変換へんかんとの区別くべつ

xFV(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.ttt.

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 xFV(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 xFV(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
タブを全て閉じる