Madhava’s Series for π
The Madhava–Leibniz series π/4 = 1 − 1/3 + 1/5 − … converges painfully slowly. This demo steps through partial sums, plots the error on a log scale, and shows how adding half of the next term sharply accelerates convergence.
π/4 = 1 − 1/3 + 1/5 − 1/7 + … · S(6) = 0.744011544 · error = 4.139e-2 · first correction 0.076923 / 2 → 0.782473082
The raw alternating sum crawls toward π/4 ≈ 0.785398163. Its error falls like 1/N, so you need thousands of terms for a few digits. Adding half of the next term cancels most of that error and converges much faster, as the green curve shows. The Kerala school used such series reasoning long before Europe.
What you are seeing
Term k is (−1)^k/(2k+1), so the partial sums alternate above and below π/4. The error shrinks only like 1/N for the raw sum.
The true value lies between consecutive partial sums. Adding half of the next term, S + term/2, cancels the leading error and converges much faster.
The chart plots both errors on a log scale against the number of terms, so you can compare convergence slopes directly.
Why it matters
This is one of the earliest uses of infinite series to compute a constant. It also teaches a lasting lesson: the same sum can converge slowly or quickly depending on how you extrapolate it.
Complexity & details
Computing N terms costs O(N). The correction adds O(1) work, and plots sample up to 201 points with a stride.
Frequently asked questions
Did Madhava discover this exact series?+
The π series is associated with Madhava and the Kerala school, and independently with later European mathematicians. Which related series came from exactly whom is not fully secure, so the demo credits the tradition rather than a single person for everything.
Why does halving the next term help so much?+
For an alternating series with decreasing terms, the limit sits between S and S + next term. The midpoint S + next/2 is far closer, removing the dominant half-step error, so the remaining error drops much faster.