precalculus25 min

Sequences and Series

Arithmetic and geometric sequences, their formulas, and partial sums

0/9Not Started

Why This Matters

A sequence is an ordered list of numbers following a pattern. Sequences are everywhere in programming: iterating through indices, generating Fibonacci numbers, paginating results, or computing running totals. The two most important types are arithmetic sequences (add the same amount each time, like 2, 5, 8, 11, 14) and geometric sequences (multiply by the same factor each time, like 3, 6, 12, 24, 48).

Knowing the closed-form formula for the nth term means you can jump directly to any position without iterating through all previous terms -- the difference between O(1) and O(n). Understanding partial sums lets you calculate totals efficiently, from summing array elements to computing compound interest over multiple periods to analyzing the total work done by nested loops.

Define Terms

Visual Model

SequenceOrdered list of numbers
ArithmeticAdd common difference d
GeometricMultiply common ratio r
a_n = a_1 + (n-1)dnth term formula
a_n = a_1 * r^(n-1)nth term formula
S_n = n(a_1 + a_n)/2Arithmetic partial sum
S_n = a_1(1-r^n)/(1-r)Geometric partial sum
Pattern RecognitionConstant difference or ratio?

The full process at a glance. Click Start tour to walk through each step.

Arithmetic sequences add a constant, geometric sequences multiply by a constant. Both have O(1) formulas for the nth term and partial sum.

Code Example

Code
// Arithmetic sequence: a_n = a1 + (n-1) * d
function arithmeticNth(a1, d, n) {
  return a1 + (n - 1) * d;
}

// Arithmetic partial sum: S_n = n * (a1 + an) / 2
function arithmeticSum(a1, d, n) {
  const an = arithmeticNth(a1, d, n);
  return n * (a1 + an) / 2;
}

console.log("Arithmetic: 2, 5, 8, 11, ...");
console.log("10th term:", arithmeticNth(2, 3, 10));  // 29
console.log("Sum of first 10:", arithmeticSum(2, 3, 10)); // 155

// Geometric sequence: a_n = a1 * r^(n-1)
function geometricNth(a1, r, n) {
  return a1 * Math.pow(r, n - 1);
}

// Geometric partial sum: S_n = a1 * (1 - r^n) / (1 - r)
function geometricSum(a1, r, n) {
  if (r === 1) return a1 * n;
  return a1 * (1 - Math.pow(r, n)) / (1 - r);
}

console.log("\nGeometric: 3, 6, 12, 24, ...");
console.log("8th term:", geometricNth(3, 2, 8));   // 384
console.log("Sum of first 8:", geometricSum(3, 2, 8)); // 765

// Generate sequence terms
function generateArithmetic(a1, d, count) {
  const terms = [];
  for (let i = 1; i <= count; i++) terms.push(arithmeticNth(a1, d, i));
  return terms;
}
console.log("\nFirst 7 terms:", generateArithmetic(2, 3, 7));

// Verify sum by iteration
const terms = generateArithmetic(2, 3, 10);
const iterSum = terms.reduce((a, b) => a + b, 0);
console.log("Verify sum:", iterSum); // 155

Interactive Experiment

Try these exercises:

  • Write out the first 10 terms of the arithmetic sequence with a1 = 1, d = 7. Verify the 10th term using the formula.
  • Write out the first 8 terms of the geometric sequence with a1 = 1, r = 3. How fast does it grow?
  • Compute the sum 1 + 2 + 3 + ... + 100 using the arithmetic sum formula. This is the famous Gauss sum.
  • For a geometric sequence with r = 0.5, compute the sum of 20 terms and the sum of 100 terms. What value does the sum approach?
  • Find the common difference d if the 1st term is 4 and the 20th term is 61.

Quick Quiz

Coding Challenge

Compute Nth Term and Partial Sum

Write two pairs of functions: (1) `arithmeticNth(a1, d, n)` returns the nth term of an arithmetic sequence, and `arithmeticSum(a1, d, n)` returns the sum of the first n terms. (2) `geometricNth(a1, r, n)` returns the nth term of a geometric sequence, and `geometricSum(a1, r, n)` returns the sum of the first n terms. All values should be numbers (no rounding needed for these test cases).

Loading editor...

Real-World Usage

Sequences and series appear constantly in programming and mathematics:

  • Loop analysis: A for loop from 1 to n does n iterations. Nested loops doing 1 + 2 + ... + n = n(n+1)/2 operations explain O(n^2) complexity.
  • Financial math: Annuities (regular payments with interest) use geometric series formulas to calculate present and future values.
  • Signal processing: Fourier series decompose signals into sums of sinusoidal terms. Each term is an element of a sequence.
  • Pagination: Displaying items in pages of size k means the ith page starts at item (i-1)*k + 1, an arithmetic sequence.
  • Fractal geometry: Fractals like the Koch snowflake have perimeters that follow geometric series, growing without bound while enclosing finite area.

Connections