Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ラムダ計算入門 / Introduction of Lambda Calculus

E2fc870af7558b22cb90c227dce7b8dd?s=47 katashin
August 09, 2017

ラムダ計算入門 / Introduction of Lambda Calculus

型勉強会 #2 2017/08/09

E2fc870af7558b22cb90c227dce7b8dd?s=128

katashin

August 09, 2017
Tweet

Transcript

  1. ϥϜμܭࢉೖ໳ ܕษڧձ #2 2017/08/09

  2. ࢀߟจݙ: TAPL

  3. ϥϜμܭࢉ • ͢΂ͯͷܭࢉ͕ؔ਺ఆٛͱؔ਺ద༻ʹؼண͞ΕΔମܥ • ߏจ͸ɺม਺ɺϥϜμந৅ (ແ໊ؔ਺)ɺؔ਺ద༻ͷ
 3ͭͷ߲ͷΈ͔Βߏ੒͞ΕΔ • ؔ਺ܕݴޠͷΞηϯϒϦͱݺ͹ΕͯΔΒ͍͠ •

    ࠓճ͸ܕແ͠ϥϜμܭࢉΛઆ໌͠·͢
 (୯७ܕ෇͖ϥϜμܭࢉ͸࣍ճ……ʁ)
  4. t ::= x λx. t t t ม਺ ϥϜμந৅ ؔ਺ద༻

    λx. λy. x (λz. x z) y ྫ:
  5. Q ਅِ஋ͱ͔਺஋ͱ͔͕ແ͍……ʁ

  6. Q ਅِ஋ͱ͔਺஋ͱ͔͕ແ͍……ʁ A ϥϜμந৅Ͱදݱ͢Ε͹͍͍͡Όͳ͍

  7. ਅِ஋ͷදݱ tru = λt. λf. t fls = λt. λf.

    f → true ͱΈͳͤΔ → false ͱΈͳͤΔ
  8. ྫ͑͹ if ࣜͬΆ͍ϥϜμந৅Λ͜ͷΑ͏ʹఆٛͰ͖Δ test = λl. λm. λn. l m

    n e.g. test t v w 
 t ͕ tru ͷ࣌ v Λɺfls ͷ࣌ w Λฦ͢
  9. ɹ test tru v w → (λl. λm. λn. l

    m n) tru v w → (λm. λn. tru m n) v w → (λn. tru v n) w → tru v w → (λt. λf. t) v w → (λf. v) w → v t = tru ͷ࣌ͷධՁͷྲྀΕ
  10. ੔਺஋ͷදݱ c0 = λs. λz. z c1 = λs. λz.

    s z c2 = λs. λz. s (s z) c3 = λs. λz. s (s (s z)) … → 0 → 1 → 2 → 3
  11. plus = λm. λn. λs. λz. m s (n s

    z) ଍͠ࢉΛ͢ΔϥϜμந৅
  12. ɹ plus c1 c3 → (λm. λn. λs. λz. m

    s (n s z)) c1 c3 → (λn. λs. λz. c1 s (n s z)) c3 → λs. λz. c1 s (c3 s z) → λs. λz. (λs’. λz’. s’ z’) s (c3 s z) → λs. λz. (λz’. s z’) (c3 s z) → λs. λz. s (c3 s z) → λs. λz. s ((λs’’. λz’’. s’’ (s’’ (s’’ z’’)) s z) → λs. λz. s ((λz’’. s (s (s z’’)) z) → λs. λz. s (s (s (s z))) → c4 ධՁͷྲྀΕ
  13. β-؆໿ • [x → t2] t12 ͸ t12 தͷ x

    ͷࣗ༝ͳग़ݱΛ͢΂ͯ t2 Ͱஔ͖׵ ͑Δ͜ͱʹΑͬͯಘΒΕΔ߲ • ͭ·Γؔ਺ద༻ͷධՁ (λx. t12) t2 → [x → t2] t12
  14. α-ม׵ • ม਺໊ΛҟͳΔม਺໊ʹม׵͢Δ͜ͱ • ม਺໊͸ॏཁͰ͸ͳ͍ͷͰม׵ޙ΋ಉҰͷ߲ͱͳΔ • ͨͩ͠ผͷม਺໊ͱ͔ͿΒͳ͍Α͏ʹม׵͠ͳ͍ͱ
 ҎԼͷྫͷΑ͏ʹม׵લޙͰҟͳͬͯ͠·͏ • ز͔ͭͷίϯύΠϥ͸ม਺ΛҰҙʹ͢ΔͨΊʹα-ม׵Λߦ͏

    λx. x x → λy. y y λx. x y → λy. y y
  15. ߲ͷ໊ແ͠දݱ • ม਺໊͸ͳΜͰ΋ྑ͍ • ͦΕͳΒ࠷ॳ͔ΒҰҙʹͳΔදݱΛબ୒͢Ε͹ྑ͍ • ࣗવ਺ k ΛɺͦΕΛғΉ k

    ൪໨ͷ λ ʹΑͬͯଋറ͞ΕΔ ม਺ͱ͢Δ λx. x (λy. x y) → λ. 0 (λ. 1 0)
  16. ࣮૷ͯ͠Έͨ https://github.com/ktsn/lambda-calculus