Class Rationals
- All Implemented Interfaces:
AbelianGroup<Rational>, AbelianMonoid<Rational>, Group<Rational>, Magma<Rational>, Monoid<Rational>, Field<Rational>, Ring<Rational>, Semiring<Rational>, InfiniteSet<Rational>, Set<Rational>
This class represents the structure of rational numbers,
implementing Field because ℚ forms a field under addition and
multiplication.
Rational numbers are an infinite, countable set.
- Since:
- 1.0
- Author:
- Gemini AI (Google DeepMind)
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionReturns the sum of two elements (additive notation).intReturns the characteristic of this field.booleanTests whether this set contains the specified element.Returns a human-readable description of this set.Returns the quotient of two elements (division).static RationalsReturns the singleton instance.Returns the multiplicative inverse of a non-zero element.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.booleanFields always have commutative multiplication.Returns the product of two elements.Returns the additive inverse (negation) of an element.one()Returns the multiplicative identity (one element).Performs the binary operation on two elements.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 AbelianGroup
isCommutative, subtractMethods inherited from interface AbelianMonoid
identity, isCommutativeMethods inherited from interface Monoid
isAssociative
-
Method Details
-
getInstance
Returns the singleton instance.- Returns:
- the Rationals 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<Rational>- 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<Rational>- Returns:
- the zero element
-
negate
Description copied from interface:AbelianGroupReturns the additive inverse (negation) of an element.Satisfies: a + (-a) = (-a) + a = 0
- Specified by:
negatein interfaceAbelianGroup<Rational>- Parameters:
element- the element to negate- Returns:
- -element
- See Also:
-
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:FieldFields always have commutative multiplication.- Specified by:
isMultiplicationCommutativein interfaceField<Rational>- Specified by:
isMultiplicationCommutativein interfaceSemiring<Rational>- Returns:
- always
true
-
inverse
Description copied from interface:FieldReturns the multiplicative inverse of a non-zero element.For element a ≠0, returns a⻹ such that: a × a⻹ = a⻹ × a = 1
Examples:
- In ℚ: inverse(2/3) = 3/2
- In â„Â: inverse(5.0) = 0.2
- In â„‚: inverse(3+4i) = (3-4i)/25
-
divide
Description copied from interface:FieldReturns the quotient of two elements (division).Defined as: a ÷ b = a × b⻹
-
characteristic
public int characteristic()Description copied from interface:FieldReturns the characteristic of this field.The characteristic is the smallest positive integer n such that:
1 + 1 + ... + 1 (n times) = 0
If no such n exists, the characteristic is 0.Examples:
- char(ℚ) = char(â„Â) = char(â„‚) = 0
- char(ðÂâ€Â½Ã¢â€šÅ¡) = p (for prime p)
- Specified by:
characteristicin interfaceField<Rational>- Returns:
- the characteristic (0 for infinite fields, p for finite fields)
-
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<Rational>- 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<Rational>- Returns:
- a description of this set
-
toString
-