Class Naturals
- All Implemented Interfaces:
AbelianMonoid<Natural>, Magma<Natural>, Monoid<Natural>, Semiring<Natural>, InfiniteSet<Natural>, Set<Natural>
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 Summary
Modifier and TypeMethodDescriptionReturns the sum of two elements (additive notation).booleanTests whether this set contains the specified element.Returns a human-readable description of this set.static NaturalsReturns the singleton instance.booleanReturnstrueif this set is countable (i.e., its elements can be put in one-to-one correspondence with the natural numbers).booleanisEmpty()Returnstrueif this set contains no elements.booleanTests whether multiplication is commutative in this semiring.Returns the product of two elements.one()Returns the multiplicative identity (one element).Performs the binary operation on two elements.stream(int count) Returns a stream of the first n natural numbers.toString()zero()Returns the additive identity (zero element).Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface AbelianMonoid
identity, isCommutativeMethods inherited from interface Monoid
isAssociative
-
Method Details
-
getInstance
Returns the singleton instance.- Returns:
- the Naturals structure
-
operate
Description copied from interface:MagmaPerforms 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)
-
add
Description copied from interface:AbelianMonoidReturns the sum of two elements (additive notation).Delegates to
Magma.operate(Object, Object).- Specified by:
addin interfaceAbelianMonoid<Natural>- Parameters:
a- the first addendb- the second addend- Returns:
- a + b
-
zero
Description copied from interface:AbelianMonoidReturns the additive identity (zero element).Delegates to
AbelianMonoid.identity().- Specified by:
zeroin interfaceAbelianMonoid<Natural>- Returns:
- the zero element
-
multiply
Description copied from interface:SemiringReturns the product of two elements.Multiplication must be associative and distribute over addition.
-
one
-
isMultiplicationCommutative
public boolean isMultiplicationCommutative()Description copied from interface:SemiringTests whether multiplication is commutative in this semiring.- Specified by:
isMultiplicationCommutativein interfaceSemiring<Natural>- Returns:
trueif multiplication commutes
-
isCountable
public boolean isCountable()Description copied from interface:InfiniteSetReturnstrueif 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:
isCountablein interfaceInfiniteSet<Natural>- Returns:
trueif this set is countable
-
contains
Description copied from interface:SetTests whether this set contains the specified element.This is the fundamental operation of a set - membership testing.
-
isEmpty
public boolean isEmpty()Description copied from interface:SetReturnstrueif this set contains no elements.The empty set (∅) is a fundamental concept in set theory. It is the unique set containing no elements.
-
description
Description copied from interface:SetReturns a human-readable description of this set.Examples:
- "â„ (Real Numbers)"
- "ℤ/12ℤ (Integers modulo 12)"
- "{1, 2, 3, 4, 5}"
- Specified by:
descriptionin interfaceSet<Natural>- Returns:
- a description of this set
-
stream
-
toString
-