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
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
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
def measure2(expr): return -count_ops(expr) # Return the most complicated result
def count(val): return count_ops(val, visual=True)
def count(val): return count_ops(val, visual=False)