Repository: sympy/sympy

Issue:
Multiple subs() yield incorrect results
Given the SymPy code (using latest master as of Oct 15, 2019)

```python
from sympy import *
AMPLRHO,SINHWRHO,xx0,SINHWZ,xx2,AMPLZ,const_dz,const_drho = symbols('AMPLRHO SINHWRHO xx0 SINHWZ xx2 AMPLZ const_dz,const_drho',real=True)
x0,x1,x2,x3 = symbols('x0 x1 x2 x3',real=True)

expr = sqrt(AMPLRHO**2*(const_drho*xx0 + 0.851960487902352830680680629342/(exp(x0) - exp(-x0)))**2 + AMPLZ**2*(const_dz*xx2 + (exp(x3) - exp(-x3))/(exp(x2) - exp(-x2)))**2)

expr = expr.subs(x1,0.414047984412679975621343929773)
expr = expr.subs(AMPLRHO,0.446696088287483306089598045219)
expr = expr.subs(xx0,0.41187635273495315502145786013)
expr = expr.subs(AMPLZ,0.588118850910659518582690452604)
expr = expr.subs(x2,1.24435070438552085937065080003)
expr = expr.subs(x0,1.00527253303887608436429294321)
expr = expr.subs(const_drho,0.595088792659128618112163167098)
expr = expr.subs(xx2,0.540732016614090760242561373161)
expr = expr.subs(const_dz,0.182385133527420140175934193394)
expr = expr.subs(x3, 0.672860265757547005562015751411)
print(expr)
```

the result from the ```print()``` statement at the bottom is
```0.581139663779179```

which is incorrect. Bisecting the substitution a bit (by converting to mathematica_code() and performing all substitutions on the expressions after each substitution above), I find the culprit is near the const_dz line.

Using the following Mathematica code, 
```mathematica
(AMPLRHO^2*(constdrho*xx0 + 
                 0.851960487902353/(Exp[x0] - Exp[-x0]))^2 + 
             AMPLZ^2*(constdz*
                  xx2 + (Exp[x3] - Exp[-x3])/(Exp[x2] - 
                    Exp[-x2]))^2)^(1/2) /. 
          x1 -> 0.414047984412679975621343929773 /. 
         AMPLRHO -> 0.446696088287483306089598045219 /. 
        xx0 -> 0.41187635273495315502145786013 /. 
       AMPLZ -> 0.588118850910659518582690452604 /. 
      x2 -> 1.24435070438552085937065080003 /. 
     x0 -> 1.00527253303887608436429294321 /. 
    constdrho -> 0.595088792659128618112163167098 /. 
   xx2 -> 0.540732016614090760242561373161 /. 
  constdz -> 0.182385133527420140175934193394 /. 
 x3 -> 0.672860265757547005562015751411
```
I get the correct answer of 
```0.4233805076587912```

which also appears if I rearrange the order of the subs above (using random.org):
```python
from sympy import *
AMPLRHO,SINHWRHO,xx0,SINHWZ,xx2,AMPLZ,const_dz,const_drho = symbols('AMPLRHO SINHWRHO xx0 SINHWZ xx2 AMPLZ const_dz,const_drho',real=True)
x0,x1,x2,x3 = symbols('x0 x1 x2 x3',real=True)

expr = sqrt(AMPLRHO**2*(const_drho*xx0 + 0.851960487902352830680680629342/(exp(x0) - exp(-x0)))**2 + AMPLZ**2*(const_dz*xx2 + (exp(x3) - exp(-x3))/(exp(x2) - exp(-x2)))**2)

expr = expr.subs(x0,1.00527253303887608436429294321)
expr = expr.subs(xx2,0.540732016614090760242561373161)
expr = expr.subs(x2,1.24435070438552085937065080003)
expr = expr.subs(xx0,0.41187635273495315502145786013)
expr = expr.subs(x1,0.414047984412679975621343929773)
expr = expr.subs(x3, 0.672860265757547005562015751411)
expr = expr.subs(const_dz,0.182385133527420140175934193394)
expr = expr.subs(const_drho,0.595088792659128618112163167098)
expr = expr.subs(AMPLZ,0.588118850910659518582690452604)
expr = expr.subs(AMPLRHO,0.446696088287483306089598045219)
print(expr)
```

The result in this case is the correct one, ```0.4233805076587912```.

**Note that this issue does not appear to exist in SymPy 1.4.**

Discussion:

Patch:
diff --git a/sympy/core/add.py b/sympy/core/add.py
index dadf372679..75f99250d1 100644
--- a/sympy/core/add.py
+++ b/sympy/core/add.py
@@ -389,13 +389,14 @@ def _eval_power(self, e):
             c, m = zip(*[i.as_coeff_Mul() for i in self.args])
             big = 0
             float = False
+            s = dict()
             for i in c:
                 float = float or i.is_Float
-                if abs(i) > big:
+                if abs(i) >= big:
                     big = 1.0*abs(i)
-                    s = -1 if i < 0 else 1
+                    s[i] = -1 if i < 0 else 1
             if float and big and big != 1:
-                addpow = Add(*[(s if abs(c[i]) == big else c[i]/big)*m[i]
+                addpow = Add(*[(s[c[i]] if abs(c[i]) == big else c[i]/big)*m[i]
                              for i in range(len(c))])**e
                 return big**e*addpow
 


Test patch:
diff --git a/sympy/core/tests/test_power.py b/sympy/core/tests/test_power.py
index d5c4817818..69e557669f 100644
--- a/sympy/core/tests/test_power.py
+++ b/sympy/core/tests/test_power.py
@@ -471,6 +471,9 @@ def test_issue_2993():
     eq = (2.3*x + 4)
     assert eq**2 == 16.0*(0.575*x + 1)**2
     assert (1/eq).args == (eq, -1)  # don't change trivial power
+    # issue 17735
+    q=.5*exp(x) - .5*exp(-x) + 0.1
+    assert int((q**2).subs(x, 1)) == 1
 
 
 def test_issue_17450():