Repository: sympy/sympy

Issue:
diophantine(x**2 - x - y**2) raises AttributeError
```
In [1]: diophantine(x**2 - x - y**2)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-5b086bf120fb> in <module>()
----> 1 diophantine(x**2 - x - y**2)
 
/root/sympy/sympy/solvers/diophantine.py in diophantine(eq, param, syms, permute)
    304         var_t, _, eq_type = classify_diop(base, _dict=False)
    305         _, base = signsimp(base, evaluate=False).as_coeff_Mul()
--> 306         solution = diop_solve(base, param)
    307
    308         if eq_type in [

/root/sympy/sympy/solvers/diophantine.py in diop_solve(eq, param)
    434
    435     elif eq_type == "binary_quadratic":
--> 436         return _diop_quadratic(var, coeff, param)
    437
    438     elif eq_type == "homogeneous_ternary_quadratic":

/root/sympy/sympy/solvers/diophantine.py in _diop_quadratic(var, coeff, t)
   1032                         sol.add((ans[0], ans[1]))
   1033                 elif x_0.is_Integer and y_0.is_Integer:
-> 1034                     if is_solution_quad(var, coeff, x_0, y_0):
   1035                         sol.add((x_0, y_0))
   1036

/root/sympy/sympy/solvers/diophantine.py in is_solution_quad(var, coeff, u, v)
   1115     """
   1116     reps = dict(zip(var, (u, v)))
-> 1117     eq = Add(*[j*i.xreplace(reps) for i, j in coeff.items()])
   1118     return _mexpand(eq) == 0
   1119

/root/sympy/sympy/solvers/diophantine.py in <listcomp>(.0)
   1115     """
   1116     reps = dict(zip(var, (u, v)))
-> 1117     eq = Add(*[j*i.xreplace(reps) for i, j in coeff.items()])
   1118     return _mexpand(eq) == 0
   1119

AttributeError: 'int' object has no attribute 'xreplace'
```

Discussion:

Patch:
diff --git a/sympy/solvers/diophantine.py b/sympy/solvers/diophantine.py
index 321ac8c938..6092e35dab 100644
--- a/sympy/solvers/diophantine.py
+++ b/sympy/solvers/diophantine.py
@@ -933,7 +933,7 @@ def _diop_quadratic(var, coeff, t):
     C = coeff[y**2]
     D = coeff[x]
     E = coeff[y]
-    F = coeff[1]
+    F = coeff[S.One]
 
     A, B, C, D, E, F = [as_int(i) for i in _remove_gcd(A, B, C, D, E, F)]
 


Test patch:
diff --git a/sympy/solvers/tests/test_diophantine.py b/sympy/solvers/tests/test_diophantine.py
index d5b6525dcc..e4e8972ae0 100644
--- a/sympy/solvers/tests/test_diophantine.py
+++ b/sympy/solvers/tests/test_diophantine.py
@@ -169,6 +169,13 @@ def test_issue_9106():
         assert not diop_simplify(eq.xreplace(dict(zip(v, sol))))
 
 
+def test_issue_18138():
+    eq = x**2 - x - y**2
+    v = (x, y)
+    for sol in diophantine(eq):
+        assert not diop_simplify(eq.xreplace(dict(zip(v, sol))))
+
+
 @slow
 def test_quadratic_non_perfect_slow():
     assert check_solutions(8*x**2 + 10*x*y - 2*y**2 - 32*x - 13*y - 23)