summaryrefslogtreecommitdiff
path: root/src/poly.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/poly.rs')
-rw-r--r--src/poly.rs69
1 files changed, 1 insertions, 68 deletions
diff --git a/src/poly.rs b/src/poly.rs
index 34df7a0..bae3a15 100644
--- a/src/poly.rs
+++ b/src/poly.rs
@@ -3,7 +3,7 @@ mod iter;
use crate::number::Number;
use iter::Iter;
use std::fmt;
-use std::ops::{Add, Div, Mul, Sub};
+use std::ops::{Add, Mul, Sub};
#[derive(PartialEq, Debug, Clone)]
pub struct Poly {
@@ -34,22 +34,10 @@ impl Poly {
self.degree
}
- fn lc(&self) -> Number {
- self.data[self.degree()]
- }
-
fn iter(&self) -> Iter {
Iter::new(self.data.clone(), self.degree())
}
- pub fn eval(&self, n: Number) -> Number {
- let mut r = 0.0;
- for i in 0..self.data.len() {
- r += self.data[i] * n.powi(i as i32);
- }
- r
- }
-
fn is_zero(&self) -> bool {
for i in 0..self.data.len() {
if self.data[i] != 0.0 {
@@ -95,21 +83,6 @@ impl Mul for &Poly {
}
}
-impl Div for &Poly {
- type Output = (Poly, Poly);
-
- fn div(self, divisor: Self) -> (Poly, Poly) {
- let mut q = Poly::new(vec![0.0]);
- let mut r = self.clone();
- while !r.is_zero() && r.degree() >= divisor.degree() {
- let s = Poly::mono(r.degree() - divisor.degree(), r.lc() / divisor.lc());
- q = &q + &s;
- r = &r - &(&s * divisor);
- }
- (q, r)
- }
-}
-
impl fmt::Display for &Poly {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut s = String::new();
@@ -128,39 +101,6 @@ mod tests {
use super::*;
#[test]
- fn derivative_test() {
- let p = Poly::new(vec![1.0, 2.0, 3.0, 4.0, 5.0]);
- assert_eq!(derivative(&p), Poly::new(vec![2.0, 6.0, 12.0, 20.0]));
- }
-
- #[test]
- fn div_equal() {
- let a = Poly::new(vec![6.0, 7.0, 1.0]);
- let b = Poly::new(vec![-6.0, -5.0, 1.0]);
- assert_eq!(
- &a / &b,
- (Poly::new(vec![1.0]), Poly::new(vec![12.0, 12.0, 0.0]))
- );
- }
-
- #[test]
- fn div_greater() {
- let a = Poly::new(vec![-6.0, -5.0, 1.0]);
- let b = Poly::new(vec![12.0, 12.0]);
- assert_eq!(
- &a / &b,
- (Poly::new(vec![-0.5, 1.0 / 12.0]), Poly::new(vec![0.0, 0.0]))
- );
- }
-
- #[test]
- fn div_less() {
- let a = Poly::new(vec![12.0, 12.0]);
- let b = Poly::new(vec![-6.0, -5.0, 1.0]);
- assert_eq!(&a / &b, (Poly::new(vec![0.0]), a));
- }
-
- #[test]
fn mul_test() {
let a = Poly::new(vec![1.0, 2.0, 3.0]);
let b = Poly::new(vec![1.0, 2.0]);
@@ -204,11 +144,4 @@ mod tests {
let p = Poly::new(vec![0.0; 6]);
assert_eq!(p.degree(), 0);
}
-
- #[test]
- fn gcd_test() {
- let a = Poly::new(vec![2.0, -8.0, 8.0]);
- let b = Poly::new(vec![-1.0, 4.0, -1.0]);
- assert_eq!(gcd(&a, &b), Poly::new(vec![-0.0625, 0.0]));
- }
}