markdown
束縛と自由変数の基本md 283170c
lecture/information/programming-languages/foundation/variable-binding-and-free-variables-basics.lecture.n.md
Download PDF

束縛そくばく自由変数じゆうへんすう基本きほん

1導入どうにゅう

この講義こうぎでは、λこう構文こうぶん定義ていぎし、変数へんすうかく出現しゅつげん束縛出現そくばくしゅつげんまたは自由出現じゆうしゅつげん分類ぶんるいする。変数名へんすうめいだけでは分類ぶんるいできず、その出現位置しゅつげんいち束縛子そくばくし作用域さよういき必要ひつようである。

2構文こうぶん構文木こうぶんぎ

可算無限かさんむげん変数集合へんすうしゅうごう[PARSE ERROR: Undefined("Command(\"mathcal\")")]V とする。かたなしλこう集合しゅうごう Λつぎ生成規則せいせいきそく再帰的さいきてき定義ていぎする。

M::=x(MN)(λx.M)(x[PARSE ERROR: Undefined("Command(\"mathcal\")")]V)

x変数へんすうMN適用てきようλx.M はλ抽象ちゅうしょうである。括弧かっこ省略しょうりゃくするとき、適用てきよう左結合ひだりけつごうとし、λ抽象ちゅうしょう本体ほんたい可能かのうかぎみぎまで延長えんちょうする。したがって MNP=(MN)P であり、λx.MN=λx.(MN) である。

3束縛子そくばくし作用域さよういき出現しゅつげん

λx.Mλxx束縛子そくばくしbinder部分項ぶぶんこう M をその作用域さよういきscopeという。構文木こうぶんぎにおける変数へんすう x出現しゅつげんが、ある λx本体ほんたいふくまれるとき、その出現しゅつげん束縛そくばくされる。該当がいとうする束縛子そくばくし複数ふくすうある場合ばあいは、構文木上こうぶんぎじょうもっとちか束縛子そくばくしがその出現しゅつげん束縛そくばくする。いずれの λx作用域さよういきにもぞくさない x出現しゅつげん自由じゆうである。

束縛そくばくされる」という性質せいしつ変数名へんすうめいでなく出現しゅつげんぞくする。たとえば

x(λx.x)

では、左端さたんx自由出現じゆうしゅつげんであり、右端うたんx内側うちがわλx による束縛出現そくばくしゅつげんである。また

λx.((λx.x)x)

では、内側うちがわ本体ほんたいにある x内側うちがわ束縛子そくばくしに、最後さいごx外側そとがわ束縛子そくばくし束縛そくばくされる。この現象げんしょう遮蔽しゃへいshadowingという。

4自由変数集合じゆうへんすうしゅうごう

FV(M)M自由出現じゆうしゅつげん変数名へんすうめい集合しゅうごうであり、構文こうぶん沿ってつぎのように定義ていぎする。

FV(x)={x}
FV(MN)=FV(M)FV(N)
FV(λx.M)=FV(M){x}

たとえば、

FV(λx.xy)={y},FV(λx.λy.xy)=[PARSE ERROR: Undefined("Command(\"varnothing\")")].

FV(M)=[PARSE ERROR: Undefined("Command(\"varnothing\")")] であるこう閉項へいこうclosed term、それ以外いがい開項かいこうopen termという。閉項へいこうであることは、変数へんすう各出現かくしゅつげんがいずれかの束縛子そくばくし束縛そくばくされることと同値どうちである。

5確認かくにん

M=λx.(x(λy.xy)z) では、ふたつの x出現しゅつげん外側そとがわλx束縛そくばくされ、y出現しゅつげんλy束縛そくばくされ、z出現しゅつげんだけが自由じゆうである。したがって FV(M)={z} である。つぎ講義こうぎでは、この出現しゅつげんごとの分類ぶんるいもちいて捕縛ほばく回避かいひする置換ちかん定義ていぎする。

6関連かんれんリンク

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

Basics of Binding and Free Variables

1Introduction

This lecture defines the syntax of lambda terms and classifies every variable occurrence as bound or free. A name alone does not determine the classification; the occurrence's position and the scope of its binder are essential.

2Syntax and syntax trees

Let [PARSE ERROR: Undefined("Command(\"mathcal\")")]V be a countably infinite set of variables. The set Λ of untyped lambda terms is defined recursively by the grammar

M::=x(MN)(λx.M)(x[PARSE ERROR: Undefined("Command(\"mathcal\")")]V).

Here x is a variable, MN is an application, and λx.M is an abstraction. When parentheses are omitted, application associates to the left and the body of an abstraction extends as far to the right as possible. Thus MNP=(MN)P and λx.MN=λx.(MN).

3Binders, scopes, and occurrences

In λx.M, the prefix λx is a binder for x, and the subterm M is its scope. An occurrence of x at a leaf of the syntax tree is bound if it lies inside the body of some λx. If several such binders enclose the occurrence, the nearest one in the syntax tree binds it. An occurrence of x that lies in the scope of no λx is free.

Boundness is a property of an occurrence, not merely of a variable name. For example, in

x(λx.x),

the leftmost occurrence of x is free, whereas the rightmost occurrence is bound by the inner λx. In

λx.((λx.x)x),

the occurrence in the inner body is bound by the inner binder, while the final occurrence is bound by the outer binder. This phenomenon is called shadowing.

4The set of free variables

FV(M) is the set of variable names that have at least one free occurrence in M. It is defined structurally by

FV(x)={x},
FV(MN)=FV(M)FV(N),
FV(λx.M)=FV(M){x}.

For example,

FV(λx.xy)={y},FV(λx.λy.xy)=[PARSE ERROR: Undefined("Command(\"varnothing\")")].

A term M is closed if FV(M)=[PARSE ERROR: Undefined("Command(\"varnothing\")")] and open otherwise. A term is closed exactly when every variable occurrence is bound by some binder.

5Check

In M=λx.(x(λy.xy)z), both occurrences of x are bound by the outer λx, the occurrence of y is bound by λy, and only the occurrence of z is free. Hence FV(M)={z}. The next lecture uses this occurrence-level classification to define substitution that avoids capture.

6Related links

data/lecture/information/programming-languages/foundation/introduction-to-functional-programming.lecture.n.md 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
タブを全て閉じる