You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2008/04/15 15:16:50 UTC

svn commit: r648234 - in /commons/sandbox/nabla/trunk/src: ./ main/ main/java/ main/java/org/ main/java/org/apache/ main/java/org/apache/commons/ main/java/org/apache/commons/nabla/ main/java/org/apache/commons/nabla/core/

Author: luc
Date: Tue Apr 15 06:16:43 2008
New Revision: 648234

URL: http://svn.apache.org/viewvc?rev=648234&view=rev
Log:
created Nabla core API components

Added:
    commons/sandbox/nabla/trunk/src/
    commons/sandbox/nabla/trunk/src/main/
    commons/sandbox/nabla/trunk/src/main/java/
    commons/sandbox/nabla/trunk/src/main/java/org/
    commons/sandbox/nabla/trunk/src/main/java/org/apache/
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/NablaMath.java   (with props)
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/NablaStrictMath.java   (with props)
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/DifferentialPair.java   (with props)
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/DifferentiationException.java   (with props)
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/NablaException.java   (with props)
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/UnivariateDerivative.java   (with props)
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/UnivariateDifferentiable.java   (with props)
    commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/UnivariateDifferentiator.java   (with props)

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/NablaMath.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/NablaMath.java?rev=648234&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/NablaMath.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/NablaMath.java Tue Apr 15 06:16:43 2008
@@ -0,0 +1,613 @@
+/*
+ * 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.apache.commons.nabla;
+
+import org.apache.commons.nabla.core.DifferentialPair;
+
+/** <code>Math</code>-like utility class computing differentials.
+ * <p>This class provides mathematical functions similar to the functions
+ * provided by the standard <code>java.lang.Math</code> class but
+ * using {@link org.apache.commons.nabla.core.DifferentialPair DifferentialPair}
+ * instances instead of doubles.</p>
+ */
+public class NablaMath {
+
+    /** Hidden constructor.
+     * <p>Since this class is a utility class, it cannot be instantiated.</p>
+     */
+    private NablaMath() {
+    }
+
+    ///////////////////////////
+    // exponential functions //
+    ///////////////////////////
+
+    /** Exponential function.
+     * @param a function input value
+     * @return e<sup>a</sup>
+     */
+    public static DifferentialPair exp(final DifferentialPair a) {
+        final double e = Math.exp(a.getU0());
+        return new DifferentialPair(e, a.getU1() * e);
+    }
+
+    /** Exponential minus 1 function.
+     * @param a function input value
+     * @return e<sup>a</sup>-1
+     */
+    public static DifferentialPair expm1(final DifferentialPair a) {
+        final double e = Math.expm1(a.getU0());
+        return new DifferentialPair(e, a.getU1() * (e + 1));
+    }
+
+    /** Natural logarithm function.
+     * @param a function input value
+     * @return log(a)
+     */
+    public static DifferentialPair log(final DifferentialPair a) {
+        final double a0 = a.getU0();
+        return new DifferentialPair(Math.log(a0), a.getU1() / a0);
+    }
+
+    /** Shifted natural logarithm function.
+     * @param a function input value
+     * @return log(1+a)
+     */
+    public static DifferentialPair log1p(final DifferentialPair a) {
+        final double a0 = a.getU0();
+        return new DifferentialPair(Math.log1p(a0), a.getU1() / (1 + a0));
+    }
+
+    /** Base 10 logarithm function.
+     * @param a function input value
+     * @return log<sub>10</sub>(a)
+     */
+    public static DifferentialPair log10(final DifferentialPair a) {
+        final double a0 = a.getU0();
+        return new DifferentialPair(Math.log10(a0), a.getU1() / (a0 * Math.log(10)));
+    }
+
+
+    ////////////////////////
+    // circular functions //
+    ////////////////////////
+
+    /** Cosine function.
+     * @param a function input value
+     * @return cos(a)
+     */
+    public static DifferentialPair cos(final DifferentialPair a) {
+        final double a0 = a.getU0();
+        return new DifferentialPair(Math.cos(a0), -a.getU1() * Math.sin(a0));
+    }
+
+    /** Sine function.
+     * @param a function input value
+     * @return sin(a)
+     */
+    public static DifferentialPair sin(final DifferentialPair a) {
+        final double a0 = a.getU0();
+        return new DifferentialPair(Math.sin(a0), a.getU1() * Math.cos(a0));
+    }
+
+    /** Tangent function.
+     * @param a function input value
+     * @return tan(a)
+     */
+    public static DifferentialPair tan(final DifferentialPair a) {
+        final double t = Math.tan(a.getU0());
+        return new DifferentialPair(t, a.getU1() * (1 + t * t));
+    }
+
+    /** Inverse cosine function.
+     * @param a function input value
+     * @return acos(a)
+     */
+    public static DifferentialPair acos(final DifferentialPair a) {
+        final double a0 = a.getU0();
+        return new DifferentialPair(Math.acos(a0), -a.getU1() / Math.sqrt(1 - a0 * a0));
+    }
+
+    /** Inverse sine function.
+     * @param a function input value
+     * @return asin(a)
+     */
+    public static DifferentialPair asin(final DifferentialPair a) {
+        final double a0 = a.getU0();
+        return new DifferentialPair(Math.asin(a0), a.getU1() / Math.sqrt(1 - a0 * a0));
+    }
+
+    /** Inverse tangent function.
+     * @param a function input value
+     * @return atan(a)
+     */
+    public static DifferentialPair atan(final DifferentialPair a) {
+        final double a0 = a.getU0();
+        return new DifferentialPair(Math.atan(a0), a.getU1() / (1 + a0 * a0));
+    }
+
+
+    /////////////////////////////////
+    // cartesian/polar conversions //
+    ////////////////////////////////
+
+    /** Cartesian to polar conversion function.
+     * @param y cartesian ordinate of the point
+     * @param x cartesian abscissa of the point
+     * @return angular part of the polar coordinates of the point
+     */
+    public static DifferentialPair atan2(final DifferentialPair y, final double x) {
+        final double y0 = y.getU0();
+        return new DifferentialPair(Math.atan2(y0, x),
+                                    x * y.getU1() / (x * x + y0 * y0));
+    }
+
+    /** Cartesian to polar conversion function.
+     * @param y cartesian ordinate of the point
+     * @param x cartesian abscissa of the point
+     * @return angular part of the polar coordinates of the point
+     */
+    public static DifferentialPair atan2(final double y, final DifferentialPair x) {
+        final double x0 = x.getU0();
+        return new DifferentialPair(Math.atan2(y, x0),
+                                    -y * x.getU1() / (x0 * x0 + y * y));
+    }
+
+    /** Cartesian to polar conversion function.
+     * @param y cartesian ordinate of the point
+     * @param x cartesian abscissa of the point
+     * @return angular part of the polar coordinates of the point
+     */
+    public static DifferentialPair atan2(final DifferentialPair y, final DifferentialPair x) {
+        final double y0 = y.getU0();
+        final double x0 = x.getU0();
+        return new DifferentialPair(Math.atan2(y0, x0),
+                                    (x0 * y.getU1() - y0 * x.getU1()) / (x0 * x0 + y0 * y0));
+    }
+
+    /** Cartesian to polar conversion function.
+     * @param x cartesian abscissa of the point
+     * @param y cartesian ordinate of the point
+     * @return radius part of the polar coordinates of the point
+     */
+    public static DifferentialPair hypot(final DifferentialPair x, final double y) {
+        final double x0 = x.getU0();
+        final double h = Math.hypot(x0, y);
+        return new DifferentialPair(h, x0 * x.getU1() / h);
+    }
+
+    /** Cartesian to polar conversion function.
+     * @param x cartesian abscissa of the point
+     * @param y cartesian ordinate of the point
+     * @return radius part of the polar coordinates of the point
+     */
+    public static DifferentialPair hypot(final double x, final DifferentialPair y) {
+        final double y0 = y.getU0();
+        final double h = Math.hypot(x, y0);
+        return new DifferentialPair(h, y0 * y.getU1() / h);
+    }
+
+    /** Cartesian to polar conversion function.
+     * @param x cartesian abscissa of the point
+     * @param y cartesian ordinate of the point
+     * @return radius part of the polar coordinates of the point
+     */
+    public static DifferentialPair hypot(final DifferentialPair x, final DifferentialPair y) {
+        final double x0 = x.getU0();
+        final double y0 = y.getU0();
+        final double h = Math.hypot(x0, y0);
+        return new DifferentialPair(h, (x0 * x.getU1() + y0 * y.getU1()) / h);
+    }
+
+
+    //////////////////////////
+    // hyperbolic functions //
+    //////////////////////////
+
+    /** Hyperbolic cosine function.
+     * @param a function input value
+     * @return cosh(a)
+     */
+    public static DifferentialPair cosh(final DifferentialPair a) {
+        final double a0 = a.getU0();
+        return new DifferentialPair(Math.cosh(a0), a.getU1() * Math.sinh(a0));
+    }
+
+    /** Hyperbolic sine function.
+     * @param a function input value
+     * @return sinh(a)
+     */
+    public static DifferentialPair sinh(final DifferentialPair a) {
+        final double a0 = a.getU0();
+        return new DifferentialPair(Math.sinh(a0), a.getU1() * Math.cosh(a0));
+    }
+
+    /** Hyperbolic tangent function.
+     * @param a function input value
+     * @return tanh(a)
+     */
+    public static DifferentialPair tanh(final DifferentialPair a) {
+        final double t = Math.tanh(a.getU0());
+        return new DifferentialPair(t, a.getU1() * (1 - t * t));
+    }
+
+    /** Inverse hyperbolic cosine function.
+     * @param a function input value
+     * @return acosh(a)
+     */
+    public static DifferentialPair acosh(final DifferentialPair a) {
+        // the acosh function is not provided by java.lang.Math as of Java6
+        final double a0 = a.getU0();
+        final double root = Math.sqrt(a0 - 1) * Math.sqrt(a0 + 1);
+        return new DifferentialPair(Math.log(a0 + root), a.getU1() / root);
+    }
+
+    /** Inverse hyperbolic sine function.
+     * @param a function input value
+     * @return asinh(a)
+     */
+    public static DifferentialPair asinh(final DifferentialPair a) {
+        // the asinh function is not provided by java.lang.Math as of Java6
+        final double a0 = a.getU0();
+        final double root = Math.sqrt(a0 * a0 + 1);
+        return new DifferentialPair(Math.log(a0 + root), a.getU1() / root);
+    }
+
+    /** Inverse hyperbolic tangent function.
+     * @param a function input value
+     * @return atanh(a)
+     */
+    public static DifferentialPair atanh(final DifferentialPair a) {
+        // the atanh function is not provided by java.lang.Math as of Java6
+        final double a0 = a.getU0();
+        final double ath = (Math.log1p(a0) - Math.log1p(-a0)) / 2;
+        return new DifferentialPair(ath, a.getU1() / (1 - a0 * a0));
+    }
+
+    /////////////////////
+    // power functions //
+    /////////////////////
+
+    /** Square root function.
+     * @param a function input value
+     * @return &sqrt;a
+     */
+    public static DifferentialPair sqrt(final DifferentialPair a) {
+        final double root = Math.sqrt(a.getU0());
+        return new DifferentialPair(root, a.getU1() / (2 * root));
+    }
+
+    /** Cubic root function.
+     * @param a function input value
+     * @return cbrt(a)
+     */
+    public static DifferentialPair cbrt(final DifferentialPair a) {
+        final double root = Math.cbrt(a.getU0());
+        return new DifferentialPair(root, a.getU1() / (3 * root * root));
+    }
+
+    /** Power function.
+     * @param a base value
+     * @param b exponent value
+     * @return a<sup>b</sup>
+     */
+    public static DifferentialPair pow(final DifferentialPair a, final double b) {
+        final double a0 = a.getU0();
+        final double p = Math.pow(a0, b);
+        return new DifferentialPair(p, a.getU1() * b * p / a0);
+    }
+
+    /** Power function.
+     * @param a base value
+     * @param b exponent value
+     * @return a<sup>b</sup>
+     */
+    public static DifferentialPair pow(final double a, final DifferentialPair b) {
+        final double p = Math.pow(a, b.getU0());
+        return new DifferentialPair(p, b.getU1() * Math.log(a) * p);
+    }
+
+    /** Power function.
+     * @param a base value
+     * @param b exponent value
+     * @return a<sup>b</sup>
+     */
+    public static DifferentialPair pow(final DifferentialPair a, final DifferentialPair b) {
+        final double a0 = a.getU0();
+        final double b0 = b.getU0();
+        final double p = Math.pow(a0, b0);
+        return new DifferentialPair(p, (a.getU1() * b0 / a0 + b.getU1() * Math.log(a0)) * p);
+    }
+
+
+    ////////////////////////////
+    // sign related functions //
+    ////////////////////////////
+
+    /** Absolute value function.
+     * @param a function input value
+     * @return |a|
+     */
+    public static DifferentialPair abs(final DifferentialPair a) {
+        return (a.getU0() >= 0) ? a : DifferentialPair.negate(a);
+    }
+
+    /** Sign function.
+     * @param a function input value
+     * @return -1, 0 or +1 according to the sign of a
+     */
+    public static DifferentialPair signum(final DifferentialPair a) {
+        return DifferentialPair.newConstant(Math.signum(a.getU0()));
+    }
+
+    /** Sign copy function.
+     * @param magnitude function input value
+     * @param sign sign reference
+     * @return either magnitude or -magnitude to match sign
+     */
+    public static DifferentialPair copySign(final DifferentialPair magnitude,
+                                            final double sign) {
+        final long mBits = Double.doubleToLongBits(magnitude.getU0());
+        final long sBits = Double.doubleToLongBits(sign);
+        return (((mBits ^ sBits) & 0x8000000000000000L) == 0) ?
+                magnitude : DifferentialPair.negate(magnitude);
+    }
+
+    /** Sign copy function.
+     * @param magnitude function input value
+     * @param sign sign reference
+     * @return either magnitude or -magnitude to match sign
+     */
+    public static DifferentialPair copySign(final double magnitude,
+                                            final DifferentialPair sign) {
+        final long mBits = Double.doubleToLongBits(magnitude);
+        final long sBits = Double.doubleToLongBits(sign.getU0());
+        return (((mBits ^ sBits) & 0x8000000000000000L) == 0) ?
+               DifferentialPair.newConstant(magnitude) :
+               DifferentialPair.newConstant(-magnitude);
+    }
+
+    /** Sign copy function.
+     * @param magnitude function input value
+     * @param sign sign reference
+     * @return either magnitude or -magnitude to match sign
+     */
+    public static DifferentialPair copySign(final DifferentialPair magnitude,
+                                            final DifferentialPair sign) {
+        final long mBits = Double.doubleToLongBits(magnitude.getU0());
+        final long sBits = Double.doubleToLongBits(sign.getU0());
+        return (((mBits ^ sBits) & 0x8000000000000000L) == 0) ?
+                magnitude : DifferentialPair.negate(magnitude);
+    }
+
+
+    ////////////////////////////
+    // neighborhood functions //
+    ////////////////////////////
+
+    /** Floor function.
+     * @param a function input value
+     * @return largest integer value smaller than a or equal to a
+     */
+    public static DifferentialPair floor(final DifferentialPair a) {
+        return DifferentialPair.newConstant(Math.floor(a.getU0()));
+    }
+
+    /** Rounding function.
+     * @param a function input value
+     * @return closest integer value to a
+     */
+    public static DifferentialPair rint(final DifferentialPair a) {
+        return DifferentialPair.newConstant(Math.rint(a.getU0()));
+    }
+
+    /** Ceil function.
+     * @param a function input value
+     * @return smallest integer value greater than a or equal to a
+     */
+    public static DifferentialPair ceil(final DifferentialPair a) {
+        return DifferentialPair.newConstant(Math.ceil(a.getU0()));
+    }
+
+    /** Neighbor function.
+     * @param a function input value
+     * @return smallest representable double value ly greater than a
+     */
+    public static DifferentialPair nextUp(final DifferentialPair a) {
+        return new DifferentialPair(Math.nextUp(a.getU0()), a.getU1());
+    }
+
+    /** Neighbor function.
+     * @param start function input value
+     * @param direction direction of neighboring (relative to a)
+     * @return closest double value different than a in given direction
+     */
+    public static DifferentialPair nextAfter(final DifferentialPair start,
+                                             final double direction) {
+        return new DifferentialPair(Math.nextAfter(start.getU0(), direction),
+                                    start.getU1());
+    }
+
+    /** Neighbor function.
+     * @param start function input value
+     * @param direction direction of neighboring (relative to a)
+     * @return closest double value different than a in given direction
+     */
+    public static DifferentialPair nextAfter(final double start,
+                                             final DifferentialPair direction) {
+        return DifferentialPair.newConstant(Math.nextAfter(start, direction.getU0()));
+    }
+
+    /** Neighbor function.
+     * @param start function input value
+     * @param direction direction of neighboring (relative to a)
+     * @return closest double value different than a in given direction
+     */
+    public static DifferentialPair nextAfter(final DifferentialPair start,
+                                             final DifferentialPair direction) {
+        return new DifferentialPair(Math.nextAfter(start.getU0(), direction.getU0()), start.getU1());
+    }
+
+
+    ////////////////////////
+    // encoding functions //
+    ////////////////////////
+
+    /** Unit in Last Position function.
+     * @param a function input value
+     * @return value of the least significant bit of a
+     */
+    public static DifferentialPair ulp(final DifferentialPair a) {
+        return DifferentialPair.newConstant(Math.ulp(a.getU0()));
+    }
+
+    /** Binary rescaling function.
+     * @param a function input value
+     * @param scale exponent part of the 2<sup>scale</sup> multiplication factor
+     * @return a &times; 2<sup>scale</sup>
+     */
+    public static DifferentialPair scalb(final DifferentialPair a,
+                                         final int scale) {
+        return new DifferentialPair(Math.scalb(a.getU0(), scale),
+                                    Math.scalb(a.getU1(), scale));
+    }
+
+    /** Remainder function.
+     * @param f1 dividend
+     * @param f2 divisor
+     * @return remainder of f1/f2, following IEEE754 conventions
+     */
+    public static DifferentialPair IEEEremainder(final DifferentialPair f1,
+                                                 final double f2) {
+        final double r = Math.IEEEremainder(f1.getU0(), f2);
+        return new DifferentialPair(r, f1.getU1());
+    }
+
+    /** Remainder function.
+     * @param f1 dividend
+     * @param f2 divisor
+     * @return remainder of f1/f2, following IEEE754 conventions
+     */
+    public static DifferentialPair IEEEremainder(final double f1,
+                                                 final DifferentialPair f2) {
+        final double f20 = f2.getU0();
+        final double r = Math.IEEEremainder(f1, f20);
+        final int n = (int) ((r - f1) / f20);
+        return new DifferentialPair(r, n * f2.getU1());
+    }
+
+    /** Remainder function.
+     * @param f1 dividend
+     * @param f2 divisor
+     * @return remainder of f1/f2, following IEEE754 conventions
+     */
+    public static DifferentialPair IEEEremainder(final DifferentialPair f1,
+                                                 final DifferentialPair f2) {
+        final double f10 = f1.getU0();
+        final double f20 = f2.getU0();
+        final double r = Math.IEEEremainder(f10, f20);
+        final int n = (int) ((r - f10) / f20);
+        return new DifferentialPair(r, f1.getU1() + n * f2.getU1());
+    }
+
+
+    //////////////////////////
+    // conversion functions //
+    //////////////////////////
+
+    /** Angular conversion function.
+     * @param a angle in radians
+     * @return angle converted to degrees
+     */
+    public static DifferentialPair toDegrees(final DifferentialPair a) {
+        return new DifferentialPair(Math.toDegrees(a.getU0()), Math.toDegrees(a.getU1()));
+    }
+
+    /** Angular conversion function.
+     * @param a angle in degrees
+     * @return angle converted to radians
+     */
+    public static DifferentialPair toRadians(final DifferentialPair a) {
+        return new DifferentialPair(Math.toRadians(a.getU0()), Math.toRadians(a.getU1()));
+    }
+
+
+    //////////////////////////
+    // comparison functions //
+    //////////////////////////
+
+    /** Max function.
+     * @param a first function input value
+     * @param b second function input value
+     * @return maximal value from the (a, b) pair
+     */
+    public static DifferentialPair max(final DifferentialPair a,
+                                       final double b) {
+        return (a.getU0() >= b) ? a : DifferentialPair.newConstant(b);
+    }
+
+    /** Max function.
+     * @param a first function input value
+     * @param b second function input value
+     * @return maximal value from the (a, b) pair
+     */
+    public static DifferentialPair max(final double a,
+                                       final DifferentialPair b) {
+        return (b.getU0() >= a) ? b : DifferentialPair.newConstant(a);
+    }
+
+    /** Max function.
+     * @param a first function input value
+     * @param b second function input value
+     * @return maximal value from the (a, b) pair
+     */
+    public static DifferentialPair max(final DifferentialPair a,
+                                       final DifferentialPair b) {
+        return (a.getU0() >= b.getU0()) ? a : b;
+    }
+
+    /** Min function.
+     * @param a first function input value
+     * @param b second function input value
+     * @return minimal value from the (a, b) pair
+     */
+    public static DifferentialPair min(final DifferentialPair a,
+                                       final double b) {
+        return (a.getU0() <= b) ? a : DifferentialPair.newConstant(b);
+    }
+
+    /** Min function.
+     * @param a first function input value
+     * @param b second function input value
+     * @return minimal value from the (a, b) pair
+     */
+    public static DifferentialPair min(final double a,
+                                       final DifferentialPair b) {
+        return (b.getU0() <= a) ? b : DifferentialPair.newConstant(a);
+    }
+
+    /** Min function.
+     * @param a first function input value
+     * @param b second function input value
+     * @return minimal value from the (a, b) pair
+     */
+    public static DifferentialPair min(final DifferentialPair a,
+                                       final DifferentialPair b) {
+        return (a.getU0() <= b.getU0()) ? a : b;
+    }
+
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/NablaMath.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/NablaStrictMath.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/NablaStrictMath.java?rev=648234&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/NablaStrictMath.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/NablaStrictMath.java Tue Apr 15 06:16:43 2008
@@ -0,0 +1,613 @@
+/*
+ * 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.apache.commons.nabla;
+
+import org.apache.commons.nabla.core.DifferentialPair;
+
+/** <code>StrictMath</code>-like utility class computing differentials.
+ * <p>This class provides mathematical functions similar to the functions
+ * provided by the standard <code>java.lang.StrictMath</code> class but
+ * using {@link org.apache.commons.nabla.core.DifferentialPair DifferentialPair}
+ * instances instead of doubles.</p>
+ */
+public class NablaStrictMath {
+
+    /** Hidden constructor.
+     * <p>Since this class is a utility class, it cannot be instantiated.</p>
+     */
+    private NablaStrictMath() {
+    }
+
+    ///////////////////////////
+    // exponential functions //
+    ///////////////////////////
+
+    /** Exponential function.
+     * @param a function input value
+     * @return e<sup>a</sup>
+     */
+    public static DifferentialPair exp(final DifferentialPair a) {
+        final double e = StrictMath.exp(a.getU0());
+        return new DifferentialPair(e, a.getU1() * e);
+    }
+
+    /** Exponential minus 1 function.
+     * @param a function input value
+     * @return e<sup>a</sup>-1
+     */
+    public static DifferentialPair expm1(final DifferentialPair a) {
+        final double e = StrictMath.expm1(a.getU0());
+        return new DifferentialPair(e, a.getU1() * (e + 1));
+    }
+
+    /** Natural logarithm function.
+     * @param a function input value
+     * @return log(a)
+     */
+    public static DifferentialPair log(final DifferentialPair a) {
+        final double a0 = a.getU0();
+        return new DifferentialPair(StrictMath.log(a0), a.getU1() / a0);
+    }
+
+    /** Shifted natural logarithm function.
+     * @param a function input value
+     * @return log(1+a)
+     */
+    public static DifferentialPair log1p(final DifferentialPair a) {
+        final double a0 = a.getU0();
+        return new DifferentialPair(StrictMath.log1p(a0), a.getU1() / (1 + a0));
+    }
+
+    /** Base 10 logarithm function.
+     * @param a function input value
+     * @return log<sub>10</sub>(a)
+     */
+    public static DifferentialPair log10(final DifferentialPair a) {
+        final double a0 = a.getU0();
+        return new DifferentialPair(StrictMath.log10(a0), a.getU1() / (a0 * StrictMath.log(10)));
+    }
+
+
+    ////////////////////////
+    // circular functions //
+    ////////////////////////
+
+    /** Cosine function.
+     * @param a function input value
+     * @return cos(a)
+     */
+    public static DifferentialPair cos(final DifferentialPair a) {
+        final double a0 = a.getU0();
+        return new DifferentialPair(StrictMath.cos(a0), -a.getU1() * StrictMath.sin(a0));
+    }
+
+    /** Sine function.
+     * @param a function input value
+     * @return sin(a)
+     */
+    public static DifferentialPair sin(final DifferentialPair a) {
+        final double a0 = a.getU0();
+        return new DifferentialPair(StrictMath.sin(a0), a.getU1() * StrictMath.cos(a0));
+    }
+
+    /** Tangent function.
+     * @param a function input value
+     * @return tan(a)
+     */
+    public static DifferentialPair tan(final DifferentialPair a) {
+        final double t = StrictMath.tan(a.getU0());
+        return new DifferentialPair(t, a.getU1() * (1 + t * t));
+    }
+
+    /** Inverse cosine function.
+     * @param a function input value
+     * @return acos(a)
+     */
+    public static DifferentialPair acos(final DifferentialPair a) {
+        final double a0 = a.getU0();
+        return new DifferentialPair(StrictMath.acos(a0), -a.getU1() / StrictMath.sqrt(1 - a0 * a0));
+    }
+
+    /** Inverse sine function.
+     * @param a function input value
+     * @return asin(a)
+     */
+    public static DifferentialPair asin(final DifferentialPair a) {
+        final double a0 = a.getU0();
+        return new DifferentialPair(StrictMath.asin(a0), a.getU1() / StrictMath.sqrt(1 - a0 * a0));
+    }
+
+    /** Inverse tangent function.
+     * @param a function input value
+     * @return atan(a)
+     */
+    public static DifferentialPair atan(final DifferentialPair a) {
+        final double a0 = a.getU0();
+        return new DifferentialPair(StrictMath.atan(a0), a.getU1() / (1 + a0 * a0));
+    }
+
+
+    /////////////////////////////////
+    // cartesian/polar conversions //
+    ////////////////////////////////
+
+    /** Cartesian to polar conversion function.
+     * @param y cartesian ordinate of the point
+     * @param x cartesian abscissa of the point
+     * @return angular part of the polar coordinates of the point
+     */
+    public static DifferentialPair atan2(final DifferentialPair y, final double x) {
+        final double y0 = y.getU0();
+        return new DifferentialPair(StrictMath.atan2(y0, x),
+                                    x * y.getU1() / (x * x + y0 * y0));
+    }
+
+    /** Cartesian to polar conversion function.
+     * @param y cartesian ordinate of the point
+     * @param x cartesian abscissa of the point
+     * @return angular part of the polar coordinates of the point
+     */
+    public static DifferentialPair atan2(final double y, final DifferentialPair x) {
+        final double x0 = x.getU0();
+        return new DifferentialPair(StrictMath.atan2(y, x0),
+                                    -y * x.getU1() / (x0 * x0 + y * y));
+    }
+
+    /** Cartesian to polar conversion function.
+     * @param y cartesian ordinate of the point
+     * @param x cartesian abscissa of the point
+     * @return angular part of the polar coordinates of the point
+     */
+    public static DifferentialPair atan2(final DifferentialPair y, final DifferentialPair x) {
+        final double y0 = y.getU0();
+        final double x0 = x.getU0();
+        return new DifferentialPair(StrictMath.atan2(y0, x0),
+                                    (x0 * y.getU1() - y0 * x.getU1()) / (x0 * x0 + y0 * y0));
+    }
+
+    /** Cartesian to polar conversion function.
+     * @param x cartesian abscissa of the point
+     * @param y cartesian ordinate of the point
+     * @return radius part of the polar coordinates of the point
+     */
+    public static DifferentialPair hypot(final DifferentialPair x, final double y) {
+        final double x0 = x.getU0();
+        final double h = StrictMath.hypot(x0, y);
+        return new DifferentialPair(h, x0 * x.getU1() / h);
+    }
+
+    /** Cartesian to polar conversion function.
+     * @param x cartesian abscissa of the point
+     * @param y cartesian ordinate of the point
+     * @return radius part of the polar coordinates of the point
+     */
+    public static DifferentialPair hypot(final double x, final DifferentialPair y) {
+        final double y0 = y.getU0();
+        final double h = StrictMath.hypot(x, y0);
+        return new DifferentialPair(h, y0 * y.getU1() / h);
+    }
+
+    /** Cartesian to polar conversion function.
+     * @param x cartesian abscissa of the point
+     * @param y cartesian ordinate of the point
+     * @return radius part of the polar coordinates of the point
+     */
+    public static DifferentialPair hypot(final DifferentialPair x, final DifferentialPair y) {
+        final double x0 = x.getU0();
+        final double y0 = y.getU0();
+        final double h = StrictMath.hypot(x0, y0);
+        return new DifferentialPair(h, (x0 * x.getU1() + y0 * y.getU1()) / h);
+    }
+
+
+    //////////////////////////
+    // hyperbolic functions //
+    //////////////////////////
+
+    /** Hyperbolic cosine function.
+     * @param a function input value
+     * @return cosh(a)
+     */
+    public static DifferentialPair cosh(final DifferentialPair a) {
+        final double a0 = a.getU0();
+        return new DifferentialPair(StrictMath.cosh(a0), a.getU1() * StrictMath.sinh(a0));
+    }
+
+    /** Hyperbolic sine function.
+     * @param a function input value
+     * @return sinh(a)
+     */
+    public static DifferentialPair sinh(final DifferentialPair a) {
+        final double a0 = a.getU0();
+        return new DifferentialPair(StrictMath.sinh(a0), a.getU1() * StrictMath.cosh(a0));
+    }
+
+    /** Hyperbolic tangent function.
+     * @param a function input value
+     * @return tanh(a)
+     */
+    public static DifferentialPair tanh(final DifferentialPair a) {
+        final double t = StrictMath.tanh(a.getU0());
+        return new DifferentialPair(t, a.getU1() * (1 - t * t));
+    }
+
+    /** Inverse hyperbolic cosine function.
+     * @param a function input value
+     * @return acosh(a)
+     */
+    public static DifferentialPair acosh(final DifferentialPair a) {
+        // the acosh function is not provided by java.lang.StrictMath as of Java6
+        final double a0 = a.getU0();
+        final double root = StrictMath.sqrt(a0 - 1) * StrictMath.sqrt(a0 + 1);
+        return new DifferentialPair(StrictMath.log(a0 + root), a.getU1() / root);
+    }
+
+    /** Inverse hyperbolic sine function.
+     * @param a function input value
+     * @return asinh(a)
+     */
+    public static DifferentialPair asinh(final DifferentialPair a) {
+        // the asinh function is not provided by java.lang.StrictMath as of Java6
+        final double a0 = a.getU0();
+        final double root = StrictMath.sqrt(a0 * a0 + 1);
+        return new DifferentialPair(StrictMath.log(a0 + root), a.getU1() / root);
+    }
+
+    /** Inverse hyperbolic tangent function.
+     * @param a function input value
+     * @return atanh(a)
+     */
+    public static DifferentialPair atanh(final DifferentialPair a) {
+        // the atanh function is not provided by java.lang.StrictMath as of Java6
+        final double a0 = a.getU0();
+        final double ath = (StrictMath.log1p(a0) - StrictMath.log1p(-a0)) / 2;
+        return new DifferentialPair(ath, a.getU1() / (1 - a0 * a0));
+    }
+
+    /////////////////////
+    // power functions //
+    /////////////////////
+
+    /** Square root function.
+     * @param a function input value
+     * @return &sqrt;a
+     */
+    public static DifferentialPair sqrt(final DifferentialPair a) {
+        final double root = StrictMath.sqrt(a.getU0());
+        return new DifferentialPair(root, a.getU1() / (2 * root));
+    }
+
+    /** Cubic root function.
+     * @param a function input value
+     * @return cbrt(a)
+     */
+    public static DifferentialPair cbrt(final DifferentialPair a) {
+        final double root = StrictMath.cbrt(a.getU0());
+        return new DifferentialPair(root, a.getU1() / (3 * root * root));
+    }
+
+    /** Power function.
+     * @param a base value
+     * @param b exponent value
+     * @return a<sup>b</sup>
+     */
+    public static DifferentialPair pow(final DifferentialPair a, final double b) {
+        final double a0 = a.getU0();
+        final double p = StrictMath.pow(a0, b);
+        return new DifferentialPair(p, a.getU1() * b * p / a0);
+    }
+
+    /** Power function.
+     * @param a base value
+     * @param b exponent value
+     * @return a<sup>b</sup>
+     */
+    public static DifferentialPair pow(final double a, final DifferentialPair b) {
+        final double p = StrictMath.pow(a, b.getU0());
+        return new DifferentialPair(p, b.getU1() * StrictMath.log(a) * p);
+    }
+
+    /** Power function.
+     * @param a base value
+     * @param b exponent value
+     * @return a<sup>b</sup>
+     */
+    public static DifferentialPair pow(final DifferentialPair a, final DifferentialPair b) {
+        final double a0 = a.getU0();
+        final double b0 = b.getU0();
+        final double p = StrictMath.pow(a0, b0);
+        return new DifferentialPair(p, (a.getU1() * b0 / a0 + b.getU1() * StrictMath.log(a0)) * p);
+    }
+
+
+    ////////////////////////////
+    // sign related functions //
+    ////////////////////////////
+
+    /** Absolute value function.
+     * @param a function input value
+     * @return |a|
+     */
+    public static DifferentialPair abs(final DifferentialPair a) {
+        return (a.getU0() >= 0) ? a : DifferentialPair.negate(a);
+    }
+
+    /** Sign function.
+     * @param a function input value
+     * @return -1, 0 or +1 according to the sign of a
+     */
+    public static DifferentialPair signum(final DifferentialPair a) {
+        return DifferentialPair.newConstant(StrictMath.signum(a.getU0()));
+    }
+
+    /** Sign copy function.
+     * @param magnitude function input value
+     * @param sign sign reference
+     * @return either magnitude or -magnitude to match sign
+     */
+    public static DifferentialPair copySign(final DifferentialPair magnitude,
+                                            final double sign) {
+        final long mBits = Double.doubleToLongBits(magnitude.getU0());
+        final long sBits = Double.doubleToLongBits(sign);
+        return (((mBits ^ sBits) & 0x8000000000000000L) == 0) ?
+                magnitude : DifferentialPair.negate(magnitude);
+    }
+
+    /** Sign copy function.
+     * @param magnitude function input value
+     * @param sign sign reference
+     * @return either magnitude or -magnitude to match sign
+     */
+    public static DifferentialPair copySign(final double magnitude,
+                                            final DifferentialPair sign) {
+        final long mBits = Double.doubleToLongBits(magnitude);
+        final long sBits = Double.doubleToLongBits(sign.getU0());
+        return (((mBits ^ sBits) & 0x8000000000000000L) == 0) ?
+               DifferentialPair.newConstant(magnitude) :
+               DifferentialPair.newConstant(-magnitude);
+    }
+
+    /** Sign copy function.
+     * @param magnitude function input value
+     * @param sign sign reference
+     * @return either magnitude or -magnitude to match sign
+     */
+    public static DifferentialPair copySign(final DifferentialPair magnitude,
+                                            final DifferentialPair sign) {
+        final long mBits = Double.doubleToLongBits(magnitude.getU0());
+        final long sBits = Double.doubleToLongBits(sign.getU0());
+        return (((mBits ^ sBits) & 0x8000000000000000L) == 0) ?
+                magnitude : DifferentialPair.negate(magnitude);
+    }
+
+
+    ////////////////////////////
+    // neighborhood functions //
+    ////////////////////////////
+
+    /** Floor function.
+     * @param a function input value
+     * @return largest integer value smaller than a or equal to a
+     */
+    public static DifferentialPair floor(final DifferentialPair a) {
+        return DifferentialPair.newConstant(StrictMath.floor(a.getU0()));
+    }
+
+    /** Rounding function.
+     * @param a function input value
+     * @return closest integer value to a
+     */
+    public static DifferentialPair rint(final DifferentialPair a) {
+        return DifferentialPair.newConstant(StrictMath.rint(a.getU0()));
+    }
+
+    /** Ceil function.
+     * @param a function input value
+     * @return smallest integer value greater than a or equal to a
+     */
+    public static DifferentialPair ceil(final DifferentialPair a) {
+        return DifferentialPair.newConstant(StrictMath.ceil(a.getU0()));
+    }
+
+    /** Neighbor function.
+     * @param a function input value
+     * @return smallest representable double value ly greater than a
+     */
+    public static DifferentialPair nextUp(final DifferentialPair a) {
+        return new DifferentialPair(StrictMath.nextUp(a.getU0()), a.getU1());
+    }
+
+    /** Neighbor function.
+     * @param start function input value
+     * @param direction direction of neighboring (relative to a)
+     * @return closest double value different than a in given direction
+     */
+    public static DifferentialPair nextAfter(final DifferentialPair start,
+                                             final double direction) {
+        return new DifferentialPair(StrictMath.nextAfter(start.getU0(), direction),
+                                    start.getU1());
+    }
+
+    /** Neighbor function.
+     * @param start function input value
+     * @param direction direction of neighboring (relative to a)
+     * @return closest double value different than a in given direction
+     */
+    public static DifferentialPair nextAfter(final double start,
+                                             final DifferentialPair direction) {
+        return DifferentialPair.newConstant(StrictMath.nextAfter(start, direction.getU0()));
+    }
+
+    /** Neighbor function.
+     * @param start function input value
+     * @param direction direction of neighboring (relative to a)
+     * @return closest double value different than a in given direction
+     */
+    public static DifferentialPair nextAfter(final DifferentialPair start,
+                                             final DifferentialPair direction) {
+        return new DifferentialPair(StrictMath.nextAfter(start.getU0(), direction.getU0()), start.getU1());
+    }
+
+
+    ////////////////////////
+    // encoding functions //
+    ////////////////////////
+
+    /** Unit in Last Position function.
+     * @param a function input value
+     * @return value of the least significant bit of a
+     */
+    public static DifferentialPair ulp(final DifferentialPair a) {
+        return DifferentialPair.newConstant(StrictMath.ulp(a.getU0()));
+    }
+
+    /** Binary rescaling function.
+     * @param a function input value
+     * @param scale exponent part of the 2<sup>scale</sup> multiplication factor
+     * @return a &times; 2<sup>scale</sup>
+     */
+    public static DifferentialPair scalb(final DifferentialPair a,
+                                         final int scale) {
+        return new DifferentialPair(StrictMath.scalb(a.getU0(), scale),
+                                    StrictMath.scalb(a.getU1(), scale));
+    }
+
+    /** Remainder function.
+     * @param f1 dividend
+     * @param f2 divisor
+     * @return remainder of f1/f2, following IEEE754 conventions
+     */
+    public static DifferentialPair IEEEremainder(final DifferentialPair f1,
+                                                 final double f2) {
+        final double r = StrictMath.IEEEremainder(f1.getU0(), f2);
+        return new DifferentialPair(r, f1.getU1());
+    }
+
+    /** Remainder function.
+     * @param f1 dividend
+     * @param f2 divisor
+     * @return remainder of f1/f2, following IEEE754 conventions
+     */
+    public static DifferentialPair IEEEremainder(final double f1,
+                                                 final DifferentialPair f2) {
+        final double f20 = f2.getU0();
+        final double r = StrictMath.IEEEremainder(f1, f20);
+        final int n = (int) ((r - f1) / f20);
+        return new DifferentialPair(r, n * f2.getU1());
+    }
+
+    /** Remainder function.
+     * @param f1 dividend
+     * @param f2 divisor
+     * @return remainder of f1/f2, following IEEE754 conventions
+     */
+    public static DifferentialPair IEEEremainder(final DifferentialPair f1,
+                                                 final DifferentialPair f2) {
+        final double f10 = f1.getU0();
+        final double f20 = f2.getU0();
+        final double r = StrictMath.IEEEremainder(f10, f20);
+        final int n = (int) ((r - f10) / f20);
+        return new DifferentialPair(r, f1.getU1() + n * f2.getU1());
+    }
+
+
+    //////////////////////////
+    // conversion functions //
+    //////////////////////////
+
+    /** Angular conversion function.
+     * @param a angle in radians
+     * @return angle converted to degrees
+     */
+    public static DifferentialPair toDegrees(final DifferentialPair a) {
+        return new DifferentialPair(StrictMath.toDegrees(a.getU0()), StrictMath.toDegrees(a.getU1()));
+    }
+
+    /** Angular conversion function.
+     * @param a angle in degrees
+     * @return angle converted to radians
+     */
+    public static DifferentialPair toRadians(final DifferentialPair a) {
+        return new DifferentialPair(StrictMath.toRadians(a.getU0()), StrictMath.toRadians(a.getU1()));
+    }
+
+
+    //////////////////////////
+    // comparison functions //
+    //////////////////////////
+
+    /** Max function.
+     * @param a first function input value
+     * @param b second function input value
+     * @return maximal value from the (a, b) pair
+     */
+    public static DifferentialPair max(final DifferentialPair a,
+                                       final double b) {
+        return (a.getU0() >= b) ? a : DifferentialPair.newConstant(b);
+    }
+
+    /** Max function.
+     * @param a first function input value
+     * @param b second function input value
+     * @return maximal value from the (a, b) pair
+     */
+    public static DifferentialPair max(final double a,
+                                       final DifferentialPair b) {
+        return (b.getU0() >= a) ? b : DifferentialPair.newConstant(a);
+    }
+
+    /** Max function.
+     * @param a first function input value
+     * @param b second function input value
+     * @return maximal value from the (a, b) pair
+     */
+    public static DifferentialPair max(final DifferentialPair a,
+                                       final DifferentialPair b) {
+        return (a.getU0() >= b.getU0()) ? a : b;
+    }
+
+    /** Min function.
+     * @param a first function input value
+     * @param b second function input value
+     * @return minimal value from the (a, b) pair
+     */
+    public static DifferentialPair min(final DifferentialPair a,
+                                       final double b) {
+        return (a.getU0() <= b) ? a : DifferentialPair.newConstant(b);
+    }
+
+    /** Min function.
+     * @param a first function input value
+     * @param b second function input value
+     * @return minimal value from the (a, b) pair
+     */
+    public static DifferentialPair min(final double a,
+                                       final DifferentialPair b) {
+        return (b.getU0() <= a) ? b : DifferentialPair.newConstant(a);
+    }
+
+    /** Min function.
+     * @param a first function input value
+     * @param b second function input value
+     * @return minimal value from the (a, b) pair
+     */
+    public static DifferentialPair min(final DifferentialPair a,
+                                       final DifferentialPair b) {
+        return (a.getU0() <= b.getU0()) ? a : b;
+    }
+
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/NablaStrictMath.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/DifferentialPair.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/DifferentialPair.java?rev=648234&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/DifferentialPair.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/DifferentialPair.java Tue Apr 15 06:16:43 2008
@@ -0,0 +1,500 @@
+/*
+ * 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.apache.commons.nabla.core;
+
+import java.io.Serializable;
+
+/** Class representing both a value and a differential.
+ * <p>This class is the workhorse of the Nabla library. It can be
+ * seen as an extension of the primitive double type used throughout
+ * mathematical expressions. In addition to holding parameter,
+ * intermediate computations and result values as double do, instances
+ * of this class also holds the first differential associated with this
+ * parameter, intermediate computations and results.</p>
+ * <p>{@link DifferentialPair} instances can be used directly thanks to
+ * the arithmetic operators provided as static methods by this class
+ * (+, -, *, /, %) and to the mathematical functions provided by the
+ * {@link org.apache.commons.nabla.NablaMath} and the {@link
+ * org.apache.commons.nabla.NablaStrictMath} utility classes.</p>
+ * <p>Implementing complex expressions by hand using these classes is
+ * however a complex and error-prone task, so the classical use is
+ * simply to develop computation code using standard primitive double
+ * values and to use {@link UnivariateDifferentiator differentiators} to create
+ * the {@link DifferentialPair}-based instances.</p>
+ * <p>Instances of this class are guaranteed to be immutable.</p>
+ */
+public class DifferentialPair implements Serializable {
+
+    /** -1 constant. */
+    public static final DifferentialPair MINUS_ONE = newConstant(-1);
+
+    /** 0 constant. */
+    public static final DifferentialPair ZERO      = newConstant( 0);
+
+    /** +1 constant. */
+    public static final DifferentialPair ONE       = newConstant( 1);
+
+    /** +2 constant. */
+    public static final DifferentialPair TWO       = newConstant( 2);
+
+    /** +3 constant. */
+    public static final DifferentialPair THREE     = newConstant( 3);
+
+
+    /** &pi; (Archimede) constant. */
+    public static final DifferentialPair PI        = newConstant(Math.PI);
+
+    /** e (Euler) constant, base of the natural logarithms. */
+    public static final DifferentialPair E         = newConstant(Math.E);
+
+    /** Serializable UID. */
+    private static final long serialVersionUID = 9015695991152713660L;
+
+
+    /** Value part of the differential pair. */
+    private final double u0;
+
+    /** First differential part of the differential pair. */
+    private final double u1;
+
+    /** Build a new instance from its components.
+     * @param u0 value part of the differential pair
+     * @param u1 first differential part of the differential pair
+     */
+    public DifferentialPair(final double u0, final double u1) {
+        this.u0 = u0;
+        this.u1 = u1;
+    }
+
+    /** Build an instance representing a univariate variable.
+     * <p>Instances built using this constructor are considered
+     * to be the free variables with respect to which differentials
+     * are computed. As such, their differential with respect to
+     * themselves is +1. Calling this constructor has the same
+     * effect as calling <code>DifferentialPair(a, 1.0)</code>.</p>
+     * @param a value of the variable
+     * @return the built variable
+     */
+    public static DifferentialPair newVariable(final double a) {
+        return new DifferentialPair(a, 1.0);
+    }
+
+    /** Build an instance representing a constant.
+     * <p>Constant do not vary ... Hence their differential
+     * is 0. Calling this constructor has the same
+     * effect as calling <code>DifferentialPair(a, 0.0)</code>.</p>
+     * @param a value of the constant
+     * @return the built constant
+     */
+    public static DifferentialPair newConstant(final double a) {
+        return new DifferentialPair(a, 0.0);
+    }
+
+    /** Get the value part of the differential pair.
+     * @return value part of the differential pair
+     */
+    public double getU0() {
+        return u0;
+    }
+
+    /** Get the first differential part of the differential pair.
+     * @return first differential part of the differential pair
+     */
+    public double getU1() {
+        return u1;
+    }
+
+    /** '+' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a+b
+     */
+    public static DifferentialPair add(final DifferentialPair a,
+                                       final int b) {
+        return new DifferentialPair(a.u0 + b, a.u1);
+    }
+
+    /** '+' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a+b
+     */
+    public static DifferentialPair add(final int a,
+                                       final DifferentialPair b) {
+        return new DifferentialPair(a + b.u0, b.u1);
+    }
+
+    /** '+' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a+b
+     */
+    public static DifferentialPair add(final DifferentialPair a,
+                                       final long b) {
+        return new DifferentialPair(a.u0 + b, a.u1);
+    }
+
+    /** '+' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a+b
+     */
+    public static DifferentialPair add(final long a,
+                                       final DifferentialPair b) {
+        return new DifferentialPair(a + b.u0, b.u1);
+    }
+
+    /** '+' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a+b
+     */
+    public static DifferentialPair add(final DifferentialPair a,
+                                       final double b) {
+        return new DifferentialPair(a.u0 + b, a.u1);
+    }
+
+    /** '+' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a+b
+     */
+    public static DifferentialPair add(final double a,
+                                       final DifferentialPair b) {
+        return new DifferentialPair(a + b.u0, b.u1);
+    }
+
+    /** '+' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a+b
+     */
+    public static DifferentialPair add(final DifferentialPair a,
+                                       final DifferentialPair b) {
+        return new DifferentialPair(a.u0 + b.u0, a.u1 + b.u1);
+    }
+
+    /** '-' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a-b
+     */
+    public static DifferentialPair subtract(final DifferentialPair a,
+                                            final int b) {
+        return new DifferentialPair(a.u0 - b, a.u1);
+    }
+
+    /** '-' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a-b
+     */
+    public static DifferentialPair subtract(final int a,
+                                            final DifferentialPair b) {
+        return new DifferentialPair(a - b.u0, -b.u1);
+    }
+
+    /** '-' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a-b
+     */
+    public static DifferentialPair subtract(final DifferentialPair a,
+                                            final long b) {
+        return new DifferentialPair(a.u0 - b, a.u1);
+    }
+
+    /** '-' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a-b
+     */
+    public static DifferentialPair subtract(final long a,
+                                            final DifferentialPair b) {
+        return new DifferentialPair(a - b.u0, -b.u1);
+    }
+
+    /** '-' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a-b
+     */
+    public static DifferentialPair subtract(final DifferentialPair a,
+                                            final double b) {
+        return new DifferentialPair(a.u0 - b, a.u1);
+    }
+
+    /** '-' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a-b
+     */
+    public static DifferentialPair subtract(final double a,
+                                            final DifferentialPair b) {
+        return new DifferentialPair(a - b.u0, -b.u1);
+    }
+
+    /** '-' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a-b
+     */
+    public static DifferentialPair subtract(final DifferentialPair a,
+                                            final DifferentialPair b) {
+        return new DifferentialPair(a.u0 - b.u0, a.u1 - b.u1);
+    }
+
+    /** '&times;' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a&times;b
+     */
+    public static DifferentialPair multiply(final DifferentialPair a,
+                                            final int b) {
+        return new DifferentialPair(a.u0 * b, a.u1 * b);
+    }
+
+    /** '&times;' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a&times;b
+     */
+    public static DifferentialPair multiply(final int a,
+                                            final DifferentialPair b) {
+        return new DifferentialPair(a * b.u0, a * b.u1);
+    }
+
+    /** '&times;' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a&times;b
+     */
+    public static DifferentialPair multiply(final DifferentialPair a,
+                                            final long b) {
+        return new DifferentialPair(a.u0 * b, a.u1 * b);
+    }
+
+    /** '&times;' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a&times;b
+     */
+    public static DifferentialPair multiply(final long a,
+                                            final DifferentialPair b) {
+        return new DifferentialPair(a * b.u0, a * b.u1);
+    }
+
+    /** '&times;' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a&times;b
+     */
+    public static DifferentialPair multiply(final DifferentialPair a,
+                                            final double b) {
+        return new DifferentialPair(a.u0 * b, a.u1 * b);
+    }
+
+    /** '&times;' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a&times;b
+     */
+    public static DifferentialPair multiply(final double a,
+                                            final DifferentialPair b) {
+        return new DifferentialPair(a * b.u0, a * b.u1);
+    }
+
+    /** '&times;' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a&times;b
+     */
+    public static DifferentialPair multiply(final DifferentialPair a,
+                                            final DifferentialPair b) {
+        return new DifferentialPair(a.u0 * b.u0, a.u1 * b.u0 + a.u0 * b.u1);
+    }
+
+    /** '&divides;' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a&divides;b
+     */
+    public static DifferentialPair divide(final DifferentialPair a,
+                                          final int b) {
+        return new DifferentialPair(a.u0 / b, a.u1 / b);
+    }
+
+    /** '&divides;' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a&divides;b
+     */
+    public static DifferentialPair divide(final int a,
+                                          final DifferentialPair b) {
+        return new DifferentialPair(a / b.u0, -a * b.u1 / (b.u0 * b.u0));
+    }
+
+    /** '&divides;' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a&divides;b
+     */
+    public static DifferentialPair divide(final DifferentialPair a,
+                                          final long b) {
+        return new DifferentialPair(a.u0 / b, a.u1 / b);
+    }
+
+    /** '&divides;' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a&divides;b
+     */
+    public static DifferentialPair divide(final long a,
+                                          final DifferentialPair b) {
+        return new DifferentialPair(a / b.u0, -a * b.u1 / (b.u0 * b.u0));
+    }
+
+    /** '&divides;' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a&divides;b
+     */
+    public static DifferentialPair divide(final DifferentialPair a,
+                                          final double b) {
+        return new DifferentialPair(a.u0 / b, a.u1 / b);
+    }
+
+    /** '&divides;' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a&divides;b
+     */
+    public static DifferentialPair divide(final double a,
+                                          final DifferentialPair b) {
+        return new DifferentialPair(a / b.u0, -a * b.u1 / (b.u0 * b.u0));
+    }
+
+    /** '&divides;' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a&divides;b
+     */
+    public static DifferentialPair divide(final DifferentialPair a,
+                                          final DifferentialPair b) {
+        return new DifferentialPair(a.u0 / b.u0, (a.u1 * b.u0 - a.u0 * b.u1) / (b.u0 * b.u0));
+    }
+
+    /** '%' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a%b
+     */
+    public static DifferentialPair remainder(final int a,
+                                             final DifferentialPair b) {
+        final double remainder = a % b.u0;
+        return new DifferentialPair(remainder, (remainder - a) * b.u1 / b.u0);
+    }
+
+    /** '%' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a%b
+     */
+    public static DifferentialPair remainder(final DifferentialPair a,
+                                             final int b) {
+        return new DifferentialPair(a.u0 % b, a.u1);
+    }
+
+    /** '%' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a%b
+     */
+    public static DifferentialPair remainder(final long a,
+                                             final DifferentialPair b) {
+        final double remainder = a % b.u0;
+        return new DifferentialPair(remainder, (remainder - a) * b.u1 / b.u0);
+    }
+
+    /** '%' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a%b
+     */
+    public static DifferentialPair remainder(final DifferentialPair a,
+                                             final long b) {
+        return new DifferentialPair(a.u0 % b, a.u1);
+    }
+
+    /** '%' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a%b
+     */
+    public static DifferentialPair remainder(final double a,
+                                             final DifferentialPair b) {
+        final double remainder = a % b.u0;
+        return new DifferentialPair(remainder, (remainder - a) * b.u1 / b.u0);
+    }
+
+    /** '%' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a%b
+     */
+    public static DifferentialPair remainder(final DifferentialPair a,
+                                             final double b) {
+        return new DifferentialPair(a.u0 % b, a.u1);
+    }
+
+    /** '%' operator, for differential pairs.
+     * @param a left hand side parameter of the operator
+     * @param b right hand side parameter of the operator
+     * @return a%b
+     */
+    public static DifferentialPair remainder(final DifferentialPair a,
+                                             final DifferentialPair b) {
+        final double remainder = a.u0 % b.u0;
+        return new DifferentialPair(remainder, (remainder - a.u0) * b.u1 / b.u0 + a.u1);
+    }
+
+    /** unary '-' operator, for differential pairs.
+     * @param a parameter of the operator
+     * @return -a
+     */
+    public static DifferentialPair negate(final DifferentialPair a) {
+        return new DifferentialPair(-a.u0 , -a.u1);
+    }
+
+    /** squaring operation, for differential pairs.
+     * @param a parameter of the operator
+     * @return a<sup>2</sup>
+     */
+    public static DifferentialPair square(final DifferentialPair a) {
+        return new DifferentialPair(a.u0 * a.u0, 2 * a.u0 * a.u1);
+    }
+
+    /** cubing operation, for differential pairs.
+     * @param a parameter of the operator
+     * @return a<sup>3</sup>
+     */
+    public static DifferentialPair cube(final DifferentialPair a) {
+        final double u02 = a.u0 * a.u0;
+        return new DifferentialPair(a.u0 * u02, 3 * u02 * a.u1);
+    }
+
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/DifferentialPair.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/DifferentiationException.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/DifferentiationException.java?rev=648234&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/DifferentiationException.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/DifferentiationException.java Tue Apr 15 06:16:43 2008
@@ -0,0 +1,42 @@
+/*
+ * 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.apache.commons.nabla.core;
+
+/** This class represent differentiation exceptions.
+
+ * <p>Exceptions of this type are thrown when a {@link UnivariateDifferentiable
+ * differentiable} class cannot be differentiated.</p>
+
+ * @version $Id: nablaException.java 1686 2005-12-16 12:59:51Z luc $
+
+ */
+
+public class DifferentiationException extends NablaException {
+
+    /** Version UID. */
+    private static final long serialVersionUID = 3219776376938014010L;
+
+    /** 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 DifferentiationException(final String specifier, final Object... parts) {
+        super(specifier, parts);
+    }
+
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/DifferentiationException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/NablaException.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/NablaException.java?rev=648234&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/NablaException.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/NablaException.java Tue Apr 15 06:16:43 2008
@@ -0,0 +1,78 @@
+/*
+ * 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.apache.commons.nabla.core;
+
+import java.text.MessageFormat;
+import java.util.ResourceBundle;
+import java.util.MissingResourceException;
+
+/** This class is the base class for all specific exceptions thrown by
+ * the nabla classes.
+
+ * <p>When the nabla classes throw exceptions that are specific to
+ * the package, these exceptions are always subclasses of
+ * NablaException. When exceptions that are already covered by the
+ * standard java API should be thrown, like
+ * ArrayIndexOutOfBoundsException or IllegalArgumentException, these
+ * standard exceptions are thrown rather than the nabla specific
+ * ones.</p>
+
+ * @version $Id: nablaException.java 1686 2005-12-16 12:59:51Z luc $
+
+ */
+
+public class NablaException extends Exception {
+
+    /** Version UID. */
+    private static final long serialVersionUID = 9178429434459078429L;
+
+    /** Localized messages resources. */
+    private static ResourceBundle resources =
+        ResourceBundle.getBundle("META-INF/localization/ExceptionsMessages");
+
+    /** 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 NablaException(final String specifier, final Object... parts) {
+        super(translate(specifier, parts));
+    }
+
+    /** Translate a string.
+     * @param s string to translate
+     * @return translated string
+     */
+    public static String translate(final String s) {
+        try {
+            return resources.getString(s);
+        } catch (MissingResourceException mre) {
+            return s;
+        }
+    }
+
+    /** Translate a message.
+     * @param specifier format specifier (to be translated)
+     * @param parts to insert in the format (no translation)
+     * @return translated message
+     */
+    public static String translate(final String specifier,
+                                   final Object... parts) {
+        return new MessageFormat(translate(specifier)).format(parts);
+    }
+
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/NablaException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/UnivariateDerivative.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/UnivariateDerivative.java?rev=648234&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/UnivariateDerivative.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/UnivariateDerivative.java Tue Apr 15 06:16:43 2008
@@ -0,0 +1,60 @@
+/*
+ * 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.apache.commons.nabla.core;
+
+/** Interface for univariate functions derivatives.
+ * <p>This interface represent a simple function which computes
+ * both the value and the first derivative of a mathematical function.
+ * The derivative is computed with respect to the input variable.</p>
+ * <p>Classes implementing this interface are automatically built by
+ * the {@link UnivariateDifferentiator differentiators} provided by the
+ * Nabla library.</p>
+ * @see UnivariateDifferentiable
+ * @see UnivariateDifferentiator
+ */
+public interface UnivariateDerivative {
+
+    /** Get the primitive function associated with this differential.
+     * <p>Each {@link UnivariateDerivative} instance is tightly bound
+     * to an {@link UnivariateDifferentiable} instance. If the state of
+     * the primitive instance changes in any way that affects the
+     * differential computation, this binding allows this change to
+     * be immediately seen by the derivative instance, there is no need
+     * to differentiate the primitive again. The existing instance is aware
+     * of the primitive changes.</p>
+     * <p>In other words in the following code snippet, the three values
+     * f1, f2 and f3 should be equal (at least at machine tolerance level)</p>
+     * <pre>
+     *    UnivariateDerivative derivative = differentiator.differentiate(derivable);
+     *    derivable.someFunctionThatMutatesHeavilyTheInstance();
+     *    double f1 = derivable.f(t);
+     *    double f2 = derivative.getPrimitive().f(t);
+     *    double f3 = detivative.f(DifferentialPair.newVariable(t)).getU0();
+     * </pre>
+     * @return primitive function bound to this derivative
+     */
+    UnivariateDifferentiable getPrimitive();
+
+    /** Simple mathematical function.
+     * <p>{@link UnivariateDerivative} classes compute both the
+     * value and the firest derivative of the function.</p>
+     * @param t function input value
+     * @return function result
+     */
+    DifferentialPair f(DifferentialPair t);
+
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/UnivariateDerivative.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/UnivariateDifferentiable.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/UnivariateDifferentiable.java?rev=648234&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/UnivariateDifferentiable.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/UnivariateDifferentiable.java Tue Apr 15 06:16:43 2008
@@ -0,0 +1,36 @@
+/*
+ * 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.apache.commons.nabla.core;
+
+/** Interface for differentiable univariate functions.
+ * <p>This interface should be implemented by the user
+ * classes that are intended to be differentiated by the
+ * Nabla library. It represent a simple function.</p>
+ * @see UnivariateDerivative
+ * @see UnivariateDifferentiator
+ */
+public interface UnivariateDifferentiable {
+
+    /** Simple mathematical function.
+     * <p>{@link UnivariateDifferentiable} classes compute only the
+     * value of the function, not its differential.</p>
+     * @param t function input value
+     * @return function result
+     */
+    double f(double t);
+
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/UnivariateDifferentiable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/UnivariateDifferentiator.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/UnivariateDifferentiator.java?rev=648234&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/UnivariateDifferentiator.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/UnivariateDifferentiator.java Tue Apr 15 06:16:43 2008
@@ -0,0 +1,32 @@
+/*
+ * 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.apache.commons.nabla.core;
+
+/** Interface defining the class differentiation operation.
+ */
+public interface UnivariateDifferentiator {
+
+    /** Create an implementation of a differential for a
+     * {@link UnivariateDifferentiable differentiable function}.
+     * @param d differentiable function to differentiate
+     * @return derivative function
+     * @exception DifferentiationException if the class cannot be differentiated
+     */
+    UnivariateDerivative differentiate(UnivariateDifferentiable d)
+        throws DifferentiationException;
+
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/core/UnivariateDifferentiator.java
------------------------------------------------------------------------------
    svn:eol-style = native