Arithmetic & geometric sequences

Compute the $n$th term and the finite sum $S_n$ for an arithmetic progression (common difference $d$) or a geometric progression (common ratio $r$).

What it computes. Closed forms for $a_n$ and finite $S_n$ only — not infinite series convergence tests.
Limitations. Large $|r|^n$ can overflow. Infinite geometric sums are not handled here. See the disclaimer.

Related: Sequences, series, and infinite sums · Sequence · Series · Partial sum