|
NumberAlgebra.java
|
// FILE. . . . . d:/hak/hlt/src/hlt/math/matrix/sources/NumberAlgebra.java // EDIT BY . . . Hassan Ait-Kaci // ON MACHINE. . Hak-Laptop // STARTED ON. . Tue Dec 3 17:40:58 2019 package hlt.math.matrix;
| package hlt.math.matrix documentation listing |
import java.util.HashMap; import java.util.Iterator;
This is an abstract class that can be subclassed by any class
defining two dual operations sum and product on a
pair of double values, as well as two nullary
zero() and one() operations, a unary operation
negation, and a binary difference operation, all
returning a double.
It provides default implementations for all six as the six standard
Java built-in floating-point arithmetic operations + and
*, the double constants 0.0 and
1.0, and unary and binary -; i.e.,
sum(x,y) = x+y, product(x,y) =
x*y, zero() = 0.0, one() =
1.0, negation(x) = -x, and
difference(x,y) = x-y. These default methods are
not final. So, unless redefined to other methods in a subclass, they
are inherited.
To understand how the algebra classes are organized in this package and
could be used by other packages, see this detailed
description.
|
abstract public class NumberAlgebra { /* ************************************************************************ */
Constructors |
| Constructs a new NumberAlgebra with the default operations. It is not public. |
protected NumberAlgebra () { }
| This defines the default zero() of this NumberAlgebra as 0.0. It can be redefined in a subclass. It should always verify sum(x,zero()) = sum(zero(),x) = x, for any double x. |
public double zero () { return 0.0; }
| This defines the default one() of this NumberAlgebra as 1.0. It can be redefined in a subclass. It should always verify product(x,one()) = product(one(),x) = x, for any double. |
public double one () { return 1.0; }
| This defines the default sum of this NumberAlgebra. It can be redefined in a subclass. It should always verify sum(x,zero()) = sum(zero(),x) = x, for any double x. |
public double sum (double x, double y) { return x + y; }
| This defines the default product of this NumberAlgebra as *. It can be redefined in a subclass. It should always verify product(x,one()) = product(one(),x) = x, for any double. |
public double product (double x, double y) { return x * y; }
| This defines the default difference of this NumberAlgebra as binary -. It can be redefined in a subclass. It should always verify difference(zero(),x) = negation(x), for any double. |
public double difference (double x, double y) { return x - y; }
| This defines the default negation of this NumberAlgebra as binary -. It can be redefined in a subclass. It should always verify difference(zero(),x) = negation(x), for any double. |
public double negation (double x) { return -x; }
| Return the default String form for this NumberAlgebra. It must redefined in any subclass. |
public String toString () { return "Number Algebra"; } /* ************************************************************************ */
Static Class Components and Algebra Manipulation MethodsThis gathers all the paraphernalia necessary and/or useful for the control of parameterization of matrix operations with respect to redefinable arithmetic operations on a matrix double entries. |
| A private holder for the canonical StandardAlgebra object. |
static private StandardAlgebra standardAlgebra;
| Return the canonical StandardAlgebra. |
static final public StandardAlgebra standardAlgebra () { if (standardAlgebra == null) standardAlgebra = (StandardAlgebra)registeredAlgebra(new StandardAlgebra()); return standardAlgebra; }
| A private holder for the canonical MaxMinAlgebra object. |
static private MaxMinAlgebra maxMinAlgebra;
| Return the canonical MaxMinAlgebra. |
static final public MaxMinAlgebra maxMinAlgebra () { if (maxMinAlgebra == null) maxMinAlgebra = (MaxMinAlgebra)registeredAlgebra(new MaxMinAlgebra()); return maxMinAlgebra; } /* ************************************************************************ */
| This is the current NumberAlgebra in effect for all matrix operations. It is set by default to the canonical StandardAlgebra. |
static private NumberAlgebra currentAlgebra;
| Return |
static final public NumberAlgebra currentAlgebra () { if (currentAlgebra == null) currentAlgebra = standardAlgebra(); return currentAlgebra; }
| Set the current canonical NumberAlgebra on double matrix entries in effect for all matrix operations to the (canonical representative algebra of the) given NumberAlgebra. |
static final public void setCurrentAlgebra (NumberAlgebra algebra) { currentAlgebra = registeredAlgebra(algebra); }
| Return the current number algebra on double matrix entries in effect for all matrix operations. |
static final public NumberAlgebra getCurrentAlgebra () { if (currentAlgebra == null) throw new RuntimeException ("There is no NumberAlgebra currently set."); return currentAlgebra; }
| Set the current number algebra in effect for all matrix operations to the canonical StandardAlgebra. |
static final public void setStandardAlgebra () { currentAlgebra = standardAlgebra(); }
| Set the current number algebra in effect for all matrix operations to the canonical MaxMinAlgebra. |
static final public void setMaxMinAlgebra () { currentAlgebra = maxMinAlgebra(); } /* ************************************************************************ */
| This is the repository of all registered concrete NumberAlgebras. It is used to provide a unique canonical algebra object for a given algebra name. Thus, it associates a String (the algebra name) to the unique NumberAlgebra it denotes. |
static final private HashMap algebras = new HashMap();
| Retrieve and return the unique canonical NumberAlgebra object representative sharing the given algebra's name. If none exists, register this algebra under its name (its toString() form), and return it. |
static final public NumberAlgebra registeredAlgebra (NumberAlgebra algebra) { String name = algebra.toString().intern(); NumberAlgebra alg = (NumberAlgebra)algebras.get(name); if (alg != null) return alg; algebras.put(name,algebra); System.err.println("*** Registering new algebra: "+name); return algebra; } static final public void showRegisteredAlgebras () { System.out.println("\tCurrently registered number algebras:\n"); for (Iterator it = algebras.keySet().iterator(); it.hasNext();) System.out.println("\t"+it.next()); System.out.println(); } }
This file was generated on Wed Dec 18 03:37:41 PST 2019 from file NumberAlgebra.java
by the hlt.language.tools.Hilite Java tool written by Hassan Aït-Kaci