Karp–Bax inclusion–exclusion Hamiltonian path counting on the word RAM #
Checked standard-basis word-RAM (Cslib.WordRAM.Basis.standard) realization of Karp and Bax's
inclusion–exclusion Hamiltonian-path counter (CslibFrontier.Algorithms.Lean.TSP.HamiltonianCount)
[Kar82] [Bax93] ([FK10], Section 4.2.2, Theorem 4.5 and Eq. (4.4)), built as a
Cslib.DataStructure.Memory.Prog client certified via Cslib.Tactic.Realize (realize) and
lowered along Realizes.exists_standard_basis_init_program_state_from_words:
program: given ann-vertex directed graphI : Instanceencoded asI.nfollowed by then × nrow-major adjacency matrix (0/1words), computes#(hamPaths I.adj)inO((I.n ^ 3 + 1) * 2 ^ I.n)instructions at every widthwwithI.FitsWidth w.decideProgram: decides(hamPaths I.adj).Nonempty(returning1or0) within the sameO((I.n ^ 3 + 1) * 2 ^ I.n)instruction bound.
Subsets S ⊆ Fin n are enumerated in place using an n-word binary odometer inMask[0..n-1]
and parity bit maskParity = #S % 2, allocating 3 * n working words (inMask, cur, next)
via Memory.allocDirty. Neither program reads the machine word size (¬ReadsWidth).
Word-size condition #
During every mask k < 2 ^ n and round r < n, every entry walkCountFrom I.adj S r u is at
most n ^ r, so totalWalkCount I.adj S ≤ (n + 1) ^ n and both partial sums evenSum and
oddSum stay at most 2 ^ n * (n + 1) ^ n. The envelope
I.wordBound = 4 * (2 ^ I.n * (I.n + 1) ^ I.n + (I.n + 1) ^ 2 + 16) (requiring O(n log n)-bit
words, matching [FK10], Section 4.2.2) covers the input, all working addresses, and all
accumulated walk counts.
Main definitions #
Cslib.Algorithms.WordRAM.HamiltonianCount.Instance: directed graph instance and flat word-RAM encoding (Instance.encode,Instance.wordBound,Instance.FitsWidth).Cslib.Algorithms.WordRAM.HamiltonianCount.program: deterministic width-blind standard-basis Word-RAM program counting Hamiltonian paths.Cslib.Algorithms.WordRAM.HamiltonianCount.decideProgram: deterministic width-blind standard-basis Word-RAM program deciding existence of a Hamiltonian path.
Main results #
Cslib.Algorithms.WordRAM.HamiltonianCount.not_readsWidth_program,Cslib.Algorithms.WordRAM.HamiltonianCount.not_readsWidth_decideProgram: width-blindness.Cslib.Algorithms.WordRAM.HamiltonianCount.computesInTime_program,Cslib.Algorithms.WordRAM.HamiltonianCount.computesInTime_decideProgram:O((I.n ^ 3 + 1) * 2 ^ I.n)instruction bounds for counting and deciding Hamiltonian paths.
References #
Encoded instances and walk-count bounds #
Word-size envelope covering the input matrix, O(n²) working addresses, and n^n-scale walk
counts accumulated across 2 ^ n subsets.
Pure binary odometer and inclusion–exclusion lemmas #
Word-size envelope arithmetic helpers #
Memory client sub-programs and realize certificates #
Uniform standard-basis Word-RAM programs and O((n³ + 1) · 2^n) bounds #
Number of registers used by program.
Standard-basis width-blind Word-RAM program computing #(hamPaths I.adj) in
O((I.n ^ 3 + 1) * 2 ^ I.n) instructions.
Constant factor in computesInTime_program.
Number of registers used by decideProgram.
Standard-basis width-blind Word-RAM program deciding (hamPaths I.adj).Nonempty (1 or 0)
in O((I.n ^ 3 + 1) * 2 ^ I.n) instructions.
Constant factor in computesInTime_decideProgram.
program never reads the machine word size (¬ReadsWidth).
decideProgram never reads the machine word size (¬ReadsWidth).
Standard-basis Program.ComputesInTime certificate for program: computes
#(hamPaths I.adj) on I.encode in O((I.n ^ 3 + 1) * 2 ^ I.n) instructions at every word
width w satisfying I.FitsWidth w (O(n log n) bits).
Standard-basis Program.ComputesInTime certificate for decideProgram: decides
(hamPaths I.adj).Nonempty (1 iff nonempty, 0 otherwise) on I.encode in
O((I.n ^ 3 + 1) * 2 ^ I.n) instructions at every word width w satisfying I.FitsWidth w
(O(n log n) bits).