Algebraic

Algebraic provides an exact number type for algebraic numbers. Algebraic numbers are roots of polynomials with rational coefficients. With it, we can represent expressions involving addition, multiplication, division, n-roots (eg. sqrt or cbrt), and roots of rational polynomials. So, it is similar Rational, but adds roots as a valid, exact operation. The cost is that this will not be as fast as Rational for many operations.

In general, you can assume all operations on this number type are exact, except for those that explicitly construct approximations to an Algebraic number, such as toBigDecimal.

For an overview of the ideas, algorithms, and proofs of this number type, you can read the following papers:

  • "On Guaranteed Accuracy Computation." C. K. Yap.
  • "Recent Progress in Exact Geometric Computation." C. Li, S. Pion, and C. K. Yap.
  • "A New Constructive Root Bound for Algebraic Expressions" by C. Li & C. K. Yap.
  • "A Separation Bound for Real Algebraic Expressions." C. Burnikel, et al.
Companion:
object
class Number
class Object
trait Matchable
class Any

Value members

Concrete methods

def *(that: Algebraic): Algebraic
def +(that: Algebraic): Algebraic
def -(that: Algebraic): Algebraic
def /(that: Algebraic): Algebraic
def <(that: Algebraic): Boolean
def <=(that: Algebraic): Boolean
def =!=(that: Algebraic): Boolean
def ===(that: Algebraic): Boolean
def >(that: Algebraic): Boolean
def >=(that: Algebraic): Boolean

Return a non-negative Algebraic with the same magnitude as this one.

Return a non-negative Algebraic with the same magnitude as this one.

Returns the cube root of this number.

Returns the cube root of this number.

def compare(that: Algebraic): Int

Returns an integer with the same sign as this - that. Specifically, if this &lt; that, then the sign is negative, if this &gt; that, then the sign is positive, otherwise this == that and this returns 0.

Returns an integer with the same sign as this - that. Specifically, if this &lt; that, then the sign is negative, if this &gt; that, then the sign is positive, otherwise this == that and this returns 0.

Returns a Double that approximates this value. If the exponent is too large to fit in a double, the Double.PositiveInfinity or Double.NegativeInfinity is returned.

Returns a Double that approximates this value. If the exponent is too large to fit in a double, the Double.PositiveInfinity or Double.NegativeInfinity is returned.

override def equals(that: Any): Boolean
Definition Classes
Any
def evaluateWith[A : ClassTag](implicit evidence$1: Field[A], evidence$2: NRoot[A], evidence$3: RootFinder[A], evidence$4: Eq[A], evidence$5: ClassTag[A], conv: ConvertableTo[A]): A

Evaluates this algebraic expression with a different number type. All Algebraic numbers store the entire expression tree, so we can use this to replay the stored expression using a different type. This will accumulate errors as if the number type had been used from the beginning and is only really suitable for more exact number types, like Real.

Evaluates this algebraic expression with a different number type. All Algebraic numbers store the entire expression tree, so we can use this to replay the stored expression using a different type. This will accumulate errors as if the number type had been used from the beginning and is only really suitable for more exact number types, like Real.

TODO: Eq/ClassTag come from poly.map - would love to get rid of them.

Returns a Float that approximates this value. If the exponent is too large to fit in a float, the Float.PositiveInfinity or Float.NegativeInfinity is returned.

Returns a Float that approximates this value. If the exponent is too large to fit in a float, the Float.PositiveInfinity or Float.NegativeInfinity is returned.

override def hashCode: Int
Definition Classes
Any

Returns the nearest, valid Int value to this Algebraic, without going further away from 0 (eg. truncation).

Returns the nearest, valid Int value to this Algebraic, without going further away from 0 (eg. truncation).

If this Algebraic represented 1.2, then this would return 1. If this represented -3.3, then this would return -3. If this value is greater than Int.MaxValue, then Int.MaxValue is returned. If this value is less than Int.MinValue, then Int.MinValue is returned.

Returns true iff this is a rational expression (ie contains no n-root expressions). Otherwise it is a radical expression and returns false.

Returns true iff this is a rational expression (ie contains no n-root expressions). Otherwise it is a radical expression and returns false.

override def isValidInt: Boolean

Returns true if this Algebraic number is a whole number (no fractional part) and fits within the bounds of an Int. That is, if x.isValidInt, then Algebraic(x.toInt) == x.

Returns true if this Algebraic number is a whole number (no fractional part) and fits within the bounds of an Int. That is, if x.isValidInt, then Algebraic(x.toInt) == x.

Definition Classes

Returns true if this Algebraic number is a whole number (no fractional part) and fits within the bounds of an Long. That is, if x.isValidLong, then Algebraic(x.toLong) == x.

Returns true if this Algebraic number is a whole number (no fractional part) and fits within the bounds of an Long. That is, if x.isValidLong, then Algebraic(x.toLong) == x.

Returns true iff this Algebraic exactly represents a valid BigInt.

Returns true iff this Algebraic exactly represents a valid BigInt.

Returns true iff this Algebraic number is exactly 0.

Returns true iff this Algebraic number is exactly 0.

Returns the nearest, valid Long value to this Algebraic, without going further away from 0 (eg. truncation).

Returns the nearest, valid Long value to this Algebraic, without going further away from 0 (eg. truncation).

If this Algebraic represented 1.2, then this would return 1. If this represented -3.3, then this would return -3. If this value is greater than Long.MaxValue, then Long.MaxValue is returned. If this value is less than Long.MinValue, then Long.MinValue is returned.

Returns the k-th root of this number.

Returns the k-th root of this number.

def pow(k: Int): Algebraic

Raise this number to the k-th power.

Raise this number to the k-th power.

def sign: Sign

Returns the sign of this Algebraic number. Algebraic numbers support exact sign tests, so this is guaranteed to be accurate.

Returns the sign of this Algebraic number. Algebraic numbers support exact sign tests, so this is guaranteed to be accurate.

def signum: Int

Returns an Int with the same sign as this algebraic number. Algebraic numbers support exact sign tests, so this is guaranteed to be accurate.

Returns an Int with the same sign as this algebraic number. Algebraic numbers support exact sign tests, so this is guaranteed to be accurate.

Returns the square root of this number.

Returns the square root of this number.

Returns an Algebraic whose value is the difference between this and (this /~ that) * that -- the remainder of truncated division.

Returns an Algebraic whose value is the difference between this and (this /~ that) * that -- the remainder of truncated division.

def toBigDecimal(scale: Int, roundingMode: RoundingMode): BigDecimal

Absolute approximation to scale decimal places with the given rounding mode. Rounding is always exact.

Absolute approximation to scale decimal places with the given rounding mode. Rounding is always exact.

Relative approximation to the precision specified in mc with the given rounding mode. Rounding is always exact. The sign is always correct; the sign of the returned BigDecimal matches the sign of the exact value this Algebraic represents.

Relative approximation to the precision specified in mc with the given rounding mode. Rounding is always exact. The sign is always correct; the sign of the returned BigDecimal matches the sign of the exact value this Algebraic represents.

Value parameters:
mc

the precision and rounding mode of the final result

Returns:

an approximation to the value of this algebraic number

Returns the nearest, valid BigInt value to this Algebraic, without going further away from 0 (eg. truncation).

Returns the nearest, valid BigInt value to this Algebraic, without going further away from 0 (eg. truncation).

If this Algebraic represented 1.2, then this would return 1. If this represented -3.3, then this would return -3.

If this is a rational expressions, then it returns the exact value as a Rational. Otherwise, this is a radical expression and None is returned.

If this is a rational expressions, then it returns the exact value as a Rational. Otherwise, this is a radical expression and None is returned.

Returns an exact Real representation of this number.

Returns an exact Real representation of this number.

override def toString: String
Definition Classes
Any

Returns an Algebraic whose value is just the integer part of this / that. This operation is exact.

Returns an Algebraic whose value is just the integer part of this / that. This operation is exact.

def underlying: AnyRef

Concrete fields

val expr: Expr