Reference · The Applied Higher-Order Functions catalogue
rainbow.algorithms.proofs.ahof.held-karp
AHoF Held-Karp Algorithm: solve the Travelling Salesman Problem EXACTLY in O(2^n * n^2) -- exponential, but far better than the O(n!) brute force -- by dynamic programming over SUBSETS of visited cities. dp[S][j] is the shortest path that starts at the origin, visits exactly the cities in S, and ends at j; it extends a shorter subpath ending at some predecessor k by the edge k -> j, taking the minimum over predecessors: path-cost subpath edge = subpath + edge better current-best candidate = min(current-best, candidate) (if candidate <= current-best then candidate else current-best) over exact-rational costs. Defined: the path-cost sum and the min-selection between two candidate predecessors. Proved native and axiom-free, as worked instances: path-cost 3 4 = 7, better 9 6 = 6, and the worked certificate 6 <= 9 (native nnrat/at-most). The optimal-substructure property and the exactness of Held-Karp for TSP are classical and not proved here. The subset enumeration (bitmask DP) is executable. Requires nnrat/add, audit/decide-nnrat-at-most, logic/if-data, nnrat/at-most, nnrat/decide-at-most-true-sound (all in the D63 checkpoint). Scope (measured by the kernel): this module has 3 worked instances (statements about specific values). None of its theorems is a guarantee about the algorithm for all inputs; `lein verify rainbow.algorithms.proofs.ahof.held-karp` prints this classification.
held-karp/path-cost
held-karp/path-cost : (x₁ x₂ : ℚ≥0) → ℚ≥0
ℚ≥0 = nnrat/NonnegativeRational
held-karp/better
held-karp/better : (x₁ x₂ : ℚ≥0) → ℚ≥0
ℚ≥0 = nnrat/NonnegativeRational
held-karp/path-cost-example
held-karp/path-cost-example : → astar/f-value 3 4 = 7
= = equality/Eq
held-karp/takes-cheaper-predecessor
held-karp/takes-cheaper-predecessor : → held-karp/better 9 6 = 6
= = equality/Eq
held-karp/chosen-subpath-minimal
held-karp/chosen-subpath-minimal : → 6 ≤ 9
≤ = nnrat/at-most