lambda calculus and computation - mitweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdflambda...
TRANSCRIPT
![Page 1: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/1.jpg)
Lambda Calculus and Computation6.037 – Structure and Interpretation of Computer Programs
Benjamin Barenblat
Massachusetts Institute of TechnologyWith material from Mike Phillips, Nelson Elhage, and Chelsea Voss
January 30, 2019
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 2: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/2.jpg)
Limits to Computation
David Hilbert’s Entscheidungsproblem (1928)
: Build a calculatingmachine that gives a yes/no answer to all mathematical questions.
Figure : Alonzo Church(1903-1995), lambda calculus
Figure : Alan Turing (1912-1954),Turing machines
Theorem (Church, Turing, 1936): These models of computationcan’t solve every problem. Proof: next!
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 3: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/3.jpg)
Limits to Computation
David Hilbert’s Entscheidungsproblem (1928): Build a calculatingmachine that gives a yes/no answer to all mathematical questions.
Figure : Alonzo Church(1903-1995), lambda calculus
Figure : Alan Turing (1912-1954),Turing machines
Theorem (Church, Turing, 1936): These models of computationcan’t solve every problem. Proof: next!
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 4: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/4.jpg)
Limits to Computation
David Hilbert’s Entscheidungsproblem (1928): Build a calculatingmachine that gives a yes/no answer to all mathematical questions.
Figure : Alonzo Church(1903-1995), lambda calculus
Figure : Alan Turing (1912-1954),Turing machines
Theorem (Church, Turing, 1936): These models of computationcan’t solve every problem. Proof: next!
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 5: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/5.jpg)
Limits to Computation
David Hilbert’s Entscheidungsproblem (1928): Build a calculatingmachine that gives a yes/no answer to all mathematical questions.
Figure : Alonzo Church(1903-1995), lambda calculus
Figure : Alan Turing (1912-1954),Turing machines
Theorem (Church, Turing, 1936): These models of computationcan’t solve every problem.
Proof: next!
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 6: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/6.jpg)
Limits to Computation
David Hilbert’s Entscheidungsproblem (1928): Build a calculatingmachine that gives a yes/no answer to all mathematical questions.
Figure : Alonzo Church(1903-1995), lambda calculus
Figure : Alan Turing (1912-1954),Turing machines
Theorem (Church, Turing, 1936): These models of computationcan’t solve every problem. Proof: next!
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 7: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/7.jpg)
Equivalence of Computation Methods
First part of the proof: Church–Turing thesis.
Any intuitive notion for a “computer” that you can come up withwill be no more powerful than a Turing machine or than lambdacalculus. That is, most models of computation are equivalent.Turing-complete means capable of simulating Turing machines.Lambda calculus is Turing-complete (proof: later), and Turingmachines can simulate lambda calculus.Some others:
Turing machines are Turing-complete
Scheme is Turing-complete
Minecraft is Turing-complete
Conway’s Game of Life is Turing-complete
Wolfram’s Rule 110 cellular automaton is Turing-complete
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 8: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/8.jpg)
Equivalence of Computation Methods
First part of the proof: Church–Turing thesis.Any intuitive notion for a “computer” that you can come up withwill be no more powerful than a Turing machine or than lambdacalculus. That is, most models of computation are equivalent.
Turing-complete means capable of simulating Turing machines.Lambda calculus is Turing-complete (proof: later), and Turingmachines can simulate lambda calculus.Some others:
Turing machines are Turing-complete
Scheme is Turing-complete
Minecraft is Turing-complete
Conway’s Game of Life is Turing-complete
Wolfram’s Rule 110 cellular automaton is Turing-complete
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 9: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/9.jpg)
Equivalence of Computation Methods
First part of the proof: Church–Turing thesis.Any intuitive notion for a “computer” that you can come up withwill be no more powerful than a Turing machine or than lambdacalculus. That is, most models of computation are equivalent.Turing-complete means capable of simulating Turing machines.
Lambda calculus is Turing-complete (proof: later), and Turingmachines can simulate lambda calculus.Some others:
Turing machines are Turing-complete
Scheme is Turing-complete
Minecraft is Turing-complete
Conway’s Game of Life is Turing-complete
Wolfram’s Rule 110 cellular automaton is Turing-complete
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 10: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/10.jpg)
Equivalence of Computation Methods
First part of the proof: Church–Turing thesis.Any intuitive notion for a “computer” that you can come up withwill be no more powerful than a Turing machine or than lambdacalculus. That is, most models of computation are equivalent.Turing-complete means capable of simulating Turing machines.Lambda calculus is Turing-complete (proof: later), and Turingmachines can simulate lambda calculus.
Some others:
Turing machines are Turing-complete
Scheme is Turing-complete
Minecraft is Turing-complete
Conway’s Game of Life is Turing-complete
Wolfram’s Rule 110 cellular automaton is Turing-complete
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 11: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/11.jpg)
Equivalence of Computation Methods
First part of the proof: Church–Turing thesis.Any intuitive notion for a “computer” that you can come up withwill be no more powerful than a Turing machine or than lambdacalculus. That is, most models of computation are equivalent.Turing-complete means capable of simulating Turing machines.Lambda calculus is Turing-complete (proof: later), and Turingmachines can simulate lambda calculus.Some others:
Turing machines are Turing-complete
Scheme is Turing-complete
Minecraft is Turing-complete
Conway’s Game of Life is Turing-complete
Wolfram’s Rule 110 cellular automaton is Turing-complete
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 12: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/12.jpg)
Equivalence of Computation Methods
First part of the proof: Church–Turing thesis.Any intuitive notion for a “computer” that you can come up withwill be no more powerful than a Turing machine or than lambdacalculus. That is, most models of computation are equivalent.Turing-complete means capable of simulating Turing machines.Lambda calculus is Turing-complete (proof: later), and Turingmachines can simulate lambda calculus.Some others:
Turing machines are Turing-complete
Scheme is Turing-complete
Minecraft is Turing-complete
Conway’s Game of Life is Turing-complete
Wolfram’s Rule 110 cellular automaton is Turing-complete
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 13: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/13.jpg)
Equivalence of Computation Methods
First part of the proof: Church–Turing thesis.Any intuitive notion for a “computer” that you can come up withwill be no more powerful than a Turing machine or than lambdacalculus. That is, most models of computation are equivalent.Turing-complete means capable of simulating Turing machines.Lambda calculus is Turing-complete (proof: later), and Turingmachines can simulate lambda calculus.Some others:
Turing machines are Turing-complete
Scheme is Turing-complete
Minecraft is Turing-complete
Conway’s Game of Life is Turing-complete
Wolfram’s Rule 110 cellular automaton is Turing-complete
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 14: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/14.jpg)
Equivalence of Computation Methods
First part of the proof: Church–Turing thesis.Any intuitive notion for a “computer” that you can come up withwill be no more powerful than a Turing machine or than lambdacalculus. That is, most models of computation are equivalent.Turing-complete means capable of simulating Turing machines.Lambda calculus is Turing-complete (proof: later), and Turingmachines can simulate lambda calculus.Some others:
Turing machines are Turing-complete
Scheme is Turing-complete
Minecraft is Turing-complete
Conway’s Game of Life is Turing-complete
Wolfram’s Rule 110 cellular automaton is Turing-complete
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 15: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/15.jpg)
Equivalence of Computation Methods
First part of the proof: Church–Turing thesis.Any intuitive notion for a “computer” that you can come up withwill be no more powerful than a Turing machine or than lambdacalculus. That is, most models of computation are equivalent.Turing-complete means capable of simulating Turing machines.Lambda calculus is Turing-complete (proof: later), and Turingmachines can simulate lambda calculus.Some others:
Turing machines are Turing-complete
Scheme is Turing-complete
Minecraft is Turing-complete
Conway’s Game of Life is Turing-complete
Wolfram’s Rule 110 cellular automaton is Turing-complete
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 16: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/16.jpg)
Does not compute?
Are there problems which our notion of computing cannotsolve?
Reworded: are there functions that cannot be computed?
Consider functions which map naturals to naturals.
Can write out a function f as the infinite list of naturals f (0),f (1), f (2)...
Any program text can be written as a single number, joiningtogether this list
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 17: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/17.jpg)
Does not compute?
Are there problems which our notion of computing cannotsolve?
Reworded: are there functions that cannot be computed?
Consider functions which map naturals to naturals.
Can write out a function f as the infinite list of naturals f (0),f (1), f (2)...
Any program text can be written as a single number, joiningtogether this list
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 18: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/18.jpg)
Does not compute?
Are there problems which our notion of computing cannotsolve?
Reworded: are there functions that cannot be computed?
Consider functions which map naturals to naturals.
Can write out a function f as the infinite list of naturals f (0),f (1), f (2)...
Any program text can be written as a single number, joiningtogether this list
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 19: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/19.jpg)
Does not compute?
Are there problems which our notion of computing cannotsolve?
Reworded: are there functions that cannot be computed?
Consider functions which map naturals to naturals.
Can write out a function f as the infinite list of naturals f (0),f (1), f (2)...
Any program text can be written as a single number, joiningtogether this list
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 20: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/20.jpg)
Does not compute?
Are there problems which our notion of computing cannotsolve?
Reworded: are there functions that cannot be computed?
Consider functions which map naturals to naturals.
Can write out a function f as the infinite list of naturals f (0),f (1), f (2)...
Any program text can be written as a single number, joiningtogether this list
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 21: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/21.jpg)
Does not compute?
Now consider every possible function
Put them in a big table, one function per row, one input percolumn
Diagonalize!
We get a contradiction: here’s a function that’s not in yourlist.
Theorem (Church, Turing): These models of computation can’tsolve every problem.
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 22: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/22.jpg)
Does not compute?
Now consider every possible function
Put them in a big table, one function per row, one input percolumn
Diagonalize!
We get a contradiction: here’s a function that’s not in yourlist.
Theorem (Church, Turing): These models of computation can’tsolve every problem.
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 23: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/23.jpg)
Does not compute?
Now consider every possible function
Put them in a big table, one function per row, one input percolumn
Diagonalize!
We get a contradiction: here’s a function that’s not in yourlist.
Theorem (Church, Turing): These models of computation can’tsolve every problem.
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 24: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/24.jpg)
Does not compute?
Now consider every possible function
Put them in a big table, one function per row, one input percolumn
Diagonalize!
We get a contradiction: here’s a function that’s not in yourlist.
Theorem (Church, Turing): These models of computation can’tsolve every problem.
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 25: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/25.jpg)
Does not compute?
Now consider every possible function
Put them in a big table, one function per row, one input percolumn
Diagonalize!
We get a contradiction: here’s a function that’s not in yourlist.
Theorem (Church, Turing): These models of computation can’tsolve every problem.
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 26: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/26.jpg)
How many uncomputable problems?
Countably infinite: ℵ0
The number of naturalsThe number of binary stringsThe number of programs
Uncountably infinite: 2ℵ0
The number of functions mapping from natural to natural
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 27: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/27.jpg)
How many uncomputable problems?
Countably infinite: ℵ0
The number of naturals
The number of binary stringsThe number of programs
Uncountably infinite: 2ℵ0
The number of functions mapping from natural to natural
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 28: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/28.jpg)
How many uncomputable problems?
Countably infinite: ℵ0
The number of naturalsThe number of binary strings
The number of programs
Uncountably infinite: 2ℵ0
The number of functions mapping from natural to natural
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 29: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/29.jpg)
How many uncomputable problems?
Countably infinite: ℵ0
The number of naturalsThe number of binary stringsThe number of programs
Uncountably infinite: 2ℵ0
The number of functions mapping from natural to natural
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 30: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/30.jpg)
How many uncomputable problems?
Countably infinite: ℵ0
The number of naturalsThe number of binary stringsThe number of programs
Uncountably infinite: 2ℵ0
The number of functions mapping from natural to natural
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 31: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/31.jpg)
How many uncomputable problems?
Countably infinite: ℵ0
The number of naturalsThe number of binary stringsThe number of programs
Uncountably infinite: 2ℵ0
The number of functions mapping from natural to natural
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 32: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/32.jpg)
Does not compute: Halting Problem
Okay, but can you give me an example?
We’ve seen our programs create infinite lists and infinite loops
Can we write a program to check if an expression will return avalue?
(define (halt? p)
; ...
)
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 33: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/33.jpg)
Does not compute: Halting Problem
Okay, but can you give me an example?
We’ve seen our programs create infinite lists and infinite loops
Can we write a program to check if an expression will return avalue?
(define (halt? p)
; ...
)
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 34: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/34.jpg)
Does not compute: Halting Problem
Okay, but can you give me an example?
We’ve seen our programs create infinite lists and infinite loops
Can we write a program to check if an expression will return avalue?
(define (halt? p)
; ...
)
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 35: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/35.jpg)
Does not compute: Halting Problem
Okay, but can you give me an example?
We’ve seen our programs create infinite lists and infinite loops
Can we write a program to check if an expression will return avalue?
(define (halt? p)
; ...
)
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 36: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/36.jpg)
Aside: what does this do?
((lambda (x) (x x))
(lambda (x) (x x)))
= ((lambda (x) (x x))
(lambda (x) (x x)))
= ((lambda (x) (x x))
(lambda (x) (x x)))
= ...
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 37: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/37.jpg)
Aside: what does this do?
((lambda (x) (x x))
(lambda (x) (x x)))
= ((lambda (x) (x x))
(lambda (x) (x x)))
= ((lambda (x) (x x))
(lambda (x) (x x)))
= ...
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 38: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/38.jpg)
Aside: what does this do?
((lambda (x) (x x))
(lambda (x) (x x)))
= ((lambda (x) (x x))
(lambda (x) (x x)))
= ((lambda (x) (x x))
(lambda (x) (x x)))
= ...
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 39: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/39.jpg)
Aside: what does this do?
((lambda (x) (x x))
(lambda (x) (x x)))
= ((lambda (x) (x x))
(lambda (x) (x x)))
= ((lambda (x) (x x))
(lambda (x) (x x)))
= ...
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 40: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/40.jpg)
Does not compute: Halting Problem
Contradiction!
(define (troll)
(if (halt? troll)
; if halts? says we halt, infinite-loop
((lambda (x) (x x)) (lambda (x) (x x)))
; if halts? says we don't, return a value
#f))
(halt? troll)
Halting Problem is undecidable for Turing Machines – and thus allprogramming languages. (Turing, 1936)Want to learn more computability theory? See 18.400J/6.045J or18.404J/6.840J (Sipser).
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 41: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/41.jpg)
Does not compute: Halting Problem
Contradiction!
(define (troll)
(if (halt? troll)
; if halts? says we halt, infinite-loop
((lambda (x) (x x)) (lambda (x) (x x)))
; if halts? says we don't, return a value
#f))
(halt? troll)
Halting Problem is undecidable for Turing Machines – and thus allprogramming languages. (Turing, 1936)Want to learn more computability theory? See 18.400J/6.045J or18.404J/6.840J (Sipser).
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 42: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/42.jpg)
Does not compute: Halting Problem
Contradiction!
(define (troll)
(if (halt? troll)
; if halts? says we halt, infinite-loop
((lambda (x) (x x)) (lambda (x) (x x)))
; if halts? says we don't, return a value
#f))
(halt? troll)
Halting Problem is undecidable for Turing Machines – and thus allprogramming languages. (Turing, 1936)Want to learn more computability theory? See 18.400J/6.045J or18.404J/6.840J (Sipser).
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 43: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/43.jpg)
Does not compute: Halting Problem
Contradiction!
(define (troll)
(if (halt? troll)
; if halts? says we halt, infinite-loop
((lambda (x) (x x)) (lambda (x) (x x)))
; if halts? says we don't, return a value
#f))
(halt? troll)
Halting Problem is undecidable for Turing Machines – and thus allprogramming languages. (Turing, 1936)
Want to learn more computability theory? See 18.400J/6.045J or18.404J/6.840J (Sipser).
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 44: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/44.jpg)
Does not compute: Halting Problem
Contradiction!
(define (troll)
(if (halt? troll)
; if halts? says we halt, infinite-loop
((lambda (x) (x x)) (lambda (x) (x x)))
; if halts? says we don't, return a value
#f))
(halt? troll)
Halting Problem is undecidable for Turing Machines – and thus allprogramming languages. (Turing, 1936)Want to learn more computability theory? See 18.400J/6.045J or18.404J/6.840J (Sipser).
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 45: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/45.jpg)
The Source of Power
What’s the minimal set of Scheme syntax that you need to achieveTuring-completeness?
define
set!
numbers
strings
if
recursion
cons
booleans
lambda
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 46: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/46.jpg)
The Source of Power
What’s the minimal set of Scheme syntax that you need to achieveTuring-completeness?
define
set!
numbers
strings
if
recursion
cons
booleans
lambda
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 47: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/47.jpg)
Cons cells?
(define (cons a b)
(lambda (c)
(c a b)))
(define (car p)
(p (lambda (a b) a)))
(define (cdr p)
(p (lambda (a b) b)))
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 48: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/48.jpg)
Cons cells?
(define (cons a b)
(lambda (c)
(c a b)))
(define (car p)
(p (lambda (a b) a)))
(define (cdr p)
(p (lambda (a b) b)))
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 49: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/49.jpg)
Cons cells?
(define (cons a b)
(lambda (c)
(c a b)))
(define (car p)
(p (lambda (a b) a)))
(define (cdr p)
(p (lambda (a b) b)))
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 50: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/50.jpg)
Booleans?
(define true
(lambda (a b)
(a)))
(define false
(lambda (a b)
(b)))
(define if
(lambda (test then else)
(test then else))
Also try: and, or, not
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 51: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/51.jpg)
Booleans?
(define true
(lambda (a b)
(a)))
(define false
(lambda (a b)
(b)))
(define if
(lambda (test then else)
(test then else))
Also try: and, or, not
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 52: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/52.jpg)
Booleans?
(define true
(lambda (a b)
(a)))
(define false
(lambda (a b)
(b)))
(define if
(lambda (test then else)
(test then else))
Also try: and, or, not
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 53: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/53.jpg)
Booleans?
(define true
(lambda (a b)
(a)))
(define false
(lambda (a b)
(b)))
(define if
(lambda (test then else)
(test then else))
Also try: and, or, not
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 54: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/54.jpg)
Numbers?
Number N: A procedure which takes in a successor function s anda zero z , and returns the successor applied to the zero N times.
For example, 3 is represented as (s (s (s z))), given s and z
This technique: Church numerals
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 55: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/55.jpg)
Numbers?
(define church-0
(lambda (s z)
z))
(define (church-1
(lambda (s z)
(s z)))
(define (church-2
(lambda (s z)
(s (s z))))
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 56: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/56.jpg)
Numbers?
(define church-0
(lambda (s z)
z))
(define (church-1
(lambda (s z)
(s z)))
(define (church-2
(lambda (s z)
(s (s z))))
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 57: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/57.jpg)
Numbers?
(define church-0
(lambda (s z)
z))
(define (church-1
(lambda (s z)
(s z)))
(define (church-2
(lambda (s z)
(s (s z))))
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 58: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/58.jpg)
Numbers?
(define (church-inc n)
(lambda (s z)
(s (n s z))))
(define (church-add a b)
(lambda (s z)
(a s (b s z))))
(define (also-church-add a b)
(a church-inc b))
For fun: Write decrement, write multiply.
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 59: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/59.jpg)
Numbers?
(define (church-inc n)
(lambda (s z)
(s (n s z))))
(define (church-add a b)
(lambda (s z)
(a s (b s z))))
(define (also-church-add a b)
(a church-inc b))
For fun: Write decrement, write multiply.
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 60: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/60.jpg)
Numbers?
(define (church-inc n)
(lambda (s z)
(s (n s z))))
(define (church-add a b)
(lambda (s z)
(a s (b s z))))
(define (also-church-add a b)
(a church-inc b))
For fun: Write decrement, write multiply.
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 61: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/61.jpg)
Numbers?
(define (church-inc n)
(lambda (s z)
(s (n s z))))
(define (church-add a b)
(lambda (s z)
(a s (b s z))))
(define (also-church-add a b)
(a church-inc b))
For fun: Write decrement, write multiply.
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 62: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/62.jpg)
Let, define?
Use lambdas.
(define x 4)
(...stuff)
becomes...
((lambda (x)
(...stuff)
) 4)
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 63: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/63.jpg)
Let, define?
Use lambdas.
(define x 4)
(...stuff)
becomes...
((lambda (x)
(...stuff)
) 4)
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 64: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/64.jpg)
Let, define?
Use lambdas.
(define x 4)
(...stuff)
becomes...
((lambda (x)
(...stuff)
) 4)
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 65: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/65.jpg)
Let, define?
A problem arises!
(define (fact n)
(if (= n 0)
1
(* n (fact (- n 1)))))
Why? (lambda (fact) ...) (...definition of fact...)
fails! fact is not yet defined when called in its function body.If we can’t name “fact” how do we use it in the recursive call?
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 66: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/66.jpg)
Let, define?
A problem arises!
(define (fact n)
(if (= n 0)
1
(* n (fact (- n 1)))))
Why? (lambda (fact) ...) (...definition of fact...)
fails! fact is not yet defined when called in its function body.
If we can’t name “fact” how do we use it in the recursive call?
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 67: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/67.jpg)
Let, define?
A problem arises!
(define (fact n)
(if (= n 0)
1
(* n (fact (- n 1)))))
Why? (lambda (fact) ...) (...definition of fact...)
fails! fact is not yet defined when called in its function body.If we can’t name “fact” how do we use it in the recursive call?
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 68: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/68.jpg)
Factorial again
Run it with a copy of itself.
(define (fact inner-fact n)
(if (= n 0)
1
(* n
(inner-fact inner-fact (- n 1)))))
Now, (fact fact 4) works!
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 69: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/69.jpg)
Factorial again
Run it with a copy of itself.
(define (fact inner-fact n)
(if (= n 0)
1
(* n
(inner-fact inner-fact (- n 1)))))
Now, (fact fact 4) works!
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 70: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/70.jpg)
Now without define
(fact fact 4) becomes:
((lambda (inner-fact n)
(if (= n 0)
1
(* n (inner-fact inner-fact (- n 1)))))
(lambda (inner-fact n)
(if (= n 0)
1
(* n (inner-fact inner-fact (- n 1)))))
4)
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 71: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/71.jpg)
Now without define
(fact fact 4) becomes:
((lambda (inner-fact n)
(if (= n 0)
1
(* n (inner-fact inner-fact (- n 1)))))
(lambda (inner-fact n)
(if (= n 0)
1
(* n (inner-fact inner-fact (- n 1)))))
4)
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 72: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/72.jpg)
Messy. Can we do better?
Let’s define generate-fact as:
(lambda (inner-fact)
(lambda (n)
(if (= n 0)
1
(* n (inner-fact (- n 1))))))
Huh – what’s (generate-fact fact)?(generate-fact fact) = fact.A fixed point!
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 73: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/73.jpg)
Messy. Can we do better?
Let’s define generate-fact as:
(lambda (inner-fact)
(lambda (n)
(if (= n 0)
1
(* n (inner-fact (- n 1))))))
Huh – what’s (generate-fact fact)?(generate-fact fact) = fact.A fixed point!
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 74: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/74.jpg)
Messy. Can we do better?
Let’s define generate-fact as:
(lambda (inner-fact)
(lambda (n)
(if (= n 0)
1
(* n (inner-fact (- n 1))))))
Huh – what’s (generate-fact fact)?
(generate-fact fact) = fact.A fixed point!
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 75: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/75.jpg)
Messy. Can we do better?
Let’s define generate-fact as:
(lambda (inner-fact)
(lambda (n)
(if (= n 0)
1
(* n (inner-fact (- n 1))))))
Huh – what’s (generate-fact fact)?(generate-fact fact) = fact.
A fixed point!
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 76: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/76.jpg)
Messy. Can we do better?
Let’s define generate-fact as:
(lambda (inner-fact)
(lambda (n)
(if (= n 0)
1
(* n (inner-fact (- n 1))))))
Huh – what’s (generate-fact fact)?(generate-fact fact) = fact.A fixed point!
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 77: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/77.jpg)
Producing Fixed Points
Now let’s define Y as:
(lambda (f)
((lambda (g) (f (g g)))
(lambda (g) (f (g g)))))
We’ll show that (Y f) = (f (Y f))
– that we can use Y tocreate fixed points.
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 78: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/78.jpg)
Producing Fixed Points
Now let’s define Y as:
(lambda (f)
((lambda (g) (f (g g)))
(lambda (g) (f (g g)))))
We’ll show that (Y f) = (f (Y f)) – that we can use Y tocreate fixed points.
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 79: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/79.jpg)
Producing Fixed Points
From the problem before: we want a fixed point ofgenerate-fact.
(define Y (lambda (f)
((lambda (g) (f (g g)))
(lambda (g) (f (g g)))))
;; For convenience:
;; H := (lambda (g) (f (g g)))
;; Is (generate-fact (Y generate-fact))
;; = (Y generate-fact)?
;; (Y generate-fact)
;; = (H H) ; (with f = generate-fact)
;; = (generate-fact (H H))
;; = (generate-fact (Y generate-fact)) ; Success!
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 80: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/80.jpg)
Producing Fixed Points
From the problem before: we want a fixed point ofgenerate-fact.
(define Y (lambda (f)
((lambda (g) (f (g g)))
(lambda (g) (f (g g)))))
;; For convenience:
;; H := (lambda (g) (f (g g)))
;; Is (generate-fact (Y generate-fact))
;; = (Y generate-fact)?
;; (Y generate-fact)
;; = (H H) ; (with f = generate-fact)
;; = (generate-fact (H H))
;; = (generate-fact (Y generate-fact)) ; Success!
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 81: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/81.jpg)
Producing Fixed Points
Now we can define fact as follows:
(Y (lambda (inner-fact)
(lambda (n)
(if (= n 0)
1
(* n (inner-fact (- n 1)))))))
Can create fact without using define!Can create all of Scheme using just lambda!Lambda calculus is Turing-complete! Church–Turing thesis!
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 82: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/82.jpg)
Producing Fixed Points
Now we can define fact as follows:
(Y (lambda (inner-fact)
(lambda (n)
(if (= n 0)
1
(* n (inner-fact (- n 1)))))))
Can create fact without using define!Can create all of Scheme using just lambda!Lambda calculus is Turing-complete! Church–Turing thesis!
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 83: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/83.jpg)
Producing Fixed Points
Now we can define fact as follows:
(Y (lambda (inner-fact)
(lambda (n)
(if (= n 0)
1
(* n (inner-fact (- n 1)))))))
Can create fact without using define!
Can create all of Scheme using just lambda!Lambda calculus is Turing-complete! Church–Turing thesis!
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 84: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/84.jpg)
Producing Fixed Points
Now we can define fact as follows:
(Y (lambda (inner-fact)
(lambda (n)
(if (= n 0)
1
(* n (inner-fact (- n 1)))))))
Can create fact without using define!Can create all of Scheme using just lambda!
Lambda calculus is Turing-complete! Church–Turing thesis!
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 85: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/85.jpg)
Producing Fixed Points
Now we can define fact as follows:
(Y (lambda (inner-fact)
(lambda (n)
(if (= n 0)
1
(* n (inner-fact (- n 1)))))))
Can create fact without using define!Can create all of Scheme using just lambda!Lambda calculus is Turing-complete!
Church–Turing thesis!
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 86: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/86.jpg)
Producing Fixed Points
Now we can define fact as follows:
(Y (lambda (inner-fact)
(lambda (n)
(if (= n 0)
1
(* n (inner-fact (- n 1)))))))
Can create fact without using define!Can create all of Scheme using just lambda!Lambda calculus is Turing-complete! Church–Turing thesis!
Benjamin Barenblat 6.037
Lambda Calculus and Computation
![Page 87: Lambda Calculus and Computation - MITweb.mit.edu/alexmv/6.001/l8-magic-transitions.pdfLambda Calculus and Computation 6.037 { Structure and Interpretation of Computer Programs Benjamin](https://reader030.vdocuments.site/reader030/viewer/2022040215/5ed6832cff0e593c0b63fb6e/html5/thumbnails/87.jpg)
Fun links
https://xkcd.com/505/
http://www.lel.ed.ac.uk/~gpullum/loopsnoop.html
https://youtu.be/1X21HQphy6I
https://youtu.be/My8AsV7bA94
https://youtu.be/xP5-iIeKXE8
https://en.wikipedia.org/wiki/Rule_110
Benjamin Barenblat 6.037
Lambda Calculus and Computation