Orbital library

orbital.math
Interface Rational

All Superinterfaces:
Arithmetic, java.lang.Comparable, Complex, Normed, Real, Scalar
All Known Subinterfaces:
Integer

public interface Rational
extends Real

Representation of a rational number a⁄s ∈ Q.

Q := Quot(Z) := (Z∖{0})-1Z = {a⁄s ¦ a,s∈Z ∧ s≠0} is the field of fractions of the ring Z.

A rational number a⁄s ∈ Q with numerator a and denominator s is usually written as

  a
  s
 

Rational numbers are a subfield of R, and the smallest subfield of all fields of characteristic 0.

Author:
André Platzer
See Also:
ValueFactory.rational(Integer, Integer), ValueFactory.rational(int, int), ValueFactory.rational(Integer), ValueFactory.rational(int), Fraction, "N. Bourbaki, Algebra I.9.4: The field of rational numbers.", "N. Bourbaki, Algebra I.2.4: Monoid of fractions of a commutative monoid."
Structure:
synonym for Fraction
Stereotype:
data-type

Field Summary
static Predicate hasType
          Checks whether the given number is in the set of rationals and not a subset.
static Predicate isa
          Checks whether the given number is in the set of rationals.
 
Fields inherited from interface orbital.math.Arithmetic
numerical
 
Method Summary
 Rational add(Rational b)
          adds two rationals returning a third as a result
 Integer denominator()
          Returns the denominator component.
 Rational divide(Rational b)
          divides two rationals returning a third as a result
 Rational multiply(Rational b)
          multiplies two rationals returning a third as a result
 Integer numerator()
          Returns the numerator component.
 Rational power(Integer b)
          Return ab.
 Real power(Rational b)
          Return ab.
 Rational representative()
          Get the "canonical" representative (cancelled out and normalized) of the equivalence class of rationals equal to this.
 Rational subtract(Rational b)
          subtracts two rationals returning a third as a result
 
Methods inherited from interface orbital.math.Real
add, compareTo, divide, doubleValue, floatValue, multiply, power, subtract
 
Methods inherited from interface orbital.math.Complex
add, arg, conjugate, divide, equals, hashCode, im, isInfinite, isNaN, multiply, norm, power, re, subtract
 
Methods inherited from interface orbital.math.Arithmetic
add, divide, equals, inverse, isOne, isZero, minus, multiply, one, power, scale, subtract, toString, valueFactory, zero
 

Field Detail

isa

static final Predicate isa
Checks whether the given number is in the set of rationals. return whether v is rational or an integer.


hasType

static final Predicate hasType
Checks whether the given number is in the set of rationals and not a subset. return whether v∈Q is a rational and not an integer.

Method Detail

numerator

Integer numerator()
Returns the numerator component.

Returns:
a of this rational number a⁄s.

denominator

Integer denominator()
Returns the denominator component.

Returns:
s of this rational number a⁄s.

representative

Rational representative()
Get the "canonical" representative (cancelled out and normalized) of the equivalence class of rationals equal to this.

Returns:
a cancelled and normalized rational.
Postconditions:
RES.equals(this) && MathUtilities.gcd(RES.numerator(), RES.denominator()) == 1 && RES.denominator() > 0.
Note:
S' = Z∖{0} is the set of allowed denominators.

add

Rational add(Rational b)
adds two rationals returning a third as a result


subtract

Rational subtract(Rational b)
subtracts two rationals returning a third as a result


multiply

Rational multiply(Rational b)
multiplies two rationals returning a third as a result


divide

Rational divide(Rational b)
divides two rationals returning a third as a result


power

Rational power(Integer b)
Return ab.

Postconditions:
(b != 0 → RES instanceof Rational)

power

Real power(Rational b)
Return ab.


Orbital library
1.3.0: 11 Apr 2009

Copyright © 1996-2009 André Platzer
All Rights Reserved.