NthRoot

com.phasmidsoftware.number.core.inner.NthRoot
See theNthRoot companion object
abstract class NthRoot(val n: Int) extends InversePower

Represents an abstract base class for mathematical root operations by extending InversePower.

A number with value x and factor InversePower(n) represents the nth root of x where n is a Rational. For example, ExactNumber(5, SquareRoot) is the square root of 5, where SquareRoot is an alias for NthRoot(2).

The NthRoot class encapsulates the concept of a mathematical nth root and provides methods to retrieve the degree of the root. It is intended to be extended by concrete implementations that define specific behaviors for inverse power computation.

Value parameters

n

the integer value representing the nth root degree.

Attributes

Constructor

Creates a new instance of the NthRoot class with the specified root degree.

Companion
object
Graph
Supertypes
trait InversePower
trait Factor
class Object
trait Matchable
class Any
Known subtypes
object CubeRoot
object SquareRoot

Members list

Value members

Concrete methods

def canMultiply(f: Factor): Boolean

Determines whether the current factor can be multiplied by the given factor.

Determines whether the current factor can be multiplied by the given factor.

TODO check the logic here

Value parameters

f

the factor to be checked for compatibility with multiplication.

Attributes

Returns

true if the factors can be multiplied; false otherwise.

override def canRaise(f: Factor, exponent: Field): Boolean

Determines whether the current factor can be raised by the given factor.

Determines whether the current factor can be raised by the given factor.

Value parameters

f

the factor to be checked for compatibility with raising to a power.

Attributes

Returns

true if the factors can be powered; false otherwise.

Definition Classes
def convert(v: Value, f: Factor): Option[Value]

Converts a given Value v from one Factor this to another Factor f, if possible. Specifically handles cases where the target factor f is of type NthRoot.

Converts a given Value v from one Factor this to another Factor f, if possible. Specifically handles cases where the target factor f is of type NthRoot.

Value parameters

f

the target factor for the conversion.

v

the value to be converted.

Attributes

Returns

an optional Value which represents the same quantity as v under the factor f, or None if the conversion is not possible.

Retrieves the root degree represented by this factor in the form of a Rational.

Retrieves the root degree represented by this factor in the form of a Rational.

The root degree indicates the mathematical nth root applicable to this factor. For instance, a root degree of 2 represents a square root, a root degree of 3 represents a cube root, and so on.

Attributes

Returns

the integer value of the root degree.

Inherited methods

def add(x: Value, y: Value, f: Factor, negative: Boolean): Option[ProtoNumber]

Adds two values together and computes an appropriate factor for the result.

Adds two values together and computes an appropriate factor for the result.

Value parameters

f

the factor associated with y

negative

NOTE ignored.

x

the first value

y

the addend

Attributes

Returns

an optional tuple containing the resultant value and its factor

Inherited from:
InversePower
def asImaginary(value: Value): Option[String]

Converts a given Value into its imaginary representation, if applicable.

Converts a given Value into its imaginary representation, if applicable.

The method checks if the provided value can be represented as an imaginary number based on specific mathematical conditions, such as whether it is a negative integer and has a corresponding square root.

Value parameters

value

the Value object to be evaluated and potentially converted into its imaginary representation.

Attributes

Returns

an optional String representing the imaginary form of the value, or None if the value does not meet the conditions for conversion to an imaginary number.

Inherited from:
InversePower
def canAdd(f: Factor): Boolean

Determines whether the current factor can be augmented by the given factor. CONSIDER do we need this method now that we have add(x, y, this)?

Determines whether the current factor can be augmented by the given factor. CONSIDER do we need this method now that we have add(x, y, this)?

Value parameters

f

the factor to be checked for compatibility with addition.

Attributes

Returns

true if the factors can be added; false otherwise.

Inherited from:
Factor
def canShow(value: Value): Boolean

Determines whether given value with this Factor can be rendered exactly.

Determines whether given value with this Factor can be rendered exactly.

Attributes

Returns

true if this Factor can be rendered exactly; false otherwise.

Inherited from:
InversePower
def clean(po: Option[ProtoNumber]): Option[ProtoNumber]

Cleans a given optional ProtoNumber by potentially simplifying its root quantities based on specific conditions and returning the modified result.

Cleans a given optional ProtoNumber by potentially simplifying its root quantities based on specific conditions and returning the modified result.

Value parameters

po

an optional ProtoNumber that may be simplified

Attributes

Returns

an optional ProtoNumber, simplified if applicable, or None if input is None

Inherited from:
Factor

Raises the value x to the power of the value y.

Raises the value x to the power of the value y.

Value parameters

x

the base value to be raised

y

the exponent value (from a PureNumber)

Attributes

Returns

an optional result of type ProtoNumber, representing the computed value if the operation is valid, or None otherwise

Inherited from:
InversePower
def invert(x: Value): Option[ProtoNumber]

Inverts the given value by raising it to the power of -1, using a pure number factor.

Inverts the given value by raising it to the power of -1, using a pure number factor.

Value parameters

x

the value to be inverted

Attributes

Returns

an optional result of type ProtoNumber, representing the inverted value if the operation is valid, or None otherwise

Inherited from:
InversePower
def isA(context: CoreContext): Boolean

Determines if the current factor satisfies certain conditions within the given context.

Determines if the current factor satisfies certain conditions within the given context.

Value parameters

context

the context in which the factor is evaluated.

Attributes

Returns

a Boolean indicating whether the factor satisfies the specified conditions in the given context.

Inherited from:
InversePower
def isAdditive: Boolean

Determines if the current factor operates additively.

Determines if the current factor operates additively.

Attributes

Returns

false.

Inherited from:
InversePower
def modulate(v: Value): Value

Modulates the given value according to the context or rules defined by this factor.

Modulates the given value according to the context or rules defined by this factor.

Value parameters

v

the value to be modulated

Attributes

Returns

the modulated value

Inherited from:
InversePower
def multiply(x: Value, y: Value, f: Factor): Option[ProtoNumber]

Multiplies two values together and computes an appropriate factor for the result.

Multiplies two values together and computes an appropriate factor for the result.

Value parameters

f

the factor associated with y

x

the first value

y

the multiplicand

Attributes

Returns

an optional tuple containing the resultant value and its factor

Inherited from:
InversePower
def multiplyRootValues(x: Value, r: Int, y: Value, s: Int): Option[ProtoNumber]

Multiplies the root values of two given Value objects based on their respective root degrees.

Multiplies the root values of two given Value objects based on their respective root degrees.

This method computes the product of the rational representations of x and y, each raised to their specified root degrees (r and s respectively). The result is wrapped with an associated factor and optional additional information if the operation is valid. The method ensures that the input values are positive and can be represented rationally.

Value parameters

r

the root degree of the first value

s

the root degree of the second value

x

the first value to be multiplied

y

the second value to be multiplied

Attributes

Returns

an optional tuple containing the resultant value, its associated factor, and optional metadata; None if the values are not positive or cannot be represented rationally

Inherited from:
InversePower
def negate(x: Value): Option[ProtoNumber]

Negates the given value and computes an appropriate output tuple. The computation may include a value, its associated factor, and an optional fuzziness.

Negates the given value and computes an appropriate output tuple. The computation may include a value, its associated factor, and an optional fuzziness.

Value parameters

x

the value to be negated

Attributes

Returns

an optional tuple containing the negated value, its factor, and an optional fuzziness; None if the operation is not applicable

Inherited from:
InversePower
def raise(x: Value, y: Value, f: Factor): Option[ProtoNumber]

Raises x to the power of y and compute an appropriate factor for the result. NOTE: for now, we only allow raising to a power of a PureNumber. TODO: enable powers of Radian factor.

Raises x to the power of y and compute an appropriate factor for the result. NOTE: for now, we only allow raising to a power of a PureNumber. TODO: enable powers of Radian factor.

Value parameters

f

the factor associated with y

x

the first value

y

the power

Attributes

Returns

an optional tuple containing the resultant value and its factor

Inherited from:
Factor
override def render(x: Value): String

Method to render a Value in the context of this Factor.

Method to render a Value in the context of this Factor.

Value parameters

x

the Value.

Attributes

Returns

a String.

Definition Classes
Inherited from:
InversePower
def render(x: String): String

Generates a string representation of the cube root for a given input.

Generates a string representation of the cube root for a given input.

Value parameters

x

the input string to be represented with the cube root symbol

Attributes

Returns

a string in the format ³√ followed by the input

Inherited from:
InversePower
def simplifyRoot(p: ProtoNumber, v: Value, r: Rational, divisor: Int): Option[ProtoNumber]

Simplifies a root representation of a number based on the given parameters. The method computes whether the provided value v can be converted into a simpler root form using the provided divisor (e.g., square root for divisor 2, cube root for divisor 3).

Simplifies a root representation of a number based on the given parameters. The method computes whether the provided value v can be converted into a simpler root form using the provided divisor (e.g., square root for divisor 2, cube root for divisor 3).

Value parameters

divisor

the root degree (e.g., 2 for square root, 3 for cube root)

p

the prototype number containing initial value and metadata

r

the rational factor determining the type of root operation

v

the value to be simplified

Attributes

Returns

an optional ProtoNumber containing the simplified root representation, or the original input if simplification is not applicable

Inherited from:
InversePower
override def toString: String

Converts the object into its string representation.

Converts the object into its string representation.

Attributes

Returns

a string representation of the object

Definition Classes
InversePower -> Any
Inherited from:
InversePower

Inherited and Abstract methods

def asRoot(value: Value): Option[String]

Converts the given value into its root representation if applicable.

Converts the given value into its root representation if applicable.

Value parameters

value

the Value object to be converted into its root representation.

Attributes

Returns

an optional String representing the root form of the value, or None if the conversion is not applicable.

Inherited from:
InversePower

Concrete fields

val n: Int

Inherited fields

lazy val isExact: Boolean

Determines whether the current scalar can be exactly converted to a PureNumber.

Determines whether the current scalar can be exactly converted to a PureNumber.

Attributes

Returns

true if the scalar represents an exact value; false otherwise.

Inherited from:
InversePower
val value: Double

A value which can be used to convert a value associated with this Factor to a different Factor.

A value which can be used to convert a value associated with this Factor to a different Factor.

Attributes

Inherited from:
InversePower