Repository: sympy/sympy

Issue:
integrate(a**t /(a**t+1), t) sucess but a**(t-s)/(a**t+1) fail 
No matter whether `conds='none'`.

``` python
import sympy as sm
print(sm.__version__)
# 1.1.1
from sympy import *
a, t, s = symbols('a t s')
f = a**t/(a**t+1)
integrate(f, t)
# >> log(a**t + 1)/log(a)
g = a**(t-s)/(a**t+1) 
integrate(g, t)
# hoping : a**(-s) log(a**t + 1)/log(a)
# but failed:
# CoercionFailed: can't convert exp(-s*log(a)) of type exp to ZZ(log(a),exp(s*log(a)))
```

And the error stack is
```
---------------------------------------------------------------------------
CoercionFailed                            Traceback (most recent call last)
<ipython-input-35-ff749dece9c9> in <module>()
----> 1 integrate(g, t)

/usr/lib/python3.5/site-packages/sympy/integrals/integrals.py in integrate(*args, **kwargs)
   1293     if isinstance(integral, Integral):
   1294         return integral.doit(deep=False, meijerg=meijerg, conds=conds,
-> 1295                              risch=risch, manual=manual)
   1296     else:
   1297         return integral

/usr/lib/python3.5/site-packages/sympy/integrals/integrals.py in doit(self, **hints)
    484                     function, xab[0],
    485                     meijerg=meijerg1, risch=risch, manual=manual,
--> 486                     conds=conds)
    487                 if antideriv is None and meijerg1 is True:
    488                     ret = try_meijerg(function, xab)

/usr/lib/python3.5/site-packages/sympy/integrals/integrals.py in _eval_integral(self, f, x, meijerg, risch, manual, conds)
    778         if risch is not False:
    779             try:
--> 780                 result, i = risch_integrate(f, x, separate_integral=True, conds=conds)
    781             except NotImplementedError:
    782                 pass

/usr/lib/python3.5/site-packages/sympy/integrals/risch.py in risch_integrate(f, x, extension, handle_first, separate_integral, rewrite_complex, conds)
   1727         fa, fd = fa.cancel(fd, include=True)
   1728         if case == 'exp':
-> 1729             ans, i, b = integrate_hyperexponential(fa, fd, DE, conds=conds)
   1730         elif case == 'primitive':
   1731             ans, i, b = integrate_primitive(fa, fd, DE)

/usr/lib/python3.5/site-packages/sympy/integrals/risch.py in integrate_hyperexponential(a, d, DE, z, conds)
   1457 
   1458     g1, h, r = hermite_reduce(a, d, DE)
-> 1459     g2, b = residue_reduce(h[0], h[1], DE, z=z)
   1460     if not b:
   1461         i = cancel(a.as_expr()/d.as_expr() - (g1[1]*derivation(g1[0], DE) -

/usr/lib/python3.5/site-packages/sympy/integrals/risch.py in residue_reduce(a, d, DE, z, invert)
   1215     z = z or Dummy('z')
   1216     a, d = a.cancel(d, include=True)
-> 1217     a, d = a.to_field().mul_ground(1/d.LC()), d.to_field().mul_ground(1/d.LC())
   1218     kkinv = [1/x for x in DE.T[:DE.level]] + DE.T[:DE.level]
   1219 

/usr/lib/python3.5/site-packages/sympy/polys/polytools.py in mul_ground(f, coeff)
   1204         """
   1205         if hasattr(f.rep, 'mul_ground'):
-> 1206             result = f.rep.mul_ground(coeff)
   1207         else:  # pragma: no cover
   1208             raise OperationNotSupported(f, 'mul_ground')

/usr/lib/python3.5/site-packages/sympy/polys/polyclasses.py in mul_ground(f, c)
    405     def mul_ground(f, c):
    406         """Multiply ``f`` by a an element of the ground domain. """
--> 407         return f.per(dmp_mul_ground(f.rep, f.dom.convert(c), f.lev, f.dom))
    408 
    409     def quo_ground(f, c):

/usr/lib/python3.5/site-packages/sympy/polys/domains/domain.py in convert(self, element, base)
    156                     pass
    157 
--> 158         raise CoercionFailed("can't convert %s of type %s to %s" % (element, type(element), self))
    159 
    160     def of_type(self, element):

CoercionFailed: can't convert exp(-s*log(a)) of type exp to ZZ(log(a),exp(s*log(a)))
```

Discussion:

Patch:
diff --git a/sympy/core/symbol.py b/sympy/core/symbol.py
index 86b3449903..cac6133572 100644
--- a/sympy/core/symbol.py
+++ b/sympy/core/symbol.py
@@ -364,19 +364,6 @@ class Wild(Symbol):
     A Wild symbol matches anything, or anything
     without whatever is explicitly excluded.
 
-    Parameters
-    ==========
-
-    name : str
-        Name of the Wild instance.
-    exclude : iterable, optional
-        Instances in ``exclude`` will not be matched.
-    properties : iterable of functions, optional
-        Functions, each taking an expressions as input
-        and returns a ``bool``. All functions in ``properties``
-        need to return ``True`` in order for the Wild instance
-        to match the expression.
-
     Examples
     ========
 
@@ -439,12 +426,6 @@ class Wild(Symbol):
     >>> E.match(a*b)
     {a_: 2, b_: x**3*y*z}
 
-    Wild also accepts a ``properties`` parameter:
-
-    >>> a = Wild('a', properties=[lambda k: k.is_Integer])
-    >>> E.match(a*b)
-    {a_: 2, b_: x**3*y*z}
-
     """
     is_Wild = True
 
diff --git a/sympy/functions/special/zeta_functions.py b/sympy/functions/special/zeta_functions.py
index 2abda6d7c3..8e9737aaf6 100644
--- a/sympy/functions/special/zeta_functions.py
+++ b/sympy/functions/special/zeta_functions.py
@@ -271,7 +271,6 @@ class polylog(Function):
 
     @classmethod
     def eval(cls, s, z):
-        s, z = sympify((s, z))
         if z == 1:
             return zeta(s)
         elif z == -1:
@@ -298,11 +297,6 @@ def eval(cls, s, z):
             return z/(1 - z)
         elif s == -1:
             return z/(1 - z)**2
-        # polylog is branched, but not over the unit disk
-        if z.is_polar:
-            from sympy.functions.elementary.complexes import Abs, unpolarify
-            if (Abs(z) <= S.One) == True:
-                return cls(s, unpolarify(z))
 
     def fdiff(self, argindex=1):
         s, z = self.args
diff --git a/sympy/polys/fields.py b/sympy/polys/fields.py
index 1917501d57..9f9fdb49ff 100644
--- a/sympy/polys/fields.py
+++ b/sympy/polys/fields.py
@@ -6,8 +6,10 @@
 
 from sympy.core.compatibility import is_sequence, reduce, string_types
 from sympy.core.expr import Expr
+from sympy.core.mod import Mod
 from sympy.core.symbol import Symbol
 from sympy.core.sympify import CantSympify, sympify
+from sympy.functions.elementary.exponential import ExpBase
 from sympy.polys.rings import PolyElement
 from sympy.polys.orderings import lex
 from sympy.polys.polyerrors import CoercionFailed
@@ -204,6 +206,8 @@ def field_new(self, element):
 
     def _rebuild_expr(self, expr, mapping):
         domain = self.domain
+        powers = tuple((gen, gen.as_base_exp()) for gen in mapping.keys()
+            if gen.is_Pow or isinstance(gen, ExpBase))
 
         def _rebuild(expr):
             generator = mapping.get(expr)
@@ -214,16 +218,24 @@ def _rebuild(expr):
                 return reduce(add, list(map(_rebuild, expr.args)))
             elif expr.is_Mul:
                 return reduce(mul, list(map(_rebuild, expr.args)))
-            elif expr.is_Pow and expr.exp.is_Integer:
-                return _rebuild(expr.base)**int(expr.exp)
-            else:
-                try:
-                    return domain.convert(expr)
-                except CoercionFailed:
-                    if not domain.is_Field and domain.has_assoc_Field:
-                        return domain.get_field().convert(expr)
-                    else:
-                        raise
+            elif expr.is_Pow or isinstance(expr, ExpBase):
+                b, e = expr.as_base_exp()
+                # look for bg**eg whose integer power may be b**e
+                choices = tuple((gen, bg, eg) for gen, (bg, eg) in powers
+                    if bg == b and Mod(e, eg) == 0)
+                if choices:
+                    gen, bg, eg = choices[0]
+                    return mapping.get(gen)**(e/eg)
+                elif e.is_Integer:
+                    return _rebuild(expr.base)**int(expr.exp)
+
+            try:
+                return domain.convert(expr)
+            except CoercionFailed:
+                if not domain.is_Field and domain.has_assoc_Field:
+                    return domain.get_field().convert(expr)
+                else:
+                    raise
 
         return _rebuild(sympify(expr))
 


Test patch:
diff --git a/sympy/functions/special/tests/test_zeta_functions.py b/sympy/functions/special/tests/test_zeta_functions.py
index ab2ec9fef4..6370cc55db 100644
--- a/sympy/functions/special/tests/test_zeta_functions.py
+++ b/sympy/functions/special/tests/test_zeta_functions.py
@@ -1,6 +1,6 @@
 from sympy import (Symbol, zeta, nan, Rational, Float, pi, dirichlet_eta, log,
                    zoo, expand_func, polylog, lerchphi, S, exp, sqrt, I,
-                   exp_polar, polar_lift, O, stieltjes, Abs, Sum)
+                   exp_polar, polar_lift, O, stieltjes, Abs)
 from sympy.utilities.randtest import (test_derivative_numerically as td,
                       random_complex_number as randcplx, verify_numerically as tn)
 
@@ -127,8 +127,6 @@ def test_polylog_expansion():
     assert polylog(s, 0) == 0
     assert polylog(s, 1) == zeta(s)
     assert polylog(s, -1) == -dirichlet_eta(s)
-    assert polylog(s, exp_polar(4*I*pi/3)) == polylog(s, exp(4*I*pi/3))
-    assert polylog(s, exp_polar(I*pi)/3) == polylog(s, exp(I*pi)/3)
 
     assert myexpand(polylog(1, z), -log(1 - z))
     assert myexpand(polylog(0, z), z/(1 - z))
@@ -137,12 +135,6 @@ def test_polylog_expansion():
     assert myexpand(polylog(-5, z), None)
 
 
-def test_issue_8404():
-    i = Symbol('i', integer=True)
-    assert Abs(Sum(1/(3*i + 1)**2, (i, 0, S.Infinity)).doit().n(4)
-        - 1.122) < 0.001
-
-
 def test_polylog_values():
     from sympy.utilities.randtest import verify_numerically as tn
     assert polylog(2, 2) == pi**2/4 - I*pi*log(2)
diff --git a/sympy/integrals/tests/test_integrals.py b/sympy/integrals/tests/test_integrals.py
index bdab321a8c..2669b154e2 100644
--- a/sympy/integrals/tests/test_integrals.py
+++ b/sympy/integrals/tests/test_integrals.py
@@ -286,10 +286,6 @@ def test_transcendental_functions():
         -x + x*LambertW(2*x) + x/LambertW(2*x)
 
 
-def test_log_polylog():
-    assert integrate(log(1 - x)/x, (x, 0, 1)) == -pi**2/6
-
-
 def test_issue_3740():
     f = 4*log(x) - 2*log(x)**2
     fid = diff(integrate(f, x), x)
diff --git a/sympy/integrals/tests/test_risch.py b/sympy/integrals/tests/test_risch.py
index 821338146a..f8b9d29c06 100644
--- a/sympy/integrals/tests/test_risch.py
+++ b/sympy/integrals/tests/test_risch.py
@@ -353,6 +353,13 @@ def test_integrate_hyperexponential_returns_piecewise():
     # TODO: Add a test where two different parts of the extension use a
     # Piecewise, like y**x + z**x.
 
+def test_issue_13947():
+    a, t, s = symbols('a t s')
+    assert risch_integrate(2**(-pi)/(2**t + 1), t) == \
+        2**(-pi)*t - 2**(-pi)*log(2**t + 1)/log(2)
+    assert risch_integrate(a**(t - s)/(a**t + 1), t) == \
+        exp(-s*log(a))*log(a**t + 1)/log(a)
+
 def test_integrate_primitive():
     DE = DifferentialExtension(extension={'D': [Poly(1, x), Poly(1/x, t)],
         'Tfuncs': [log]})
diff --git a/sympy/polys/tests/test_fields.py b/sympy/polys/tests/test_fields.py
index 92a5b56592..eaf849b041 100644
--- a/sympy/polys/tests/test_fields.py
+++ b/sympy/polys/tests/test_fields.py
@@ -1,6 +1,6 @@
 """Test sparse rational functions. """
 
-from sympy.polys.fields import field, sfield, FracField
+from sympy.polys.fields import field, sfield, FracField, FracElement
 from sympy.polys.rings import ring
 from sympy.polys.domains import ZZ, QQ
 from sympy.polys.orderings import lex
@@ -129,6 +129,12 @@ def test_FracElement_from_expr():
     raises(ValueError, lambda: F.from_expr(2**x))
     raises(ValueError, lambda: F.from_expr(7*x + sqrt(2)))
 
+    assert isinstance(ZZ[2**x].get_field().convert(2**(-x)),
+        FracElement)
+    assert isinstance(ZZ[x**2].get_field().convert(x**(-6)),
+        FracElement)
+
+
 def test_FracElement__lt_le_gt_ge__():
     F, x, y = field("x,y", ZZ)