Class Naturals

java.lang.Object
org.episteme.core.mathematics.sets.Naturals
All Implemented Interfaces:
AbelianMonoid<Natural>, Magma<Natural>, Monoid<Natural>, Semiring<Natural>, InfiniteSet<Natural>, Set<Natural>

public final class Naturals extends Object implements Semiring<Natural>, InfiniteSet<Natural>
The structure of natural numbers (â„• = {0, 1, 2, 3, ...}).

This class represents the structure of natural numbers, not individual elements. It implements Semiring because â„• forms a commutative semiring with addition and multiplication, but lacks additive inverses (so it's not a Ring).

Natural numbers are an infinite, countable set.

Usage

Naturals structure = Naturals.getInstance();
Natural five = Natural.of(5);
Natural three = Natural.of(3);

// Use structure for operations
Natural eight = structure.add(five, three);
Natural fifteen = structure.multiply(five, three);

// Query structure properties
Natural zero = structure.zero(); // 0
Natural one = structure.one(); // 1
boolean contains = structure.contains(five); // true
Since:
1.0
Author:
Gemini AI (Google DeepMind)
See Also:
  • Method Details

    • getInstance

      public static Naturals getInstance()
      Returns the singleton instance.
      Returns:
      the Naturals structure
    • operate

      public Natural operate(Natural a, Natural b)
      Description copied from interface: Magma
      Performs the binary operation on two elements.

      This is the fundamental operation of a magma. The result must be an element of this magma (closure property).

      Properties: None required (not necessarily associative or commutative)

      Specified by:
      operate in interface Magma<Natural>
      Parameters:
      a - the first operand
      b - the second operand
      Returns:
      the result of a ∗ b
      See Also:
    • add

      public Natural add(Natural a, Natural b)
      Description copied from interface: AbelianMonoid
      Returns the sum of two elements (additive notation).

      Delegates to Magma.operate(Object, Object).

      Specified by:
      add in interface AbelianMonoid<Natural>
      Parameters:
      a - the first addend
      b - the second addend
      Returns:
      a + b
    • zero

      public Natural zero()
      Description copied from interface: AbelianMonoid
      Returns the additive identity (zero element).

      Delegates to AbelianMonoid.identity().

      Specified by:
      zero in interface AbelianMonoid<Natural>
      Returns:
      the zero element
    • multiply

      public Natural multiply(Natural a, Natural b)
      Description copied from interface: Semiring
      Returns the product of two elements.

      Multiplication must be associative and distribute over addition.

      Specified by:
      multiply in interface Semiring<Natural>
      Parameters:
      a - the first factor
      b - the second factor
      Returns:
      a × b
    • one

      public Natural one()
      Description copied from interface: Semiring
      Returns the multiplicative identity (one element).

      Satisfies: 1 × a = a × 1 = a for all elements a.

      Specified by:
      one in interface Semiring<Natural>
      Returns:
      the multiplicative identity
    • isMultiplicationCommutative

      public boolean isMultiplicationCommutative()
      Description copied from interface: Semiring
      Tests whether multiplication is commutative in this semiring.
      Specified by:
      isMultiplicationCommutative in interface Semiring<Natural>
      Returns:
      true if multiplication commutes
    • isCountable

      public boolean isCountable()
      Description copied from interface: InfiniteSet
      Returns true if this set is countable (i.e., its elements can be put in one-to-one correspondence with the natural numbers).

      Examples:

      • Countable: â„• (Natural numbers), ℤ (Integers), ℚ (Rational numbers)
      • Uncountable: ℝ (Real numbers), â„‚ (Complex numbers)

      Specified by:
      isCountable in interface InfiniteSet<Natural>
      Returns:
      true if this set is countable
    • contains

      public boolean contains(Natural element)
      Description copied from interface: Set
      Tests whether this set contains the specified element.

      This is the fundamental operation of a set - membership testing.

      Specified by:
      contains in interface Set<Natural>
      Parameters:
      element - the element to test for membership
      Returns:
      true if this set contains the element, false otherwise
      See Also:
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: Set
      Returns true if this set contains no elements.

      The empty set (∅) is a fundamental concept in set theory. It is the unique set containing no elements.

      Specified by:
      isEmpty in interface Set<Natural>
      Returns:
      true if this set is empty
    • description

      public String description()
      Description copied from interface: Set
      Returns a human-readable description of this set.

      Examples:

      • "ℝ (Real Numbers)"
      • "ℤ/12ℤ (Integers modulo 12)"
      • "{1, 2, 3, 4, 5}"

      Specified by:
      description in interface Set<Natural>
      Returns:
      a description of this set
    • stream

      public Stream<Natural> stream(int count)
      Returns a stream of the first n natural numbers.

      Since â„• is infinite, we provide a way to get a finite stream.

      Parameters:
      count - number of elements
      Returns:
      stream of 0, 1, 2, ..., count-1
    • toString

      public String toString()
      Overrides:
      toString in class Object