Prev Next

@(@\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 .
Json AD Graph Operator Definitions

Notation

op_code
Each operator definition has a op_code value that is used to identify it for a particular json_ad_graph .

Arguments
The values first_arg , ... , last_arg are the node indices for arguments to an operator.

Unary Operators
All these operations create one result node and have the following Json definition:
{
    "op_code":      
op_code,
    "name":         
name,
    "n_arg":        1
}
where name is a string . A corresponding op_usage has the form
    [ 
op_codearg ]
The possible values for the string name are listed in the table below. The corresponding result is the node value as a function of the argument value.
name result
abs absolute value
acos inverse cosine
acosh inverse hyperbolic cosine
asin inverse sine
asinh inverse hyperbolic sine
atan inverse tangent
atanh inverse hyperbolic sine
cos cosine
cosh hyperbolic cosine
erf error functions
erfc complementary error function
exp exponential
expm1 minus one plus the exponential
log logarithm
log1p log plus one
neg negative
sign sign function
sin sine
sinh hyperbolic sine
sqrt square root
tan tangent
tanh hyperbolic tangent

Example
The file json_unary_op.cpp is an example and test for one of these operators.

Binary Operators
All these operations create one result node and have the following Json definition:
{
    "op_code":      
op_code,
    "name":         
name,
    "n_arg":        2
}
where name is a string . A corresponding op_usage has the form
    [ 
op_codefirst_argsecond_arg ]
The possible values for the string name are listed below:

add
The result is the first argument value plus the second argument value; see the example and test json_add_op.cpp .

azmul
If the first argument value is zero, the result is zero (even if the second argument value is nan). Otherwise the result is the first argument value times the second argument value; see the example and test json_azmul_op.cpp .

div
The result is the first argument value divided by the second argument value; see the example and test json_div_op.cpp .

mul
The result is the first argument value times the second argument value; see the example and test json_mul_op.cpp .

pow
The result is the first argument value raised to the second argument value; see the example and test json_pow_op.cpp .

sub
The result is the first argument value minus the second argument value; see the example and test json_sub_op.cpp .

sum
This operator has the following Json definition:
{
    "op_code":      
op_code,
    "name":         "sum"
}
A corresponding op_usage has the form
    [ 
op_coden_resultn_arg, [ first_arg...last_arg ] ]
where n_result is always 1. This operation creates one node with value equal to the sum of values corresponding to all of its argument nodes.

Example
The file json_sum_op.cpp is an example and test of this operation.

Conditional Expressions
These operators are conditional expressions and have the following Json definition:
{
    "op_code":      
op_code,
    "name":         "cexp_
rel,
    "n_arg":        4
}
where rel is eq (equal), le (less than or equal), or lt (less than). The first argument is left , the second is right , the third is if_true , the fourth is if_false , the result is given by
    if( 
left cop right)
        
result = if_true;
    else
        
result = if_false;
where the comparison cop is define by the cases below:

cexp_eq
For this operator cop is ==

cexp_le
For this operator cop is <=

cexp_lt
For this operator cop is <

Other Comparisons
Note that
    CondExpGt(
leftrightif_trueif_false)
is equivalent to
    CondExpLe(
leftrightif_falseif_true)
Similar conversions can be used for all the possible conditional expressions .

Example
The file json_cexp_op.cpp is an example and test for one of these operators.

Compare Operators
These are comparison operators and have the following Json definition:
{
    "op_code":      
op_code,
    "name":         "comp_
rel"
}
where rel is eq (equal), ne (not equal), le (less than or equal), or lt (less than). A corresponding op_usage has the form
    [ 
op_coden_resultn_arg, [ leftright ] ]

n_result
This is always zero because a comparison operator does not create any new nodes.

n_arg
This is always two because a comparison operator has two argument nodes corresponding to the left and right operands.

left, right
The logical comparison is defined as the logical expression
    
left cop right
The comparison cop is define by the cases below. The Json graph corresponds to the comparison being true. If, for a value of the independent parameters and variables, the comparison is false, the Json graph may no longer be valid. For example, the Json graph may only contain the code for the true case below:
    if( 
left cop right )
    {   
source code when result is true }
    else
    {   
source code when result is false }
Including this operator enables CppAD to detect when the graph may no longer be a valid representation of the intended function.

comp_eq
For this operator cop is ==

comp_le
For this operator cop is <=

comp_lt
For this operator cop is <

comp_ne
For this operator cop is !=

Other Comparisons
The comparison result true for left > right is equivalent to the comparison result true for right < left . The comparison result false for left > right is equivalent to the comparison result true for left <= right . In a similar fashion, all the possible comparisons results can be converted to a true result for one of the comparisons above.

Example
The file json_comp_op.cpp is an example and test for one of these operators.

Discrete Functions
This operator has the following Json definition:
{
    "op_code":     
op_code,
    "name":        "discrete"
}
A corresponding op_usage has the form
    [ 
op_codenamen_resultn_arg, [ arg ]  ]

name
The value name is a string specifying the name of the discrete function that is called.

n_result
This is always 1 because a discrete function creates one new node. The result node value is the specified discrete function of the argument value.

n_arg
This is always 1 because a discrete function has one argument node.

arg
is the node index for the argument to the discrete function.

Example
the example and test json_discrete_op.cpp .

Atomic Functions
These operators create n_result nodes with values determined by an evaluation of the an atomic_three or atomic_four function.

Atomic Three
This operator has the following Json definition:
{
    "op_code":      
op_code,
    "name":          "atom"
}
A corresponding op_usage has the form
    [ 
op_codenamen_resultn_arg,
        [ 
first_arg...last_arg ]
    ]

Atomic Four
This operator has the following Json definition:
{
    "op_code":      
op_code,
    "name":          "atom4"
}
A corresponding op_usage has the form
    [ 
op_codenamecall_idn_resultn_arg,
        [ 
first_arg...last_arg ]
    ]

name
The value name is a string specifying the name of the atomic_three function that is called.

call_id
is a non-negative integer specifying the call_id for an atomic four function.

n_result
is the number of results for this function; i.e., its range space dimension.

n_arg
is the number of arguments to this function; i.e., its domain space dimension.

first_arg, ..., last_arg
The values corresponding to the node indices first_arg , ..., last_arg are the arguments (independent variables) for the atomic function evaluation. In the case where the atomic function is a chkpoint_two function, the independent dynamic parameters are specified by calling its new_dynamic routine.

Example
the example and test json_atom_op.cpp .

Print
This operator has the following Json definition:
{
    "op_code":      
op_code,
    "name":          "print"
}
A corresponding op_usage has the form
    [ 
op_codebeforeaftern_resultn_arg, [ notposvalue ] ]

before
is a string that is printed before the value for this operator.

after
is a string that is printed after the value for this operator.

n_result
This is always zero because a print operator does not create any new nodes.

n_arg
This is always two because a print operator has two argument nodes.

notpos
This is notpos which determines if the value is printed.

value
This is the value that is printed.

Example
The file json_print_op.cpp is an example and test of this operator.

Contents
json_unary_op.cppJson Unary Operators: Example and Test
json_add_op.cppJson add Operator: Example and Test
json_azmul_op.cppJson azmul Operator: Example and Test
json_div_op.cppJson div Operator: Example and Test
json_mul_op.cppJson mul Operator: Example and Test
json_pow_op.cppJson pow Operator: Example and Test
json_sub_op.cppJson sub Operator: Example and Test
json_sum_op.cppJson sum Operator: Example and Test
json_cexp_op.cppJson Conditional Expressions: Example and Test
json_comp_op.cppJson Comparison Operators: Example and Test
json_discrete_op.cppJson add Operator: Example and Test
json_atom_op.cppJson Atomic Function Three Operator: Example and Test
json_atom4_op.cppJson Atomic Function Operator: Example and Test
json_print_op.cppJson AD Graph print Operator: Example and Test

Input File: include/cppad/core/graph/json_graph_op.omh