Professional Documents
Culture Documents
Logic For Computer Science: Computing
Logic For Computer Science: Computing
Logic For Computer Science: Computing
Computing
Math1090,EECS3101
Computable & Uncomputable
Time Complexity
Classifying Functions
Math1090,EECS2001
Coding Phase vs Execution Phase
Table Lookup and TM
Probabilistic Algorithms
Universal TM
Hugely Expressive
Many Courses
Jeff Edmonds Math1090,EECS2001,
3101,6111
Lecture 5.1 York University
Applications
Applications
An Algorithm/Program/Machine M is
• a set of instructions
(described by a finite string “M”)
• on a given input I
• follow instructions and
• produces output M(I)
• or runs forever.
Eg: Insertion Sort
Computable Problem
Problem P is
computable if
$M, "I, M(I)=P(I)
$M,“Machine/Algorithm M
computes problem P.”
"I, “Machine/Algorithm M
gives the answer required
by problem P on input I.”
M(I)=P(I)
Computable Problem
Problem P is
computable if
$M, "I, M(I)=P(I)
I am invested in proving that the sentence is true.
I produce a good object when it is a $.
I have a machine M that I claim works.
REALY matters.
If you don’t know if it is true or not,
trust the game.
Computable Problem
Problem P is Problem P is
true computable if uncomputable if true
$M, "I, M(I)=Sorting(I) "M, $I, M(I) Halting(I)
"I, $M, M(I) = Halting(I) true
I give you an input I.
Given I either
Halting(I) = yes or
Halting(I) = no.
I needed to do this
in order to prove my incompleteness theorem.
Gödel’s 1929
Unknown
Turing 1936
Known
GCD
Time Complexity
Computable Halting
Exp
Poly
f(n) = θ(g(n))
f(n) = θ(g(n))
Let c=2n.
The relation is true.
2n ≤ 2nn = cn
Classifying Functions
Theta f(n) = θ(g(n)) f(n) ≈ c g(n)
BigOh f(n) = O(g(n)) f(n) ≤ c g(n)
Omega f(n) = Ω(g(n)) f(n) ≥ c g(n)
Little Oh f(n) = o(g(n)) f(n) << c g(n)
Little Omega f(n) = ω(g(n)) f(n) >> c g(n)
3n2 + 7n + 8 = nθ(1)
Polynomial time
3n n = 2[ log(3) n + log n ]
= 2θ(n)
Exponential time
P A I A(I)=P(I)
M multiplies xy. No
2,3 6
2,4 8
57
Probabilistic Algorithms
Remember Quick Sort
Problem P is computable if
$A, "I, A(I)=P(I) & Time(A,I) ≤ T =n2
No. Actually, I am quite mean.
I really do give a worst case input.
My algorithm A specifies to pivot with the middle item.
I know this.
My input I puts the smallest element in the middle.
Oh dear.
58
Probabilistic Algorithms
Problem P is computable by a random algorithm if
$A, "I, R, AR(I)=P(I)
I have a random algorithm A that I claim works.
My algorithm is to open random doors
hoping to find a prize.
Note that this makes all doors
symmetrically the same.
59
Probabilistic Algorithms
Problem P is computable by a random algorithm if
$A, "I, R, AR(I)=P(I)
I have a random algorithm A that I claim works.
60
Probabilistic Algorithms
Problem P is computable by a random algorithm if
$A, "I, R, AR(I)=P(I)
I have a random algorithm A that I claim works.
61
Probabilistic Algorithms
Problem P is computable by a random algorithm if
$A, "I, PrRR, AR(I)=P(I) ≥ 1-2-T
Time(AR,I) ≤ T
Half the doors have prizes.
For each random door, the probability of finding a prize
is ½.
63
Universal TM
64
Universal TM
ComputeM(I,y) ≡ “M(I)=y”
A Turing Machine
(1936)
is the simplest model
of computation.
66
Universal TM
MLaptop(M,I) = M(I).
universal
A Universal TM is a TM Muniversal that is given
a description of a TM M and its input I
and simulates this computation.
$ TM Muniversal " inputs Iuniversal = M,I Muniversal (M,I) = M(I).
Predicate Logic Game:
• We construct Muniversal
• The adversary gives us an arbitrary input Iuniversal = M,I
(Adversary knows Muniversal and hence
M can be much bigger than Muniversal)
• Prove Muniversal (M,I) = M(I).
Hugely Expressive
"x, $y, y>x
Predicate logic can only say these stupid things.
Why should I care?
Actually, it is hugely expressive.
• Math: For any mathematical statement you want to understand
and prove, it is best to first write it as a Predicate logic sentence.
• Proof: Sometimes the mechanics of the proof just falls out.
• The next example is really quite amazing!
Hugely Expressive
"x, $y, y>x
All Computation: There is a Predicate logic sentence Compute(J,I,y).
• Over the integers (+,), i.e. of the form "x, $i, (xJ ≤ I+i)
A Turing Machine
(1936)
is the simplest model
of computation.
t 11012 [0,0,1,1,0,0,1,1,0]
t+1 10102 [0,0,1,1,1,0,1,1,0]
…
Hugely Expressive
ComputeM(I,y) ≡ “M(I)=y”.
Consider the computation of TM M(I):
• δ(q1,0) = q1011,1,right Write state names in binary.
• δ(q1011,1) = …
• Halts in state q110.
• With output y = 0011101010 on the tape.
A valid computation of a TM
Time state Tape Contents Head
1 12 [0,1,1,0,0,1,1]
2 10112 [1,1,1,0,0,1,1]
…
t 11012 [0,0,1,1,0,0,1,1,0]
t+1 10102 [0,0,1,1,1,0,1,1,0]
…
Hugely Expressive
ComputeM(I,y) ≡ “M(I)=y”.
Lets encoded this entire computation into a single integer C.
• Gödel needed to invent computation before Turing.
• Gödel used prime numbers in a strange recursive way.
• This is Jeff’s encoding just adds a few more digits.
A valid computation of a TM
Time state Tape Contents Head
1 12 [0,1,1,0,0,1,1] Mark Head
2 10112 [1,1,1,0,0,1,1] with digit 2
…
t 11012 [0,0,1,1,0,0,1,1,0]
t+1 10102 [0,0,1,1,1,0,1,1,0]
…
Hugely Expressive
ComputeM(I,y) ≡ “M(I)=y”.
Lets encoded this entire computation into a single integer C.
• Gödel needed to invent computation before Turing.
• Gödel used prime numbers in a strange recursive way.
• This is Jeff’s encoding just adds a few more digits.
A valid computation of a TM
Time state Tape Contents Head 2
1 12 [2,0,1,1,0,0,1,1] Separate
Mark Head
blocks
2 10112 [1,2,1,1,0,0,1,1] with
withdigits
digit 3,4
2
…
t 11012 [0,0,1,1,2,0,0,1,1,0]
t+1 10102 [0,0,1,2,1,1,0,1,1,0]
…
Hugely Expressive
ComputeM(I,y) ≡ “M(I)=y”.
Lets encoded this entire computation into a single integer C.
• Gödel needed to invent computation before Turing.
• Gödel used prime numbers in a strange recursive way.
• This is Jeff’s encoding just adds a few more digits.
A valid computation of a TM
Time state Tape Contents Head 2
4 1 3 [2,0,1,1,0,0,1,1] Separate blocks
Remove
with [,]3,4
digits
4 1011 3 [1,2,1,1,0,0,1,1]
…
4 1101 3 [0,0,1,1,2,0,0,1,1,0]
4 1010 3 [0,0,1,2,1,1,0,1,1,0]
…
Hugely Expressive
ComputeM(I,y) ≡ “M(I)=y”.
Lets encoded this entire computation into a single integer C.
• Gödel needed to invent computation before Turing.
• Gödel used prime numbers in a strange recursive way.
• This is Jeff’s encoding just adds a few more digits.
A valid computation of a TM
Time state Tape Contents Head 2
4 1 3 20110011
Remove
Merge Digits
[,]
4 1011 3 1 2 1 1 0 0 1 1
…
4 1101 3 0011200110
4 1010 3 0012110110
…
Hugely Expressive
ComputeM(I,y) ≡ “M(I)=y”.
Lets encoded this entire computation into a single integer C.
• Gödel needed to invent computation before Turing.
• Gödel used prime numbers in a strange recursive way.
• This is Jeff’s encoding just adds a few more digits.
= 4132011001141011312110011…
40000
i j
Wow
That was cool.
End