Prev Next ad_numeric.py Headings

@(@\newcommand{\B}[1]{{\bf #1}} \newcommand{\R}[1]{{\rm #1}}@)@
Binary Numeric Operators With an AD Result: Example and Test
 
from pycppad import *
# Example using a_float -----------------------------------------------------
def pycppad_test_ad_numeric() :
  x    = 2.
  y    = 3.
  a_x  = ad(x)
  a_y  = ad(y)
  #
  assert a_x + a_y == x + y
  assert a_x + y   == x + y
  assert x   + a_y == x + y
  #
  assert a_x - a_y == x - y
  assert a_x - y   == x - y
  assert x   - a_y == x - y
  #
  assert a_x * a_y == x * y
  assert a_x * y   == x * y
  assert x   * a_y == x * y
  #
  assert a_x / a_y == x / y
  assert a_x / y   == x / y
  assert x   / a_y == x / y
  #
  assert a_x ** a_y == x ** y
  assert a_x ** y   == x ** y
  assert x   ** a_y == x ** y
  #
# Example using a2float -----------------------------------------------------
def pycppad_test_ad_numeric_a2() :
  x    = 2.
  y    = 3.
  a2x  = ad(ad(x))
  a2y  = ad(ad(y))
  #
  assert a2x + a2y == x + y
  assert a2x + y   == x + y
  assert x   + a2y == x + y
  #
  assert a2x - a2y == x - y
  assert a2x - y   == x - y
  assert x   - a2y == x - y
  #
  assert a2x * a2y == x * y
  assert a2x * y   == x * y
  assert x   * a2y == x * y
  #
  assert a2x / a2y == x / y
  assert a2x / y   == x / y
  assert x   / a2y == x / y
  #
  assert a2x ** a2y == x ** y
  assert a2x ** y   == x ** y
  assert x   ** a2y == x ** y
  #

Input File: example/ad_numeric.py