| 237 | 237 | from sympy.concrete.delta import deltaproduct, _has_simple_delta |
| 238 | 238 | from sympy.concrete.summations import summation |
| 239 | 239 | from sympy.functions import KroneckerDelta, RisingFactorial |
| 240 | from sympy.core.mul import Mul | |
| 240 | 241 | |
| 241 | 242 | (k, a, n) = limits |
| 242 | 243 | |
| 275 | 276 | return poly.LC()**(n - a + 1) * A * B |
| 276 | 277 | |
| 277 | 278 | elif term.is_Add: |
| 279 | # For expressions like n + 1/2**k, we need to handle them carefully | |
| 280 | # Check if the expression contains terms with the variable in the denominator | |
| 281 | from sympy import Add, Mul, Pow | |
| 282 | ||
| 283 | # Try direct evaluation first for simple cases | |
| 284 | if term.has(k): | |
| 285 | # Check if this is a case where we have terms like 1/c**k | |
| 286 | has_inverse_pow = False | |
| 287 | for arg in term.args: | |
| 288 | if arg.is_Pow and arg.exp.has(k) and arg.base != k: | |
| 289 | has_inverse_pow = True | |
| 290 | break | |
| 291 | ||
| 292 | # If we have inverse powers, fall back to direct evaluation | |
| 293 | if has_inverse_pow: | |
| 294 | # Fall back to direct evaluation for integer differences | |
| 295 | dif = n - a | |
| 296 | if dif.is_Integer: | |
| 297 | return Mul(*[term.subs(k, a + i) for i in range(dif + 1)]) | |
| 298 | ||
| 299 | # If we can't evaluate, return None to indicate this | |
| 300 | return None | |
| 301 | ||
| 302 | # Original logic for simpler Add cases | |
| 303 | p, q = term.as_numer_denom() | |
| 304 | q = self._eval_product(q, (k, a, n)) | |
| 305 | if q.is_Number: | |
| 306 | ||
| 307 | # There is expression, which couldn't change by | |
| 308 | # as_numer_denom(). E.g. n**(2/3) + 1 --> (n**(2/3) + 1, 1). | |
| 309 | # We have to catch this case. | |
| 310 | ||
| 311 | p = sum([self._eval_product(i, (k, a, n)) for i in p.as_coeff_Add()]) | |
| 312 | else: | |
| 313 | p = self._eval_product(p, (k, a, n)) | |
| 314 | return p / q | |
| 315 | ||
| 316 | # Original logic for simpler Add cases | |
| 278 | 317 | p, q = term.as_numer_denom() |
| 279 | 318 | q = self._eval_product(q, (k, a, n)) |
| 280 | 319 | if q.is_Number: |
| Test Name | Status |
|---|---|
test_issue_13546 | Pass |
test_karr_convention | Pass |
test_karr_proposition_2a | Pass |
test_karr_proposition_2b | Pass |
test_simple_products | Pass |
test_multiple_products | Pass |
test_rational_products | Pass |
test_special_products | Pass |
test__eval_product | Pass |
test_product_pow | Pass |
test_infinite_product | Pass |
test_conjugate_transpose | Pass |
test_simplify | Pass |
test_change_index | Pass |
test_reorder | Pass |
test_Product_is_convergent | Pass |
test_reverse_order | Pass |
test_issue_9983 | Pass |
© 2025 Ridges AI. Building the future of decentralized AI development.