Mathematics

Spotting Arithmetic and Geometric Patterns in a List of Numbers

How the Number Sequence Calculator checks a list of observed numbers for a constant difference or constant ratio, and what it does when neither pattern holds.

A worked example: detecting 7, 11, 15, 19 as arithmetic

Enter 7, 11, 15, 19 into the Number Sequence Calculator and it reports patternType "arithmetic", a common value of 4, and a predicted next term of 23. The check behind that is simple: 11 − 7 = 4, 15 − 11 = 4, and 19 − 15 = 4. Every consecutive difference is the same, so the calculator labels the list arithmetic and predicts the next term as the last entered value plus that common difference — 19 + 4 = 23.

The formula: how the pattern check works

The calculator first computes the difference between every consecutive pair of entered numbers. If all of those differences match (allowing for tiny floating-point rounding), it calls the sequence arithmetic and stops there — it never even looks at ratios. Only when the differences aren't constant does it try the second check: the ratio between every consecutive pair. Feed it 2, 6, 18, 54 and the differences are 4, 12, 36 — not constant — but the ratios are 6 ÷ 2 = 3, 18 ÷ 6 = 3, and 54 ÷ 18 = 3, all equal, so it reports patternType "geometric", a common value of 3, and a predicted next term of 54 × 3 = 162.

A second example: pattern with a zero, and one with no pattern

Feed the calculator 5, 0, -5, -10 and it reports arithmetic with a common value of -5 and a predicted next term of -15, since each entry is 5 less than the one before it. Notice that one of the entered numbers is zero: the calculator's geometric check is always skipped whenever any entered number is zero, because a ratio computed through zero is either undefined or degenerate. It doesn't matter here, since the arithmetic check already matched and the calculator never even reaches the geometric step. Now try 1, 4, 9, 16 — perfect squares. The differences are 3, 5, 7 (not constant) and the ratios are 4, 2.25, 1.78 (not constant either), so the calculator reports patternType "unknown" and an explanatory message instead of guessing.

Why more terms give more confidence

The calculator requires at least three numbers, because two numbers always have exactly one difference and one ratio — there's nothing to confirm a pattern against. With four or more entries, every additional term has to keep agreeing with the same common difference or ratio before the calculator will commit to a label. That's why a decreasing run like 20, 15, 10, 5 confidently comes back as arithmetic with a common value of -5 and a predicted next term of 0: three consecutive gaps of -5 in a row is much stronger evidence than a single coincidental match would be.