Quadratic equation with SymPy

Very strange behaviour of solve command in SymPy, when I try to solve quadratic equation with parameter a:

from sympy import *
x, a = symbols("x a")
eq = Eq(0, (4 - 4*x + x**2)/(4*a**2))
print(solve(eq, x))
print(solve(simplify(eq), x))

Output:

[2 - sqrt(a**2 - 1)/a, 2 + sqrt(a**2 - 1)/a]
[2]

Just solve gives two (!) solutions, which depend on a. After symplifying it gives only solution x=2, which is correct. What happens? Command solveset works correctly, but I am interested in using solve command. My SymPy version is 1.9.


Solution 1:

This is a bug in as_numer_denom which get an expression that starts as an Add but is essentially a Mul. It is being corrected with this PR.