Skip to main content

AlgebraicNumber

Struct AlgebraicNumber 

Source
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

Source

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.

Source

pub fn from_rational(r: BigRational) -> Self

Create an algebraic number from a rational number.

Source

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.

Source

pub fn polynomial(&self) -> &Polynomial

Get the polynomial defining this algebraic number.

Source

pub fn interval(&self) -> (&BigRational, &BigRational)

Get the isolating interval as (lower, upper).

Source

pub fn var(&self) -> Var

Get the variable used in the polynomial.

Source

pub fn refine(&mut self)

Refine the isolating interval by bisection.

This makes the interval smaller, improving precision for approximations.

Source

pub fn approximate(&self) -> BigRational

Get an approximation of the algebraic number as a rational.

This returns the midpoint of the isolating interval.

Source

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.

Source

pub fn is_zero(&self) -> bool

Check if this algebraic number is definitely zero.

Source

pub fn is_positive(&self) -> bool

Check if this algebraic number is definitely positive.

Source

pub fn is_negative(&self) -> bool

Check if this algebraic number is definitely negative.

Source

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.

Source

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)
Source

pub fn cmp_algebraic(&mut self, other: &mut AlgebraicNumber) -> Ordering

Compare this algebraic number with another.

Source

pub fn cmp_rational(&mut self, r: &BigRational) -> Ordering

Compare this algebraic number with a rational.

Source

pub fn negate(&self) -> AlgebraicNumber

Negate this algebraic number.

If α is a root of p(x), then -α is a root of p(-x).

Source

pub fn add_rational(&self, r: &BigRational) -> AlgebraicNumber

Add this algebraic number with a rational.

Source

pub fn mul_rational(&self, r: &BigRational) -> AlgebraicNumber

Multiply this algebraic number by a rational.

Source

pub fn sub_rational(&self, r: &BigRational) -> AlgebraicNumber

Subtract a rational from this algebraic number.

Source

pub fn inverse(&self) -> Option<AlgebraicNumber>

Compute the multiplicative inverse of this algebraic number.

Returns None if the number is zero.

Source

pub fn div_rational(&self, r: &BigRational) -> Option<AlgebraicNumber>

Divide this algebraic number by a rational.

Returns None if the divisor is zero.

Source

pub fn pow(&self, n: i32) -> Option<AlgebraicNumber>

Raise this algebraic number to an integer power.

Source

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”)

Source

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

Source§

fn clone(&self) -> AlgebraicNumber

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for AlgebraicNumber

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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, 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.