pub fn berlekamp_massey<T>(a: &[T]) -> Vec<T>
Examples found in repository?
More examples
crates/competitive/src/math/black_box_matrix.rs (line 232)
216 fn minimal_polynomial(&self) -> Vec<MInt<M>>
217 where
218 M: MIntConvert<u64>,
219 {
220 assert_eq!(self.shape().0, self.shape().1);
221 let n = self.shape().0;
222 let mut rng = Xorshift::new();
223 let b: Vec<MInt<M>> = (0..n).map(|_| MInt::from(rng.rand64())).collect();
224 let u: Vec<MInt<M>> = (0..n).map(|_| MInt::from(rng.rand64())).collect();
225 let a: Vec<MInt<M>> = (0..2 * n)
226 .scan(b, |b, _| {
227 let a = b.iter().zip(&u).fold(MInt::zero(), |s, (x, y)| s + x * y);
228 *b = self.apply(b);
229 Some(a)
230 })
231 .collect();
232 let mut p = berlekamp_massey(&a);
233 p.reverse();
234 p
235 }