Field

com.phasmidsoftware.number.core.numerical.Field
See theField companion object
trait Field extends Numerical, Approximatable, Ordered[Field]

Trait which describes the behavior of all Numbers and Complex instances. See https://en.wikipedia.org/wiki/Field_(mathematics).

The operations supported are addition, subtraction, multiplication and division. By inference, we should be able to raise an instance of Field to a numeric power.

TODO it is inappropriate to extend Ordered here since complex numbers do not have an intrinsic order.

Attributes

Companion
object
Graph
Supertypes
trait Ordered[Field]
trait Comparable[Field]
trait Numerical
trait NumberLike
class Object
trait Matchable
class Any
Show all
Known subtypes
trait Multivariate
trait Complex
class BaseComplex
class ComplexPolar
class Real
object NaN
Show all

Members list

Value members

Abstract methods

infix def add(x: Field): Field

Add x to this Field and return the result. See Number.plus for more detail.

Add x to this Field and return the result. See Number.plus for more detail.

Value parameters

x

the addend.

Attributes

Returns

the sum.

def atan(y: Real): Field

Calculates the arctangent (inverse tangent) of the given Real number.

Calculates the arctangent (inverse tangent) of the given Real number.

Value parameters

y

the Real number whose arctangent is to be calculated.

Attributes

Returns

the arctangent of the specified Real number, represented as a Field.

def cos: Field

Computes the trigonometric cosine of this Field.

Computes the trigonometric cosine of this Field.

Attributes

Returns

the cosine of this Field.

def cosh: Field
infix def divide(x: Field): Field

Divide this Field by x and return the result.

Divide this Field by x and return the result.

Value parameters

x

the divisor.

Attributes

Returns

the quotient.

def exp: Field

Computes the exponential of this Field.

Computes the exponential of this Field.

Attributes

Returns

a Field representing the exponential of this instance.

def isAlgebraic: Boolean

Determines if this Field instance is algebraic. An algebraic Field is one that can be expressed as the root of a non-zero polynomial with rational coefficients. In this type hierarchy, we are going to consider that complex numbers are algebraic. However, the subtrait which should probably be called Algebraic is, at least for now, named MultiVariate.

Determines if this Field instance is algebraic. An algebraic Field is one that can be expressed as the root of a non-zero polynomial with rational coefficients. In this type hierarchy, we are going to consider that complex numbers are algebraic. However, the subtrait which should probably be called Algebraic is, at least for now, named MultiVariate.

Attributes

Returns

true if this Field is algebraic (multivariate); false otherwise.

def isComplex: Boolean

Method to determine if this Field is represented by a Complex number.

Method to determine if this Field is represented by a Complex number.

Attributes

Returns

true if this is Complex.

def isImaginary: Boolean

Method to determine if this Field is imaginary-valued (i.e., the point lies on the imaginary axis).

Method to determine if this Field is imaginary-valued (i.e., the point lies on the imaginary axis).

Attributes

Returns

true if this is imaginary.

def isReal: Boolean

Method to determine if this Field is real-valued (i.e., the point lies on the real axis).

Method to determine if this Field is real-valued (i.e., the point lies on the real axis).

Attributes

Returns

true if not imaginary.

def ln: Field

Computes the natural logarithm (log base e) of this Field. CONSIDER renaming this as "ln" but note that the Java library calls this operation "log."

Computes the natural logarithm (log base e) of this Field. CONSIDER renaming this as "ln" but note that the Java library calls this operation "log."

Attributes

Returns

a new Field representing the result of the logarithmic computation.

infix def multiply(x: Field): Field

Multiply this Field by x and return the result.

Multiply this Field by x and return the result.

  • @param x the multiplicand.
  • @return the product.

Attributes

infix def power(p: Number): Field

Raises this Field to the power of the specified number.

Raises this Field to the power of the specified number.

Value parameters

p

the exponent, provided as a Number.

Attributes

Returns

the result of raising this Field to the power p.

infix def power(p: Field): Field

Raise this Field to the power p.

Raise this Field to the power p.

Value parameters

p

a Field.

Attributes

Returns

this Field raised to power p.

def sin: Field

Computes the sine of this Field.

Computes the sine of this Field.

Attributes

Returns

the sine of this Field, as an instance of Field.

def sinh: Field
def square: Field

Squares this Field instance by multiplying it with itself.

Squares this Field instance by multiplying it with itself.

Attributes

Returns

the result of squaring this Field.

def tan: Field

Computes the tangent of this Field.

Computes the tangent of this Field.

Attributes

Returns

the tangent of this Field as a new Field.

def tanh: Field

Concrete methods

infix def *(x: Field): Field

Multiply this Field by the given Field and return the result.

Multiply this Field by the given Field and return the result.

Value parameters

x

the multiplicand, an instance of Field.

Attributes

Returns

the product of this Field and the given Field.

infix def +(x: Field): Field

Synonym for add.

Synonym for add.

Value parameters

x

the addend.

Attributes

Returns

the result.

infix def -(x: Field): Field

Synonym for subtract.

Synonym for subtract.

Value parameters

x

the subtrahend.

Attributes

Returns

this - x.

def approximation: Option[Real]

Computes an approximation of the field as a real number, if possible. This method attempts to map the underlying numerical representation to a real value.

Computes an approximation of the field as a real number, if possible. This method attempts to map the underlying numerical representation to a real value.

Attributes

Returns

an Option containing the Real representation of this field if it can be approximated, or None if the approximation is not possible.

infix def power(p: Int): Field

Raise this Field to the power p.

Raise this Field to the power p.

Value parameters

p

an Int.

Attributes

Returns

this Field raised to power p.

infix def subtract(x: Field): Field

Subtract x from this Field and return the result.

Subtract x from this Field and return the result.

Value parameters

x

the subtrahend.

Attributes

Returns

the difference of this - x.

def toRational: Option[Rational]

Converts this Field instance to its equivalent rational representation if it is real-valued.

Converts this Field instance to its equivalent rational representation if it is real-valued.

Attributes

Returns

an Option containing the rational representation of this Field if it is real-valued; otherwise, None.

Inherited methods

def <(that: Field): Boolean

Returns true if this is less than that

Returns true if this is less than that

Value parameters

that

the instance to compare against

Attributes

Inherited from:
Ordered
def <=(that: Field): Boolean

Returns true if this is less than or equal to that.

Returns true if this is less than or equal to that.

Attributes

Inherited from:
Ordered
def >(that: Field): Boolean

Returns true if this is greater than that.

Returns true if this is greater than that.

Value parameters

that

the instance to compare against

Attributes

Inherited from:
Ordered
def >=(that: Field): Boolean

Returns true if this is greater than or equal to that.

Returns true if this is greater than or equal to that.

Attributes

Inherited from:
Ordered
def asJavaNumber: Option[Number]

Converts this NumberLike object into an optional java.lang.Number provided that the conversion can be performed without loss of precision.

Converts this NumberLike object into an optional java.lang.Number provided that the conversion can be performed without loss of precision.

The method determines whether the current NumberLike object can be represented as a java.lang.Number by leveraging the asNumber method and further evaluating certain conditions:

  • If the NumberLike object is an ExactNumber and its factor is PureNumber, the result is converted using Value.asJavaNumber.
  • If the NumberLike object is a FuzzyNumber with a wiggle value below a specified tolerance, the result is also converted using Value.asJavaNumber.
  • In all other cases, None is returned.

Attributes

Returns

an optional java.lang.Number representation of this object. The result is Some(java.lang.Number) if the conversion is successful under the stated conditions; otherwise, None.

Inherited from:
NumberLike
def compareTo(that: Field): Int

Result of comparing this with operand that.

Result of comparing this with operand that.

Value parameters

that

the instance to compare against

Attributes

Inherited from:
Ordered
def memberOf(set: NumberSet): Boolean

Method to determine if this NumberLike object is a member of the given set.

Method to determine if this NumberLike object is a member of the given set.

Value parameters

set

the candidate NumberSet.

Attributes

Returns

true if this is exact and belongs to set.

Inherited from:
NumberLike
def memberOf: Option[NumberSet]

Method to determine the NumberSet, if any, to which this NumberLike object belongs. NOTE that we don't yet support H, the quaternions.

Method to determine the NumberSet, if any, to which this NumberLike object belongs. NOTE that we don't yet support H, the quaternions.

Attributes

Returns

Some(numberSet) or None if it doesn't belong to any (for example, it is fuzzy).

Inherited from:
NumberLike
def show: String

Method to show this NumberLike in a human-friendly manner. Subclasses may override for prettier output (vulgar fractions, dropped trailing zeros, etc.). The default falls back to render.

Method to show this NumberLike in a human-friendly manner. Subclasses may override for prettier output (vulgar fractions, dropped trailing zeros, etc.). The default falls back to render.

Attributes

Returns

a String

Inherited from:
NumberLike

Inherited and Abstract methods

def abs: Numerical

Computes the absolute value of this Numerical instance. The result is a Numerical object representing a non-negative magnitude of this instance.

Computes the absolute value of this Numerical instance. The result is a Numerical object representing a non-negative magnitude of this instance.

Attributes

Returns

a Numerical object representing the absolute value of this instance.

Inherited from:
Numerical

Method to return this Field as a Complex. If this is a Real number x, return ComplexPolar(x) otherwise, return this.

Method to return this Field as a Complex. If this is a Real number x, return ComplexPolar(x) otherwise, return this.

Attributes

Returns

a Complex.

Inherited from:
Numerical
def asNumber: Option[Number]

Method to represent this NumberLike object as an optional Number. The result will be defined if: (1) we do not lose precision and (2) this object is not complex.

Method to represent this NumberLike object as an optional Number. The result will be defined if: (1) we do not lose precision and (2) this object is not complex.

NOTE: to force this as a Number, use convertToNumber in the companion Object.

CONSIDER redefining this as Option[Field] or Option[Real].

Attributes

Returns

a Some(x) if this is a Number; otherwise return None.

Inherited from:
NumberLike
def asReal: Option[Real]

Method to return this Field as a Real, if possible. If this is a Real number x, return Some(x) otherwise, return None.

Method to return this Field as a Real, if possible. If this is a Real number x, return Some(x) otherwise, return None.

Attributes

Returns

an Option[Real].

Inherited from:
Numerical
def compare(that: Field): Int

Result of comparing this with operand that.

Result of comparing this with operand that.

Implement this method to determine how instances of A will be sorted.

Returns x where:

  • x &lt; 0 when this &lt; that

  • x == 0 when this == that

  • x > 0 when this > that

Value parameters

that

the instance to compare against

Attributes

Returns

an integer whose sign indicates the ordering relation between this and that

Inherited from:
Ordered
def invert: Field

Yields the inverse of this Field. This Number is first normalized so that its factor is PureNumber, since we cannot directly invert Numbers with other factors. TODO note that this method does not belong in Numerical: it belongs in Field.

Yields the inverse of this Field. This Number is first normalized so that its factor is PureNumber, since we cannot directly invert Numbers with other factors. TODO note that this method does not belong in Numerical: it belongs in Field.

Attributes

Inherited from:
Numerical
def isExact: Boolean

Method to determine if this NumberLike object is exact. For instance, Number.pi is exact, although if you converted it into a PureNumber, it would no longer be exact.

Method to determine if this NumberLike object is exact. For instance, Number.pi is exact, although if you converted it into a PureNumber, it would no longer be exact.

Attributes

Returns

true if this NumberLike object is exact in the context of No factor, else false.

Inherited from:
NumberLike
def isInfinite: Boolean

Method to determine if this Field has infinite magnitude.

Method to determine if this Field has infinite magnitude.

Attributes

Returns

true if the magnitude of this Field is infinite.

Inherited from:
Numerical
def isProbablyZero(confidence: Double = ...): Boolean

Determines whether the magnitude of this Numerical instance is probably zero based on a given probability threshold.

Determines whether the magnitude of this Numerical instance is probably zero based on a given probability threshold.

Value parameters

confidence

the probability threshold (default is oneSigma). A higher value increases the confidence needed to determine that the magnitude is zero.

Attributes

Returns

true if the magnitude is considered to be probably zero based on the probability threshold, false otherwise.

Inherited from:
Numerical
def isSame(x: Numerical, confidence: Double = ...): Boolean

Method to determine if this Numerical is equivalent to another Numerical object (x).

Method to determine if this Numerical is equivalent to another Numerical object (x).

Value parameters

x

the other Numerical.

Attributes

Returns

true if they are most probably the same, otherwise false.

Inherited from:
Numerical
def isUnity: Boolean

Method to determine if this Field has unity magnitude. Unity is the multiplicative identity.

Method to determine if this Field has unity magnitude. Unity is the multiplicative identity.

Attributes

Returns

true if the magnitude of this Field is one.

Inherited from:
Numerical
def isZero: Boolean

Method to determine if this Field has zero magnitude. Zero is the additive identity.

Method to determine if this Field has zero magnitude. Zero is the additive identity.

Attributes

Returns

true if the magnitude of this Field is zero.

Inherited from:
Numerical
def maybeFactor: Option[Factor]

Method to determine what Factor, if there is such, this NumberLike object is based on. Unlike context, a None result is not permissive.

Method to determine what Factor, if there is such, this NumberLike object is based on. Unlike context, a None result is not permissive.

Attributes

Returns

an optional Factor.

Inherited from:
NumberLike

Method to "normalize" a field.

Method to "normalize" a field.

Attributes

Returns

a Field which is in canonical form.

Inherited from:
Numerical
def render: String

Method to render this NumberLike in a presentable manner.

Method to render this NumberLike in a presentable manner.

Attributes

Returns

a String

Inherited from:
NumberLike
def signum: Int

Determine the "sign" of this field. For a real-valued quantity (Real or Number), we try to determine if it is to the right, left or at the origin. For a complex number, we get the signum of the real part.

Determine the "sign" of this field. For a real-valued quantity (Real or Number), we try to determine if it is to the right, left or at the origin. For a complex number, we get the signum of the real part.

Attributes

Returns

+1 if to the right of the origin, -1 if to the left, 0 if at the origin.

Inherited from:
Numerical
def unary_-: Field

Change the sign of this Field.

Change the sign of this Field.

Attributes

Inherited from:
Numerical