Skip to content

Commit

Permalink
Merge pull request #2510 from o1-labs/dw/mvpoly-pbt-tests-degree
Browse files Browse the repository at this point in the history
MVPoly: more PBT regarding degree computation
  • Loading branch information
dannywillems authored Aug 29, 2024
2 parents 1f749e5 + a367055 commit 1a14a22
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions mvpoly/tests/prime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,3 +716,66 @@ fn test_is_constant() {
let p = unsafe { Dense::<Fp, 4, 5>::random(&mut rng, None) };
assert!(!p.is_constant());
}

#[test]
fn test_mvpoly_add_degree_pbt() {
let mut rng = o1_utils::tests::make_test_rng(None);
let degree = rng.gen_range(1..5);
let p1 = unsafe { Dense::<Fp, 4, 5>::random(&mut rng, Some(degree)) };
let p2 = unsafe { Dense::<Fp, 4, 5>::random(&mut rng, Some(degree)) };
let p3 = p1.clone() + p2.clone();
let degree_p1 = unsafe { p1.degree() };
let degree_p2 = unsafe { p2.degree() };
let degree_p3 = unsafe { p3.degree() };
assert!(degree_p3 <= std::cmp::max(degree_p1, degree_p2));
}

#[test]
fn test_mvpoly_sub_degree_pbt() {
let mut rng = o1_utils::tests::make_test_rng(None);
let degree = rng.gen_range(1..5);
let p1 = unsafe { Dense::<Fp, 4, 5>::random(&mut rng, Some(degree)) };
let p2 = unsafe { Dense::<Fp, 4, 5>::random(&mut rng, Some(degree)) };
let p3 = p1.clone() - p2.clone();
let degree_p1 = unsafe { p1.degree() };
let degree_p2 = unsafe { p2.degree() };
let degree_p3 = unsafe { p3.degree() };
assert!(degree_p3 <= std::cmp::max(degree_p1, degree_p2));
}

#[test]
fn test_mvpoly_neg_degree_pbt() {
let mut rng = o1_utils::tests::make_test_rng(None);
let degree = rng.gen_range(1..5);
let p1 = unsafe { Dense::<Fp, 4, 5>::random(&mut rng, Some(degree)) };
let p2 = -p1.clone();
let degree_p1 = unsafe { p1.degree() };
let degree_p2 = unsafe { p2.degree() };
assert_eq!(degree_p1, degree_p2);
}

#[test]
fn test_mvpoly_mul_by_scalar_degree_pbt() {
let mut rng = o1_utils::tests::make_test_rng(None);
let degree = rng.gen_range(1..5);
let p1 = unsafe { Dense::<Fp, 4, 5>::random(&mut rng, Some(degree)) };
let c = Fp::rand(&mut rng);
let p2 = p1.clone() * Dense::<Fp, 4, 5>::from(c);
let degree_p1 = unsafe { p1.degree() };
let degree_p2 = unsafe { p2.degree() };
assert!(degree_p2 <= degree_p1);
}

#[test]
fn test_mvpoly_mul_degree_pbt() {
let mut rng = o1_utils::tests::make_test_rng(None);
// half max degree
let degree = rng.gen_range(1..3);
let p1 = unsafe { Dense::<Fp, 4, 6>::random(&mut rng, Some(degree)) };
let p2 = unsafe { Dense::<Fp, 4, 6>::random(&mut rng, Some(degree)) };
let p3 = p1.clone() * p2.clone();
let degree_p1 = unsafe { p1.degree() };
let degree_p2 = unsafe { p2.degree() };
let degree_p3 = unsafe { p3.degree() };
assert!(degree_p3 <= degree_p1 + degree_p2);
}

0 comments on commit 1a14a22

Please sign in to comment.