Struct algebraic_equation_over_finite_prime_field::PolynomialOverP[][src]

pub struct PolynomialOverP<T> { /* fields omitted */ }

Implementations

PolynomialOverP ring over finite prime field $F_p[x]$

use num_traits::Zero;
use polynomial_over_finite_prime_field::PolynomialOverP;
let p = PolynomialOverP::<i32>::new(vec![3, 1, 4, 1, 5], 17);
let q = PolynomialOverP::<i32>::new(vec![2, 7, 1], 17);
let mut r = p.clone();
let d = r.division(&q);
assert!((d * q + r - p).is_zero());

degree of polynomial

use polynomial_over_finite_prime_field::PolynomialOverP;
let p = PolynomialOverP::<i32>::new(vec![3, 2, 1], 5); // 3+2x+x^2
assert_eq!(p.deg(), Some(2));
let q = PolynomialOverP::<i32>::new(vec![0], 5); // 0
assert_eq!(q.deg(), None);

leading coefficent

use polynomial_over_finite_prime_field::PolynomialOverP;
let p = PolynomialOverP::<i32>::new(vec![3, 2, 1], 5); // 3+2x+x^2
assert_eq!(p.lc(), Some(&1));
let q = PolynomialOverP::<i32>::new(vec![0], 5); // 0
assert_eq!(q.lc(), None);

get coefficents

use polynomial_over_finite_prime_field::PolynomialOverP;
let p = PolynomialOverP::<i32>::new(vec![3, 2, 1], 5); // 3+2x+x^2
assert_eq!(p.coefs(), vec![3, 2, 1]);
let q = PolynomialOverP::<i32>::new(vec![0], 5); // 0
assert_eq!(q.coefs(), vec![]);

get prime

use polynomial_over_finite_prime_field::PolynomialOverP;
let p = PolynomialOverP::<i32>::new(vec![3, 2, 1], 97); // 3+2x+x^2
assert_eq!(p.prime_ref(), &97);
let q = PolynomialOverP::<i32>::new(vec![0], 5); // 0
assert_eq!(q.prime_ref(), &5);

construct polynomial

use polynomial_over_finite_prime_field::PolynomialOverP;
let p = PolynomialOverP::<i32>::new(vec![3, 2, 1], 5);
assert_eq!(p.to_string(), "x^2+2*x+3");

construct polynomial from monomial $cx^d$ ($c$=coefficent, $d$=degree)

use polynomial_over_finite_prime_field::PolynomialOverP;
let p = PolynomialOverP::<i32>::from_monomial(3, 2, 5);
let q = PolynomialOverP::<i32>::new(vec![0, 0, 3], 5);
assert_eq!(p, q);

Make one polynomial

use polynomial_over_finite_prime_field::PolynomialOverP;
let p = PolynomialOverP::<i32>::one(5);
assert_eq!(p, PolynomialOverP::<i32>::new(vec![1], 5));

evaluate polynomial by Horner’s method

use polynomial_over_finite_prime_field::PolynomialOverP;
let p = PolynomialOverP::<i32>::new(vec![3, 2, 1], 7); // 3+2x+x^2
assert_eq!(p.eval(&1), 6);
assert_eq!(p.eval(&2), 4);
assert_eq!(p.eval(&3), 4);

derivative

use polynomial_over_finite_prime_field::PolynomialOverP;
let p = PolynomialOverP::<usize>::new(vec![1, 2, 3, 2, 1], 7); // 1+2x+3x^2+2x^3+x^4
assert_eq!(p.derivative(), PolynomialOverP::<usize>::new(vec![2, 6, 6, 4], 7));
let q = PolynomialOverP::<usize>::new(vec![1, 2, 3, 4, 3, 2, 1], 5); // 1+2x+3x^2+4x^3+3x^4+2x^5+x^6
assert_eq!(q.derivative(), PolynomialOverP::<usize>::new(vec![2, 1, 2, 2, 0, 1], 5));

make polynomial monic

use polynomial_over_finite_prime_field::PolynomialOverP;
let mut p = PolynomialOverP::<i32>::new(vec![1, 2, 3], 5);
p.monic();
let q = PolynomialOverP::<i32>::new(vec![2, 4, 1], 5);
assert_eq!(p, q);

polynomial division

use num_traits::Zero;
use polynomial_over_finite_prime_field::PolynomialOverP;
let p = PolynomialOverP::<i32>::new(vec![3, 1, 4, 1, 5], 17);
let q = PolynomialOverP::<i32>::new(vec![2, 7, 1], 17);
let mut r = p.clone();
let d = r.division(&q);
assert!((d * q + r - p).is_zero());

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the += operation. Read more

Performs the += operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

Performs the /= operation. Read more

Performs the /= operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

Performs the *= operation. Read more

Performs the *= operation. Read more

The resulting type after applying the - operator.

Performs the unary - operation. Read more

The resulting type after applying the - operator.

Performs the unary - operation. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

The resulting type after applying the % operator.

Performs the % operation. Read more

The resulting type after applying the % operator.

Performs the % operation. Read more

The resulting type after applying the % operator.

Performs the % operation. Read more

The resulting type after applying the % operator.

Performs the % operation. Read more

Performs the %= operation. Read more

Performs the %= operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Performs the -= operation. Read more

Performs the -= operation. Read more

Returns the additive identity element of Self, 0. Read more

Returns true if self is equal to the additive identity.

Sets self to the additive identity element of Self, 0.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.