Class/Object

spire.math

Algebraic

Related Docs: object Algebraic | package math

Permalink

final class Algebraic extends ScalaNumber with ScalaNumericConversions with Serializable

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:

Annotations
@SerialVersionUID()
Linear Supertypes
Serializable, ScalaNumericConversions, ScalaNumericAnyConversions, ScalaNumber, java.lang.Number, Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Algebraic
  2. Serializable
  3. ScalaNumericConversions
  4. ScalaNumericAnyConversions
  5. ScalaNumber
  6. Number
  7. Serializable
  8. AnyRef
  9. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. def *(that: Algebraic): Algebraic

    Permalink
  4. def +(that: Algebraic): Algebraic

    Permalink
  5. def -(that: Algebraic): Algebraic

    Permalink
  6. def /(that: Algebraic): Algebraic

    Permalink
  7. def <(that: Algebraic): Boolean

    Permalink
  8. def <=(that: Algebraic): Boolean

    Permalink
  9. def =!=(that: Algebraic): Boolean

    Permalink
  10. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  11. def ===(that: Algebraic): Boolean

    Permalink
  12. def >(that: Algebraic): Boolean

    Permalink
  13. def >=(that: Algebraic): Boolean

    Permalink
  14. def abs: Algebraic

    Permalink

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

  15. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  16. def byteValue(): Byte

    Permalink
    Definition Classes
    Number
  17. def cbrt: Algebraic

    Permalink

    Returns the cube root of this number.

  18. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  19. def compare(that: Algebraic): Int

    Permalink

    Returns an integer with the same sign as this - that.

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

  20. def doubleValue(): Double

    Permalink

    Returns a Double that approximates this value.

    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.

    Definition Classes
    Algebraic → ScalaNumericAnyConversions → Number
  21. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  22. def equals(that: Any): Boolean

    Permalink
    Definition Classes
    Algebraic → AnyRef → Any
  23. def evaluateWith[A](implicit arg0: Field[A], arg1: NRoot[A], arg2: RootFinder[A], arg3: Eq[A], arg4: ClassTag[A], conv: ConvertableTo[A]): A

    Permalink

    Evaluates this algebraic expression with a different number type.

    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.

  24. val expr: Expr

    Permalink
  25. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  26. def floatValue(): Float

    Permalink

    Returns a Float that approximates this value.

    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.

    Definition Classes
    Algebraic → ScalaNumericAnyConversions → Number
  27. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  28. def hashCode(): Int

    Permalink
    Definition Classes
    Algebraic → AnyRef → Any
  29. def intValue(): Int

    Permalink

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

    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.

    Definition Classes
    Algebraic → ScalaNumericAnyConversions → Number
  30. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  31. def isRational: Boolean

    Permalink

    Returns true iff this is a rational expression (ie contains no n-root expressions).

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

  32. def isValidByte: Boolean

    Permalink
    Definition Classes
    ScalaNumericAnyConversions
  33. def isValidChar: Boolean

    Permalink
    Definition Classes
    ScalaNumericAnyConversions
  34. def isValidInt: Boolean

    Permalink

    Returns true if this Algebraic number is a whole number (no fractional part) and fits within the bounds of an Int.

    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
    Algebraic → ScalaNumericAnyConversions
  35. def isValidLong: Boolean

    Permalink

    Returns true if this Algebraic number is a whole number (no fractional part) and fits within the bounds of an Long.

    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.

  36. def isValidShort: Boolean

    Permalink
    Definition Classes
    ScalaNumericAnyConversions
  37. def isWhole(): Boolean

    Permalink

    Returns true iff this Algebraic exactly represents a valid BigInt.

    Returns true iff this Algebraic exactly represents a valid BigInt.

    Definition Classes
    Algebraic → ScalaNumericAnyConversions → ScalaNumber
  38. def isZero: Boolean

    Permalink

    Returns true iff this Algebraic number is exactly 0.

  39. def longValue(): Long

    Permalink

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

    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.

    Definition Classes
    Algebraic → ScalaNumericAnyConversions → Number
  40. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  41. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  42. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  43. def nroot(k: Int): Algebraic

    Permalink

    Returns the k-th root of this number.

  44. def pow(k: Int): Algebraic

    Permalink

    Raise this number to the k-th power.

  45. def shortValue(): Short

    Permalink
    Definition Classes
    Number
  46. def sign: Sign

    Permalink

    Returns the sign of this Algebraic number.

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

  47. def signum: Int

    Permalink

    Returns an Int with the same sign as this algebraic number.

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

  48. def sqrt: Algebraic

    Permalink

    Returns the square root of this number.

  49. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  50. def tmod(that: Algebraic): Algebraic

    Permalink

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

  51. def toBigDecimal(mc: MathContext): BigDecimal

    Permalink

    Relative approximation to the precision specified in mc with the given rounding mode.

    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.

    mc

    the precision and rounding mode of the final result

    returns

    an approximation to the value of this algebraic number

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

    Permalink

    Absolute approximation to scale decimal places with the given rounding mode.

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

  53. def toBigInt: BigInt

    Permalink

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

    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.

  54. def toByte: Byte

    Permalink
    Definition Classes
    ScalaNumericAnyConversions
  55. def toChar: Char

    Permalink
    Definition Classes
    ScalaNumericAnyConversions
  56. def toDouble: Double

    Permalink
    Definition Classes
    ScalaNumericAnyConversions
  57. def toExprString: String

    Permalink
  58. def toFloat: Float

    Permalink
    Definition Classes
    ScalaNumericAnyConversions
  59. def toInt: Int

    Permalink
    Definition Classes
    ScalaNumericAnyConversions
  60. def toLong: Long

    Permalink
    Definition Classes
    ScalaNumericAnyConversions
  61. def toRational: Option[Rational]

    Permalink

    If this is a rational expressions, then it returns the exact value as a Rational.

    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.

  62. def toReal: Real

    Permalink

    Returns an exact Real representation of this number.

  63. def toShort: Short

    Permalink
    Definition Classes
    ScalaNumericAnyConversions
  64. def toString(): String

    Permalink
    Definition Classes
    Algebraic → AnyRef → Any
  65. def tquot(that: Algebraic): Algebraic

    Permalink

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

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

  66. def unary_-: Algebraic

    Permalink
  67. def underlying(): AnyRef

    Permalink
    Definition Classes
    Algebraic → ScalaNumericConversions → ScalaNumericAnyConversions → ScalaNumber
  68. def unifiedPrimitiveEquals(x: Any): Boolean

    Permalink
    Attributes
    protected
    Definition Classes
    ScalaNumericAnyConversions
  69. def unifiedPrimitiveHashcode(): Int

    Permalink
    Attributes
    protected
    Definition Classes
    ScalaNumericAnyConversions
  70. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  71. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  72. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Serializable

Inherited from ScalaNumericConversions

Inherited from ScalaNumericAnyConversions

Inherited from ScalaNumber

Inherited from java.lang.Number

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped