def test_sympify_mix_symbol_and_matrx(input_expr, output_expr, subs): assert sympify(input_expr, locals=subs) == output_expr subs = {k: sympify(v) for k, v in subs.items()} assert sympify(input_expr, locals=subs) == output_expr
def test_sympify_invalid_substitutions(subs): with pytest.raises(ValueError): sympify('x + y', locals=subs)
def test_sympify(input_expr, output_expr): assert sympify(input_expr) == output_expr assert sympify(sympify(input_expr)) == output_expr
def test_sympify_substitutions(input_expr, output_expr, subs): assert sympify(input_expr, locals=subs) == output_expr subs = {k: sympify(v) for k, v in subs.items()} assert sympify(input_expr, locals=subs) == output_expr
com_x**3 * A + com_x**2 * A + com_x**2 * B, com_x**3 * A + com_x**2 * A + com_x**2 * B + com_x * A ], [0, -com_x**3 * A - com_x**2 * A - com_x**2 * B]]) def test_make_commutative(): assert make_commutative(expr1, com_x).expand() == (make_commutative(expr1, x)).expand() assert make_commutative(expr1, com_x).expand() == (com_x**3 * A + com_x**2 * A + com_x**2 * B).expand() assert make_commutative(matr_com, com_x).expand() == (res_mat).expand() matr_monomials = sympify("[[x+y, a*x**2 + b*y], [y, x]]") x, y, z = position_operators a, b = sympy.symbols('a, b') fA, fB = sympy.symbols('A B', cls=sympy.Function) @pytest.mark.parametrize('expr, gens, output', [ (x * fA(x) * x + x**2 * a, None, { x**2: fA(x), a * x**2: 1 }), (x * fA(x) * x + x**2 * a, [x], { x**2: fA(x) + a }), (x**2, [x], { x**2: 1