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
Railsだからできる 例外業務に禍根を残さない 設定設計パターン
ei_ei_eiichi
0
920
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
170
kiroとCodexで最高のSpec駆動開発を!!数時間で web3ネイティブなミニゲームを作ってみたよ!
mashharuki
0
570
SwiftDataを使って10万件のデータを読み書きする
akidon0000
0
140
ALL CODE BASE ARE BELONG TO STUDY
uzulla
25
6.1k
CSC305 Lecture 06
javiergs
PRO
0
240
その面倒な作業、「Dart」にやらせませんか? Flutter開発者のための業務効率化
yordgenome03
1
130
詳しくない分野でのVibe Codingで困ったことと学び/vibe-coding-in-unfamiliar-area
shibayu36
3
5.1k
『毎日の移動』を支えるGoバックエンド内製開発
yutautsugi
2
250
Go言語の特性を活かした公式MCP SDKの設計
hond0413
1
230
ソフトウェア設計の実践的な考え方
masuda220
PRO
4
590
All About Angular's New Signal Forms
manfredsteyer
PRO
0
170
Featured
See All Featured
A better future with KSS
kneath
239
18k
GraphQLの誤解/rethinking-graphql
sonatard
73
11k
YesSQL, Process and Tooling at Scale
rocio
173
14k
Making Projects Easy
brettharned
120
6.4k
Gamification - CAS2011
davidbonilla
81
5.5k
4 Signs Your Business is Dying
shpigford
185
22k
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
45
2.5k
Side Projects
sachag
455
43k
It's Worth the Effort
3n
187
28k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
127
53k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
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/)