コード例 #1
0
    def test_multiple_relational(self):
        from sympy import Eq, Ne, Lt, Le, Gt, Ge
        from mitesting.sympy_customized import Or, And
        from mitesting.customized_commands import Gts, Lts

        a=Symbol('a')
        b=Symbol('b')
        c=Symbol('c')
        x=Symbol('x')
        y=Symbol('y')
        z=Symbol('z')
 
        expr=parse_expr("a < b <=c <x")
        self.assertEqual(expr, And(Lt(a,b), Le(b,c), Lt(c,x)))

        expr=parse_expr("a < b <=c <x", replace_symmetric_intervals=True)
        self.assertEqual(expr, And(Lt(a,b), Le(b,c), Lt(c,x)))

        expr=parse_expr("a>b >= c >=x")
        self.assertEqual(expr, And(Gt(a,b), Ge(b,c), Ge(c,x)))

        expr=parse_expr("a < b <=c <x", evaluate=False)
        self.assertEqual(expr, Lts((a,b,c,x), (True, False, True), evaluate=False))
        self.assertEqual(latex(expr), "a < b \leq c < x")
        

        expr=parse_expr("a>b >= c >=x", evaluate=False)
        self.assertEqual(expr, Gts((a,b,c,x), (True, False, False), evaluate=False))
        self.assertEqual(latex(expr), "a > b \geq c \geq x")
コード例 #2
0
ファイル: math_objects.py プロジェクト: dqnykamp/mathinsight
    def __str__(self):
        """
        Return latex version of expression as string
        Use symbol_name_dict from create_symbol_name_dict to convert
        some symbols into their corresponding latex expressions.

        In addition, if expression is a LinearEntity, then display as equation
        of line set to zero.
        """

        from sympy.geometry.line import LinearEntity

        expression = self._expression
        symbol_name_dict = create_symbol_name_dict()

        if isinstance(expression, LinearEntity):
            xvar = self._parameters.get("xvar", "x")
            yvar = self._parameters.get("yvar", "y")
            output = "%s = 0" % latex(expression.equation(x=xvar, y=yvar), symbol_names=symbol_name_dict)
        else:
            try:
                output = latex(expression, symbol_names=symbol_name_dict)
            except RuntimeError:
                # for now, since dividing by one creates infinite recursion
                # in latex printer, use sstr print
                from sympy.printing import sstr

                output = sstr(expression)
            except:
                output = "[error]"

        return output
コード例 #3
0
    def test_evalf(self):
        """
        #These fail due to behavior of evalf.

        context=Context({"a": 1.2345})
        result=Template("{% load question_tags %}{{a|evalf:4}}").render(context)
        self.assertEqual(result,"1.235")

        x=Symbol('x')
        context=Context({"a": 1.2345*x})
        result=Template("{% load question_tags %}{{a|evalf:4}}").render(context)
        self.assertEqual(result,latex(1.235*x))

        context=Context({"a": math_object(1.2345*x)})
        result=Template("{% load question_tags %}{{a|evalf:4}}").render(context)
        self.assertEqual(result,latex(1.235*x))
        """

        context=Context({"a": 1.2345})
        result=Template("{% load question_tags %}{{a|evalf:3}}").render(context)
        self.assertEqual(result,"1.23")

        x=Symbol('x')
        context=Context({"a": 1.2345*x})
        result=Template("{% load question_tags %}{{a|evalf:3}}").render(context)
        self.assertEqual(result,latex(1.23*x))

        context=Context({"a": math_object(1.2345*x)})
        result=Template("{% load question_tags %}{{a|evalf:3}}").render(context)
        self.assertEqual(result,latex(1.23*x))
コード例 #4
0
    def test_conditional_probability_expression(self):
        from mitesting.customized_commands import conditional_probability_expression
        from mitesting.sympy_customized import SymbolCallable

        A=Symbol("A")
        B=Symbol("B")
        P=SymbolCallable("P")

        expr=parse_expr("A|B")
        self.assertEqual(expr, conditional_probability_expression(A,B))
        self.assertEqual(latex(expr), "A ~|~ B")

        expr=parse_expr("P(A|B)", local_dict={'P': P})
        self.assertEqual(expr, P(conditional_probability_expression(A,B)))
        self.assertEqual(latex(expr), "P{\\left (A ~|~ B \\right )}")
コード例 #5
0
    def test_round(self):
        context=Context({"a": 1.2345})
        result=Template("{% load question_tags %}{{a|round}}").render(context)
        self.assertEqual(result,"1")
        result=Template("{% load question_tags %}{{a|round:3}}").render(context)
        self.assertEqual(result,"1.235")

        x=Symbol('x')
        context=Context({"a": 1.2345*x})
        result=Template("{% load question_tags %}{{a|round:3}}").render(context)
        self.assertEqual(result,latex(1.235*x))

        context=Context({"a": math_object(1.2345*x)})
        result=Template("{% load question_tags %}{{a|round:3}}").render(context)
        self.assertEqual(result,latex(1.235*x))
コード例 #6
0
    def test_boolean(self):
        self.assertEqual(parse_expr("True and True"), True)
        self.assertEqual(parse_expr("True and not True"), False)
        self.assertEqual(parse_expr("False or not True"), False)
        self.assertEqual(parse_expr("not False or not True"), True)

        local_dict = {'a': sympify(1), 'b': sympify(2), 'c': sympify(3),
                       'd': sympify(4)}
        expr = parse_expr("a and b and c and d", local_dict=local_dict)
        self.assertEqual(expr, True)
        local_dict['b'] = sympify(0)
        expr = parse_expr("a and b and c and d", local_dict=local_dict)
        self.assertEqual(expr, False)

        self.assertEqual(latex(parse_expr("a and b")), r'a ~\text{and}~ b')
        self.assertEqual(latex(parse_expr("a or b")), r'a ~\text{or}~ b')
コード例 #7
0
    def test_relational(self):
        from sympy import Eq, Ne, Lt, Ge
        from mitesting.sympy_customized import Or, And
        
        x=Symbol('x')
        y=Symbol('y')
        
        expr = parse_expr("x=y")
        self.assertEqual(expr, Eq(x,y))

        expr = parse_expr("x==y")
        self.assertEqual(expr, False)

        expr = parse_expr("x==y", evaluate=False)
        self.assertEqual(latex(expr), "x == y")
        self.assertEqual(expr.doit(), False)
        self.assertEqual(expr.subs(y,x).doit(), True)

        expr = parse_expr("x != y")
        self.assertEqual(expr, Ne(x,y))
 
        expr = parse_expr("x !== y")
        self.assertEqual(expr, True)
       
        expr = parse_expr("x!==y", evaluate=False)
        self.assertEqual(latex(expr), "x != y")
        self.assertEqual(expr.doit(), True)
        self.assertEqual(expr.subs(y,x).doit(), False)

        expr = parse_expr("x < y")
        self.assertEqual(expr, Lt(x,y))

        expr = parse_expr("x >= y")
        self.assertEqual(expr, Ge(x,y))

        expr = parse_expr("x=y or x^2 != y")
        self.assertEqual(expr,Or(Eq(x,y),Ne(x**2,y)))
        
        expr = parse_expr("(x=1)=(y=2)")
        self.assertEqual(expr,Eq(Eq(x,1),Eq(y,2)))

        a=Symbol('a')
        b=Symbol('b')
        c=Symbol('c')
        z=Symbol('z')
        expr = parse_expr("x-1=y+c and (y/a=x(z) or a^2 != (b+2)(c-1)/2)")
        self.assertEqual(expr, And(Eq(x-1,y+c), Or(Eq(y/a,x*z), Ne(a**2,(b+2)*(c-1)/2))))
コード例 #8
0
    def test_diffsubs(self):
        x=Symbol('x')
        y=Symbol('y')
        z=Symbol('z')

        self.assertEqual(DiffSubs(x*y-1,x,z,1).doit(), y-z*y)
        from mitesting.sympy_customized import latex
        self.assertEqual(latex(DiffSubs(2*x,x,y,z)),
            r'\left. 2 x \vphantom{\Large I} \right|_{\substack{ x=y }}^{\substack{ x=z }}')

        from mitesting.sympy_customized import AddUnsort
        self.assertEqual(DiffSubs(2*x,x,1,2).as_difference(), AddUnsort(4,-2))
コード例 #9
0
    def test_derivative_prime_notation(self):
        from sympy import Function, Derivative
        from mitesting.sympy_customized import SymbolCallable, \
            DerivativePrimeNotation, DerivativePrimeSimple
        
        f=Function(str('f'))
        g=SymbolCallable(str('g'))
        x=Symbol('x')
        y=Symbol('y')
        
        fn=Function(str('fn'))
        
        local_dict={'f': f, 'g': g, 'fn': fn}
        
        expr=parse_expr("f'(x)+g'(y)", local_dict=local_dict)
        self.assertEqual(expr, DerivativePrimeSimple(f(x),x)
                         +DerivativePrimeSimple(g(y),y))
        self.assertEqual(latex(expr), "f'(x) + g'(y)")

        expr=parse_expr("yf'(x)", local_dict=local_dict, split_symbols=True)
        self.assertEqual(expr, y*DerivativePrimeSimple(f(x),x))

        expr=parse_expr("yf'(x)", local_dict=local_dict)
        self.assertEqual(expr, DerivativePrimeSimple(Function('yf')(x),x))

        expr=parse_expr("2f'(x)", local_dict=local_dict)
        self.assertEqual(expr, 2*DerivativePrimeSimple(f(x),x))

        expr=parse_expr("fn'(x)", local_dict=local_dict)
        self.assertEqual(expr, DerivativePrimeSimple(fn(x),x))

        expr=parse_expr("fn'(x)", local_dict=local_dict, split_symbols=True)
        self.assertEqual(expr, DerivativePrimeSimple(fn(x),x))

        expr=parse_expr("f0'(x)", local_dict=local_dict)
        self.assertEqual(expr, DerivativePrimeSimple(Function('f0')(x),x))

        self.assertRaises(SyntaxError, parse_expr,"f0'(x)", 
                          local_dict=local_dict, split_symbols=True)

        expr=parse_expr("2f'(x*y)", local_dict=local_dict)
        self.assertEqual(expr, 2*DerivativePrimeNotation(f,x*y))
        from sympy import Subs
        self.assertEqual(expr.doit(), 2*Subs(Derivative(f(x),x),x,x*y))
        
        expr2=parse_expr("2f'(x*y, dummy_variable==='t')", local_dict=local_dict)
        self.assertEqual(expr,expr2)
        self.assertEqual(expr.doit(),expr2.doit())
        
        expr3=parse_expr("2f'(x*y, dummy_variable==='s')", local_dict=local_dict)
        self.assertEqual(expr3,expr2)
        self.assertEqual(expr3.doit(),expr2.doit())
コード例 #10
0
    def test_callable_symbol_commutative(self):
        # symbol callable is commutative even with argument such an equality
        from mitesting.sympy_customized import SymbolCallable
        
        P=SymbolCallable('P')

        local_dict = {'P': P}
        expr = parse_expr("P(R=1)", local_dict=local_dict)
        self.assertTrue(expr.is_commutative)
        
        expr = parse_expr("P(A)/P(R=1)", local_dict=local_dict)
        self.assertEqual(latex(expr), 
            '\\frac{P{\\left (A \\right )}}{P{\\left (R = 1 \\right )}}')
コード例 #11
0
    def test_contains(self):
        from mitesting.sympy_customized import Interval, FiniteSet, Or
        x=Symbol('x')
        expr=parse_expr("x in (1,2)")
        self.assertEqual(expr, Interval(1,2, left_open=True, right_open=True).contains(x))
        self.assertEqual(latex(expr), r'x > 1 ~\text{and}~ x < 2')

        expr=parse_expr("x in (1,2)", evaluate=False)
        self.assertEqual(expr, Interval(1,2, left_open=True, right_open=True).contains(x, evaluate=False))
        self.assertEqual(latex(expr), r'x \in \left(1, 2\right)')

        expr=parse_expr("1 in [1,2]")
        self.assertEqual(expr, True)

        expr=parse_expr("1 in [1,2]", evaluate=False)
        self.assertEqual(expr, Interval(1,2).contains(1, evaluate=False))
        self.assertEqual(latex(expr), r'1 \in \left[1, 2\right]')

        expr=parse_expr("x in {1,2,3}")
        self.assertEqual(expr, FiniteSet(1,2,3).contains(x))

        expr=parse_expr("x in {1,2,x}")
        self.assertEqual(expr, True)

        expr=parse_expr("x in {1,2,x}", evaluate=False)
        self.assertEqual(expr, FiniteSet(1,2,x).contains(x, evaluate=False))
        self.assertEqual(latex(expr), r'x \in \left\{1, 2, x\right\}')

        a=Symbol('a')
        b=Symbol('b')
        expr=parse_expr("x in {a,b} or x in (1,2]")
        self.assertEqual(expr, Or(FiniteSet(a,b).contains(x),Interval(1,2, left_open=True).contains(x)))

        from mitesting.user_commands import iif
        expr=parse_expr("if(x in {a,b}, 1, 0)", local_dict={'x': a, 'if': iif})
        self.assertEqual(expr,1)
コード例 #12
0
ファイル: test_utils.py プロジェクト: dqnykamp/mathinsight
    def test_no_evaluate(self):
        from mitesting.models import Expression
        from mitesting.sympy_customized import latex
        z=Symbol('z')
        fun = return_parsed_function("3*x*-1*1*x-1+0-3+x","x", name="f",
                                     evaluate_level=Expression.EVALUATE_NONE)
        self.assertEqual(repr(fun(z)), '3*z*(-1)*1*z - 1 + 0 - 3 + z')
        self.assertEqual(latex(fun(z)), '3 z \\left(-1\\right) 1 z - 1 + 0 - 3 + z')

        from sympy import log, S
        fun = return_parsed_function("log(x)", "x", name="f", local_dict={'log': log},
                                     evaluate_level=Expression.EVALUATE_NONE)
        fun_34 = fun(S("3/4"))
        self.assertEqual(fun_34, log(S("3/4"), evaluate=False))
        self.assertNotEqual(fun_34, log(S("3/4")))

        fun = return_parsed_function("log(x)", "x", name="f", local_dict={'log': log})
        fun_34 = fun(S("3/4"))
        self.assertNotEqual(fun_34, log(S("3/4"), evaluate=False))
        self.assertEqual(fun_34, log(S("3/4")))
コード例 #13
0
    def __new__(cls, a,b, real=False):

        from mitesting.sympy_customized import latex

        symbol_name=''
        if b is None:
            if a is None:
                symbol_name='_'
            else:
                symbol_name='%s_' % a
        else:
            if not b.is_Symbol:
                b=latex(b)
            if a is None:
                symbol_name='_%s' % b
            else:
                symbol_name='%s_%s' % (a,b)

        if real:
            return Symbol(symbol_name, real=True)
        else:
            return Symbol(symbol_name)
コード例 #14
0
    def test_parse_subscripts(self):
        x=Symbol('x')
        y=Symbol('y')
        n=Symbol('n')
        m=Symbol('m')
        
        expr1=parse_expr("x_n")
        expr2=parse_expr("x_n", parse_subscripts=True)
        expr3=parse_expr("x_n", parse_subscripts=True, 
                         assume_real_variables=True)
        expr4=parse_expr("x_n", parse_subscripts=True, evaluate=False)
        
        self.assertEqual(expr1,Symbol("x_n"))
        self.assertEqual(expr2,Symbol("x_n"))
        self.assertEqual(expr1,expr2)
        self.assertEqual(expr3,Symbol("x_n", real=True))
        self.assertEqual(expr4,Symbol("x_n"))

        expr1=parse_expr("x_(n+1)")
        expr2=parse_expr("x_(n+1)", parse_subscripts=True)
        self.assertEqual(expr1,Symbol("x_")*(n+1))
        self.assertEqual(expr2,Symbol("x_n + 1"))
        self.assertEqual(latex(expr2), "x_{n + 1}")

        expr=parse_expr("xx_nn", parse_subscripts=True, 
                        local_dict={'xx': y, 'nn': m })
        self.assertEqual(expr, Symbol('y_m'))

        expr=parse_expr("xx_nn", parse_subscripts=True, split_symbols=True,
                        local_dict={'xx': y, 'nn': m })
        self.assertEqual(expr, Symbol('y_m'))

        expr=parse_expr("xx_nn", parse_subscripts=True,
                        local_dict={'xx': y, 'nn': m, 'xx_nn': Symbol('a')})
        self.assertEqual(expr, Symbol('a'))

        expr=parse_expr("xx_nn", parse_subscripts=True, split_symbols=True,
                        local_dict={'xx': y, 'nn': m, 'xx_nn': Symbol('a')})
        self.assertEqual(expr, Symbol('a'))

        expr=parse_expr("y+xx_nn/2", parse_subscripts=True)
        self.assertEqual(expr, y+Symbol('xx_nn')/2)

        expr=parse_expr("y+xx_nn/2", parse_subscripts=True, split_symbols=True)
        self.assertEqual(expr, y+x*n*Symbol('x_n')/2)

        expr=parse_expr("y+xx_nn/2", parse_subscripts=True, split_symbols=True,
                        local_dict={'nn': Symbol('nn')})
        self.assertEqual(expr, y+x*Symbol('x_nn')/2)

        expr=parse_expr("y+xx_nn/2", parse_subscripts=True, split_symbols=True,
                        local_dict={'xx': Symbol('xx')})
        self.assertEqual(expr, y+n*Symbol('xx_n')/2)

        expr=parse_expr("y+xx_nn/2", parse_subscripts=True, split_symbols=True,
                        local_dict={'xx': Symbol('xx'), 'nn': Symbol('nn')})
        self.assertEqual(expr, y+Symbol('xx_nn')/2)

        expr=parse_expr("y+xx_(nm)/2", parse_subscripts=True, 
                        split_symbols=True)
        self.assertEqual(expr, y+x*Symbol('x_m n')/2)

        expr=parse_expr("y+xx_(nm)/2", parse_subscripts=True, 
                        split_symbols=True, local_dict={'nm': Symbol('nm')})
        self.assertEqual(expr, y+x*Symbol('x_nm')/2)


        expr=parse_expr("y+6xx_nn/2", parse_subscripts=True)
        self.assertEqual(expr, y+3*Symbol('xx_nn'))

        expr=parse_expr("y+xx_28/2", parse_subscripts=True, split_symbols=True)
        self.assertEqual(expr, y+x*Symbol('x_28')/2)

        expr=parse_expr("y+xx_28n/2", parse_subscripts=True, split_symbols=True)
        self.assertEqual(expr, y+x*n*Symbol('x_28')/2)
 
        expr=parse_expr("y+xx_28n/2", parse_subscripts=True)
        self.assertEqual(expr, y+Symbol('xx_28 n')/2)


        expr=parse_expr("a1_b", parse_subscripts=True, split_symbols=True)
        self.assertEqual(expr,  Symbol('a1_b'))

        expr=parse_expr("1a_b", parse_subscripts=True, split_symbols=True)
        self.assertEqual(expr,  Symbol('a_b'))

        S1= Symbol('SS_1')
        expr=parse_expr("xS_1y", parse_subscripts=True, split_symbols=True,
                        local_dict={'S_1': S1})
        self.assertEqual(expr, x*S1*y)


        expr1=parse_expr("lambda_delta", parse_subscripts=True, 
                         split_symbols=True)
        expr2=parse_expr("lambda_delta", parse_subscripts=False, 
                         split_symbols=True)
        expr3=parse_expr("lambda_delta", parse_subscripts=True, 
                         split_symbols=False)
        expr4=parse_expr("lambda_delta", parse_subscripts=False, 
                         split_symbols=False)
        expr5=parse_expr("λ_δ", parse_subscripts=True, 
                         split_symbols=True)
        expr6=parse_expr("λ_δ", parse_subscripts=False, 
                         split_symbols=True)
        expr7=parse_expr("λ_δ", parse_subscripts=True, 
                         split_symbols=False)
        expr8=parse_expr("λ_δ", parse_subscripts=False, 
                         split_symbols=False)
        
        self.assertEqual(expr1,expr2)
        self.assertEqual(expr1,expr3)
        self.assertEqual(expr1,expr4)
        self.assertEqual(expr1,expr5)
        self.assertEqual(expr1,expr6)
        self.assertEqual(expr1,expr7)
        self.assertEqual(expr1,expr8)
コード例 #15
0
    def test_derivative_simplified_notation(self):
        from sympy import Function, Derivative
        from mitesting.sympy_customized import SymbolCallable, \
            DerivativeSimplifiedNotation
        
        f=Function(str('f'))
        g=SymbolCallable(str('g'))
        x=Symbol(str('x'))
        y=Symbol('y')
        fn=Function(str('fn'))
        xx=Symbol('xx')
        local_dict={'f': f, 'g': g, 'fn': fn, 'xx': xx}
        
        expr=parse_expr("df/dx+dg/dy", local_dict=local_dict)
        self.assertEqual(expr, DerivativeSimplifiedNotation(f(x),x)
                         +DerivativeSimplifiedNotation(g(y),y))
        self.assertEqual(latex(expr), "\\frac{d f}{d x} + \\frac{d g}{d y}")

        expr=parse_expr("ydf/dxy", local_dict=local_dict, split_symbols=True)
        self.assertEqual(expr, y**2*DerivativeSimplifiedNotation(f(x),x))
        
        expr=parse_expr("ydf/dxy", local_dict=local_dict)
        self.assertEqual(expr, Symbol('ydf')/Symbol('dxy'))

        expr=parse_expr("3dfn/dxx", local_dict=local_dict)
        self.assertEqual(expr, 3*DerivativeSimplifiedNotation(fn(xx),xx))

        expr=parse_expr("df/dx+dg/dy")
        self.assertEqual(expr, DerivativeSimplifiedNotation(f(x),x)
                         +DerivativeSimplifiedNotation(g(y),y))
        self.assertEqual(latex(expr), "\\frac{d f}{d x} + \\frac{d g}{d y}")

        expr=parse_expr("dvar/dy", local_dict={'var': x})
        self.assertEqual(expr, DerivativeSimplifiedNotation(x(y),y))
        self.assertEqual(latex(expr), "\\frac{d x}{d y}")

        expr=parse_expr("dx/dx")
        self.assertEqual(expr, DerivativeSimplifiedNotation(x(x),x))
        self.assertEqual(latex(expr), "\\frac{d x}{d x}")
        self.assertEqual(expr.doit(),1)

        expr=parse_expr("dvar/dx", local_dict={'var': x})
        self.assertEqual(expr, DerivativeSimplifiedNotation(x(x),x))
        self.assertEqual(latex(expr), "\\frac{d x}{d x}")
        self.assertEqual(expr.doit(),1)

        expr=parse_expr("dvar/dx", local_dict={'var': x*x})
        self.assertEqual(expr, Derivative(x**2,x))
        self.assertEqual(latex(expr), "\\frac{d}{d x} x^{2}")
        self.assertEqual(expr.doit(), 2*x)

        from sympy import sin, cos
        expr=parse_expr("dvar/dx", local_dict={'var': sin })
        self.assertEqual(expr, DerivativeSimplifiedNotation(sin(x),x))
        self.assertEqual(latex(expr), "\\frac{d}{d x} \\sin{\\left (x \\right )}")
        self.assertEqual(expr.doit(), cos(x))

        expr=parse_expr("dvar/dx", local_dict={'var': sin(x) })
        self.assertEqual(expr, Derivative(sin(x),x))

        expr=parse_expr("dvar/dx", local_dict={'var': x+y+1 })
        self.assertEqual(expr, Derivative(x+y+1,x))
コード例 #16
0
    def test_no_evaluate(self):
        expr_no_evaluate = parse_expr("x - lambda + x + 2*lambda",
                                      evaluate=False)
        expr = parse_expr("x - lambda + x + 2*lambda")
        expr_with_evaluate = parse_expr("x + x - lambda + 2*lambda",
                                        evaluate=True)
        self.assertNotEqual(expr_no_evaluate, expr)
        self.assertEqual(expr, expr_with_evaluate)
        self.assertEqual(repr(expr_no_evaluate),'x - lambda + x + 2*lambda')

        expr1=parse_expr("2+y*x", evaluate=False)
        expr2=parse_expr("2+y*x")
        expr3=parse_expr("x*y+2", evaluate=False)
        expr4=parse_expr("foo", local_dict={'foo': expr1})
        self.assertNotEqual(expr1,expr2)
        self.assertEqual(expr2,expr3)
        self.assertNotEqual(expr1,expr3)
        self.assertEqual(expr2,expr4)
        self.assertNotEqual(expr1,expr4)
        self.assertEqual(repr(expr1), '2 + y*x')
        self.assertEqual(repr(expr4), 'x*y + 2')

        expr=parse_expr("1*x*1", evaluate=False)
        self.assertEqual(repr(expr), '1*x*1')
        self.assertEqual(latex(expr), '1 x 1')
        
        expr=parse_expr("0+x+0", evaluate=False)
        self.assertEqual(repr(expr), '0 + x + 0')
        self.assertEqual(latex(expr), '0 + x + 0')
        

        # test with leading minus sign in Mul
        expr=parse_expr("4*(-4*x+1)", evaluate=False)
        self.assertEqual(repr(expr), '4*(-4*x + 1)')
        self.assertEqual(latex(expr), '4 \\left(-4 x + 1\\right)')

        expr=parse_expr("-1*(-4*x+1)", evaluate=False)
        self.assertEqual(repr(expr), '-1*(-4*x + 1)')
        self.assertEqual(latex(expr), '-1 \\left(-4 x + 1\\right)')

        
        # parentheses around negative numbers or expressions with negative sign
        expr=parse_expr("4*2*-1*x*-x",evaluate=False)
        self.assertEqual(repr(expr), '4*2*(-1)*x*(-x)')
        self.assertEqual(latex(expr), '4 \\cdot 2 \\left(-1\\right) x \\left(- x\\right)')

        # subtracting and adding a negative
        from sympy import Integral
        expr=parse_expr("5*Integral(t,(t,0,1))+(-1)*Integral(t^2,(t,1,2))", 
                        evaluate=False,
                        local_dict={'Integral': Integral})
        self.assertEqual(latex(expr), 
                '5 \\int_{0}^{1} t\\, dt - 1 \\int_{1}^{2} t^{2}\\, dt')

        expr=parse_expr("5*Integral(t,(t,0,1))-Integral(t^2,(t,1,2))",
                        evaluate=False,
                        local_dict={'Integral': Integral})
        self.assertEqual(latex(expr), 
                    '5 \\int_{0}^{1} t\\, dt - \\int_{1}^{2} t^{2}\\, dt')

        expr=parse_expr("5*x*y*3-3*y*x*5-7-x", evaluate=False)
        self.assertEqual(latex(expr), '5 x y 3 - 3 y x 5 - 7 - x')

        expr=parse_expr("-5*x*x*3-3*x-x*3-3-x", evaluate=False)
        self.assertEqual(latex(expr), '-5 x x 3 - 3 x - x 3 - 3 - x')

        expr=parse_expr("5*x*x*3+-3*x+-x*3+-3+-x", evaluate=False)
        self.assertEqual(latex(expr), '5 x x 3 - 3 x - x 3 - 3 - x')

        expr=parse_expr("5*x*x*3--3*x--x*3--3--x", evaluate=False)
        self.assertEqual(latex(expr), '5 x x 3 + 3 x + x 3 + 3 + x')

        expr=parse_expr("1*x*x/(x*x)-1*x*x/(x*x)+-1*x*x/(-x*x)", evaluate=False)
        self.assertEqual(latex(expr), 
            '\\frac{1 x x}{x x} - \\frac{1 x x}{x x} - \\frac{1 x x}{- x x}')

        expr=parse_expr("-t/x", evaluate=False)
        self.assertEqual(latex(expr), '\\frac{- t}{x}')

        expr=parse_expr("x-(y-z)", evaluate=False)
        self.assertEqual(latex(expr), 'x - \\left(y - z\\right)')

        # should be equal to evaluate if looks the same
        expr1=parse_expr("-5z^2-5", evaluate=False)
        expr2=parse_expr("-5z^2-5")
        self.assertEqual(expr1,expr2)

        expr_base=parse_expr("-14*x^3+2")
        expr1=parse_expr("expr_base.as_ordered_terms()[1]+expr_base.as_ordered_terms()[0]", local_dict={'expr_base': expr_base}, evaluate=False)
        expr2=parse_expr("2-14*x^3", evaluate=False)
        self.assertEqual(expr1,expr2)

        expr1=parse_expr("1-5x", evaluate=False)
        expr2=parse_expr("1-1*5*x", evaluate=False)
        self.assertNotEqual(expr1,expr2)

        from sympy import Gt, Lt, Ge, Le
        from mitesting.sympy_customized import And, Or
        expr1=parse_expr("2<3", evaluate=False)
        self.assertEqual(expr1, Lt(2,3,evaluate=False))

        expr1=parse_expr("2>3 and 5<=-1 or 3>=3", evaluate=False)
        self.assertEqual(expr1, Or(And(Gt(2,3,evaluate=False), Le(5,-1,evaluate=False)), Ge(3,3,evaluate=False)))
        

        expr1=parse_expr("5/1", evaluate=False)
        self.assertEqual(latex(expr1), '\\frac{5}{1}')

        expr1=parse_expr("-(x-y)", evaluate=False)
        self.assertEqual(latex(expr1), r'-\left(x - y\right)')