Successor

com.phasmidsoftware.number.top.Successor
case class Successor(natural: Natural) extends Natural

Represents the successor of a natural number in the Peano arithmetic system.

A Successor object encapsulates a natural number, providing various operations for arithmetic and representation. It extends the Natural trait and defines the following functionalities:

  • next: Returns the next natural number by creating a new Successor object.
  • add: Recursively adds another natural number to this natural number.
  • toString: Returns a Roman numeral representation of the natural number.

Value parameters

natural

A natural number representing the predecessor of this number.

Attributes

Constructor

Creates a Successor object with the given natural number.

Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait Natural
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def add(n: Natural): Natural

Adds the specified natural number to this natural number and returns the result.

Adds the specified natural number to this natural number and returns the result.

Value parameters

n

the natural number to add

Attributes

Returns

the result of adding the specified natural number to this one

def next: Natural

Computes the next natural number by returning the successor of the current natural number.

Computes the next natural number by returning the successor of the current natural number.

Attributes

Returns

the Successor of this natural number.

override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Any

Inherited methods

infix def multiply(n: Natural): Natural

Multiplies the current natural number by the given natural number.

Multiplies the current natural number by the given natural number.

This method performs multiplication using a tail-recursive helper function. It repeatedly adds the current number to an accumulator based on the value of the given n.

Value parameters

n

the natural number to multiply with the current number

Attributes

Returns

the result of the multiplication as a natural number

Inherited from:
Natural
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
infix def subtract(n: Natural): Option[Natural]

Subtracts the given natural number n from this natural number. The subtraction operation is defined for natural numbers (non-negative integers). If the result would be negative, the method returns None.

Subtracts the given natural number n from this natural number. The subtraction operation is defined for natural numbers (non-negative integers). If the result would be negative, the method returns None.

Value parameters

n

the natural number to subtract from this natural number

Attributes

Returns

an Option[Natural] containing the result of the subtraction if non-negative, otherwise None

Inherited from:
Natural