def simplification_test(): x = e.Variable(5, "x") y = e.Variable(5, "y") z = e.Variable(5, "z") zero = e._Constant(0) one = e._Constant(1) check_equal_structure(x * y * z, e.mul(x, y, z)) check_equal_structure(e._Constant(1) * 2 * 3, e._Constant(6)) check_equal_structure(0 * x, zero) check_equal_structure(x * 0, zero) check_equal_structure(x * 1 * y * z, x * y * z) check_equal_structure(x * 1 * 2 * 3, x * 6) check_equal_structure(0 + x, x) check_equal_structure(x + 0, x) check_equal_structure(x + 1 + 2 + 3, x + 6) check_equal_structure(e.neg(2 * x), -2 * x) check_equal_structure(e.neg(e.neg(x)), x) check_equal_structure(e.inv(e.inv(x)), x) check_equal_structure(x * x, e.sq(x)) check_equal_structure(x * e.inv(x), e._Constant(1)) check_equal_structure(x + x, 2 * x) check_equal_structure(x - x, e._Constant(0)) check_equal_structure(3 * x - x + 8 * x, 10 * x)
def pds_test(): x = e.Variable(5, "x") y = e.Variable(5, "y") z = e.Variable(5, "z") check_pds(x, {x: 10, y:4}) check_pds(e.sq(x) + e.sqrt(y) + z, {x: 0.6, y: 10, z: 3}) check_pds(x - y, {x: 0.6, y: 10}) check_pds(x * e.pow(y, 4) * z, {x: 0.6, y: 10, z: 3}) check_pds(x / y, {x: 0.6, y: 10}) check_pds(e.sq(e.sq(x)), {x: 0.6}) check_pds(-x, {x: 0.6}) check_pds(e.sqrt(x), {x: 0.6}) check_pds(e.pow(x, 2), {x: 0.6}) check_pds(e.pow(x, 5), {x: 0.6}) check_pds(e.acos(x), {x: 0.6})