Zero
Zero represents the natural number zero in the Peano arithmetic system.
It is the base case of the natural numbers and does not have a predecessor. The Zero object extends the Natural trait and provides implementations for its methods.
next: Returns the successor of zero, which is the natural number one.add: Returns the input natural number as the result of adding zero to it.toString: Overrides the string representation to an empty string.
Attributes
Members list
Type members
Inherited types
The names of the product elements.
The names of the product elements.
Attributes
- Inherited from:
- Singleton
Attributes
- Inherited from:
- Singleton
The mirrored *-type.
The mirrored *-type.
Attributes
- Inherited from:
- Singleton
Attributes
- Inherited from:
- Singleton
Inherited and Abstract types
The name of the type.
The name of the type.
Attributes
- Inherited from:
- Mirror
Value members
Concrete methods
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
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
Successorof this natural number.
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
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
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
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
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
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, otherwiseNone - Inherited from:
- Natural