Repository: sympy/sympy

Issue:
factor_list should collect factors identified from partially factored input
From [this SO](https://stackoverflow.com/questions/75337159/how-do-i-store-factors-of-polynomials-in-a-list-in-sympy/75339700#75339700): Note that the expanded polynomial returns a factor with multiplicity of 2. Expansion should not be necessary to get the same from a partially factored input. This requires that the results of individual factors be combined before returning:
```python
>>> factor_list((x+1)*(x**6-1))
(1, [(x - 1, 1), (x + 1, 1), (x + 1, 1), (x**2 - x + 1, 1), (x**2 + x + 1, 1)])
>>> factor_list(expand((x+1)*(x**6-1)))
(1, [(x - 1, 1), (x + 1, 2), (x**2 - x + 1, 1), (x**2 + x + 1, 1)])

# prefer this

>>> [(b,e*c) for (b,e),c in Counter(factor_list((x+1)*(x**6-1))[1]).items()]
[(x - 1, 1), (x + 1, 2), (x**2 - x + 1, 1), (x**2 + x + 1, 1)]
```

Discussion:

Patch:
diff --git a/sympy/polys/polytools.py b/sympy/polys/polytools.py
index 4171328885..0546cd1674 100644
--- a/sympy/polys/polytools.py
+++ b/sympy/polys/polytools.py
@@ -4,7 +4,7 @@
 from functools import wraps, reduce
 from operator import mul
 from typing import Optional
-from collections import Counter
+from collections import Counter, defaultdict
 
 from sympy.core import (
     S, Expr, Add, Tuple
@@ -6336,8 +6336,11 @@ def _symbolic_factor_list(expr, opt, method):
     if method == 'sqf':
         factors = [(reduce(mul, (f for f, _ in factors if _ == k)), k)
                    for k in {i for _, i in factors}]
-
-    return coeff, factors
+    #collect duplicates
+    rv = defaultdict(int)
+    for k, v in factors:
+        rv[k] += v
+    return coeff, list(rv.items())
 
 
 def _symbolic_factor(expr, opt, method):


Test patch:
diff --git a/sympy/integrals/tests/test_transforms.py b/sympy/integrals/tests/test_transforms.py
index ad299fea91..fdf7192594 100644
--- a/sympy/integrals/tests/test_transforms.py
+++ b/sympy/integrals/tests/test_transforms.py
@@ -356,10 +356,11 @@ def simp_pows(expr):
         == (x - 1)**(beta - 1)*Heaviside(x - 1)
     assert simp_pows(IMT(gamma(s)*gamma(rho - s)/gamma(rho), s, x, (0, None))) \
         == (1/(x + 1))**rho
-    assert simp_pows(IMT(d**c*d**(s - 1)*sin(pi*c)
+    expr = IMT(d**c*d**(s - 1)*sin(pi*c)
                          *gamma(s)*gamma(s + c)*gamma(1 - s)*gamma(1 - s - c)/pi,
-                         s, x, (Max(-re(c), 0), Min(1 - re(c), 1)))) \
-        == (x**c - d**c)/(x - d)
+                         s, x, (Max(-re(c), 0), Min(1 - re(c), 1)))
+    assert powsimp(expand_mul(expr, deep=False)).replace(exp_polar, exp).simplify() \
+        == (-d**c + x**c)/(-d + x)
 
     assert simplify(IMT(1/sqrt(pi)*(-c/2)*gamma(s)*gamma((1 - c)/2 - s)
                         *gamma(-c/2 - s)/gamma(1 - c - s),
diff --git a/sympy/polys/tests/test_polytools.py b/sympy/polys/tests/test_polytools.py
index b7ec95d056..c33ae574c7 100644
--- a/sympy/polys/tests/test_polytools.py
+++ b/sympy/polys/tests/test_polytools.py
@@ -2756,6 +2756,8 @@ def test_factor():
 
     assert factor_list(x**3 - x*y**2, t, w, x) == (
         1, [(x, 1), (x - y, 1), (x + y, 1)])
+    assert factor_list((x+1)*(x**6-1)) == (
+        1, [(x - 1, 1), (x + 1, 2), (x**2 - x + 1, 1), (x**2 + x + 1, 1)])
 
     # https://github.com/sympy/sympy/issues/24952
     s2, s2p, s2n = sqrt(2), 1 + sqrt(2), 1 - sqrt(2)