json_graph_op

View page source

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_code , arg ]

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

log1p

log plus one

log

logarithm

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_code , first_arg , second_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_code , n_result , n_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 ( left , right , if_true , if_false )

is equivalent to

CondExpLe ( left , right , if_false , if_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_code , n_result , n_arg , [ left , right ] ]

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_code , name , n_result , n_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_code , name , n_result , n_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_code , name , call_id , n_result , n_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_code , before , after , n_result , n_arg , [ notpos , value ] ]

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