feat: add function for polynomial differentiation
This commit is contained in:
parent
b595276143
commit
4b1bca8ee0
5 changed files with 69 additions and 22 deletions
|
|
@ -292,6 +292,19 @@ impl Polynomial {
|
|||
|
||||
Polynomial::new(result)
|
||||
}
|
||||
|
||||
pub fn diff(mut self) -> Self {
|
||||
// Pop first element
|
||||
self.polynomial.remove(0);
|
||||
|
||||
for (position, element) in self.polynomial.iter_mut().enumerate() {
|
||||
if position % 2 == 1 {
|
||||
*element = FieldElement::new(vec![0; 16]);
|
||||
}
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for Polynomial {
|
||||
|
|
@ -645,26 +658,6 @@ mod tests {
|
|||
// Note this useful idiom: importing names from outer (for mod tests) scope.
|
||||
use super::*;
|
||||
|
||||
/*
|
||||
* TODO: Consider removing
|
||||
#[test]
|
||||
fn coefficients_to_byte_arr_xex_test1() {
|
||||
let coefficients: Vec<u8> = vec![0];
|
||||
let byte_array = vec![
|
||||
01, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00,
|
||||
];
|
||||
assert_eq!(coefficients_to_byte_arr_xex(coefficients), byte_array)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn coefficients_to_byte_arr_xex_test2() {
|
||||
let coefficients: Vec<u8> = vec![127, 12, 9, 0];
|
||||
let byte_array = vec![
|
||||
01, 12, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 80,
|
||||
];
|
||||
assert_eq!(coefficients_to_byte_arr_xex(coefficients), byte_array)
|
||||
}
|
||||
*/
|
||||
#[test]
|
||||
fn byte_indices_0x01() {
|
||||
let byte: u8 = 0x01;
|
||||
|
|
@ -1192,4 +1185,25 @@ mod tests {
|
|||
|
||||
assert_eq!(json!(result.to_c_array()), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_poly_diff() {
|
||||
let json1 = json!([
|
||||
"IJustWannaTellYouAAAAA==",
|
||||
"HowImFeelingAAAAAAAAAA==",
|
||||
"GottaMakeYouAAAAAAAAAA==",
|
||||
"UnderstaaaaaaaaaaaaanQ=="
|
||||
]);
|
||||
let expected = json!([
|
||||
"HowImFeelingAAAAAAAAAA==",
|
||||
"AAAAAAAAAAAAAAAAAAAAAA==",
|
||||
"UnderstaaaaaaaaaaaaanQ=="
|
||||
]);
|
||||
let element1: Polynomial = Polynomial::from_c_array(&json1);
|
||||
eprintln!("Starting poly sqrt");
|
||||
|
||||
let result = element1.diff();
|
||||
|
||||
assert_eq!(json!(result.to_c_array()), expected);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue