GroebnerBasis

Struct GroebnerBasis 

Source
pub struct GroebnerBasis {
    pub basis: Vec<Expression>,
    pub variables: Vec<Symbol>,
    pub ordering: MonomialOrder,
    pub is_reduced: bool,
}
Expand description

Represents a Gröbner basis for a polynomial ideal

A Gröbner basis is a special generating set for a polynomial ideal that has useful computational properties, analogous to row echelon form for matrices or GCD for integers.

§Mathematical Background

For an ideal I = <f1, f2, …, fn> in k[x1, …, xm], a Gröbner basis is a finite subset G of I such that:

  1. G generates I (every element of I is a polynomial combination of G)
  2. The leading terms of G generate the ideal of leading terms of I

§Applications

  • Ideal membership testing: Check if f ∈ I
  • Solving systems of polynomial equations
  • Computing ideal operations (intersection, quotient, elimination)
  • Implicitization in algebraic geometry
  • Computational commutative algebra

Fields§

§basis: Vec<Expression>

The basis polynomials

§variables: Vec<Symbol>

Variables in the polynomial ring

§ordering: MonomialOrder

Monomial ordering used for computation

§is_reduced: bool

Whether the basis is reduced

Implementations§

Source§

impl GroebnerBasis

Source

pub fn new( polynomials: Vec<Expression>, variables: Vec<Symbol>, ordering: MonomialOrder, ) -> Self

Create a new Gröbner basis from polynomials

§Arguments
  • polynomials - Initial generating set for the ideal
  • variables - Variables in the polynomial ring
  • ordering - Monomial ordering to use
§Examples
use mathhook_core::{symbol, expr, Expression};
use mathhook_core::algebra::groebner::{GroebnerBasis, MonomialOrder};

let x = symbol!(x);
let y = symbol!(y);
let f1 = Expression::add(vec![Expression::pow(x.clone().into(), Expression::integer(2)), Expression::pow(y.clone().into(), Expression::integer(2)), Expression::integer(-1)]);
let f2 = Expression::add(vec![x.clone().into(), Expression::mul(vec![Expression::integer(-1), y.clone().into()])]);
let gb = GroebnerBasis::new(
    vec![f1, f2],
    vec![x, y],
    MonomialOrder::Lex
);
Source

pub fn compute(&mut self)

Compute the Gröbner basis using Buchberger’s algorithm

Transforms the initial generators into a Gröbner basis by computing S-polynomials and adding non-zero remainders to the basis.

§Examples
use mathhook_core::{symbol, expr};
use mathhook_core::algebra::groebner::{GroebnerBasis, MonomialOrder};

let x = symbol!(x);
let y = symbol!(y);
let f1 = Expression::add(vec![Expression::pow(x.clone().into(), Expression::integer(2)), Expression::pow(y.clone().into(), Expression::integer(2)), Expression::integer(-1)]);
let f2 = Expression::add(vec![x.clone().into(), Expression::mul(vec![Expression::integer(-1), y.clone().into()])]);
let mut gb = GroebnerBasis::new(
    vec![f1, f2],
    vec![x, y],
    MonomialOrder::Lex
);
gb.compute();
Source

pub fn compute_with_result(&mut self) -> MathResult<()>

Compute the Gröbner basis with explicit error handling

Returns Ok(()) on success or Err(MathError) if computation times out or exceeds iteration limit.

§Examples
use mathhook_core::{symbol, expr};
use mathhook_core::algebra::groebner::{GroebnerBasis, MonomialOrder};

let x = symbol!(x);
let y = symbol!(y);
let f1 = Expression::add(vec![Expression::pow(x.clone().into(), Expression::integer(2)), Expression::pow(y.clone().into(), Expression::integer(2)), Expression::integer(-1)]);
let f2 = Expression::add(vec![x.clone().into(), Expression::mul(vec![Expression::integer(-1), y.clone().into()])]);
let mut gb = GroebnerBasis::new(
    vec![f1, f2],
    vec![x, y],
    MonomialOrder::Lex
);
if gb.compute_with_result().is_ok() {
    // Computation succeeded
} else {
    // Computation timed out or exceeded iteration limit
}
Source

pub fn reduce(&mut self)

Reduce the Gröbner basis to minimal form

A reduced Gröbner basis has:

  1. Leading coefficients are 1 (monic)
  2. No monomial of any basis element is divisible by the leading term of another basis element
Source

pub fn contains(&self, poly: &Expression) -> bool

Test if a polynomial is in the ideal generated by this basis

§Arguments
  • poly - Polynomial to test for membership
§Returns

Returns true if the polynomial reduces to zero modulo the basis

§Examples
use mathhook_core::{symbol, expr};
use mathhook_core::algebra::groebner::{GroebnerBasis, MonomialOrder};

let x = symbol!(x);
let y = symbol!(y);
let f1 = expr!(x - y);
let f2 = Expression::add(vec![Expression::pow(y.clone().into(), Expression::integer(2)), Expression::integer(-1)]);
let mut gb = GroebnerBasis::new(
    vec![f1, f2],
    vec![x.clone(), y.clone()],
    MonomialOrder::Lex
);
gb.compute();

let test = Expression::add(vec![Expression::pow(x.clone().into(), Expression::integer(2)), Expression::integer(-1)]);
assert!(gb.contains(&test));
Source

pub fn get_variables(&self) -> Vec<Symbol>

Get all variables that appear in the basis

Trait Implementations§

Source§

impl Clone for GroebnerBasis

Source§

fn clone(&self) -> GroebnerBasis

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for GroebnerBasis

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.