Work with functionsLesson 24 of 48 · 7 min

Sum a family of terms

Represent a finite symbolic sum and evaluate its closed form.

Maths refresher: Sigma notation

The symbol Σ instructs you to add one term for each integer index in the specified range, including both endpoints here.

∑k=1nk=n(n+1)2\sum_{k=1}^{n}k=\frac{n(n+1)}2
Worked example

For n=4n=4, the terms are 1+2+3+4=101+2+3+4=10, and the formula gives 4⋅5/2=104\cdot5/2=10.

Maths prerequisite map ↗

A finite sum adds terms indexed by an integer. SymPy Sum can retain the summation object before evaluating it with doit. This separates the mathematical definition from the closed form a symbolic algorithm can obtain.

Build a sum from its steps
  1. First term
    11
  2. Add the second
    1+2=31+2=3
  3. Add the third
    3+3=63+3=6
  4. Add the fourth
    6+4=106+4=10
Starter reference. At n = 4, the finite sum contains four terms. The closed form n(n + 1)/2 gives the same total.

The upper endpoint is included in the sum below. Declaring n as a positive integer matches the intended finite-count model. Product uses an analogous notation for multiplication rather than addition.

Compare the symbolic formula with a small hand-checkable case. When moving to infinite sums, convergence becomes an additional mathematical requirement; a finite-sum identity should not be extended by simply replacing n with infinity without checking that requirement.

Does sp.Sum(k,(k,1,4)) include the term k=4k=4?

Write a prediction (optional)

Exact symbolic investigation

Select Run Python with the code unchanged.

Tools
About Python

Python and the course packages can load while you read. Each run starts with fresh user variables; imported modules stay loaded. Stop replaces the worker. Runtime details ↗

Ctrl+Enter or ⌘+Enter runs Python.

Compare with the worked example

Executed from the published Python during the site build. Your own run appears above. Build environment ↗

Defined sum
∑k=1nk\sum_{k=1}^{n} k
Closed form
n22+n2\frac{n^{2}}{2} + \frac{n}{2}
Sum at n=4
1010
Finite product at 4
2424
Worked text output
Defined sum: Sum(k, (k, 1, n))
Closed form: n**2/2 + n/2
Sum at n=4: 10
Finite product at 4: 24

Read the starter result

The starter Sum at n=4 is 10, while Finite product at 4 is 24. Similar index notation can describe different operations.

Edit and compare

Replace term = k with term = k**2 and check_n = 4 with check_n = 3. Select Run Python. Compare Sum at n=3 with the hand calculation 1² + 2² + 3² and connect it to the new Closed form.

Return to the editor

Scope. This lesson establishes finite indexed operations; infinite-series convergence requires further analysis.

Try a fresh case

Before interpreting an infinite-series result, what extra question matters?

Choose an answer
Need a hint?
Hint 1

Finite and infinite addition are different mathematical claims.

Hint 2

Check the conditions under which the infinite total exists.

Your notesNotes save in this browser when storage is available.