Gabriel Lebec
October 15, 2020
220

# Lambda Calc Talk (FrontSide Version)

Slightly modified / updated version of my LC talk, delivered remotely for the FrontSide conference in Paris, France. For the original version, see https://github.com/glebec/lambda-talk. For a follow-up code examples repo including the Z-combinator, see https://github.com/glebec/lambda-talk-practical.

October 15, 2020

## Transcript

1. as.js
A FL O C K of FU N C T I O N S
COMBINATORS, LAMBDA CALCULUS,
& CHURCH ENCODINGS in JAVASCRIPT

2. glebec
glebec
glebec
glebec
g_lebec

Gabriel Lebec
github.com/glebec/lambda-talk
formerly @
currently*@
presenting @
*Views and opinions in this presentation
are my own and do not represent
those of my employer.

3. a.a
IDENTITY

4. λ
JS I = a => a
I := a.a

5. λ
JS I = a => a
I := a.a

6. λ
JS I(x) === ?
I x = ?
I := a.a
I = a => a

7. λ
JS I(x) === x
I x = x
I := a.a
I = a => a

8. λ
JS I(I) === ?
I I = ?
I := a.a
I = a => a

9. λ
JS I(I) === I
I I = I
I := a.a
I = a => a

10. id 5 == 5

11. ?

12. a.a

13. a.a
FUNCTION
SIGNIFIER

14. a.a
FUNCTION
SIGNIFIER
PARAMETER VARIABLE

15. a.a
FUNCTION
SIGNIFIER
PARAMETER VARIABLE
RETURN
EXPRESSION

16. a.a
FUNCTION
SIGNIFIER
PARAMETER VARIABLE
RETURN
EXPRESSION
LAMBDA ABSTRACTION

17. -CALCULUS SYNTAX
expression ::= variable identifier
| expression expression application
| variable . expression abstraction
| ( expression ) grouping

18. λ JS

19. VARIABLES
x x
(a) (a)

20. f a f(a)
f a b f(a)(b)
(f a) b (f(a))(b)
f (a b) f(a(b))
APPLICATIONS

21. a.b a => b
a.b x a => b(x)
a.(b x) a => (b(x))
(a.b) x (a => b)(x)
a.b.a a => b => a
a.(b.a) a => (b => a)
ABSTRACTIONS

22. ((a.a)b.c.b)(x)e.f
β-REDUCTION

23. ((a.a)b.c.b)(x)e.f
β-REDUCTION

24. ((a.a)b.c.b)(x)e.f
β-REDUCTION

25. ((a.a)b.c.b)(x)e.f
= (b.c.b) (x)e.f
β-REDUCTION

26. ((a.a)b.c.b)(x)e.f
= (b.c.b) (x)e.f
β-REDUCTION

27. ((a.a)b.c.b)(x)e.f
= (b.c.b) (x)e.f
β-REDUCTION

28. ((a.a)b.c.b)(x)e.f
= (b.c.b) (x)e.f
β-REDUCTION

29. ((a.a)b.c.b)(x)e.f
= (b.c.b) (x)e.f
= (c.x) e.f
β-REDUCTION

30. ((a.a)b.c.b)(x)e.f
= (b.c.b) (x)e.f
= (c.x) e.f
β-REDUCTION

31. ((a.a)b.c.b)(x)e.f
= (b.c.b) (x)e.f
= (c.x) e.f
β-REDUCTION

32. ((a.a)b.c.b)(x)e.f
= (b.c.b) (x)e.f
= (c.x) e.f
β-REDUCTION

33. ((a.a)b.c.b)(x)e.f
= (b.c.b) (x)e.f
= (c.x) e.f
= x
β-REDUCTION

34. ((a.a)b.c.b)(x)e.f
= (b.c.b) (x)e.f
= (c.x) e.f
= x
β-REDUCTION

35. ((a.a)b.c.b)(x)e.f
= (b.c.b) (x)e.f
= (c.x) e.f
= x
β-REDUCTION
β-NORMAL FORM

36. ((a.a)b.c.b)(x)e.f
= (b.c.b) (x)e.f
= (c.x) e.f
= x
β-REDUCTION*
β-NORMAL FORM
*not covered: evaluation order, variable collision avoidance

37. f.ff
MOCKINGBIRD

38. λ
JS M = f => f(f)
M := f.ff

39. λ
JS M = f => f(f)
M := f.ff

40. λ
JS M = f => f(f)
M := f.ff

41. λ
JS M = f => f(f)
M := f.ff

42. λ
JS M(I) === ?
M I = ?
M := f.ff

43. λ
JS M(I) === I(I)
M I = I I
M := f.ff

44. λ
JS M(I) === I(I)
&& I(I) === ?
M I = I I = ?
M := f.ff

45. λ
JS M(I) === I(I)
&& I(I) === I
M I = I I = I
M := f.ff

46. λ
JS M(M) === ?
M M = ?
M := f.ff

47. λ
JS M(M) === M(M)
M M = M M
M := f.ff

48. λ
JS M(M) === M(M) === ?
M M = M M = ?
M := f.ff

49. λ
JS M(M) === M(M) ===
M M = M M = M M = …
// stack overflow
M := f.ff
M(M) === M(M) === M(M) === M(M) === M
M(M) === M(M) === M(M) === M(M) === M
M(M) === M(M) === M(M) === M(M) === M
M(M) === M(M) === M(M) === M(M) === M
M(M) === M(M) === M(M) === M(M) === M

50. λ
JS
M M = M M = M M = Ω
// stack overflow
M := f.ff
M(M) === M(M) === M(M) === M(M) === M
M(M) === M(M) === M(M) === M(M) === M
M(M) === M(M) === M(M) === M(M) === M
M(M) === M(M) === M(M) === M(M) === M
M(M) === M(M) === M(M) === M(M) === M

51. a.b.c.b a => b => c => b
abc.b a => b => c => b
(a, b, c) => b
=
ABSTRACTIONS, again

52. ((a.a)bc.b)(x)e.f
β-REDUCTION, again

53. ((a.a)bc.b)(x)e.f
β-REDUCTION, again

54. ((a.a)bc.b)(x)e.f
β-REDUCTION, again

55. ((a.a)bc.b)(x)e.f
= (bc.b) (x)e.f
β-REDUCTION, again

56. ((a.a)bc.b)(x)e.f
= (bc.b) (x)e.f
β-REDUCTION, again

57. ((a.a)bc.b)(x)e.f
= (bc.b) (x)e.f
β-REDUCTION, again

58. ((a.a)bc.b)(x)e.f
= (bc.b) (x)e.f
β-REDUCTION, again

59. ((a.a)bc.b)(x)e.f
= (bc.b) (x)e.f
= (c.x) e.f
β-REDUCTION, again

60. ((a.a)bc.b)(x)e.f
= (bc.b) (x)e.f
= (c.x) e.f
β-REDUCTION, again

61. ((a.a)bc.b)(x)e.f
= (bc.b) (x)e.f
= (c.x) e.f
β-REDUCTION, again

62. ((a.a)bc.b)(x)e.f
= (bc.b) (x)e.f
= (c.x) e.f
β-REDUCTION, again

63. ((a.a)bc.b)(x)e.f
= (bc.b) (x)e.f
= (c.x) e.f
= x
β-REDUCTION, again

64. ((a.a)bc.b)(x)e.f
= (bc.b) (x)e.f
= (c.x) e.f
= x
β-REDUCTION, again

65. ((a.a)bc.b)(x)e.f
= (bc.b) (x)e.f
= (c.x) e.f
= x
β-REDUCTION, again
β-NORMAL FORM

66. ab.a
KESTREL

67. λ
JS K = a => b => a
K := ab.a
= a.b.a

68. λ
JS K(M)(I) === ?
K M I = ?
K := ab.a
K = a => b => a

69. λ
JS K(M)(I) === M
K M I = M
K := ab.a
K = a => b => a

70. λ
JS K(M)(I) === M
K(I)(M) === ?
K M I = M
K I M = ?
K := ab.a
K = a => b => a

71. λ
JS K(M)(I) === M
K(I)(M) === I
K M I = M
K I M = I
K := ab.a
K = a => b => a

72. const 7 2 == 7

73. λ
JS K(I)(x) === ?
K I x = ?
K := ab.a
K = a => b => a

74. λ
JS K(I)(x) === I
K I x = I
K := ab.a
K = a => b => a

75. λ
JS K(I)(x)(y) === I(y)
K I x y = I y
K := ab.a
K = a => b => a

76. λ
JS K(I)(x)(y) === I(y)
&& I(y) === ?
K I x y = I y = ?
K := ab.a
K = a => b => a

77. λ
JS
K I x y = I y = y
K := ab.a
K = a => b => a
K(I)(x)(y) === I(y)
&& I(y) === y

78. λ
JS
K I x y = I y = y
K := ab.a
K = a => b => a
K(I)(x)(y) === I(y)
&& I(y) === y

79. λ
JS
K I x y = I y = y
K := ab.a
K = a => b => a
K(I)(x)(y) === I(y)
&& I(y) === y

80. ab.b
KITE

81. λ
JS KI = a => b => b
KI = K(I)
KI := ab.b
= K I

82. λ
JS KI(M)(K) === ?
KI M K = ?
KI := ab.b
KI = a => b => b

83. λ
JS KI(M)(K) === K
KI M K = K
KI := ab.b
KI = a => b => b

84. λ
JS KI(M)(K) === K
KI(K)(M) === ?
KI M K = K
KI K M = ?
KI := ab.b
KI = a => b => b

85. λ
JS KI(M)(K) === K
KI(K)(M) === M
KI M K = K
KI K M = M
KI := ab.b
KI = a => b => b

86. λ
JS KI(M)(K) === K
KI(K)(M) === M
KI M K = K
KI K M = M
KI := ab.b
KI = a => b => b

87. ?

88. SCHÖNFINKEL CURRY SMULLYAN
Identitätsfunktion
Konstante Funktion
verSchmelzungsfunktion
verTauschungsfunktion
Zusammensetzungsf.
I
K
S
C
B
Idiot
Kestrel
Starling
Cardinal
Bluebird
Ibis?

89. ?

90. PEANO
FREGE
RUSSELL
SCHÖNFINKEL
VON NEUMANN
CURRY CHURCH
GÖDEL
TURING
KLEENE ROSSER
TH E FO R M A L I Z AT I O N O F
MAT H E M AT I C A L LO G I C
PÉTER

91. PEANO
FREGE
RUSSELL
SCHÖNFINKEL
VON NEUMANN
CURRY CHURCH
GÖDEL
TURING
KLEENE ROSSER
FO R M A L NO TAT I O N FO R FU N C T I O N S
1889
PE A N O AR I T H M E T I C
PÉTER

92. PEANO
FREGE
RUSSELL
SCHÖNFINKEL
VON NEUMANN
CURRY CHURCH
GÖDEL
TURING
KLEENE ROSSER
AX I O M AT I C LO G I C · FN NO TAT I O N
FU N C T I O N S A S GR A P H S · CU R RY I N G
1891
PÉTER

93. PEANO
FREGE
RUSSELL
SCHÖNFINKEL
VON NEUMANN
CURRY CHURCH
GÖDEL
TURING
KLEENE ROSSER
PR I N C I P I A MAT H E M AT I C A
1910
RU S S E L L ’S PA R A D OX · FN NO TAT I O N
PÉTER

94. PEANO
FREGE
RUSSELL
SCHÖNFINKEL
VON NEUMANN
CURRY CHURCH
GÖDEL
TURING
KLEENE ROSSER
CO M B I N AT O RY LO G I C
CO M B I N AT O R S · CU R RY I N G
1920
PÉTER

95. PEANO
FREGE
RUSSELL
SCHÖNFINKEL
VON NEUMANN
CURRY CHURCH
GÖDEL
TURING
KLEENE ROSSER
FU N C T I O N A L SY S T E M O F SE T TH E O RY
1925
(OV E R L A P P E D W I T H CO M B I N AT O RY LO G I C )
PÉTER

96. PEANO
FREGE
RUSSELL
SCHÖNFINKEL
VON NEUMANN
CURRY CHURCH
GÖDEL
TURING
KLEENE ROSSER
CO M B I N AT O RY LO G I C (AG A I N )
CO M B I N AT O R S · M A N Y C O N T R I B U T I O N S
1926
PÉTER

97. PEANO
FREGE
RUSSELL
SCHÖNFINKEL
VON NEUMANN
CURRY CHURCH
GÖDEL
TURING
KLEENE ROSSER
D I S C OV E R S SC H Ö N F I N K E L
“This paper anticipates much of what I have done.”
1927
PÉTER

98. PEANO
FREGE
RUSSELL
SCHÖNFINKEL
VON NEUMANN
CURRY CHURCH
GÖDEL
TURING
KLEENE ROSSER
IN C O M P L E T E N E S S TH E O R E M S
1931
EN D I N G T H E SE A RC H FO R SU F F I C I E N T AX I O M S
PÉTER

99. PEANO
FREGE
RUSSELL
SCHÖNFINKEL
VON NEUMANN
CURRY CHURCH
GÖDEL
TURING
KLEENE ROSSER
RE C U R S I V E FU N C T I O N TH E O RY
1932
RE K U R S I V E FU N K T I O N E N
PÉTER

100. PEANO
FREGE
RUSSELL
SCHÖNFINKEL
VON NEUMANN
CURRY CHURCH
GÖDEL
TURING
KLEENE ROSSER
-CA L C U L U S
AN EF F E C T I V E MO D E L O F CO M P U TAT I O N
1932
PÉTER

101. PEANO
FREGE
RUSSELL
SCHÖNFINKEL
VON NEUMANN
CURRY CHURCH
GÖDEL
TURING
KLEENE ROSSER
I N C O N S I S T E N C Y O F S P E C I A L I Z E D
1931–1936
C O N S I S T E N C Y O F P U R E
PÉTER

102. PEANO
FREGE
RUSSELL
SCHÖNFINKEL
VON NEUMANN
CURRY CHURCH
GÖDEL
TURING
KLEENE ROSSER
SO LV E S T H E DE C I S I O N PRO B L E M
V I A T H E -CA L C U L U S
1936
PÉTER

103. PEANO
FREGE
RUSSELL
SCHÖNFINKEL
VON NEUMANN
CURRY CHURCH
GÖDEL
TURING
KLEENE ROSSER
SO LV E S T H E DE C I S I O N PRO B L E M
1936
V I A T H E TU R I N G MAC H I N E
PÉTER

104. PEANO
FREGE
RUSSELL
SCHÖNFINKEL
VON NEUMANN
CURRY CHURCH
GÖDEL
TURING
KLEENE ROSSER
ES TA B L I S H E S T H E CH U RC H -TU R I N G TH E S I S
1936
-CA L C U L U S 㱻 TU R I N G MAC H I N E
PÉTER

105. PEANO
FREGE
RUSSELL
SCHÖNFINKEL
VON NEUMANN
CURRY CHURCH
GÖDEL
TURING
KLEENE ROSSER
O B TA I N S PH D U N D E R CH U RC H
1936–1938
PU B L I S H E S 1S T FI X E D -PO I N T CO M B I N AT O R
PÉTER

106. combinator?

107. COMBINATORS
functions with no free variables

108. COMBINATORS
functions with no free variables
b.b combinator
b.a not a combinator

109. COMBINATORS
functions with no free variables
b.b combinator
b.a not a combinator
ab.a combinator
a.ab not a combinator

110. COMBINATORS
functions with no free variables
b.b combinator
b.a not a combinator
ab.a combinator
a.ab not a combinator
abc.c(e.b) combinator

111. COMBINATORS
I Idiot a.a identity id
M Mockingbird f.ﬀ self-application (cannot deﬁne)
K Kestrel ab.a ﬁrst, const const
KI Kite ab.b = KI second const id
C Cardinal fab.fba reverse arguments flip
B Bluebird fga.f(ga) 1°-1° composition (.)
B1
Blackbird fgab.f(gab) = BBB 1°-2° composition (.) . (.)
Th
Thrush af.fa = CI hold an argument flip id
V Vireo abf.fab = BCT hold a pair of args flip . flip id

112. CARDINAL
fab.fba

113. λ
JS C = f => a => b => f(b)(a)
C := fab.fba

114. λ
JS C(K)(I)(M) === ?
C K I M = ?
C := fab.fba
C = f => a => b => f(b)(a)

115. λ
JS C(K)(I)(M) === M
C K I M = M
C := fab.fba
C = f => a => b => f(b)(a)

116. λ
JS C(K)(I)(M) === M
C K I M = M
C := fab.fba
C = f => a => b => f(b)(a)

117. λ
JS KI(I)(M) === M
KI I M = M
C := fab.fba
C = f => a => b => f(b)(a)

118. COMBINATORS
I Idiot a.a identity id
M Mockingbird f.ﬀ self-application (cannot deﬁne)
K Kestrel ab.a ﬁrst, const const
KI Kite ab.b = KI second const id
C Cardinal fab.fba reverse arguments flip
B Bluebird fga.f(ga) 1°-1° composition (.)
B1
Blackbird fgab.f(gab) = BBB 1°-2° composition (.) . (.)
Th
Thrush af.fa = CI hold an argument flip id
V Vireo abf.fab = BCT hold a pair of args flip . flip id

119. COMBINATORS
I Idiot a.a identity id
M Mockingbird f.ﬀ self-application (cannot deﬁne)
K Kestrel ab.a ﬁrst, const const
KI Kite ab.b = KI second const id
C Cardinal fab.fba reverse arguments flip
B Bluebird fga.f(ga) 1°-1° composition (.)
B1
Blackbird fgab.f(gab) = BBB 1°-2° composition (.) . (.)
Th
Thrush af.fa = CI hold an argument flip id
V Vireo abf.fab = BCT hold a pair of args flip . flip id

120. COMBINATORS
I Idiot a.a identity id
M Mockingbird f.ﬀ self-application (cannot deﬁne)
K Kestrel ab.a ﬁrst, const const
KI Kite ab.b = KI = CK second const id
C Cardinal fab.fba reverse arguments flip
B Bluebird fga.f(ga) 1°-1° composition (.)
B1
Blackbird fgab.f(gab) = BBB 1°-2° composition (.) . (.)
Th
Thrush af.fa = CI hold an argument flip id
V Vireo abf.fab = BCT hold a pair of args flip . flip id

121. flip const 1 8 == 8

122. so?

123. -CALCULUS
abstract symbol rewriting
functional computation
TURING MACHINE
hypothetical device
state-based computation
(f.ff)a.a
purely functional programming languages
higher-level machine-centric languages
assembly languages
machine code
higher-level abstract stateful languages
real computers

124. TM

125. EVERYTHING
CAN BE
FUNCTIONS
*though in FP, not everything
IS or SHOULD BE functions
**but maybe more than you expect

126. TRUE FALSE NOT AND OR BEQ

127. !x == y || (a && z)

128. !x == y || (a && z)

129. how‽

130. λ
JS bool

131. λ
JS const result = bool ? exp1 : exp2

132. λ
JS const result = bool ? exp1 : exp2
// true

133. λ
JS const result = bool ? exp1 : exp2
// false

134. λ
JS const result = bool ? exp1 : exp2

135. λ
JS const result = bool ? exp1 : exp2
result := ?

136. λ
JS const result = bool ? exp1 : exp2
result := bool ? exp1 : exp2

137. λ
JS const result = bool ? exp1 : exp2
result := bool ? exp1 : exp2

138. λ
JS const result = bool ? exp1 : exp2
result := bool exp1 exp2

139. λ
JS const result = bool (exp1) (exp2)
result := func exp1 exp2

140. λ
JS
result := func exp1 exp2
const result = bool (exp1) (exp2)
// true

141. λ
JS
result := func exp1 exp2
const result = bool (exp1) (exp2)
// false

142. λ
JS const result = bool (exp1) (exp2)
result := func exp1 exp2
TRUE
FALSE

143. λ
JS const result = bool (exp1) (exp2)
result := func exp1 exp2
K
KI

144. λ
JS const T = K
const F = KI
TRUE := K
FALSE := KI = C K
CHURCH ENCODINGS: BOOLEANS

145. λ
JS p

146. λ
JS !p

147. λ
JS !p
! p

148. λ
JS !p
! p

149. λ
JS not(p)
NOT p

150. λ
JS not(T) === F
not(F) === T
NOT T = F
NOT F = T

151. λ
JS not(K) === KI
not(KI) === K
NOT K = KI
NOT (KI) = K

152. λ
JS not(K) === KI
not(KI) === K
NOT K = KI
NOT (KI) = K
ab.a ba.a
ba.a ab.a

153. λ
JS C(K) (chirp)(tweet) === tweet
C(KI)(chirp)(tweet) === chirp
C K = KI
C (KI) = K

154. λ
JS C(T) (chirp)(tweet) === tweet
C(F) (chirp)(tweet) === chirp
C T = F
C F = T

155. CHURCH ENCODINGS: BOOLEANS
Sym. Name -Calculus Use
T TRUE ab.a = K encoding for true
F FALSE ab.b = KI = CK encoding for false
NOT p.pFT negation
AND pq.pqF or pq.pqp conjunction
OR pq.pTq or pq.ppq disjunction
BEQ pq.p q (NOT q) equality

156. CHURCH ENCODINGS: BOOLEANS
Sym. Name -Calculus Use
T TRUE ab.a = K encoding for true
F FALSE ab.b = KI = CK encoding for false
NOT C negation
AND pq.pqF or pq.pqp conjunction
OR pq.pTq or pq.ppq disjunction
BEQ pq.p q (NOT q) equality

157. λ
JS not(p)
NOT p
F
T
F
T

158. λ
JS not(T)
NOT T
F
T
F
T

159. λ
JS not(F)
NOT F
F
T
F
T

160. λ
JS not( )
NOT
F
T
F
T
p
p

161. λ
JS p F T
F T
p
( )
( )

162. λ
JS T F T
F T
T
( )
( )
K
K

163. λ
JS ( ) ( )
T F T
F T
T
K
K
KI
KI

164. λ
JS p F T
F T
p
( )
( )

165. λ
JS ( ) ( )
F F T
F T
F
KI
KI

166. λ
JS ( ) ( )
F F T
F T
F
KI
KI K
K

167. λ
JS p F T
F T
p
( )
( )

168. λ
JS p F T
F T
p
( )
( )
p .
p =>

169. λ
JS const not = p => p(F)(T)
NOT := p.pFT

170. CHURCH ENCODINGS: BOOLEANS
Sym. Name -Calculus Use
T TRUE ab.a = K encoding for true
F FALSE ab.b = KI = CK encoding for false
NOT C negation
AND pq.pqF or pq.pqp conjunction
OR pq.pTq or pq.ppq disjunction
BEQ pq.p q (NOT q) equality

171. CHURCH ENCODINGS: BOOLEANS
Sym. Name -Calculus Use
T TRUE ab.a = K encoding for true
F FALSE ab.b = KI = CK encoding for false
NOT p.pFT or C negation
AND pq.pqF or pq.pqp conjunction
OR pq.pTq or pq.ppq disjunction
BEQ pq.p q (NOT q) equality

172. λ
JS const and = ?
AND := ?

173. λ
JS const and = ? => ?
AND := ?.?

174. λ
JS const and = p => q => ?
AND := pq.?

175. λ
JS const and = p => q => p…
AND := pq.p…

176. λ
JS const and = p => q => p(?)(¿)
AND := pq.p?¿

177. λ
JS const and = p => q => p(?)(¿)
AND := pq.p?¿
F
F

178. λ
JS const and = p => q => p(?)(¿)
AND := pq.p?¿
F
F

179. λ
JS const and = p => q => p(?)(F)
AND := pq.p?F

180. λ
JS const and = p => q => p(?)(F)
AND := pq.p?F
T
T

181. λ
JS const and = p => q => p(?)(F)
AND := pq.p?F
T
T

182. λ
JS const and = p => q => p(q)(F)
AND := pq.pqF

183. pq.p F
q

184. pq.p
F
q

185. pq.p
p
q

186. pq.p p
q

187. CHURCH ENCODINGS: BOOLEANS
Sym. Name -Calculus Use
T TRUE ab.a = K encoding for true
F FALSE ab.b = KI = CK encoding for false
NOT p.pFT or C negation
AND pq.pqF or pq.pqp conjunction
OR pq.pTq or pq.ppq disjunction
BEQ pq.p q (NOT q) equality

188. CHURCH ENCODINGS: BOOLEANS
Sym. Name -Calculus Use
T TRUE ab.a = K encoding for true
F FALSE ab.b = KI = CK encoding for false
NOT p.pFT or C negation
AND pq.pqF or pq.pqp conjunction
OR pq.pTq or pq.ppq disjunction
BEQ pq.p q (NOT q) equality

189. λ
JS const or = ?
OR := ?

190. λ
JS const or = p => q => …
OR := pq.…

191. λ
JS const or = p => q => p(?)(¿)
OR := pq.p?¿

192. λ
JS const or = p => q => p(T)(¿)
OR := pq.pT¿

193. λ
JS const or = p => q => p(T)(q)
OR := pq.pTq

194. λ
JS const or = p => q => p(p)(q)
OR := pq.ppq

195. CHURCH ENCODINGS: BOOLEANS
Sym. Name -Calculus Use
T TRUE ab.a = K encoding for true
F FALSE ab.b = KI = CK encoding for false
NOT p.pFT or C negation
AND pq.pqF or pq.pqp conjunction
OR pq.pTq or pq.ppq disjunction
BEQ pq.p q (NOT q) equality

196. CHURCH ENCODINGS: BOOLEANS
Sym. Name -Calculus Use
T TRUE ab.a = K encoding for true
F FALSE ab.b = KI = CK encoding for false
NOT p.pFT or C negation
AND pq.pqF or pq.pqp conjunction
OR pq.pTq or pq.ppq disjunction
BEQ pq.p q (NOT q) equality

197. pq.ppq

198. ( pq.ppq ) xy

199. ( pq.ppq ) xy = ?

200. ( pq.ppq ) xy = xxy

201. ( pq.ppq ) xy = xxy
( ? ) xy = xxy

202. ( pq.ppq ) xy = xxy
( ? ) xy = xxy

203. ( pq.ppq ) xy = xxy
M xy = xxy

204. ( pq.ppq ) xy = xxy
M xy = xxy

205. CHURCH ENCODINGS: BOOLEANS
Sym. Name -Calculus Use
T TRUE ab.a = K encoding for true
F FALSE ab.b = KI = CK encoding for false
NOT p.pFT or C negation
AND pq.pqF or pq.pqp conjunction
OR pq.pTq or pq.ppq disjunction
BEQ pq.p q (NOT q) equality

206. CHURCH ENCODINGS: BOOLEANS
Sym. Name -Calculus Use
T TRUE ab.a = K encoding for true
F FALSE ab.b = KI = CK encoding for false
NOT p.pFT or C negation
AND pq.pqF or pq.pqp conjunction
OR pq.pTq or pq.ppq = M* disjunction
BEQ pq.p q (NOT q) equality

207. ( )
pq.p( ) T
T F F
q
q
p => q => p(q(T)(F))(q(F)(T))

208. ( )
pq.p( ) T
T F F
q
q

209. ( )
pq.p( ) T
T F F
q
q

210. ( )
pq.p( ) T
T F F
q
q

211. ( )
pq.p
( )
T
T F
F
q
q

212. ( )
pq.p
( )
T
T
F
F
q
q

213. ( )
pq.p
( )
T
T
F
F
q
q

214. ( )
pq.p
( )
T
T
F
F
q
q

215. ( )
pq.p
( )
T
T
F
F
q
q

216. ( )
pq.p
( )
T
T
F
F
q
q

217. ( )
pq.p
( )
T
T
F
F
q
q

218. ( )
pq.p
( )
T
T
F
F
q
q
BOOLEAN EQUALITY

219. pq.p
( )
T
F
q
q

220. ( )
pq.p
q
NOT
q

221. ( )
pq.p q
q NOT

222. ( )
pq.p q
q NOT
p => q => p(q)(not(q))

223. CHURCH ENCODINGS: BOOLEANS
Sym. Name -Calculus Use
T TRUE ab.a = K encoding for true
F FALSE ab.b = KI = CK encoding for false
NOT p.pFT or C negation
AND pq.pqF or pq.pqp conjunction
OR pq.pTq or pq.ppq = M* disjunction
BEQ pq.p q (NOT q) equality

224. CHURCH ENCODINGS: BOOLEANS
Sym. Name -Calculus Use
T TRUE ab.a = K encoding for true
F FALSE ab.b = KI = CK encoding for false
NOT p.pFT or C negation
AND pq.pqF or pq.pqp conjunction
OR pq.pTq or pq.ppq = M* disjunction
BEQ pq.p q (NOT q) equality

225. (ONE OF) DE MORGAN'S LAWS
¬(P ∧ Q) = (¬P) ∨ (¬Q)
BEQ (NOT (AND p q)) (OR (NOT p) (NOT q))
!(p && q) === (!p) || (!q)

226. BEQ (NOT (AND p q)) (OR (NOT p) (NOT q))
(xy.x y ((fab.fba) y))
((fab.fba) ((xy.xyx) p q))
((f.ff) ((fab.fba) p) ((fab.fba) q))

227. BEQ (NOT (AND p q)) (OR (NOT p) (NOT q))
(xy.x y ((fab.fba) y))
((fab.fba) ((xy.xyx) p q))
((f.ff) ((fab.fba) p) ((fab.fba) q))

228. BEQ (NOT (AND p q)) (OR (NOT p) (NOT q))
(xy.x y ((fab.fba) y))
((fab.fba) ((xy.xyx) p q))
((f.ff) ((fab.fba) p) ((fab.fba) q))

229. BEQ (NOT (AND p q)) (OR (NOT p) (NOT q))
(xy.x y ((fab.fba) y))
((fab.fba) ((xy.xyx) p q))
((f.ff) ((fab.fba) p) ((fab.fba) q))

230. BEQ (NOT (AND p q)) (OR (NOT p) (NOT q))
(xy.x y ((fab.fba) y))
((fab.fba) ((xy.xyx) p q))
((f.ff) ((fab.fba) p) ((fab.fba) q))

231. BEQ (NOT (AND p q)) (OR (NOT p) (NOT q))
(xy.x y ((fab.fba) y))
((fab.fba) ((xy.xyx) p q))
((f.ff) ((fab.fba) p) ((fab.fba) q))

232. BEQ (NOT (AND p q)) (OR (NOT p) (NOT q))
(xy.x y ((fab.fba) y))
((fab.fba) ((xy.xyx) p q))
((f.ff) ((fab.fba) p) ((fab.fba) q))

233. BEQ (NOT (AND p q)) (OR (NOT p) (NOT q))
(xy.x y ((fab.fba) y))
((fab.fba) ((xy.xyx) p q))
((f.ff) ((fab.fba) p) ((fab.fba) q))

234. WHAT ELSE CAN WE INVENT?
numbers
arithmetic
data structures
type systems
recursion
Sorry… can't ﬁt them all in today!
See part II online

235. B C K I
KI = K I = C K
B1
= B B B
Th
= C I
V = B C Th
= B C (C I)

236. QUESTION
how many combinators
are needed to form a basis?
20? 10? 5?

237. STARLING · KESTREL
S := abc.ac(bc)
K := ab.a

238. THE
SK
COMBINATOR
CALCULUS
SK

239. THE
SK
COMBINATOR
CALCULUS
SKI

240. I = ?

241. I = S K K

242. I = S K K
V = ?

243. I = S K K
V = (S(K((S((S(K((
S(KS))K)))S))(KK))))
((S(K(S((SK)K))))K)

244. BUT ACTUALLY…
1

245. IOTA
ι := f.(f abc.ac(bc))ab.a
I := ιι
K := ι(ι(ιι))
S := ι(ι(ι(ιι)))

246. seriously though,
why?

248. COMBINATORS
I Idiot a.a identity id
M Mockingbird f.ﬀ self-application (cannot deﬁne)
K Kestrel ab.a true, ﬁrst, const const
KI Kite ab.b = KI = CK false, second const id
C Cardinal fab.fba reverse arguments flip
B Bluebird fga.f(ga) 1°←1° composition (.)
Th
Thrush af.fa = CI hold an argument flip id
V Vireo abf.fab = BCT hold a pair of args flip . flip id
B1
Blackbird fgab.f(gab) = BBB 1°←2° composition (.) . (.)

249. CHURCH ENCODINGS: BOOLEANS
Sym. Name -Calculus Use
T TRUE ab.a = K = C(KI) encoding for true
F FALSE ab.b = KI = CK encoding for false
NOT p.pFT or C negation
AND pq.pqF or pq.pqp conjunction
OR pq.pTq or pq.ppq = M* disjunction
BEQ pq.p q (NOT q) equality

250. CHURCH ENCODINGS: NUMERALS
Sym. Name -Calculus Use
N0 ZERO fa.a = F apply f no times to a
N1 ONCE fa.f a = I* apply f once to a
N2 TWICE fa.f (f a) apply 2-fold f to a
N3 THRICE fa.f (f (f a)) apply 3-fold f to a
N4 FOURFOLD fa.f (f (f (f a))) apply 4-fold f to a
N5 FIVEFOLD fa.f (f (f (f (f a))))) apply 5-fold f to a

251. CHURCH ARITHMETIC
Name -Calculus Use
SUCC nf.B f (nf) = nfa.f(nfa) successor of n
ADD nk.n SUCC k = nkf.B (n f) (k f) addition of n and k
MULT nkf.n(kf) = B multiplication of n and k
POW nk.kn = Th
raise n to the power of k
PRED n.n (g.IS0 (g N1) I (B SUCC g)) (K N0) N0 predecessor of n
PRED n.FST (n Φ (PAIR N0 N0)) predecessor of n (easier)
SUB nk.k PRED n subtract k from n

252. CHURCH ARITHMETIC: BOOLEAN OPS
Name -Calculus Use
IS0 n.n (K F) T test if n = 0
LEQ nk.IS0 (SUB n k) test if n <= k
EQ nk.AND (LEQ n k) (LEQ k n) test if n = k
GT nk.B1
NOT LEQ test if n > k

253. CHURCH PAIRS
Sym. Name -Calculus Use
PAIR abf.fab = V pair two arguments
FST p.pK extract ﬁrst of pair
SND p.p(KI) extract second of pair
Φ PHI p.PAIR (SND p) (SUCC (SND p) copy 2nd to 1st, inc 2nd
SET1ST cp.PAIR c (SND p) set ﬁrst, immutably
SET2ND cp.PAIR (FST p) c set second, immutably

254. f.(x.f(xx))(x.f(xx))
THE Y FIXED-POINT COMBINATOR

255. f.(x.f(v.xxv))(x.f(v.xxv))
THE Z FIXED-POINT COMBINATOR