cs 381 - summer 2005 final class - july 1st assorted fun topics in computability and complexity

Post on 20-Dec-2015

220 Views

Category:

Documents

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

CS 381 - Summer CS 381 - Summer 20052005

CS 381 - Summer CS 381 - Summer 20052005

Final class - July 1stFinal class - July 1stAssorted fun topics in computability and Assorted fun topics in computability and

complexitycomplexity

One-slide summary of 381

Linguistic Formalism Device

Reg exp DFA

CFG NPDA

CSG NLBA

Recursive languages Total TM

R. E. languages TM

Practical uses of these languages

• Regular expressions– pattern matching– lexical analysis in compilers

• CFGs– compilers– NLP

• Recursive languages– everything computers do!

What happens now?• Many more practical applications

(program analysis, databases)– may need to design a new language; tradeoff

between expressivity of language and the difficulty of implementing/analyzing programs

• As new computational devices are created (e.g. cellular automata, quantum computers), want to reason about their power relative to TMs

What happens now? (2)• Recursion (Computability) Theory

studies the hierarchy of languages above the r.e. sets– oracle TMs : suppose I could get answers to

arbitrary instances of HP "for free". What would this allow me to compute?

– suppose I had TMs taking real numbers as input (so inputs may be infinite). What functions can these compute?

What happens now? (3)• Complexity Theory studies issues that

arise when we put time or space constraints on our computational devices– e.g. TMs bounded to run in time or space

polynomial in the length of the input– or other computational devices, like circuits– The P vs NP question - most famous open

problem in all of CS.

Fun topic #1 - cellular automata

• A computational model equivalent to a Turing machine

• Based on natural phenomena– e.g. the generation of patterns on seashells

• Most famous example - "Game of Life"– created by John Conway

Game of Life• Infinite square grid; some cells are

"alive", others are "dead"• Cells can die or come to life depending on their neighbors

The rules of life• If a live cell has fewer than 2 live

neighbors, it dies (loneliness)• If a live cell has more than 3 live

neighbors, it dies (overcrowding)• If a live cell has 2 or 3 live neighbors, it

goes on living• If a dead cell has exactly 3 live

neighbors, it becomes alive (reproduction)

How the game runs• The game proceeds in generations• Initially, a finite number of cells is

live• In each generation, some cells

become live and some die according to the rules

Example:

Why this game is addictive...

• Various interesting patterns emerge– "gliders", "spaceships"– demo (see website, Resources

section, for references)

Computing with the Game of Life

• Prime numbers (demo)• Can make a full Turing machine!• Game of Life is just one example of

cellular automata– many more exist; for example, 1-

dimensional CAs– even 1-dimensional CAs can simulate a TM!

More on computation in nature

• Another model - L-systems (similar to CFGs/CSGs)– related to fractals– JFLAP can handle L-systems– for references see course website

• Fun reading: "The Computational Beauty of Nature", by Gary W. Flake

Fun topic #2 - Quines• Brought to us through the power

of recursion theory.– A very deep theorem called the

Recursion Theorem is behind quines

• A quine is a program that prints itself out.

From our course website - Java Quine

class Quine {

public static void main(String[] v) {

char c = 34;System.out.print(s+c+s+c+';'+'}');

}

static String s ="class Quine{public static void main(String[]v){char

c=34;System.out.print(s+c+s+c+';'+'}');}static String s=";

}

How does it work? (is it magic?)

• A quine in English:Print two copies of the following, the second one in

quotes:

"Print two copies of the following, the second one in quotes:"

• A quine has 2 parts:– "code" - instructions for printing– "data" - includes a listing of the code

Java Quine, revisitedclass Quine {

public static void main(String[] v) {

char c = 34;System.out.print(s+c+s+c+';'+'}');

}

static String s ="class Quine{public static void main(String[]v){char

c=34;System.out.print(s+c+s+c+';'+'}');}static String s=";

}

Data

Java Quine, revisitedclass Quine {

public static void main(String[] v) {

char c = 34;System.out.print(s+c+s+c+';'+'}');

}

static String s ="class Quine{public static void main(String[]v){char

c=34;System.out.print(s+c+s+c+';'+'}');}static String s=";

}

Data

Code (compare with data!)

Java Quine, revisitedclass Quine {

public static void main(String[] v) {

char c = 34;System.out.print(s+c+s+c+';'+'}');

}

static String s ="class Quine{public static void main(String[]v){char

c=34;System.out.print(s+c+s+c+';'+'}');}static String s=";

}

Data

Print 2 copies of data, second one in quotes, followed by ; and }

Output of Java Quine?(with spaces added)

class Quine {

public static void main(String[] v) {

char c = 34;System.out.print(s+c+s+c+';'+'}');

}

static String s ="class Quine{public static void main(String[]v){char

c=34;System.out.print(s+c+s+c+';'+'}');}static String s=";

}

Second copy of

data

First copy of data

Quotes

Closing ; and }

More quines• Can make quines in any Turing-complete language - see website refs.• Can even make a TM that prints out its own description on the tape!• The closest thing to the above is a quine in BrainF***:

->++>+++>+>+>+++>>>>>>>>>>>>>>>>>>>>>>+>+>++>+++>++>>

+++>+>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>+>+>>+++>>>>+++>>>

+++>+>>>>>>>++>+++>+++>+>+++>+>>+++>>>+++>+>++>+++>>

>+>+>+>+>++>+++>+>+>>+++>>>>>>>+>+>>>+>+>++>+++>+++>+

>>+++>+++>+>+++>+>++>+++>++>>+>+>++>+++>+>+>>+++>>>+

++>+>>>++>+++>+++>+>>+++>>>+++>+>+++>+>>+++>>+++>>+[

[>>+[>]+>+[<]<-]>>[>]<+<+++[<]<<+]>+[>>]+++>+[+[<++++++++++++++++>-]<++++++++++.<]

Confused enough?• If a TM can print out its own

description on the tape (through a quine), it can then use that description to simulate itself on something!– Huh?– The recursion theorem talks about

that (kind of)

Fun topic # 3 - P vs NP• Restrict TMs so that they have to

halt in polynomially many time steps (in the length of the input)

• What class of problems can be solved in polynomial time?– Depends if the machine is

deterministic or not (maybe!!)

P vs NP• P = class of problems that can be

solved in PTIME on a deterministic TM

• NP = class of problems that can be solved in PTIME on a nondeterministic TM

An example of a problem in NP

• Hamiltonian Cycle– Given an undirected graph, find a cycle that

visits each vertex exactly once.

• Can do it in NP - guess the cycle and verify that it's correct– verification step itself takes polynomial time

• But can we find it fast, without guessing?

Lots of problems known to be in NP

• You'll see some of them in 482• Factoring - important for crypto• We even have reductions between them;

if we could solve HAMCYCLE in polynomial time, would immediately have solutions for multiple other problems

• But a general proof that P = NP or not still eludes us

Next week• Review session Tuesday July 5th

– send me your questions, or come armed with them

• Final exam July 6th, 3-5:30 pm– watch CMS for sample questions on TMs– cumulative, but somewhat more

emphasis on TMs

381

top related