Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // calculate a reversed representation of the coefficients of
- // prod_{i=0}^{N}((x- q_i))
- pub fn prod_helper(input: &[i128]) -> Vec<i128> {
- if let Some((q_j, elements)) = input.split_first() {
- match elements {
- [] => vec![1, -q_j],
- _ => {
- // The recursive call calculates (x-q_j)*rec = x*rec - q_j*rec
- let mut rec = Polynomial::prod_helper(elements);
- rec.push(0);
- let mut i = rec.len() - 1;
- while i > 0 {
- rec[i] -= q_j * rec[i - 1];
- i -= 1;
- }
- rec
- }
- }
- } else {
- panic!("Empty array received");
- }
- }
Add Comment
Please, Sign In to add comment