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:
- G generates I (every element of I is a polynomial combination of G)
- 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: MonomialOrderMonomial ordering used for computation
is_reduced: boolWhether the basis is reduced
Implementations§
Source§impl GroebnerBasis
impl GroebnerBasis
Sourcepub fn new(
polynomials: Vec<Expression>,
variables: Vec<Symbol>,
ordering: MonomialOrder,
) -> Self
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 idealvariables- Variables in the polynomial ringordering- 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
);Sourcepub fn compute(&mut self)
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();Sourcepub fn compute_with_result(&mut self) -> MathResult<()>
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
}Sourcepub fn reduce(&mut self)
pub fn reduce(&mut self)
Reduce the Gröbner basis to minimal form
A reduced Gröbner basis has:
- Leading coefficients are 1 (monic)
- No monomial of any basis element is divisible by the leading term of another basis element
Sourcepub fn contains(&self, poly: &Expression) -> bool
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));Sourcepub fn get_variables(&self) -> Vec<Symbol>
pub fn get_variables(&self) -> Vec<Symbol>
Get all variables that appear in the basis
Trait Implementations§
Source§impl Clone for GroebnerBasis
impl Clone for GroebnerBasis
Source§fn clone(&self) -> GroebnerBasis
fn clone(&self) -> GroebnerBasis
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for GroebnerBasis
impl RefUnwindSafe for GroebnerBasis
impl Send for GroebnerBasis
impl Sync for GroebnerBasis
impl Unpin for GroebnerBasis
impl UnwindSafe for GroebnerBasis
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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