SlideShare a Scribd company logo
1 of 63
Programming Languages and
Paradigms
Functional Programming Background
(computability, turing machines, lambda calculus)
Edward (Ned) Blurock
Functional Programming Functional Programming
COMPUTABILITY
Will an algorithm be able to compute the task?
Is the task I want impossible?
Is it possible to formulate an impossible task?
What is the consequences for other algorithms
Functional Programming Computability
Computability vs Complexity
• Computability refers to whether of not in
principle it is possible to evaluate f(n) by
following a set of instructions.
• We are not for the moment worried if this
computation requires 1,000,000 or more
consecutive steps.
• The latter refers to complexity which we will
return to later.
Functional Programming Computability
Ensheidungsproblem
Decision problem
Hilbert 1928
The Entscheidungsproblem asks for
an algorithm
that takes as input a statement of a first-order logic
and
answers "Yes" or "No"
according to whether the statement is universally valid
(valid in every structure satisfying the axioms).
An algorithm to ask whether something is true
Is it computableFunctional Programming Computability
Ensheidungsproblem
Decision problem
Hilbert 1928
• Before the question could be answered, the
notion of "algorithm" had to be formally
defined.
– This was done by Alonzo Church in 1936 with the
concept of "effective calculability" based on his λ
calculus
– and by Alan Turing in the same year with his
concept of Turing machines.
– It was recognized immediately by Turing that
these are equivalent models of computation.
Functional Programming Computability
Alan Turing
(1912 – 1954)
Alonzo Church
(1903-1995)
Turing Machine Lambda calculus
Two mathematical ways to ask questions about
“computability”
Functional Programming Computability
Equivalent Computers
z z zz z z z
1
Start
HALT
), X, L
2:
look
for (
#, 1, -
), #, R
(, #, L
(, X, R
#, 0, -
Finite State Machine
...
Turing Machine

term = variable
| term term
| (term)
|  variable . term
y. M  v. (M [y v])
where v does not occur in M.
(x. M)N   M [ x N ]


Lambda Calculus
Functional Programming Computability
Alan Turing, 1936
• "On computable numbers, with an application
to the Entscheidungsproblem [decision
problem]”
• addressed a previously unsolved
mathematical problem posed by the German
mathematician David Hilbert in 1928:
Functional Programming Computability
Turing, 1936
Is there, in principal,
any definite mechanical method or process
by which
all mathematical questions
could be decided?
The Decision Problem
Functional Programming Computability
Turing, 1936
• To answer the question (in the negative),
• Turing proposed a simple abstract computing
machine,
• modeled after a mathematician with a pencil,
an eraser, and a stack of pieces of paper
• He asserted that any function is a computable
function if it is computable by one of these
abstract machines.
Functional Programming Computability
Turing, 1936
• He then investigated whether there were
some mathematical problems which could not
be solved by any such abstract machine.
• Such abstract computing machines are now
called "Turing machines".
• One particular Turing machine, called a
"Universal Turing Machine", served as the
model for designing actual programmable
computers.
Functional Programming Computability
Why a Turing Machine
Because Turing machines are very simple
compared with computers in practical use,
conceptually easier
to prove impossibility results
for Turing machines.
These impossibility results
apply as well to all known computers
Functional Programming Computability
Turing, 1936
• Startling result of Turing's 1936 paper
• assertion that there are well-defined
problems that cannot be solved by any
computational procedure.
Functional Programming Computability
What is Computable?
Computation is usually modelled as a mapping from inputs to outputs,
carried out by a formal “machine,” or program, which processes its
input in a sequence of steps.
An “effectively computable” function is one that can be computed in
a finite amount of time using finite resources.
…………
…………
…
input
yes
no
output
Effectively
computable
function
Functional Programming Computability
Unsolvable
• problems are formulated as functions
– unsolvable functions: noncomputable;
• Problems formulated as predicates
– Undecidable.
Using Turing's concept of the abstract machine,
we would say that a function is noncomputable
if there exists no Turing machine that could compute it.
Functional Programming Computability
TURING MACHINE
Computability
Functional Programming Turing Machine
............
Tape
Read-Write head
Control Unit
Functional Programming Turing Machine
Turing Machine
............
Read-Write head
No boundaries -- infinite length
The head moves Left or Right
The
tape
OR
Functional Programming
Turing Machine
............
Read-Write head
The head at each time step:
1. Reads a symbol
2. Writes a symbol
3. Moves Left or Right
Functional Programming
Turing Machine
............
Example:
Time 0
............
Time 1
a a cb
a b k c
1. Reads a
2. Writes k
3. Moves Left
a
Functional Programming
Turing Machine
............
Time 1
a b k c
............
Time 2
a k cf
1. Reads b
2. Writes f
3. Moves Right
b
Functional Programming
Add 1 to a sequence of ones
If 1, then move right If 1, then move left
Loop
If 0, replace with 1
Start: 0 0 0 1 1 1 1 0 0 0 4 ones in a row
End: 0 0 0 1 1 1 1 1 0 0 5 ones in a row
Functional Programming Turing Machine
So what?
You can add a 1 to a sequence of ones
From a set of a few (a manageable number) of primitive operations
If a number is represented by a sequence of ones
then you have the x+1 operator, i.e addition
This is a/(the most) basic mathematical operator
Powerful enough to represent complex mathematics
You can derive other (all) mathematic operations and objects
Functional Programming Turing Machine
Powerful “language”
From a set of a few (a manageable number) of
primitive operations
Easier enough
To formulate
Proofs about algorithms
Powerful enough
To
represent complex
mathematics
All the ingredients are there Only have to deal with a few basic operations
Not worried about complexity…. Worried about, for example, “can” we compute?
Functional Programming Turing Machine
TURING MACHINE (PT 2)
Computability
Functional Programming Turing Machine (pt 2)
Turing Machine (pt 2)
The Input String
............    
Blank symbol
head
a b ca
Head starts at the leftmost position
of the input string
Input string
Functional Programming
Turing Machine (pt 2)
States & Transitions
1q 2qLba ,
Read Write Move Left
1q 2qRba ,
Move Right
Functional Programming
Turing Machine (pt 2)
Turing machine for the language }{ nn
ba
0q 1q 2q3q
Rxa ,
Raa ,
Ryy ,
Lyb ,
Laa ,
Lyy ,
Rxx ,
Ryy ,
Ryy ,
4q
L,
Functional Programming
Turing Machine (pt 2)
0q 1q 2q3q
Rxa ,
Raa ,
Ryy ,
Lyb ,
Laa ,
Lyy ,
Rxx ,
Ryy ,
Ryy ,
4q
L,
 ba
0q
a bTime 0 
Functional Programming
Turing Machine (pt 2)
0q 1q 2q3q
Rxa ,
Raa ,
Ryy ,
Lyb ,
Laa ,
Lyy ,
Rxx ,
Ryy ,
Ryy ,
4q
L,
 bx
1q
a b Time 1
Functional Programming
Turing Machine (pt 2)
0q 1q 2q3q
Rxa ,
Raa ,
Ryy ,
Lyb ,
Laa ,
Lyy ,
Rxx ,
Ryy ,
Ryy ,
4q
L,
 x
2q
a b Time 2 b
Functional Programming
Turing Machine (pt 2)
0q 1q 2q3q
Rxa ,
Raa ,
Ryy ,
Lyb ,
Laa ,
Lyy ,
Rxx ,
Ryy ,
Ryy ,
4q
L,
 yx
2q
a b Time 3
Functional Programming
Turing Machine (pt 2)
0q 1q 2q3q
Rxa ,
Raa ,
Ryy ,
Lyb ,
Laa ,
Lyy ,
Rxx ,
Ryy ,
Ryy ,
4q
L,
 yx
2q
a b Time 4
Functional Programming
Turing Machine (pt 2)
0q 1q 2q3q
Rxa ,
Raa ,
Ryy ,
Lyb ,
Laa ,
Lyy ,
Rxx ,
Ryy ,
Ryy ,
4q
L,
 yx
0q
a b Time 5
Functional Programming
Turing Machine (pt 2)
0q 1q 2q3q
Rxa ,
Raa ,
Ryy ,
Lyb ,
Laa ,
Lyy ,
Rxx ,
Ryy ,
Ryy ,
4q
L,
 yx
1q
x b Time 6
Functional Programming
Turing Machine (pt 2)
0q 1q 2q3q
Rxa ,
Raa ,
Ryy ,
Lyb ,
Laa ,
Lyy ,
Rxx ,
Ryy ,
Ryy ,
4q
L,
 yx
1q
x b Time 7
Functional Programming
Turing Machine (pt 2)
0q 1q 2q3q
Rxa ,
Raa ,
Ryy ,
Lyb ,
Laa ,
Lyy ,
Rxx ,
Ryy ,
Ryy ,
4q
L,
 yx x y
2q
Time 8
Functional Programming
Turing Machine (pt 2)
0q 1q 2q3q
Rxa ,
Raa ,
Ryy ,
Lyb ,
Laa ,
Lyy ,
Rxx ,
Ryy ,
Ryy ,
4q
L,
 yx x y
2q
Time 9
Functional Programming
Turing Machine (pt 2)
0q 1q 2q3q
Rxa ,
Raa ,
Ryy ,
Lyb ,
Laa ,
Lyy ,
Rxx ,
Ryy ,
Ryy ,
4q
L,
 yx
0q
x y Time 10
Functional Programming
Turing Machine (pt 2)
0q 1q 2q3q
Rxa ,
Raa ,
Ryy ,
Lyb ,
Laa ,
Lyy ,
Rxx ,
Ryy ,
Ryy ,
4q
L,
 yx
3q
x y Time 11
Functional Programming
Turing Machine (pt 2)
0q 1q 2q3q
Rxa ,
Raa ,
Ryy ,
Lyb ,
Laa ,
Lyy ,
Rxx ,
Ryy ,
Ryy ,
4q
L,
 yx
3q
x y Time 12
Functional Programming
Turing Machine (pt 2)
0q 1q 2q3q
Rxa ,
Raa ,
Ryy ,
Lyb ,
Laa ,
Lyy ,
Rxx ,
Ryy ,
Ryy ,
4q
L,
 yx
4q
x y 
Halt & Accept
Time 13
Functional Programming
LAMBDA CALCULUS
Computability
Functional Programming Lambda Calculus
Lambda Calculus
Alonzo Church
(1903-1995)
Another formulation
of
computability
Functional Programming Lambda Calculus
Equivalent Computers
z z zz z z z ...
Turing Machine

term = variable
| term term
| (term)
|  variable . term
y. M  v. (M [y v])
where v does not occur in M.
(x. M)N   M [ x N ]


Lambda Calculus
Functional Programming Lambda Calculus
What is Calculus?
• In High School:
d/dx xn = nxn-1 [Power Rule]
d/dx (f + g) = d/dx f + d/dx g [Sum Rule]
Calculus
is a branch of mathematics
that deals with limits
and the differentiation and
integration of functions
of one or more variables...
Functional Programming Lambda Calculus
Real Definition
• A calculus is just a bunch of rules for
manipulating symbols.
• People can give meaning to those symbols,
but that’s not part of the calculus.
• Differential calculus is a bunch of rules for
manipulating symbols. There is an
interpretation of those symbols corresponds
with physics, slopes, etc.
Functional Programming Lambda Calculus
-calculus
Alonzo Church, 1940
term = variable
| term term
| (term)
|  variable . term
Functional Programming Lambda Calculus
-calculus
 variable . term
F(variable) = term
Functional Programming Lambda Calculus
Why?
• Once we have precise and formal rules for
manipulating symbols, we can use it to reason
with.
• Since we can interpret the symbols as
representing computations, we can use it to
reason about programs.
Functional Programming Lambda Calculus
Universal Computer
• Lambda Calculus can simulate a Turing Machine
– Everything a Turing Machine can compute, Lambda
Calculus can compute also
• Turing Machine can simulate Lambda Calculus
– Everything Lambda Calculus can compute, a Turing
Machine can compute also
• Church-Turing Thesis: this is true for any other
mechanical computer also
Functional Programming Lambda Calculus
Normal Steps
• Turing machine:
– Read one square on tape, follow one FSM
transition rule, write one square on tape, move
tape head one square
• Lambda calculus:
– One beta reduction
• Your PC:
– Execute one instruction (?)
• What one instruction does varies
Functional Programming Lambda Calculus
-Reduction
(the source of all computation)
(x. M)N
This is the function definition
M is an expression with the variable x
N is used at the value of x
N substitutes x in the expression M
Functional Programming Lambda Calculus
(x. x)a = a
-Reduction
(the source of all computation)
Identity operation
Function gives the argument as output
(x. xx)a = aa
(y.(x. xy)a)b =(y.ay)b=ab
(y.(x. xy) z.zy)b =(y.(z.zy)y)b
= (y. yy)b
=bb
Functional Programming Lambda Calculus
-calculus
Useful and expression enough that a programming
language was modeled after it
LISP
was developed from -calculus
not the other way round.)
This was the “first” general language of
Artificial intelligence
Also
The “first” functional programming language
Functional Programming Lambda Calculus
Expression Reductions
Functional Programming Lambda Calculus
Reductions
are used in the lambda calculus to
reduce a statement to its simplest possible form.
This is, essentially, what a computation in lambda calculus does.
If you were to give a lambda calculus expression to "lambda
calculus" calculator,
it would use a combination of alpha, beta, and eta reductions
to find the simplest reduction of your expression.
https://classes.soe.ucsc.edu/cmps112/Spring03/readings/lambdacalculus/reductions.html
Expression Reduction
Functional Programming Lambda Calculus
(𝛌x. x x) (𝛌y. y)
--> x x [𝛌y. y / x]
== (𝛌y. y) (𝛌y. y)
--> y [𝛌y. y / y]
== 𝛌y. y
How the original expression is
evaluated
Is determined the
operational semantics
of lambda calculus
(there are many ways to evaluate expressions)
Operational Semantics: how the substitutions are made:
Key concepts:
specification of free variables
specification of bound variables
Β-reduction
a formalization of simple substitution
Name Capture
Functional Programming Lambda Calculus
Care must be taken
to avoid “name capture”
of bound variables.
For example, this reduction would be “wrong”:
(λx. (λy. x)) y ⇒ λy. y
because the outer y is presumably different
from the inner y bound by the lambda.
In cases like these, the bound variable is renamed to obtain the “correct” behavior:
(λx. (λy. x)) y ⇒ λz. y
http://www.cs.yale.edu/homes/hudak/CS201S08/lambda.pdf
Α-reduction is a formalization of renaming of variables
(without this, β-reduction can give the wrong answer)
EXAMPLES OF LAMBDA CALCULUS
Computability
Functional Programming Examples
syntax
• the identity function:
– 𝛌x.x
• 2 notational conventions:
• applications associate to the left (like in ML):
• “y z x” is “(y z) x”
• the body of a lambda extends as far as possible to the
right:
• “𝛌x.x 𝛌z.x z x” is “𝛌x.(x 𝛌z.(x z x))”
Functional Programming Examples
terminology
• 𝛌x.t
• 𝛌x.x y
the scope of x is the term t
(this is the part of the expression
where x can be substituted)
x is bound in the term 𝛌x.x y
(x is one of the variables that can be substituted)
y is free in the term 𝛌x.x y
(y is free to be substituted
into the expression .. In this case x)
Functional Programming Examples
Example
(λx. x x) (𝛌y. y)
--> x x [𝛌y. y / x]
== (𝛌y. y) (𝛌y. y)
--> y [𝛌y. y / y]
== 𝛌y. y
Substitute (𝛌y. y) into x
Substituted
Substitute (𝛌y. y) into y
Substituted
Functional Programming Examples
Another example
(𝛌x. x x) (𝛌x. x x)
--> x x [𝛌x. x x/x]
== (𝛌x. x x) (𝛌x. x x)
In other words,
it is simple to write non terminating computations
in the lambda calculus
what else can we do?
Substitute 𝛌x. x x into every x
The result is the same as the beginning
Functional Programming Examples

More Related Content

What's hot

Pumping Lemma and Regular language or not?
Pumping Lemma and Regular language or not?Pumping Lemma and Regular language or not?
Pumping Lemma and Regular language or not?Animesh Chaturvedi
 
Cs2303 theory of computation all anna University question papers
Cs2303 theory of computation all anna University question papersCs2303 theory of computation all anna University question papers
Cs2303 theory of computation all anna University question papersappasami
 
Graphic Notes on Introduction to Linear Algebra
Graphic Notes on Introduction to Linear AlgebraGraphic Notes on Introduction to Linear Algebra
Graphic Notes on Introduction to Linear AlgebraKenji Hiranabe
 
A new (proposed) formula for interpolation and comparison
A new (proposed) formula for interpolation and comparisonA new (proposed) formula for interpolation and comparison
A new (proposed) formula for interpolation and comparisonAlexander Decker
 
Principles of soft computing-Associative memory networks
Principles of soft computing-Associative memory networksPrinciples of soft computing-Associative memory networks
Principles of soft computing-Associative memory networksSivagowry Shathesh
 
Rabin karp string matching algorithm
Rabin karp string matching algorithmRabin karp string matching algorithm
Rabin karp string matching algorithmGajanand Sharma
 
Markov chain and its Application
Markov chain and its Application Markov chain and its Application
Markov chain and its Application Tilakpoudel2
 
fourier series
fourier seriesfourier series
fourier series8laddu8
 
2-Approximation Vertex Cover
2-Approximation Vertex Cover2-Approximation Vertex Cover
2-Approximation Vertex CoverKowshik Roy
 
Extension principle
Extension principleExtension principle
Extension principleSavo Delić
 
Concepts of Maxima And Minima
Concepts of Maxima And MinimaConcepts of Maxima And Minima
Concepts of Maxima And MinimaJitin Pillai
 
Context Free Grammar
Context Free GrammarContext Free Grammar
Context Free GrammarAkhil Kaushik
 
Lecture 1 graphical models
Lecture 1  graphical modelsLecture 1  graphical models
Lecture 1 graphical modelsDuy Tung Pham
 
Elliptic curve cryptography and zero knowledge proof
Elliptic curve cryptography and zero knowledge proofElliptic curve cryptography and zero knowledge proof
Elliptic curve cryptography and zero knowledge proofNimish Joseph
 

What's hot (20)

Pumping Lemma and Regular language or not?
Pumping Lemma and Regular language or not?Pumping Lemma and Regular language or not?
Pumping Lemma and Regular language or not?
 
Fuzzy sets
Fuzzy sets Fuzzy sets
Fuzzy sets
 
Cs2303 theory of computation all anna University question papers
Cs2303 theory of computation all anna University question papersCs2303 theory of computation all anna University question papers
Cs2303 theory of computation all anna University question papers
 
Graphic Notes on Introduction to Linear Algebra
Graphic Notes on Introduction to Linear AlgebraGraphic Notes on Introduction to Linear Algebra
Graphic Notes on Introduction to Linear Algebra
 
A new (proposed) formula for interpolation and comparison
A new (proposed) formula for interpolation and comparisonA new (proposed) formula for interpolation and comparison
A new (proposed) formula for interpolation and comparison
 
Initial Value Problems
Initial Value ProblemsInitial Value Problems
Initial Value Problems
 
Principles of soft computing-Associative memory networks
Principles of soft computing-Associative memory networksPrinciples of soft computing-Associative memory networks
Principles of soft computing-Associative memory networks
 
Rabin karp string matching algorithm
Rabin karp string matching algorithmRabin karp string matching algorithm
Rabin karp string matching algorithm
 
Markov chain and its Application
Markov chain and its Application Markov chain and its Application
Markov chain and its Application
 
fourier series
fourier seriesfourier series
fourier series
 
Approximation Algorithms TSP
Approximation Algorithms   TSPApproximation Algorithms   TSP
Approximation Algorithms TSP
 
2-Approximation Vertex Cover
2-Approximation Vertex Cover2-Approximation Vertex Cover
2-Approximation Vertex Cover
 
Primality
PrimalityPrimality
Primality
 
Extension principle
Extension principleExtension principle
Extension principle
 
Concepts of Maxima And Minima
Concepts of Maxima And MinimaConcepts of Maxima And Minima
Concepts of Maxima And Minima
 
Context Free Grammar
Context Free GrammarContext Free Grammar
Context Free Grammar
 
Turing machine
Turing machineTuring machine
Turing machine
 
Lecture 1 graphical models
Lecture 1  graphical modelsLecture 1  graphical models
Lecture 1 graphical models
 
Turing machine by_deep
Turing machine by_deepTuring machine by_deep
Turing machine by_deep
 
Elliptic curve cryptography and zero knowledge proof
Elliptic curve cryptography and zero knowledge proofElliptic curve cryptography and zero knowledge proof
Elliptic curve cryptography and zero knowledge proof
 

Viewers also liked

From Imperative to Functional Programming (for Absolute Beginners)
From Imperative to Functional Programming (for Absolute Beginners)From Imperative to Functional Programming (for Absolute Beginners)
From Imperative to Functional Programming (for Absolute Beginners)Alex Bunardzic
 
The Lambda Calculus and The JavaScript
The Lambda Calculus and The JavaScriptThe Lambda Calculus and The JavaScript
The Lambda Calculus and The JavaScriptNorman Richards
 
2012 05-08-lambda-draft
2012 05-08-lambda-draft2012 05-08-lambda-draft
2012 05-08-lambda-draftLin Jen-Shin
 
Functional programming
Functional programmingFunctional programming
Functional programmingedusmildo
 
Functional programming
Functional programmingFunctional programming
Functional programmingPrateek Jain
 
An Adventure in Serverless ClojureScript
An Adventure in Serverless ClojureScriptAn Adventure in Serverless ClojureScript
An Adventure in Serverless ClojureScriptNorman Richards
 
Intro to functional programming
Intro to functional programmingIntro to functional programming
Intro to functional programmingAssaf Gannon
 
Reinventing the Y combinator
Reinventing the Y combinatorReinventing the Y combinator
Reinventing the Y combinatorIan Wang
 
Introduction to Functional Programming
Introduction to Functional ProgrammingIntroduction to Functional Programming
Introduction to Functional ProgrammingAndreas Pauley
 
Introduction To Functional Programming
Introduction To Functional ProgrammingIntroduction To Functional Programming
Introduction To Functional Programmingnewmedio
 
Functional Programming Fundamentals
Functional Programming FundamentalsFunctional Programming Fundamentals
Functional Programming FundamentalsShahriar Hyder
 

Viewers also liked (12)

From Imperative to Functional Programming (for Absolute Beginners)
From Imperative to Functional Programming (for Absolute Beginners)From Imperative to Functional Programming (for Absolute Beginners)
From Imperative to Functional Programming (for Absolute Beginners)
 
The Lambda Calculus and The JavaScript
The Lambda Calculus and The JavaScriptThe Lambda Calculus and The JavaScript
The Lambda Calculus and The JavaScript
 
2012 05-08-lambda-draft
2012 05-08-lambda-draft2012 05-08-lambda-draft
2012 05-08-lambda-draft
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
An Adventure in Serverless ClojureScript
An Adventure in Serverless ClojureScriptAn Adventure in Serverless ClojureScript
An Adventure in Serverless ClojureScript
 
Intro to functional programming
Intro to functional programmingIntro to functional programming
Intro to functional programming
 
Reinventing the Y combinator
Reinventing the Y combinatorReinventing the Y combinator
Reinventing the Y combinator
 
Lambda Calculus
Lambda CalculusLambda Calculus
Lambda Calculus
 
Introduction to Functional Programming
Introduction to Functional ProgrammingIntroduction to Functional Programming
Introduction to Functional Programming
 
Introduction To Functional Programming
Introduction To Functional ProgrammingIntroduction To Functional Programming
Introduction To Functional Programming
 
Functional Programming Fundamentals
Functional Programming FundamentalsFunctional Programming Fundamentals
Functional Programming Fundamentals
 

Similar to Computability, turing machines and lambda calculus

Computability and Complexity
Computability and ComplexityComputability and Complexity
Computability and ComplexityEdward Blurock
 
G044053060
G044053060G044053060
G044053060inventy
 
Interview questions slide deck
Interview questions slide deckInterview questions slide deck
Interview questions slide deckMikeBegley
 
Analysis of Algorithm full version 2024.pptx
Analysis of Algorithm  full version  2024.pptxAnalysis of Algorithm  full version  2024.pptx
Analysis of Algorithm full version 2024.pptxrajesshs31r
 
Design Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptxDesign Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptxrajesshs31r
 
Lecture 01-2.ppt
Lecture 01-2.pptLecture 01-2.ppt
Lecture 01-2.pptRaoHamza24
 
CP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithmsCP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithmsSheba41
 
Analysis of Algorithms
Analysis of AlgorithmsAnalysis of Algorithms
Analysis of AlgorithmsAmna Saeed
 
Design & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesDesign & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesFellowBuddy.com
 

Similar to Computability, turing machines and lambda calculus (20)

Computability and Complexity
Computability and ComplexityComputability and Complexity
Computability and Complexity
 
Unit 1.pptx
Unit 1.pptxUnit 1.pptx
Unit 1.pptx
 
G044053060
G044053060G044053060
G044053060
 
Intro to automata theory
Intro to automata theoryIntro to automata theory
Intro to automata theory
 
Np
NpNp
Np
 
Cs2251 daa
Cs2251 daaCs2251 daa
Cs2251 daa
 
chapter 1
chapter 1chapter 1
chapter 1
 
2017 07 04_cmmse_quantum_programming_v1
2017 07 04_cmmse_quantum_programming_v12017 07 04_cmmse_quantum_programming_v1
2017 07 04_cmmse_quantum_programming_v1
 
02 analysis
02 analysis02 analysis
02 analysis
 
Clojure intro
Clojure introClojure intro
Clojure intro
 
Interview questions slide deck
Interview questions slide deckInterview questions slide deck
Interview questions slide deck
 
Scala qq
Scala qqScala qq
Scala qq
 
Analysis of Algorithm full version 2024.pptx
Analysis of Algorithm  full version  2024.pptxAnalysis of Algorithm  full version  2024.pptx
Analysis of Algorithm full version 2024.pptx
 
Design Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptxDesign Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptx
 
Analysis
AnalysisAnalysis
Analysis
 
Lecture 01-2.ppt
Lecture 01-2.pptLecture 01-2.ppt
Lecture 01-2.ppt
 
CP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithmsCP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithms
 
Analysis of Algorithms
Analysis of AlgorithmsAnalysis of Algorithms
Analysis of Algorithms
 
Daa
DaaDaa
Daa
 
Design & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesDesign & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture Notes
 

More from Edward Blurock

KEOD23-JThermodynamcsCloud
KEOD23-JThermodynamcsCloudKEOD23-JThermodynamcsCloud
KEOD23-JThermodynamcsCloudEdward Blurock
 
BlurockPresentation-KEOD2023
BlurockPresentation-KEOD2023BlurockPresentation-KEOD2023
BlurockPresentation-KEOD2023Edward Blurock
 
ChemConnect: Poster for European Combustion Meeting 2017
ChemConnect: Poster for European Combustion Meeting 2017ChemConnect: Poster for European Combustion Meeting 2017
ChemConnect: Poster for European Combustion Meeting 2017Edward Blurock
 
ChemConnect: SMARTCATS presentation
ChemConnect: SMARTCATS presentationChemConnect: SMARTCATS presentation
ChemConnect: SMARTCATS presentationEdward Blurock
 
EU COST Action CM1404: WG€ - Efficient Data Exchange
EU COST Action CM1404: WG€ - Efficient Data ExchangeEU COST Action CM1404: WG€ - Efficient Data Exchange
EU COST Action CM1404: WG€ - Efficient Data ExchangeEdward Blurock
 
ChemConnect: Viewing the datasets in the repository
ChemConnect: Viewing the datasets in the repositoryChemConnect: Viewing the datasets in the repository
ChemConnect: Viewing the datasets in the repositoryEdward Blurock
 
ChemConnect: Characterizing CombusAon KineAc Data with ontologies and meta-­‐...
ChemConnect: Characterizing CombusAon KineAc Data with ontologies and meta-­‐...ChemConnect: Characterizing CombusAon KineAc Data with ontologies and meta-­‐...
ChemConnect: Characterizing CombusAon KineAc Data with ontologies and meta-­‐...Edward Blurock
 
Poster: Characterizing Ignition behavior through morphing to generic curves
Poster: Characterizing Ignition behavior through morphing to generic curvesPoster: Characterizing Ignition behavior through morphing to generic curves
Poster: Characterizing Ignition behavior through morphing to generic curvesEdward Blurock
 
Poster: Very Open Data Project
Poster: Very Open Data ProjectPoster: Very Open Data Project
Poster: Very Open Data ProjectEdward Blurock
 
Poster: Adaptive On-­‐the-­‐fly Regression Tabula@on: Beyond ISAT
Poster: Adaptive On-­‐the-­‐fly Regression Tabula@on: Beyond ISATPoster: Adaptive On-­‐the-­‐fly Regression Tabula@on: Beyond ISAT
Poster: Adaptive On-­‐the-­‐fly Regression Tabula@on: Beyond ISATEdward Blurock
 
Characterization Ignition Behavior through Morphing to Generic Ignition Curves
Characterization Ignition Behavior through Morphing to Generic Ignition CurvesCharacterization Ignition Behavior through Morphing to Generic Ignition Curves
Characterization Ignition Behavior through Morphing to Generic Ignition CurvesEdward Blurock
 
Imperative programming
Imperative programmingImperative programming
Imperative programmingEdward Blurock
 
Database normalization
Database normalizationDatabase normalization
Database normalizationEdward Blurock
 
Generalization abstraction
Generalization abstractionGeneralization abstraction
Generalization abstractionEdward Blurock
 

More from Edward Blurock (20)

KEOD23-JThermodynamcsCloud
KEOD23-JThermodynamcsCloudKEOD23-JThermodynamcsCloud
KEOD23-JThermodynamcsCloud
 
BlurockPresentation-KEOD2023
BlurockPresentation-KEOD2023BlurockPresentation-KEOD2023
BlurockPresentation-KEOD2023
 
KEOD-2023-Poster.pptx
KEOD-2023-Poster.pptxKEOD-2023-Poster.pptx
KEOD-2023-Poster.pptx
 
ChemConnect: Poster for European Combustion Meeting 2017
ChemConnect: Poster for European Combustion Meeting 2017ChemConnect: Poster for European Combustion Meeting 2017
ChemConnect: Poster for European Combustion Meeting 2017
 
ChemConnect: SMARTCATS presentation
ChemConnect: SMARTCATS presentationChemConnect: SMARTCATS presentation
ChemConnect: SMARTCATS presentation
 
EU COST Action CM1404: WG€ - Efficient Data Exchange
EU COST Action CM1404: WG€ - Efficient Data ExchangeEU COST Action CM1404: WG€ - Efficient Data Exchange
EU COST Action CM1404: WG€ - Efficient Data Exchange
 
ChemConnect: Viewing the datasets in the repository
ChemConnect: Viewing the datasets in the repositoryChemConnect: Viewing the datasets in the repository
ChemConnect: Viewing the datasets in the repository
 
ChemConnect: Characterizing CombusAon KineAc Data with ontologies and meta-­‐...
ChemConnect: Characterizing CombusAon KineAc Data with ontologies and meta-­‐...ChemConnect: Characterizing CombusAon KineAc Data with ontologies and meta-­‐...
ChemConnect: Characterizing CombusAon KineAc Data with ontologies and meta-­‐...
 
Poster: Characterizing Ignition behavior through morphing to generic curves
Poster: Characterizing Ignition behavior through morphing to generic curvesPoster: Characterizing Ignition behavior through morphing to generic curves
Poster: Characterizing Ignition behavior through morphing to generic curves
 
Poster: Very Open Data Project
Poster: Very Open Data ProjectPoster: Very Open Data Project
Poster: Very Open Data Project
 
Poster: Adaptive On-­‐the-­‐fly Regression Tabula@on: Beyond ISAT
Poster: Adaptive On-­‐the-­‐fly Regression Tabula@on: Beyond ISATPoster: Adaptive On-­‐the-­‐fly Regression Tabula@on: Beyond ISAT
Poster: Adaptive On-­‐the-­‐fly Regression Tabula@on: Beyond ISAT
 
Characterization Ignition Behavior through Morphing to Generic Ignition Curves
Characterization Ignition Behavior through Morphing to Generic Ignition CurvesCharacterization Ignition Behavior through Morphing to Generic Ignition Curves
Characterization Ignition Behavior through Morphing to Generic Ignition Curves
 
Paradigms
ParadigmsParadigms
Paradigms
 
Imperative programming
Imperative programmingImperative programming
Imperative programming
 
Programming Languages
Programming LanguagesProgramming Languages
Programming Languages
 
Relational algebra
Relational algebraRelational algebra
Relational algebra
 
Database normalization
Database normalizationDatabase normalization
Database normalization
 
Generalization abstraction
Generalization abstractionGeneralization abstraction
Generalization abstraction
 
Overview
OverviewOverview
Overview
 
Networks
NetworksNetworks
Networks
 

Recently uploaded

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 

Recently uploaded (20)

TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 

Computability, turing machines and lambda calculus

  • 1. Programming Languages and Paradigms Functional Programming Background (computability, turing machines, lambda calculus) Edward (Ned) Blurock Functional Programming Functional Programming
  • 2. COMPUTABILITY Will an algorithm be able to compute the task? Is the task I want impossible? Is it possible to formulate an impossible task? What is the consequences for other algorithms Functional Programming Computability
  • 3. Computability vs Complexity • Computability refers to whether of not in principle it is possible to evaluate f(n) by following a set of instructions. • We are not for the moment worried if this computation requires 1,000,000 or more consecutive steps. • The latter refers to complexity which we will return to later. Functional Programming Computability
  • 4. Ensheidungsproblem Decision problem Hilbert 1928 The Entscheidungsproblem asks for an algorithm that takes as input a statement of a first-order logic and answers "Yes" or "No" according to whether the statement is universally valid (valid in every structure satisfying the axioms). An algorithm to ask whether something is true Is it computableFunctional Programming Computability
  • 5. Ensheidungsproblem Decision problem Hilbert 1928 • Before the question could be answered, the notion of "algorithm" had to be formally defined. – This was done by Alonzo Church in 1936 with the concept of "effective calculability" based on his λ calculus – and by Alan Turing in the same year with his concept of Turing machines. – It was recognized immediately by Turing that these are equivalent models of computation. Functional Programming Computability
  • 6. Alan Turing (1912 – 1954) Alonzo Church (1903-1995) Turing Machine Lambda calculus Two mathematical ways to ask questions about “computability” Functional Programming Computability
  • 7. Equivalent Computers z z zz z z z 1 Start HALT ), X, L 2: look for ( #, 1, - ), #, R (, #, L (, X, R #, 0, - Finite State Machine ... Turing Machine  term = variable | term term | (term) |  variable . term y. M  v. (M [y v]) where v does not occur in M. (x. M)N   M [ x N ]   Lambda Calculus Functional Programming Computability
  • 8. Alan Turing, 1936 • "On computable numbers, with an application to the Entscheidungsproblem [decision problem]” • addressed a previously unsolved mathematical problem posed by the German mathematician David Hilbert in 1928: Functional Programming Computability
  • 9. Turing, 1936 Is there, in principal, any definite mechanical method or process by which all mathematical questions could be decided? The Decision Problem Functional Programming Computability
  • 10. Turing, 1936 • To answer the question (in the negative), • Turing proposed a simple abstract computing machine, • modeled after a mathematician with a pencil, an eraser, and a stack of pieces of paper • He asserted that any function is a computable function if it is computable by one of these abstract machines. Functional Programming Computability
  • 11. Turing, 1936 • He then investigated whether there were some mathematical problems which could not be solved by any such abstract machine. • Such abstract computing machines are now called "Turing machines". • One particular Turing machine, called a "Universal Turing Machine", served as the model for designing actual programmable computers. Functional Programming Computability
  • 12. Why a Turing Machine Because Turing machines are very simple compared with computers in practical use, conceptually easier to prove impossibility results for Turing machines. These impossibility results apply as well to all known computers Functional Programming Computability
  • 13. Turing, 1936 • Startling result of Turing's 1936 paper • assertion that there are well-defined problems that cannot be solved by any computational procedure. Functional Programming Computability
  • 14. What is Computable? Computation is usually modelled as a mapping from inputs to outputs, carried out by a formal “machine,” or program, which processes its input in a sequence of steps. An “effectively computable” function is one that can be computed in a finite amount of time using finite resources. ………… ………… … input yes no output Effectively computable function Functional Programming Computability
  • 15. Unsolvable • problems are formulated as functions – unsolvable functions: noncomputable; • Problems formulated as predicates – Undecidable. Using Turing's concept of the abstract machine, we would say that a function is noncomputable if there exists no Turing machine that could compute it. Functional Programming Computability
  • 18. Turing Machine ............ Read-Write head No boundaries -- infinite length The head moves Left or Right The tape OR Functional Programming
  • 19. Turing Machine ............ Read-Write head The head at each time step: 1. Reads a symbol 2. Writes a symbol 3. Moves Left or Right Functional Programming
  • 20. Turing Machine ............ Example: Time 0 ............ Time 1 a a cb a b k c 1. Reads a 2. Writes k 3. Moves Left a Functional Programming
  • 21. Turing Machine ............ Time 1 a b k c ............ Time 2 a k cf 1. Reads b 2. Writes f 3. Moves Right b Functional Programming
  • 22. Add 1 to a sequence of ones If 1, then move right If 1, then move left Loop If 0, replace with 1 Start: 0 0 0 1 1 1 1 0 0 0 4 ones in a row End: 0 0 0 1 1 1 1 1 0 0 5 ones in a row Functional Programming Turing Machine
  • 23. So what? You can add a 1 to a sequence of ones From a set of a few (a manageable number) of primitive operations If a number is represented by a sequence of ones then you have the x+1 operator, i.e addition This is a/(the most) basic mathematical operator Powerful enough to represent complex mathematics You can derive other (all) mathematic operations and objects Functional Programming Turing Machine
  • 24. Powerful “language” From a set of a few (a manageable number) of primitive operations Easier enough To formulate Proofs about algorithms Powerful enough To represent complex mathematics All the ingredients are there Only have to deal with a few basic operations Not worried about complexity…. Worried about, for example, “can” we compute? Functional Programming Turing Machine
  • 25. TURING MACHINE (PT 2) Computability Functional Programming Turing Machine (pt 2)
  • 26. Turing Machine (pt 2) The Input String ............     Blank symbol head a b ca Head starts at the leftmost position of the input string Input string Functional Programming
  • 27. Turing Machine (pt 2) States & Transitions 1q 2qLba , Read Write Move Left 1q 2qRba , Move Right Functional Programming
  • 28. Turing Machine (pt 2) Turing machine for the language }{ nn ba 0q 1q 2q3q Rxa , Raa , Ryy , Lyb , Laa , Lyy , Rxx , Ryy , Ryy , 4q L, Functional Programming
  • 29. Turing Machine (pt 2) 0q 1q 2q3q Rxa , Raa , Ryy , Lyb , Laa , Lyy , Rxx , Ryy , Ryy , 4q L,  ba 0q a bTime 0  Functional Programming
  • 30. Turing Machine (pt 2) 0q 1q 2q3q Rxa , Raa , Ryy , Lyb , Laa , Lyy , Rxx , Ryy , Ryy , 4q L,  bx 1q a b Time 1 Functional Programming
  • 31. Turing Machine (pt 2) 0q 1q 2q3q Rxa , Raa , Ryy , Lyb , Laa , Lyy , Rxx , Ryy , Ryy , 4q L,  x 2q a b Time 2 b Functional Programming
  • 32. Turing Machine (pt 2) 0q 1q 2q3q Rxa , Raa , Ryy , Lyb , Laa , Lyy , Rxx , Ryy , Ryy , 4q L,  yx 2q a b Time 3 Functional Programming
  • 33. Turing Machine (pt 2) 0q 1q 2q3q Rxa , Raa , Ryy , Lyb , Laa , Lyy , Rxx , Ryy , Ryy , 4q L,  yx 2q a b Time 4 Functional Programming
  • 34. Turing Machine (pt 2) 0q 1q 2q3q Rxa , Raa , Ryy , Lyb , Laa , Lyy , Rxx , Ryy , Ryy , 4q L,  yx 0q a b Time 5 Functional Programming
  • 35. Turing Machine (pt 2) 0q 1q 2q3q Rxa , Raa , Ryy , Lyb , Laa , Lyy , Rxx , Ryy , Ryy , 4q L,  yx 1q x b Time 6 Functional Programming
  • 36. Turing Machine (pt 2) 0q 1q 2q3q Rxa , Raa , Ryy , Lyb , Laa , Lyy , Rxx , Ryy , Ryy , 4q L,  yx 1q x b Time 7 Functional Programming
  • 37. Turing Machine (pt 2) 0q 1q 2q3q Rxa , Raa , Ryy , Lyb , Laa , Lyy , Rxx , Ryy , Ryy , 4q L,  yx x y 2q Time 8 Functional Programming
  • 38. Turing Machine (pt 2) 0q 1q 2q3q Rxa , Raa , Ryy , Lyb , Laa , Lyy , Rxx , Ryy , Ryy , 4q L,  yx x y 2q Time 9 Functional Programming
  • 39. Turing Machine (pt 2) 0q 1q 2q3q Rxa , Raa , Ryy , Lyb , Laa , Lyy , Rxx , Ryy , Ryy , 4q L,  yx 0q x y Time 10 Functional Programming
  • 40. Turing Machine (pt 2) 0q 1q 2q3q Rxa , Raa , Ryy , Lyb , Laa , Lyy , Rxx , Ryy , Ryy , 4q L,  yx 3q x y Time 11 Functional Programming
  • 41. Turing Machine (pt 2) 0q 1q 2q3q Rxa , Raa , Ryy , Lyb , Laa , Lyy , Rxx , Ryy , Ryy , 4q L,  yx 3q x y Time 12 Functional Programming
  • 42. Turing Machine (pt 2) 0q 1q 2q3q Rxa , Raa , Ryy , Lyb , Laa , Lyy , Rxx , Ryy , Ryy , 4q L,  yx 4q x y  Halt & Accept Time 13 Functional Programming
  • 44. Lambda Calculus Alonzo Church (1903-1995) Another formulation of computability Functional Programming Lambda Calculus
  • 45. Equivalent Computers z z zz z z z ... Turing Machine  term = variable | term term | (term) |  variable . term y. M  v. (M [y v]) where v does not occur in M. (x. M)N   M [ x N ]   Lambda Calculus Functional Programming Lambda Calculus
  • 46. What is Calculus? • In High School: d/dx xn = nxn-1 [Power Rule] d/dx (f + g) = d/dx f + d/dx g [Sum Rule] Calculus is a branch of mathematics that deals with limits and the differentiation and integration of functions of one or more variables... Functional Programming Lambda Calculus
  • 47. Real Definition • A calculus is just a bunch of rules for manipulating symbols. • People can give meaning to those symbols, but that’s not part of the calculus. • Differential calculus is a bunch of rules for manipulating symbols. There is an interpretation of those symbols corresponds with physics, slopes, etc. Functional Programming Lambda Calculus
  • 48. -calculus Alonzo Church, 1940 term = variable | term term | (term) |  variable . term Functional Programming Lambda Calculus
  • 49. -calculus  variable . term F(variable) = term Functional Programming Lambda Calculus
  • 50. Why? • Once we have precise and formal rules for manipulating symbols, we can use it to reason with. • Since we can interpret the symbols as representing computations, we can use it to reason about programs. Functional Programming Lambda Calculus
  • 51. Universal Computer • Lambda Calculus can simulate a Turing Machine – Everything a Turing Machine can compute, Lambda Calculus can compute also • Turing Machine can simulate Lambda Calculus – Everything Lambda Calculus can compute, a Turing Machine can compute also • Church-Turing Thesis: this is true for any other mechanical computer also Functional Programming Lambda Calculus
  • 52. Normal Steps • Turing machine: – Read one square on tape, follow one FSM transition rule, write one square on tape, move tape head one square • Lambda calculus: – One beta reduction • Your PC: – Execute one instruction (?) • What one instruction does varies Functional Programming Lambda Calculus
  • 53. -Reduction (the source of all computation) (x. M)N This is the function definition M is an expression with the variable x N is used at the value of x N substitutes x in the expression M Functional Programming Lambda Calculus
  • 54. (x. x)a = a -Reduction (the source of all computation) Identity operation Function gives the argument as output (x. xx)a = aa (y.(x. xy)a)b =(y.ay)b=ab (y.(x. xy) z.zy)b =(y.(z.zy)y)b = (y. yy)b =bb Functional Programming Lambda Calculus
  • 55. -calculus Useful and expression enough that a programming language was modeled after it LISP was developed from -calculus not the other way round.) This was the “first” general language of Artificial intelligence Also The “first” functional programming language Functional Programming Lambda Calculus
  • 56. Expression Reductions Functional Programming Lambda Calculus Reductions are used in the lambda calculus to reduce a statement to its simplest possible form. This is, essentially, what a computation in lambda calculus does. If you were to give a lambda calculus expression to "lambda calculus" calculator, it would use a combination of alpha, beta, and eta reductions to find the simplest reduction of your expression. https://classes.soe.ucsc.edu/cmps112/Spring03/readings/lambdacalculus/reductions.html
  • 57. Expression Reduction Functional Programming Lambda Calculus (𝛌x. x x) (𝛌y. y) --> x x [𝛌y. y / x] == (𝛌y. y) (𝛌y. y) --> y [𝛌y. y / y] == 𝛌y. y How the original expression is evaluated Is determined the operational semantics of lambda calculus (there are many ways to evaluate expressions) Operational Semantics: how the substitutions are made: Key concepts: specification of free variables specification of bound variables Β-reduction a formalization of simple substitution
  • 58. Name Capture Functional Programming Lambda Calculus Care must be taken to avoid “name capture” of bound variables. For example, this reduction would be “wrong”: (λx. (λy. x)) y ⇒ λy. y because the outer y is presumably different from the inner y bound by the lambda. In cases like these, the bound variable is renamed to obtain the “correct” behavior: (λx. (λy. x)) y ⇒ λz. y http://www.cs.yale.edu/homes/hudak/CS201S08/lambda.pdf Α-reduction is a formalization of renaming of variables (without this, β-reduction can give the wrong answer)
  • 59. EXAMPLES OF LAMBDA CALCULUS Computability Functional Programming Examples
  • 60. syntax • the identity function: – 𝛌x.x • 2 notational conventions: • applications associate to the left (like in ML): • “y z x” is “(y z) x” • the body of a lambda extends as far as possible to the right: • “𝛌x.x 𝛌z.x z x” is “𝛌x.(x 𝛌z.(x z x))” Functional Programming Examples
  • 61. terminology • 𝛌x.t • 𝛌x.x y the scope of x is the term t (this is the part of the expression where x can be substituted) x is bound in the term 𝛌x.x y (x is one of the variables that can be substituted) y is free in the term 𝛌x.x y (y is free to be substituted into the expression .. In this case x) Functional Programming Examples
  • 62. Example (λx. x x) (𝛌y. y) --> x x [𝛌y. y / x] == (𝛌y. y) (𝛌y. y) --> y [𝛌y. y / y] == 𝛌y. y Substitute (𝛌y. y) into x Substituted Substitute (𝛌y. y) into y Substituted Functional Programming Examples
  • 63. Another example (𝛌x. x x) (𝛌x. x x) --> x x [𝛌x. x x/x] == (𝛌x. x x) (𝛌x. x x) In other words, it is simple to write non terminating computations in the lambda calculus what else can we do? Substitute 𝛌x. x x into every x The result is the same as the beginning Functional Programming Examples