Polynomial

Struct Polynomial 

Source
pub struct Polynomial<F> {
    pub terms: Vec<Term<F>>,
    pub nvars: usize,
    pub order: MonomialOrder,
}

Fields§

§terms: Vec<Term<F>>§nvars: usize§order: MonomialOrder

Implementations§

Source§

impl<F: Field> Polynomial<F>

Source

pub fn new(terms: Vec<Term<F>>, nvars: usize, order: MonomialOrder) -> Self

Examples found in repository?
examples/basic.rs (lines 12-29)
5fn main() {
6    // Example: Compute a Groebner basis for the ideal (x^2 + y^2 - 1, x - y)
7    // Variables: x = 0, y = 1
8    let nvars = 2;
9    let order = MonomialOrder::Lex;
10
11    // x^2 + y^2 - 1
12    let f = Polynomial::new(
13        vec![
14            Term::new(
15                BigRational::new(1.into(), 1.into()),
16                Monomial::new(vec![2, 0]),
17            ), // x^2
18            Term::new(
19                BigRational::new(1.into(), 1.into()),
20                Monomial::new(vec![0, 2]),
21            ), // y^2
22            Term::new(
23                BigRational::new((-1).into(), 1.into()),
24                Monomial::new(vec![0, 0]),
25            ), // -1
26        ],
27        nvars,
28        order,
29    );
30
31    // x - y
32    let g = Polynomial::new(
33        vec![
34            Term::new(
35                BigRational::new(1.into(), 1.into()),
36                Monomial::new(vec![1, 0]),
37            ), // x
38            Term::new(
39                BigRational::new((-1).into(), 1.into()),
40                Monomial::new(vec![0, 1]),
41            ), // -y
42        ],
43        nvars,
44        order,
45    );
46
47    // Compute the Groebner basis
48    match groebner_basis(vec![f, g], order, true) {
49        Ok(basis) => {
50            println!("Groebner basis:");
51            for (i, poly) in basis.iter().enumerate() {
52                println!("g{}: {}", i + 1, poly);
53            }
54        }
55        Err(e) => {
56            println!("Error computing Groebner basis: {e}");
57        }
58    }
59}
Source

pub fn zero(nvars: usize, order: MonomialOrder) -> Self

Source

pub fn constant(coeff: F, nvars: usize, order: MonomialOrder) -> Self

Source

pub fn is_zero(&self) -> bool

Source

pub fn leading_term(&self) -> Option<&Term<F>>

Source

pub fn leading_monomial(&self) -> Option<&Monomial>

Source

pub fn leading_coefficient(&self) -> Option<&F>

Source

pub fn make_monic(&self) -> Self

Source

pub fn add(&self, other: &Self) -> Self

Source

pub fn subtract(&self, other: &Self) -> Self

Source

pub fn multiply_scalar(&self, scalar: &F) -> Self

Source

pub fn multiply_monomial(&self, monomial: &Monomial) -> Self

Source

pub fn multiply(&self, other: &Self) -> Self

Source

pub fn s_polynomial(&self, other: &Self) -> Result<Self, PolynomialError>

Source

pub fn reduce(&self, basis: &[Self]) -> Result<Self, PolynomialError>

Trait Implementations§

Source§

impl<F: Clone> Clone for Polynomial<F>

Source§

fn clone(&self) -> Polynomial<F>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F: Debug> Debug for Polynomial<F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F: Field> Display for Polynomial<F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F: PartialEq> PartialEq for Polynomial<F>

Source§

fn eq(&self, other: &Polynomial<F>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<F> StructuralPartialEq for Polynomial<F>

Auto Trait Implementations§

§

impl<F> Freeze for Polynomial<F>

§

impl<F> RefUnwindSafe for Polynomial<F>
where F: RefUnwindSafe,

§

impl<F> Send for Polynomial<F>
where F: Send,

§

impl<F> Sync for Polynomial<F>
where F: Sync,

§

impl<F> Unpin for Polynomial<F>
where F: Unpin,

§

impl<F> UnwindSafe for Polynomial<F>
where F: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.