pub fn polyval_vec(x: &[f64], coeffs: &[f64]) -> Vec<f64> {
    let mut result = vec![0.0; x.len()];
    for &c in coeffs.iter().rev() {
        for (i, val) in x.iter().enumerate() {
            result[i] = result[i] * val + c;
        }
    }
    result
}

pub fn polyval_scalar(x: f64, coeffs: &[f64]) -> f64 {
    let mut result = 0.0;
    for c in coeffs.iter().rev(){
        result = result * x + c;
    }
    result
}