// FILE. . . . . d:/hak/hlt/src/hlt/math/matrix/sources/GenMatrix.java
// EDIT BY . . . Hassan Ait-Kaci
// ON MACHINE. . Hak-Laptop
// STARTED ON. . Tue Dec  3 13:47:39 2019

/**
 * @version     Last modified on Thu Dec 12 11:14:08 2019 by hak
 * @author      <a href="mailto:hak@acm.org">Hassan A&iuml;t-Kaci</a>
 * @copyright   &copy; <a href="http://www.hassan-ait-kaci.net/">by the author</a>
 */

package hlt.math.matrix;
/**
 * <a href="000StartHere.html"><tt>package hlt.math.matrix</tt>
 * documentation listing</a>
 */

import hlt.language.tools.Misc;

/**
 * This is a generic class meant to be subclassed by a class
 * representing and manipulating 2D matrices of <tt>double</tt> entries,
 * with <tt>sum</tt>, <tt>product</tt>, <tt>difference</tt>, and
 * <tt>negation</tt> operations on the <tt>double</tt> entries that are
 * defined by a concrete subclass of the generic (abstract) class
 * <tt>NumberAlgebra</tt>. This gives the flexibility to define matrix
 * operations in terms various algebras on <tt>double</tt>s
 * (<tt>+</tt>/<tt>&times;</tt>, <tt>Math.max</tt>/<tt>Math.min</tt>,
 * <i>etc.</i>).
 *
 * <p/>
 * <span style="font-family:arial,helvetica;">
 * 
 * <a name="contents"><span style="font-family:arial,helvetica;">
 * <b>Contents</b> <small>(<a
 * href="000StartHere.html"><tt>package hlt.math.matrix</tt>
 * documentation listing</a>)</small> </span></a>
 *
 * <ul>
 * <li><a href="#constructors">Constructors</a></li>
 * <p/>
 * <li><a href="#components">Object Components</a></li>
 * <p/>
 * <li><a href="#objectmethods">Object Methods</a></li>
 * <p/>
 * </ul>
 * </span>
 *
 * @see         Matrix
 * @see         NumberAlgebra
 * @see         StandardAlgebra
 */
public class GenMatrix
{
  /**
   * <h2 align="center"><span style="font-family:arial,helvetica;">
   * <a name="constructors" href="#contents">Constructors</a>
   * </span></h2>
   */

  /**
   * Constructs a vacuous <tt>GenMatrix</tt> using the default
   * <tt>NumberAlgebra</tt> (<tt>StandardAlgebra</tt>).
   */
  protected GenMatrix ()
  {
    algebra = NumberAlgebra.getAlgebra(new StandardAlgebra());
  }

  /**
   * Constructs a new <tt>GenMatrix</tt> with the given <tt>algebra</tt>.
   */
  public GenMatrix (NumberAlgebra algebra)
  {
    this.algebra = NumberAlgebra.getAlgebra(algebra);
  }

  /**
   * <h2 align="center"><span style="font-family:arial,helvetica;">
   * <a name="components" href="#contents">Object Components</a>
   * </span></h2>
   */
  /**
   * <h2 align="center"><span style="font-family:arial,helvetica;">
   * <a name="objectmethods" href="#contents">Object Methods</a>
   * </span></h2>
   */
  /**
   * The binary <tt>sum</tt> operation on <tt>double</tt> entries.
   */
  public final double sum (double x, double y)
  {
    return algebra.sum(x,y);
  }

  /**
   * The binary <tt>product</tt> operation on <tt>double</tt> entries.
   */
  public final double product (double x, double y)
  {
    return algebra.product(x,y);
  }

  /**
   * The binary <tt>difference</tt> operation on <tt>double</tt> entries.
   */
  public final double difference (double x, double y)
  {
    return algebra.difference(x,y);
  }

  /**
   * The unary negating operation on a <tt>double</tt> entry.
   */
  public final double negation (double x)
  {
    return algebra.negation(x);
  }

  /**
   * <h2 align="center"><span style="font-family:arial,helvetica;">
   * <a name="classmethods" href="#contents">Class Components and Methods</a>
   * </span></h2>
   */

  
  /**
   * This is the <tt>sum</tt>/<tt>product</tt> algebra used on the
   * <tt>double</tt> entries for the generic matrix operations of a
   * <tt>GenMatrix<NumberAlgebra></tt>; the default algebra is a
   * <tt>StandardAlgebra<tt>.
   */
  static private NumberAlgebra algebra = NumberAlgebra.getAlgebra(new StandardAlgebra());
  
  /**
   * Return the <tt>sum</tt>/<tt>product</tt> algebra used on the
   * <tt>double</tt> entries for the generic matrix operations of a
   * <tt>GenMatrix</tt>.
   */
  static public NumberAlgebra getNumberAlgebra ()
  {
    return algebra;
  }

  /**
   * Set the <tt>sum</tt>/<tt>product</tt> algebra used on the
   * <tt>double</tt> entries for the generic matrix operations of a
   * <tt>GenMatrix</tt> to the given <tt>NumberAlgebra</tt>.
   */
  static public final void setNumberAlgebra (NumberAlgebra alg)
  {
    algebra = NumberAlgebra.getAlgebra(alg);
  }

}
