Repository: sympy/sympy

Issue:
Care is not taken at the point x = 1 for Sum( k*x**k, (k, 0, n))
```
>>> pprint(Sum( x**k, (k, 0, n-1)).doit())
⎧   n      for x = 1
⎪                   
⎪   n               
⎨- x  + 1           
⎪────────  otherwise
⎪ -x + 1            
⎩                   
>>> pprint(Sum( k*x**k, (k, 0, n-1)).doit())
     n      n      n    
n⋅x⋅x  - n⋅x  - x⋅x  + x
────────────────────────
               2        
        (x - 1)                  
```
Similarly for `Sum( k*k*x**k, (k, 0, n-1)).doit()`


Discussion:

Patch:
diff --git a/sympy/concrete/summations.py b/sympy/concrete/summations.py
index e7c6a1888b..60d8a78dc8 100644
--- a/sympy/concrete/summations.py
+++ b/sympy/concrete/summations.py
@@ -6,6 +6,7 @@
 from sympy.core.relational import Eq
 from sympy.core.singleton import S
 from sympy.core.symbol import Dummy, Wild, Symbol
+from sympy.core.mul import Mul
 from sympy.core.add import Add
 from sympy.core.mul import Mul
 from sympy.calculus.singularities import is_decreasing
@@ -13,7 +14,7 @@
 from sympy.functions.special.zeta_functions import zeta
 from sympy.functions.elementary.piecewise import Piecewise
 from sympy.logic.boolalg import And
-from sympy.polys import apart, PolynomialError
+from sympy.polys import apart, PolynomialError, together
 from sympy.series.limits import limit
 from sympy.series.order import O
 from sympy.sets.sets import FiniteSet
@@ -22,6 +23,7 @@
 from sympy.solvers import solve
 from sympy.solvers.solveset import solveset
 from sympy.core.compatibility import range
+from sympy.simplify import denom
 from sympy.calculus.util import AccumulationBounds
 import itertools
 
@@ -1053,6 +1055,25 @@ def eval_sum_symbolic(f, limits):
 
         r = gosper_sum(f, (i, a, b))
 
+        if isinstance(r, (Mul,Add)):
+            from sympy import ordered, Tuple
+            non_limit = r.free_symbols - Tuple(*limits[1:]).free_symbols
+            den = denom(together(r))
+            den_sym = non_limit & den.free_symbols
+            args = []
+            for v in ordered(den_sym):
+                try:
+                    s = solve(den, v)
+                    m = Eq(v, s[0]) if s else S.false
+                    if m != False:
+                        args.append((Sum(f_orig.subs(*m.args), limits).doit(), m))
+                    break
+                except NotImplementedError:
+                    continue
+
+            args.append((r, True))
+            return Piecewise(*args)
+
         if not r in (None, S.NaN):
             return r
 


Test patch:
diff --git a/sympy/concrete/tests/test_sums_products.py b/sympy/concrete/tests/test_sums_products.py
index 4ff3272a8e..17f348cae6 100644
--- a/sympy/concrete/tests/test_sums_products.py
+++ b/sympy/concrete/tests/test_sums_products.py
@@ -1014,6 +1014,21 @@ def test_issue_10156():
         8*y**3*Sum(x, (x, 1, 3))*Sum(x**2, (x, 1, 9))
 
 
+def test_issue_14129():
+    assert Sum( k*x**k, (k, 0, n-1)).doit() == \
+        Piecewise((n**2/2 - n/2, Eq(x, 1)), ((n*x*x**n -
+            n*x**n - x*x**n + x)/(x - 1)**2, True))
+    assert Sum( x**k, (k, 0, n-1)).doit() == \
+        Piecewise((n, Eq(x, 1)), ((-x**n + 1)/(-x + 1), True))
+    assert Sum( k*(x/y+x)**k, (k, 0, n-1)).doit() == \
+        Piecewise((n*(n - 1)/2, Eq(x, y/(y + 1))),
+        (x*(y + 1)*(n*x*y*(x + x/y)**n/(x + x/y)
+        + n*x*(x + x/y)**n/(x + x/y) - n*y*(x
+        + x/y)**n/(x + x/y) - x*y*(x + x/y)**n/(x
+        + x/y) - x*(x + x/y)**n/(x + x/y) + y)/(x*y
+        + x - y)**2, True))
+
+
 def test_issue_14112():
     assert Sum((-1)**n/sqrt(n), (n, 1, oo)).is_absolutely_convergent() is S.false
     assert Sum((-1)**(2*n)/n, (n, 1, oo)).is_convergent() is S.false