use super::{PolyOverZ, fmpz_poly_helpers::reduce_fmpz_poly_by_poly_over_z};
impl PolyOverZ {
pub fn reduce_by_poly(&mut self, modulus: &PolyOverZ) {
unsafe { reduce_fmpz_poly_by_poly_over_z(&mut self.poly, modulus) }
}
}
#[cfg(test)]
mod test_reduce_by_poly {
use crate::integer::PolyOverZ;
use std::str::FromStr;
#[test]
fn reduce_more_than_once() {
let mut a = PolyOverZ::from_str("4 0 1 2 3").unwrap();
let modulus = PolyOverZ::from_str("3 0 1 1").unwrap();
a.reduce_by_poly(&modulus);
assert_eq!(PolyOverZ::from_str("2 0 2").unwrap(), a);
}
#[test]
#[should_panic]
fn no_leading_zero() {
let mut a = PolyOverZ::from_str("3 1 2 3").unwrap();
let modulus = PolyOverZ::from_str("2 1 2").unwrap();
a.reduce_by_poly(&modulus);
}
#[test]
fn large_coefficients() {
let mut a = PolyOverZ::from_str(&format!("3 1 -{} -1", u64::MAX)).unwrap();
let modulus = PolyOverZ::from_str(&format!("2 {} 1", u64::MAX)).unwrap();
a.reduce_by_poly(&modulus);
assert_eq!(PolyOverZ::from(1), a);
}
}