a_double_binary#

View page source

a_double Binary Operators with an AD Result#

Syntax#

Python#

az = ax op ay
az = ax op y
az = x op ay

C++#

az = ax op ay
az = ax op y
az = fun ( x , ax )

op#

The binary operator op is one of the following: addition + , subtraction - , multiplication * , division / , or exponentiation ** . Note that exponentiation in c++ is special and always has the function syntax; i.e.,

az = pow ( ax , ay )
az = pow ( ax , y )
az = pow ( x , ay )
az = pow_int ( ax , i )

fun#

This function is one of the following: radd (right addition) , rsub (right subtraction) , rmul (right multiplication) , rdiv (right division).

ax#

This object has c++ prototype

      const a_double& ax

ay#

This object has c++ prototype

      const a_double& ay

y#

This object has c++ prototype

      const double& y

x#

This object has c++ prototype

      const double& x

az#

The result has c++ prototype

      a_double az

pow_int#

Exponentiation by an integer is an even more special case. Derivatives of the pow function will return nan when the argument value is zero; e.g. the derivative of \(\R{pow} (x, 2)\) at \(x = 0\) ( derivatives of the pow function work fine when \(x \ne 0\) ). This is because the derivative of the log function at zero results in a division by zero. This nan can be avoided by using multiplication, instead of logs, to compute powers when the exponent is an integer.

i#

The argument to the pow_int function has c++ prototype

      const int& i

Example#