SlideShare une entreprise Scribd logo
1  sur  26
Introduction to the Lambda Calculus
Alonzo Church
1932, “A set of postulates for the foundation of logic”, a formal system
with the aim of providing a foundation for logic which would be more
natural than Russell’s type theory or Zermelo’s set theory, and would
not contain free variables
1936 Church isolated and published just the portion relevant to
computation, what is now called the untyped lambda calculus
1940, he also introduced a computationally weaker, but logically
consistent system, known as the simply typed lambda calculus
Re-discovered as a versatile tool in Computer Science by people like
McCarthy, et al. in the 1960s
Operational Semantics -- Syntax
t ::=
x /* variable */
λx.t /* abstraction */
t t /* application */
v ::=
λx.t /* abstraction value */
Operational Semantics -- Evaluation
t1 t1'
/* congruence rule 1 */
t1 t2 t1' t2
t2 t2'
/* congruence rule 2 */
v1 t2 v1 t2'
(λx.t) v [x ↦ v]t /* computation rule */
That’s it!
No data structures
No control flow statements
No strings, numbers, or even booleans
Any questions?
Any questions?
Like, how do you do anything?
Church encoding
representing data and operators in the lambda calculus
Let’s start with the booleans
true = λt. λf. t
false = λt. λf. f
not = λa. a false true
Applying not
(λa. a false true) true
(λa. a false true) (λt. λf. t)
(λt. λf. t) false true
false
(λx.t) v [x ↦ v]t
(from operational semantic rules)
β-reduction
applying functions to their arguments
Normal order reduction – most well-known languages work
from the leftmost, outermost, redex and work in, halting when
the outermost argument can no longer be applied
Redex – reducible expression
Full β-reduction – reduce available redexes in any desired order
Full β-reduction
λs.λz. (λs'.λz'. (λb. b) s' ((λt.λb. b) s' z')) s ((λs'.λz'.
(λs''.λz''. (λb. b) s'' ((λt.λb. b) s'' z''))
s' ((λt.λb. b) s' z'))
s z)
Full β-reduction
λs.λz. (λs'.λz'. s' z') s ((λs'.λz'. (λs''.λz''. s'' z'') s' z') s z)
Full β-reduction
λs.λz. s ((λs'.λz'. (λs''.λz''. s'' z'') s' z') s z)
Full β-reduction
λs.λz. s ((λs'.λz'. s' z') s z)
Full β-reduction
λs.λz. s (s z)
Back to the booleans
and = λa. λb. a b fls
or = λa. λb. a tru b
nand = λa. λb. not (and a b)
xor = λa. λb. and (nand a b) (or a b)
cond = λp. λt. λf. p t f /* i.e. if else */
and
(λa. λb. a b fls) tru fls
(λt. λf. t) (λt. λf. f) (λt. λf. f)
λt. λf. f
(λa. λb. a b fls) tru tru
(λt. λf. t) (λt. λf. t) (λt. λf. f)
λt. λf. t
Hooray!
xnor = λa. λb. not (xor a b)
Now we have assertions!
xnor = λa. λb. not (xor a b)
xnor tru (cond fls fls tru)
xnor fls (cond fls tru fls)
Tuples
pair = λf. λs. λb. b f s
fst = λp. p tru
snd = λp. p fls
Numbers
c0 = λs. λz. z
c1 = λs. λz. s z
c2 = λs. λz. s (s z)
c3 = λs. λz. s (s (s z))
…
Just like Peano arithmetic
Operations on numbers
iszro = λm. m (λx. fls) tru
plus = λm. λn. λs. λz. m s (n s z)
mult = λm. λn. m (plus n) c0
exp = λm. λn. n (mult m) c1
scc = λn. λs. λz. s (n s z) /* number successor */
/* number predecessor */
prd = λm. fst (m (λp. pair (snd p) (plus c1 (snd p))) (pair c0 c0))
eql = λm. λn. and (iszro (m prd n)) (iszro (n prd m))
Automating assertions
/* it is true that ... */
xnor tru (eql c1 (exp c1 c1))
xnor tru (eql c6 (plus c2 c4))
xnor tru (eql c1 (fst (pair c1 tru)))
Lists
Lists follow from tuples and numbers
(more on that another time)
Recursion
fix (a.k.a the Y-combinator)
= λf. (λx. f (λy. x x y)) (λx. f (λy. x x y))
takes recursive abstraction
λf. λx. __f__
Haskell Curry
Recursion
(λf. (λx. f (λy. x x y)) (λx. f (λy. x x y))) (λf. λx. __) (bar)
(λx. (λf. λx'. __) (λy. x x y)) (λx. (λf. λx'. __) (λy. x x y)) (bar)
(foo)
(λf. λx'. __) (λy. foo foo y) (bar)
λx'. __ (bar)
Recursion
fact = λf. λx. cond (iszro x) c1 (mult x (f (prd x)))
(λf. (λx. f (λy. x x y)) (λx. f (λy. x x y))) fact c3
/* successive interations */
(λy. (λx. f (λy'.x x y')) (λx. f (λy'.x x y')) y) (/* prev recurs*/)

Contenu connexe

Tendances

HKG18-120 - Devicetree Schema Documentation and Validation
HKG18-120 - Devicetree Schema Documentation and Validation HKG18-120 - Devicetree Schema Documentation and Validation
HKG18-120 - Devicetree Schema Documentation and Validation
Linaro
 
条件分岐とcmovとmaxps
条件分岐とcmovとmaxps条件分岐とcmovとmaxps
条件分岐とcmovとmaxps
MITSUNARI Shigeo
 
My lecture infix-to-postfix
My lecture infix-to-postfixMy lecture infix-to-postfix
My lecture infix-to-postfix
Senthil Kumar
 

Tendances (20)

[TechPlayConf]Rekognition導入事例
[TechPlayConf]Rekognition導入事例[TechPlayConf]Rekognition導入事例
[TechPlayConf]Rekognition導入事例
 
HKG18-120 - Devicetree Schema Documentation and Validation
HKG18-120 - Devicetree Schema Documentation and Validation HKG18-120 - Devicetree Schema Documentation and Validation
HKG18-120 - Devicetree Schema Documentation and Validation
 
AVX-512(フォーマット)詳解
AVX-512(フォーマット)詳解AVX-512(フォーマット)詳解
AVX-512(フォーマット)詳解
 
Care and Feeding of Catalyst Optimizer
Care and Feeding of Catalyst OptimizerCare and Feeding of Catalyst Optimizer
Care and Feeding of Catalyst Optimizer
 
Computer Science class 12
Computer Science  class 12Computer Science  class 12
Computer Science class 12
 
条件分岐とcmovとmaxps
条件分岐とcmovとmaxps条件分岐とcmovとmaxps
条件分岐とcmovとmaxps
 
My lecture infix-to-postfix
My lecture infix-to-postfixMy lecture infix-to-postfix
My lecture infix-to-postfix
 
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQLTen Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
 
Enterprise Tic-Tac-Toe
Enterprise Tic-Tac-ToeEnterprise Tic-Tac-Toe
Enterprise Tic-Tac-Toe
 
Dawid Weiss- Finite state automata in lucene
 Dawid Weiss- Finite state automata in lucene Dawid Weiss- Finite state automata in lucene
Dawid Weiss- Finite state automata in lucene
 
Bca numer
Bca numerBca numer
Bca numer
 
20090713 Hbase Schema Design Case Studies
20090713 Hbase Schema Design Case Studies20090713 Hbase Schema Design Case Studies
20090713 Hbase Schema Design Case Studies
 
Scala DSLの作り方
Scala DSLの作り方Scala DSLの作り方
Scala DSLの作り方
 
A Deep Dive into Apache Cassandra for .NET Developers
A Deep Dive into Apache Cassandra for .NET DevelopersA Deep Dive into Apache Cassandra for .NET Developers
A Deep Dive into Apache Cassandra for .NET Developers
 
Python Pandas.pptx
Python Pandas.pptxPython Pandas.pptx
Python Pandas.pptx
 
6-Python-Recursion PPT.pptx
6-Python-Recursion PPT.pptx6-Python-Recursion PPT.pptx
6-Python-Recursion PPT.pptx
 
Looking ahead at PostgreSQL 15
Looking ahead at PostgreSQL 15Looking ahead at PostgreSQL 15
Looking ahead at PostgreSQL 15
 
CuPy解説
CuPy解説CuPy解説
CuPy解説
 
PostgreSQL Deep Internal
PostgreSQL Deep InternalPostgreSQL Deep Internal
PostgreSQL Deep Internal
 
深層強化学習入門 2020年度Deep Learning基礎講座「強化学習」
深層強化学習入門 2020年度Deep Learning基礎講座「強化学習」深層強化学習入門 2020年度Deep Learning基礎講座「強化学習」
深層強化学習入門 2020年度Deep Learning基礎講座「強化学習」
 

En vedette

En vedette (6)

Lambda Calculus by Dustin Mulcahey
Lambda Calculus by Dustin Mulcahey Lambda Calculus by Dustin Mulcahey
Lambda Calculus by Dustin Mulcahey
 
Introduction to lambda expression & lambda calculus
Introduction to lambda expression & lambda calculusIntroduction to lambda expression & lambda calculus
Introduction to lambda expression & lambda calculus
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
Lambda calculus
Lambda calculusLambda calculus
Lambda calculus
 
Lambda Calculus
Lambda CalculusLambda Calculus
Lambda Calculus
 
Functional Programming Fundamentals
Functional Programming FundamentalsFunctional Programming Fundamentals
Functional Programming Fundamentals
 

Similaire à Introduction to the lambda calculus

Scala Turkiye 2013-02-07 Sunumu
Scala Turkiye 2013-02-07 SunumuScala Turkiye 2013-02-07 Sunumu
Scala Turkiye 2013-02-07 Sunumu
Volkan Yazıcı
 
Real World Haskell: Lecture 2
Real World Haskell: Lecture 2Real World Haskell: Lecture 2
Real World Haskell: Lecture 2
Bryan O'Sullivan
 
ECS140A-F16-07 October 27, 2016ASSIGNMENT 5 LISPDue .docx
ECS140A-F16-07 October 27, 2016ASSIGNMENT 5 LISPDue .docxECS140A-F16-07 October 27, 2016ASSIGNMENT 5 LISPDue .docx
ECS140A-F16-07 October 27, 2016ASSIGNMENT 5 LISPDue .docx
SALU18
 
Type header file in c++ and its function
Type header file in c++ and its functionType header file in c++ and its function
Type header file in c++ and its function
Frankie Jones
 

Similaire à Introduction to the lambda calculus (20)

Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
 
Lambda Calculus
Lambda CalculusLambda Calculus
Lambda Calculus
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and ScalaFolding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
 
recursion.ppt
recursion.pptrecursion.ppt
recursion.ppt
 
Scala Turkiye 2013-02-07 Sunumu
Scala Turkiye 2013-02-07 SunumuScala Turkiye 2013-02-07 Sunumu
Scala Turkiye 2013-02-07 Sunumu
 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative Practice
 
Real World Haskell: Lecture 2
Real World Haskell: Lecture 2Real World Haskell: Lecture 2
Real World Haskell: Lecture 2
 
ECS140A-F16-07 October 27, 2016ASSIGNMENT 5 LISPDue .docx
ECS140A-F16-07 October 27, 2016ASSIGNMENT 5 LISPDue .docxECS140A-F16-07 October 27, 2016ASSIGNMENT 5 LISPDue .docx
ECS140A-F16-07 October 27, 2016ASSIGNMENT 5 LISPDue .docx
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
 
Class 11: Deeper List Procedures
Class 11: Deeper List ProceduresClass 11: Deeper List Procedures
Class 11: Deeper List Procedures
 
Type header file in c++ and its function
Type header file in c++ and its functionType header file in c++ and its function
Type header file in c++ and its function
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskell
 
Data transformation-cheatsheet
Data transformation-cheatsheetData transformation-cheatsheet
Data transformation-cheatsheet
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
 
Statistics lab 1
Statistics lab 1Statistics lab 1
Statistics lab 1
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 

Plus de Jack Fox

Plus de Jack Fox (10)

Dependent Types make bad data unrepresentable
Dependent Types make bad data unrepresentableDependent Types make bad data unrepresentable
Dependent Types make bad data unrepresentable
 
Dependent Types
Dependent TypesDependent Types
Dependent Types
 
Tools for reading papers
Tools for reading papersTools for reading papers
Tools for reading papers
 
Functional programming for production quality code
Functional programming for production quality codeFunctional programming for production quality code
Functional programming for production quality code
 
Intoduction to Homotopy Type Therory
Intoduction to Homotopy Type TheroryIntoduction to Homotopy Type Therory
Intoduction to Homotopy Type Therory
 
Type Theory and Practical Application
Type Theory and Practical ApplicationType Theory and Practical Application
Type Theory and Practical Application
 
F# for functional enthusiasts
F# for functional enthusiastsF# for functional enthusiasts
F# for functional enthusiasts
 
Semantically coherent functional linear data structures
Semantically coherent functional linear data structuresSemantically coherent functional linear data structures
Semantically coherent functional linear data structures
 
Linear structures lightning talk
Linear structures lightning talkLinear structures lightning talk
Linear structures lightning talk
 
Functional linear data structures in f#
Functional linear data structures in f#Functional linear data structures in f#
Functional linear data structures in f#
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Dernier (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

Introduction to the lambda calculus

  • 1. Introduction to the Lambda Calculus Alonzo Church 1932, “A set of postulates for the foundation of logic”, a formal system with the aim of providing a foundation for logic which would be more natural than Russell’s type theory or Zermelo’s set theory, and would not contain free variables 1936 Church isolated and published just the portion relevant to computation, what is now called the untyped lambda calculus 1940, he also introduced a computationally weaker, but logically consistent system, known as the simply typed lambda calculus Re-discovered as a versatile tool in Computer Science by people like McCarthy, et al. in the 1960s
  • 2. Operational Semantics -- Syntax t ::= x /* variable */ λx.t /* abstraction */ t t /* application */ v ::= λx.t /* abstraction value */
  • 3. Operational Semantics -- Evaluation t1 t1' /* congruence rule 1 */ t1 t2 t1' t2 t2 t2' /* congruence rule 2 */ v1 t2 v1 t2' (λx.t) v [x ↦ v]t /* computation rule */
  • 4. That’s it! No data structures No control flow statements No strings, numbers, or even booleans Any questions?
  • 5. Any questions? Like, how do you do anything?
  • 6. Church encoding representing data and operators in the lambda calculus
  • 7. Let’s start with the booleans true = λt. λf. t false = λt. λf. f not = λa. a false true
  • 8. Applying not (λa. a false true) true (λa. a false true) (λt. λf. t) (λt. λf. t) false true false (λx.t) v [x ↦ v]t (from operational semantic rules)
  • 9. β-reduction applying functions to their arguments Normal order reduction – most well-known languages work from the leftmost, outermost, redex and work in, halting when the outermost argument can no longer be applied Redex – reducible expression Full β-reduction – reduce available redexes in any desired order
  • 10. Full β-reduction λs.λz. (λs'.λz'. (λb. b) s' ((λt.λb. b) s' z')) s ((λs'.λz'. (λs''.λz''. (λb. b) s'' ((λt.λb. b) s'' z'')) s' ((λt.λb. b) s' z')) s z)
  • 11. Full β-reduction λs.λz. (λs'.λz'. s' z') s ((λs'.λz'. (λs''.λz''. s'' z'') s' z') s z)
  • 12. Full β-reduction λs.λz. s ((λs'.λz'. (λs''.λz''. s'' z'') s' z') s z)
  • 13. Full β-reduction λs.λz. s ((λs'.λz'. s' z') s z)
  • 15. Back to the booleans and = λa. λb. a b fls or = λa. λb. a tru b nand = λa. λb. not (and a b) xor = λa. λb. and (nand a b) (or a b) cond = λp. λt. λf. p t f /* i.e. if else */
  • 16. and (λa. λb. a b fls) tru fls (λt. λf. t) (λt. λf. f) (λt. λf. f) λt. λf. f (λa. λb. a b fls) tru tru (λt. λf. t) (λt. λf. t) (λt. λf. f) λt. λf. t
  • 17. Hooray! xnor = λa. λb. not (xor a b)
  • 18. Now we have assertions! xnor = λa. λb. not (xor a b) xnor tru (cond fls fls tru) xnor fls (cond fls tru fls)
  • 19. Tuples pair = λf. λs. λb. b f s fst = λp. p tru snd = λp. p fls
  • 20. Numbers c0 = λs. λz. z c1 = λs. λz. s z c2 = λs. λz. s (s z) c3 = λs. λz. s (s (s z)) … Just like Peano arithmetic
  • 21. Operations on numbers iszro = λm. m (λx. fls) tru plus = λm. λn. λs. λz. m s (n s z) mult = λm. λn. m (plus n) c0 exp = λm. λn. n (mult m) c1 scc = λn. λs. λz. s (n s z) /* number successor */ /* number predecessor */ prd = λm. fst (m (λp. pair (snd p) (plus c1 (snd p))) (pair c0 c0)) eql = λm. λn. and (iszro (m prd n)) (iszro (n prd m))
  • 22. Automating assertions /* it is true that ... */ xnor tru (eql c1 (exp c1 c1)) xnor tru (eql c6 (plus c2 c4)) xnor tru (eql c1 (fst (pair c1 tru)))
  • 23. Lists Lists follow from tuples and numbers (more on that another time)
  • 24. Recursion fix (a.k.a the Y-combinator) = λf. (λx. f (λy. x x y)) (λx. f (λy. x x y)) takes recursive abstraction λf. λx. __f__ Haskell Curry
  • 25. Recursion (λf. (λx. f (λy. x x y)) (λx. f (λy. x x y))) (λf. λx. __) (bar) (λx. (λf. λx'. __) (λy. x x y)) (λx. (λf. λx'. __) (λy. x x y)) (bar) (foo) (λf. λx'. __) (λy. foo foo y) (bar) λx'. __ (bar)
  • 26. Recursion fact = λf. λx. cond (iszro x) c1 (mult x (f (prd x))) (λf. (λx. f (λy. x x y)) (λx. f (λy. x x y))) fact c3 /* successive interations */ (λy. (λx. f (λy'.x x y')) (λx. f (λy'.x x y')) y) (/* prev recurs*/)