fix: Fix error in random polynomial generation in edf

Upper bound wa incorrect
This commit is contained in:
Alivecow 2024-11-30 23:46:59 +01:00
parent e2ef29bfd5
commit e8f4a58732
2 changed files with 15 additions and 10 deletions

View file

@ -234,7 +234,7 @@ pub fn task_distribute_st(testcases: &Testcases) -> Result<Responses> {
pub fn task_distribute(testcases: &Testcases) -> Result<Responses> { pub fn task_distribute(testcases: &Testcases) -> Result<Responses> {
let cpus = num_cpus::get(); let cpus = num_cpus::get();
if cpus > 1000000 { if cpus > 100000 {
task_distribute_mt(testcases) task_distribute_mt(testcases)
} else { } else {
task_distribute_st(testcases) task_distribute_st(testcases)

View file

@ -4,30 +4,34 @@ use rand::Rng;
use super::poly::{gcd, Polynomial}; use super::poly::{gcd, Polynomial};
pub fn edf(f: Polynomial, d: u32) -> Vec<Polynomial> { pub fn edf(f: Polynomial, d: u32) -> Vec<Polynomial> {
eprintln!("edf started: {:?}", f.clone().to_c_array());
let q = BigUint::pow(&BigUint::from_u8(2).unwrap(), 128); let q = BigUint::pow(&BigUint::from_u8(2).unwrap(), 128);
let n: u32 = (f.degree() as u32) / (d); let n: u32 = (f.degree() as u32) / (d);
let mut z: Vec<Polynomial> = vec![f.clone()]; let mut z: Vec<Polynomial> = vec![f.clone()];
let one_cmp = Polynomial::one(); let one_cmp = Polynomial::one();
while (z.len() as u32) < n { while (z.len() as u32) < n {
//eprintln!("z len {}", z.len()); eprintln!("z len {}", z.len());
//eprintln!("n len {}", n); eprintln!("n len {}", n);
let h = Polynomial::rand(&rand::thread_rng().gen_range(0..f.degree())); let h = Polynomial::rand(&rand::thread_rng().gen_range(1..=f.degree()));
//eprintln!("h: {:02X?}", h); eprintln!("h: {:02X?}", h);
let exponent = (q.pow(d) - BigUint::one()) / BigUint::from_u8(3).unwrap(); let exponent = (q.pow(d) - BigUint::one()) / BigUint::from_u8(3).unwrap();
let g = h.bpow_mod(exponent, &f) + Polynomial::one(); let g = h.bpow_mod(exponent, &f) + Polynomial::one();
//eprintln!("g before for {:0X?}", g); eprintln!("g before for {:0X?}", g);
//eprintln!("z before for {:0X?}", z); eprintln!("z before for {:0X?}", z);
for i in 0..z.len() { for i in (0..z.len()).rev() {
if z[i].degree() as u32 > d { if z[i].degree() as u32 > d {
//eprintln!("Inside if"); eprintln!("Inside if");
let j = gcd(&z[i], &g); let j = gcd(&z[i], &g);
eprintln!("j != one_cmp {:?}", j != one_cmp);
eprintln!("j != z[i] {:?}", j != z[i]);
eprintln!("Inside if");
if j != one_cmp && j != z[i] { if j != one_cmp && j != z[i] {
let intemediate = z[i].div(&j).0; let intemediate = z[i].div(&j).0;
z.remove(i); z.remove(i);
@ -37,9 +41,10 @@ pub fn edf(f: Polynomial, d: u32) -> Vec<Polynomial> {
} }
} }
//eprintln!("z after for {:0X?}", z); eprintln!("z after for {:0X?}", z);
} }
eprintln!("edf finished");
z z
} }