Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solveset is perhaps oversimplifying #16793

Open
smichr opened this issue May 9, 2019 · 1 comment
Open

solveset is perhaps oversimplifying #16793

smichr opened this issue May 9, 2019 · 1 comment

Comments

@smichr
Copy link
Member

smichr commented May 9, 2019

When computing a solution for a surd within a numerical expression, solveset appears to add in factoring of the surd. This can add a lot of time when the argument is large. solve does not do so and returns much more quickly with an unsimplified surd:

>>> solve(z,surds[0])
[-sqrt(494780809584713239924897123795467407048970073445360407198353838952892466)
, sqrt(494780809584713239924897123795467407048970073445360407198353838952892466)
]
>>> solveset(z,surds[0])
{-3253006644823572288469*sqrt(46756602478563333774770976706), 325300664482357228
8469*sqrt(46756602478563333774770976706)}

>>> nfloat(_)
{-7.03406574880213e+35, 7.03406574880213e+35}
>>> nfloat(surds[0])
7.03406574880213e+35
>>> surds[0].args[0]
494780809584713239924897123795467407048970073445360407198353838952892466
>>> factorint(_)
{2: 1, 19: 1, 445187: 1, 4274029139: 2, 761110076471: 2, 2763865313521315866601: 1}

So solveset factored out the squares:

>>> 4274029139*761110076471
3253006644823572288469
@smichr
Copy link
Member Author

smichr commented May 16, 2019

This may also be a symptom of the same problem. I suspect it is related to the use of roots (or similar):

>>> a = S("6506833320952669167898688709329/5070602400912917605986812821504")
>>> solve(Rational(Float(a,5))<(a.p-x)/a.q)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "s\solvers\solvers.py", line 985, in solve
    return reduce_inequalities(f, symbols=symbols)
  File "s\solvers\inequalities.py", line 986, in reduce_inequalities
    rv = _reduce_inequalities(inequalities, symbols)
  File "s\solvers\inequalities.py", line 923, in _reduce_inequalities
    poly_reduced.append(reduce_rational_inequalities([exprs], gen))
  File "s\solvers\inequalities.py", line 266, in reduce_rational_inequalities
    solution &= solve_rational_inequalities(eqs)
  File "s\solvers\inequalities.py", line 164, in solve_rational_inequalities
    numer_intervals = solve_poly_inequality(numer*denom, rel)
  File "s\solvers\inequalities.py", line 57, in solve_poly_inequality
    reals, intervals = poly.real_roots(multiple=False), []
  File "s\polys\polytools.py", line 3496, in real_roots
    reals = sympy.polys.rootoftools.CRootOf.real_roots(f, radicals=radicals)
  File "s\polys\rootoftools.py", line 400, in real_roots
    return cls._get_roots("_real_roots", poly, radicals)
  File "s\polys\rootoftools.py", line 732, in _get_roots
    coeff, poly = cls._preprocess_roots(poly)
  File "s\polys\rootoftools.py", line 706, in _preprocess_roots
    coeff, poly = preprocess_roots(poly)
  File "s\polys\polyroots.py", line 770, in preprocess_roots
    basis = _integer_basis(poly)
  File "s\polys\polyroots.py", line 693, in _integer_basis
    divs = reversed(divisors(gcd_list(coeffs))[1:])
  File "s\ntheory\factor_.py", line 1404, in divisors
    return sorted(rv)
  File "s\ntheory\factor_.py", line 1344, in _divisors

    factordict = factorint(n)
  File "s\ntheory\factor_.py", line 1217, in factorint

    seed=high_)
  File "s\ntheory\factor_.py", line 492, in pollard_rho
    g = igcd(U - V, n)
  File "s\core\numbers.py", line 180, in igcd
    args_temp = [abs(as_int(i)) for i in args]
  File "s\core\numbers.py", line 180, in <listcomp>
    args_temp = [abs(as_int(i)) for i in args]
  File "s\core\compatibility.py", line 416, in as_int
    from sympy.core.numbers import Integer
  File "<frozen importlib._bootstrap>", line 1019, in _handle_fromlist
KeyboardInterrupt -> it was going very slow

The following is very fast:

>>> solve(Rational(Float(a,5))-(a.p-x)/a.q)
[-1967882098648739254148399]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants