SlideShare a Scribd company logo
1 of 25
Download to read offline
Deriving
the Y Combinator
Yuta Okazaki!
Recurse Center Spring 2 2015
Recursive Function
factorial = function(n){	
if(n == 0){ return 1 } 	
else{ n * factorial(n - 1) }	
}
Pseudo Code
Recursive Function
let’s simplify this to an ‘infinite’ function.
fact-forever = function(n){	
n * fact-forever(n - 1)	
}
Recursive Function
What if we can’t use a variable?
fact-forever = function(n){	
n * fact-forever(n - 1)	
}
Recursive Function
What is this inside ‘fact-forever’ gonna be?
fact-forever = function(n){	
n * fact-forever(n - 1)	
}
function(n){	
!
n * (n - 1)	
!
}
Recursive Function
I’m imagining if we have a ‘magical function’,
that prepares itself again when we need it…
Thought Experiment
with Scheme(Lisp)
Thought Experiment #1
Is it possible to think of a lambda, which
returns a lambda, that takes ‘itself’ as an argument?
((lambda(me)(me me))	
(lambda(x)(quote hi)))
Thought Experiment #1
Is it possible to think of a lambda, which
returns a lambda, that takes ‘itself’ as an argument?
((lambda(me)(me me))	
(lambda(x)(quote hi)))
=> ‘hi
((lambda(me)(me me))	
(lambda(x)( )))
Thought Experiment #2
Since ‘me’ function takes ‘me’ as an argument,
isn’t it fun if we can somehow use it inside it?
quote hi
((lambda(me)(me me))	
(lambda(x)( )))
Thought Experiment #2
Since ‘me’ function takes ‘me’ as an argument,
isn’t it fun if we can somehow use it inside it?
x
((lambda(me)(me me))	
(lambda(x)( )))
Thought Experiment #2
Since ‘me’ function takes ‘me’ as an argument,
isn’t it fun if we can somehow use it inside it?
=> expects 1 argument,	
but found none.
x
((lambda(me)(me me))	
(lambda(x)( )))
Thought Experiment #3
Yeah my bad, x is a lambda expecting
one argument. so… pass in x itself maybe?
x
((lambda(me)(me me))	
(lambda(x)( )))
Thought Experiment #3
Yeah my bad, x is a lambda expecting
one argument. so… pass in x itself maybe?
xx
=>
((lambda(me)(me me))	
(lambda(x)( )))
Thought Experiment #3
Yeah my bad, x is a lambda expecting
one argument. so… pass in x itself maybe?
xx
((lambda(x)(x x))	
(lambda(x)(x x)))
=>
((lambda(me)(me me))	
(lambda(x)( )))
Thought Experiment #3
Yeah my bad, x is a lambda expecting
one argument. so… pass in x itself maybe?
=> infinite loop!
xx
((lambda(x)(x x))	
(lambda(x)(x x)))
=>
Thought Experiment #3
This is the Javascript version of same thing.
function(x){	
return x(x)	
}(function(x){return x(x)})
((lambda(me)(me me))	
(lambda(x)( )))
Resume the Problem
So, how can we use this piece
with the original problem?
xx
function(n)	
n * (n - 1)
((lambda(x) x )(quote hi))
Functional Refactoring
Wrap Function
((lambda(y)((lambda(x)x)y))(quote hi))
if you have a lambda that takes one argument, you can
wrap it with another lambda which also takes one argument,
and call it with that argument, you still get the same result.
((lambda(me)( me me ))	
(lambda(x)
Combine them
So, here I use a twisted version of Wrap Function,
in order to accumulate the calculation.
(lambda(number)(number * (
( x x )))
(number - 1))))
((lambda(me)( me me ))	
(lambda(x)
Combine them
So, here I use a twisted version of Wrap Function,
in order to accumulate the calculation.
(lambda(number)(number * (
( x x )
))
(number - 1))))
((lambda(me)( me me ))	
(lambda(x)
Combine them
So, here I use a twisted version of Wrap Function,
in order to accumulate the calculation.
(lambda(number)(number * (
( x x )
))
(number - 1))))
((lambda(me)( me me ))	
(lambda(x)
Combine them
So, here I use a twisted version of Wrap Function,
in order to accumulate the calculation.
(lambda(number)(number * (
( x x )
))
(number - 1))))
Ω Combinator
((lambda(me)( me me ))	
(lambda(x)
The code below is an application of
Ω Combinator.
(lambda(number)(number * (
( x x )
))
(number - 1))))
Demo Available
Where’s Y Combinator?
Y Combinator is a nicer form of Omega Combinator.
If you want to derive one, please talk to me!
(lambda(le)	
((lambda(f)(f f))	
(lambda(f)	
(le (lambda(x) ((f f) x))))))
Twitter @kenzan100

More Related Content

What's hot

Introducing Assignment invalidates the Substitution Model of Evaluation and v...
Introducing Assignment invalidates the Substitution Model of Evaluation and v...Introducing Assignment invalidates the Substitution Model of Evaluation and v...
Introducing Assignment invalidates the Substitution Model of Evaluation and v...Philip Schwarz
 
Skiena algorithm 2007 lecture15 backtracing
Skiena algorithm 2007 lecture15 backtracingSkiena algorithm 2007 lecture15 backtracing
Skiena algorithm 2007 lecture15 backtracingzukun
 
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 ScalaPhilip Schwarz
 
M sc it_modelling_biological_systems2005
M sc it_modelling_biological_systems2005M sc it_modelling_biological_systems2005
M sc it_modelling_biological_systems2005Aafaq Malik
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2Philip Schwarz
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programmingPrudhviVuda
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 5
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 5Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 5
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 5Philip Schwarz
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheoryKnoldus Inc.
 
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...Philip Schwarz
 
Lambda Calculus by Dustin Mulcahey
Lambda Calculus by Dustin Mulcahey Lambda Calculus by Dustin Mulcahey
Lambda Calculus by Dustin Mulcahey Hakka Labs
 

What's hot (20)

Signal Processing Assignment Help
Signal Processing Assignment HelpSignal Processing Assignment Help
Signal Processing Assignment Help
 
Lec3
Lec3Lec3
Lec3
 
Introducing Assignment invalidates the Substitution Model of Evaluation and v...
Introducing Assignment invalidates the Substitution Model of Evaluation and v...Introducing Assignment invalidates the Substitution Model of Evaluation and v...
Introducing Assignment invalidates the Substitution Model of Evaluation and v...
 
Skiena algorithm 2007 lecture15 backtracing
Skiena algorithm 2007 lecture15 backtracingSkiena algorithm 2007 lecture15 backtracing
Skiena algorithm 2007 lecture15 backtracing
 
Machnical Engineering Assignment Help
Machnical Engineering Assignment HelpMachnical Engineering Assignment Help
Machnical Engineering Assignment Help
 
Signals and systems assignment help
Signals and systems assignment helpSignals and systems assignment help
Signals and systems assignment help
 
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
 
Lec10
Lec10Lec10
Lec10
 
Clojure basics
Clojure basicsClojure basics
Clojure basics
 
M sc it_modelling_biological_systems2005
M sc it_modelling_biological_systems2005M sc it_modelling_biological_systems2005
M sc it_modelling_biological_systems2005
 
Lambda calculus
Lambda calculusLambda calculus
Lambda calculus
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2
 
Recursion
RecursionRecursion
Recursion
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 5
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 5Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 5
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 5
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheory
 
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...
 
Lambda Calculus by Dustin Mulcahey
Lambda Calculus by Dustin Mulcahey Lambda Calculus by Dustin Mulcahey
Lambda Calculus by Dustin Mulcahey
 
Mechanical Engineering Homework Help
Mechanical Engineering Homework HelpMechanical Engineering Homework Help
Mechanical Engineering Homework Help
 
Algorithm Homework Help
Algorithm Homework HelpAlgorithm Homework Help
Algorithm Homework Help
 

Viewers also liked

Billion Dollar Startup Advice from Y Combinator
Billion Dollar Startup Advice from Y CombinatorBillion Dollar Startup Advice from Y Combinator
Billion Dollar Startup Advice from Y CombinatorJim Rettew
 
Technology Business Incubator Manual by Lalkaka 2000
Technology Business Incubator Manual by Lalkaka 2000Technology Business Incubator Manual by Lalkaka 2000
Technology Business Incubator Manual by Lalkaka 2000Vasily Ryzhonkov
 
Final nzl incubation 23 sepv2
Final nzl incubation 23 sepv2Final nzl incubation 23 sepv2
Final nzl incubation 23 sepv2Hanisevae Visanti
 
The Personal incubation Philosophy of Candace Ngina Brathwaite Babson MBA and...
The Personal incubation Philosophy of Candace Ngina Brathwaite Babson MBA and...The Personal incubation Philosophy of Candace Ngina Brathwaite Babson MBA and...
The Personal incubation Philosophy of Candace Ngina Brathwaite Babson MBA and...Candace Ngina Brathwaite
 
EcoMachines Incubator: Resource 2015 - Funding Options for Startups
EcoMachines Incubator: Resource 2015 - Funding Options for StartupsEcoMachines Incubator: Resource 2015 - Funding Options for Startups
EcoMachines Incubator: Resource 2015 - Funding Options for StartupsEcoMachines Ventures
 
Денис Гурський
Денис ГурськийДенис Гурський
Денис ГурськийSmartLviv
 
Hans Y Combinator Presentation on Lessons from China for Global Entrepreneurs
Hans Y Combinator Presentation on Lessons from China for Global EntrepreneursHans Y Combinator Presentation on Lessons from China for Global Entrepreneurs
Hans Y Combinator Presentation on Lessons from China for Global EntrepreneursGGV Capital
 
Technology business incubator
Technology business incubatorTechnology business incubator
Technology business incubatorRajni Ranjan
 
[InDMF 2013] Indra Purnama - Incubator Role in Startup Industry
[InDMF 2013] Indra Purnama - Incubator Role in Startup Industry[InDMF 2013] Indra Purnama - Incubator Role in Startup Industry
[InDMF 2013] Indra Purnama - Incubator Role in Startup IndustrySegitiga.Net
 
Nurturing The Start Up Company
Nurturing The Start Up CompanyNurturing The Start Up Company
Nurturing The Start Up Companyignatiadis
 
Gptp 2014 way of the combinator
Gptp 2014 way of the combinatorGptp 2014 way of the combinator
Gptp 2014 way of the combinatorbillwzel
 
The Startup Factories: The Rise of Accelerator Programs
The Startup Factories: The Rise of Accelerator ProgramsThe Startup Factories: The Rise of Accelerator Programs
The Startup Factories: The Rise of Accelerator ProgramsVasily Ryzhonkov
 
Incubator models
Incubator modelsIncubator models
Incubator modelsNIABI
 

Viewers also liked (13)

Billion Dollar Startup Advice from Y Combinator
Billion Dollar Startup Advice from Y CombinatorBillion Dollar Startup Advice from Y Combinator
Billion Dollar Startup Advice from Y Combinator
 
Technology Business Incubator Manual by Lalkaka 2000
Technology Business Incubator Manual by Lalkaka 2000Technology Business Incubator Manual by Lalkaka 2000
Technology Business Incubator Manual by Lalkaka 2000
 
Final nzl incubation 23 sepv2
Final nzl incubation 23 sepv2Final nzl incubation 23 sepv2
Final nzl incubation 23 sepv2
 
The Personal incubation Philosophy of Candace Ngina Brathwaite Babson MBA and...
The Personal incubation Philosophy of Candace Ngina Brathwaite Babson MBA and...The Personal incubation Philosophy of Candace Ngina Brathwaite Babson MBA and...
The Personal incubation Philosophy of Candace Ngina Brathwaite Babson MBA and...
 
EcoMachines Incubator: Resource 2015 - Funding Options for Startups
EcoMachines Incubator: Resource 2015 - Funding Options for StartupsEcoMachines Incubator: Resource 2015 - Funding Options for Startups
EcoMachines Incubator: Resource 2015 - Funding Options for Startups
 
Денис Гурський
Денис ГурськийДенис Гурський
Денис Гурський
 
Hans Y Combinator Presentation on Lessons from China for Global Entrepreneurs
Hans Y Combinator Presentation on Lessons from China for Global EntrepreneursHans Y Combinator Presentation on Lessons from China for Global Entrepreneurs
Hans Y Combinator Presentation on Lessons from China for Global Entrepreneurs
 
Technology business incubator
Technology business incubatorTechnology business incubator
Technology business incubator
 
[InDMF 2013] Indra Purnama - Incubator Role in Startup Industry
[InDMF 2013] Indra Purnama - Incubator Role in Startup Industry[InDMF 2013] Indra Purnama - Incubator Role in Startup Industry
[InDMF 2013] Indra Purnama - Incubator Role in Startup Industry
 
Nurturing The Start Up Company
Nurturing The Start Up CompanyNurturing The Start Up Company
Nurturing The Start Up Company
 
Gptp 2014 way of the combinator
Gptp 2014 way of the combinatorGptp 2014 way of the combinator
Gptp 2014 way of the combinator
 
The Startup Factories: The Rise of Accelerator Programs
The Startup Factories: The Rise of Accelerator ProgramsThe Startup Factories: The Rise of Accelerator Programs
The Startup Factories: The Rise of Accelerator Programs
 
Incubator models
Incubator modelsIncubator models
Incubator models
 

Similar to Deriving the Y Combinator

Introduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScriptIntroduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScripttmont
 
Composition birds-and-recursion
Composition birds-and-recursionComposition birds-and-recursion
Composition birds-and-recursionDavid Atchley
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsEelco Visser
 
237654933 mathematics-t-form-6
237654933 mathematics-t-form-6237654933 mathematics-t-form-6
237654933 mathematics-t-form-6homeworkping3
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskellgoncharenko
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming iiPrashant Kalkar
 
Programming in Scala - Lecture Two
Programming in Scala - Lecture TwoProgramming in Scala - Lecture Two
Programming in Scala - Lecture TwoAngelo Corsaro
 
Real World Haskell: Lecture 6
Real World Haskell: Lecture 6Real World Haskell: Lecture 6
Real World Haskell: Lecture 6Bryan O'Sullivan
 
Functional programming with haskell
Functional programming with haskellFunctional programming with haskell
Functional programming with haskellfaradjpour
 
Good functional programming is good programming
Good functional programming is good programmingGood functional programming is good programming
Good functional programming is good programmingkenbot
 
Function Analysis v.1
Function Analysis v.1Function Analysis v.1
Function Analysis v.1Arun Umrao
 
Principle of Function Analysis - by Arun Umrao
Principle of Function Analysis - by Arun UmraoPrinciple of Function Analysis - by Arun Umrao
Principle of Function Analysis - by Arun Umraossuserd6b1fd
 
Lecture 2 family of fcts
Lecture 2   family of fctsLecture 2   family of fcts
Lecture 2 family of fctsnjit-ronbrown
 
Sienna 10 dynamic
Sienna 10 dynamicSienna 10 dynamic
Sienna 10 dynamicchidabdu
 
Stdlib functions lesson
Stdlib functions lessonStdlib functions lesson
Stdlib functions lessonteach4uin
 
Principles of functional progrmming in scala
Principles of functional progrmming in scalaPrinciples of functional progrmming in scala
Principles of functional progrmming in scalaehsoon
 

Similar to Deriving the Y Combinator (20)

Introduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScriptIntroduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScript
 
Composition birds-and-recursion
Composition birds-and-recursionComposition birds-and-recursion
Composition birds-and-recursion
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class Functions
 
237654933 mathematics-t-form-6
237654933 mathematics-t-form-6237654933 mathematics-t-form-6
237654933 mathematics-t-form-6
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskell
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming ii
 
Programming in Scala - Lecture Two
Programming in Scala - Lecture TwoProgramming in Scala - Lecture Two
Programming in Scala - Lecture Two
 
Functional programming java
Functional programming javaFunctional programming java
Functional programming java
 
Real World Haskell: Lecture 6
Real World Haskell: Lecture 6Real World Haskell: Lecture 6
Real World Haskell: Lecture 6
 
04. haskell handling
04. haskell handling04. haskell handling
04. haskell handling
 
Functional programming with haskell
Functional programming with haskellFunctional programming with haskell
Functional programming with haskell
 
Good functional programming is good programming
Good functional programming is good programmingGood functional programming is good programming
Good functional programming is good programming
 
Tricks
TricksTricks
Tricks
 
Function Analysis v.1
Function Analysis v.1Function Analysis v.1
Function Analysis v.1
 
Principle of Function Analysis - by Arun Umrao
Principle of Function Analysis - by Arun UmraoPrinciple of Function Analysis - by Arun Umrao
Principle of Function Analysis - by Arun Umrao
 
Lecture 2 family of fcts
Lecture 2   family of fctsLecture 2   family of fcts
Lecture 2 family of fcts
 
Sienna 10 dynamic
Sienna 10 dynamicSienna 10 dynamic
Sienna 10 dynamic
 
Stdlib functions lesson
Stdlib functions lessonStdlib functions lesson
Stdlib functions lesson
 
.
..
.
 
Principles of functional progrmming in scala
Principles of functional progrmming in scalaPrinciples of functional progrmming in scala
Principles of functional progrmming in scala
 

Recently uploaded

System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingBootNeck1
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating SystemRashmi Bhat
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgsaravananr517913
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptNarmatha D
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating SystemRashmi Bhat
 
National Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfNational Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfRajuKanojiya4
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptMadan Karki
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionMebane Rash
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...Amil Baba Dawood bangali
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating SystemRashmi Bhat
 
Steel Structures - Building technology.pptx
Steel Structures - Building technology.pptxSteel Structures - Building technology.pptx
Steel Structures - Building technology.pptxNikhil Raut
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadaditya806802
 

Recently uploaded (20)

System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event Scheduling
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating System
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.ppt
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating System
 
National Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfNational Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdf
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.ppt
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating System
 
Steel Structures - Building technology.pptx
Steel Structures - Building technology.pptxSteel Structures - Building technology.pptx
Steel Structures - Building technology.pptx
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasad
 

Deriving the Y Combinator

  • 1. Deriving the Y Combinator Yuta Okazaki! Recurse Center Spring 2 2015
  • 2. Recursive Function factorial = function(n){ if(n == 0){ return 1 } else{ n * factorial(n - 1) } } Pseudo Code
  • 3. Recursive Function let’s simplify this to an ‘infinite’ function. fact-forever = function(n){ n * fact-forever(n - 1) }
  • 4. Recursive Function What if we can’t use a variable? fact-forever = function(n){ n * fact-forever(n - 1) }
  • 5. Recursive Function What is this inside ‘fact-forever’ gonna be? fact-forever = function(n){ n * fact-forever(n - 1) }
  • 6. function(n){ ! n * (n - 1) ! } Recursive Function I’m imagining if we have a ‘magical function’, that prepares itself again when we need it…
  • 8. Thought Experiment #1 Is it possible to think of a lambda, which returns a lambda, that takes ‘itself’ as an argument? ((lambda(me)(me me)) (lambda(x)(quote hi)))
  • 9. Thought Experiment #1 Is it possible to think of a lambda, which returns a lambda, that takes ‘itself’ as an argument? ((lambda(me)(me me)) (lambda(x)(quote hi))) => ‘hi
  • 10. ((lambda(me)(me me)) (lambda(x)( ))) Thought Experiment #2 Since ‘me’ function takes ‘me’ as an argument, isn’t it fun if we can somehow use it inside it? quote hi
  • 11. ((lambda(me)(me me)) (lambda(x)( ))) Thought Experiment #2 Since ‘me’ function takes ‘me’ as an argument, isn’t it fun if we can somehow use it inside it? x
  • 12. ((lambda(me)(me me)) (lambda(x)( ))) Thought Experiment #2 Since ‘me’ function takes ‘me’ as an argument, isn’t it fun if we can somehow use it inside it? => expects 1 argument, but found none. x
  • 13. ((lambda(me)(me me)) (lambda(x)( ))) Thought Experiment #3 Yeah my bad, x is a lambda expecting one argument. so… pass in x itself maybe? x
  • 14. ((lambda(me)(me me)) (lambda(x)( ))) Thought Experiment #3 Yeah my bad, x is a lambda expecting one argument. so… pass in x itself maybe? xx =>
  • 15. ((lambda(me)(me me)) (lambda(x)( ))) Thought Experiment #3 Yeah my bad, x is a lambda expecting one argument. so… pass in x itself maybe? xx ((lambda(x)(x x)) (lambda(x)(x x))) =>
  • 16. ((lambda(me)(me me)) (lambda(x)( ))) Thought Experiment #3 Yeah my bad, x is a lambda expecting one argument. so… pass in x itself maybe? => infinite loop! xx ((lambda(x)(x x)) (lambda(x)(x x))) =>
  • 17. Thought Experiment #3 This is the Javascript version of same thing. function(x){ return x(x) }(function(x){return x(x)})
  • 18. ((lambda(me)(me me)) (lambda(x)( ))) Resume the Problem So, how can we use this piece with the original problem? xx function(n) n * (n - 1)
  • 19. ((lambda(x) x )(quote hi)) Functional Refactoring Wrap Function ((lambda(y)((lambda(x)x)y))(quote hi)) if you have a lambda that takes one argument, you can wrap it with another lambda which also takes one argument, and call it with that argument, you still get the same result.
  • 20. ((lambda(me)( me me )) (lambda(x) Combine them So, here I use a twisted version of Wrap Function, in order to accumulate the calculation. (lambda(number)(number * ( ( x x ))) (number - 1))))
  • 21. ((lambda(me)( me me )) (lambda(x) Combine them So, here I use a twisted version of Wrap Function, in order to accumulate the calculation. (lambda(number)(number * ( ( x x ) )) (number - 1))))
  • 22. ((lambda(me)( me me )) (lambda(x) Combine them So, here I use a twisted version of Wrap Function, in order to accumulate the calculation. (lambda(number)(number * ( ( x x ) )) (number - 1))))
  • 23. ((lambda(me)( me me )) (lambda(x) Combine them So, here I use a twisted version of Wrap Function, in order to accumulate the calculation. (lambda(number)(number * ( ( x x ) )) (number - 1))))
  • 24. Ω Combinator ((lambda(me)( me me )) (lambda(x) The code below is an application of Ω Combinator. (lambda(number)(number * ( ( x x ) )) (number - 1)))) Demo Available
  • 25. Where’s Y Combinator? Y Combinator is a nicer form of Omega Combinator. If you want to derive one, please talk to me! (lambda(le) ((lambda(f)(f f)) (lambda(f) (le (lambda(x) ((f f) x)))))) Twitter @kenzan100