> You have to explicitly tell that indexed variables can overlap and intersect.
I see, I had similar thoughts for explicit splits but was hoping there might be some automation on the side of sympy for this way. Indeed I guess this could stretch too much what sympy should do for us and a split remains viable solution for simple enough cases. I believe there could be more complex equations out there where such explicit split might not be easily possible (in addition to slightly harmed readability from a shorter form of each equation) but have to reach this point first to confirm. In any case, thanks for the quick reply! On Saturday, February 1, 2025 at 5:13:24 AM UTC+8 [email protected] wrote: > You have to explicitly tell that indexed variables can overlap and > intersect. Maybe this code fetches you the desired result, > Try to split the sum into parts > > dF_dxi = x[i] + sp.Sum(x[j], (j, 1, i-1)) + sp.Sum(x[j], (j, i+1, C)) + > x[i] > #outpur: (Sum(x[j], (j, 1, i - 1)) + Sum(x[j], (j, i + 1, C)))*x[i] + > x[i]**2 > > On Tuesday, 28 January 2025 at 15:10:22 UTC+5:30 [email protected] wrote: > >> Hi, does anyone know how to properly integrate this indexed sum for an xi >> term that is also present in the sum indexed by j below? >> ``` >> i, j, C = sp.symbols('i, j, k, C', integer=True) >> x = sp.IndexedBase('x') >> dF_dxi = x[i] + sp.Sum(x[j], (j, 1, C)) >> Fxi = sp.integrate(dF_dxi, x[i]) >> # result: x[i]**2/2 + x[i]*Sum(x[j], (j, 1, C)) >> ``` >> It seems the integration does not realize that one of the xj terms in the >> sum is an xi since it assumes the indices don't ever intersect even though >> these are both defined as integers. >> >> >> -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/sympy/b39874db-f5d3-4dcb-9ffb-2f254a93499cn%40googlegroups.com.
