Documentation

CslibFrontier.Algorithms.WordRAM.HamiltonianCount

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:

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 #

Main results #

References #

Encoded instances and walk-count bounds #

A directed graph on Fin n given by its boolean adjacency matrix.

  • n : ℕ

    Number of vertices n.

  • adj : Fin self.n → Fin self.n → Bool

    Adjacency predicate adj u v = true when (u, v) is an arc.

Word-size envelope covering the input matrix, O(n²) working addresses, and n^n-scale walk counts accumulated across 2 ^ n subsets.

@[reducible, inline]

Width admissibility predicate for Instance.

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.

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.

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).