


is_Numerical : r0, r1 = return def roots_cubic ( f, trig = False ): """Returns a list of roots of a cubic polynomial. is_negative : r0, r1 = r1, r0 elif not dom. is_Numerical : d = _simplify ( d ) B = _simplify ( B ) D = factor_terms ( _sqrt ( d ) / A ) r0 = B - D r1 = B + D if a. is_Numerical : r = _simplify ( r ) R = _sqrt ( r ) r0 = - R r1 = R else : d = b ** 2 - 4 * a * c A = 2 * a B = - b / A if not dom. is_negative : r0, r1 = r1, r0 elif b is S. is_Numerical : r1 = _simplify ( r1 ) elif r1. is_Composite : return factor ( expr ) else : return simplify ( expr ) if c is S. append ( di ) if co : d = Mul ( * other ) co = Mul ( * co ) return co * sqrt ( d ) return sqrt ( d ) def _simplify ( expr ): if dom. get_domain () def _sqrt ( d ): # remove squares from square root since both will be represented # in the results a similar thing is happening in roots() but # must be duplicated here because not all quadratics are binomials co = other = for di in Mul. The ordering will be the same for any numerical coefficients as long as the assumptions tested are correct, otherwise the ordering will not be sorted (but will be canonical). If the domain is ZZ then the roots will be sorted with negatives coming before positives. is_Composite : r = factor ( r ) else : r = simplify ( r ) return def roots_quadratic ( f ): """Returns a list of roots of a quadratic polynomial. """ from _future_ import print_function, division import math from import Dummy, Symbol, symbols from re import S, I, pi from import ordered from import expand_2arg, Mul from import Pow from import Eq from import sympify from import Rational, igcd, comp from import factor_terms from import fuzzy_not from sympy.ntheory import divisors, isprime, nextprime from sympy.functions import exp, sqrt, im, cos, acos, Piecewise from import root from import Poly, cancel, factor, gcd_list, discriminant from import cyclotomic_poly from import ( PolynomialError, GeneratorsNeeded, DomainError ) from import PolyQuintic from import together from sympy.simplify import simplify, powsimp from sympy.utilities import public from import reduce, range def roots_linear ( f ): """Returns a list of roots of a linear polynomial.""" r = - f. """Algorithms for computing symbolic roots of polynomials.
