Contents
Deep Breakdown
What it tells me (Situation Awareness):
An arithmetic sequence has a constant difference between consecutive terms. The formula gives the -th term in time from , , and . In DA/DS: np.linspace and np.arange produce arithmetic sequences; straight-line depreciation models a linear decrease; cohort analysis uses weekly/monthly arithmetic offsets; histogram bin edges are arithmetic sequences. Plotting vs. gives a straight line with slope — it is the discrete analogue of .
Flowchart
Real-world use
Where it is used
Equally spaced time indices; straight-line depreciation; linearly spaced feature bins; cohort offsets (weeks 1, 8, 15, ...); uniform sampling grids; constant-rate growth/decline models.
Problem it solves
Jump directly to the -th value in a linearly growing/declining sequence without iterating all prior terms.
How it solves the problem
Start at , add exactly times: .
Example in a business
Straight-line depreciation: asset purchased for EUR 50,000 (, /yr). Book value in year : . At year 10: (salvage value).
The formula, piece by piece
Each symbol:
- : the -th term
- : the first term ()
- : position in sequence (, 1-based)
- : common difference; for any Find : Find : 0-based (Python indexing): for
The formula in words
"Start at . Take equal steps of size . You land on ."
Critical Concepts
- Verify constant :
np.diff(sequence)should all be equal. - : decreasing sequence (depreciation, declining metrics).
- : constant sequence.
- Linear in : is an affine function of with slope .
- np.linspace:
np.linspace(a, b, n)gives arithmetic terms, . - np.arange:
np.arange(a, b, step)uses explicit .
Step-by-step calculation (tiny example)
Sequence: 3, 7, 11, 15, ... Find .
Step 1: Identify parameters , (verify: )
Step 2: Apply formula
Step 3: Check
Code examples
Beginner example (Python)
import numpy as np
def arithmetic_nth_term(a: float, d: float, n: int | np.ndarray) -> float | np.ndarray:
"""n-th term: u_n = a + (n-1)*d."""
return a + (n - 1) * d # Sequence 3, 7, 11, ...
a_val, d_val = 3.0, 4.0
print("Arithmetic sequence (a=3, d=4):")
for n in [1, 2, 5, 10, 20]:
print(f" u_{n:2d} = {arithmetic_nth_term(a_val, d_val, n):.1f}") # Straight-line depreciation
print("\nDepreciation (a=50000, d=-5000):")
for year in [1, 3, 5, 10]:
print(f" Year {year:2d}: EUR {arithmetic_nth_term(50_000, -5_000, year):>9,.0f}") # np.linspace produces arithmetic sequences
x_values = np.linspace(0.0, 1.0, 11)
print(f"\nnp.linspace(0,1,11): {x_values}")
print(f"d = {x_values[1] - x_values[0]:.2f}, all equal: {np.allclose(np.diff(x_values), 0.1)}")Beginner example (R)
arithmetic_nth_term <- function(a, d, n) a + (n - 1) * d
a_val <- 3; d_val <- 4
cat("Arithmetic sequence (a=3, d=4):\n")
for (n in c(1, 2, 5, 10, 20)) { cat(sprintf(" u_%d = %.1f\n", n, arithmetic_nth_term(a_val, d_val, n)))
}
cat("\nDepreciation (a=50000, d=-5000):\n")
for (year in c(1, 3, 5, 10)) { cat(sprintf(" Year %2d: EUR %9.0f\n", year, arithmetic_nth_term(50000, -5000, year)))
}Professional example (Python)
"""
Arithmetic sequences in DA/DS: cohort offsets, feature bins, depreciation.
"""
import numpy as np
import pandas as pd
def arithmetic_nth_term(a: float, d: float, n: int | np.ndarray) -> float | np.ndarray:
"""u_n = a + (n-1)*d."""
return a + (n - 1) * d # 1. Weekly cohort follow-up offsets: weeks 1, 8, 15, 22, ... (d=7)
cohort_weeks = arithmetic_nth_term(1, 7, np.arange(1, 9)).astype(int)
print(f"Cohort follow-up weeks: {cohort_weeks}") # 2. Age feature bins for marketing model
age_edges = np.linspace(18, 68, 6).astype(int)
print(f"Age bin edges: {age_edges}") # 3. Depreciation register
assets = [("Server rack", 80_000, -8_000, 10), ("Office fit-out", 120_000, -10_000, 12)]
records = []
for name, a, d, life in assets:
for yr in range(1, life + 1):
records.append({"asset": name, "year": yr, "book_value": arithmetic_nth_term(a, d, yr)})
df = pd.DataFrame(records)
print("\nDepreciation (selected years):")
print(df[df["year"].isin([1, 3, 5, 10])].to_string(index=False))Source: MFB p. 160