pub struct AlgebraicNumber { /* private fields */ }Expand description
An algebraic number represented by a polynomial and an isolating interval.
An algebraic number α is represented by:
- A polynomial p(x) such that p(α) = 0
- An isolating interval (a, b) that contains exactly one root of p
This representation allows for exact comparisons and arithmetic on algebraic numbers.
Implementations§
Source§impl AlgebraicNumber
impl AlgebraicNumber
Sourcepub fn new(
polynomial: Polynomial,
var: Var,
lower: BigRational,
upper: BigRational,
) -> Self
pub fn new( polynomial: Polynomial, var: Var, lower: BigRational, upper: BigRational, ) -> Self
Create a new algebraic number from a polynomial and an isolating interval.
§Panics
Panics if the interval doesn’t contain exactly one root of the polynomial.
Sourcepub fn from_rational(r: BigRational) -> Self
pub fn from_rational(r: BigRational) -> Self
Create an algebraic number from a rational number.
Sourcepub fn sqrt(n: &BigRational) -> Option<Self>
pub fn sqrt(n: &BigRational) -> Option<Self>
Create an algebraic number representing √n for a non-negative rational n.
Returns None if n is negative.
Sourcepub fn polynomial(&self) -> &Polynomial
pub fn polynomial(&self) -> &Polynomial
Get the polynomial defining this algebraic number.
Sourcepub fn interval(&self) -> (&BigRational, &BigRational)
pub fn interval(&self) -> (&BigRational, &BigRational)
Get the isolating interval as (lower, upper).
Sourcepub fn refine(&mut self)
pub fn refine(&mut self)
Refine the isolating interval by bisection.
This makes the interval smaller, improving precision for approximations.
Sourcepub fn approximate(&self) -> BigRational
pub fn approximate(&self) -> BigRational
Get an approximation of the algebraic number as a rational.
This returns the midpoint of the isolating interval.
Sourcepub fn approximate_with_precision(
&mut self,
epsilon: &BigRational,
) -> BigRational
pub fn approximate_with_precision( &mut self, epsilon: &BigRational, ) -> BigRational
Get an approximation with a specified precision.
Refines the interval until its width is less than epsilon.
Sourcepub fn is_positive(&self) -> bool
pub fn is_positive(&self) -> bool
Check if this algebraic number is definitely positive.
Sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Check if this algebraic number is definitely negative.
Sourcepub fn is_rational(&self) -> bool
pub fn is_rational(&self) -> bool
Check if this algebraic number is actually a rational number.
Returns true if the polynomial is linear (degree 1) which means the number is rational.
Sourcepub fn sign(&self) -> Option<i8>
pub fn sign(&self) -> Option<i8>
Get the sign of this algebraic number.
Returns:
- Some(1) if definitely positive
- Some(-1) if definitely negative
- Some(0) if definitely zero
- None if sign is unknown (shouldn’t happen with a proper isolating interval)
Sourcepub fn cmp_algebraic(&mut self, other: &mut AlgebraicNumber) -> Ordering
pub fn cmp_algebraic(&mut self, other: &mut AlgebraicNumber) -> Ordering
Compare this algebraic number with another.
Sourcepub fn cmp_rational(&mut self, r: &BigRational) -> Ordering
pub fn cmp_rational(&mut self, r: &BigRational) -> Ordering
Compare this algebraic number with a rational.
Sourcepub fn negate(&self) -> AlgebraicNumber
pub fn negate(&self) -> AlgebraicNumber
Negate this algebraic number.
If α is a root of p(x), then -α is a root of p(-x).
Sourcepub fn add_rational(&self, r: &BigRational) -> AlgebraicNumber
pub fn add_rational(&self, r: &BigRational) -> AlgebraicNumber
Add this algebraic number with a rational.
Sourcepub fn mul_rational(&self, r: &BigRational) -> AlgebraicNumber
pub fn mul_rational(&self, r: &BigRational) -> AlgebraicNumber
Multiply this algebraic number by a rational.
Sourcepub fn sub_rational(&self, r: &BigRational) -> AlgebraicNumber
pub fn sub_rational(&self, r: &BigRational) -> AlgebraicNumber
Subtract a rational from this algebraic number.
Sourcepub fn inverse(&self) -> Option<AlgebraicNumber>
pub fn inverse(&self) -> Option<AlgebraicNumber>
Compute the multiplicative inverse of this algebraic number.
Returns None if the number is zero.
Sourcepub fn div_rational(&self, r: &BigRational) -> Option<AlgebraicNumber>
pub fn div_rational(&self, r: &BigRational) -> Option<AlgebraicNumber>
Divide this algebraic number by a rational.
Returns None if the divisor is zero.
Sourcepub fn pow(&self, n: i32) -> Option<AlgebraicNumber>
pub fn pow(&self, n: i32) -> Option<AlgebraicNumber>
Raise this algebraic number to an integer power.
Sourcepub fn add_algebraic(&mut self, other: &mut AlgebraicNumber) -> AlgebraicNumber
pub fn add_algebraic(&mut self, other: &mut AlgebraicNumber) -> AlgebraicNumber
Add two algebraic numbers using resultant-based computation.
Given α (root of p(x)) and β (root of q(y)), computes α + β. For now, this uses interval arithmetic for robustness. A full resultant-based implementation requires careful handling of multivariate polynomials and root isolation, which is complex.
Reference: Standard symbolic computation textbooks (e.g., “Algorithms in Real Algebraic Geometry”)
Sourcepub fn mul_algebraic(&mut self, other: &mut AlgebraicNumber) -> AlgebraicNumber
pub fn mul_algebraic(&mut self, other: &mut AlgebraicNumber) -> AlgebraicNumber
Multiply two algebraic numbers using resultant-based computation.
Given α (root of p(x)) and β (root of q(y)), computes α * β. For now, this uses interval arithmetic for robustness. A full resultant-based implementation requires careful handling of multivariate polynomials and root isolation, which is complex.
Reference: Standard symbolic computation textbooks (e.g., “Algorithms in Real Algebraic Geometry”)
Trait Implementations§
Source§impl Clone for AlgebraicNumber
impl Clone for AlgebraicNumber
Source§fn clone(&self) -> AlgebraicNumber
fn clone(&self) -> AlgebraicNumber
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more