BRAGA

02 Writing02-02 Notes02-02-321

Arithmetic n-th term

Published 16 Apr 20264 min read
Contents
  1. 01Deep Breakdown
  2. 02Flowchart
  3. 03Real-world use
  4. 04The formula, piece by piece
  5. 05The formula in words
  6. 06Critical Concepts
  7. 07Step-by-step calculation (tiny example)
  8. 08Code examples
un=a+(n−1)du_n = a + (n-1)d
(1)

Deep Breakdown

What it tells me (Situation Awareness): An arithmetic sequence has a constant difference dd between consecutive terms. The formula un=a+(n−1)du_n = a + (n-1)d gives the nn-th term in O(1)O(1) time from aa, dd, and nn. 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 unu_n vs. nn gives a straight line with slope dd — it is the discrete analogue of f(x)=a+dxf(x) = a + dx.

Flowchart

Given: first terma, commondifference d,position nu_n = a +(n-1)*dn=1: u_1 = an=2: u_2 = a + dn=k: u_k = a +(k-1)*dFind d from twoknown terms: d= (u_n - u_m) /(n - m)Find n from u_n:n = (u_n - a)/d +1

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 nn-th value in a linearly growing/declining sequence without iterating all prior terms.

How it solves the problem

Start at aa, add dd exactly (n−1)(n-1) times: un=a+(n−1)du_n = a + (n-1)d.

Example in a business

Straight-line depreciation: asset purchased for EUR 50,000 (a=50,000a = 50{,}000, d=−5,000d = -5{,}000/yr). Book value in year nn: un=55,000−5,000nu_n = 55{,}000 - 5{,}000n. At year 10: u10=5,000u_{10} = 5{,}000 (salvage value).

The formula, piece by piece

un=a+(n−1)du_n = a + (n-1)d
(2)

Each symbol:

  • unu_n: the nn-th term
  • aa: the first term (u1u_1)
  • nn: position in sequence (n≥1n \geq 1, 1-based)
  • dd: common difference; d=uk+1−ukd = u_{k+1} - u_k for any kk Find dd: d=un−umn−md = \dfrac{u_n - u_m}{n - m} Find nn: n=un−ad+1n = \dfrac{u_n - a}{d} + 1 0-based (Python indexing): u[i]=a+i⋅du[i] = a + i \cdot d for i=0,1,2,…i = 0, 1, 2, \ldots

The formula in words

"Start at aa. Take (n−1)(n-1) equal steps of size dd. You land on a+(n−1)da + (n-1)d."

Critical Concepts

  • Verify constant dd: np.diff(sequence) should all be equal.
  • d<0d < 0: decreasing sequence (depreciation, declining metrics).
  • d=0d = 0: constant sequence.
  • Linear in nn: unu_n is an affine function of nn with slope dd.
  • np.linspace: np.linspace(a, b, n) gives nn arithmetic terms, d=(b−a)/(n−1)d = (b-a)/(n-1).
  • np.arange: np.arange(a, b, step) uses explicit dd.

Step-by-step calculation (tiny example)

Sequence: 3, 7, 11, 15, ... Find u20u_{20}.

Step 1: Identify parameters a=3a = 3, d=7−3=4d = 7 - 3 = 4 (verify: 11−7=411-7=4)

Step 2: Apply formula u20=3+(20−1)(4)=3+76=79u_{20} = 3 + (20-1)(4) = 3 + 76 = 79

Step 3: Check u20−u1=76=19×4=(20−1)du_{20} - u_1 = 76 = 19 \times 4 = (20-1)d

Code examples

Beginner example (Python)

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)

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)

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

#calculus#series-and-transforms#arithmetic-and-geometric-progressions

Keyboard shortcuts

Single keys, ignored while typing in a field or with Cmd, Ctrl or Alt held.

0
Home
1 2 3 4
Work, Writing, Tools, About
j / k
Next / previous section on this page
n / p
Next / previous project or essay
u
Up one level
l
Deutsch
t
Light or dark theme
?
This list
Esc
Close