Orbital library

orbital.math
Interface Arithmetic

All Superinterfaces:
Normed
All Known Subinterfaces:
BinaryFunction, BinaryFunction.Composite, Complex, Euclidean, Fraction, Function, Function.Composite, Integer, MathFunctor, MathFunctor.Composite, Matrix, Polynomial, Quotient, Rational, Real, Scalar, Symbol, Tensor, UnivariatePolynomial, Vector

public interface Arithmetic
extends Normed

Arithmetic is implemented by all arithmetic objects that behave like algebraic numbers in terms of their compositional laws.

Such an arithmetic object should return objects of appropriate type as resulting values.


Operations on arithmetic objects for groups, rings, fields, R-modules, R-algebras, etc.
law of composition + (addition)
add +:M×M→M; (a,b)↦a+b for magmas
minus −:M→M; a↦ −a for groups
subtract -:M×M→M; (a,b)↦a-b = a+(−b) for groups
law ⋅ (multiplication)
multiply ⋅:M×M→M; (a,b)↦a⋅b=a b law of composition for rings
inverse -1:M→M; (a,b)↦a-1 for fields
divide ∕:M×M→M; (a,b)↦a∕b = a⋅b-1 for fields
scale ·:R×M→M; (α,x)↦α·x law of action for R-modules
multiply ·:M×N→P; (a,b)↦a∙b=a·b inner product for tensors
extended law ^ (power)
power ^:M×M→M; (a,b)↦a^b = ab for rings,
requires ㏒ and ea in general case,
Will often work only for b∈Z

Note: Arithmetic objects may support composition with arithmetic objects of various types other than those in M as well. For simplicity these more general laws with a signature of M1×M2→M0 are omitted in the table above. Since they are indeed very useful they can nevertheless be implemented. Vectors for example can be multiplied with a scalar as well as a matrix or a vector resulting in different objects.

Also see the complete description of algebraic structures related to the interface Arithmetic.


An arithmetic object that supports an order should implement Comparable as well. Of course, a norm imposes a primitive order ≤ ⊆ M×M by x≤y :⇔ d(x,a)≤d(y,a), for any center a∈M. But this will most likely differ from the natural ordering on M which should be implemented via Comparable. By the way, Operations can be very useful to implement Arithmetic objects.

Arithmetic objects provides a strong type system which can be either dynamic or static. Operations generally depend polymorphically on the types of all arguments and thus may require dynamic dispatch with regard of the types of all arguments.

Author:
André Platzer
See Also:
Operations, Comparable, Algebraic Structures

Field Summary
static Predicate numerical
          Checks recursively whether the given arithmetic object is a numerical quantity, i.e., involves Real numerical approximations somewhere.
 
Method Summary
 Arithmetic add(Arithmetic b)
          Adds an arithmetic object to this returning the result.
 Arithmetic divide(Arithmetic b)
          Divides this by an arithmetic object returning the result.
 boolean equals(java.lang.Object o, Real tolerance)
          Compares two arithmetic objects for tolerant equality.
 Arithmetic inverse()
          Returns the multiplicative inverse of this arithmetic object.
 boolean isOne()
          Checks for identity to 1.
 boolean isZero()
          Checks for identity to 0.
 Arithmetic minus()
          Returns the additive inverse of this arithmetic object.
 Arithmetic multiply(Arithmetic b)
          Multiplies an arithmetic object to this returning the result.
 Arithmetic one()
          1.
 Arithmetic power(Arithmetic b)
          Returns the power of an arithmetic object to this base.
 Arithmetic scale(Arithmetic alpha)
          Multiplies a scalar with this arithmetic object returning the result.
 Arithmetic subtract(Arithmetic b)
          Subtracts an arithmetic object from this returning the result.
 java.lang.String toString()
          Returns a string representation of the Arithmetic object.
 ValueFactory valueFactory()
          Get the value factory producing this object
 Arithmetic zero()
          0.
 
Methods inherited from interface orbital.math.Normed
norm
 

Field Detail

numerical

static final Predicate numerical
Checks recursively whether the given arithmetic object is a numerical quantity, i.e., involves Real numerical approximations somewhere.

To be precise, for all numbers with machine precision can only be rational. Nevertheless, we model the difference between (machine precision) reals and explicit fractional numbers as Rationals with numerator and denominator.

return whether v∈R\Q is real, but not rational and thus irrational (for machine dimensions).

Method Detail

equals

boolean equals(java.lang.Object o,
               Real tolerance)
Compares two arithmetic objects for tolerant equality.

Parameters:
tolerance - specifies how much the arithmetic objects may differ to be treated as equal.
Returns:
Whether this ≈ o. More precisely whether d(this,o) := |this-o| ≤ tolerance.
Preconditions:
true
Postconditions:
RES ⇔ Metric.INDUCED.distance(this, o).compareTo(tolerance) ≤ 0
Attributes:
derived

isZero

boolean isZero()
               throws java.lang.UnsupportedOperationException
Checks for identity to 0.

Returns:
Whether this element equals the zero in the corresponding algebraic structure (if it is a unital magma or monoid).
Throws:
java.lang.UnsupportedOperationException - if this algebraic structure does not have a 0. This should not happen for monoids of +.
Postconditions:
RES == OLD(RES) && RES == equals(zero())

isOne

boolean isOne()
              throws java.lang.UnsupportedOperationException
Checks for identity to 1.

Returns:
Whether this element equals the 1 in the corresponding algebraic structure (if it is a true ring with 1, or ...).
Throws:
java.lang.UnsupportedOperationException - if this algebraic structure does not have a 1. This should not happen for monoids of ⋅.
Postconditions:
RES == OLD(RES) && RES == equals(one())

zero

Arithmetic zero()
                throws java.lang.UnsupportedOperationException
0.

0 = 0·x.

Returns:
the neutral element 0 for addition in this algebraic structure (if it is a unital magma or monoid).
Throws:
java.lang.UnsupportedOperationException - if this algebraic structure does not have a 0. This should not happen for monoids of +.
Postconditions:
RES == OLD(RES) ∧ this.getClass().isInstance(RES)
Attributes:
neutral element for Operations.plus

one

Arithmetic one()
               throws java.lang.UnsupportedOperationException
1.

1 = x0 at least for x≠0.

Returns:
the neutral element 1 for multiplication in this algebraic structure (if it is a true ring with 1, or ...).
Throws:
java.lang.UnsupportedOperationException - if this algebraic structure does not have a 1. This should not happen for monoids of ⋅.
Postconditions:
RES == OLD(RES) ∧ this.getClass().isInstance(RES)
Attributes:
neutral element for Operations.times

add

Arithmetic add(Arithmetic b)
               throws java.lang.ArithmeticException
Adds an arithmetic object to this returning the result.

Returns:
this+b.
Throws:
java.lang.ArithmeticException - if an exceptional arithmetic condition has occurred while performing the operation. This should not happen for magmas of +.
java.lang.IllegalArgumentException - if the argument type is illegal for this operation. Note: for single type handling it is also allowed to throw a ClassCastException, instead.

minus

Arithmetic minus()
                 throws java.lang.ArithmeticException
Returns the additive inverse of this arithmetic object.

Returns:
−this.
Throws:
java.lang.ArithmeticException - if an exceptional arithmetic condition has occurred while performing the operation. This should not happen for groups of +.

subtract

Arithmetic subtract(Arithmetic b)
                    throws java.lang.ArithmeticException
Subtracts an arithmetic object from this returning the result.

Returns:
this-b.
Throws:
java.lang.ArithmeticException - if an exceptional arithmetic condition has occurred while performing the operation. This should not happen for groups of +.
java.lang.IllegalArgumentException - if the argument type is illegal for this operation. Note: for single type handling it is also allowed to throw a ClassCastException, instead.

multiply

Arithmetic multiply(Arithmetic b)
                    throws java.lang.ArithmeticException,
                           java.lang.UnsupportedOperationException
Multiplies an arithmetic object to this returning the result.

Note that if type checking permits, this method may implement both, a⋅b and a·b depending upon context. However, this is not a requirement, since there are a few pathological cases with differing scalar and ring multiplication on the same set.

Returns:
this⋅b.
Throws:
java.lang.ArithmeticException - if an exceptional arithmetic condition has occurred while performing the operation. This should not happen for magmas of ⋅.
java.lang.IllegalArgumentException - if the argument type is illegal for this operation. Note: for single type handling it is also allowed to throw a ClassCastException, instead.
java.lang.UnsupportedOperationException - if this class does not support this operation, principially, regardless of the argument.
See Also:
scale(Arithmetic)

inverse

Arithmetic inverse()
                   throws java.lang.ArithmeticException,
                          java.lang.UnsupportedOperationException
Returns the multiplicative inverse of this arithmetic object.

Returns:
this-1.
Throws:
java.lang.ArithmeticException - if an exceptional arithmetic condition has occurred while performing the operation. This should not happen for groups of ⋅.
java.lang.UnsupportedOperationException - if this class does not support this operation, principially, regardless of the argument.

divide

Arithmetic divide(Arithmetic b)
                  throws java.lang.ArithmeticException,
                         java.lang.UnsupportedOperationException
Divides this by an arithmetic object returning the result.

Returns:
this∕b.
Throws:
java.lang.ArithmeticException - if an exceptional arithmetic condition has occurred while performing the operation. This should not happen for groups of ⋅.
java.lang.IllegalArgumentException - if the argument type is illegal for this operation. Note: for single type handling it is also allowed to throw a ClassCastException, instead.
java.lang.UnsupportedOperationException - if this class does not support this operation, principially, regardless of the argument.

scale

Arithmetic scale(Arithmetic alpha)
                 throws java.lang.ArithmeticException,
                        java.lang.UnsupportedOperationException
Multiplies a scalar with this arithmetic object returning the result.

Parameters:
alpha - the factor α to scale this arithmetic object with (per law of action of scalar multiplication).
Returns:
α·this
Throws:
java.lang.ArithmeticException - if an exceptional arithmetic condition has occurred while performing the operation. This should not happen for R-modules (where R=alpha.getClass()).
java.lang.IllegalArgumentException - if the argument type is illegal for this operation. Note: it is also allowed to throw a ClassCastException, instead.
java.lang.UnsupportedOperationException - if this class does not support this operation, principially, regardless of the argument.
See Also:
multiply(Arithmetic)

power

Arithmetic power(Arithmetic b)
                 throws java.lang.ArithmeticException,
                        java.lang.UnsupportedOperationException
Returns the power of an arithmetic object to this base.

Returns:
thisb.
Throws:
java.lang.ArithmeticException - if an exceptional arithmetic condition has occurred while performing the operation.
java.lang.IllegalArgumentException - if the argument type is illegal for this operation. Note: for single type handling it is also allowed to throw a ClassCastException, instead.
java.lang.UnsupportedOperationException - if this class does not support this operation, principially, regardless of the argument.

valueFactory

ValueFactory valueFactory()
Get the value factory producing this object


toString

java.lang.String toString()
Returns a string representation of the Arithmetic object. This method is already provided in Object. If it is overwritten it should return a sound representation of the Arithmetic object.

Overrides:
toString in class java.lang.Object
Returns:
a sound representation of this Arithmetic object.

Orbital library
1.3.0: 11 Apr 2009

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