[][src]Struct rug_polynomial::ModPoly

pub struct ModPoly { /* fields omitted */ }

Implementations

impl ModPoly[src]

pub fn new(modulus: Integer) -> Self[src]

A new polynomial, equal to zero.

pub fn with_capacity(modulus: Integer, n: usize) -> Self[src]

A new polynomial, equal to zero, with room for n coefficients.

pub fn interpolate_from_mul_subgroup(
    ys: Vec<Integer>,
    m: Integer,
    w: &Integer
) -> Self
[src]

Interpolate a polynomial which agrees with the given values over a multiplicative subgroup of the prime field with modulus m.

Let n be a power of two and the order of the multiplicative subgroup generated by w modulo m. Let ys be a vector of values at 1, w, w^2, ...

Returns a polynomial f, such that for i in 0..n, f(w^i) = ys[i] mod m.

Panics

If n is not a power of two, or if w does not generate a subgroup of order n.

Examples

use rug_polynomial::*;
use rug::Integer;

let m = Integer::from(5);
let w = Integer::from(2);
let ys: Vec<Integer> = vec![2, 3, 0, 4].into_iter().map(Integer::from).collect();
let p = ModPoly::interpolate_from_mul_subgroup(ys, m, &w);
debug_assert_eq!(p.len(), 2);
debug_assert_eq!(p.get_coefficient(0), Integer::from(1));
debug_assert_eq!(p.get_coefficient(1), Integer::from(1));

pub fn with_roots(xs: impl IntoIterator<Item = Integer>, m: &Integer) -> Self[src]

Returns the minimal-degree monic polynomial with the given roots.

Example

use rug_polynomial::*;
use rug::Integer;

let p = ModPoly::with_roots(vec![0, 1].into_iter().map(Integer::from), &Integer::from(5));
debug_assert_eq!(p.len(), 3);
debug_assert_eq!(p.get_coefficient(0), Integer::from(0));
debug_assert_eq!(p.get_coefficient(1), Integer::from(4));
debug_assert_eq!(p.get_coefficient(2), Integer::from(1));

pub fn reserve(&mut self, n: usize)[src]

Reallocates the polynomial to have room for n coefficients. Truncates the polynomial if it has more than n coefficients.

pub fn modulus(&self) -> &Integer[src]

Get the modulus of this polynomial.

pub fn get_coefficient(&self, i: usize) -> Integer[src]

Get the ith coefficient

pub fn set_coefficient(&mut self, i: usize, c: &Integer)[src]

Set the ith coefficient to be c

pub fn set_coefficient_ui(&mut self, i: usize, c: usize)[src]

Set the ith coefficient to be c

pub fn len(&self) -> usize[src]

The number of coefficients in the polynomial. One more than the degree.

pub fn neg(&mut self)[src]

self = -self

pub fn add(&mut self, other: &Self)[src]

self = self + other

pub fn sub(&mut self, other: &Self)[src]

self = self - other

pub fn sub_from(&mut self, other: &Self)[src]

self = other - self

pub fn mul(&mut self, other: &Self)[src]

self = self * other

pub fn divrem(&self, other: &Self) -> (ModPoly, ModPoly)[src]

Find q and r such that self = other * q + r and r has degree less than other.

Returns

(q, r)

pub fn div(&mut self, other: &Self)[src]

self = self / other

pub fn div_from(&mut self, other: &Self)[src]

self = other / self

pub fn rem(&mut self, other: &Self)[src]

self = self % other

pub fn rem_from(&mut self, other: &Self)[src]

self = other % self

pub fn sqr(&mut self)[src]

self = self * self

Trait Implementations

impl<'_> Add<&'_ ModPoly> for ModPoly[src]

type Output = ModPoly

The resulting type after applying the + operator.

impl Add<ModPoly> for ModPoly[src]

type Output = ModPoly

The resulting type after applying the + operator.

impl<'_> Add<ModPoly> for &'_ ModPoly[src]

type Output = ModPoly

The resulting type after applying the + operator.

impl<'_> AddAssign<&'_ ModPoly> for ModPoly[src]

impl AddAssign<ModPoly> for ModPoly[src]

impl Clone for ModPoly[src]

impl Debug for ModPoly[src]

impl Display for ModPoly[src]

impl<'_> Div<&'_ ModPoly> for ModPoly[src]

type Output = ModPoly

The resulting type after applying the / operator.

impl Div<ModPoly> for ModPoly[src]

type Output = ModPoly

The resulting type after applying the / operator.

impl<'_> Div<ModPoly> for &'_ ModPoly[src]

type Output = ModPoly

The resulting type after applying the / operator.

impl<'_> DivAssign<&'_ ModPoly> for ModPoly[src]

impl DivAssign<ModPoly> for ModPoly[src]

impl Drop for ModPoly[src]

impl Eq for ModPoly[src]

impl<'_> Mul<&'_ ModPoly> for ModPoly[src]

type Output = ModPoly

The resulting type after applying the * operator.

impl Mul<ModPoly> for ModPoly[src]

type Output = ModPoly

The resulting type after applying the * operator.

impl<'_> Mul<ModPoly> for &'_ ModPoly[src]

type Output = ModPoly

The resulting type after applying the * operator.

impl<'_> MulAssign<&'_ ModPoly> for ModPoly[src]

impl MulAssign<ModPoly> for ModPoly[src]

impl PartialEq<ModPoly> for ModPoly[src]

impl<'_> Rem<&'_ ModPoly> for ModPoly[src]

type Output = ModPoly

The resulting type after applying the % operator.

impl Rem<ModPoly> for ModPoly[src]

type Output = ModPoly

The resulting type after applying the % operator.

impl<'_> Rem<ModPoly> for &'_ ModPoly[src]

type Output = ModPoly

The resulting type after applying the % operator.

impl<'_> RemAssign<&'_ ModPoly> for ModPoly[src]

impl RemAssign<ModPoly> for ModPoly[src]

impl<'_> Sub<&'_ ModPoly> for ModPoly[src]

type Output = ModPoly

The resulting type after applying the - operator.

impl Sub<ModPoly> for ModPoly[src]

type Output = ModPoly

The resulting type after applying the - operator.

impl<'_> Sub<ModPoly> for &'_ ModPoly[src]

type Output = ModPoly

The resulting type after applying the - operator.

impl<'_> SubAssign<&'_ ModPoly> for ModPoly[src]

impl SubAssign<ModPoly> for ModPoly[src]

Auto Trait Implementations

impl RefUnwindSafe for ModPoly

impl !Send for ModPoly

impl !Sync for ModPoly

impl Unpin for ModPoly

impl UnwindSafe for ModPoly

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Az for T[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> CheckedAs for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> OverflowingAs for T[src]

impl<T> SaturatingAs for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> WrappingAs for T[src]