Class NaturalInterval

java.lang.Object
org.episteme.core.mathematics.algebra.intervals.NaturalInterval

public final class NaturalInterval extends Object
Factory and convenience class for creating intervals over Natural numbers.

Natural numbers are non-negative integers: 0, 1, 2, 3, ... Unlike real intervals, Natural intervals are discrete (countable), enabling:

  • Iteration over all elements
  • Exact element count
  • Successor/predecessor operations

* @author Silvere Martin-Michiellot
Since:
1.0
Author:
Gemini AI (Google DeepMind)
  • Method Details

    • closed

      public static RingIntervalND<Natural> closed(Natural min, Natural max)
      Creates a closed interval [min, max] over Natural numbers.
      Parameters:
      min - the minimum value (inclusive)
      max - the maximum value (inclusive)
      Returns:
      a closed interval containing all naturals from min to max
      Throws:
      IllegalArgumentException - if min > max
    • closed

      public static RingIntervalND<Natural> closed(long min, long max)
      Creates a closed interval [min, max] from long values.
    • closedOpen

      public static RingIntervalND<Natural> closedOpen(Natural min, Natural max)
      Creates a half-open interval [min, max) over Natural numbers.
      Parameters:
      min - the minimum value (inclusive)
      max - the maximum value (exclusive)
      Returns:
      a half-open interval
    • closedOpen

      public static RingIntervalND<Natural> closedOpen(long min, long max)
      Creates a half-open interval [min, max) from long values.
    • open

      public static RingIntervalND<Natural> open(Natural min, Natural max)
      Creates an open interval (min, max) over Natural numbers.
    • open

      public static RingIntervalND<Natural> open(long min, long max)
      Creates an open interval (min, max) from long values.
    • iterator

      public static Iterator<Natural> iterator(Interval<Natural> interval)
      Returns an iterator over all Natural numbers in the interval.

      For closed intervals [a, b], iterates a, a+1, ..., b. For half-open [a, b), iterates a, a+1, ..., b-1.

      Parameters:
      interval - the interval to iterate
      Returns:
      an iterator over the Natural numbers in the interval
    • stream

      public static Stream<Natural> stream(Interval<Natural> interval)
      Returns a stream of all Natural numbers in the interval.
      Parameters:
      interval - the interval to stream
      Returns:
      a Stream of Natural numbers
    • size

      public static long size(Interval<Natural> interval)
      Returns the number of Natural numbers in the interval.
      Parameters:
      interval - the interval
      Returns:
      the count of elements (cardinality)
    • isEmpty

      public static boolean isEmpty(Interval<Natural> interval)
      Returns whether the interval is empty.
      Parameters:
      interval - the interval to check
      Returns:
      true if the interval contains no Natural numbers
    • singleton

      public static RingIntervalND<Natural> singleton(Natural value)
      Creates an interval containing a single Natural number.
      Parameters:
      value - the singleton value
      Returns:
      a closed interval [value, value]
    • singleton

      public static RingIntervalND<Natural> singleton(long value)
      Creates an interval containing a single Natural number from a long.