# solve can't find solution #14721

Closed
opened this Issue May 16, 2018 · 4 comments

Projects
None yet
3 participants

### proy87 commented May 16, 2018

 `solve([h, -1 + (-k + 1)**2/b**2 + (-h - 1)**2/a**2, -1 + (-k + 1)**2/b**2 + (-h + 1)**2/a**2, k + 2], h, k, a, b)` given empty list, but in fact there is infinite number of solutions.

### skirpichev added a commit to skirpichev/diofant that referenced this issue May 17, 2018

``` Add regression test ```
`Closes sympy/sympy#14721`
``` 4ee2b25 ```
Contributor

### skirpichev commented May 20, 2018

 @proy87, this is fixed in the https://github.com/diofant/diofant, if you are interested.

### proy87 commented May 20, 2018

 @skirpichev, thank you.
Member

### smichr commented May 22, 2018 • edited

 ```diff --git a/sympy/solvers/solvers.py b/sympy/solvers/solvers.py index de0601a..3931b46 100644 --- a/sympy/solvers/solvers.py +++ b/sympy/solvers/solvers.py @@ -288,7 +288,7 @@ def checksol(f, symbol, sol=None, **flags): return False # there are free symbols -- simple expansion might work _, val = val.as_content_primitive() - val = expand_mul(expand_multinomial(val)) + val = _mexpand(val, recursive=True) elif attempt == 2: if minimal: return @@ -301,7 +301,7 @@ def checksol(f, symbol, sol=None, **flags): if flags.get('force', True): val, reps = posify(val) # expansion may work now, so try again and check - exval = expand_mul(expand_multinomial(val)) + exval = _mexpand(val, recursive=True) if exval.is_number or not exval.free_symbols: # we can decide now val = exval @@ -1869,8 +1869,8 @@ def _ok_syms(e, sort=False): legal = set(symbols) # what we are interested in # sort so equation with the fewest potential symbols is first + u = Dummy() # used in solution checking for eq in ordered(failed, lambda _: len(_ok_syms(_))): - u = Dummy() # used in solution checking newresult = [] bad_results = [] got_s = set() @@ -1891,6 +1891,8 @@ def _ok_syms(e, sort=False): else: bad_results.append(r) continue + if _mexpand(eq2.as_numer_denom()[0]) == 0: + break # redundant equation: equals 0 # search for a symbol amongst those available that # can be solved for ok_syms = _ok_syms(eq2, sort=True) diff --git a/sympy/solvers/tests/test_solvers.py b/sympy/solvers/tests/test_solvers.py index b742121..cd008ff 100644 --- a/sympy/solvers/tests/test_solvers.py +++ b/sympy/solvers/tests/test_solvers.py @@ -1932,3 +1932,13 @@ def test_issue_12476(): def test_issue_13849(): t = symbols('t') assert solve((t*(sqrt(5) + sqrt(2)) - sqrt(2), t), t) == [] + + +def test_issue_14721(): + k, h, a, b = symbols(':4') + assert solve([ + -1 + (-k + 1)**2/b**2 + (-h - 1)**2/a**2, + -1 + (-k + 1)**2/b**2 + (-h + 1)**2/a**2, + h, k + 2], h, k, a, b) == [ + (0, -2, -b*sqrt(1/(b**2 - 9)), b), + (0, -2, b*sqrt(1/(b**2 - 9)), b)]```

Member

### smichr commented May 25, 2018

 There is a branch of mine named 14721b that implements these changes.

Merged