Repository: sympy/sympy

Issue:
Bug in solve maybe
With python 3.4.2, Sympy 1.0:

```
mike@quaking:~/solver/client/app$ pip3 list | grep -i sympy
sympy (1.0)
mike@quaking:~/solver/client/app$ python3
Python 3.4.2 (default, Oct  8 2014, 10:45:20) 
[GCC 4.9.1] on linux
```

If I run the following script

```
import sympy
import math
x, y = sympy.symbols('x y')
e1 = x - y**3 + 4
e2 =  x + y + 4 + 4 * sympy.E
e3 =  x + y + 4 + 4 * math.e
print ("with sympy.E:", sympy.solve([e1, e2], x, y))
print ("with math.e :", sympy.solve([e1, e3], x, y))
```

then I get:

```
mike@quaking:~/solver/client/app$ python3 /tmp/s.py 
with sympy.E: []
with math.e : [(-12.8079458780453, -2.06518143579091), (-15.9057180317317 - 2.04908046988193*I, 1.03259071789545 + 2.04908046988193*I), (-15.9057180317317 + 2.04908046988193*I, 1.03259071789545 - 2.04908046988193*I)]
```

Granted sympy.E and math.e are not the same thing, its odd that in the former case sympy says there are no solutions, and in the second that there are three (which looks plausible since there is a cube term.

Regards
Mike


Discussion:

Patch:
diff --git a/sympy/polys/constructor.py b/sympy/polys/constructor.py
index f62532ef93..080343cb68 100644
--- a/sympy/polys/constructor.py
+++ b/sympy/polys/constructor.py
@@ -120,7 +120,7 @@ def _construct_composite(coeffs, opt):
         return None
 
     if opt.composite is None:
-        if any(gen.is_number for gen in gens):
+        if any(gen.is_number and gen.is_algebraic for gen in gens):
             return None # generators are number-like so lets better use EX
 
         all_symbols = set([])


Test patch:
diff --git a/sympy/polys/tests/test_constructor.py b/sympy/polys/tests/test_constructor.py
index 5238ec52af..41575a50cb 100644
--- a/sympy/polys/tests/test_constructor.py
+++ b/sympy/polys/tests/test_constructor.py
@@ -4,9 +4,10 @@
 from sympy.polys.domains import ZZ, QQ, RR, EX
 from sympy.polys.domains.realfield import RealField
 
-from sympy import S, sqrt, sin, Float
+from sympy import S, sqrt, sin, Float, E, GoldenRatio, pi, Catalan
 from sympy.abc import x, y
 
+
 def test_construct_domain():
     assert construct_domain([1, 2, 3]) == (ZZ, [ZZ(1), ZZ(2), ZZ(3)])
     assert construct_domain([1, 2, 3], field=True) == (QQ, [QQ(1), QQ(2), QQ(3)])
@@ -92,6 +93,7 @@ def test_construct_domain():
 
     assert construct_domain({}) == (ZZ, {})
 
+
 def test_composite_option():
     assert construct_domain({(1,): sin(y)}, composite=False) == \
         (EX, {(1,): EX(sin(y))})
@@ -105,6 +107,7 @@ def test_composite_option():
     assert construct_domain({(1, 0): y}, composite=False) == \
         (EX, {(1, 0): EX(y)})
 
+
 def test_precision():
     f1 = Float("1.01")
     f2 = Float("1.0000000000000000000001")
@@ -121,3 +124,11 @@ def test_precision():
     result = construct_domain([f2])
     y = result[1][0]
     assert y-1 > 1e-50
+
+
+def test_issue_11538():
+    for n in [E, pi, Catalan]:
+        assert construct_domain(n)[0] == ZZ[n]
+        assert construct_domain(x + n)[0] == ZZ[x, n]
+    assert construct_domain(GoldenRatio)[0] == EX
+    assert construct_domain(x + GoldenRatio)[0] == EX
diff --git a/sympy/solvers/tests/test_solvers.py b/sympy/solvers/tests/test_solvers.py
index b1ffb2f806..85e721c00f 100644
--- a/sympy/solvers/tests/test_solvers.py
+++ b/sympy/solvers/tests/test_solvers.py
@@ -4,7 +4,8 @@
     Wild, acos, asin, atan, atanh, cos, cosh, diff, erf, erfinv, erfc,
     erfcinv, exp, im, log, pi, re, sec, sin,
     sinh, solve, solve_linear, sqrt, sstr, symbols, sympify, tan, tanh,
-    root, simplify, atan2, arg, Mul, SparseMatrix, ask, Tuple, nsolve, oo)
+    root, simplify, atan2, arg, Mul, SparseMatrix, ask, Tuple, nsolve, oo,
+    E, cbrt)
 
 from sympy.core.compatibility import range
 from sympy.core.function import nfloat
@@ -1797,6 +1798,22 @@ def test_issue_9567():
     assert solve(1 + 1/(x - 1)) == [0]
 
 
+def test_issue_11538():
+    assert solve(x + E) == [-E]
+    assert solve(x**2 + E) == [-I*sqrt(E), I*sqrt(E)]
+    assert solve(x**3 + 2*E) == [
+        -cbrt(2 * E),
+        cbrt(2)*cbrt(E)/2 - cbrt(2)*sqrt(3)*I*cbrt(E)/2,
+        cbrt(2)*cbrt(E)/2 + cbrt(2)*sqrt(3)*I*cbrt(E)/2]
+    assert solve([x + 4, y + E], x, y) == {x: -4, y: -E}
+    assert solve([x**2 + 4, y + E], x, y) == [
+        (-2*I, -E), (2*I, -E)]
+
+    e1 = x - y**3 + 4
+    e2 = x + y + 4 + 4 * E
+    assert len(solve([e1, e2], x, y)) == 3
+
+
 def test_issue_12114():
     a, b, c, d, e, f, g = symbols('a,b,c,d,e,f,g')
     terms = [1 + a*b + d*e, 1 + a*c + d*f, 1 + b*c + e*f,
@@ -1823,6 +1840,7 @@ def test_issue_12114():
                   d: -f/2 + sqrt(-3*f**2 + 6)/2,
                   e: -f/2 - sqrt(3)*sqrt(-f**2 + 2)/2, g: 2}]
 
+
 def test_inf():
     assert solve(1 - oo*x) == []
     assert solve(oo*x, x) == []
diff --git a/sympy/solvers/tests/test_solveset.py b/sympy/solvers/tests/test_solveset.py
index aef1efc5d8..134a88400a 100644
--- a/sympy/solvers/tests/test_solveset.py
+++ b/sympy/solvers/tests/test_solveset.py
@@ -709,7 +709,7 @@ def test_solveset_complex_exp():
 def test_solve_complex_log():
     assert solveset_complex(log(x), x) == FiniteSet(1)
     assert solveset_complex(1 - log(a + 4*x**2), x) == \
-        FiniteSet(-sqrt(-a/4 + E/4), sqrt(-a/4 + E/4))
+        FiniteSet(-sqrt(-a + E)/2, sqrt(-a + E)/2)
 
 
 def test_solve_complex_sqrt():