View
4
Download
0
Category
Preview:
Citation preview
1
Polly Huang, NTU EE Theory of Computation 1
Introduction to Computer Science
Polly HuangNTU EEhttp://homepage.ntu.edu.tw/~pollyhuangpollyhuang@ntu.edu.tw
Polly Huang, NTU EE Theory of Computation 2
Chapter 12
Theory of Computation
2
Polly Huang, NTU EE Theory of Computation 3
Chapter 12: Theory of Computation®12.1 Functions and Their Computation®12.2 Turing Machines®12.3 Universal Programming Languages®12.4 A Noncomputable Function®12.5 Complexity of Problems®12.6 Public Key Cryptography
Polly Huang, NTU EE Theory of Computation 4
Functions® The relationship between
® F: x à y® A collection of possible input values
® x® And a collection of possible output values
® y® So that each possible input is assigned a
single output® y = F(x)
3
Polly Huang, NTU EE Theory of Computation 5
Computing®To determine the output value given an
input value®Given x®Get y
Polly Huang, NTU EE Theory of Computation 6
Example:Yards à Meters Conversion
4
Polly Huang, NTU EE Theory of Computation 7
Computability® Computable function
® Some functions are computable ® Output values can be determined algorithmically
from the input values
® Non-computable function ® Some functions are not computable® No well-defined, step-by-step process for
determining output based given input values® Beyond the ability of algorithmic systems
Polly Huang, NTU EE Theory of Computation 8
Chapter 12: Theory of Computation®12.1 Functions and Their Computation®12.2 Turing Machines®12.3 Universal Programming Languages®12.4 A Noncomputable Function®12.5 Complexity of Problems®12.6 Public Key Cryptography
5
Polly Huang, NTU EE Theory of Computation 9
Turing Machine
Polly Huang, NTU EE Theory of Computation 10
That is not all!
6
Polly Huang, NTU EE Theory of Computation 11
Theory and Practice®The theoretical part
®State machine
®The practical part®Head and tape
(Source: Turing’s World, http://www-csli.stanford.edu/hp/Turing1.html)
Polly Huang, NTU EE Theory of Computation 12
State Machines®Alphabets and symbols®States
®Start state®Halt state
Start Halt
7
Polly Huang, NTU EE Theory of Computation 13
Turing Machine Operation
® Inputs at each step®1. Current state®2. Value at current tape position
®Actions at each step®3. Write a value at current tape position®4. Move read/write head®5. Change state
Polly Huang, NTU EE Theory of Computation 14
Remember This?
( 1 , 1 , )
go d1 d2 back
( _ , _ , )
( 0 , 1 , )
( 1 , _ , )( 1 , _ , )
( 1 , 1 , )
( _ , _ , )
done
+
_ 1 1 1 0 1 1 _ _ _ …
_ 1 1 1 1 _ _ _ _ _ …
1. Current State
2. Value on tape
3. Write value4. Move head
5. Change state
8
Polly Huang, NTU EE Theory of Computation 15
Ex: Incrementing a Value
Polly Huang, NTU EE Theory of Computation 16
Begin
* 1 0 1 *
state = START
9
Polly Huang, NTU EE Theory of Computation 17
Step 2
* 1 0 1 *
state = ADD
Polly Huang, NTU EE Theory of Computation 18
Step 3
* 1 0 0 *
state = CARRY
10
Polly Huang, NTU EE Theory of Computation 19
Step 4
* 1 1 0 *
state = RETURN
Polly Huang, NTU EE Theory of Computation 20
Stop
* 1 1 0 *
state = HALT
11
Polly Huang, NTU EE Theory of Computation 21
Turing Computable Functions
Functions that can be computed by a Turing machine
Polly Huang, NTU EE Theory of Computation 22
Church-Turing Thesis
“The computable functions and the Turing computable functions are considered one and the same.”
12
Polly Huang, NTU EE Theory of Computation 23
In Other Words
®Any computable function is Turing computable
®Not proven, but generally accepted
Polly Huang, NTU EE Theory of Computation 24
A Turing Machine® Essence of computational process® As good as any algorithmic system
® If a problem can not be solved by a Turing machine, it can not be solved by any algorithmic system
® If a problem can be solved by any algorithmic system, it can be solved by a Turing machine
® Theoretical bound on the capabilities of actual machines
13
Polly Huang, NTU EE Theory of Computation 25
Chapter 12: Theory of Computation®12.1 Functions and Their Computation®12.2 Turing Machines®12.3 Universal Programming Languages®12.4 A Noncomputable Function®12.5 Complexity of Problems®12.6 Public Key Cryptography
Polly Huang, NTU EE Theory of Computation 26
Universal Programming Language® A language that can® Express a program to® Compute any computable function® Examples
® “Bare Bones”® Most popular programming languages
® If a problem can be solved algorithmically, it can be expressed using this language.
14
Polly Huang, NTU EE Theory of Computation 27
The Bare Bones Language
®Bare Bones®Very simple and yet universal language
®Statements®clear name;®incr name;®decr name;
®while name not 0 do; … end;
Polly Huang, NTU EE Theory of Computation 28
Tomorrow ß Today
Value of Aux, Today?
Value of Today, Tomorrow, Aux?
Aux=Today, Today=0
Today=Aux, Tomorrow=Aux, Aux=0
15
Polly Huang, NTU EE Theory of Computation 29
X * Y
Value of Z, W, Y?
Value of Y and W?
Z+=Y, W=Y, Y=0
Y=W, W=0
Polly Huang, NTU EE Theory of Computation 30
Quiz Time!
16
Polly Huang, NTU EE Theory of Computation 31
Universality of Bare Bones® Using the ‘increment’ Turing machine to
compute incr X® Bare Bones program for the addition function
® Assign, add, multiply
® Bare Bones language can be used to express algorithms for computing all (Turing-) computable functions
® Any computable function can be computed by a program written in Bare Bones
Polly Huang, NTU EE Theory of Computation 32
Chapter 12: Theory of Computation®12.1 Functions and Their Computation®12.2 Turing Machines®12.3 Universal Programming Languages®12.4 A Noncomputable Function®12.5 Complexity of Problems®12.6 Public Key Cryptography
17
Polly Huang, NTU EE Theory of Computation 33
The Halting Problem® This problem is not computable!
® Given the encoded version of any program® Return 1 if the program will eventually halt® Return 0 if the program will run forever
® Trying to predict in advance whether a program will terminate (or halt)
Polly Huang, NTU EE Theory of Computation 34
Assume a Solution Exist
18
Polly Huang, NTU EE Theory of Computation 35
Proof by Contradiction I
Polly Huang, NTU EE Theory of Computation 36
Proof by Contradiction II
19
Polly Huang, NTU EE Theory of Computation 37
A Story of Contradiction®Mother and child coming across a river®The child falls®A crocodile grabs the child®Mother pleads that the crocodile let go
of the child
Polly Huang, NTU EE Theory of Computation 38
Crocodile’s Challenge®The Crocodile says to the mother ®Say something® If it is right, I’ll give you your child back® If wrong, I’ll eat your child
20
Polly Huang, NTU EE Theory of Computation 39
Smart Mom?®The troubled mother thinks and says®You will eat my child®The crocodile …
Polly Huang, NTU EE Theory of Computation 40
Moral of the Story
There are problems in the world that is not computable!
21
Polly Huang, NTU EE Theory of Computation 41
Chapter 12: Theory of Computation®12.1 Functions and Their Computation®12.2 Turing Machines®12.3 Universal Programming Languages®12.4 A Noncomputable Function®12.5 Complexity of Problems®12.6 Public Key Cryptography
Polly Huang, NTU EE Theory of Computation 42
Complexity of Problems
® Time complexity® Number of instruction executions required® “Complexity”à “time complexity”® For a series of n entries, f(n)
® A problem is in class O(f(n)) if it can be solved by an algorithm in Θ(f(n)) or better.
® Θ(n2): complexity is kn2+o(n2 )® f(n)/n2 à k, n à ∞
22
Polly Huang, NTU EE Theory of Computation 43
Merging Two Lists
Polly Huang, NTU EE Theory of Computation 44
Merge Sort
23
Polly Huang, NTU EE Theory of Computation 45
The Hierarchy
Polly Huang, NTU EE Theory of Computation 46
n, lgn, nlgn, n2
24
Polly Huang, NTU EE Theory of Computation 47
Class P
®Class P®All problems in any class Θ(f(n)), where f(n)
is a polynomial® Intractable
®All problems too complex to be solved practically
®Most computer scientists consider all problems not in class P to be intractable.
Polly Huang, NTU EE Theory of Computation 48
Intractable Problems
® Intractable - All problems ® too complex to be solved practically
® (1) Most computer scientists consider all problems not in class P to be intractable.
® (2) Non-computable problems, of course intractable®E.g., halting problem, the self-contradiced
crocodile problem
25
Polly Huang, NTU EE Theory of Computation 49
Problem Classification
computable non-‐computable
The Challenge is®Given a problem®Can you tell for sure if it’s P or non-P or
non-computable?
®For some problems, yes®Search, sort, halting
®But for some problems, not quite
Polly Huang, NTU EE Theory of Computation 50
26
P or non-P?
How do you know if there exists a polynomial time algorithm for a problem?
Polly Huang, NTU EE Theory of Computation 51
Polly Huang, NTU EE Quiz 52
Recall Quiz #17® The old bank ATM system requires a
password of 4 digits (from 0-9)® Hack the password
27
Polly Huang, NTU EE Quiz 53
Many Solutions® Exhaustively try passwords
® 0000, 0001, 0002, …, 0010, 0011, …
®Try the popular passwords® Identify the birthday of the potential
victim®…
Polly Huang, NTU EE Quiz 54
Common of these Solutions® One can’t compute for the sure password® But one can compute to verify if the
guess/attempt is successful
28
Polly Huang, NTU EE Theory of Computation 55
Class NP
® Class NP - All problems ® (1) whose answers can be verified in polynomial time® (2) that may be solved by a non-deterministic algorithm
® Non-deterministic algorithm - An “algorithm”® whose steps may not be uniquely and completely
determined by the process state® May require “creativity”, “guessing”, ”randomness”
® Whether the class NP is bigger than class P is currently unknown.
Polly Huang, NTU EE Theory of Computation 56
Problem Classification
A US$ 1 million ?
29
Polly Huang, NTU EE Theory of Computation 57
NP-Complete Problems®Problems having the property that
®A polynomial time solution for any of them ®Would provide a polynomial time solution
for all the other problems in NP as well®~Hardest problems in NP
The Quest is simiplified to
Find a polynomial solution for any of the NP-Complete problems
Polly Huang, NTU EE Theory of Computation 58
30
Polly Huang, NTU EE Theory of Computation 59
Chapter 12: Theory of Computation®12.1 Functions and Their Computation®12.2 Turing Machines®12.3 Universal Programming Languages®12.4 A Noncomputable Function®12.5 Complexity of Problems®12.6 Public Key Cryptography
Polly Huang, NTU EE Theory of Computation 60
Public Key Cryptography
® Key ® Specially generated set of values used for
encryption® Public key: used to encrypt messages® Private key: used to decrypt messages
® RSA® A popular public key cryptographic algorithm® Relies on the (presumed) intractability of the
problem of factoring large numbers
31
Polly Huang, NTU EE Theory of Computation 61
RSA
Encrypt and Decrypt®Public key: e®Private key: d®Generator: n
® (data)e mod n = secret® (secret)d mod n = data
® (secret)e mod n <> dataPolly Huang, NTU EE Theory of Computation 62
32
Polly Huang, NTU EE Theory of Computation 63
Encrypting 10111®Encrypting keys: e = 5 and n = 91®10111two = 23ten
®23e = 235 = 6,436,343®6,436,343 ÷ 91 has a remainder of 4®4ten = 100two
®Therefore, encrypted version of 10111 is 100.
Polly Huang, NTU EE Theory of Computation 64
Decrypting 100®Decrypting keys: d = 29, n = 91®100two = 4ten®4d = 429 = 288,230,376,151,711,744®288,230,376,151,711,744 ÷ 91 has a
remainder of 23®23ten = 10111two
®Therefore, decrypted version of 100 is 10111.
33
Polly Huang, NTU EE Theory of Computation 65
RSA Key Generation
Given 2 Prime #: p and q®Compute n = pq®Compute φ = (p-1)(q-1)®Find d, e such that de mod φ = 1
®Keep d in private®Give e to the public
Polly Huang, NTU EE Theory of Computation 66
34
Polly Huang, NTU EE Theory of Computation 67
Quiz Time!
Polly Huang, NTU EE Theory of Computation 68
One algorithm®1. Factorize 91®2. Compute φ = (p-1)(q-1)®3. Populate possible de, say DE®4. Find DE/e such that {(DE mod e) = 0}
35
Polly Huang, NTU EE Quiz 69
Remember Q25?® Listen to Gru’s
plan on stealing the moon
® Sounds easy?® Suffices as an
algorithm?
Polly Huang, NTU EE Theory of Computation 70
Which step is the hardest?®1. Factorize 91®2. Compute φ = (p-1)(q-1)®3. Populate possible de, say DE®4. Find DE/e such that {(DE mod e) = 1}
36
Polly Huang, NTU EE Theory of Computation 71
Quiz Time!
Polly Huang, NTU EE Theory of Computation 72
295927 is an RSA-6
6 decimal digits (19 bits)
37
RSA-100100 decimal digits (330 bits)
RSA-100 = 1522605027922533360535618378132637429718068114961380688657908494580122963258952897654000350692006139
RSA-100 = 37975227936943673922808872755445627854565536638199 ×40094690950920881030683735292761468389214899724061
Polly Huang, NTU EE Theory of Computation 73
RSA-2048617 decimal digits (2048 bits)Cash prize: US$200,000
RSA-2048 = 251959084756578934940271832400483985714292821262040320277771378360436620207075955562640185258807844069182906412495150821892985591491761845028084891200728449926873928072877767359714183472702618963750149718246911650776133798590957 000973304597488084284017974291006424586918171951187461215151726546322822168699875491824224336372590851418654620435767984233871847744479207399342365848238242811981638150106748104516603773060562016196762561338441436038339044149526 34432190114657544454178424020924616515723350778707749817125772467962926386356373289912154831438167899885040445364023527381951378636564391212010397122822120720357
Polly Huang, NTU EE Theory of Computation 74
38
About RSA
Polly Huang, NTU EE Theory of Computation 75
Rivest, Shamir, Adleman
Polly Huang, NTU EE Theory of Computation 76
Questions?
Recommended