WholeNumber

com.phasmidsoftware.number.algebra.eager.WholeNumber
See theWholeNumber companion class
object WholeNumber

The WholeNumber companion object contains utility methods, predefined constants, and typeclass instances for working with WholeNumbers. WholeNumbers are represented using rational numbers and comply with the algebraic structure of a commutative group.

Attributes

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

Members list

Type members

Classlikes

Provides an implicit implementation of a commutative group for the WholeNumber type, supporting group operations such as identity, combination, and inversion.

Provides an implicit implementation of a commutative group for the WholeNumber type, supporting group operations such as identity, combination, and inversion.

This allows WholeNumber objects to adhere to the algebraic structure of a commutative group, where the combine operation is associative and commutative, an identity element exists, and each element has an additive inverse.

Attributes

Companion
trait
Supertypes
trait CommutativeRing[WholeNumber]
trait CommutativeRng[WholeNumber]
trait CommutativeRig[WholeNumber]
trait MultiplicativeCommutativeMonoid[WholeNumber]
trait CommutativeSemiring[WholeNumber]
trait MultiplicativeCommutativeSemigroup[WholeNumber]
trait Ring[WholeNumber]
trait Rng[WholeNumber]
trait AdditiveCommutativeGroup[WholeNumber]
trait AdditiveGroup[WholeNumber]
trait Rig[WholeNumber]
trait MultiplicativeMonoid[WholeNumber]
trait Semiring[WholeNumber]
trait MultiplicativeSemigroup[WholeNumber]
trait AdditiveCommutativeMonoid[WholeNumber]
trait AdditiveCommutativeSemigroup[WholeNumber]
trait AdditiveMonoid[WholeNumber]
trait AdditiveSemigroup[WholeNumber]
trait Serializable
class Object
trait Matchable
class Any
Show all
Self type
trait WholeNumberIsCommutativeRing extends CommutativeRing[WholeNumber]

Provides an implicit implementation of a commutative group for the WholeNumber type, supporting group operations such as identity, combination, and inversion.

Provides an implicit implementation of a commutative group for the WholeNumber type, supporting group operations such as identity, combination, and inversion.

This allows WholeNumber objects to adhere to the algebraic structure of a commutative group, where the combine operation is associative and commutative, an identity element exists, and each element has an additive inverse.

Attributes

Companion
object
Supertypes
trait CommutativeRing[WholeNumber]
trait CommutativeRng[WholeNumber]
trait CommutativeRig[WholeNumber]
trait MultiplicativeCommutativeMonoid[WholeNumber]
trait CommutativeSemiring[WholeNumber]
trait MultiplicativeCommutativeSemigroup[WholeNumber]
trait Ring[WholeNumber]
trait Rng[WholeNumber]
trait AdditiveCommutativeGroup[WholeNumber]
trait AdditiveGroup[WholeNumber]
trait Rig[WholeNumber]
trait MultiplicativeMonoid[WholeNumber]
trait Semiring[WholeNumber]
trait MultiplicativeSemigroup[WholeNumber]
trait AdditiveCommutativeMonoid[WholeNumber]
trait AdditiveCommutativeSemigroup[WholeNumber]
trait AdditiveMonoid[WholeNumber]
trait AdditiveSemigroup[WholeNumber]
trait Serializable
class Object
trait Matchable
class Any
Show all
Known subtypes

Represents a given instance of the Convertible typeclass to transform a Real into a WholeNumber, provided the Real value is exact and can be represented as a whole number.

Represents a given instance of the Convertible typeclass to transform a Real into a WholeNumber, provided the Real value is exact and can be represented as a whole number.

The implementation leverages FP.recover to handle failures gracefully and will throw an AlgebraException if the provided Real cannot be converted into a WholeNumber.

The conversion is only possible if the Real value satisfies the following conditions:

  • It is marked as exact.
  • Its numerical value can be expressed as an integer.

Attributes

Returns

a WholeNumber instance representing the converted value.

Note

Throws an com.phasmidsoftware.number.algebra.util.AlgebraException if the input Real cannot be converted to a WholeNumber.

Supertypes
class Object
trait Matchable
class Any
Self type

Provides a Convertible implementation for converting instances of WholeNumber to WholeNumber.

Provides a Convertible implementation for converting instances of WholeNumber to WholeNumber.

This implementation allows a WholeNumber instance to be converted to another WholeNumber without applying any transformation, effectively serving as an identity conversion.

Value parameters

u

the source WholeNumber to be converted

witness

a WholeNumber instance that serves as a template or context for the conversion

Attributes

Returns

the same WholeNumber instance as passed in u

Note

This implementation adheres to the contract of the Convertible typeclass.

Supertypes
class Object
trait Matchable
class Any
Self type

Value members

Concrete methods

def apply(x: BigInt): WholeNumber

Constructs a new WholeNumber instance from a given BigInt value.

Constructs a new WholeNumber instance from a given BigInt value.

Value parameters

name

an optional name associated with the WholeNumber instance; defaults to None if not provided

x

the BigInt value to be wrapped as a WholeNumber

Attributes

Returns

a new instance of WholeNumber created using the provided BigInt value and optional name

Concrete fields

Represents the constant whole number value of -1.

Represents the constant whole number value of -1.

This is a lazily computed instance of the WholeNumber type, initialized with the value -1.

Attributes

Represents the whole number value 1 as an instance of WholeNumber.

Represents the whole number value 1 as an instance of WholeNumber.

This is a lazy value, ensuring that the object is not instantiated until it is accessed, and thereafter remains constant for the duration of the application's lifecycle.

Attributes

Represents the whole number two as a lazy value of type WholeNumber.

Represents the whole number two as a lazy value of type WholeNumber.

This is a predefined constant for convenient access to the numeric value 2 in the context of WholeNumber operations and conversions.

Attributes

Represents the WholeNumber constant for the value zero (0).

Represents the WholeNumber constant for the value zero (0).

This is a lazily evaluated instance of WholeNumber initialized with the value 0.

Attributes

Givens

Givens

Represents a given instance of the Convertible typeclass to transform a Real into a WholeNumber, provided the Real value is exact and can be represented as a whole number.

Represents a given instance of the Convertible typeclass to transform a Real into a WholeNumber, provided the Real value is exact and can be represented as a whole number.

The implementation leverages FP.recover to handle failures gracefully and will throw an AlgebraException if the provided Real cannot be converted into a WholeNumber.

The conversion is only possible if the Real value satisfies the following conditions:

  • It is marked as exact.
  • Its numerical value can be expressed as an integer.

Attributes

Returns

a WholeNumber instance representing the converted value.

Note

Throws an com.phasmidsoftware.number.algebra.util.AlgebraException if the input Real cannot be converted to a WholeNumber.

Provides a Convertible implementation for converting instances of WholeNumber to WholeNumber.

Provides a Convertible implementation for converting instances of WholeNumber to WholeNumber.

This implementation allows a WholeNumber instance to be converted to another WholeNumber without applying any transformation, effectively serving as an identity conversion.

Value parameters

u

the source WholeNumber to be converted

witness

a WholeNumber instance that serves as a template or context for the conversion

Attributes

Returns

the same WholeNumber instance as passed in u

Note

This implementation adheres to the contract of the Convertible typeclass.

Provides an implementation of the DyadicOperator trait for the WholeNumber type.

Provides an implementation of the DyadicOperator trait for the WholeNumber type.

This given instance enables the application of binary operations on WholeNumber instances using a provided function f. The function encapsulates the operation logic and handles the operand types and potential failures via Try.

Attributes

Returns

A DyadicOperator instance for the WholeNumber type, facilitating binary operations with safety provided by Try.

Provides an implementation of the Eq type class for the WholeNumber type.

Provides an implementation of the Eq type class for the WholeNumber type.

This given instance defines equality for WholeNumber values. It uses the eqv method defined on WholeNumber, falling back to false if the equality operation is not defined.

Attributes

Returns

an Eq instance for comparing WholeNumber values for equality

Provides an instance of FuzzyEq for the WholeNumber type.

Provides an instance of FuzzyEq for the WholeNumber type.

This instance defines the fuzzy equality behavior for WholeNumber values, where two WholeNumber instances are considered equal if they are exactly the same, regardless of the probability p.

Attributes

Returns

An instance of FuzzyEq for WholeNumber that implements strict equality.

Implicits

Implicits

implicit def convIntWholeNumber(x: Int): WholeNumber

Converts an Int to a WholeNumber implicitly.

Converts an Int to a WholeNumber implicitly.

This implicit conversion allows an Int to be seamlessly treated as a WholeNumber.

Value parameters

x

the integer value to be converted to a WholeNumber

Attributes

Returns

the converted WholeNumber instance

implicit val showWholeNumber: Show[WholeNumber]

Provides an implicit Show instance for the WholeNumber class, enabling conversion of an WholeNumber instance to a string representation using its render method.

Provides an implicit Show instance for the WholeNumber class, enabling conversion of an WholeNumber instance to a string representation using its render method.

This allows the WholeNumber class to integrate seamlessly with libraries or frameworks requiring a Show typeclass instance for displaying or logging purposes.

Attributes