From acc66025849d19fed1ac5f4cabc26e552c7cf1fb Mon Sep 17 00:00:00 2001 From: Danny Willems Date: Sat, 21 Dec 2024 10:13:30 +0100 Subject: [PATCH] MVPoly: additional checks reg. multiplication of polynomials The degree is in the type, but we suppose the user will be careful when using the library, which is a bad assumption. --- mvpoly/src/monomials.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mvpoly/src/monomials.rs b/mvpoly/src/monomials.rs index e08be206fa..828d1b7ea1 100644 --- a/mvpoly/src/monomials.rs +++ b/mvpoly/src/monomials.rs @@ -102,6 +102,9 @@ impl Mul for Sparse { fn mul(self, other: Self) -> Self { let mut monomials = HashMap::new(); + let degree_lhs = unsafe { self.degree() }; + let degree_rhs = unsafe { other.degree() }; + assert!(degree_lhs + degree_rhs <= D, "The degree of the output is expected to be maximum {D}, but the resulting output would be larger than {D} ({res})", res=degree_lhs + degree_rhs); self.monomials.iter().for_each(|(exponents1, coeff1)| { other .monomials