public class DerivativeStructure extends Object implements Derivative<DerivativeStructure>, Serializable
This class is the workhorse of the differentiation package.
This class is an implementation of the extension to Rall's numbers described in Dan Kalman's paper Doubly Recursive Multivariate Automatic Differentiation, Mathematics Magazine, vol. 75, no. 3, June 2002. Rall's numbers are an extension to the real numbers used throughout mathematical expressions; they hold the derivative together with the value of a function. Dan Kalman's derivative structures hold all partial derivatives up to any specified order, with respect to any number of free parameters. Rall's numbers therefore can be seen as derivative structures for order one derivative and one free parameter, and real numbers can be seen as derivative structures with zero order derivative and no free parameters.
DerivativeStructure
instances can be used directly thanks to
the arithmetic operators to the mathematical functions provided as
methods by this class (+, -, *, /, %, sin, cos ...).
Implementing complex expressions by hand using these classes is
a tedious and error-prone task but has the advantage of having no limitation
on the derivation order despite not requiring users to compute the derivatives by
themselves. Implementing complex expression can also be done by developing computation
code using standard primitive double values and to use differentiators
to create the DerivativeStructure
-based instances. This method is simpler but may be limited in
the accuracy and derivation orders and may be computationally intensive (this is
typically the case for finite differences
differentiator
.
Instances of this class are guaranteed to be immutable.
DSCompiler
,
FieldDerivativeStructure
,
Serialized FormModifier and Type | Method and Description |
---|---|
DerivativeStructure |
abs()
absolute value.
|
DerivativeStructure |
acos()
Arc cosine operation.
|
DerivativeStructure |
acosh()
Inverse hyperbolic cosine operation.
|
DerivativeStructure |
add(DerivativeStructure a)
Compute this + a.
|
DerivativeStructure |
add(double a)
'+' operator.
|
DerivativeStructure |
asin()
Arc sine operation.
|
DerivativeStructure |
asinh()
Inverse hyperbolic sine operation.
|
DerivativeStructure |
atan()
Arc tangent operation.
|
DerivativeStructure |
atan2(DerivativeStructure x)
Two arguments arc tangent operation.
|
static DerivativeStructure |
atan2(DerivativeStructure y,
DerivativeStructure x)
Two arguments arc tangent operation.
|
DerivativeStructure |
atanh()
Inverse hyperbolic tangent operation.
|
DerivativeStructure |
cbrt()
Cubic root.
|
DerivativeStructure |
ceil()
Get the smallest whole number larger than instance.
|
DerivativeStructure |
compose(double... f)
Compute composition of the instance by a univariate function.
|
DerivativeStructure |
copySign(DerivativeStructure sign)
Returns the instance with the sign of the argument.
|
DerivativeStructure |
copySign(double sign)
Returns the instance with the sign of the argument.
|
DerivativeStructure |
cos()
Cosine operation.
|
DerivativeStructure |
cosh()
Hyperbolic cosine operation.
|
DerivativeStructure |
divide(DerivativeStructure a)
Compute this ÷ a.
|
DerivativeStructure |
divide(double a)
'÷' operator.
|
boolean |
equals(Object other)
Test for the equality of two derivative structures.
|
DerivativeStructure |
exp()
Exponential.
|
DerivativeStructure |
expm1()
Exponential minus 1.
|
DerivativeStructure |
floor()
Get the largest whole number smaller than instance.
|
double[] |
getAllDerivatives()
Get all partial derivatives.
|
int |
getExponent()
Return the exponent of the instance value, removing the bias.
|
DSFactory |
getFactory()
Get the factory that built the instance.
|
Field<DerivativeStructure> |
getField()
Get the
Field to which the instance belongs. |
int |
getFreeParameters()
Get the number of free parameters.
|
int |
getOrder()
Get the derivation order.
|
double |
getPartialDerivative(int... orders)
Get a partial derivative.
|
DerivativeStructure |
getPi()
Get the Archimedes constant π.
|
double |
getReal()
Get the real value of the number.
|
double |
getValue()
Get the value part of the derivative structure.
|
int |
hashCode()
Get a hashCode for the derivative structure.
|
DerivativeStructure |
hypot(DerivativeStructure y)
Returns the hypotenuse of a triangle with sides
this and y
- sqrt(this2 +y2)
avoiding intermediate overflow or underflow. |
static DerivativeStructure |
hypot(DerivativeStructure x,
DerivativeStructure y)
Returns the hypotenuse of a triangle with sides
x and y
- sqrt(x2 +y2)
avoiding intermediate overflow or underflow. |
DerivativeStructure |
linearCombination(DerivativeStructure[] a,
DerivativeStructure[] b)
Compute a linear combination.
|
DerivativeStructure |
linearCombination(DerivativeStructure a1,
DerivativeStructure b1,
DerivativeStructure a2,
DerivativeStructure b2)
Compute a linear combination.
|
DerivativeStructure |
linearCombination(DerivativeStructure a1,
DerivativeStructure b1,
DerivativeStructure a2,
DerivativeStructure b2,
DerivativeStructure a3,
DerivativeStructure b3)
Compute a linear combination.
|
DerivativeStructure |
linearCombination(DerivativeStructure a1,
DerivativeStructure b1,
DerivativeStructure a2,
DerivativeStructure b2,
DerivativeStructure a3,
DerivativeStructure b3,
DerivativeStructure a4,
DerivativeStructure b4)
Compute a linear combination.
|
DerivativeStructure |
linearCombination(double[] a,
DerivativeStructure[] b)
Compute a linear combination.
|
DerivativeStructure |
linearCombination(double a1,
DerivativeStructure b1,
double a2,
DerivativeStructure b2)
Compute a linear combination.
|
DerivativeStructure |
linearCombination(double a1,
DerivativeStructure b1,
double a2,
DerivativeStructure b2,
double a3,
DerivativeStructure b3)
Compute a linear combination.
|
DerivativeStructure |
linearCombination(double a1,
DerivativeStructure b1,
double a2,
DerivativeStructure b2,
double a3,
DerivativeStructure b3,
double a4,
DerivativeStructure b4)
Compute a linear combination.
|
DerivativeStructure |
log()
Natural logarithm.
|
DerivativeStructure |
log10()
Base 10 logarithm.
|
DerivativeStructure |
log1p()
Shifted natural logarithm.
|
DerivativeStructure |
multiply(DerivativeStructure a)
Compute this × a.
|
DerivativeStructure |
multiply(double a)
'×' operator.
|
DerivativeStructure |
multiply(int n)
Compute n × this.
|
DerivativeStructure |
negate()
Returns the additive inverse of
this element. |
DerivativeStructure |
newInstance(double value)
Create an instance corresponding to a constant real value.
|
DerivativeStructure |
pow(DerivativeStructure e)
Power operation.
|
DerivativeStructure |
pow(double p)
Power operation.
|
static DerivativeStructure |
pow(double a,
DerivativeStructure x)
Compute ax where a is a double and x a
DerivativeStructure |
DerivativeStructure |
pow(int n)
Integer power operation.
|
DerivativeStructure |
reciprocal()
Returns the multiplicative inverse of
this element. |
DerivativeStructure |
remainder(DerivativeStructure a)
IEEE remainder operator.
|
DerivativeStructure |
remainder(double a)
IEEE remainder operator.
|
DerivativeStructure |
rint()
Get the whole number that is the nearest to the instance, or the even one if x is exactly half way between two integers.
|
DerivativeStructure |
rootN(int n)
Nth root.
|
DerivativeStructure |
scalb(int n)
Multiply the instance by a power of 2.
|
DerivativeStructure |
sign()
Compute the sign of the instance.
|
DerivativeStructure |
sin()
Sine operation.
|
FieldSinCos<DerivativeStructure> |
sinCos()
Combined Sine and Cosine operation.
|
DerivativeStructure |
sinh()
Hyperbolic sine operation.
|
FieldSinhCosh<DerivativeStructure> |
sinhCosh()
Combined hyperbolic sine and sosine operation.
|
DerivativeStructure |
sqrt()
Square root.
|
DerivativeStructure |
subtract(DerivativeStructure a)
Compute this - a.
|
DerivativeStructure |
subtract(double a)
'-' operator.
|
DerivativeStructure |
tan()
Tangent operation.
|
DerivativeStructure |
tanh()
Hyperbolic tangent operation.
|
double |
taylor(double... delta)
Evaluate Taylor expansion a derivative structure.
|
DerivativeStructure |
toDegrees()
Convert radians to degrees, with error of less than 0.5 ULP
|
DerivativeStructure |
toRadians()
Convert degrees to radians, with error of less than 0.5 ULP
|
DerivativeStructure |
ulp()
Compute least significant bit (Unit in Last Position) for a number.
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
isFinite, isInfinite, isNaN, norm, round
isZero
public DerivativeStructure newInstance(double value)
newInstance
in interface CalculusFieldElement<DerivativeStructure>
value
- constant real valuepublic DSFactory getFactory()
public int getFreeParameters()
Derivative
getFreeParameters
in interface Derivative<DerivativeStructure>
public int getOrder()
Derivative
getOrder
in interface Derivative<DerivativeStructure>
public double getReal()
getReal
in interface FieldElement<DerivativeStructure>
public double getValue()
getValue
in interface Derivative<DerivativeStructure>
getPartialDerivative(int...)
public double getPartialDerivative(int... orders) throws MathIllegalArgumentException
getPartialDerivative
in interface Derivative<DerivativeStructure>
orders
- derivation orders with respect to each variable (if all orders are 0,
the value is returned)MathIllegalArgumentException
- if the numbers of variables does not
match the instanceDerivative.getValue()
public double[] getAllDerivatives()
DSCompiler.getPartialDerivativeIndex(int...)
public DerivativeStructure add(double a)
add
in interface CalculusFieldElement<DerivativeStructure>
a
- right hand side parameter of the operatorpublic DerivativeStructure add(DerivativeStructure a) throws MathIllegalArgumentException
add
in interface FieldElement<DerivativeStructure>
a
- element to addMathIllegalArgumentException
- if number of free parameters
or orders do not matchpublic DerivativeStructure subtract(double a)
subtract
in interface CalculusFieldElement<DerivativeStructure>
a
- right hand side parameter of the operatorpublic DerivativeStructure subtract(DerivativeStructure a) throws MathIllegalArgumentException
subtract
in interface FieldElement<DerivativeStructure>
a
- element to subtractMathIllegalArgumentException
- if number of free parameters
or orders do not matchpublic DerivativeStructure multiply(int n)
multiply
in interface FieldElement<DerivativeStructure>
n
- Number of times this
must be added to itself.public DerivativeStructure multiply(double a)
multiply
in interface CalculusFieldElement<DerivativeStructure>
a
- right hand side parameter of the operatorpublic DerivativeStructure multiply(DerivativeStructure a) throws MathIllegalArgumentException
multiply
in interface FieldElement<DerivativeStructure>
a
- element to multiplyMathIllegalArgumentException
- if number of free parameters
or orders do not matchpublic DerivativeStructure divide(double a)
divide
in interface CalculusFieldElement<DerivativeStructure>
a
- right hand side parameter of the operatorpublic DerivativeStructure divide(DerivativeStructure a) throws MathIllegalArgumentException
divide
in interface FieldElement<DerivativeStructure>
a
- element to divide byMathIllegalArgumentException
- if number of free parameters
or orders do not matchpublic DerivativeStructure remainder(double a)
remainder
in interface CalculusFieldElement<DerivativeStructure>
a
- right hand side parameter of the operatorpublic DerivativeStructure remainder(DerivativeStructure a) throws MathIllegalArgumentException
remainder
in interface CalculusFieldElement<DerivativeStructure>
a
- right hand side parameter of the operatorMathIllegalArgumentException
- if number of free parameters
or orders do not matchpublic DerivativeStructure negate()
this
element.negate
in interface FieldElement<DerivativeStructure>
this
.public DerivativeStructure abs()
Just another name for CalculusFieldElement.norm()
abs
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure ceil()
ceil
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure floor()
floor
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure rint()
rint
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure sign()
sign
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure copySign(DerivativeStructure sign)
sign
argument is treated as positive.copySign
in interface CalculusFieldElement<DerivativeStructure>
sign
- the sign for the returned valuesign
argumentpublic DerivativeStructure copySign(double sign)
sign
argument is treated as positive.copySign
in interface CalculusFieldElement<DerivativeStructure>
sign
- the sign for the returned valuesign
argumentpublic int getExponent()
For double numbers of the form 2x, the unbiased exponent is exactly x.
getExponent
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure scalb(int n)
scalb
in interface CalculusFieldElement<DerivativeStructure>
n
- power of 2public DerivativeStructure ulp()
The ulp
function is a step function, hence all its derivatives are 0.
ulp
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure hypot(DerivativeStructure y) throws MathIllegalArgumentException
this
and y
- sqrt(this2 +y2)
avoiding intermediate overflow or underflow.
hypot
in interface CalculusFieldElement<DerivativeStructure>
y
- a valueMathIllegalArgumentException
- if number of free parameters
or orders do not matchpublic static DerivativeStructure hypot(DerivativeStructure x, DerivativeStructure y) throws MathIllegalArgumentException
x
and y
- sqrt(x2 +y2)
avoiding intermediate overflow or underflow.
x
- a valuey
- a valueMathIllegalArgumentException
- if number of free parameters
or orders do not matchpublic DerivativeStructure compose(double... f) throws MathIllegalArgumentException
compose
in interface Derivative<DerivativeStructure>
f
- array of value and derivatives of the function at
the current point (i.e. [f(getValue()
),
f'(getValue()
), f''(getValue()
)...]).MathIllegalArgumentException
- if the number of derivatives
in the array is not equal to order
+ 1public DerivativeStructure reciprocal()
this
element.reciprocal
in interface CalculusFieldElement<DerivativeStructure>
reciprocal
in interface FieldElement<DerivativeStructure>
this
.public DerivativeStructure sqrt()
sqrt
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure cbrt()
cbrt
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure rootN(int n)
rootN
in interface CalculusFieldElement<DerivativeStructure>
n
- order of the rootpublic Field<DerivativeStructure> getField()
Field
to which the instance belongs.getField
in interface FieldElement<DerivativeStructure>
Field
to which the instance belongspublic static DerivativeStructure pow(double a, DerivativeStructure x)
DerivativeStructure
a
- number to exponentiatex
- power to applypublic DerivativeStructure pow(double p)
pow
in interface CalculusFieldElement<DerivativeStructure>
p
- power to applypublic DerivativeStructure pow(int n)
pow
in interface CalculusFieldElement<DerivativeStructure>
n
- power to applypublic DerivativeStructure pow(DerivativeStructure e) throws MathIllegalArgumentException
pow
in interface CalculusFieldElement<DerivativeStructure>
e
- exponentMathIllegalArgumentException
- if number of free parameters
or orders do not matchpublic DerivativeStructure exp()
exp
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure expm1()
expm1
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure log()
log
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure log1p()
log1p
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure log10()
log10
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure cos()
cos
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure sin()
sin
in interface CalculusFieldElement<DerivativeStructure>
public FieldSinCos<DerivativeStructure> sinCos()
sinCos
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure tan()
tan
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure acos()
acos
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure asin()
asin
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure atan()
atan
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure atan2(DerivativeStructure x) throws MathIllegalArgumentException
Beware of the order or arguments! As this is based on a
two-arguments functions, in order to be consistent with
arguments order, the instance is the first argument
and the single provided argument is the second argument.
In order to be consistent with programming languages atan2
,
this method computes atan2(this, x)
, i.e. the instance
represents the y
argument and the x
argument is
the one passed as a single argument. This may seem confusing especially
for users of Wolfram alpha, as this site is not consistent
with programming languages atan2
two-arguments arc tangent
and puts x
as its first argument.
atan2
in interface CalculusFieldElement<DerivativeStructure>
x
- second argument of the arc tangentMathIllegalArgumentException
- if number of free parameters or orders are inconsistentpublic static DerivativeStructure atan2(DerivativeStructure y, DerivativeStructure x) throws MathIllegalArgumentException
y
- first argument of the arc tangentx
- second argument of the arc tangentMathIllegalArgumentException
- if number of free parameters
or orders do not matchpublic DerivativeStructure cosh()
cosh
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure sinh()
sinh
in interface CalculusFieldElement<DerivativeStructure>
public FieldSinhCosh<DerivativeStructure> sinhCosh()
sinhCosh
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure tanh()
tanh
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure acosh()
acosh
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure asinh()
asinh
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure atanh()
atanh
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure toDegrees()
toDegrees
in interface CalculusFieldElement<DerivativeStructure>
public DerivativeStructure toRadians()
toRadians
in interface CalculusFieldElement<DerivativeStructure>
public double taylor(double... delta) throws MathRuntimeException
delta
- parameters offsets (Δx, Δy, ...)MathRuntimeException
- if factorials becomes too largepublic DerivativeStructure linearCombination(DerivativeStructure[] a, DerivativeStructure[] b) throws MathIllegalArgumentException
linearCombination
in interface CalculusFieldElement<DerivativeStructure>
a
- Factors.b
- Factors.Σi ai bi
.MathIllegalArgumentException
- if number of free parameters
or orders do not matchpublic DerivativeStructure linearCombination(double[] a, DerivativeStructure[] b) throws MathIllegalArgumentException
linearCombination
in interface CalculusFieldElement<DerivativeStructure>
a
- Factors.b
- Factors.Σi ai bi
.MathIllegalArgumentException
- if number of free parameters
or orders do not matchpublic DerivativeStructure linearCombination(DerivativeStructure a1, DerivativeStructure b1, DerivativeStructure a2, DerivativeStructure b2) throws MathIllegalArgumentException
linearCombination
in interface CalculusFieldElement<DerivativeStructure>
a1
- first factor of the first termb1
- second factor of the first terma2
- first factor of the second termb2
- second factor of the second termMathIllegalArgumentException
- if number of free parameters
or orders do not matchCalculusFieldElement.linearCombination(FieldElement, FieldElement, FieldElement, FieldElement, FieldElement, FieldElement)
,
CalculusFieldElement.linearCombination(FieldElement, FieldElement, FieldElement, FieldElement, FieldElement, FieldElement, FieldElement, FieldElement)
public DerivativeStructure linearCombination(double a1, DerivativeStructure b1, double a2, DerivativeStructure b2) throws MathIllegalArgumentException
linearCombination
in interface CalculusFieldElement<DerivativeStructure>
a1
- first factor of the first termb1
- second factor of the first terma2
- first factor of the second termb2
- second factor of the second termMathIllegalArgumentException
- if number of free parameters
or orders do not matchCalculusFieldElement.linearCombination(double, FieldElement, double, FieldElement, double, FieldElement)
,
CalculusFieldElement.linearCombination(double, FieldElement, double, FieldElement, double, FieldElement, double, FieldElement)
public DerivativeStructure linearCombination(DerivativeStructure a1, DerivativeStructure b1, DerivativeStructure a2, DerivativeStructure b2, DerivativeStructure a3, DerivativeStructure b3) throws MathIllegalArgumentException
linearCombination
in interface CalculusFieldElement<DerivativeStructure>
a1
- first factor of the first termb1
- second factor of the first terma2
- first factor of the second termb2
- second factor of the second terma3
- first factor of the third termb3
- second factor of the third termMathIllegalArgumentException
- if number of free parameters
or orders do not matchCalculusFieldElement.linearCombination(FieldElement, FieldElement, FieldElement, FieldElement)
,
CalculusFieldElement.linearCombination(FieldElement, FieldElement, FieldElement, FieldElement, FieldElement, FieldElement, FieldElement, FieldElement)
public DerivativeStructure linearCombination(double a1, DerivativeStructure b1, double a2, DerivativeStructure b2, double a3, DerivativeStructure b3) throws MathIllegalArgumentException
linearCombination
in interface CalculusFieldElement<DerivativeStructure>
a1
- first factor of the first termb1
- second factor of the first terma2
- first factor of the second termb2
- second factor of the second terma3
- first factor of the third termb3
- second factor of the third termMathIllegalArgumentException
- if number of free parameters
or orders do not matchCalculusFieldElement.linearCombination(double, FieldElement, double, FieldElement)
,
CalculusFieldElement.linearCombination(double, FieldElement, double, FieldElement, double, FieldElement, double, FieldElement)
public DerivativeStructure linearCombination(DerivativeStructure a1, DerivativeStructure b1, DerivativeStructure a2, DerivativeStructure b2, DerivativeStructure a3, DerivativeStructure b3, DerivativeStructure a4, DerivativeStructure b4) throws MathIllegalArgumentException
linearCombination
in interface CalculusFieldElement<DerivativeStructure>
a1
- first factor of the first termb1
- second factor of the first terma2
- first factor of the second termb2
- second factor of the second terma3
- first factor of the third termb3
- second factor of the third terma4
- first factor of the fourth termb4
- second factor of the fourth termMathIllegalArgumentException
- if number of free parameters
or orders do not matchCalculusFieldElement.linearCombination(FieldElement, FieldElement, FieldElement, FieldElement)
,
CalculusFieldElement.linearCombination(FieldElement, FieldElement, FieldElement, FieldElement, FieldElement, FieldElement)
public DerivativeStructure linearCombination(double a1, DerivativeStructure b1, double a2, DerivativeStructure b2, double a3, DerivativeStructure b3, double a4, DerivativeStructure b4) throws MathIllegalArgumentException
linearCombination
in interface CalculusFieldElement<DerivativeStructure>
a1
- first factor of the first termb1
- second factor of the first terma2
- first factor of the second termb2
- second factor of the second terma3
- first factor of the third termb3
- second factor of the third terma4
- first factor of the fourth termb4
- second factor of the fourth termMathIllegalArgumentException
- if number of free parameters
or orders do not matchCalculusFieldElement.linearCombination(double, FieldElement, double, FieldElement)
,
CalculusFieldElement.linearCombination(double, FieldElement, double, FieldElement, double, FieldElement)
public DerivativeStructure getPi()
Archimedes constant is the ratio of a circle's circumference to its diameter.
getPi
in interface CalculusFieldElement<DerivativeStructure>
public boolean equals(Object other)
Derivative structures are considered equal if they have the same number of free parameters, the same derivation order, and the same derivatives.
Copyright © 2016-2021 CS GROUP. All rights reserved.