Sunteți pe pagina 1din 37

A Gentle Introduction to Theory of Computation:

Ravindra V. Joshi

Goals of the session


What is meant by Computation? A model for Computation ( Turing Machine ) Why Turing Machine is Universal? Relevance of Church-Turing thesis Halting theorem and its proof ( informal ) Complexity P, NP, NP-Hard, NP-Complete Most Important Problem in Computer Science!!

Theory of Computations
What are different types of Computers (Automata ) and what kind of problems can be solved by them?
FSM RegEx Pattern Matching PDA CFG -> Language Parsers TM -> TM-Languages -> All computer languages and Programs

Turing Machine (Revised )

Universal Turing Machine

Universal Turing Machine


In other words, Any UTM with any number of Tapes and Heads can be simulated by a 3-Tape Head in Polynomial Time

How Universal is UTM ?


Church-Turing thesis : Every form of computation can be expressed as a TM with Polynomial overhead Parallel Real ( Precision ) Randomness
A Tape with Random Bits

Quantum Computation Other Exotic Theories ( String Theory!!! ) Natural-BIO_Inspired


ANN, ACO, Swarm_Intelligence, Cellular Automata and other algorithms

Apporximate Solutions
for subset of all Inputs for some Sub Optimal Solution

UnComputability
0-Normal Idea = Input Program Output
Hello, Hyderabad; Hello, Bangalore; Hello, Chennai; Hello, Mumbai;

PROGRAM TO COUNT NO OF SEMICOLONS

Hello

PROGRAM TO REVERSE RS(REVERSE A STRING) Get(s); While( *s ) S.Push(s); While ( !S.Empty() ) Print S.Pop();

olleH

UnComputability
1- Idea-Program as Input = Another Program Program Output
RS(REVERSE A STRING) Get(s); While( *s ) Stack.Push(*s); While ( !Stack.Empty() ) Print Stack.Pop(); PROGRAM TO COUNT NO OF SEMICOLONS Get (S); Count = 0; Foreach ( char c in S ) If ( c==; ) Count++; Print Count;

UnComputability
Idea 2- Same-Program as Input To Itself = Program Program Output
PROGRAM TO COUNT NO OF SEMICOLONS Get (S); Count = 0; Foreach ( char c in S ) If ( c==; ) Count++; Print Count; PROGRAM TO COUNT NO OF SEMICOLONS Get (S); Count = 0; Foreach ( char c in S ) If ( c==; ) Count++; Print Count;

UnComputability Hello, World


Consider a program to print Hello, World

Print Hello, World

Hello, World

While(true) ; Print Hello, World;

UnComputability Dependency of Ouptut on both Program and Input


This program will print Hello, world for positive values and 0 but not for negative values The point is same program may print Hello, World for some data and may not, for some other and vice versa

Get(x); While(x != 0 ) x-- ; Print Hello, World

Hello, World

The UnComputability Problem


Given a Program P and Input I can we say whether it will print Hello, World or not?

P PRINTS_HW If P prints HW for input I return TRUE else FALSE I

TRUE

FALSE

UnComputability Problem - Proof


Let us consider the pseudo-code for H The Undecidability function H( P, I ) {

If ( P halts over I ) Return Yes Else Return No


}

UnComputability Proof ( contd )


Let us construct a function H1 on top of H as follows H1( P, I) { IF (H( P, I) == TRUE ) Print YES; ELSE Print Hello, World; }

UnComputability
Let us build a function H2 on top of H1. H2( P ) { H1(P,P) } Here a program is given as input to the same program. This eliminates the need for Data. H2(P) If a Program P ( /* when P itself is given as input to it */) prints Hello World, it prints YES else it prints Hello, World Now, the twist comes, what happens when we invoke following function H2(H2)?

UnComputability( contd )
// IF H2 can print HW, then Yes // ELSE should Print Hello, World // CASE-A: H2(H2) will print HW I.e., H(H2,H2)==> YES

H2(H2) H1(H2,H2) H(H2,H2) returns TRUE H1 prints YES Output is YES Where is "Hello, World?"

Uncomputability( Contd. )
//CASE-B: H2(H2) will not print HW i.e., //PRINTS(H2,H2)==>FALSE H2(H2) H1(H2,H2) H(H2, H2) returns FALSE In H1, ELSE part is executed "Hello, World" is printed But according to our own starting condition, H2(H2) should not print "Hello, World"

UnComputability Problem Proof ( Final )


H2 is a contradiction H2 can not exist H1 can not exist H can not exist Our assumption was wrong Hence the theorem

Uncomputability Problem Implemented in LISP

UnComputability Problem Implemented in LISP

From Computability To Complexity


Given that a function is Computable by Turing Machine how many instances of Turing Instructions will be executed? In other words, how efficient is given function? Given a definition of Problem, can we tell what is the minimum number of instructions required to implement it?

Some Complexity Classes


Let n be the size of input ( like Length of Array ) P-Polynomial - No of steps required can be expressed as a polynomial of (length of Array ) O(n^2) Complement of Polynomial
Cannot expressed as Polynomial of n Exponential of n

NP Problems whose correctness can be verified within Polynomial number of steps


NP is not same as Complement of P, in fact it is super set of P

NP-Hard, a class of problems which are currently solvable in exponential time only, and satisfy a curious property that if one of the problems belonging to this class can be solved, all the problems in that class can be solved NP-Complete : A problem that is both NP and NP-Hard

Examples
P - Sorting Problem NP Dinner Party Problem NP Hard Finding the Hamiltonian Circuit in a Graph NP Complete Mine Sweeper, also Dinner Party

Example ofOF ALL PARTIES - Dinner Party MOTHER NP Problem

But---Guests should be carefully invited

But---Guests should be carefully invited

But---Guests should be carefully invited

But---Guests should be carefully invited

Complexity Classes, Visualized

NP P NP-COMPLETE NP-HARD

Most Important Question in Computer Science Today


Is this relation true?

http://www.claymath.org/millennium/P_vs_NP/

Some Historical background


http://blog.computationalcomplexity.org/2006/04/kurt-gdel-19061978.html In a letter written by Godel to Neumann, Godel raises the question of P=NP

QUESTIONS??

THANK YOU

Testing Ourselves Have we really understood Uncomputability theoremto do all this twisting and turning? Cant be there a 1. Do we need
2. simpler proof? We reverse the functionalities of h in h1. Is this fair? Can't we negate existence of any logic by this kind of approach? Just consider following series functions

MoreThan100 ( P ) { If P contains more than 100 Lines Return TRUE Else Return FALSE }

Testing Ourselves
h1( P ) { If MoreThan100( P ) Print No Else Print Yes }

h2( P ) {
h1( P ) }

Testing Ourselves
3. Answer following questions on programs above.
a. b.
c.

Is h2 necessary? What will be the output when A program contains 50 lines? 150 lines? hat will be output of h2(h2)? Will it not give wrong results ? Does this mean there cannot be a program to count the no. of lines( We all know that there indeed exists a program. Then, where did we go wrong?

4.

When we map h2(p) ==> h1( p, p). Is it merely, an approach to reduce two parameters to one? Could'nt we make h1 accept only program and no data h1(p,null)? Or Program P and Data some f(P). F may be any string transforming function?

Testing Ourselves
3. 4. 5. In Final step, we give H2 only as input to H2. Is this a must? If so, why? Can't we find a simpler version? Prove the Undecidability of Halting Theorem This is only out-line of the Proof. Formal forms techniques used here are known as Diagonalization and Reduction. Study them

S-ar putea să vă placă și