RationalNumber

com.phasmidsoftware.number.algebra.eager.RationalNumber
See theRationalNumber companion class

Represents a rational number with basic arithmetic operations and field properties. This class provides methods and implicit instances for managing rational numbers and their integration with mathematical abstractions such as the Field typeclass.

Attributes

Companion
class
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Type members

Classlikes

Provides a given instance of the Convertible typeclass for RationalNumber to RationalNumber.

Provides a given instance of the Convertible typeclass for RationalNumber to RationalNumber.

This instance defines a no-op conversion, where a RationalNumber is returned as-is when converted to another RationalNumber. It enables compatibility with the Convertible typeclass interface, but does not alter or transform the provided RationalNumber.

Value parameters

u

the RationalNumber instance to be returned

witness

an optional RationalNumber instance provided as a template (unused in this implementation)

Attributes

Returns

the input RationalNumber returned directly without modification

Supertypes
class Object
trait Matchable
class Any
Self type

Provides an instance of the Convertible typeclass for transforming an instance of Real into a RationalNumber.

Provides an instance of the Convertible typeclass for transforming an instance of Real into a RationalNumber.

This conversion attempts to recover a RationalNumber representation from a given Real object. If the Real instance cannot be converted into a RationalNumber, an AlgebraException is thrown describing the failure.

Attributes

Returns

a RationalNumber instance that is equivalent to the provided Real, if the conversion is successful

Note
Supertypes
class Object
trait Matchable
class Any
Self type

Provides a given instance of the Convertible type class to enable the conversion of a WholeNumber into a RationalNumber.

Provides a given instance of the Convertible type class to enable the conversion of a WholeNumber into a RationalNumber.

This implementation defines the convert method, which delegates the conversion of a WholeNumber to its corresponding RationalNumber representation by invoking the toRationalNumber method on the WholeNumber instance.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
object rationalNumberIsField extends Field[RationalNumber]

Provides an implicit implementation of the Field type class for the RationalNumber type.

Provides an implicit implementation of the Field type class for the RationalNumber type.

This object defines the standard operations required for RationalNumber to function as a field, including addition, multiplication, division, and their respective identity and inverse operations. By extending the Field type class, it ensures compliance with field axioms.

Attributes

Supertypes
trait Field[RationalNumber]
trait CommutativeSemifield[RationalNumber]
trait MultiplicativeCommutativeGroup[RationalNumber]
trait DivisionRing[RationalNumber]
trait Semifield[RationalNumber]
trait MultiplicativeGroup[RationalNumber]
trait EuclideanRing[RationalNumber]
trait GCDRing[RationalNumber]
trait CommutativeRing[RationalNumber]
trait CommutativeRng[RationalNumber]
trait CommutativeRig[RationalNumber]
trait MultiplicativeCommutativeMonoid[RationalNumber]
trait CommutativeSemiring[RationalNumber]
trait MultiplicativeCommutativeSemigroup[RationalNumber]
trait Ring[RationalNumber]
trait Rng[RationalNumber]
trait AdditiveCommutativeGroup[RationalNumber]
trait AdditiveGroup[RationalNumber]
trait Rig[RationalNumber]
trait MultiplicativeMonoid[RationalNumber]
trait Semiring[RationalNumber]
trait MultiplicativeSemigroup[RationalNumber]
trait AdditiveCommutativeMonoid[RationalNumber]
trait AdditiveCommutativeSemigroup[RationalNumber]
trait AdditiveMonoid[RationalNumber]
trait AdditiveSemigroup[RationalNumber]
trait Serializable
class Object
trait Matchable
class Any
Show all
Self type

Value members

Concrete methods

Converts a given Rational to a RationalNumber.

Converts a given Rational to a RationalNumber.

Value parameters

r

the Rational value to be converted

Attributes

Returns

a new RationalNumber instance representing the given Rational

def apply(x: Long, y: Long): RationalNumber

Creates a RationalNumber instance from two provided Long values, representing the numerator and denominator of a rational number.

Creates a RationalNumber instance from two provided Long values, representing the numerator and denominator of a rational number.

Value parameters

x

the numerator of the rational number

y

the denominator of the rational number

Attributes

Returns

a RationalNumber instance constructed from the given numerator and denominator

def apply(x: BigInt, y: BigInt): RationalNumber

Constructs a RationalNumber instance from the given numerator and denominator.

Constructs a RationalNumber instance from the given numerator and denominator.

Value parameters

x

The numerator as a BigInt.

y

The denominator as a BigInt.

Attributes

Returns

A RationalNumber representing the fraction x / y.

def apply(x: Long): RationalNumber

Creates a rational number representation from a given integer value.

Creates a rational number representation from a given integer value.

Value parameters

x

the integer value to be converted into a rational number

Attributes

Returns

a RationalNumber representing the input integer

def parse(w: String): Option[RationalNumber]

Parses a string representation of a rational number and converts it into an Option[RationalNumber].

Parses a string representation of a rational number and converts it into an Option[RationalNumber].

Value parameters

w

the string representation of the rational number to be parsed

Attributes

Returns

an Option[RationalNumber] containing the parsed rational number if successful, or None if parsing fails

Converts a given Rational value into a RationalNumber representing its percentage equivalent.

Converts a given Rational value into a RationalNumber representing its percentage equivalent.

Value parameters

r

the Rational value expressed as a percentage, e.g., 50 for 50%.

Attributes

Returns

a RationalNumber instance representing the percentage value of the given Rational

Concrete fields

Represents a predefined constant value of one-half as a RationalNumber. This is a convenience representation of the fraction 1/2 in the system of rational numbers.

Represents a predefined constant value of one-half as a RationalNumber. This is a convenience representation of the fraction 1/2 in the system of rational numbers.

Attributes

Represents a rational number with an infinite value.

Represents a rational number with an infinite value.

This value is constructed from the infinity representation of the Rational type.

Attributes

Represents the rational number -1 as a predefined constant. This is an instance of the RationalNumber class initialized with the negative one value from the Rational type.

Represents the rational number -1 as a predefined constant. This is an instance of the RationalNumber class initialized with the negative one value from the Rational type.

Attributes

Represents the rational number one as an instance of RationalNumber.

Represents the rational number one as an instance of RationalNumber.

Attributes

Represents the rational number zero. This is a predefined constant in the RationalNumber class.

Represents the rational number zero. This is a predefined constant in the RationalNumber class.

Attributes

Givens

Givens

Provides a given instance of the Convertible typeclass for RationalNumber to RationalNumber.

Provides a given instance of the Convertible typeclass for RationalNumber to RationalNumber.

This instance defines a no-op conversion, where a RationalNumber is returned as-is when converted to another RationalNumber. It enables compatibility with the Convertible typeclass interface, but does not alter or transform the provided RationalNumber.

Value parameters

u

the RationalNumber instance to be returned

witness

an optional RationalNumber instance provided as a template (unused in this implementation)

Attributes

Returns

the input RationalNumber returned directly without modification

Provides an instance of the Convertible typeclass for transforming an instance of Real into a RationalNumber.

Provides an instance of the Convertible typeclass for transforming an instance of Real into a RationalNumber.

This conversion attempts to recover a RationalNumber representation from a given Real object. If the Real instance cannot be converted into a RationalNumber, an AlgebraException is thrown describing the failure.

Attributes

Returns

a RationalNumber instance that is equivalent to the provided Real, if the conversion is successful

Note

Provides a given instance of the Convertible type class to enable the conversion of a WholeNumber into a RationalNumber.

Provides a given instance of the Convertible type class to enable the conversion of a WholeNumber into a RationalNumber.

This implementation defines the convert method, which delegates the conversion of a WholeNumber to its corresponding RationalNumber representation by invoking the toRationalNumber method on the WholeNumber instance.

Attributes

A given instance of DyadicOperator for RationalNumber that provides an implementation of the op method, enabling the execution of a dyadic operation on two rational numbers. The operation is defined by a user-supplied function f, which specifies how the operands should be combined and produces a result wrapped in a Try.

A given instance of DyadicOperator for RationalNumber that provides an implementation of the op method, enabling the execution of a dyadic operation on two rational numbers. The operation is defined by a user-supplied function f, which specifies how the operands should be combined and produces a result wrapped in a Try.

Attributes

Returns

A Try[Z] representing the result of the operation f applied to the operands, or an exception if the operation fails.

Provides an instance of Eq[RationalNumber], enabling equality comparison between two RationalNumber instances.

Provides an instance of Eq[RationalNumber], enabling equality comparison between two RationalNumber instances.

Attributes

Returns

an Eq[RationalNumber] instance that defines equality by delegating to the eqv method of RationalNumber, or returning false if undefined

Provides an instance of the FuzzyEq type class for RationalNumber.

Provides an instance of the FuzzyEq type class for RationalNumber.

This instance defines the fuzzy equality for RationalNumber using the == operator to compare two RationalNumber instances based on their exact equality.

Attributes

Returns

a FuzzyEq[RationalNumber] instance defining the fuzzy equality for RationalNumber

Implicits

Implicits

Implicitly converts a Rational instance into a RationalNumber.

Implicitly converts a Rational instance into a RationalNumber.

Value parameters

x

the Rational value to be converted

Attributes

Returns

a RationalNumber instance representing the given Rational

LatexRenderer for Rational numbers.

LatexRenderer for Rational numbers.

Renders as:

  • Integer if denominator is 1
  • Fraction otherwise using \frac{numerator}{denominator}
  • Handles negative values appropriately

Attributes

LatexRenderer for RationalNumber.

LatexRenderer for RationalNumber.

Delegates to the Rational renderer.

Attributes

implicit val showRationalNumber: Show[RationalNumber]

Provides an implicit Show instance for the RationalNumber class. This instance defines how a RationalNumber is transformed into a String representation by using its render method.

Provides an implicit Show instance for the RationalNumber class. This instance defines how a RationalNumber is transformed into a String representation by using its render method.

Attributes