m. smith final fantasy is really hard - math.utah.edu · final fantasy xiii-2 (2011). most players...

40
Final Fantasy is Really Hard M. Smith Introduction The Clock Puzzle A Well Known Problem Algorithms Rigorous Definition Time Complexity A Caveat P vs NP P, NP P vs NP Conclusions Final Fantasy is Really Hard Algorithms, Complexity, and P vs NP M. Smith Department of Mathematics University of Utah 6 September 2016 / GSAC

Upload: phamphuc

Post on 26-Aug-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Final Fantasy is Really HardAlgorithms, Complexity, and P vs NP

M. Smith

Department of MathematicsUniversity of Utah

6 September 2016 / GSAC

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Outline

1 IntroductionThe Clock PuzzleA Well Known Problem

2 AlgorithmsRigorous DefinitionTime ComplexityA Caveat

3 P vs NPP, NPP vs NP

4 Conclusions

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Outline

1 IntroductionThe Clock PuzzleA Well Known Problem

2 AlgorithmsRigorous DefinitionTime ComplexityA Caveat

3 P vs NPP, NPP vs NP

4 Conclusions

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Motivation

The clock puzzle is an infamous part of the video gameFinal Fantasy XIII-2 (2011).

Most players rely on computer tools developed specificallyto solve these puzzles.

Main question: are these puzzles really that hard? Is there asimpler solution we just haven’t found yet?

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Live Demonstration

Understanding the puzzle is easiest with a demonstration.

Here is a video of some puzzles being solved:<https://youtu.be/IVJ3GDu3Kn8?t=2m50s>

Here is a link to a puzzle solver:<www.robertwoodward.com/clockPuzzle/>

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Outline

1 IntroductionThe Clock PuzzleA Well Known Problem

2 AlgorithmsRigorous DefinitionTime ComplexityA Caveat

3 P vs NPP, NPP vs NP

4 Conclusions

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Formalizing the Puzzle

A clock puzzle is 0, ...N − 1 points in a circle. Each point nhas an associated integer k(n). From n we can move toeither n + k(n) or n − k(n) (mod N). This is data for adirected graph.

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Formalizing the Solution

A solution to the clock puzzle is a valid path that hits eachinteger n exactly once. This is called a Hamiltonian path ifit exists.

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

A Familiar Problem

The Hamiltonian Path Problem asks for a Hamiltonianpath on a finite directed graph, or a proof that no such pathexists.

Clock puzzles are a special case of this well-studiedproblem in graph theory!

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Brute Force

Here’s one way to find all Hamiltonian paths for a graph:

k = 0.While (k < N!):

P[k] = k-th permutation of 0,...,N-1.If P[k] gives an allowed path:

Print P[k].Increase k by 1.

For a graph on N vertices, there are N! permutations. As Ngrows, the time needed to find all solutions grows rapidly!

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Outline

1 IntroductionThe Clock PuzzleA Well Known Problem

2 AlgorithmsRigorous DefinitionTime ComplexityA Caveat

3 P vs NPP, NPP vs NP

4 Conclusions

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Motivation

We have an algorithm which can find Hamiltonian paths(and hence solve clock puzzles), but it is very slow.

Question: Is there a faster algorithm?

To discuss what we know about this question, we need todo some rigorous math.

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Turing Machines

Informally, a Turing machine is a finite program attached toa read/write head which moves along an infinite tape.

The tape is divided into squares, each of which containsone symbol or is blank.

Initially the tape contains a finite non-blank input, and theTuring machine starts running at one end of the input.

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Turing Machines

A Turing machine is defined by M = (Σ, Γ,Q, δ).Σ, Γ,Q are finite nonempty sets. Q is disjoint from Γ.Σ ⊆ Γ are alphabets. b ∈ Γ \ Σ is the blank character.The allowed inputs are finite strings over Σ.Q is the state of the machine. It contains three specialstates: the initial state q0, qaccept , and qreject .δ is the transition function.

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Transition Function

The transition function is defined by:δ :

(Q − {qaccept ,qreject}

)× Γ→ Q × Γ× {+1,−1}

Suppose δ(q, s) = (q′, s′,h). The interpretation is: M is instate q scanning symbol s. Application of δ:

Changes M to state q′.Replaces symbol s on the tape with symbol s′.Moves M to the left on the tape if h = −1, or to the rightif h = +1.

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Configurations

A configuration of M is a string xqy , where x and y arefinite strings in Γ and q ∈ Q.

We interpret the configuration xqy to mean that the string xyis printed on the tape and M is in state q reading theleftmost character in y .

If C,C′ are configurations of M, we write C →M C′ if C′

arises from C after an application of δ.

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Computation

Given an input string w , the computation of M on w is asequence of configurations C0,C1, ... so that:

C0 = q0w (or C0 = q0b with empty input).Ci →M Ci+1 for each i with Ci+1 in the computation.

If qi = qaccept or qreject , then the computation halts at step i .There are i + 1 configurations, and i applications of δ.

Note that it is possible for qi to never be qaccept or qreject , sothe machine runs forever.

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Outline

1 IntroductionThe Clock PuzzleA Well Known Problem

2 AlgorithmsRigorous DefinitionTime ComplexityA Caveat

3 P vs NPP, NPP vs NP

4 Conclusions

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Computation Time

We say a Turing machine M accepts w as an input if thecomputation of M given w halts with M in state qaccept .

If M accepts w , the running time R(w) for the computationis the number of applications of the transition function δ.

The worst case running time for M is a function TM :

TM(n) = max{R(w) : length(w) ≤ n and M accepts w}

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Big O Notation

This notation is commonly used to describe running times.

Given F ,G : N→ R, we say that F (n) is O(G(n)) if thereare constants C,N > 0 so that:

|F (n)| ≤ C|G(n)|

whenever n ≥ N.

Note: this is asymmetric, and is not an equivalence relation!

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Big O Example

Let F (n) = 2n2 − 1. For n ≥ 1 we compute:

|2n2 − 1| ≤ |2n2|+ | − 1| ≤ 2n2 + n2 ≤ 3|n2|

so F (n) is O(n2), with C = 3 and N = 1.

By similar reasoning, a polynomial in n of degree d is O(nd ).

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Common Algorithms and their Orders

Using the worst case running time, we can compute howcomplicated certain tasks are based on their input size. Thisdetermines the time complexity of the problem.

O(1) : Printing "Billy Crystal".O(log n): Binary search in a list of size n.O(n): Addition of two n-digit integers.O(n2): Simple multiplication of two n-digit integers.O(cn), c > 1: Best known Hamiltonian path finder.O(n!): Brute force Hamiltonian path finder, n vertices.

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Outline

1 IntroductionThe Clock PuzzleA Well Known Problem

2 AlgorithmsRigorous DefinitionTime ComplexityA Caveat

3 P vs NPP, NPP vs NP

4 Conclusions

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Slow Fast Algorithms

Consider the Deep Thought algorithm:

wait 7.5 million years.print "42".

This algorithm is O(1), but we would not call it "fast".

Since the constants in Big O notation can be arbitrarilylarge, we need to be careful!

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Outline

1 IntroductionThe Clock PuzzleA Well Known Problem

2 AlgorithmsRigorous DefinitionTime ComplexityA Caveat

3 P vs NPP, NPP vs NP

4 Conclusions

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Motivation

Despite the caveat, we can consider polynomial timealgorithms to be "fast" or "easy" and algorithms which run inmore than polynomial time to be "slow" or "hard".

However, just because there is no known "fast" algorithm fora problem does not mean that there isn’t one!

So, we need further work to show that clock puzzles are"hard".

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Class P

P stands for deterministic polynomial time. A problem isin class P if there exists a Turing machine which can solve itin polynomial time or faster.

Binary search, addition, and multiplication are all problemsin class P: we have O(log n), O(n) and O(n2) algorithms(respectively).

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Class NP

NP stands for nondeterministic polynomial time.Informally, a problem is in class NP if there exists a"verification algorithm" for the problem which runs inpolynomial time.

The Hamiltonian path problem is in class NP, since it takesO(n) steps to verify that a path on n vertices is aHamiltonian path.

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

P ⊆ NP

It is easy to show that P ⊆ NP, as a polynomial timealgorithm gives a polynomial time verification for a problem.

It is unknown whether P = NP! This gives us some hopethat "hard" problems might be easy.

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Outline

1 IntroductionThe Clock PuzzleA Well Known Problem

2 AlgorithmsRigorous DefinitionTime ComplexityA Caveat

3 P vs NPP, NPP vs NP

4 Conclusions

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Historical Background

One of the seven Clay Millenium Problems, announced in2000, is to determine whether P = NP or not.

In the 1960’s, the notion of polynomial time computationwas formalized by Cobham and Edmonds.

In 1971, the notion of NP-completeness was introduced byCook. In 1972 Karp demonstrated that many naturalproblems are NP-complete.

Karp also introduced the notation P and NP.

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

NP-completeness

Informally, a fixed problem in NP is NP-complete if it ispossible to "reduce" any NP problem to the fixed problem inpolynomial time.

There are hundreds of NP-complete problems, including theHamiltonian path problem!

This means we can say Final Fantasy XIII-2 is"NP-complete" (in some sense).

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

What happens if P = NP?

If P = NP, then there is a polynomial time algorithm solvingan NP-complete problem.

By the reduction definition of NP-completeness, thisalgorithm is universal: it can solve all problems in NP.

The existence of a fast algorithm for NP-complete problemswould change the world!

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

What happens if P = NP?

Modern cryptography is based on integer factorization,which is in NP, and believed to be "hard".

But if P = NP, then many aspects of the internet, includingfinancial transactions, could no longer be secure!

On the other hand, many important optimization problemslike finding Hamiltonian paths would become easy to solve.

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Alternative Scenarios

Most complexity theorists believe that P 6= NP because ofthe stunning consequences of equality.

However, polynomial time does not mean "fast". We couldhave P = NP, but the best universal algorithm hascoefficients on the order of Graham’s number.

Another option is that P = NP, but the proof is notconstructive. There would be a universal algorithm for NPproblems, but no-one would be able to write it down.

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

What About P 6= NP?

To prove P 6= NP, it suffices to find a superpolynomial lowerbound for the running time of an NP problem.

However, complexity theory has failed in many cases toprovide interesting lower bounds in many cases, includingfor P and NP.

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Outline

1 IntroductionThe Clock PuzzleA Well Known Problem

2 AlgorithmsRigorous DefinitionTime ComplexityA Caveat

3 P vs NPP, NPP vs NP

4 Conclusions

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

Summary

We don’t know whether Final Fantasy’s clock puzzlesare actually hard!A solution to the P vs NP problem could take manydifferent forms, some with dramatic consequences.Many unexpected things can lead to beautifulmathematics.

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

References and Further Reading

Final Fantasy XIII-2Nathaniel Johnston’s blog<www.njohnston.ca/2012/02/counting-and-solving-final-fantasy-xiii-2s-clock-puzzles/>

Pictures on slides 7 and 8 are taken from the abovepost.

Final Fantasyis Really Hard

M. Smith

IntroductionThe Clock Puzzle

A Well KnownProblem

AlgorithmsRigorous Definition

Time Complexity

A Caveat

P vs NPP, NP

P vs NP

Conclusions

References and Further Reading

Big Ohttps://en.wikipedia.org/wiki/Big_O_notation

Has a more exhaustive list of problems and orders ofsolution algorithms.

P vs NP<http://www.claymath.org/millennium-problems/p-vs-np-problem>

The official problem description by Cook is the majorreference for this talk.