Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
自作ラムダ計算インタプリタで不動点演算をする
Search
Arata Sato
August 30, 2021
Programming
140
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
自作ラムダ計算インタプリタで不動点演算をする
https://github.com/atrn0/lambda
Arata Sato
August 30, 2021
More Decks by Arata Sato
See All by Arata Sato
Flutterでやっていくアプリケーション開発
atrn0
0
1.1k
Other Decks in Programming
See All in Programming
AIエージェント時代のコードレビューを設計する
nogu66
6
2.6k
標準パッケージに uuid が追加された 背景から見る Go らしい意思決定 / go_127_uuid_decision
convto
5
6.1k
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
6
1.9k
[DroidKaigi 2026] Bring your own phones to Gradle Managed Devices
f2lk
0
110
ALB ログから Trace を気合で繋げる技術
fohte
7
880
Security issues being discussed on Web Platforms
petamoriken
0
730
DroidKaigi 2026 「個人開発という実験場: Android エンジニアが手にする4つの自由」
slashnephy
0
230
AgentCore CLI で進化した AWS での AI エージェントの作り方 : 必要な機能を必要な時に
icoxfog417
PRO
3
310
アクセシビリティから考える情報設計
high_g_engineer
0
350
『寄り添うラジオ』をAIで作る 体験価値から逆算した、会話しないUXと品質設計
theoriatec2024
3
150
20260828_品質と開発生産性を両立させる、AI時代のE2Eテストの考え方
magicpod
0
190
Webの地図
yosuke_furukawa
PRO
6
4.1k
Featured
See All Featured
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
240
Code Review Best Practice
trishagee
74
20k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
270
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.9k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
340
Speed Design
sergeychernyshev
33
2.1k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
Music & Morning Musume
bryan
47
7.4k
Balancing Empowerment & Direction
lara
6
1.3k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
270
So, you think you're a good person
axbom
PRO
2
2.1k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
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/)