Skip to main content

detect_linear_recurrence

Function detect_linear_recurrence 

Source
pub fn detect_linear_recurrence(v: &[i64]) -> Option<(Vec<i64>, Vec<i64>)>
Expand description

Recognize v as a constant-coefficient linear recurrence v[i] = Σⱼ cⱼ·v[i-1-j] of minimal order k ≤ [MAX_RECUR_ORDER] with integer coefficients, and return (coeffs, seeds)k coefficients + the first k values. This is exactly Berlekamp–Massey over ℤ: it captures Fibonacci, Lucas, Pell, and any linear-feedback sequence — none of which the polynomial detector can reach (their finite differences never settle). The coefficients are solved exactly (Cramer over i128) from the smallest 2k terms and then CONFIRMED by replaying the recurrence with the SAME wrapping arithmetic the decoder uses, so a match certifies a bit-exact reconstruction.