WIP: feat: Initial implementation of ssf. Sort missinf
This commit is contained in:
parent
69a2026c84
commit
17bade8a62
7 changed files with 108 additions and 10 deletions
|
|
@ -12,7 +12,7 @@ use serde_json::Value;
|
|||
|
||||
use super::field::FieldElement;
|
||||
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub struct Polynomial {
|
||||
polynomial: Vec<FieldElement>,
|
||||
}
|
||||
|
|
@ -178,13 +178,16 @@ impl Polynomial {
|
|||
}
|
||||
|
||||
// Returns (quotient, remainder)
|
||||
pub fn div(self, rhs: &Self) -> (Self, Self) {
|
||||
pub fn div(&self, rhs: &Self) -> (Self, Self) {
|
||||
// Div by zero check ommitted since data is guaranteed to be non 0
|
||||
|
||||
eprintln!("{:?}, {:?}", self.polynomial.len(), rhs.polynomial.len());
|
||||
|
||||
if self.polynomial.len() < rhs.polynomial.len() {
|
||||
return (Polynomial::new(vec![FieldElement::new(vec![0; 16])]), self);
|
||||
return (
|
||||
Polynomial::new(vec![FieldElement::new(vec![0; 16])]),
|
||||
self.clone(),
|
||||
);
|
||||
}
|
||||
|
||||
let mut remainder = self.clone();
|
||||
|
|
@ -483,12 +486,13 @@ impl Ord for Polynomial {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn gcd(a: Polynomial, b: Polynomial) -> Polynomial {
|
||||
pub fn gcd(a: &Polynomial, b: &Polynomial) -> Polynomial {
|
||||
if a.is_zero() {
|
||||
return b;
|
||||
return b.clone();
|
||||
}
|
||||
|
||||
return gcd(b.div(&a).1.monic(), a);
|
||||
let monic_b = b.div(&a).1.monic();
|
||||
return gcd(&monic_b, a);
|
||||
}
|
||||
|
||||
pub fn sort_polynomial_array(mut polys: Vec<Polynomial>) -> Result<Vec<Polynomial>> {
|
||||
|
|
@ -1300,7 +1304,7 @@ mod tests {
|
|||
let a: Polynomial = Polynomial::from_c_array(&a);
|
||||
let b: Polynomial = Polynomial::from_c_array(&b);
|
||||
|
||||
let result = gcd(a.monic(), b.monic());
|
||||
let result = gcd(&a.monic(), &b.monic());
|
||||
|
||||
assert_eq!(json!(result.to_c_array()), expected);
|
||||
}
|
||||
|
|
@ -1314,7 +1318,7 @@ mod tests {
|
|||
let a: Polynomial = Polynomial::from_c_array(&a);
|
||||
let b: Polynomial = Polynomial::from_c_array(&b);
|
||||
|
||||
let result = gcd(a.monic(), b.monic());
|
||||
let result = gcd(&a.monic(), &b.monic());
|
||||
|
||||
assert_eq!(json!(result.to_c_array()), expected);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue