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

29
CS 381 - Summer CS 381 - Summer 2005 2005 Final class - July 1st Final class - July 1st Assorted fun topics in computability Assorted fun topics in computability and complexity and complexity

Post on 20-Dec-2015

219 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

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

Page 2: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

One-slide summary of 381

Linguistic Formalism Device

Reg exp DFA

CFG NPDA

CSG NLBA

Recursive languages Total TM

R. E. languages TM

Page 3: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

Practical uses of these languages

• Regular expressions– pattern matching– lexical analysis in compilers

• CFGs– compilers– NLP

• Recursive languages– everything computers do!

Page 4: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

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

Page 5: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

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?

Page 6: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

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.

Page 7: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

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

Page 8: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

Game of Life• Infinite square grid; some cells are

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

Page 9: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

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)

Page 10: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

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

Page 11: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

Example:

Page 12: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

Why this game is addictive...

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

section, for references)

Page 13: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

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!

Page 14: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

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

Page 15: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

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.

Page 16: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

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=";

}

Page 17: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

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

Page 18: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

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

Page 19: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

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!)

Page 20: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

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 }

Page 21: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

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 }

Page 22: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

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***:

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

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

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

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

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

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

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

Page 23: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

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)

Page 24: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

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!!)

Page 25: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

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

Page 26: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

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?

Page 27: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

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

Page 28: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

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

Page 29: CS 381 - Summer 2005 Final class - July 1st Assorted fun topics in computability and complexity

381