Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
自作ラムダ計算インタプリタで不動点演算をする
Search
Arata Sato
August 30, 2021
Programming
0
120
自作ラムダ計算インタプリタで不動点演算をする
https://github.com/atrn0/lambda
Arata Sato
August 30, 2021
Tweet
Share
More Decks by Arata Sato
See All by Arata Sato
Flutterでやっていくアプリケーション開発
atrn0
1
1.1k
Other Decks in Programming
See All in Programming
もうちょっといいRubyプロファイラを作りたい (2025)
osyoyu
1
440
rage against annotate_predecessor
junk0612
0
170
私の後悔をAWS DMSで解決した話
hiramax
4
210
AI時代のUIはどこへ行く?
yusukebe
18
8.9k
Updates on MLS on Ruby (and maybe more)
sylph01
1
180
プロポーザル駆動学習 / Proposal-Driven Learning
mackey0225
2
1.3k
GitHubとGitLabとAWS CodePipelineでCI/CDを組み比べてみた
satoshi256kbyte
4
230
Navigation 2 を 3 に移行する(予定)ためにやったこと
yokomii
0
230
アルテニア コンサル/ITエンジニア向け 採用ピッチ資料
altenir
0
100
そのAPI、誰のため? Androidライブラリ設計における利用者目線の実践テクニック
mkeeda
2
300
概念モデル→論理モデルで気をつけていること
sunnyone
2
180
意外と簡単!?フロントエンドでパスキー認証を実現する WebAuthn
teamlab
PRO
2
750
Featured
See All Featured
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.4k
Art, The Web, and Tiny UX
lynnandtonic
303
21k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.9k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.4k
Unsuck your backbone
ammeep
671
58k
Reflections from 52 weeks, 52 projects
jeffersonlam
352
21k
Intergalactic Javascript Robots from Outer Space
tanoku
272
27k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
For a Future-Friendly Web
brad_frost
180
9.9k
Java REST API Framework Comparison - PWX 2021
mraible
33
8.8k
How to Ace a Technical Interview
jacobian
279
23k
[RailsConf 2023] Rails as a piece of cake
palkan
57
5.8k
Transcript
自作ラムダ計算インタプリタで 不動点演算をする CAMPHOR- 定例LT @atrn0
(単純型無し)ラムダ計算とは - 関数の作成と関数の適用のみからなる計算モデル - これだけでチューリング完全 - シンタックスはこんな感じ
言語の定義 文法(シンタックス)と意味(セマンティクス)を決める
シンタックス - 関数適用は左結合: s t u = (s t) u
- 適当にかっこはつけて良い - 変数のスコープはその関数の本体
セマンティクス (λx. s) t という形が来たら、sの中に出てくるxをtで置き換える(簡約) 例えば (λx.x) ((λx.x) (λz. (λx.x)
z)) → (λx. x) (λz. ((λx. x) z)) → (λz. ((λx. x) z)) → (λz. z)
目標: nの階乗を求めたい f(0) = 1 f(n) = f(n-1) * n
必要なもの: - 条件分岐 - 数 - 掛け算 - 再帰
複数引数 複数の引数は高階関数(関数を返す関数)で表す λx. λy. s つまり λx. (λy. s) *任意の複数引数の関数はカリー化によって高階関数に変換できる
Boolean - プリミティブな定数がない代わりにエンコードで表す - Booleanは true = λt. λf. t
false = λt. λf. f とエンコードする - 条件分岐は次のように書けたりする λl. λm. λn. l m n
Number c0 = λs. λz. z c1 = λs. λz.
s z c2 = λs. λz. s (s z) c3 = λs. λz. s (s (s z)) etc. - 例えば加算は λm. λn. λs. λz. m s (n s z) と書けたりする
再帰演算 不動点コンビネータを使う - 不動点コンビネータ: F g → g (F g)
となるようなFのこと。 g = λf. <fを含む本体> とすると、 F g x → g (F g) x より、<fを含む本体>でgを複製して繰り返し使える。
Yコンビネータ 不動点コンビネータの一つ Y = λf. (λx. f (x x)) (λx.
f (x x))
階乗の計算 f(0) = 1 f(n) = f(n-1) * n 必要なもの:
- 条件分岐: test = λl. λm. λn. l m n - 数: c2 = λs. λz. s (s z) など - 掛け算: times = λm. λn. m (plus n) c0 - 再帰: 不動点コンビネータ
階乗の計算 このぐらいマクロを定義するとできます。
デモ g = λf. λn. test (iszro n) (λx. c1)
(λx. (times n (f (prd n)))) c0 (fix g) cn → g (fix g) cn = (λf. λn. test (iszro n) (λx. c1) (λx. (times n (f (prd n)))) c0) (fix g) cn → test (iszro cn) (λx. c1) (λx. (times cn ((fix g) (prd cn)))) c0 ...
参考 - Types and Programming Languages (https://www.cis.upenn.edu/~bcpierce/tapl/)