Prev Next zdouble

@(@\newcommand{\W}[1]{ \; #1 \; } \newcommand{\R}[1]{ {\rm #1} } \newcommand{\B}[1]{ {\bf #1} } \newcommand{\D}[2]{ \frac{\partial #1}{\partial #2} } \newcommand{\DD}[3]{ \frac{\partial^2 #1}{\partial #2 \partial #3} } \newcommand{\Dpow}[2]{ \frac{\partial^{#1}}{\partial {#2}^{#1}} } \newcommand{\dpow}[2]{ \frac{ {\rm d}^{#1}}{{\rm d}\, {#2}^{#1}} }@)@ This is cppad-20221105 documentation. Here is a link to its current documentation .
zdouble: An AD Base Type With Absolute Zero

Deprecated 2015-09-26
Use the function azmul instead.

Absolute Zero
The zdouble class acts like the double type with the added property that zero times any value is zero. This includes zero time nan and zero times infinity. In addition, zero divided by any value and any value times zero are also zero.

Syntax

Constructor and Assignment
    zdouble z
    zdouble z(x)
    zdouble z(i)
    z1 op x
were i is a size_t, long, or int, x is a double or zdouble, and op is =, +=, -=, *= or /=-.

Comparison Operators
    b = z op x
    b = x op z
where b is a bool object, z is a zdouble object, x is a double or zdouble object, and op is ==, !=, <=, >=, < or >.

Arithmetic Operators
    z2 = z1 op x
    z2 = x op z1
where z1 , z2 are zdouble objects, x is a double or zdouble object, and op is +, -, * or /.

Standard Math
    z2 = fun(z1)
    z3 = pow(z1z2)
where z1 , z2 , z3 are zdouble objects and fun is a unary_standard_math function.

Nan
There is a specialization of nan so that
    z2
 = nan(z1)
returns 'not a number' when z1 has type zdouble. Note that this template function needs to be specialized because     zdouble(0.0) ==  zdouble(0.0) / zdouble(0.0)

Motivation

General
Often during computing (and more so in parallel computing) alternative values for an expression are computed and one of the alternatives is chosen using some boolean variable. This is often represented by
    
result = flag * value_if_true + (1 - flag) * value_if_false
where flag is one for true and zero for false. This representation does not work for double when the value being multiplied by zero is +inf, -inf, or nan.

CppAD
In CppAD one can use conditional expressions to achieve the representation
    
result = flag * value_if_true + (1 - flag) * value_if_false
This works fine except when there are multiple levels of AD ; e.g., when using AD< AD<double> > . In this case the corresponding AD function objects have type ADFun< AD<double> > . When these AD function objects compute derivatives using reverse mode, the conditional expressions are represented use zeros to multiply the expression that is not used. Using AD< AD<zdouble> > instead of AD< AD<double> > makes this representation work and fixes the problem.

Base Type Requirements
The type zdouble satisfies all of the CppAD base type requirements .
Input File: include/cppad/core/zdouble.hpp