mod additive;
pub use additive::{AdditiveFft, FftError};
use crate::{BinaryFieldExtras, Bit, Block16, TowerField, constants};
pub struct CantorBasis;
impl CantorBasis {
pub const DIM: usize = 16;
pub fn beta_tower(i: usize) -> Block16 {
Block16(constants::CANTOR_BASIS_TOWER_16[i])
}
pub fn self_check() -> bool {
if Self::beta_tower(0) != Block16::ONE {
return false;
}
let mut piv = [0u16; 16];
let mut rank = 0;
for i in 0..Self::DIM {
let b = Self::beta_tower(i);
if vanish_eval(i, b) != Block16::ONE {
return false;
}
if (b.trace() == Bit(1)) != (i == Self::DIM - 1) {
return false;
}
if i >= 1 && b.square() + b != Self::beta_tower(i - 1) {
return false;
}
let mut x = b.0;
while x != 0 {
let p = x.trailing_zeros() as usize;
if piv[p] == 0 {
piv[p] = x;
rank += 1;
break;
}
x ^= piv[p];
}
}
rank == Self::DIM
}
}
pub fn vanish_eval<F: BinaryFieldExtras>(i: usize, x: F) -> F {
let mut t = x;
for _ in 0..i {
t = t.square() + t;
}
t
}