commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r476930 [2/22] - in /jakarta/commons/proper/math/trunk/src/mantissa: ./ src/ src/org/ src/org/spaceroots/ src/org/spaceroots/mantissa/ src/org/spaceroots/mantissa/algebra/ src/org/spaceroots/mantissa/estimation/ src/org/spaceroots/mantissa/...
Date Sun, 19 Nov 2006 21:36:23 GMT
Added: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/algebra/OrthogonalPolynomial.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/algebra/OrthogonalPolynomial.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/algebra/OrthogonalPolynomial.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/algebra/OrthogonalPolynomial.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,151 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.algebra;
+
+import java.util.List;
+
+/**
+ * This class is the base class for orthogonal polynomials.
+
+ * <p>Orthogonal polynomials can be defined by recurrence relations like:
+ * <pre>
+ *      O0(X)   = some 0 degree polynomial
+ *      O1(X)   = some first degree polynomial
+ *  a1k Ok+1(X) = (a2k + a3k X) Ok(X) - a4k Ok-1(X)
+ * </pre>
+ * where a0k, a1k, a2k and a3k are simple expressions which either are
+ * constants or depend on k.</p>
+
+ * @version $Id: OrthogonalPolynomial.java 1705 2006-09-17 19:57:39Z luc $
+ * @author L. Maisonobe
+
+ */
+public abstract class OrthogonalPolynomial
+  extends Polynomial.Rational {
+
+  /** Simple constructor.
+   * Build a degree d orthogonal polynomial
+   * @param d degree of the polynomial
+   * @param l list containing all coefficients already computed
+   * @param maxDegree maximal degree of computed coefficients, this
+   * coefficient <em>must</em> be greater or equal to 1, i.e. the
+   * derived class <em>must</em> have initialized the first two
+   * polynomials of degree 0 and 1 before this constructor can be
+   * called.
+   */
+  protected OrthogonalPolynomial(int d, List l, int maxDegree) {
+    if (d > maxDegree) {
+      computeUpToDegree(d, l, maxDegree);
+    }
+
+    // coefficient  for polynomial 0 is  l [0]
+    // coefficient  for polynomial 1 are l [1] ... l [2] (degrees 0 ... 1)
+    // coefficients for polynomial 2 are l [3] ... l [5] (degrees 0 ... 2)
+    // coefficients for polynomial 3 are l [6] ... l [9] (degrees 0 ... 3)
+    // coefficients for polynomial 4 are l[10] ... l[14] (degrees 0 ... 4)
+    // coefficients for polynomial 5 are l[15] ... l[20] (degrees 0 ... 5)
+    // coefficients for polynomial 6 are l[21] ... l[27] (degrees 0 ... 6)
+    // ...
+    int start = d * (d + 1) / 2;
+
+    a = new RationalNumber[d+1];
+    for (int i = 0; i <= d; ++i) {
+      a[i] = new RationalNumber((RationalNumber) l.get(start + i));
+    }
+
+    unknown = null;
+
+  }
+
+  /** Initialize the recurrence coefficients.
+   * The recurrence relation is
+   *  <pre>a1k Ok+1(X) = (a2k + a3k X) Ok(X) - a4k Ok-1(X)</pre>
+   * @param k index of the current step
+   * @param b2k coefficient to initialize (b2k = a2k / a1k)
+   * @param b3k coefficient to initialize (b3k = a3k / a1k)
+   * @param b4k coefficient to initialize (b4k = a4k / a1k)
+   */
+  protected abstract void initRecurrenceCoefficients(int k,
+                                                     RationalNumber b2k,
+                                                     RationalNumber b3k,
+                                                     RationalNumber b4k);
+
+  /** Set the maximal degree of already computed polynomials.
+   * @param d maximal degree of already computed polynomials
+   */
+  protected abstract void setMaxDegree(int d);
+
+  /** Compute all the polynomial coefficients up to a given degree.
+   * @param d maximal degree
+   * @param l list containing all coefficients already computed
+   * @param maxDegree maximal degree of computed coefficients
+   */
+  protected void computeUpToDegree(int d, List l, int maxDegree) {
+
+    RationalNumber b2k = new RationalNumber();
+    RationalNumber b3k = new RationalNumber();
+    RationalNumber b4k = new RationalNumber();
+
+    int startK = (maxDegree - 1) * maxDegree / 2;
+    for (int k = maxDegree; k < d; ++k) {
+
+      // start indices of two previous polynomials Ok(X) and Ok-1(X)
+      int startKm1 = startK;
+      startK += k;
+
+      // a1k Ok+1(X) = (a2k + a3k X) Ok(X) - a4k Ok-1(X)
+      // we use bik = aik/a1k
+      initRecurrenceCoefficients(k, b2k, b3k, b4k);
+
+      RationalNumber ckPrev = null;
+      RationalNumber ck     = (RationalNumber)l.get(startK);
+      RationalNumber ckm1   = (RationalNumber)l.get(startKm1);
+
+      // degree 0 coefficient
+      RationalNumber coeff  = RationalNumber.multiply(ck, b2k);
+      coeff.multiplyAndSubtractFromSelf(ckm1, b4k);
+      l.add(coeff);
+
+      // degree 1 to degree k-1 coefficients
+      for (int i = 1; i < k; ++i) {
+        ckPrev = ck;
+        ck     = (RationalNumber)l.get(startK + i);
+        ckm1   = (RationalNumber)l.get(startKm1 + i);
+        coeff  = RationalNumber.multiply(ck, b2k);
+        coeff.multiplyAndAddToSelf(ckPrev, b3k);
+        coeff.multiplyAndSubtractFromSelf(ckm1, b4k);
+        l.add(coeff);
+      }
+
+      // degree k coefficient
+      ckPrev = ck;
+      ck     = (RationalNumber)l.get(startK + k);
+      coeff  = RationalNumber.multiply(ck, b2k);
+      coeff.multiplyAndAddToSelf(ckPrev, b3k);
+      l.add(coeff);
+
+      // degree k+1 coefficient
+      l.add(RationalNumber.multiply(ck, b3k));
+
+    }
+
+    setMaxDegree(d);
+
+  }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/algebra/OrthogonalPolynomial.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/algebra/Polynomial.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/algebra/Polynomial.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/algebra/Polynomial.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/algebra/Polynomial.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,1202 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.algebra;
+
+import java.io.Serializable;
+import java.math.BigInteger;
+
+/**
+ * This class implements polynomials with one unknown.
+
+ * <p>This is an abstract class that only declares general methods but
+ * does not hold the coefficients by themselves. Specific subclasses
+ * are used to handle exact rational coefficients or approximate real
+ * coefficients. This design is taken from the various java.awt.geom
+ * classes (Point2D, Rectangle2D ...)</p>
+
+ * <p>The methods implemented deal mainly with the polynomials algebra
+ * (addition, multiplication ...) but the analysis aspects are also
+ * considered (value of the polynom for a given unknown,
+ * derivative).</p>
+
+ * @version $Id: Polynomial.java 1705 2006-09-17 19:57:39Z luc $
+ * @author L. Maisonobe
+
+*/
+public abstract class Polynomial
+  implements Cloneable, Serializable {
+
+  /** Create a copy of the instance.
+   * @return a copy of the instance
+   */
+  public abstract Object clone();
+
+  /** Check if the instance is the null polynomial.
+   * @return true if the polynomial is null
+   */
+  public abstract boolean isZero();
+
+  /** Check if the instance is the constant unit polynomial.
+   * @return true if the polynomial is the constant unit polynomial
+   */
+  public abstract boolean isOne();
+
+  /** Check if the instance is the identity polynomial.
+   * @return true if the polynomial is the identity polynomial
+   */
+  public abstract boolean isIdentity();
+
+  /** Get the polynomial degree.
+   * @return degree
+   */
+  public abstract int getDegree();
+
+  /** Negate the instance.
+   */
+  public abstract void negateSelf();
+
+  /** Multiply the instance by a constant.
+   * @param r constant to multiply by
+   */
+  public abstract void multiplySelf(RationalNumber r);
+
+  /** Multiply the instance by a constant.
+   * @param l constant to multiply by
+   */
+  public abstract void multiplySelf(long l);
+
+  /** Multiply the instance by a constant.
+   * @param i constant to multiply by
+   */
+  public void multiplySelf(BigInteger i) {
+    multiplySelf(new RationalNumber(i));
+  }
+
+  /** Get the value of the polynomial for a specified unknown.
+   * @param x value of the unknown
+   * @return value of the polynomial
+   */
+  public abstract double valueAt(double x);
+
+  /** Get the derivative of the instance with respect to the unknown.
+   * The derivative of a n degree polynomial is a n-1 degree polynomial of
+   * the same type.
+   * @return a new polynomial which is the derivative of the instance
+   */
+  public abstract Polynomial getDerivative();
+
+  /** Set the name of the unknown (to appear during conversions to strings).
+   * @param name name to set (if null, the default 'x' value  will be used)
+   */
+  public abstract void setUnknownName(String name);
+
+  /** This class implements polynomials with one unknown and rational
+   * coefficients.
+
+   * <p>In addition to classical algebra operations, euclidian
+   * division and remainder are handled.</p>
+
+   */
+  public static class Rational extends Polynomial {
+
+    /** Simple constructor.
+     * Build a null polynomial
+     */
+    public Rational() {
+      a = new RationalNumber[1];
+      a[0] = new RationalNumber(0l);
+      unknown = null;
+    }
+
+    /** Simple constructor.
+     * Build a constant polynomial
+     * @param value constant value of the polynomial
+     */
+    public Rational(long value) {
+      this(new RationalNumber(value));
+    }
+
+    /** Simple constructor.
+     * Build a constant polynomial
+     * @param value constant value of the polynomial
+     */
+    public Rational(RationalNumber value) {
+      a = new RationalNumber[1];
+      a[0] = value;
+      unknown = null;
+    }
+
+    /** Simple constructor.
+     * Build a first degree polynomial
+     * @param a1 leeding degree coefficient
+     * @param a0 constant term
+     */
+    public Rational(long a1, long a0) {
+      this(new RationalNumber(a1), new RationalNumber(a0));
+    }
+
+    /** Simple constructor.
+     * Build a first degree polynomial
+     * @param a1 leeding degree coefficient
+     * @param a0 constant term
+     */
+    public Rational(RationalNumber a1, RationalNumber a0) {
+      if (! a1.isZero()) {
+        a = new RationalNumber[2];
+        a[1] = a1;
+      } else {
+        a = new RationalNumber[1];
+      }
+      a[0] = a0;
+      unknown = null;
+    }
+
+    /** Simple constructor.
+     * Build a second degree polynomial
+     * @param a2 leeding degree coefficient
+     * @param a1 first degree coefficient
+     * @param a0 constant term
+     */
+    public Rational(long a2, long a1, long a0) {
+      this(new RationalNumber(a2),
+           new RationalNumber(a1),
+           new RationalNumber(a0));
+    }
+
+    /** Simple constructor.
+     * Build a second degree polynomial
+     * @param a2 leeding degree coefficient
+     * @param a1 first degree coefficient
+     * @param a0 constant term
+     */
+    public Rational(RationalNumber a2, RationalNumber a1, RationalNumber a0) {
+      if (! a2.isZero()) {
+        a = new RationalNumber[3];
+        a[2] = a2;
+        a[1] = a1;
+      } else {
+        if (! a1.isZero()) {
+          a = new RationalNumber[2];
+          a[1] = a1;
+        } else {
+          a = new RationalNumber[1];
+        }
+      }
+      a[0] = a0;
+      unknown = null;
+    }
+
+    /** Simple constructor.
+     * Build a polynomial from its coefficients
+     * @param a coefficients array, the a[0] array element is the
+     * constant term while the a[a.length-1] element is the leeding
+     * degree coefficient. The array is copied in a new array, so it
+     * can be changed once the constructor as returned.
+     */
+    public Rational(RationalNumber[] a) {
+
+      // remove null high degree coefficients
+      int i = a.length - 1;
+      while ((i > 0) && (a[i].isZero())) {
+        --i;
+      }
+
+      // copy the remaining coefficients
+      this.a = new RationalNumber[i + 1];
+      System.arraycopy(a, 0, this.a, 0, i + 1);
+
+      unknown = null;
+
+    }
+
+    /** Simple constructor.
+     * Build a one term polynomial from one coefficient and the corresponding degree
+     * @param c coefficient
+     * @param degree degree associated with the coefficient
+     */
+    public Rational(RationalNumber c, int degree) {
+
+      if (c.isZero() || degree < 0) {
+        a = new RationalNumber[1];
+        a[0] = new RationalNumber(0l);
+      } else {
+        a = new RationalNumber[degree + 1];
+        for (int i = 0; i < degree; ++i) {
+          a[i] = new RationalNumber(0l);
+        }
+        a[degree] = new RationalNumber(c);
+      }
+
+      unknown = null;
+
+    }
+
+    /** Copy constructor.
+     * The copy is a deep copy: the polynomials do <em>not</em> share
+     * their coefficients arrays
+     * @param p polynomial to copy
+     */
+    public Rational(Rational p) {
+
+      a = new RationalNumber[p.a.length];
+      for (int i = 0; i < a.length; ++i) {
+        a[i] = new RationalNumber(p.a[i]);
+      }
+
+      if (p.unknown == null) {
+        unknown = null;
+      } else {
+        unknown = new String(p.unknown);
+      }
+
+    }
+
+    /** Create a copy of the instance.
+     * @return a copy of the instance
+     */
+    public Object clone() {
+      return new Rational(this);
+    }
+
+    /** Check if the instance is the null polynomial.
+     * @return true if the polynomial is null
+     */
+    public boolean isZero() {
+      return (a.length == 1) && a[0].isZero();
+    }
+
+    /** Check if the instance is the constant unit polynomial.
+     * @return true if the polynomial is the constant unit polynomial
+     */
+    public boolean isOne() {
+      return (a.length == 1) && a[0].isOne();
+    }
+
+    /** Check if the instance is the identity polynomial.
+     * @return true if the polynomial is the identity polynomial
+     */
+    public boolean isIdentity() {
+      return (a.length == 2) && a[0].isZero() && a[1].isOne();
+    }
+
+    /** Get the polynomial degree.
+     * @return degree
+     */
+    public int getDegree() {
+      return a.length - 1;
+    }
+
+    /** Get the coefficients of the polynomial.
+     * @return a reference to the internal coefficients array, the array
+     * element at index 0 is the constant term while the element at
+     * index a.length-1 is the leeding degree coefficient
+     */
+    public RationalNumber[] getCoefficients() {
+      return a;
+    }
+
+    /** Set the name of the unknown (to appear during conversions to strings).
+     * @param name name to set (if null, the default 'x' value  will be used)
+     */
+    public void setUnknownName(String name) {
+      unknown = name;
+    }
+
+    /** Simplify the polynomial, by removing null high degree terms.
+     */
+    private void simplify() {
+
+      int i = a.length - 1;
+      while ((i > 0) && a[i].isZero()) {
+        --i;
+      }
+
+      if (i < a.length - 1) {
+        RationalNumber[] newA = new RationalNumber[i + 1];
+        System.arraycopy(a, 0, newA, 0, i + 1);
+        a = newA;
+      }
+
+    }
+
+    /** Add a polynomial to the instance.
+     * @param p polynomial to add
+     */
+    public void addToSelf(Rational p) {
+
+      if (p.a.length > a.length) {
+        RationalNumber[] newA = new RationalNumber[p.a.length];
+        System.arraycopy(a, 0, newA, 0, a.length);
+        for (int i = a.length; i < newA.length; ++i) {
+          newA[i] = new RationalNumber(0l);
+        }
+        a = newA;
+      }
+
+      for (int i = 0; i < p.a.length; ++i) {
+        a[i].addToSelf(p.a[i]);
+      }
+
+      simplify();
+
+    }
+
+    /** Add two polynomials.
+     * @param p1 first polynomial
+     * @param p2 second polynomial
+     * @return a new polynomial which is the sum of p1 and p2
+     */
+    public static Rational add(Rational p1, Rational p2) {
+      Rational copy = new Rational(p1);
+      copy.addToSelf(p2);
+      return copy;
+    }
+
+    /** Subtract a polynomial from the instance.
+     * @param p polynomial to subtract
+     */
+    public void subtractFromSelf(Rational p) {
+
+      if (p.a.length > a.length) {
+        RationalNumber[] newA = new RationalNumber[p.a.length];
+        System.arraycopy(a, 0, newA, 0, a.length);
+        for (int i = a.length; i < newA.length; ++i) {
+          newA[i] = new RationalNumber(0l);
+        }
+        a = newA;
+      }
+
+      for (int i = 0; i < p.a.length; ++i) {
+        a[i].subtractFromSelf(p.a[i]);
+      }
+
+      simplify();
+
+    }
+
+    /** Subtract two polynomials.
+     * @param p1 first polynomial
+     * @param p2 second polynomial
+     * @return a new polynomial which is the difference p1 minus p2
+     */
+    public static Rational subtract(Rational p1, Rational p2) {
+      Rational copy = new Rational(p1);
+      copy.subtractFromSelf(p2);
+      return copy;
+    }
+
+    /** Negate the instance.
+     */
+    public void negateSelf() {
+      for (int i = 0; i < a.length; ++i) {
+        a[i].negateSelf();
+      }
+    }
+
+    /** Negate a polynomial.
+     * @param p polynomial to negate
+     * @return a new polynomial which is the opposite of p
+     */
+    public static Rational negate(Rational p) {
+      Rational copy = new Rational(p);
+      copy.negateSelf();
+      return copy;
+    }
+
+    /** Multiply the instance by a polynomial.
+     * @param p polynomial to multiply by
+     */
+    public void multiplySelf(Rational p) {
+
+      RationalNumber[] newA = new RationalNumber[a.length + p.a.length - 1];
+
+      for (int i = 0; i < newA.length; ++i) {
+        newA[i] = new RationalNumber(0l);
+        for (int j = Math.max(0, i + 1 - p.a.length);
+             j < Math.min(a.length, i + 1);
+             ++j) {
+          newA[i].addToSelf(RationalNumber.multiply(a[j], p.a[i-j]));
+        }
+      }
+
+      a = newA;
+
+    }
+
+    /** Multiply two polynomials.
+     * @param p1 first polynomial
+     * @param p2 second polynomial
+     * @return a new polynomial which is the product of p1 and p2
+     */
+    public static Rational multiply(Rational p1, Rational p2) {
+      Rational copy = new Rational(p1);
+      copy.multiplySelf(p2);
+      return copy;
+    }
+
+    /** Multiply the instance by a constant.
+     * @param r constant to multiply by
+     */
+    public void multiplySelf(RationalNumber r) {
+
+      if (r.isZero()) {
+        a = new RationalNumber[1];
+        a[0] = new RationalNumber(0l);
+      }
+
+      for (int i = 0; i < a.length; ++i) {
+        a[i].multiplySelf(r);
+      }
+
+    }
+
+    /** Multiply a polynomial by a constant.
+     * @param p polynomial
+     * @param r constant
+     * @return a new polynomial which is the product of p and r
+     */
+    public static Rational multiply(Rational p, RationalNumber r) {
+      Rational copy = new Rational(p);
+      copy.multiplySelf(r);
+      return copy;
+    }
+
+    /** Multiply the instance by a constant.
+     * @param l constant to multiply by
+     */
+    public void multiplySelf(long l) {
+
+      if (l == 0l) {
+        a = new RationalNumber[1];
+        a[0] = new RationalNumber(0l);
+      }
+
+      for (int i = 0; i < a.length; ++i) {
+        a[i].multiplySelf(l);
+      }
+
+    }
+
+    /** Multiply a polynomial by a constant.
+     * @param p polynomial
+     * @param l constant
+     * @return a new polynomial which is the product of p and l
+     */
+    public static Rational multiply(Rational p, long l) {
+      Rational copy = new Rational(p);
+      copy.multiplySelf(l);
+      return copy;
+    }
+
+    /** Get the value of the polynomial for a specified unknown.
+     * @param x value of the unknown
+     * @return value of the polynomial
+     */
+    public double valueAt(double x) {
+      double y = 0;
+      for (int i = a.length - 1; i >= 0; --i) {
+        y = y * x + a[i].doubleValue();
+      }
+      return y;
+    }
+
+    /** Get the derivative of the instance with respect to the unknown.
+     * The derivative of a n degree polynomial is a n-1 degree polynomial of
+     * the same type.
+     * @return a new polynomial which is the derivative of the instance
+     */
+    public Polynomial getDerivative() {
+      Rational derivative = new Rational();
+      if (a.length == 1) {
+        return derivative;
+      }
+      derivative.a = new RationalNumber[a.length - 1];
+      for (int i = 1; i < a.length; ++i) {
+        derivative.a[i-1] = RationalNumber.multiply(a[i], i);
+      }
+      return derivative;
+    }
+
+    /** Perform the euclidian division of two polynomials.
+     * @param dividend numerator polynomial
+     * @param divisor  denominator polynomial
+     * @return an object containing the quotient and the remainder of the division
+     */
+    public static DivisionResult euclidianDivision(Rational dividend,
+                                                   Rational divisor) {
+
+      Rational quotient  = new Rational(0l);
+      Rational remainder = new Rational(dividend);
+
+      int divisorDegree   = divisor.getDegree();
+      int remainderDegree = remainder.getDegree();
+      while ((! remainder.isZero()) && (remainderDegree >= divisorDegree)) {
+
+        RationalNumber c = RationalNumber.divide(remainder.a[remainderDegree],
+                                                 divisor.a[divisorDegree]);
+        Rational monomial = new Rational(c, remainderDegree - divisorDegree);
+
+        remainder.subtractFromSelf(Rational.multiply(monomial, divisor));
+        quotient.addToSelf(monomial);
+
+        remainderDegree = remainder.getDegree();
+
+      }
+
+      return new DivisionResult(quotient, remainder);
+
+    }
+
+    /** Get the Least Common Multiple of the coefficients denominators.
+     * This number is the smallest integer by which we should multiply
+     * the instance to get a polynomial whose coefficients are all integers.
+     * @return the Least Common Multiple of the coefficients denominators
+     */
+    public BigInteger getDenominatorsLCM() {
+
+      BigInteger lcm = BigInteger.ONE;
+
+      for (int i = 0; i < a.length; ++i) {
+        RationalNumber newCoeff = RationalNumber.multiply(a[i], lcm);
+        if (! newCoeff.isInteger()) {
+          lcm = lcm.multiply(newCoeff.getDenominator());
+        }
+      }
+
+      return lcm;
+
+    }
+
+    /** Returns a string representation of the polynomial.
+
+    * <p>The representation is user oriented. Terms are displayed lowest
+    * degrees first. The multiplications signs, coefficients equals to
+    * one and null terms are not displayed (except if the polynomial is 0,
+    * in which case the 0 constant term is displayed). Addition of terms
+    * with negative coefficients are replaced by subtraction of terms
+    * with positive coefficients except for the first displayed term
+    * (i.e. we display <code>-3</code> for a constant negative polynomial,
+    * but <code>1 - 3 x + x^2</code> if the negative coefficient is not
+    * the first one displayed).</p>
+
+    * <p>The name of the unknown is <code>x</code> by default, but can
+    * be changed using the {@link #setUnknownName setUnknownName}
+    * method.</p>
+
+    * @return a string representation of the polynomial
+
+    */
+    public String toString() {
+
+      StringBuffer s = new StringBuffer();
+      if (a[0].isZero()) {
+        if (a.length == 1) {
+          return "0";
+        }
+      } else {
+        s.append(a[0].toString());
+      }
+
+      for (int i = 1; i < a.length; ++i) {
+
+        if (! a[i].isZero()) {
+
+          if (s.length() > 0) {
+            if (a[i].isNegative()) {
+              s.append(" - ");
+            } else {
+              s.append(" + ");
+            }
+          } else {
+            if (a[i].isNegative()) {
+              s.append("-");
+            }
+          }
+
+          RationalNumber absAi = RationalNumber.abs(a[i]);
+          if (! absAi.isOne()) {
+            s.append(absAi.toString());
+            s.append(' ');
+          }
+
+          s.append((unknown == null) ? defaultUnknown : unknown);
+          if (i > 1) {
+            s.append('^');
+            s.append(Integer.toString(i));
+          }
+        }
+
+      }
+
+      return s.toString();
+
+    }
+
+    /** Coefficients array. */
+    protected RationalNumber[] a;
+
+    /** Name of the unknown. */
+    protected String unknown;
+
+    private static final long serialVersionUID = 3035650338772911046L;
+
+  }
+
+  /** This class stores the result of the euclidian division of two polynomials.
+   * This class is a simple placeholder, it does not provide any
+   * processing method
+   * @see Polynomial.Rational#euclidianDivision
+   */
+  public static class DivisionResult {
+
+    /** The quotient of the division. */
+    public final Rational quotient;
+
+    /** The remainder of the division. */
+    public final Rational remainder;
+
+    /** Simple constructor. */
+    public DivisionResult(Rational quotient, Rational remainder) {
+      this.quotient  = quotient;
+      this.remainder = remainder;
+    }
+
+  }
+
+  /** This class implements polynomials with one unknown and real
+   * coefficients.
+   */
+  public static class Double extends Polynomial {
+
+    /** Simple constructor.
+     * Build a null polynomial
+     */
+    public Double() {
+      a = new double[1];
+      a[0] = 0;
+      unknown = null;
+    }
+
+    /** Simple constructor.
+     * Build a constant polynomial
+     * @param value constant value of the polynomial
+     */
+    public Double(double value) {
+      a = new double[1];
+      a[0] = value;
+      unknown = null;
+    }
+
+    /** Simple constructor.
+     * Build a first degree polynomial
+     * @param a1 leeding degree coefficient
+     * @param a0 constant term
+     */
+    public Double(double a1, double a0) {
+      if (Math.abs(a1) > 1.0e-12) {
+        a = new double[2];
+        a[1] = a1;
+      } else {
+        a = new double[1];
+      }
+      a[0] = a0;
+      unknown = null;
+    }
+
+    /** Simple constructor.
+     * Build a second degree polynomial
+     * @param a2 leeding degree coefficient
+     * @param a1 first degree coefficient
+     * @param a0 constant term
+     */
+    public Double(double a2, double a1, double a0) {
+      if (Math.abs(a2) > 1.0e-12) {
+        a = new double[3];
+        a[2] = a2;
+        a[1] = a1;
+      } else {
+        if (Math.abs(a1) > 1.0e-12) {
+          a = new double[2];
+          a[1] = a1;
+        } else {
+          a = new double[1];
+        }
+      }
+      a[0] = a0;
+      unknown = null;
+    }
+
+    /** Simple constructor.
+     * Build a polynomial from its coefficients
+     * @param a coefficients array, the a[0] array element is the
+     * constant term while the a[a.length-1] element is the leeding
+     * degree coefficient. The array is copied in a new array, so it
+     * can be changed once the constructor as returned.
+     */
+    public Double(double[] a) {
+
+      // remove null high degree coefficients
+      int i = a.length - 1;
+      while ((i > 0) && (Math.abs(a[i]) <= 1.0e-12)) {
+        --i;
+      }
+
+      // copy the remaining coefficients
+      this.a = new double[i + 1];
+      System.arraycopy(a, 0, this.a, 0, i + 1);
+
+      unknown = null;
+
+    }
+
+    /** Simple constructor.
+     * Build a one term polynomial from one coefficient and the corresponding degree
+     * @param c coefficient
+     * @param degree degree associated with the coefficient
+     */
+    public Double(double c, int degree) {
+
+      if ((Math.abs(c) <= 1.0e-12) || degree < 0) {
+        a = new double[1];
+        a[0] = 0;
+      } else {
+        a = new double[degree + 1];
+        for (int i = 0; i < degree; ++i) {
+          a[i] = 0;
+        }
+        a[degree] = c;
+      }
+
+      unknown = null;
+
+    }
+
+    /** Copy constructor.
+     * The copy is a deep copy: the polynomials do <em>not</em> share
+     * their coefficients arrays
+     * @param p polynomial to copy
+     */
+    public Double(Double p) {
+
+      a = new double[p.a.length];
+      for (int i = 0; i < a.length; ++i) {
+        a[i] = p.a[i];
+      }
+
+      if (p.unknown == null) {
+        unknown = null;
+      } else {
+        unknown = new String(p.unknown);
+      }
+
+    }
+
+    /** Copy constructor.
+     * The copy is a deep copy: the polynomials do <em>not</em> share
+     * their coefficients arrays
+     * @param p polynomial to copy
+     */
+    public Double(Rational p) {
+
+      RationalNumber[] pA = p.getCoefficients();
+      a = new double[pA.length];
+      for (int i = 0; i < a.length; ++i) {
+        a[i] = pA[i].doubleValue();
+      }
+
+      if (p.unknown == null) {
+        unknown = null;
+      } else {
+        unknown = new String(p.unknown);
+      }
+
+    }
+
+    /** Create a copy of the instance.
+     * @return a copy of the instance
+     */
+    public Object clone() {
+      return new Double(this);
+    }
+
+    /** Check if the instance is the null polynomial.
+     * @return true if the polynomial is null
+     */
+    public boolean isZero() {
+      return (a.length == 1) && (Math.abs(a[0]) < 1.0e-12);
+    }
+
+    /** Check if the instance is the constant unit polynomial.
+     * @return true if the polynomial is the constant unit polynomial
+     */
+    public boolean isOne() {
+      return (a.length == 1) && (Math.abs(a[0] - 1) < 1.0e-12);
+    }
+
+    /** Check if the instance is the identity polynomial.
+     * @return true if the polynomial is the identity polynomial
+     */
+    public boolean isIdentity() {
+      return (a.length == 2)
+        && (Math.abs(a[0]) < 1.0e-12)
+        && (Math.abs(a[1] - 1) < 1.0e-12);
+    }
+
+    /** Get the polynomial degree.
+     * @return degree
+     */
+    public int getDegree() {
+      return a.length - 1;
+    }
+
+    /** Get the coefficients of the polynomial.
+     * @return a reference to the internal coefficients array, the array
+     * element at index 0 is the constant term while the element at
+     * index a.length-1 is the leeding degree coefficient
+     */
+    public double[] getCoefficients() {
+      return a;
+    }
+
+    /** Simplify the polynomial, by removing null high degree terms.
+     */
+    private void simplify() {
+
+      int i = a.length - 1;
+      while ((i > 0) && (Math.abs(a[i]) <= 1.0e-12)) {
+        --i;
+      }
+
+      if (i < a.length - 1) {
+        double[] newA = new double[i + 1];
+        System.arraycopy(a, 0, newA, 0, i + 1);
+        a = newA;
+      }
+
+    }
+
+    /** Add a polynomial to the instance.
+     * @param p polynomial to add
+     */
+    public void addToSelf(Double p) {
+
+      if (p.a.length > a.length) {
+        double[] newA = new double[p.a.length];
+        System.arraycopy(a, 0, newA, 0, a.length);
+        for (int i = a.length; i < newA.length; ++i) {
+          newA[i] = 0;
+        }
+        a = newA;
+      }
+
+      for (int i = 0; i < p.a.length; ++i) {
+        a[i] += p.a[i];
+      }
+
+      simplify();
+
+    }
+
+    /** Add two polynomials.
+     * @param p1 first polynomial
+     * @param p2 second polynomial
+     * @return a new polynomial which is the sum of p1 and p2
+     */
+    public static Double add(Double p1, Double p2) {
+      Double copy = new Double(p1);
+      copy.addToSelf(p2);
+      return copy;
+    }
+
+    /** Subtract a polynomial from the instance.
+     * @param p polynomial to subtract
+     */
+    public void subtractFromSelf(Double p) {
+
+      if (p.a.length > a.length) {
+        double[] newA = new double[p.a.length];
+        System.arraycopy(a, 0, newA, 0, a.length);
+        for (int i = a.length; i < newA.length; ++i) {
+          newA[i] = 0;
+        }
+        a = newA;
+      }
+
+      for (int i = 0; i < p.a.length; ++i) {
+        a[i] -= p.a[i];
+      }
+
+      simplify();
+
+    }
+
+    /** Subtract two polynomials.
+     * @param p1 first polynomial
+     * @param p2 second polynomial
+     * @return a new polynomial which is the difference p1 minus p2
+     */
+    public static Double subtract(Double p1, Double p2) {
+      Double copy = new Double(p1);
+      copy.subtractFromSelf(p2);
+      return copy;
+    }
+
+    /** Negate the instance.
+     */
+    public void negateSelf() {
+      for (int i = 0; i < a.length; ++i) {
+        a[i] = -a[i];
+      }
+    }
+
+    /** Negate a polynomial.
+     * @param p polynomial to negate
+     * @return a new polynomial which is the opposite of p
+     */
+    public static Double negate(Double p) {
+      Double copy = new Double(p);
+      copy.negateSelf();
+      return copy;
+    }
+
+    /** Multiply the instance by a polynomial.
+     * @param p polynomial to multiply by
+     */
+    public void multiplySelf(Double p) {
+
+      double[] newA = new double[a.length + p.a.length - 1];
+
+      for (int i = 0; i < newA.length; ++i) {
+        newA[i] = 0;
+        for (int j = Math.max(0, i + 1 - p.a.length);
+             j < Math.min(a.length, i + 1);
+             ++j) {
+          newA[i] += a[j] * p.a[i-j];
+        }
+      }
+
+      a = newA;
+
+    }
+
+    /** Multiply two polynomials.
+     * @param p1 first polynomial
+     * @param p2 second polynomial
+     * @return a new polynomial which is the product of p1 and p2
+     */
+    public static Double multiply(Double p1, Double p2) {
+      Double copy = new Double(p1);
+      copy.multiplySelf(p2);
+      return copy;
+    }
+
+    /** Multiply the instance by a constant.
+     * @param r constant to multiply by
+     */
+    public void multiplySelf(double r) {
+
+      if (Math.abs(r) < 1.0e-12) {
+        a = new double[1];
+        a[0] = 0;
+      }
+
+      for (int i = 0; i < a.length; ++i) {
+        a[i] *= r;
+      }
+
+    }
+
+    /** Multiply a polynomial by a constant.
+     * @param p polynomial
+     * @param r constant
+     * @return a new polynomial which is the product of p and r
+     */
+    public static Double multiply(Double p, double r) {
+      Double copy = new Double(p);
+      copy.multiplySelf(r);
+      return copy;
+    }
+
+    /** Multiply the instance by a constant.
+     * @param r constant to multiply by
+     */
+    public void multiplySelf(RationalNumber r) {
+
+      if (r.isZero()) {
+        a = new double[1];
+        a[0] = 0;
+      }
+
+      double rValue = r.doubleValue();
+      for (int i = 0; i < a.length; ++i) {
+        a[i] *= rValue;
+      }
+
+    }
+
+    /** Multiply the instance by a constant.
+     * @param l constant to multiply by
+     */
+    public void multiplySelf(long l) {
+
+      if (l == 0l) {
+        a = new double[1];
+        a[0] = 0;
+      }
+
+      for (int i = 0; i < a.length; ++i) {
+        a[i] *= l;
+      }
+
+    }
+
+    /** Multiply a polynomial by a constant.
+     * @param p polynomial
+     * @param l constant
+     * @return a new polynomial which is the product of p and l
+     */
+    public static Double multiply(Double p, long l) {
+      Double copy = new Double(p);
+      copy.multiplySelf(l);
+      return copy;
+    }
+
+    /** Get the value of the polynomial for a specified unknown.
+     * @param x value of the unknown
+     * @return value of the polynomial
+     */
+    public double valueAt(double x) {
+      double y = 0;
+      for (int i = a.length - 1; i >= 0; --i) {
+        y = y * x + a[i];
+      }
+      return y;
+    }
+
+    /** Get the derivative of the instance with respect to the unknown.
+     * The derivative of a n degree polynomial is a n-1 degree polynomial of
+     * the same type.
+     * @return a new polynomial which is the derivative of the instance
+     */
+    public Polynomial getDerivative() {
+      Double derivative = new Double();
+      if (a.length == 1) {
+        return derivative;
+      }
+      derivative.a = new double[a.length - 1];
+      for (int i = 1; i < a.length; ++i) {
+        derivative.a[i-1] = a[i] * i;
+      }
+      return derivative;
+    }
+
+    /** Set the name of the unknown (to appear during conversions to strings).
+     * @param name name to set (if null, the default 'x' value  will be used)
+     */
+    public void setUnknownName(String name) {
+      unknown = name;
+    }
+
+    /** Returns a string representation of the polynomial.
+
+    * <p>The representation is user oriented. Terms are displayed lowest
+    * degrees first. The multiplications signs, coefficients equals to
+    * one and null terms are not displayed (except if the polynomial is 0,
+    * in which case the 0 constant term is displayed). Addition of terms
+    * with negative coefficients are replaced by subtraction of terms
+    * with positive coefficients except for the first displayed term
+    * (i.e. we display <code>-3</code> for a constant negative polynomial,
+    * but <code>1 - 3 x + x^2</code> if the negative coefficient is not
+    * the first one displayed).</p>
+
+    * <p>The name of the unknown is <code>x</code> by default, but can
+    * be changed using the {@link #setUnknownName setUnknownName}
+    * method.</p>
+
+    * @return a string representation of the polynomial
+
+    */
+    public String toString() {
+
+      double maxCoeff = 0;
+      for (int i = 0; i < a.length; ++i) {
+        double abs = Math.abs(a[i]);
+        if (abs > maxCoeff) {
+          maxCoeff = abs;
+        }
+      }
+      double epsilon = 1.0e-12 * maxCoeff;
+
+      StringBuffer s = new StringBuffer();
+      if (Math.abs(a[0]) <= epsilon) {
+        if (a.length == 1) {
+          return "0";
+        }
+      } else {
+        s.append(a[0]);
+      }
+
+      for (int i = 1; i < a.length; ++i) {
+
+        if (Math.abs(a[i]) > epsilon) {
+
+          if (s.length() > 0) {
+            if (a[i] < 0) {
+              s.append(" - ");
+            } else {
+              s.append(" + ");
+            }
+          } else {
+            if (a[i] < 0) {
+              s.append("-");
+            }
+          }
+
+          double absAi = Math.abs(a[i]);
+          if (Math.abs(absAi - 1) > 1.0e-12) {
+            s.append(absAi);
+            s.append(' ');
+          }
+
+          s.append((unknown == null) ? defaultUnknown : unknown);
+          if (i > 1) {
+            s.append('^');
+            s.append(Integer.toString(i));
+          }
+        }
+
+      }
+
+      return s.toString();
+
+    }
+
+    /** Coefficients array. */
+    protected double[] a;
+
+    /** Name of the unknown. */
+    protected String unknown;
+
+    private static final long serialVersionUID = -5907669461605191069L;
+
+  }
+
+  /** Default name of unknowns. */
+  protected static String defaultUnknown = new String("x");
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/algebra/Polynomial.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/algebra/Polynomial.java
------------------------------------------------------------------------------
    svn:executable = *

Added: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/algebra/PolynomialFraction.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/algebra/PolynomialFraction.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/algebra/PolynomialFraction.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/algebra/PolynomialFraction.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,439 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.algebra;
+
+import java.math.BigInteger;
+
+/**
+ * This class implements fractions of polynomials with one unknown and
+ * rational coefficients.
+
+ * @version $Id: PolynomialFraction.java 1705 2006-09-17 19:57:39Z luc $
+ * @author L. Maisonobe
+
+ */
+
+public class PolynomialFraction {
+
+  /**
+   * Simple constructor.
+   * Build a constant null fraction
+   */
+  public PolynomialFraction() {
+    this(new Polynomial.Rational(new RationalNumber(0l)),
+         new Polynomial.Rational(new RationalNumber(1l)));
+  }
+
+  /**
+   * Simple constructor.
+   * Build a fraction from a numerator and a denominator.
+   * @param numerator numerator of the fraction
+   * @param denominator denominator of the fraction
+   * @exception ArithmeticException if the denominator is null
+   */
+  public PolynomialFraction(long numerator, long denominator) {
+    this(new Polynomial.Rational(new RationalNumber(numerator)),
+         new Polynomial.Rational(new RationalNumber(denominator)));
+  }
+
+  /**
+   * Simple constructor.
+   * Build a fraction from a numerator and a denominator.
+   * @param numerator numerator of the fraction
+   * @param denominator denominator of the fraction
+   * @exception ArithmeticException if the denominator is null
+   */
+  public PolynomialFraction(BigInteger numerator, BigInteger denominator) {
+    this(new Polynomial.Rational(new RationalNumber(numerator)),
+         new Polynomial.Rational(new RationalNumber(denominator)));
+  }
+
+  /**
+   * Simple constructor.
+   * Build a fraction from a numerator and a denominator.
+   * @param numerator numerator of the fraction
+   * @param denominator denominator of the fraction
+   * @exception ArithmeticException if the denominator is null
+   */
+  public PolynomialFraction(RationalNumber numerator,
+                            RationalNumber denominator) {
+    this(new Polynomial.Rational(numerator),
+         new Polynomial.Rational(denominator));
+  }
+
+  /**
+   * Simple constructor.
+   * Build a fraction from a numerator and a denominator.
+   * @param numerator numerator of the fraction
+   * @param denominator denominator of the fraction
+   * @exception ArithmeticException if the denominator is null
+   */
+  public PolynomialFraction(Polynomial.Rational numerator,
+                            Polynomial.Rational denominator) {
+
+    if (denominator.isZero()) {
+      throw new ArithmeticException("null denominator");
+    }
+
+    p = new Polynomial.Rational(numerator);
+    q = new Polynomial.Rational(denominator);
+
+    RationalNumber[] a = q.getCoefficients();
+    if (a[a.length - 1].isNegative()) {
+      p.negateSelf();
+      q.negateSelf();
+    }
+
+    simplify();
+
+  }
+
+  /**
+   * Simple constructor.
+   * Build a fraction from a single integer
+   * @param l value of the fraction
+   */
+  public PolynomialFraction(long l) {
+    this(l, 1l);
+  }
+
+  /**
+   * Simple constructor.
+   * Build a fraction from a single integer
+   * @param i value of the fraction
+   */
+  public PolynomialFraction(BigInteger i) {
+    this(i, BigInteger.ONE);
+  }
+
+  /**
+   * Simple constructor.
+   * Build a fraction from a single rational number
+   * @param r value of the fraction
+   */
+  public PolynomialFraction(RationalNumber r) {
+    this(r.getNumerator(), r.getDenominator());
+  }
+
+  /**
+   * Simple constructor.
+   * Build a fraction from a single Polynom
+   * @param p value of the fraction
+   */
+  public PolynomialFraction(Polynomial.Rational p) {
+    this(p, new Polynomial.Rational(new RationalNumber(1l)));
+  }
+
+  /**
+   * Copy-constructor.
+   * @param f fraction to copy
+   */
+  public PolynomialFraction(PolynomialFraction f) {
+    p = new Polynomial.Rational(f.p);
+    q = new Polynomial.Rational(f.q);
+  }
+
+  /**
+   * Negate the instance
+   */
+  public void negateSelf() {
+    p.negateSelf();
+  }
+
+  /**
+   * Negate a fraction.
+   * @param f fraction to negate
+   * @return a new fraction which is the opposite of f
+   */
+  public static PolynomialFraction negate(PolynomialFraction f) {
+    PolynomialFraction copy = new PolynomialFraction(f);
+    copy.negateSelf();
+    return copy;
+  }
+
+  /**
+   * Add a fraction to the instance.
+   * @param f fraction to add.
+   */
+  public void addToSelf(PolynomialFraction f) {
+    PolynomialFraction sum = add(this, f);
+    p = sum.p;
+    q = sum.q;
+  }
+
+  /** Add two fractions.
+   * @param f1 first fraction
+   * @param f2 second fraction
+   * @return a new fraction which is the sum of f1 and f2
+   */
+  public static PolynomialFraction add(PolynomialFraction f1,
+                                       PolynomialFraction f2) {
+    Polynomial.Rational num =
+      Polynomial.Rational.add(Polynomial.Rational.multiply(f1.p, f2.q),
+                              Polynomial.Rational.multiply(f2.p, f1.q));
+    Polynomial.Rational den = Polynomial.Rational.multiply(f1.q, f2.q);
+    return new PolynomialFraction(num, den);
+  }
+
+  /**
+   * Subtract a fraction to the instance.
+   * @param f fraction to subtract.
+   */
+  public void subtractFromSelf(PolynomialFraction f) {
+    PolynomialFraction diff = subtract(this, f);
+    p = diff.p;
+    q = diff.q;
+  }
+
+  /** Subtract two fractions.
+   * @param f1 first fraction
+   * @param f2 second fraction
+   * @return a new fraction which is the difference f1 minus f2
+   */
+  public static PolynomialFraction subtract(PolynomialFraction f1,
+                                            PolynomialFraction f2) {
+    Polynomial.Rational num =
+      Polynomial.Rational.subtract(Polynomial.Rational.multiply(f1.p, f2.q),
+                                   Polynomial.Rational.multiply(f2.p, f1.q));
+    Polynomial.Rational den = Polynomial.Rational.multiply(f1.q, f2.q);
+    return new PolynomialFraction(num, den);
+  }
+
+  /** Multiply the instance by a fraction.
+   * @param f fraction to multiply by
+   */
+  public void multiplySelf(PolynomialFraction f) {
+    p.multiplySelf(f.p);
+    q.multiplySelf(f.q);
+    simplify();
+  }
+
+  /** Multiply two fractions.
+   * @param f1 first fraction
+   * @param f2 second fraction
+   * @return a new fraction which is the product of f1 and f2
+   */
+  public static PolynomialFraction multiply(PolynomialFraction f1,
+                                            PolynomialFraction f2) {
+    PolynomialFraction copy = new PolynomialFraction(f1);
+    copy.multiplySelf(f2);
+    return copy;
+  }
+
+  /** Divide the instance by a fraction.
+   * @param f fraction to divide by
+   * @exception ArithmeticException if f is null
+   */
+  public void divideSelf(PolynomialFraction f) {
+
+    if (f.p.isZero()) {
+      throw new ArithmeticException("divide by zero");
+    }
+
+    p.multiplySelf(f.q);
+    q.multiplySelf(f.p);
+
+    RationalNumber[] a = q.getCoefficients();
+    if (a[a.length - 1].isNegative()) {
+      p.negateSelf();
+      q.negateSelf();
+    }
+
+    simplify();
+
+  }
+
+  /** Divide two fractions.
+   * @param f1 first fraction
+   * @param f2 second fraction
+   * @return a new fraction which is the quotient of f1 by f2
+   */
+  public static PolynomialFraction divide(PolynomialFraction f1,
+                                          PolynomialFraction f2) {
+    PolynomialFraction copy = new PolynomialFraction(f1);
+    copy.divideSelf(f2);
+    return copy;
+  }
+
+  /** Invert the instance.
+   * Replace the instance by its inverse.
+   * @exception ArithmeticException if the instance is null
+   */
+  public void invertSelf() {
+
+    if (p.isZero()) {
+      throw new ArithmeticException("divide by zero");
+    }
+
+    Polynomial.Rational tmp = p;
+    p = q;
+    q = tmp;
+
+    RationalNumber[] a = q.getCoefficients();
+    if (a[a.length - 1].isNegative()) {
+      p.negateSelf();
+      q.negateSelf();
+    }
+
+    simplify();
+
+  }
+
+  /** Invert a fraction.
+   * @param f fraction to invert
+   * @return a new fraction which is the inverse of f
+   */
+  public static PolynomialFraction invert(PolynomialFraction f) {
+    PolynomialFraction copy = new PolynomialFraction(f);
+    copy.invertSelf();
+    return copy;
+  }
+
+  /** Simplify a fraction.
+   * If the denominator polynom is a constant polynom, then
+   * simplification involves merging this constant in the rational
+   * coefficients of the numerator in order to replace the denominator
+   * by the constant 1. If the degree of the denominator is non null,
+   * then simplification involves both removing common polynomial
+   * factors (by euclidian division) and replacing rational
+   * coefficients by integer coefficients (multiplying both numerator
+   * and denominator by the proper value). The signs of both the
+   * numerator and the denominator are adjusted in order to have a
+   * positive leeding degree term in the denominator.
+   */
+  private void simplify() {
+
+    Polynomial.Rational a = new Polynomial.Rational(p);
+    Polynomial.Rational b = new Polynomial.Rational(q);
+    if (a.getDegree() < b.getDegree()) {
+      Polynomial.Rational tmp = a;
+      a = b;
+      b = tmp;
+    }
+
+    Polynomial.DivisionResult res =
+      Polynomial.Rational.euclidianDivision(a, b);
+    while (res.remainder.getDegree() != 0) {
+      a = b;
+      b = res.remainder;
+      res = Polynomial.Rational.euclidianDivision(a, b);
+    }
+
+    if (res.remainder.isZero()) {
+      // there is a common factor we can remove
+      p = Polynomial.Rational.euclidianDivision(p, b).quotient;
+      q = Polynomial.Rational.euclidianDivision(q, b).quotient;
+    }
+
+    if (q.getDegree() == 0) {
+      if (! q.isOne()) {
+        RationalNumber f = q.getCoefficients()[0];
+        f.invertSelf();
+        p.multiplySelf(f);
+        q = new Polynomial.Rational(1l);
+      }
+    } else {
+
+      BigInteger lcm = p.getDenominatorsLCM();
+      if (lcm.compareTo(BigInteger.ONE) != 0) {
+        p.multiplySelf(lcm);
+        q.multiplySelf(lcm);
+      }
+
+      lcm = q.getDenominatorsLCM();
+      if (lcm.compareTo(BigInteger.ONE) != 0) {
+        p.multiplySelf(lcm);
+        q.multiplySelf(lcm);
+      }
+
+    }
+
+    if (q.getCoefficients()[q.getDegree()].isNegative()) {
+      p.negateSelf();
+      q.negateSelf();
+    }
+
+  }
+
+  /**
+   * Get the numerator.
+   * @return the numerator
+   */
+  public Polynomial.Rational getNumerator() {
+    return p;
+  }
+
+  /**
+   * Get the denominator.
+   * @return the denominator (leeding coefficient is always positive)
+   */
+  public Polynomial.Rational getDenominator() {
+    return q;
+  }
+
+  /** Set the name of the unknown (to appear during conversions to
+   * strings).
+   * @param name name to set (if null, the default 'x' value will be
+   * used)
+   */
+  public void setUnknownName(String name) {
+    p.setUnknownName(name);
+    q.setUnknownName(name);
+  }
+
+  public String toString() {
+    if (p.isZero()) {
+      return "0";
+    } else if (q.isOne()) {
+      return p.toString();
+    } else {
+
+      StringBuffer s = new StringBuffer();
+
+      String pString = p.toString();
+      if (pString.indexOf(' ') > 0) {
+        s.append('(');
+        s.append(pString);
+        s.append(')');
+      } else {
+        s.append(pString);
+      }
+
+      s.append('/');
+
+      String qString = q.toString();
+      if (qString.indexOf(' ') > 0) {
+        s.append('(');
+        s.append(qString);
+        s.append(')');
+      } else {
+        s.append(qString);
+      }
+
+      return s.toString();
+
+    }
+  }
+
+  /** Numerator. */
+  private Polynomial.Rational p;
+
+  /** Denominator. */
+  private Polynomial.Rational q;
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/algebra/PolynomialFraction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/algebra/PolynomialFraction.java
------------------------------------------------------------------------------
    svn:executable = *

Added: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/algebra/RationalNumber.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/algebra/RationalNumber.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/algebra/RationalNumber.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/algebra/RationalNumber.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,536 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.algebra;
+
+import java.math.BigInteger;
+/**
+ * This class implements reduced rational numbers.
+
+ * @version $Id: RationalNumber.java 1705 2006-09-17 19:57:39Z luc $
+ * @author L. Maisonobe
+
+ */
+
+public class RationalNumber {
+
+  /**
+   * Simple constructor.
+   * Build a null rational number
+   */
+  public RationalNumber() {
+    p = BigInteger.ZERO;
+    q = BigInteger.ONE;
+  }
+
+  /**
+   * Simple constructor.
+   * Build a rational number from a numerator and a denominator.
+   * @param numerator numerator of the rational number
+   * @param denominator denominator of the rational number
+   * @exception ArithmeticException if the denominator is zero
+   */
+  public RationalNumber(long numerator, long denominator) {
+    reset(numerator, denominator);
+  }
+
+  /**
+   * Simple constructor.
+   * Build a rational number from a numerator and a denominator.
+   * @param numerator numerator of the rational number
+   * @param denominator denominator of the rational number
+   * @exception ArithmeticException if the denominator is zero
+   */
+  public RationalNumber(BigInteger numerator, BigInteger denominator) {
+    reset(numerator, denominator);
+  }
+
+  /**
+   * Simple constructor.
+   * Build a rational number from a single integer
+   * @param l value of the rational number
+   */
+  public RationalNumber(long l) {
+    p = BigInteger.valueOf(l);
+    q = BigInteger.ONE;
+  }
+
+  /**
+   * Simple constructor.
+   * Build a rational number from a single integer
+   * @param i value of the rational number
+   */
+  public RationalNumber(BigInteger i) {
+    p = i;
+    q = BigInteger.ONE;
+  }
+
+  /**
+   * Copy-constructor.
+   * @param r rational number to copy
+   */
+  public RationalNumber(RationalNumber r) {
+    p = r.p;
+    q = r.q;
+  }
+
+  /** Reset the instance from a numerator and a denominator.
+   * @param numerator numerator of the rational number
+   * @param denominator denominator of the rational number
+   * @exception ArithmeticException if the denominator is zero
+   */
+  public void reset(long numerator, long denominator) {
+    if (denominator == 0l) {
+      throw new ArithmeticException("divide by zero");
+    }
+
+    p = BigInteger.valueOf(numerator);
+    q = BigInteger.valueOf(denominator);
+
+    if (q.signum() < 0) {
+      p = p.negate();
+      q = q.negate();
+    }
+
+    simplify();
+
+  }
+
+  /** Reset the instance from a numerator and a denominator.
+   * @param numerator numerator of the rational number
+   * @param denominator denominator of the rational number
+   * @exception ArithmeticException if the denominator is zero
+   */
+  public void reset(BigInteger numerator, BigInteger denominator) {
+    if (denominator.signum() == 0) {
+      throw new ArithmeticException("divide by zero");
+    }
+
+    p = numerator;
+    q = denominator;
+
+    if (q.signum() < 0) {
+      p = p.negate();
+      q = q.negate();
+    }
+
+    simplify();
+
+  }
+
+  /** Reset the instance from a single integer
+   * @param l value of the rational number
+   */
+  public void reset(long l) {
+    p = BigInteger.valueOf(l);
+    q = BigInteger.ONE;
+  }
+
+  /** Reset the instance from a single integer
+   * @param i value of the rational number
+   */
+  public void reset(BigInteger i) {
+    p = i;
+    q = BigInteger.ONE;
+  }
+
+  /** Reset the instance from another rational number.
+   * @param r rational number to copy
+   */
+  public void reset(RationalNumber r) {
+    p = r.p;
+    q = r.q;
+  }
+
+  /**
+   * Negate the instance
+   */
+  public void negateSelf() {
+    p = p.negate();
+  }
+
+  /**
+   * Negate a rational number.
+   * @param r rational number to negate
+   * @return a new rational number which is the opposite of r
+   */
+  public static RationalNumber negate(RationalNumber r) {
+    RationalNumber copy = new RationalNumber(r);
+    copy.negateSelf();
+    return copy;
+  }
+
+  /**
+   * Add a rational number to the instance.
+   * @param r rational number to add.
+   */
+  public void addToSelf(RationalNumber r) {
+    p = p.multiply(r.q).add(r.p.multiply(q));
+    q = q.multiply(r.q);
+    simplify();
+  }
+
+  /** Add two rational numbers.
+   * @param r1 first rational number
+   * @param r2 second rational number
+   * @return a new rational number which is the sum of r1 and r2
+   */
+  public static RationalNumber add(RationalNumber r1, RationalNumber r2) {
+    return new RationalNumber(r1.p.multiply(r2.q).add(r2.p.multiply(r1.q)),
+                              r1.q.multiply(r2.q));
+  }
+
+  /**
+   * Subtract a rational number to the instance.
+   * @param r rational number to subtract.
+   */
+  public void subtractFromSelf(RationalNumber r) {
+    p = p.multiply(r.q).subtract(r.p.multiply(q));
+    q = q.multiply(r.q);
+    simplify();
+  }
+
+  /** Subtract two rational numbers.
+   * @param r1 first rational number
+   * @param r2 second rational number
+   * @return a new rational number which is the difference r1 minus r2
+   */
+  public static RationalNumber subtract(RationalNumber r1, RationalNumber r2) {
+    return new RationalNumber(r1.p.multiply(r2.q).subtract(r2.p.multiply(r1.q)),
+                              r1.q.multiply(r2.q));
+  }
+
+  /** Multiply the instance by an integer.
+   * @param l integer to multiply by
+   */
+  public void multiplySelf(long l) {
+    p = p.multiply(BigInteger.valueOf(l));
+    simplify();
+  }
+
+  /** Multiply the instance by an integer.
+   * @param i integer to multiply by
+   */
+  public void multiplySelf(BigInteger i) {
+    p = p.multiply(i);
+    simplify();
+  }
+
+  /** Multiply a rational number by an integer.
+   * @param l integer to multiply by
+   */
+  public static RationalNumber multiply(RationalNumber r, long l) {
+    return new RationalNumber(r.p.multiply(BigInteger.valueOf(l)), r.q);
+  }
+
+  /** Multiply a rational number by an integer.
+   * @param i integer to multiply by
+   */
+  public static RationalNumber multiply(RationalNumber r, BigInteger i) {
+    return new RationalNumber(r.p.multiply(i), r.q);
+  }
+
+  /** Multiply the instance by a rational number.
+   * @param r rational number to multiply by
+   */
+  public void multiplySelf(RationalNumber r) {
+    p = p.multiply(r.p);
+    q = q.multiply(r.q);
+    simplify();
+  }
+
+  /** Multiply two rational numbers.
+   * @param r1 first rational number
+   * @param r2 second rational number
+   * @return a new rational number which is the product of r1 and r2
+   */
+  public static RationalNumber multiply(RationalNumber r1, RationalNumber r2) {
+    return new RationalNumber(r1.p.multiply(r2.p),
+                              r1.q.multiply(r2.q));
+  }
+
+  /** Divide the instance by an integer.
+   * @param l integer to divide by
+   * @exception ArithmeticException if l is zero
+   */
+  public void divideSelf(long l) {
+
+    if (l == 0l) {
+      throw new ArithmeticException("divide by zero");
+    } else if (l > 0l) {
+      q = q.multiply(BigInteger.valueOf(l));
+    } else {
+      p = p.negate();
+      q = q.multiply(BigInteger.valueOf(-l));
+    }
+
+    simplify();
+
+  }
+
+  /** Divide the instance by an integer.
+   * @param i integer to divide by
+   * @exception ArithmeticException if l is zero
+   */
+  public void divideSelf(BigInteger i) {
+
+    if (i.signum() == 0) {
+      throw new ArithmeticException("divide by zero");
+    } else if (i.signum() > 0) {
+      q = q.multiply(i);
+    } else {
+      p = p.negate();
+      q = q.multiply(i.negate());
+    }
+
+    simplify();
+
+  }
+
+  /** Divide a rational number by an integer
+   * @param r rational number
+   * @param l integer
+   * @return a new rational number which is the quotient of r by l
+   * @exception ArithmeticException if l is zero
+   */
+  public static RationalNumber divide(RationalNumber r, long l) {
+    RationalNumber copy = new RationalNumber(r);
+    copy.divideSelf(l);
+    return copy;
+  }
+
+  /** Divide a rational number by an integer
+   * @param r rational number
+   * @param i integer
+   * @return a new rational number which is the quotient of r by l
+   * @exception ArithmeticException if l is zero
+   */
+  public static RationalNumber divide(RationalNumber r, BigInteger i) {
+    RationalNumber copy = new RationalNumber(r);
+    copy.divideSelf(i);
+    return copy;
+  }
+
+  /** Divide the instance by a rational number.
+   * @param r rational number to divide by
+   * @exception ArithmeticException if r is zero
+   */
+  public void divideSelf(RationalNumber r) {
+
+    if (r.p.signum() == 0) {
+      throw new ArithmeticException("divide by zero");
+    }
+
+    p = p.multiply(r.q);
+    q = q.multiply(r.p);
+
+    if (q.signum() < 0) {
+      p = p.negate();
+      q = q.negate();
+    }
+
+    simplify();
+
+  }
+
+  /** Divide two rational numbers.
+   * @param r1 first rational number
+   * @param r2 second rational number
+   * @return a new rational number which is the quotient of r1 by r2
+   * @exception ArithmeticException if r2 is zero
+   */
+  public static RationalNumber divide(RationalNumber r1, RationalNumber r2) {
+    RationalNumber copy = new RationalNumber(r1);
+    copy.divideSelf(r2);
+    return copy;
+  }
+
+  /** Invert the instance.
+   * Replace the instance by its inverse.
+   * @exception ArithmeticException if the instance is zero
+   */
+  public void invertSelf() {
+
+    if (p.signum() == 0) {
+      throw new ArithmeticException("divide by zero");
+    }
+
+    BigInteger tmp = p;
+    p = q;
+    q = tmp;
+
+    if (q.signum() < 0) {
+      p = p.negate();
+      q = q.negate();
+    }
+
+  }
+
+  /** Invert a rational number.
+   * @param r rational number to invert
+   * @return a new rational number which is the inverse of r
+   * @exception ArithmeticException if r is zero
+   */
+  public static RationalNumber invert(RationalNumber r) {
+    return new RationalNumber(r.q, r.p);
+  }
+
+  /**
+   * Add the product of two rational numbers to the instance.
+   * This operation is equivalent to
+   * <code>addToSelf(RationalNumber.multiply(r1, r2))</code> except
+   * that no intermediate simplification is attempted.
+   * @param r1 first term of the product to add
+   * @param r2 second term of the product to add
+   */
+  public void multiplyAndAddToSelf(RationalNumber r1, RationalNumber r2) {
+    BigInteger r1qr2q = r1.q.multiply(r2.q);
+    p = p.multiply(r1qr2q).add(r1.p.multiply(r2.p).multiply(q));
+    q = q.multiply(r1qr2q);
+    simplify();
+  }
+
+  /**
+   * Subtract the product of two rational numbers from the instance.
+   * This operation is equivalent to
+   * <code>subtractFromSelf(RationalNumber.multiply(r1, r2))</code>
+   * except that no intermediate simplification is attempted.
+   * @param r1 first term of the product to subtract
+   * @param r2 second term of the product to subtract
+   */
+  public void multiplyAndSubtractFromSelf(RationalNumber r1, RationalNumber r2) {
+    BigInteger r1qr2q = r1.q.multiply(r2.q);
+    p = p.multiply(r1qr2q).subtract(r1.p.multiply(r2.p).multiply(q));
+    q = q.multiply(r1qr2q);
+    simplify();
+  }
+
+  /** Simplify a rational number by removing common factors.
+   */
+  private void simplify() {
+    if (p.signum() == 0) {
+      q = BigInteger.ONE;
+    } else {
+      BigInteger gcd = p.gcd(q);
+      p = p.divide(gcd);
+      q = q.divide(gcd);
+    }
+  }
+
+  /**
+   * Get the numerator.
+   * @return the signed numerator
+   */
+  public BigInteger getNumerator() {
+    return p;
+  }
+
+  /**
+   * Get the denominator.
+   * @return the denominator (always positive)
+   */
+  public BigInteger getDenominator() {
+    return q;
+  }
+
+  /** Check if the number is zero.
+   * @return true if the number is zero
+   */
+  public boolean isZero() {
+    return p.signum() == 0;
+  }
+
+  /** Check if the number is one.
+   * @return true if the number is one
+   */
+  public boolean isOne() {
+    return (p.compareTo(BigInteger.ONE) == 0)
+        && (q.compareTo(BigInteger.ONE) == 0);
+  }
+
+  /** Check if the number is integer.
+   * @return true if the number is an integer
+   */
+  public boolean isInteger() {
+    return q.compareTo(BigInteger.ONE) == 0;
+  }
+
+  /** Check if the number is negative.
+   * @return true if the number is negative
+   */
+  public boolean isNegative() {
+    return p.signum() < 0;
+  }
+
+  /** Get the absolute value of a rational number.
+   * @param r rational number from which we want the absolute value
+   * @return a new rational number which is the absolute value of r
+   */
+  public static RationalNumber abs(RationalNumber r) {
+    return new RationalNumber(r.p.abs(), r.q);
+  }
+
+  /** Return the <code>double</code> value of the instance.
+   * @return the double value of the instance
+   */
+  public double doubleValue() {
+    BigInteger[] result = p.divideAndRemainder(q);
+    return result[0].doubleValue()
+        + (result[1].doubleValue() / q.doubleValue());
+  }
+
+  /** Check if the instance is equal to another rational number.
+   * Equality here is having the same value.
+   * @return true if the object is a rational number which has the
+   * same value as the instance
+   */
+  public boolean equals(Object o) {
+    if (o instanceof RationalNumber) {
+      RationalNumber r = (RationalNumber) o;
+      return (p.compareTo(r.p) == 0) && (q.compareTo(r.q) == 0);
+    }
+    return false;
+  }
+
+  /** Returns a hash code value for the object.
+   * The hash code value is computed from the reduced numerator and
+   * denominator, hence equal rational numbers have the same hash code,
+   * as required by the method specification.
+   * @return a hash code value for this object.
+   */
+  public int hashCode() {
+    return p.hashCode() ^ q.hashCode();
+  }
+
+  /** Returns a string representation of the rational number.
+   * The representation is reduced: there is no common factor left
+   * between the numerator and the denominator. The '/' character and
+   * the denominator are displayed only if the denominator is not
+   * one. The sign is on the numerator.
+   * @return string representation of the rational number
+   */
+  public String toString() {
+    return p + ((q.compareTo(BigInteger.ONE) == 0) ? "" : ("/" + q));
+  }
+
+  /** Numerator. */
+  private BigInteger p;
+
+  /** Denominator. */
+  private BigInteger q;
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/algebra/RationalNumber.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/EstimatedParameter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/EstimatedParameter.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/EstimatedParameter.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/EstimatedParameter.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,123 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.estimation;
+
+import java.io.Serializable;
+
+/** This class represent the estimated parameters of an estimation problem.
+
+ * <p>The parameters of an estimation problem have a name, a value and
+ * a bound flag. The value of bound parameters is considered trusted
+ * and the solvers should not adjust them. On the other hand, the
+ * solvers should adjust the value of unbounds parameters until they
+ * satisfy convergence criterions specific to each solver.</p>
+
+ * @version $Id: EstimatedParameter.java 1705 2006-09-17 19:57:39Z luc $
+ * @author L. Maisonobe
+
+ */
+
+public class EstimatedParameter
+  implements Serializable {
+
+  /** Simple constructor.
+   * Build an instance from a first estimate of the parameter,
+   * initially considered unbound.
+   * @param name name of the parameter
+   * @param firstEstimate first estimate of the parameter
+   */
+  public EstimatedParameter(String name, double firstEstimate) {
+    this.name = name;
+    estimate  = firstEstimate;
+    bound     = false;
+  }
+
+  /** Simple constructor.
+   * Build an instance from a first estimate of the parameter and a
+   * bound flag
+   * @param name name of the parameter
+   * @param firstEstimate first estimate of the parameter
+   * @param bound flag, should be true if the parameter is bound
+   */
+  public EstimatedParameter(String name,
+                            double firstEstimate,
+                            boolean bound) {
+    this.name  = name;
+    estimate   = firstEstimate;
+    this.bound = bound;
+  }
+
+  /** Copy constructor.
+   * Build a copy of a parameter
+   * @param parameter instance to copy
+   */
+  public EstimatedParameter(EstimatedParameter parameter) {
+    name     = parameter.name;
+    estimate = parameter.estimate;
+    bound    = parameter.bound;
+  }
+
+  /** Set a new estimated value for the parameter.
+   * @param estimate new estimate for the parameter
+   */
+  public void setEstimate(double estimate) {
+    this.estimate = estimate;
+  }
+
+  /** Get the current estimate of the parameter
+   * @return current estimate
+   */
+  public double getEstimate() {
+    return estimate;
+  }
+
+  /** get the name of the parameter
+   * @return parameter name
+   */
+  public String getName() {
+    return name;
+  }
+
+  /** Set the bound flag of the parameter
+   * @param bound this flag should be set to true if the parameter is
+   * bound (i.e. if it should not be adjusted by the solver).
+   */
+  public void setBound(boolean bound) {
+    this.bound = bound;
+  }
+
+  /** Check if the parameter is bound
+   * @return true if the parameter is bound */
+  public boolean isBound() {
+    return bound;
+  }
+
+  /** Name of the parameter */
+  private   String  name;
+
+  /** Current value of the parameter */
+  protected double  estimate;
+
+  /** Indicator for bound parameters
+   * (ie parameters that should not be estimated)
+   */
+  private   boolean bound;
+
+  private static final long serialVersionUID = -555440800213416949L;
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/EstimatedParameter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/EstimationException.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/EstimationException.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/EstimationException.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/EstimationException.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,59 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.estimation;
+
+import org.spaceroots.mantissa.MantissaException;
+
+/** This class represents exceptions thrown by the estimation solvers.
+
+ * @version $Id: EstimationException.java 1705 2006-09-17 19:57:39Z luc $
+ * @author L. Maisonobe
+
+ */
+
+public class EstimationException
+  extends MantissaException {
+
+  /** Simple constructor.
+   * Build an exception by translating the specified message
+   * @param message message to translate
+   */
+  public EstimationException(String message) {
+    super(message);
+  }
+
+  /** Simple constructor.
+   * Build an exception by translating and formating a message
+   * @param specifier format specifier (to be translated)
+   * @param parts to insert in the format (no translation)
+   */
+  public EstimationException(String specifier, String[] parts) {
+    super(specifier, parts);
+  }
+
+  /** Simple constructor.
+   * Build an exception from a cause
+   * @param cause cause of this exception
+   */
+  public EstimationException(Throwable cause) {
+    super(cause);
+  }
+
+  private static final long serialVersionUID = 1613719630569355278L;
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/EstimationException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/EstimationProblem.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/EstimationProblem.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/EstimationProblem.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/EstimationProblem.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,61 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.estimation;
+
+/** This interface represents an estimation problem.
+
+ * <p>This interface should be implemented by all real estimation
+ * problems before they can be handled by the estimators through the
+ * {@link Estimator#estimate Estimator.estimate} method.</p>
+
+ * <p>An estimation problem, as seen by a solver is a set of
+ * parameters and a set of measurements. The parameters are adjusted
+ * during the estimation through the {@link #getUnboundParameters
+ * getUnboundParameters} and {@link EstimatedParameter#setEstimate
+ * EstimatedParameter.setEstimate} methods. The measurements both have
+ * a measured value which is generally fixed at construction and a
+ * theoretical value which depends on the model and hence varies as
+ * the parameters are adjusted. The purpose of the solver is to reduce
+ * the residual between these values, it can retrieve the measurements
+ * through the {@link #getMeasurements getMeasurements} method.</p>
+
+ * @see Estimator
+ * @see WeightedMeasurement
+
+ * @version $Id: EstimationProblem.java 1705 2006-09-17 19:57:39Z luc $
+ * @author L. Maisonobe
+
+ */
+
+public interface EstimationProblem {
+  /** Get the measurements of an estimation problem.
+   * @return measurements
+   */
+  public WeightedMeasurement[] getMeasurements();
+
+  /** Get the unbound parameters of the problem.
+   * @return unbound parameters
+   */
+  public EstimatedParameter[] getUnboundParameters();
+
+  /** Get all the parameters of the problem.
+   * @return parameters
+   */
+  public EstimatedParameter[] getAllParameters();
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/EstimationProblem.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/Estimator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/Estimator.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/Estimator.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/Estimator.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,66 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.estimation;
+
+/** This interface represents solvers for estimation problems.
+
+ * <p>The classes which are devoted to solve estimation problems
+ * should implement this interface. The problems which can be handled
+ * should implement the {@link EstimationProblem} interface which
+ * gather all the information needed by the solver.</p>
+
+ * <p>The interface is composed only of the {@link #estimate estimate}
+ * method.</p>
+
+ * @see EstimationProblem
+
+ * @version $Id: Estimator.java 1705 2006-09-17 19:57:39Z luc $
+ * @author L. Maisonobe
+
+ */
+
+public interface Estimator {
+
+  /** Solve an estimation problem.
+
+   * <p>The method should set the parameters of the problem to several
+   * trial values until it reaches convergence. If this method returns
+   * normally (i.e. without throwing an exception), then the best
+   * estimate of the parameters can be retrieved from the problem
+   * itself, through the {@link EstimationProblem#getAllParameters
+   * EstimationProblem.getAllParameters} method.</p>
+
+   * @param problem estimation problem to solve
+   * @exception EstimationException if the problem cannot be solved
+
+   */
+  public void estimate(EstimationProblem problem)
+    throws EstimationException;
+
+  /** Get the Root Mean Square value.
+   * Get the Root Mean Square value, i.e. the root of the arithmetic
+   * mean of the square of all weighted residuals. This is related to the
+   * criterion that is minimized by the estimator as follows: if
+   * <em>c</em> if the criterion, and <em>n</em> is the number of
+   * measurements, the the RMS is <em>sqrt (c/n)</em>.
+   * @param problem estimation problem
+   * @return RMS value
+   */
+  public double getRMS(EstimationProblem problem);
+ 
+}

Propchange: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/Estimator.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message