$30 off During Our Annual Pro Sale. View details »

Lambda as JS, or A Flock of Functions: Combinators, Lambda Calculus, and Church Encodings in JavaScript

Lambda as JS, or A Flock of Functions: Combinators, Lambda Calculus, and Church Encodings in JavaScript

🔗 Repo: https://github.com/glebec/lambda-talk
🔗 Video Part I: https://youtu.be/3VQ382QG-y4
🔗 Video Part II: https://youtu.be/pAnLQ9jwN-E

A presentation given at Fullstack Academy, by instructor Gabriel Lebec. The Lambda Calculus is a symbol manipulation system which suffices to calculate anything calculable. Developed in the 1930s by Alonzo Church, this branch of pure math forms the basis of many functional programming languages (such as Scheme and Haskell), and is explained here through the familiar lens of JavaScript. Along the way, related concepts like combinatory logic (investigated by Haskell B. Curry) and encodings are examined, building up boolean logic and arithmetic from scratch.

(Errata: 307–311 & 313, the JS function `eq` should be written as `gt`.)

Gabriel Lebec

August 24, 2017
Tweet

More Decks by Gabriel Lebec

Other Decks in Programming

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

  3. a.a IDENTITY

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

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

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

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

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

  9. λ JS I(x) === ? I x = ? I

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

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

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

    := a.a I = a => a
  13. id 5 == 5

  14. ?

  15. a.a FUNCTION SIGNIFIER

  16. a.a FUNCTION SIGNIFIER PARAMETER VARIABLE

  17. a.a FUNCTION SIGNIFIER PARAMETER VARIABLE RETURN EXPRESSION

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

  19. -CALCULUS SYNTAX expression ::= variable identifier | expression expression application

    | variable . expression abstraction | ( expression ) grouping
  20. λ JS →

  21. VARIABLES x x (a) (a)

  22. f a f(a) f a b f(a)(b) (f a) b

    (f(a))(b) f (a b) f(a(b)) APPLICATIONS
  23. 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
  24. ((a.a)b.c.b)(x)e.f β-REDUCTION

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

  26. ((a.a)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 β-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*

    β-NORMAL FORM *not covered: evaluation order, variable collision avoidance
  35. f.ff MOCKINGBIRD

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

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

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

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

  40. λ JS M(I) === ? M I = ? M

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

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

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

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

    M M = ? M := f.ff
  45. λ 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
  46. λ JS ω ω = ω ω = ω ω

    = Ω // 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
  47. a.b.c.b a => b => c => b abc.b a

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

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

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

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

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

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

    again β-NORMAL FORM
  54. ab.a KESTREL

  55. λ JS K = a => b => a K

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

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

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

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

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

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

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

    I = M K I M = I K := ab.a K = a => b => a
  63. const 7 2 == 7

  64. λ JS K(I)(x) === I K I x = I

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

    I x y = I y = ? K := ab.a K = a => b => a
  66. λ JS K I x y = I y =

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

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

    y K := ab.a K = a => b => a K(I)(x)(y) === I(y) && I(y) === y
  69. ab.b KITE

  70. λ JS KI = a => b => b KI

    = K(I) KI := ab.b = K I
  71. λ JS KI(M)(K) === ? KI M K = ?

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

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

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

    K = K KI K M = M KI := ab.b KI = a => b => b
  75. ?

  76. SCHÖNFINKEL CURRY SMULLYAN Identitätsfunktion Konstante Funktion verSchmelzungsfunktion verTauschungsfunktion Zusammensetzungsf. I


    K
 S
 C
 B Idiot
 Kestrel
 Starling
 Cardinal
 Bluebird Ibis?
  77. None
  78. ?

  79. 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
  80. 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
  81. 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
  82. 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
  83. 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
  84. 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 )
  85. 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
  86. 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
  87. 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
  88. 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
  89. 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
  90. 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
  91. 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
  92. 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
  93. 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
  94. 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
  95. COMBINATORS Sym. Bird -Calculus Use Haskell I Idiot a.a identity

    id M Mockingbird f.ff self-application (cannot define) K Kestrel ab.a first, 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
  96. CARDINAL fab.fba

  97. λ JS C = f => a => b =>

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

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

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

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

    C := fab.fba C = f => a => b => f(b)(a)
  102. COMBINATORS Sym. Bird -Calculus Use Haskell I Idiot a.a identity

    id M Mockingbird f.ff self-application (cannot define) K Kestrel ab.a first, 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
  103. COMBINATORS Sym. Bird -Calculus Use Haskell I Idiot a.a identity

    id M Mockingbird f.ff self-application (cannot define) K Kestrel ab.a first, 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
  104. flip const 1 8 == 8

  105. -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
  106. TM

  107. EVERYTHING CAN BE FUNCTIONS

  108. … TRUE FALSE NOT AND OR BEQ

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

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

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

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

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

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

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

    func exp1 exp2
  116. λ JS result := func exp1 exp2 const result =

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

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

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

    func exp1 exp2 K KI
  120. λ JS const T = K const F = KI

    TRUE := K FALSE := KI = C K CHURCH ENCODINGS: BOOLEANS
  121. λ JS !p ! p

  122. λ JS not(p) NOT p

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

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

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

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

    ( )
  127. λ JS ( ) ( ) T F T F

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

    T F KI KI K K
  129. λ JS const not = p => p(F)(T) NOT :=

    p.pFT
  130. 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
  131. λ JS not(T) === F not(F) === T NOT T

    = F NOT F = T
  132. λ JS not(K) === KI not(KI) === K NOT K

    = KI NOT (KI) = K ab.a ba.a ba.a ab.a
  133. λ JS C(K) (chirp)(tweet) === tweet C(KI)(chirp)(tweet) === chirp C

    K = KI C (KI) = K
  134. λ JS C(T) (chirp)(tweet) === tweet C(F) (chirp)(tweet) === chirp

    C T = F C F = T
  135. 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
  136. 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
  137. λ JS const and = ? AND := ?

  138. λ JS const and = p => q => ?

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

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

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

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

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

    AND := pq.pqF
  144. pq.p F q

  145. pq.p F q

  146. pq.p p q

  147. pq.p p q

  148. 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
  149. λ JS const or = ? OR := ?

  150. λ JS const or = p => q => …

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

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

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

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

    OR := pq.ppq
  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 or C negation AND pq.pqF or pq.pqp conjunction OR pq.pTq or pq.ppq disjunction BEQ pq.p q (NOT q) equality
  156. pq.ppq

  157. ( pq.ppq ) xy = ?

  158. ( pq.ppq ) xy = xxy

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

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

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

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

  163. 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
  164. 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
  165. ( ) pq.p( ) T T F F q q

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

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

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

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

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

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

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

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

  174. ( ) pq.p q NOT q

  175. ( ) pq.p q q NOT p => q =>

    p(q)(not(q))
  176. 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
  177. (ONE OF) DE MORGAN'S LAWS ¬(P ∧ Q) = (¬P)

    ∨ (¬Q) BEQ (NOT (AND p q)) (OR (NOT p) (NOT q)) !(p && q) === (!p) || (!q)
  178. 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))
  179. 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))
  180. 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))
  181. 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))
  182. 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))
  183. 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))
  184. 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))
  185. … ZERO ONE TWO THREE SUCC

  186. … ZERO ONCE TWICE THRICE SUCC

  187. λ JS n1 = f => a => f(a) n2

    = f => a => f(f(a)) n3 = f => a => f(f(f(a))) N1 := fa.fa N2 := fa.f(fa) N3 := fa.f(f(fa))
  188. λ JS n1(not)(T) = not(T) = ? N1 NOT T

    = NOT T = ? N1 := fa.fa N1 = f => a => f(a)
  189. λ JS n1(not)(T) = not(T) = F N1 NOT T

    = NOT T = F N1 := fa.fa N1 = f => a => f(a)
  190. λ JS n2(not)(T) = not(not(T)) = ? N2 NOT T

    = NOT (NOT T) = ? N2 := fa.f(fa) N2 = f => a => f(f(a))
  191. λ JS n2(not)(T) = not(not(T)) = T N2 NOT T

    = NOT (NOT T) = T N2 := fa.f(fa) N2 = f => a => f(f(a))
  192. λ JS n3(not)(T) = not(not(not(T))) = F N3 NOT T

    = NOT (NOT (NOT T))) = F N3 := fa.f(f(fa)) N3 = f => a => f(f(f(a)))
  193. λ JS n0 = f => a => a n1

    = f => a => f(a) n2 = f => a => f(f(a)) n3 = f => a => f(f(f(a))) N0 := fa.a N1 := fa.fa N2 := fa.f(fa) N3 := fa.f(f(fa))
  194. λ JS n0(not)(T) = ? N0 NOT T = ?

    N0 := fa.a N3 = f => a => a
  195. λ JS n0(not)(T) = T N0 NOT T = T

    N0 := fa.a N3 = f => a => a
  196. 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
  197. + 1 ?

  198. PEANO NUMBERS SUCC N1 = N2 SUCC N2 = N3

    SUCC (SUCC N1) = N3
  199. λ JS succ = n => ? SUCC := n.?

    SUCC N1 = N2
  200. λ JS succ = n => ? SUCC := n.?

    SUCC fa.fa = fa.f(fa)
  201. λ JS succ = n => f => a =>

    f(n(f)(a)) SUCC := nfa.f(nfa) SUCC fa.fa = fa.f(fa)
  202. λ JS succ = n => f => a =>

    f(n(f)(a)) SUCC := nfa.f(nfa) SUCC fa.fa = fa.f(fa)
  203. λ JS succ = n => f => a =>

    f(n(f)(a)) SUCC := nfa.f(nfa) SUCC fa.fa = fa.f(fa)
  204. SUCC N2 = (nfa.f(nfa)) N2 = fa.f(N2 f a) =

    fa.f(f(f a) = N3
  205. CHURCH ARITHMETIC Name -Calculus Use SUCC 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
  206. BLUEBIRD fga.f(ga)

  207. λ JS B = f => g => a =>

    f(g(a)) B := fga.f(ga)
  208. λ JS B(not)(not)(T) === ? B NOT NOT T =

    ? B := fga.f(ga) B = f => g => a => f(g(a))
  209. λ JS B(not)(not)(T) === T B NOT NOT T =

    T B := fga.f(ga) B = f => g => a => f(g(a))
  210. odd = not . even

  211. COMBINATORS Sym. Bird -Calculus Use Haskell I Idiot a.a identity

    id M Mockingbird f.ff self-application (cannot define) K Kestrel ab.a true, first, 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 (.) 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
  212. λ JS succ = n => f => a =>

    f(n(f)(a)) SUCC := nfa.f(nfa)
  213. λ JS succ = n => f => B(f)(n(f)) SUCC

    := nf.Bf(nf)
  214. 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
  215. … ADD MULT POW

  216. λ JS add = n => k => ? ADD

    := nk.? ADD N3 N5 = SUCC (SUCC (SUCC N5))
  217. λ JS add = n => k => ? ADD

    := nk.? ADD N3 N5 = (SUCC ∘ SUCC ∘ SUCC) N5
  218. λ JS add = n => k => ? ADD

    := nk.? ADD N3 N5 = N3 SUCC N5
  219. λ JS add = n => k => n(succ)(k) ADD

    := nk.n SUCC k ADD N3 N5 = N3 SUCC N5
  220. ADD N3 N5 = N3 SUCC N5 = THRICE SUCC

    FIVEFOLD = SUCC (SUCC (SUCC FIVEFOLD))) = EIGHTFOLD
  221. 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
  222. λ JS mult = n => k => ? MULT

    := nk.? MULT N2 N3 = N6
  223. λ JS mult = n => k => ? MULT

    := nk.? MULT N2 N3 f a = N6 f a
  224. λ JS mult = n => k => ? MULT

    := nk.? MULT N2 N3 f a = (f ∘ f ∘ f ∘ f ∘ f ∘ f) a
  225. λ JS mult = n => k => ? MULT

    := nk.? MULT N2 N3 f a = ((f ∘ f ∘ f) ∘ (f ∘ f ∘ f)) a
  226. λ JS mult = n => k => ? MULT

    := nk.? MULT N2 N3 f a = ((N3 f) ∘ (N3 f)) a
  227. λ JS mult = n => k => ? MULT

    := nk.? MULT N2 N3 f a = N2 (N3 f) a
  228. λ JS mult = n => k => ? MULT

    := nk.? MULT N2 N3 f a = N2 (N3 f) a
  229. λ JS mult = n => k => ? MULT

    := nk.? MULT N2 N3 f = N2 (N3 f)
  230. λ JS mult = n => k => n(k(f)) MULT

    := nkf.n(kf) MULT N2 N3 f = N2 (N3 f)
  231. MULT N2 N3 f = N2 (N3 f) = TWICE

    (THRICE f) = (f ∘ f ∘ f) ∘ (f ∘ f ∘ f) = SIXFOLD f
  232. 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) 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
  233. λ JS MULT := nkf.n(kf) MULT N2 N3 f =

    N2 (N3 f) mult = n => k => n(k(f))
  234. λ JS MULT := nkf.n(kf) MULT N2 N3 f =

    (N2 ∘ N3) f mult = n => k => n(k(f))
  235. λ JS MULT := nkf.n(kf) MULT N2 N3 f =

    (N2 ∘ N3) f mult = n => k => n(k(f))
  236. λ JS MULT := nkf.n(kf) MULT N2 N3 = N2

    ∘ N3 mult = n => k => n(k(f))
  237. λ JS MULT := nkf.n(kf) MULT N2 N3 = B

    N2 N3 mult = n => k => n(k(f))
  238. λ JS MULT := nkf.n(kf) MULT N2 N3 = B

    N2 N3 mult = n => k => n(k(f))
  239. λ JS MULT := nkf.n(kf) MULT = B mult =

    n => k => n(k(f))
  240. MULT := B

  241. Mult := n k f . n ( k f)

    = B = f g a . f ( g a) -EQUIVALENCE
  242. 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
  243. λ JS pow = n => k => ? POW

    := nk.? POW N2 N3 = N8
  244. λ JS pow = n => k => ? POW

    := nk.? POW N2 N3 = N2 × N2 × N2
  245. λ JS pow = n => k => ? POW

    := nk.? POW N2 N3 = N2 ∘ N2 ∘ N2
  246. λ JS pow = n => k => ? POW

    := nk.? POW N2 N3 = N3 N2
  247. λ JS pow = n => k => k(n) POW

    := nk.kn POW N2 N3 = N3 N2
  248. POW N2 N3 = N3 N2 = THRICE TWICE =

    TWICE ∘ TWICE ∘ TWICE = EIGHTFOLD
  249. 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 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
  250. THRUSH af.fa

  251. COMBINATORS Sym. Bird -Calculus Use Haskell I Idiot a.a identity

    id M Mockingbird f.ff self-application (cannot define) K Kestrel ab.a true, first, 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 hold an argument V Vireo abf.fab = BCT hold a pair of args flip . flip id B1 Blackbird fgab.f(gab) = BBB 1°←2° composition (.) . (.)
  252. COMBINATORS Sym. Bird -Calculus Use Haskell I Idiot a.a identity

    id M Mockingbird f.ff self-application (cannot define) K Kestrel ab.a true, first, 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 (.) . (.)
  253. 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 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
  254. 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
  255. … ISZERO

  256. IS0 N0 = T IS0 N1 = F IS0 N2

    = F …
  257. λ JS is0 = n => ? IS0 := n.?

  258. λ JS is0 = n => n(func)(arg) IS0 := n.n

    func arg
  259. λ JS is0 = n => n(func)(arg) IS0 := n.n

    func arg N0
  260. λ JS is0 = n => n(func)(T) IS0 := n.n

    func T N0
  261. λ JS is0 = n => n(func)(T) IS0 := n.n

    func T N1 F
  262. λ JS is0 = n => n(func)(T) IS0 := n.n

    func T N2 F
  263. λ JS is0 = n => n(func)(T) IS0 := n.n

    func T N > 0 F
  264. λ JS is0 = n => n(K(F))(T) IS0 := n.n

    (KF) T
  265. λ JS is0 = n => n(K(F))(T) IS0 := n.n

    (KF) T IS0 N3 = KF(KF(KF(T))) = F
  266. λ JS is0 = n => n(K(F))(T) IS0 := n.n

    (KF) T IS0 N3 = KF(KF(KF(T))) = F
  267. λ JS is0 = n => n(K(F))(T) IS0 := n.n

    (KF) T IS0 N3 = KF(KF(KF(T))) = F
  268. 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
  269. + × ^

  270. – 1 ?

  271. PRED := n.n (g.IS0 (g N1) I (B SUCC g))

    (K N0) N0
  272. N0: N0 (g.IS0 (g N1) ) (K N0) N0 I

    (B SUCC g) N0 N1: N1 (g.IS0 (g N1) ) (K N0) N0 I (B SUCC g) N0 N2: N2 (g.IS0 (g N1) ) (K N0) N0 I (B SUCC g) N1 N3: N3 (g.IS0 (g N1) ) (K N0) N0 I (B SUCC g) N2 (K N0) I (SUCC ∘ I) PRED := n.n (g.IS0 (g N1) I (B SUCC g)) (K N0) N0
  273. … PAIR FST SND PHI

  274. VIREO abf.fab

  275. λ JS V = a => b => f =>

    f(a)(b) V := abf.fab
  276. λ JS V(I)(M) // f => f(I)(M) V I M

    = (f.f I M) V := abf.fab V = a => b => f => f(a)(b)
  277. λ JS V(I)(M)(K) // (f => f(I)(M))(K) === ? V

    I M K = (f.f I M) K = ? V := abf.fab V = a => b => f => f(a)(b)
  278. λ JS V(I)(M)(K) // (f => f(I)(M))(K) === I V

    I M K = (f.f I M) K = I V := abf.fab V = a => b => f => f(a)(b)
  279. λ JS V I M KI = (f.f I M)

    KI = M V := abf.fab V = a => b => f => f(a)(b) V(I)(M)(KI) // (f => f(I)(M))(KI) === M
  280. None
  281. COMBINATORS Sym. Bird -Calculus Use Haskell I Idiot a.a identity

    id M Mockingbird f.ff self-application (cannot define) K Kestrel ab.a true, first, 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 (.) . (.)
  282. CHURCH PAIRS Sym. Name -Calculus Use PAIR abf.fab = V

    pair two arguments FST p.pK extract first 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 first, immutably SET2ND cp.PAIR (FST p) c set second, immutably
  283. FST := p.pK SND := p.p(KI)

  284. CHURCH PAIRS Sym. Name -Calculus Use PAIR abf.fab = V

    pair two arguments FST p.pK extract first 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 first, immutably SET2ND cp.PAIR (FST p) c set second, immutably
  285. λ JS phi = p => pair (snd(p)) (succ(snd(p))) PHI

    := p.V (SND p) (SUCC (SND p))
  286. Φ := p.PAIR (SND p) (SUCC (SND p)) Φ (M,

    N7) = ?
  287. Φ := p.PAIR (SND p) (SUCC (SND p)) Φ (M,

    N7) = ( , )
  288. Φ := p.PAIR (SND p) (SUCC (SND p)) Φ (M,

    N7) = (N7, )
  289. Φ := p.PAIR (SND p) (SUCC (SND p)) Φ (M,

    N7) = (N7, N8)
  290. Φ := p.PAIR (SND p) (SUCC (SND p)) Φ (M,

    N7) = (N7, N8) Φ (N9, N2) = (N2, N3)
  291. CHURCH PAIRS Sym. Name -Calculus Use PAIR abf.fab = V

    pair two arguments FST p.pK extract first 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 first, immutably SET2ND cp.PAIR (FST p) c set second, immutably
  292. Φ := p.PAIR (SND p) (SUCC (SND p)) Φ (M,

    N7) = (N7, N8) Φ (N9, N2) = (N2, N3) Φ (N0, N0) = (N0, N1)
  293. Φ := p.PAIR (SND p) (SUCC (SND p)) Φ (M,

    N7) = (N7, N8) Φ (N9, N2) = (N2, N3) Φ (N0, N0) = (N0, N1) Φ (N0, N1) = (N1, N2)
  294. Φ := p.PAIR (SND p) (SUCC (SND p)) Φ (M,

    N7) = (N7, N8) Φ (N9, N2) = (N2, N3) Φ (N0, N0) = (N0, N1) Φ (N0, N1) = (N1, N2) Φ (N1, N2) = (N2, N3)
  295. Φ := p.PAIR (SND p) (SUCC (SND p)) Φ (M,

    N7) = (N7, N8) Φ (N9, N2) = (N2, N3) Φ (N0, N0) = (N0, N1) Φ (N0, N1) = (N1, N2) Φ (N1, N2) = (N2, N3) N8 Φ (N0, N0) = ?
  296. Φ := p.PAIR (SND p) (SUCC (SND p)) Φ (M,

    N7) = (N7, N8) Φ (N9, N2) = (N2, N3) Φ (N0, N0) = (N0, N1) Φ (N0, N1) = (N1, N2) Φ (N1, N2) = (N2, N3) N8 Φ (N0, N0) = (N7, N8)
  297. FST ( ) Φ := p.PAIR (SND p) (SUCC (SND

    p)) Φ (M, N7) = (N7, N8) Φ (N9, N2) = (N2, N3) Φ (N0, N0) = (N0, N1) Φ (N0, N1) = (N1, N2) Φ (N1, N2) = (N2, N3) N8 Φ (N0, N0) = FST (N7, N8) = N7
  298. FST ( ) Φ := p.PAIR (SND p) (SUCC (SND

    p)) Φ (M, N7) = (N7, N8) Φ (N9, N2) = (N2, N3) Φ (N0, N0) = (N0, N1) Φ (N0, N1) = (N1, N2) Φ (N1, N2) = (N2, N3) N8 Φ (N0, N0) = FST (N7, N8) = N7
  299. λ JS pred = n => fst(n(phi)(pair(n0)(n0))) PRED := n.FST

    (n Φ (PAIR N0 N0))
  300. 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
  301. … SUB LEQ EQ GT

  302. λ JS sub = n => k => k(pred)(n) SUB

    := nk.k PRED n
  303. 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
  304. λ JS leq = n => k => is0(sub(n)(k)) LEQ

    := nk.IS0 (SUB n k)
  305. λ JS eq = n => k => and(leq(n)(k))(leq(k)(n)) EQ

    := nk.AND(LEQ n k)(LEQ k n)
  306. 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
  307. λ JS eq = n => k => not(leq(n)(k)) GT

    := nk.NOT (LEQ n k)
  308. λ JS eq = n => k => not(leq(n)(k)) GT

    := nk.NOT (LEQ n k)
  309. λ JS eq = B(not)(leq) ??? GT := B NOT

    LEQ ???
  310. λ JS eq = B(not)(leq) GT := B NOT LEQ

  311. λ JS eq = n => k => not(leq(n)(k)) GT

    := nk.NOT (LEQ n k)
  312. BLACKBIRD fgab.f(gab)

  313. λ JS eq = B1(not)(leq) GT := B1 NOT LEQ

    B1 = fgab.f(gab)
  314. 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
  315. COMBINATORS Sym. Bird -Calculus Use Haskell I Idiot a.a identity

    id M Mockingbird f.ff self-application (cannot define) K Kestrel ab.a true, first, 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) 1°←2° composition
  316. COMBINATORS Sym. Bird -Calculus Use Haskell I Idiot a.a identity

    id M Mockingbird f.ff self-application (cannot define) K Kestrel ab.a true, first, 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 (.) . (.)
  317. B C K I KI = K I = C

    K B1 = B B B Th = C I V = B C Th = B C (C I)
  318. QUESTION how many combinators
 are needed to form a basis?

    20? 10? 5?
  319. STARLING · KESTREL S := abc.ac(bc) K := ab.a

  320. THE SK COMBINATOR CALCULUS

  321. I = S K K

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

  323. seriously though, why?

  324. None
  325. None
  326. None
  327. None
  328. … ADDENDUM

  329. COMBINATORS Sym. Bird -Calculus Use Haskell I Idiot a.a identity

    id M Mockingbird f.ff self-application (cannot define) K Kestrel ab.a true, first, 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 (.) . (.)
  330. 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
  331. 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
  332. 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
  333. 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
  334. CHURCH PAIRS Sym. Name -Calculus Use PAIR abf.fab = V

    pair two arguments FST p.pK extract first 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 first, immutably SET2ND cp.PAIR (FST p) c set second, immutably
  335. f.M(x.f(Mx)) THE Y FIXED-POINT COMBINATOR

  336. EVALUATION STRATEGIES (ab.b)((f.ff)f.ff) x = (b.b) x = x (ab.b)((f.ff)f.ff)x

    = (ab.b)((f.ff)f.ff)x = (ab.b)((f.ff)f.ff)x = (ab.b)((f.ff)f.ff)x = (ab.b)((f.ff)f.ff)x C A L L B Y N A M E (apply to args before reduction) C A L L B Y VA L U E (reduce args before application) (AKA normal order; lazy) (AKA applicative order; strict)
  337. f.M(x.f(v.Mxv)) THE Z FIXED-POINT COMBINATOR

  338. ADDITIONAL RESOURCES Combinator Birds · Rathman · http://bit.ly/2iudab9 To Mock

    a Mockingbird · Smullyan · http://amzn.to/2g9AlXl To Dissect a Mockingbird · Keenan · http://dkeenan.com/Lambda .:.
 A Tutorial Introduction to the Lambda Calculus · Rojas · http://bit.ly/1agRC97 Lambda Calculus · Wikipedia · http://bit.ly/1TsPkGn The Lambda Calculus · Stanford · http://stanford.io/2vtg8hp .:.
 History of Lambda-calculus and Combinatory Logic Cardone, Hindley · http://bit.ly/2wCxv4k .:.
 An Introduction to Functional Programming
 through Lambda Calculus · Michaelson · http://amzn.to/2vtts56