In your case: a(i+1) = a(i) + 1 . You want to find the sum: sum(a(i), i=1..n) . That is, knowing the recurrence formula for a sequence, you can find a closed formula for the sum:
n ___ β² β² nβ
(n + 1) β± i = βββββββββ β± 2 βΎβΎβΎ i = 1
The formula can help find sympy (or another symbolic computing system):
>>> from sympy import Function, Sum, rsolve >>> from sympy.abc import i, n >>> a = Function('a') >>> rsolve(a(i+1)-a(i)-1, a(i), {a(1):1}) i >>> Sum(i, (i, 1, n)).doit() 2 nn ββ + β 2 2
Although in such trivial cases, it can and brute force - this demonstrates the general technique, which can in other cases come in handy. More examples: