本文整理汇总了Python中sympy.polys.Poly.degree方法的典型用法代码示例。如果您正苦于以下问题:Python Poly.degree方法的具体用法?Python Poly.degree怎么用?Python Poly.degree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.polys.Poly
的用法示例。
在下文中一共展示了Poly.degree方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _solve_as_poly
# 需要导入模块: from sympy.polys import Poly [as 别名]
# 或者: from sympy.polys.Poly import degree [as 别名]
def _solve_as_poly(f, symbol, solveset_solver, invert_func):
"""
Solve the equation using polynomial techniques if it already is a
polynomial equation or, with a change of variables, can be made so.
"""
result = None
if f.is_polynomial(symbol):
solns = roots(f, symbol, cubics=True, quartics=True,
quintics=True, domain='EX')
num_roots = sum(solns.values())
if degree(f, symbol) <= num_roots:
result = FiniteSet(*solns.keys())
else:
poly = Poly(f, symbol)
solns = poly.all_roots()
if poly.degree() <= len(solns):
result = FiniteSet(*solns)
else:
result = ConditionSet(symbol, Eq(f, 0), S.Complexes)
else:
poly = Poly(f)
if poly is None:
result = ConditionSet(symbol, Eq(f, 0), S.Complexes)
gens = [g for g in poly.gens if g.has(symbol)]
if len(gens) == 1:
poly = Poly(poly, gens[0])
gen = poly.gen
deg = poly.degree()
poly = Poly(poly.as_expr(), poly.gen, composite=True)
poly_solns = FiniteSet(*roots(poly, cubics=True, quartics=True,
quintics=True).keys())
if len(poly_solns) < deg:
result = ConditionSet(symbol, Eq(f, 0), S.Complexes)
if gen != symbol:
y = Dummy('y')
lhs, rhs_s = invert_func(gen, y, symbol)
if lhs is symbol:
result = Union(*[rhs_s.subs(y, s) for s in poly_solns])
else:
result = ConditionSet(symbol, Eq(f, 0), S.Complexes)
else:
result = ConditionSet(symbol, Eq(f, 0), S.Complexes)
if result is not None:
if isinstance(result, FiniteSet):
# this is to simplify solutions like -sqrt(-I) to sqrt(2)/2
# - sqrt(2)*I/2. We are not expanding for solution with free
# variables because that makes the solution more complicated. For
# example expand_complex(a) returns re(a) + I*im(a)
if all([s.free_symbols == set() and not isinstance(s, RootOf)
for s in result]):
s = Dummy('s')
result = imageset(Lambda(s, expand_complex(s)), result)
return result
else:
return ConditionSet(symbol, Eq(f, 0), S.Complexes)
示例2: _sqrt_symbolic_denest
# 需要导入模块: from sympy.polys import Poly [as 别名]
# 或者: from sympy.polys.Poly import degree [as 别名]
def _sqrt_symbolic_denest(a, b, r):
"""Given an expression, sqrt(a + b*sqrt(b)), return the denested
expression or None.
Algorithm:
If r = ra + rb*sqrt(rr), try replacing sqrt(rr) in ``a`` with
(y**2 - ra)/rb, and if the result is a quadratic, ca*y**2 + cb*y + cc, and
(cb + b)**2 - 4*ca*cc is 0, then sqrt(a + b*sqrt(r)) can be rewritten as
sqrt(ca*(sqrt(r) + (cb + b)/(2*ca))**2).
Examples
========
>>> from sympy.simplify.sqrtdenest import _sqrt_symbolic_denest, sqrtdenest
>>> from sympy import sqrt, Symbol
>>> from sympy.abc import x
>>> a, b, r = 16 - 2*sqrt(29), 2, -10*sqrt(29) + 55
>>> _sqrt_symbolic_denest(a, b, r)
sqrt(-2*sqrt(29) + 11) + sqrt(5)
If the expression is numeric, it will be simplified:
>>> w = sqrt(sqrt(sqrt(3) + 1) + 1) + 1 + sqrt(2)
>>> sqrtdenest(sqrt((w**2).expand()))
1 + sqrt(2) + sqrt(1 + sqrt(1 + sqrt(3)))
Otherwise, it will only be simplified if assumptions allow:
>>> w = w.subs(sqrt(3), sqrt(x + 3))
>>> sqrtdenest(sqrt((w**2).expand()))
sqrt((sqrt(sqrt(sqrt(x + 3) + 1) + 1) + 1 + sqrt(2))**2)
Notice that the argument of the sqrt is a square. If x is made positive
then the sqrt of the square is resolved:
>>> _.subs(x, Symbol('x', positive=True))
sqrt(sqrt(sqrt(x + 3) + 1) + 1) + 1 + sqrt(2)
"""
a, b, r = map(sympify, (a, b, r))
rval = _sqrt_match(r)
if not rval:
return None
ra, rb, rr = rval
if rb:
y = Dummy('y', positive=True)
try:
newa = Poly(a.subs(sqrt(rr), (y**2 - ra)/rb), y)
except PolynomialError:
return None
if newa.degree() == 2:
ca, cb, cc = newa.all_coeffs()
cb += b
if _mexpand(cb**2 - 4*ca*cc).equals(0):
z = sqrt(ca*(sqrt(r) + cb/(2*ca))**2)
if z.is_number:
z = _mexpand(Mul._from_args(z.as_content_primitive()))
return z
示例3: _is_function_class_equation
# 需要导入模块: from sympy.polys import Poly [as 别名]
# 或者: from sympy.polys.Poly import degree [as 别名]
def _is_function_class_equation(func_class, f, symbol):
""" Tests whether the equation is an equation of the given function class.
The given equation belongs to the given function class if it is
comprised of functions of the function class which are multiplied by
or added to expressions independent of the symbol. In addition, the
arguments of all such functions must be linear in the symbol as well.
Examples
========
>>> from sympy.solvers.solveset import _is_function_class_equation
>>> from sympy import tan, sin, tanh, sinh, exp
>>> from sympy.abc import x
>>> from sympy.functions.elementary.trigonometric import (TrigonometricFunction,
... HyperbolicFunction)
>>> _is_function_class_equation(TrigonometricFunction, exp(x) + tan(x), x)
False
>>> _is_function_class_equation(TrigonometricFunction, tan(x) + sin(x), x)
True
>>> _is_function_class_equation(TrigonometricFunction, tan(x**2), x)
False
>>> _is_function_class_equation(TrigonometricFunction, tan(x + 2), x)
True
>>> _is_function_class_equation(HyperbolicFunction, tanh(x) + sinh(x), x)
True
"""
if f.is_Mul or f.is_Add:
return all(_is_function_class_equation(func_class, arg, symbol)
for arg in f.args)
if f.is_Pow:
if not f.exp.has(symbol):
return _is_function_class_equation(func_class, f.base, symbol)
else:
return False
if not f.has(symbol):
return True
if isinstance(f, func_class):
try:
g = Poly(f.args[0], symbol)
return g.degree() <= 1
except PolynomialError:
return False
else:
return False
示例4: _solve_inequality
# 需要导入模块: from sympy.polys import Poly [as 别名]
# 或者: from sympy.polys.Poly import degree [as 别名]
def _solve_inequality(ie, s):
""" A hacky replacement for solve, since the latter only works for
univariate inequalities. """
from sympy import Poly
if not ie.rel_op in ('>', '>=', '<', '<='):
raise NotImplementedError
expr = ie.lhs - ie.rhs
p = Poly(expr, s)
if p.degree() != 1:
raise NotImplementedError('%s' % ie)
a, b = p.all_coeffs()
if a.is_positive:
return ie.func(s, -b/a)
elif a.is_negative:
return ie.func(-b/a, s)
else:
raise NotImplementedError
示例5: root_factors
# 需要导入模块: from sympy.polys import Poly [as 别名]
# 或者: from sympy.polys.Poly import degree [as 别名]
def root_factors(f, *gens, **args):
"""Returns all factors of a univariate polynomial.
Examples
========
>>> from sympy.abc import x, y
>>> from sympy.polys.polyroots import root_factors
>>> root_factors(x**2-y, x)
[x - y**(1/2), x + y**(1/2)]
"""
F = Poly(f, *gens, **args)
if not F.is_Poly:
return [f]
if F.is_multivariate:
raise ValueError('multivariate polynomials not supported')
x = F.gens[0]
if 'multiple' in args:
del args['multiple']
zeros = roots(F, **args)
if not zeros:
factors = [F]
else:
factors, N = [], 0
for r, n in zeros.iteritems():
factors, N = factors + [Poly(x-r, x)]*n, N + n
if N < F.degree():
g = reduce(lambda p,q: p*q, factors)
factors.append(f.exquo(g))
if not isinstance(f, Poly):
return [ f.as_basic() for f in factors ]
else:
return factors
示例6: _solve_inequality
# 需要导入模块: from sympy.polys import Poly [as 别名]
# 或者: from sympy.polys.Poly import degree [as 别名]
def _solve_inequality(ie, s):
""" A hacky replacement for solve, since the latter only works for
univariate inequalities. """
if not ie.rel_op in (">", ">=", "<", "<="):
raise NotImplementedError
expr = ie.lhs - ie.rhs
try:
p = Poly(expr, s)
except PolynomialError:
raise NotImplementedError
if p.degree() != 1:
raise NotImplementedError("%s" % ie)
a, b = p.all_coeffs()
if a.is_positive:
return ie.func(s, -b / a)
elif a.is_negative:
return ie.func(-b / a, s)
else:
raise NotImplementedError
示例7: _solve_inequality
# 需要导入模块: from sympy.polys import Poly [as 别名]
# 或者: from sympy.polys.Poly import degree [as 别名]
def _solve_inequality(ie, s):
""" A hacky replacement for solve, since the latter only works for
univariate inequalities. """
expr = ie.lhs - ie.rhs
try:
p = Poly(expr, s)
if p.degree() != 1:
raise NotImplementedError
except (PolynomialError, NotImplementedError):
try:
return reduce_rational_inequalities([[ie]], s)
except PolynomialError:
return solve_univariate_inequality(ie, s)
a, b = p.all_coeffs()
if a.is_positive or ie.rel_op in ('!=', '=='):
return ie.func(s, -b/a)
elif a.is_negative:
return ie.reversed.func(s, -b/a)
else:
raise NotImplementedError
示例8: _solve_inequality
# 需要导入模块: from sympy.polys import Poly [as 别名]
# 或者: from sympy.polys.Poly import degree [as 别名]
def _solve_inequality(ie, s, assume=True):
""" A hacky replacement for solve, since the latter only works for
univariate inequalities. """
if not ie.rel_op in ('>', '>=', '<', '<='):
raise NotImplementedError
expr = ie.lhs - ie.rhs
try:
p = Poly(expr, s)
if p.degree() != 1:
raise NotImplementedError
except (PolynomialError, NotImplementedError):
try:
n, d = expr.as_numer_denom()
return reduce_rational_inequalities([[ie]], s, assume=assume)
except PolynomialError:
return solve_univariate_inequality(ie, s, assume=assume)
a, b = p.all_coeffs()
if a.is_positive:
return ie.func(s, -b/a)
elif a.is_negative:
return ie.func(-b/a, s)
else:
raise NotImplementedError
示例9: ratint_ratpart
# 需要导入模块: from sympy.polys import Poly [as 别名]
# 或者: from sympy.polys.Poly import degree [as 别名]
def ratint_ratpart(f, g, x):
"""Horowitz-Ostrogradsky algorithm.
Given a field K and polynomials f and g in K[x], such that f and g
are coprime and deg(f) < deg(g), returns fractions A and B in K(x),
such that f/g = A' + B and B has square-free denominator.
"""
f = Poly(f, x)
g = Poly(g, x)
u, v, _ = g.cofactors(g.diff())
n = u.degree()
m = v.degree()
d = g.degree()
A_coeffs = [ Dummy('a' + str(n-i)) for i in xrange(0, n) ]
B_coeffs = [ Dummy('b' + str(m-i)) for i in xrange(0, m) ]
C_coeffs = A_coeffs + B_coeffs
A = Poly(A_coeffs, x, domain=ZZ[C_coeffs])
B = Poly(B_coeffs, x, domain=ZZ[C_coeffs])
H = f - A.diff()*v + A*(u.diff()*v).exquo(u) - B*u
result = solve(H.coeffs(), C_coeffs)
A = A.as_basic().subs(result)
B = B.as_basic().subs(result)
rat_part = cancel(A/u.as_basic(), x)
log_part = cancel(B/v.as_basic(), x)
return rat_part, log_part
示例10: dispersionset
# 需要导入模块: from sympy.polys import Poly [as 别名]
# 或者: from sympy.polys.Poly import degree [as 别名]
def dispersionset(p, q=None, *gens, **args):
r"""Compute the *dispersion set* of two polynomials.
For two polynomials `f(x)` and `g(x)` with `\deg f > 0`
and `\deg g > 0` the dispersion set `\operatorname{J}(f, g)` is defined as:
.. math::
\operatorname{J}(f, g)
& := \{a \in \mathbb{N}_0 | \gcd(f(x), g(x+a)) \neq 1\} \\
& = \{a \in \mathbb{N}_0 | \deg \gcd(f(x), g(x+a)) \geq 1\}
For a single polynomial one defines `\operatorname{J}(f) := \operatorname{J}(f, f)`.
Examples
========
>>> from sympy import poly
>>> from sympy.polys.dispersion import dispersion, dispersionset
>>> from sympy.abc import x
Dispersion set and dispersion of a simple polynomial:
>>> fp = poly((x - 3)*(x + 3), x)
>>> sorted(dispersionset(fp))
[0, 6]
>>> dispersion(fp)
6
Note that the definition of the dispersion is not symmetric:
>>> fp = poly(x**4 - 3*x**2 + 1, x)
>>> gp = fp.shift(-3)
>>> sorted(dispersionset(fp, gp))
[2, 3, 4]
>>> dispersion(fp, gp)
4
>>> sorted(dispersionset(gp, fp))
[]
>>> dispersion(gp, fp)
-oo
Computing the dispersion also works over field extensions:
>>> from sympy import sqrt
>>> fp = poly(x**2 + sqrt(5)*x - 1, x, domain='QQ<sqrt(5)>')
>>> gp = poly(x**2 + (2 + sqrt(5))*x + sqrt(5), x, domain='QQ<sqrt(5)>')
>>> sorted(dispersionset(fp, gp))
[2]
>>> sorted(dispersionset(gp, fp))
[1, 4]
We can even perform the computations for polynomials
having symbolic coefficients:
>>> from sympy.abc import a
>>> fp = poly(4*x**4 + (4*a + 8)*x**3 + (a**2 + 6*a + 4)*x**2 + (a**2 + 2*a)*x, x)
>>> sorted(dispersionset(fp))
[0, 1]
See Also
========
dispersion
References
==========
1. [ManWright94]_
2. [Koepf98]_
3. [Abramov71]_
4. [Man93]_
"""
# Check for valid input
same = False if q is not None else True
if same:
q = p
p = Poly(p, *gens, **args)
q = Poly(q, *gens, **args)
if not p.is_univariate or not q.is_univariate:
raise ValueError("Polynomials need to be univariate")
# The generator
if not p.gen == q.gen:
raise ValueError("Polynomials must have the same generator")
gen = p.gen
# We define the dispersion of constant polynomials to be zero
if p.degree() < 1 or q.degree() < 1:
return set([0])
# Factor p and q over the rationals
fp = p.factor_list()
fq = q.factor_list() if not same else fp
# Iterate over all pairs of factors
J = set([])
for s, unused in fp[1]:
for t, unused in fq[1]:
#.........这里部分代码省略.........
示例11: number_of_real_roots
# 需要导入模块: from sympy.polys import Poly [as 别名]
# 或者: from sympy.polys.Poly import degree [as 别名]
def number_of_real_roots(f, *gens, **args):
"""Returns the number of distinct real roots of `f` in `(inf, sup]`.
Examples
========
>>> from sympy import Poly
>>> from sympy.abc import x, y
>>> from sympy.polys.polyroots import number_of_real_roots
>>> f = Poly(x**2 - 1, x)
Count real roots in the (-oo, oo) interval:
>>> number_of_real_roots(f)
2
Count real roots in the (0, 2) interval:
>>> number_of_real_roots(f, inf=0, sup=2)
1
Count real roots in the (2, oo) interval:
>>> number_of_real_roots(f, inf=2)
0
References
==========
.. [Davenport88] J.H. Davenport, Y. Siret, E. Tournier, Computer
Algebra Systems and Algorithms for Algebraic Computation,
Academic Press, London, 1988, pp. 124-128
"""
def sign_changes(seq):
count = 0
for i in xrange(1, len(seq)):
if (seq[i-1] < 0 and seq[i] >= 0) or \
(seq[i-1] > 0 and seq[i] <= 0):
count += 1
return count
F = Poly(f, *gens, **args)
if not F.is_Poly:
return 0
if F.is_multivariate:
raise ValueError('multivariate polynomials not supported')
if F.degree() < 1:
return 0
inf = args.get('inf', None)
if inf is not None:
inf = sympify(inf)
if not inf.is_number:
raise ValueError("Not a number: %s" % inf)
elif abs(inf) is S.Infinity:
inf = None
sup = args.get('sup', None)
if sup is not None:
sup = sympify(sup)
if not sup.is_number:
raise ValueError("Not a number: %s" % sup)
elif abs(sup) is S.Infinity:
sup = None
sturm = F.sturm()
if inf is None:
signs_inf = sign_changes([ s.LC()*(-1)**s.degree() for s in sturm ])
else:
signs_inf = sign_changes([ s.eval(inf) for s in sturm ])
if sup is None:
signs_sup = sign_changes([ s.LC() for s in sturm ])
else:
signs_sup = sign_changes([ s.eval(sup) for s in sturm ])
return abs(signs_inf - signs_sup)
示例12: roots
# 需要导入模块: from sympy.polys import Poly [as 别名]
# 或者: from sympy.polys.Poly import degree [as 别名]
#.........这里部分代码省略.........
def _update_dict(result, root, k):
if root in result:
result[root] += k
else:
result[root] = k
def _try_decompose(f):
"""Find roots using functional decomposition. """
factors = f.decompose()
result, g = {}, factors[0]
for h, i in g.sqf_list()[1]:
for r in _try_heuristics(h):
_update_dict(result, r, i)
for factor in factors[1:]:
last, result = result.copy(), {}
for last_r, i in last.iteritems():
g = factor - Poly(last_r, x)
for h, j in g.sqf_list()[1]:
for r in _try_heuristics(h):
_update_dict(result, r, i*j)
return result
def _try_heuristics(f):
"""Find roots using formulas and some tricks. """
if f.is_ground:
return []
if f.is_monomial:
return [S(0)]*f.degree()
if f.length() == 2:
if f.degree() == 1:
return map(cancel, roots_linear(f))
else:
return roots_binomial(f)
result = []
for i in [S(-1), S(1)]:
if f.eval(i).expand().is_zero:
f = f.exquo(Poly(x-1, x))
result.append(i)
break
n = f.degree()
if n == 1:
result += map(cancel, roots_linear(f))
elif n == 2:
result += map(cancel, roots_quadratic(f))
elif n == 3 and flags.get('cubics', True):
result += roots_cubic(f)
elif n == 4 and flags.get('quartics', True):
result += roots_quartic(f)
return result
if f.is_monomial == 1:
if f.is_ground:
if multiple:
return []
示例13: _solve_inequality
# 需要导入模块: from sympy.polys import Poly [as 别名]
# 或者: from sympy.polys.Poly import degree [as 别名]
def _solve_inequality(ie, s, linear=False):
"""Return the inequality with s isolated on the left, if possible.
If the relationship is non-linear, a solution involving And or Or
may be returned. False or True are returned if the relationship
is never True or always True, respectively.
If `linear` is True (default is False) an `s`-dependent expression
will be isoloated on the left, if possible
but it will not be solved for `s` unless the expression is linear
in `s`. Furthermore, only "safe" operations which don't change the
sense of the relationship are applied: no division by an unsigned
value is attempted unless the relationship involves Eq or Ne and
no division by a value not known to be nonzero is ever attempted.
Examples
========
>>> from sympy import Eq, Symbol
>>> from sympy.solvers.inequalities import _solve_inequality as f
>>> from sympy.abc import x, y
For linear expressions, the symbol can be isolated:
>>> f(x - 2 < 0, x)
x < 2
>>> f(-x - 6 < x, x)
x > -3
Sometimes nonlinear relationships will be False
>>> f(x**2 + 4 < 0, x)
False
Or they may involve more than one region of values:
>>> f(x**2 - 4 < 0, x)
(-2 < x) & (x < 2)
To restrict the solution to a relational, set linear=True
and only the x-dependent portion will be isolated on the left:
>>> f(x**2 - 4 < 0, x, linear=True)
x**2 < 4
Division of only nonzero quantities is allowed, so x cannot
be isolated by dividing by y:
>>> y.is_nonzero is None # it is unknown whether it is 0 or not
True
>>> f(x*y < 1, x)
x*y < 1
And while an equality (or unequality) still holds after dividing by a
non-zero quantity
>>> nz = Symbol('nz', nonzero=True)
>>> f(Eq(x*nz, 1), x)
Eq(x, 1/nz)
the sign must be known for other inequalities involving > or <:
>>> f(x*nz <= 1, x)
nz*x <= 1
>>> p = Symbol('p', positive=True)
>>> f(x*p <= 1, x)
x <= 1/p
When there are denominators in the original expression that
are removed by expansion, conditions for them will be returned
as part of the result:
>>> f(x < x*(2/x - 1), x)
(x < 1) & Ne(x, 0)
"""
from sympy.solvers.solvers import denoms
if s not in ie.free_symbols:
return ie
if ie.rhs == s:
ie = ie.reversed
if ie.lhs == s and s not in ie.rhs.free_symbols:
return ie
expr = ie.lhs - ie.rhs
rv = None
try:
p = Poly(expr, s)
if p.degree() == 0:
rv = ie.func(p.as_expr(), 0)
elif not linear and p.degree() > 1:
# handle in except clause
raise NotImplementedError
except (PolynomialError, NotImplementedError):
if not linear:
try:
return reduce_rational_inequalities([[ie]], s)
except PolynomialError:
return solve_univariate_inequality(ie, s)
else:
p = Poly(expr)
e = expanded = p.as_expr() # this is in exanded form
#.........这里部分代码省略.........
示例14: _solve
# 需要导入模块: from sympy.polys import Poly [as 别名]
# 或者: from sympy.polys.Poly import degree [as 别名]
#.........这里部分代码省略.........
# Poly(sqrt(x) + x**(1/4), sqrt(x), x**(1/4), domain='ZZ')
# If the exponents are Rational then a change of variables
# will make this a polynomial equation in a single base.
def as_base_q(x):
"""Return (b**e, q) for x = b**(p*e/q) where p/q is the leading
Rational of the exponent of x, e.g. exp(-2*x/3) -> (exp(x), 3)
"""
b, e = x.as_base_exp()
if e.is_Rational:
return b, e.q
if not e.is_Mul:
return x, 1
c, ee = e.as_coeff_Mul()
if c.is_Rational and not c is S.One: # c could be a Float
return b**ee, c.q
return x, 1
bases, qs = zip(*[as_base_q(g) for g in gens])
bases = set(bases)
if len(bases) == 1 and any(q != 1 for q in qs):
# e.g. for x**(1/2) + x**(1/4) a change of variables
# can be made using p**4 to give p**2 + p
base = bases.pop()
m = reduce(ilcm, qs)
p = Dummy('p', positive=True)
cov = p**m
fnew = f_num.subs(base, cov)
poly = Poly(fnew, p) # we now have a single generator, p
# for cubics and quartics, if the flag wasn't set, DON'T do it
# by default since the results are quite long. Perhaps one could
# base this decision on a certain critical length of the roots.
if poly.degree() > 2:
flags['simplify'] = flags.get('simplify', False)
soln = roots(poly, cubics=True, quartics=True).keys()
# We now know what the values of p are equal to. Now find out
# how they are related to the original x, e.g. if p**2 = cos(x) then
# x = acos(p**2)
#
inversion = _solve(cov - base, symbol, **flags)
result = [i.subs(p, s) for i in inversion for s in soln]
if check:
result = [r for r in result if checksol(f_num, {symbol: r}, **flags) is not False]
elif len(gens) == 1:
# There is only one generator that we are interested in, but there may
# have been more than one generator identified by polys (e.g. for symbols
# other than the one we are interested in) so recast the poly in terms
# of our generator of interest.
if len(poly.gens) > 1:
poly = Poly(poly, gens[0])
# if we haven't tried tsolve yet, do so now
if not flags.pop('tsolve', False):
# for cubics and quartics, if the flag wasn't set, DON'T do it
# by default since the results are quite long. Perhaps one could
# base this decision on a certain critical length of the roots.
if poly.degree() > 2:
flags['simplify'] = flags.get('simplify', False)
soln = roots(poly, cubics=True, quartics=True).keys()
gen = poly.gen
if gen != symbol:
u = Dummy()