This commit is contained in:
Nicholas Ward 2021-07-21 09:56:00 -07:00
parent 5062029d3f
commit c5bbe9d503
4 changed files with 12 additions and 9 deletions

View File

@ -6,6 +6,7 @@ use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssi
use num_bigint::BigUint;
use num::Integer;
use rand::Rng;
use serde::{Deserialize, Serialize};
use crate::field::extension_field::quadratic::QuadraticCrandallField;
@ -147,7 +148,7 @@ impl Field for CrandallField {
const TWO: Self = Self(2);
const NEG_ONE: Self = Self(FIELD_ORDER - 1);
const ORDER : BigUint = BigUint::from(FIELD_ORDER);
const ORDER: BigUint = BigUint::from(FIELD_ORDER);
const TWO_ADICITY: usize = 28;
const CHARACTERISTIC: u64 = FIELD_ORDER;
@ -329,6 +330,10 @@ impl Field for CrandallField {
}
result
}
fn rand_from_rng<R: Rng>(rng: &mut R) -> Self {
Self::from_canonical_u64(rng.gen_range(0, FIELD_ORDER))
}
}
impl Neg for CrandallField {

View File

@ -34,8 +34,8 @@ pub trait Frobenius<const D: usize>: OEF<D> {
return self.repeated_frobenius(count % D);
}
let arr = self.to_basefield_array();
let k = (Self::BaseField::ORDER - 1) / (D as u64);
let z0 = Self::W.exp(k * count as u64);
let k = (Self::BaseField::ORDER - 1u32) / (D as u64);
let z0 = Self::W.exp_bigint(k * count as u64);
let mut res = [Self::BaseField::ZERO; D];
for (i, z) in z0.powers().take(D).enumerate() {
res[i] = arr[i] * z;

View File

@ -31,8 +31,8 @@ impl<const D: usize> ExtensionTarget<D> {
return self.repeated_frobenius(count % D, builder);
}
let arr = self.to_target_array();
let k = (F::ORDER - 1) / (D as u64);
let z0 = F::Extension::W.exp(k * count as u64);
let k = (F::ORDER - 1u32) / (D as u64);
let z0 = F::Extension::W.exp_bigint(k * count as u64);
let zs = z0
.powers()
.take(D)

View File

@ -184,6 +184,8 @@ pub trait Field:
Self::from_canonical_u64(n as u64)
}
fn rand_from_rng<R: Rng>(rng: &mut R) -> Self;
fn bits(&self) -> usize {
bits_u64(self.to_canonical_u64())
}
@ -308,10 +310,6 @@ pub trait Field:
Self::mds(vec.to_vec()).try_into().unwrap()
}
fn rand_from_rng<R: Rng>(rng: &mut R) -> Self {
Self::from_canonical_u64(rng.gen_range(0, Self::ORDER))
}
fn rand() -> Self {
Self::rand_from_rng(&mut rand::thread_rng())
}