Deciding TSP by the Bellman–Held–Karp algorithm #
This file connects the Bellman–Held–Karp dynamic program
Cslib.Algorithms.Lean.TSP.heldKarp [Bel62] [HK62] to the decision problem
Cslib.Complexity.TSP on instances x : TSPInstance and certifies its exponential running time
on deterministic multi-tape Turing machines.
An instance x with x.dist.length = n + 1 has the cities 0, …, n at distances
TSP.dist x.dist i j, and it belongs to TSP when some ordering of all cities has closed tour
length at most x.bound. The tour length is the closed-walk cost cycleCost (dist x.dist)
(TSP.tourLength_eq_cycleCost), which is invariant under rotation (cycleCost_append_comm), so
such a tour can be taken to start at city 0, which is the normal form heldKarp optimizes over.
For the multi-tape Turing-machine realization, the DP table of 2 ^ n subset rows (each row
holding n + 1 optional binary tour costs List (Option ℕ)) is processed in streaming passes
via a cyclic bit-rotation butterfly (evens table ++ passOdds row i table): each pass pairs
adjacent even/odd entries (i ∉ S vs. i ∈ S), relaxes S from S \ {i}, and moves bit i
to the back of the table ordering so that n passes restore the original order and complete one
Bellman–Held–Karp stage, repeated n times (O(2 ^ n · poly(|encTSP x|)) total steps, with zero
quadratic 4 ^ n table-copying overhead). Composing with the polynomial-time reduction
HamCycle.toTSP decides HamCycle within 2 ^ (n - 1) · poly(|encGraph G|) multi-tape steps.
Main definitions #
Cslib.Complexity.TSP.heldKarpDecide: runheldKarpon the distance matrix and compare the optimal tour length with the budget.
Main results #
Cslib.Complexity.TSP.tourLength_eq_cycleCost: tour length is the cost of the closed walk.Cslib.Complexity.TSP.mem_TSP_iff_heldKarp_le:x ∈ TSPexactly when the Bellman–Held–Karp optimum is at mostx.bound.Cslib.Complexity.TSP.heldKarpDecide_eq_true_iff:heldKarpDecidedecidesTSP.Cslib.Complexity.TSP.exists_computableInO_heldKarpDecide,Cslib.Complexity.TSP.decidableInExpTime:TSPis decidable on multi-tape Turing machines in time2 ^ (n - 1) · poly(|encTSP x|).Cslib.Complexity.HamCycle.heldKarpDecide_toTSP_eq_true_iff,Cslib.Complexity.HamCycle.exists_computableInO_heldKarpDecide_toTSP,Cslib.Complexity.HamCycle.decidableInExpTime:HamCycleis decidable on multi-tape Turing machines in time2 ^ (n - 1) · poly(|encGraph G|)throughHamCycle.toTSP.
References #
TSP by the Bellman–Held–Karp algorithm. An instance with n + 1 cities belongs to
TSP exactly when the optimal tour computed by heldKarp has length at most the budget.
Decide TSP by the Bellman–Held–Karp algorithm [HK62]: run heldKarp on the
distance matrix and compare the optimal tour length with the budget. The empty matrix is a
yes-instance, witnessed by the empty tour.
heldKarpDecide decides TSP.
Multi-tape Turing-machine exponential-time realization #
Streaming list-pass combinator and DP correctness #
Full DP iteration and semantic equivalence #
TSP in exponential time 2 ^ (n - 1) · poly(|encTSP x|) on multi-tape Turing machines.
heldKarpDecide is computable within time and space
O(2 ^ (x.dist.length - 1) · (|encTSP x| + 1) ^ e) for some polynomial exponent e.
TSP is in DTIME(2 ^ (n - 1) · poly(|encTSP x|)) on multi-tape Turing machines, where
n = x.dist.length is the number of cities (μ x = x.dist.length - 1, δ = 1).
Deciding HamCycle by reducing to TSP via HamCycle.toTSP and running
TSP.heldKarpDecide.
HamCycle in exponential time 2 ^ (n - 1) · poly(|encGraph G|) on multi-tape Turing
machines, where n = G.distinctVertices.length.
HamCycle is in DTIME(2 ^ (n - 1) · poly(|encGraph G|)) on multi-tape Turing machines,
where n = G.distinctVertices.length (μ G = G.distinctVertices.length - 1, δ = 1).