org.apache.commons.nabla.core
Class DifferentialPair

java.lang.Object
  extended by org.apache.commons.nabla.core.DifferentialPair
All Implemented Interfaces:
Serializable

public class DifferentialPair
extends Object
implements Serializable

Class representing both a value and a differential.

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.

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 NablaMath and the NablaStrictMath utility classes.

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 differentiators to create the DifferentialPair-based instances.

Instances of this class are guaranteed to be immutable.

See Also:
Serialized Form

Field Summary
static DifferentialPair E
          e (Euler) constant, base of the natural logarithms.
static DifferentialPair MINUS_ONE
          -1 constant.
static DifferentialPair ONE
          +1 constant.
static DifferentialPair PI
          π (Archimede) constant.
static DifferentialPair THREE
          +3 constant.
static DifferentialPair TWO
          +2 constant.
static DifferentialPair ZERO
          0 constant.
 
Constructor Summary
DifferentialPair(double u0, double u1)
          Build a new instance from its components.
 
Method Summary
static DifferentialPair add(DifferentialPair a, DifferentialPair b)
          '+' operator, for differential pairs.
static DifferentialPair add(DifferentialPair a, double b)
          '+' operator, for differential pairs.
static DifferentialPair add(DifferentialPair a, int b)
          '+' operator, for differential pairs.
static DifferentialPair add(DifferentialPair a, long b)
          '+' operator, for differential pairs.
static DifferentialPair add(double a, DifferentialPair b)
          '+' operator, for differential pairs.
static DifferentialPair add(int a, DifferentialPair b)
          '+' operator, for differential pairs.
static DifferentialPair add(long a, DifferentialPair b)
          '+' operator, for differential pairs.
static DifferentialPair cube(DifferentialPair a)
          cubing operation, for differential pairs.
static DifferentialPair divide(DifferentialPair a, DifferentialPair b)
          '÷s;' operator, for differential pairs.
static DifferentialPair divide(DifferentialPair a, double b)
          '÷s;' operator, for differential pairs.
static DifferentialPair divide(DifferentialPair a, int b)
          '÷s;' operator, for differential pairs.
static DifferentialPair divide(DifferentialPair a, long b)
          '÷s;' operator, for differential pairs.
static DifferentialPair divide(double a, DifferentialPair b)
          '÷s;' operator, for differential pairs.
static DifferentialPair divide(int a, DifferentialPair b)
          '÷s;' operator, for differential pairs.
static DifferentialPair divide(long a, DifferentialPair b)
          '÷s;' operator, for differential pairs.
 double getFirstDerivative()
          Get the first derivative part of the differential pair.
 double getValue()
          Get the value part of the differential pair.
static DifferentialPair multiply(DifferentialPair a, DifferentialPair b)
          '×' operator, for differential pairs.
static DifferentialPair multiply(DifferentialPair a, double b)
          '×' operator, for differential pairs.
static DifferentialPair multiply(DifferentialPair a, int b)
          '×' operator, for differential pairs.
static DifferentialPair multiply(DifferentialPair a, long b)
          '×' operator, for differential pairs.
static DifferentialPair multiply(double a, DifferentialPair b)
          '×' operator, for differential pairs.
static DifferentialPair multiply(int a, DifferentialPair b)
          '×' operator, for differential pairs.
static DifferentialPair multiply(long a, DifferentialPair b)
          '×' operator, for differential pairs.
static DifferentialPair negate(DifferentialPair a)
          unary '-' operator, for differential pairs.
static DifferentialPair newConstant(double a)
          Build an instance representing a constant.
static DifferentialPair newVariable(double a)
          Build an instance representing a univariate variable.
static DifferentialPair remainder(DifferentialPair a, DifferentialPair b)
          '%' operator, for differential pairs.
static DifferentialPair remainder(DifferentialPair a, double b)
          '%' operator, for differential pairs.
static DifferentialPair remainder(DifferentialPair a, int b)
          '%' operator, for differential pairs.
static DifferentialPair remainder(DifferentialPair a, long b)
          '%' operator, for differential pairs.
static DifferentialPair remainder(double a, DifferentialPair b)
          '%' operator, for differential pairs.
static DifferentialPair remainder(int a, DifferentialPair b)
          '%' operator, for differential pairs.
static DifferentialPair remainder(long a, DifferentialPair b)
          '%' operator, for differential pairs.
static DifferentialPair square(DifferentialPair a)
          squaring operation, for differential pairs.
static DifferentialPair subtract(DifferentialPair a, DifferentialPair b)
          '-' operator, for differential pairs.
static DifferentialPair subtract(DifferentialPair a, double b)
          '-' operator, for differential pairs.
static DifferentialPair subtract(DifferentialPair a, int b)
          '-' operator, for differential pairs.
static DifferentialPair subtract(DifferentialPair a, long b)
          '-' operator, for differential pairs.
static DifferentialPair subtract(double a, DifferentialPair b)
          '-' operator, for differential pairs.
static DifferentialPair subtract(int a, DifferentialPair b)
          '-' operator, for differential pairs.
static DifferentialPair subtract(long a, DifferentialPair b)
          '-' operator, for differential pairs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MINUS_ONE

public static final DifferentialPair MINUS_ONE
-1 constant.


ZERO

public static final DifferentialPair ZERO
0 constant.


ONE

public static final DifferentialPair ONE
+1 constant.


TWO

public static final DifferentialPair TWO
+2 constant.


THREE

public static final DifferentialPair THREE
+3 constant.


PI

public static final DifferentialPair PI
π (Archimede) constant.


E

public static final DifferentialPair E
e (Euler) constant, base of the natural logarithms.

Constructor Detail

DifferentialPair

public DifferentialPair(double u0,
                        double u1)
Build a new instance from its components.

Parameters:
u0 - value part of the differential pair
u1 - first derivative part of the differential pair
Method Detail

newVariable

public static DifferentialPair newVariable(double a)
Build an instance representing a univariate variable.

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 DifferentialPair(a, 1.0).

Parameters:
a - value of the variable
Returns:
the built variable

newConstant

public static DifferentialPair newConstant(double a)
Build an instance representing a constant.

Constant do not vary ... Hence their differential is 0. Calling this constructor has the same effect as calling DifferentialPair(a, 0.0).

Parameters:
a - value of the constant
Returns:
the built constant

getValue

public double getValue()
Get the value part of the differential pair.

Returns:
value part of the differential pair
See Also:
getFirstDerivative()

getFirstDerivative

public double getFirstDerivative()
Get the first derivative part of the differential pair.

Returns:
first derivative part of the differential pair
See Also:
getValue()

add

public static DifferentialPair add(DifferentialPair a,
                                   int b)
'+' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a+b

add

public static DifferentialPair add(int a,
                                   DifferentialPair b)
'+' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a+b

add

public static DifferentialPair add(DifferentialPair a,
                                   long b)
'+' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a+b

add

public static DifferentialPair add(long a,
                                   DifferentialPair b)
'+' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a+b

add

public static DifferentialPair add(DifferentialPair a,
                                   double b)
'+' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a+b

add

public static DifferentialPair add(double a,
                                   DifferentialPair b)
'+' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a+b

add

public static DifferentialPair add(DifferentialPair a,
                                   DifferentialPair b)
'+' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a+b

subtract

public static DifferentialPair subtract(DifferentialPair a,
                                        int b)
'-' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a-b

subtract

public static DifferentialPair subtract(int a,
                                        DifferentialPair b)
'-' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a-b

subtract

public static DifferentialPair subtract(DifferentialPair a,
                                        long b)
'-' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a-b

subtract

public static DifferentialPair subtract(long a,
                                        DifferentialPair b)
'-' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a-b

subtract

public static DifferentialPair subtract(DifferentialPair a,
                                        double b)
'-' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a-b

subtract

public static DifferentialPair subtract(double a,
                                        DifferentialPair b)
'-' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a-b

subtract

public static DifferentialPair subtract(DifferentialPair a,
                                        DifferentialPair b)
'-' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a-b

multiply

public static DifferentialPair multiply(DifferentialPair a,
                                        int b)
'×' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a×b

multiply

public static DifferentialPair multiply(int a,
                                        DifferentialPair b)
'×' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a×b

multiply

public static DifferentialPair multiply(DifferentialPair a,
                                        long b)
'×' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a×b

multiply

public static DifferentialPair multiply(long a,
                                        DifferentialPair b)
'×' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a×b

multiply

public static DifferentialPair multiply(DifferentialPair a,
                                        double b)
'×' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a×b

multiply

public static DifferentialPair multiply(double a,
                                        DifferentialPair b)
'×' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a×b

multiply

public static DifferentialPair multiply(DifferentialPair a,
                                        DifferentialPair b)
'×' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a×b

divide

public static DifferentialPair divide(DifferentialPair a,
                                      int b)
'÷s;' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a÷s;b

divide

public static DifferentialPair divide(int a,
                                      DifferentialPair b)
'÷s;' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a÷s;b

divide

public static DifferentialPair divide(DifferentialPair a,
                                      long b)
'÷s;' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a÷s;b

divide

public static DifferentialPair divide(long a,
                                      DifferentialPair b)
'÷s;' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a÷s;b

divide

public static DifferentialPair divide(DifferentialPair a,
                                      double b)
'÷s;' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a÷s;b

divide

public static DifferentialPair divide(double a,
                                      DifferentialPair b)
'÷s;' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a÷s;b

divide

public static DifferentialPair divide(DifferentialPair a,
                                      DifferentialPair b)
'÷s;' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a÷s;b

remainder

public static DifferentialPair remainder(int a,
                                         DifferentialPair b)
'%' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a%b

remainder

public static DifferentialPair remainder(DifferentialPair a,
                                         int b)
'%' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a%b

remainder

public static DifferentialPair remainder(long a,
                                         DifferentialPair b)
'%' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a%b

remainder

public static DifferentialPair remainder(DifferentialPair a,
                                         long b)
'%' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a%b

remainder

public static DifferentialPair remainder(double a,
                                         DifferentialPair b)
'%' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a%b

remainder

public static DifferentialPair remainder(DifferentialPair a,
                                         double b)
'%' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a%b

remainder

public static DifferentialPair remainder(DifferentialPair a,
                                         DifferentialPair b)
'%' operator, for differential pairs.

Parameters:
a - left hand side parameter of the operator
b - right hand side parameter of the operator
Returns:
a%b

negate

public static DifferentialPair negate(DifferentialPair a)
unary '-' operator, for differential pairs.

Parameters:
a - parameter of the operator
Returns:
-a

square

public static DifferentialPair square(DifferentialPair a)
squaring operation, for differential pairs.

Parameters:
a - parameter of the operator
Returns:
a2

cube

public static DifferentialPair cube(DifferentialPair a)
cubing operation, for differential pairs.

Parameters:
a - parameter of the operator
Returns:
a3


Copyright © 2008-2009 The Apache Software Foundation. All Rights Reserved.