Data Structures and Functional Programming Computability Ramin Zabih Cornell University Fall 2012.

Slides:



Advertisements
Similar presentations
Lecture 19. Reduction: More Undecidable problems
Advertisements

Problem: Give as many proofs as you can for the Pythagorean Theorem. i.e., a 2 + b 2 = c 2 holds for any right triangle with sides a & b and hypotenuse.
The Big Picture Chapter 3. We want to examine a given computational problem and see how difficult it is. Then we need to compare problems Problems appear.
1 COMP 382: Reasoning about algorithms Unit 9: Undecidability [Slides adapted from Amos Israeli’s]
Week 7 - Wednesday.  What did we talk about last time?  Set proofs and disproofs  Russell’s paradox.
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
Computability and Complexity 4-1 Existence of Undecidable Problems Computability and Complexity Andrei Bulatov.
1 Undecidability Andreas Klappenecker [based on slides by Prof. Welch]
Complexity 11-1 Complexity Andrei Bulatov Space Complexity.
1 Introduction to Computability Theory Lecture12: Reductions Prof. Amos Israeli.
Introduction to Computability Theory
Courtesy Costas Busch - RPI1 A Universal Turing Machine.
CPSC 411, Fall 2008: Set 12 1 CPSC 411 Design and Analysis of Algorithms Set 12: Undecidability Prof. Jennifer Welch Fall 2008.
1 Linear Bounded Automata LBAs. 2 Linear Bounded Automata are like Turing Machines with a restriction: The working space of the tape is the space of the.
1 Undecidability Andreas Klappenecker [based on slides by Prof. Welch]
1 Module 7 Halting Problem –Fundamental program behavior problem –A specific unsolvable problem –Diagonalization technique revisited Proof more complex.
CHAPTER 4 Decidability Contents Decidable Languages
1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 29: Computability, Turing Machines, Can Computers Think?
Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing.
CS 310 – Fall 2006 Pacific University CS310 The Halting Problem Section 4.2 November 15, 2006.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 18 Instructor: Paul Beame.
CS21 Decidability and Tractability
1 Introduction to Computability Theory Lecture11: The Halting Problem Prof. Amos Israeli.
Halting Problem. Background - Halting Problem Common error: Program goes into an infinite loop. Wouldn’t it be nice to have a tool that would warn us.
04/25/13 Halting Problem Discrete Structures (CS 173) Derek Hoiem, University of Illinois 1
Theory of Computing Lecture 19 MAS 714 Hartmut Klauck.
MA/CSSE 474 Theory of Computation More Reduction Examples Non-SD Reductions.
1 Undecidability Reading: Chapter 8 & 9. 2 Decidability vs. Undecidability There are two types of TMs (based on halting): (Recursive) TMs that always.
Lecture 1 Computation and Languages CS311 Fall 2012.
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 15-1 Mälardalen University 2012.
Great Theoretical Ideas in Computer Science for Some.
Copyright © Cengage Learning. All rights reserved. CHAPTER 7 FUNCTIONS.
Ch. 11: Cantor’s Infinity!. N = {1, 2, 3, 4, 5, 6, …} “the natural numbers” Z = {…, –3, –2, –1, 0, 1, 2, 3, …} “the integers” Q = {all quotients “a/b”
Great Theoretical Ideas in Computer Science about AWESOME Some Generating Functions Probability Infinity Computability With Alan! (not Turing) Mind-
Halting Problem Introduction to Computing Science and Programming I.
A Universal Turing Machine
CSE 311 Foundations of Computing I Lecture 26 Computability: Turing machines, Undecidability of the Halting Problem Spring
CSE 311 Foundations of Computing I Lecture 29 Computability: Turing machines, Undecidability of the Halting Problem Autumn 2012 CSE 3111.
Halting Problem and TSP Wednesday, Week 8. Background - Halting Problem Common error: Program goes into an infinite loop. Wouldn’t it be nice to have.
1 Linear Bounded Automata LBAs. 2 Linear Bounded Automata (LBAs) are the same as Turing Machines with one difference: The input string tape space is the.
1 Turing’s Thesis. 2 Turing’s thesis: Any computation carried out by mechanical means can be performed by a Turing Machine (1930)
SNU OOPSLA Lab. 1 Great Ideas of CS with Java Part 1 WWW & Computer programming in the language Java Ch 1: The World Wide Web Ch 2: Watch out: Here comes.
TM Design Macro Language D and SD MA/CSSE 474 Theory of Computation.
Lecture 4 Infinite Cardinals. Some Philosophy: What is “2”? Definition 1: 2 = 1+1. This actually needs the definition of “1” and the definition of the.
CSE 311: Foundations of Computing Fall 2013 Lecture 26: Pattern matching, cardinality.
CSE 311: Foundations of Computing Fall 2014 Lecture 27: Cardinality.
1 Undecidability Andreas Klappenecker [based on slides by Prof. Welch]
Week 7 - Wednesday.  What did we talk about last time?  Proving the subset relationship  Proving set equality  Set counterexamples  Laws of set algebra.
CompSci Today’s Topics Computer Science Noncomputability Upcoming Special Topic: Enabled by Computer -- Decoding the Human Genome Reading Great.
Theory of Computation Automata Theory Dr. Ayman Srour.
1 A Universal Turing Machine. 2 Turing Machines are “hardwired” they execute only one program A limitation of Turing Machines: Real Computers are re-programmable.
Fall 2013 Lecture 27: Turing machines and decidability CSE 311: Foundations of Computing.
Module 7 Halting Problem –Fundamental program behavior problem –A specific unsolvable problem –Diagonalization technique revisited Proof more complex 1.
Modeling Arithmetic, Computation, and Languages Mathematical Structures for Computer Science Chapter 8 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesTuring.
The Acceptance Problem for TMs
A Universal Turing Machine
CS 461 – Nov. 2 Sets Prepare for ATM finite vs. infinite Infinite sets
Set Operations CS 202, Spring 2008 Epp, chapter 5.
CSE 311 Foundations of Computing I
Lecture12 The Halting Problem
CSCE 411 Design and Analysis of Algorithms
Decidable Languages Costas Busch - LSU.
Halting Problem.
Discrete Math for CS CMPSC 360 LECTURE 43 Last time: Variance
Formal Languages, Automata and Models of Computation
CS21 Decidability and Tractability
Cpt S 317: Spring 2009 Reading: Chapter 8 & 9
Computability and Undecidability
Discrete Mathematics CS 2610
Turing Machines Everything is an Integer
Presentation transcript:

Data Structures and Functional Programming Computability Ramin Zabih Cornell University Fall 2012

What have we covered? Tools for solving difficult computational problems  Abstraction, specification, design  Functional programming  Concurrency  Reasoning about programs  Data structures and algorithms

Computer science vs programming There are over 100x as many computer programmers as computer scientists  What is the difference? There are programs that exist, and programs that do not but clearly could  Ukrainian spell checker for Android Computer programmers write such programs  Always clear such a program exists  Not trivial to write within resource constraints –Programmer time, budget, running time & space, …

When do computer scientists program? Programs whose existence is not at all clear  Make a car that drives itself?  Distinguish pictures of cats from dogs?  Find broken bones in x-ray images?  Synthesize pictures that look real? Sometimes (often) we fail  “If you aren’t occasionally failing, then you are working on problems that are too easy.” Maybe the problem is fundamentally hard  No one could have solved it!  Correct compression algorithm?

Different excuses for failure 5 Garey & Johnson, Computers and Intractability

Set sizes Two sets A and B are the same size if there is an exact pairing between them. There is a set R of pairs (a b) such that: 1. every element of A occurs on the left-hand side of exactly one pair in R and 2. every element of B occurs on the right-hand side of exactly one pair in R.  Example: the sets {0,1,2} and {2,4,6} are the same size because we can pair them up as follows: (0 2), (1 4), (2 6).  This definition goes for infinite sets as well.

Countable sets A set is countable if it is the same size as the natural numbers N = {0,1,2,…}.  Countable sets are all the same size א 0  This is the smallest infinite size Not all infinite sets are this size!  There are larger infinities (how many?) If a set is countable we can list out its elements, starting with the zero-th, first, second, etc.  For example, Z is countable: we pair n with 2n, and –n with 2n+1

Countable sets (2) N is a subset of Z, but they are the same size??  Welcome to the confusing world of the infinite! The even numbers are a subset of N  But also countable: pair up n with 2n The rational numbers are countable also 1/1 1/2 1/3 1/4 1/5 2/1 2/2 2/3 2/4 2/5 3/1 3/2 3/3 3/4 3/5 4/1 4/2 4/3 4/4 4/5 5/1 5/2 5/3 5/4 5/5 Diagonal zigzag, skipping duplicates

There are countably many programs In OCaml, or any other language (or all)  A program is a finite string  We can number these: first is “a”, second is “b”, etc. Not all of these are legal programs But all legal programs are on the list! So far it looks like everything is countable In fact, any set whose elements are finite is countable!  If you can write down an element without risking taking forever, the set is guaranteed to be countable

Real numbers are uncountable The real numbers in [0,1) are not countable  The discoverer (Cantor) went to the asylum Think of a real number as a function from N to {0,1,…,9}, where f(m) is the m th digit  Example: π-3 = f, f(0)=1, f(1)=4, f(2)=1, f(3)=5 But functions from N to {0,1,…,9} are not countable!  Consider the simpler case of functions from N to {0,1}, i.e. binary representation of a real  Let’s write these functions down in order, starting with the first, and find a contradiction

Real numbers are uncountable (2) Call the first function f0, then f1, etc. Will write output as #f/#t for convenience inputs f0 | #f #t #f #t #f #t #f #t #f #t... f1 | #f #f #t #t #f #t #f #t #f #f... f2 | #t #f #t #f #t #f #t #f #t #f... f3 | #f #f #f #f #t #f #f #f #f #f... f4 | #f #t #f #f #t #t #t #f #f #t... But we can easily create a function not on this table by diagonalization  One of the all-time best ideas, applied by Cantor, Godel, Russell, Turing

Some uncountable sets The following sets are all the same size:  Boolean valued functions of 1 argument  Infinite binary strings  Real numbers in [0,1)  Paths in the infinite complete binary tree (0 = go left, 1 = go right)  Subsets of N There are uncountably infinitely many of each of these!

Back from math to programs Easy to write programs from integers to bool  Examples: prime, even, perfect, etc. But there are countably many programs and uncountably many such functions So there must be some function that we cannot write a program for  In fact, almost all such functions cannot be written, in any programming language  Similarly, almost all real numbers have no finite description  “Almost all” means a set of measure 0

An uncomputable programming task Does a function of one argument run forever on a given input?  halts(f,a) is true or false depending on f(a) Such a function is impossible in any programming language  We’ll prove it in a generic language (not OCaml) Consider a new boolean-valued function safely  Check to see if your argument halts on itself  Note that this always returns true or false safely(g) = if halts(g,g) then not(g(g)) else false  What is the boolean value of safely(safely)?

Uncomputable functions The halting problem is uncomputable  No matter the language or programmer!  More broadly, the only way you can figure out what a program does is to run it Enormous real-world consequences  App store  Microsoft plug-ins  Viruses  Computer security  Etc, etc.

Turing equivalence Computer scientists tend to say that all programming languages are equivalent  This isn’t quite true, there are actually some useful “weak” languages There is a precise way to say this using Turing equivalence  See CS3810, taught by John Hopcroft  One of Cornell’s Turing Award winners

When is a problem uncomputable? This is actually extremely difficult, but there are some good rules  Any non-trivial property of a program is uncomputable (Rice’s theorem)  Anything you can solve with exhaustive search is obviously computable  Small differences in problem formulation can change a computable problem into an uncomputable one! Here are some cool example problems

A children’s game We are given blocks with symbols such as a,b,c. Each block has a top and a bottom. There are certain types of blocks, such as a block with “ab” above “bc”. We have as many blocks of each type as we want. Can we find a series of blocks so that the top and bottoms symbols are the same?

Game examples 19

Can we solve the children’s game? For a binary alphabet (example 1) this is decidable For an alphabet with 7 characters or more it is undecidable! For an alphabet with 3 characters (example 2) it is an open question What if we can use no more than k blocks, including copies, in our solution? It’s decidable but you can’t do better than exhaustive search!

Tiling the plane 21

Final CS3110 example: hashing Problem: given a hash function from bit strings to bit strings (no size limits), does this function have two inputs that produce the same output, i.e. a collision? Reduction: if we could solve this we could solve the halting problem. Here’s how, care of Bobby Kleinberg: Consider this hash function 1. Let n denote the length of the input string, x. 2. Run program P for at most n steps. 3. If P halts before step n, output Else, output x. If P halts, this hashes all but finitely many strings to 0, so lots of collisions. If P does not halt, no collisions (identity function). So if we could determine that this hash function has collisions, we would know if P halts!

What have we learned? Smart ways to write big programs Fundamental algorithms and data structures Parallel programming Thursday night at 11:59PM will never be the same!

(See you at the final!) 24