1 / 29

CS 381 - Summer 2005

CS 381 - Summer 2005. Final class - July 1st Assorted fun topics in computability and complexity. One-slide summary of 381. Practical uses of these languages. Regular expressions pattern matching lexical analysis in compilers CFGs compilers NLP Recursive languages

idalee
Télécharger la présentation

CS 381 - Summer 2005

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. One-slide summary of 381

  3. Practical uses of these languages • Regular expressions • pattern matching • lexical analysis in compilers • CFGs • compilers • NLP • Recursive languages • everything computers do!

  4. 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

  5. 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?

  6. 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.

  7. 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

  8. Game of Life • Infinite square grid; some cells are "alive", others are "dead" • Cells can die or come to life depending on their neighbors

  9. 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)

  10. 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

  11. Example:

  12. Why this game is addictive... • Various interesting patterns emerge • "gliders", "spaceships" • demo (see website, Resources section, for references)

  13. 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!

  14. 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

  15. 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.

  16. 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="; }

  17. 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

  18. Java Quine, revisited 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="; } Data

  19. Java Quine, revisited 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="; } Code (compare with data!) Data

  20. Java Quine, revisited 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="; } Print 2 copies of data, second one in quotes, followed by ; and } Data

  21. 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="; } First copy of data Second copy of data Quotes Closing ; and }

  22. 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***: ->++>+++>+>+>+++>>>>>>>>>>>>>>>>>>>>>>+>+>++>+++>++>> +++>+>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>+>+>>+++>>>>+++>>> +++>+>>>>>>>++>+++>+++>+>+++>+>>+++>>>+++>+>++>+++>> >+>+>+>+>++>+++>+>+>>+++>>>>>>>+>+>>>+>+>++>+++>+++>+ >>+++>+++>+>+++>+>++>+++>++>>+>+>++>+++>+>+>>+++>>>+ ++>+>>>++>+++>+++>+>>+++>>>+++>+>+++>+>>+++>>+++>>+[ [>>+[>]+>+[<]<-]>>[>]<+<+++[<]<<+]>+[>>]+++>+[+[<++++++ ++++++++++>-]<++++++++++.<]

  23. 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)

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

  25. 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

  26. 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?

  27. 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

  28. 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

  29. 381

More Related