Skip to content
Rainbow docs menu

Reference · The Applied Higher-Order Functions catalogue

rainbow.algorithms.proofs.ahof.manacher

The Applied Higher-Order Functions cataloguesrc/rainbow/algorithms/proofs/ahof/manacher.clj1 definitions, 3 theorems

AHoF Manacher's Algorithm: find the longest palindromic substring (and all maximal palindrome radii) in LINEAR time, beating the O(n^2) expand-around-center approach by reusing mirror symmetry so each position is examined O(1) amortized. The one primitive operation, whether an expand-around-center step continues, is a character MATCH between the mirrored positions: characters-match? left-char right-char = (left-char <= right-char) AND (right-char <= left-char) (the two characters are equal), over exact-rational (integer) character codes. The match test is defined as a conjunction of two comparisons via logic/if-data. Proved native and axiom-free, as worked instances: codes 65 and 65 match; the one-direction worked certificate 65 <= 65 (native nnrat/at-most); and codes 65 and 66 do not match. Manacher's correctness and its linear-time bound are classical and not proved here; the center iteration with mirror-radius reuse is executable. Requires 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.manacher` prints this classification.

manacher/characters-match?

DefinitionSource, line 63

manacher/characters-match? :
  (x₁ x₂ : ℚ≥0)
  → data/Bool

ℚ≥0 = nnrat/NonnegativeRational

manacher/equal-chars-extend

TheoremWorked exampleNo axiomsSource, line 80

manacher/equal-chars-extend :
  → floyd-cycle/meet? 65 65 = data/true

= = equality/Eq

manacher/matching-chars-coincide

TheoremWorked exampleNo axiomsSource, line 88

manacher/matching-chars-coincide :
  → 65 ≤ 65

≤ = nnrat/at-most

manacher/different-chars-stop

TheoremWorked exampleNo axiomsSource, line 94

manacher/different-chars-stop :
  → floyd-cycle/meet? 65 66 = data/false

= = equality/Eq