Understanding The Halting Problem and Its Implications in Java Programming
This discussion delves into the complexities of the Halting Problem and presents intriguing Java programming examples that illustrate well-formed mathematical problems unsolvable by computers, regardless of speed. We explore the behavior of various Java programs, including "CountWordsInFile", "RunForever", and "StrangeProgram", to highlight cases where programs can either run indefinitely or yield unexpected results. Through these examples, we aim to foster a deeper understanding of computability, the limits of programming, and the inherent challenges posed by the Halting Problem.
Understanding The Halting Problem and Its Implications in Java Programming
E N D
Presentation Transcript
Very Hard Problems I am so not kidding about this. Please grab a handout.
What do you think? There are some well-formed mathematical problems that computers can’t solve, no matter how fast computers get. • True • False
Java Programs That Take Files as Inputs For example: CountOfWordsInFile.java …we run it like this “CountWordsInFile file.txt” And it prints the number of words in that file.txt. What if we ran it like this: “CountWordsInFile CountWordsInFile.java” What would it print? • That doesn’t make sense • It would run forever • The number of words in the CountWordsInFile.java file (say 100)
Ok, another program • RunForever.java • It’s a program with an infinite loop • …we run it like this “RunForever file.txt” • But no matter what file we put in, it runs forever • So what would happen if we run it like this: “RunForever RunForever.java” • That doesn’t make sense • It would run forever • It would print something
Still Another Program • RunWithItself.java • Just runs the java program passed in, with itself as input. So “RunWithItselfJavaProg.java” is the same thing as “JavaProg JavaProg.java” • So say we ran “RunWithItself CountWordsInFile.java” • That doesn’t make sense • It would run forever • It would print out a number
Penultimate Program WillRunForever.java • Really handy program that determines if a program will run forever *if passed itself as an input* (it acts a lot like RunWithItself.java) • Prints either “SAFE” or “DANGER” • This program never runs forever • What is the output of:
Last Program • StrangeProgram.java • Runs WillRunForever.java on it’s input. If WillRunForever.java prints “SAFE”, StrangeProgram runs forever. If WillRunForever.java prints “DANGER” StrangeProgram prints “STRANGE” and exits.
Final Question • What is the output of: StrangeProgram StrangeProgram.java • Hint: It helps if you figure out the output of WillItRunForever StrangeProgram.java first
You can see my PNP “slides” here: • http://prezi.com/k8e5v1wgicit/copy-of-copy-of-ghp-pnp/