SomeNorwegianGuy
SomeNorwegianGuy

Reputation: 1534

Why cant sympy simplify these Sum expressions of Indexed variables

Ive hit what seems like a limitation of SymPy. In the middle of trying a small project I notised that SymPy is not able to simplify the following expresison

n, N = symbols('n N', cls=Idx)
x = IndexedBase('x')
eq = Sum(x[n], (n, 0, N)) - Sum(x[n], (n, 0, N-1))
simplify(eq)

The output is simply

enter image description here

This should be "simplifyable" to simply XN

I've tried to replace both one of and both of n and N with Symbol(, integer=True), as well as adding all combinations of the assumptions "positive" and "nonzero". I've also tried to make X a function instead

N = symbols('N', cls=Idx)
n = Symbol('n')
x = Function('x')

eq = Sum(x(n), (n, 0, N)) - Sum(x(n), (n, 0, N-1))
simplify(eq)

Either way SymPy is not able to recognize the possible simplification

Is there any way I can make SymPy be able to do this simplification? Is there an assumption I could add? Is there another function to simplify this?

Update: An issue was opened on the SymPy github asking for implementation of this feature. Any new info will be updated here.

Upvotes: 1

Views: 252

Answers (1)

SomeNorwegianGuy
SomeNorwegianGuy

Reputation: 1534

As noted in the comments by Oscar Benjamin, this is simply a case of this not being implemented. As per now, I have not found any good way to get around this, so if anyone else is running into the same issue, I suggest simply waiting for an update that implements this, or if this is a deal breaker, trying to find another library that can handle this use case.

Upvotes: 0

Related Questions