SquareRoot

com.phasmidsoftware.number.core.inner.SquareRoot
case object SquareRoot extends NthRoot

This object represents the square root factor.

Attributes

Graph
Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
class NthRoot
trait InversePower
trait Factor
class Object
trait Matchable
class Any
Show all
Self type
SquareRoot.type

Members list

Type members

Classlikes

implicit class IntToImaginary(x: Int)

Provides an implicit conversion from an Int to an imaginary number representation.

Provides an implicit conversion from an Int to an imaginary number representation.

This class allows integers to be interpreted as imaginary numbers by appending .i to an integer. The imaginary number is constructed using the square of the integer negated, combined with the square root notation.

Value parameters

x

the integer to be converted into an imaginary number

Attributes

Supertypes
class Object
trait Matchable
class Any

Inherited types

type MirroredElemLabels = EmptyTuple

The names of the product elements.

The names of the product elements.

Attributes

Inherited from:
Singleton
type MirroredElemTypes = EmptyTuple

Attributes

Inherited from:
Singleton
type MirroredMonoType = this.type

The mirrored *-type.

The mirrored *-type.

Attributes

Inherited from:
Singleton
type MirroredType = this.type

Attributes

Inherited from:
Singleton

Inherited and Abstract types

type MirroredLabel <: String

The name of the type.

The name of the type.

Attributes

Inherited from:
Mirror

Value members

Concrete methods

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

Attempts to add two Value instances under the influence of a given Factor.

Attempts to add two Value instances under the influence of a given Factor.

The method verifies whether the operation can be applied with the given factor (e.g., a square root) and performs rational arithmetic to compute the result. The operation ensures that the values can be combined via integer arithmetic after factoring out common divisors and applies root simplifications where necessary.

Value parameters

f

the factor defining the context for the addition (e.g., square root)

negative

true if the y value should be considered as being subtracted from the x value. NOTE this is not the same thing as the y value being negative, which would imply an imaginary number.

x

the first value to be added

y

the second value to be added

Attributes

Returns

an optional ProtoNumber that contains the resultant Value, its factor, and optional metadata; None if the operation cannot be performed

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

Constructs an optional string representation of the current root object concatenated with the string representation of the specified value.

Constructs an optional string representation of the current root object concatenated with the string representation of the specified value.

Value parameters

value

the value to be represented as part of the root string.

Attributes

Returns

an Option containing the concatenated string representation of the root and the value, or None if the string construction is unsuccessful.

override def doRaiseByPureNumber(x: Value, y: Value): Option[ProtoNumber]

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

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

TODO move this up into NthRoot.

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

Definition Classes
override def render(x: String): String

Renders the input string with a square root symbol.

Renders the input string with a square root symbol.

Value parameters

x

the input string to be rendered

Attributes

Returns

a string prefixed with the square root symbol

Definition Classes
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 methods

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

Inherited from:
NthRoot
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
Inherited from:
NthRoot
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
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.

Inherited from:
NthRoot
def fromProduct(p: Product): MirroredMonoType

Creates a new instance of type T with elements taken from product p.

Creates a new instance of type T with elements taken from product p.

Attributes

Inherited from:
Singleton

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 from:
NthRoot
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 productElementNames: Iterator[String]

An iterator over the names of all the elements of this product.

An iterator over the names of all the elements of this product.

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

An iterator over all the elements of this product.

An iterator over all the elements of this product.

Attributes

Returns

in the default implementation, an Iterator[Any]

Inherited from:
Product
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 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

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 n: Int

Attributes

Inherited from:
NthRoot
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

Implicits

Implicits

final implicit def IntToImaginary(x: Int): IntToImaginary

Provides an implicit conversion from an Int to an imaginary number representation.

Provides an implicit conversion from an Int to an imaginary number representation.

This class allows integers to be interpreted as imaginary numbers by appending .i to an integer. The imaginary number is constructed using the square of the integer negated, combined with the square root notation.

Value parameters

x

the integer to be converted into an imaginary number

Attributes