Status: New
Owner: ----
Labels: Type-Defect Priority-Medium
New issue 2078 by fluid.thought: Solve fails or hangs on a simple pair of
simultaneous linear equations in sympy 0.6.7
http://code.google.com/p/sympy/issues/detail?id=2078
Consider the following code which illustrates (1) successful solution of a
pair of simultaneous linear equations, (2) crash when solving identical
equations with the variable "c" renamed to "C_p", and (3) indefinite hang
when solving a simpler pair of simultaneous linear equations, also with "c"
called "C_p". The error message for scenario 2 is also shown below.
========================================================
from sympy import symbols, solve
scenario = 2 # set to 1, 2, or 3 to see different behavior
if scenario == 1: # this works fine
S, V, P, T, a, c, b, M, N = symbols('S, V, P, T, a, c, b, M, N')
e1 = c + c*N + M*S - P*V*a + M*P*V*a
e2 = N*V + P*V*b - T*V*a - M*P*V*b - N*T*V*a
print solve([e1, e2], [M, N])
if scenario == 2: # this crashes
S, V, P, T, a, C_p, b, M, N = symbols('S, V, P, T, a, C_p, b, M, N')
e1 = C_p + C_p*N + M*S - P*V*a + M*P*V*a
e2 = N*V + P*V*b - T*V*a - M*P*V*b - N*T*V*a
print solve([e1, e2], [M, N])
if scenario == 3: # this hangs
S, V, P, T, a, C_p, b, M, N = symbols('S, V, P, T, a, C_p, b, M, N')
e1 = C_p + C_p*N + M*S - P*V*a # + M*P*V*a
e2 = N*V + P*V*b - T*V*a - M*P*V*b - N*T*V*a
print solve([e1, e2], [M, N])
The stack trace for scenario 2 follows:
===================================================
Traceback (most recent call last):
File "<stdin>", line 15, in <module>
File "/usr/local/lib/python2.6/dist-packages/sympy/solvers/solvers.py",
line 383, in solve
soln = solve_linear_system(matrix, *symbols, **flags)
File "/usr/local/lib/python2.6/dist-packages/sympy/solvers/solvers.py",
line 502, in solve_linear_system
solutions[syms[k]] = simplify(content)
File "/usr/local/lib/python2.6/dist-packages/sympy/simplify/simplify.py",
line 1311, in simplify
expr = Poly.cancel(powsimp(expr))
File "/usr/local/lib/python2.6/dist-packages/sympy/polys/polynomial.py",
line 695, in cancel
g = sympy.polys.algorithms.poly_gcd(p, q)
File "/usr/local/lib/python2.6/dist-packages/sympy/polys/algorithms.py",
line 483, in poly_gcd
h = poly_div(f*g, poly_lcm(f, g))[0]
File "/usr/local/lib/python2.6/dist-packages/sympy/polys/algorithms.py",
line 412, in poly_lcm
h_coeffs = H[0].coeffs
IndexError: list index out of range
===============================================
Judging by the stack trace, this issue may be related to issue 989
(http://code.google.com/p/sympy/issues/detail?id=989)
Attachments:
sympy_linear_system_solve_bug.py 798 bytes
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy-issues?hl=en.