Tapl 5
- 12. Operational
Semantics
関数適用
(λx.a) b ! [x!b]a
a の中の x を b に置き換える
例: (λx.x) y ! y
- 13. Operational
Semantics
簡約基 (redex)
(λx.a) b という形をした項のこと
β簡約 (beta-reduction)
簡約基を、先のルールに従って書き換えること
- 14. Operational
Semantics
簡約戦略
full beta-reduction
normal order strategy
call-by-name strategy
call-by-value strategy
- 15. Operational
Semantics
full beta-reduction
任意の簡約可能式を、任意のタイミングで簡
約できる
- 16. Operational
Semantics
normal order strategy
最左最外簡約 (leftmost, outermost)
左側、外側の項から順番に簡約していく
- 17. Operational
Semantics
call-by-name strategy
ラムダ抽象の中は簡約しない
それ以外は normal order strategy
call-by-need strategy
評価結果を保存して、再計算しない版
- 18. Operational
Semantics
call-by-value strategy
関数適用の前に、右側を先に簡約する
それ以外は call-by-name strategy
- 19. Operational
Semantics
call-by-value strategy
正格 (strict)
関数内で引数が使われなくでも、引数を評
価する
call-by-name/need は 遅延 (lazy)
- 34. Pairs
例:
fst (pair tru fls)
! fst ((λf.λs.λb.b f s) tru fls)
! fst ((λs.λb.b tru s) fls)
! fst (λb.b tru fls)
! (λp.p tru) (λb.b tru fls)
- 35. Pairs
例:
fst (pair tru fls)
! (λp.p tru) (λb.b tru fls)
! (λb.b tru fls) tru
! tru tru fls
! (λt.λf.t) tru fls ! tru
- 37. Church Numerals
z: 0 を表すもの
c0 = λs.λz.z
c1 = λs.λz.s z s: 次を取得するもの
c2 = λs.λz.s (s z)
c3 = λs.λz.s (s (s z))
...
- 49. Church Numerals
prd = λm.fst (m ss zz)
ss = λp.pair (snd p) (scc (snd p))
zz = pair c0 c0
(0, 0) から始めて
- 50. Church Numerals
prd = λm.fst (m ss zz)
ss = λp.pair (snd p) (scc (snd p))
zz = pair c0 c0
(_, x) ! (x, x + 1)
(0, 0) から始めて
- 51. Church Numerals
m 回やると、
m = 0 の時は
(m - 1, m) (0, 0)
prd = λm.fst (m ss zz)
ss = λp.pair (snd p) (scc (snd p))
zz = pair c0 c0
(_, x) ! (x, x + 1)
(0, 0) から始めて
- 52. Enriching the
Calculus
λNB
NB (3章) に λ を加える
NB (Real) と λ (Church) は、
両方とも boolean と numeral を
持っている
- 53. Enriching the
Calculus
Church ! Real
realbool = λb.b true false
realnat = λm.m (λx.succ x) 0
Real ! Church
churchbool =
λb.if b then tru else fls
- 54. Enriching the
Calculus
振る舞い同値 (behaviorally equivalent)
どんな引数に対しても、2つの評価結果が同じ
例: call-by-value での scc c1
(λs.λz.s ((λs’.λz’.s’ z’) s z))
(λs.λz.s (s z)) と “振る舞い同値”
- 56. Recursion
不動点 (fixed-point)
fix = λf.
(λx.f (λy.x x y))
(λx.f (λy.x x y))
Z-combinator / call-by-value Y-combinator
Y-combinator: λf.(λx.f (x x)) (λx.f (x x))
- 61. Syntax
項集合 T
x ∈ V ! x ∈ T
t ∈ T かつ x ∈ V ! λx.t ∈ T
s ∈ T かつ t ∈ T ! s t ∈ T
- 62. Syntax
自由変数集合
項 t の自由変数集合 FV(t)
FV(x) = {x}
FV(λx.t) = FV(t) - {x}
FV(s t) = FV(s) ∪ FV(t)
- 65. Operational
Semantics
Syntax
項 (term) 値 (value)
t ::= v ::=
x λx.t
λx.t
t t
- 66. Operational
Semantics
評価 (evaluation) (call-by-value)
t1 ! t1’
E-APP1
t1 t2 ! t1’ t2
t ! t’
E-APP2
v t ! v t’
(λx.t) v ! [x!v]t E-APPABS