Ejemplo n.º 1
0
def test_simplify_ratio():
    # roots of x**3-3*x+5
    roots = ['(1/2 - sqrt(3)*I/2)*(sqrt(21)/2 + 5/2)**(1/3) + 1/((1/2 - '
             'sqrt(3)*I/2)*(sqrt(21)/2 + 5/2)**(1/3))',
             '1/((1/2 + sqrt(3)*I/2)*(sqrt(21)/2 + 5/2)**(1/3)) + '
             '(1/2 + sqrt(3)*I/2)*(sqrt(21)/2 + 5/2)**(1/3)',
             '-(sqrt(21)/2 + 5/2)**(1/3) - 1/(sqrt(21)/2 + 5/2)**(1/3)']

    for root in roots:
        root = sympify(root)
        assert count_ops(simplify(root, ratio=1)) <= count_ops(root)
        # If ratio=oo, simplify() is always applied:
        assert simplify(root, ratio=oo) is not root
Ejemplo n.º 2
0
def test_simplify_ratio():
    # roots of x**3-3*x+5
    roots = [(Rational(1, 2) - sqrt(3) * I / 2) *
             cbrt(sqrt(21) / 2 + Rational(5, 2)) + 1 /
             ((Rational(1, 2) - sqrt(3) * I / 2) *
              cbrt(sqrt(21) / 2 + Rational(5, 2))),
             1 / ((Rational(1, 2) + sqrt(3) * I / 2) *
                  cbrt(sqrt(21) / 2 + Rational(5, 2))) +
             (Rational(1, 2) + sqrt(3) * I / 2) *
             cbrt(sqrt(21) / 2 + Rational(5, 2)),
             -cbrt(sqrt(21) / 2 + Rational(5, 2)) -
             1 / cbrt(sqrt(21) / 2 + Rational(5, 2))]

    for root in roots:
        assert count_ops(simplify(root, ratio=1)) <= count_ops(root)
        # If ratio=oo, simplify() is always applied:
        assert simplify(root, ratio=oo) is not root
Ejemplo n.º 3
0
def test_simplify_ratio():
    # roots of x**3-3*x+5
    roots = [(S.Half - sqrt(3)*I/2) *
             (sqrt(21)/2 + Rational(5, 2))**Rational(1, 3) +
             1/((S.Half - sqrt(3)*I/2)*(sqrt(21)/2 +
                                        Rational(5, 2))**Rational(1, 3)),
             1/((S.Half + sqrt(3)*I/2) *
             (sqrt(21)/2 + Rational(5, 2))**Rational(1, 3)) +
             (S.Half + sqrt(3)*I/2)*(sqrt(21)/2 +
                                     Rational(5, 2))**Rational(1, 3),
             -(sqrt(21)/2 + Rational(5, 2))**Rational(1, 3) -
             1/(sqrt(21)/2 + Rational(5, 2))**Rational(1, 3)]

    for root in roots:
        assert count_ops(simplify(root, ratio=1)) <= count_ops(root)
        # If ratio=oo, simplify() is always applied:
        assert simplify(root, ratio=oo) is not root
Ejemplo n.º 4
0
 def measure2(expr):
     return -count_ops(expr)  # Return the most complicated result
Ejemplo n.º 5
0
 def count(val):
     return count_ops(val, visual=True)
Ejemplo n.º 6
0
 def count(val):
     return count_ops(val, visual=False)
Ejemplo n.º 7
0
 def count(val):
     return count_ops(val, visual=True)
Ejemplo n.º 8
0
 def count(val):
     return count_ops(val, visual=False)
Ejemplo n.º 9
0
 def measure2(expr):
     return -count_ops(expr)  # Return the most complicated result