BRAGA

02 Writing02-02 Notes02-02-019

Summation

Published 16 Apr 20267 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
∑i=1nxi=x1+x2+⋯+xn\sum_{i=1}^n x_i = x_1 + x_2 + \dots + x_n
(1)

Deep Breakdown

What it tells me (Situation Awareness): ∑i=1nxi\sum_{i=1}^{n} x_i is the summation notation (capital sigma notation): a compact way to write "add all these terms together." It is one of the most frequently used symbols in statistics, ML, and data analysis. Every average, every loss function, every error metric you will ever compute involves ∑\sum. It is the mathematical skeleton behind sum(), np.sum(), mean(), np.dot(), and almost every aggregation operation in data work.

Flowchart

NoYesSummation:sum from i=1 ton of x_iInitializeaccumulator = 0(additiveidentity)Set i = 1Add x_i toaccumulatori == n?i = i + 1Returnaccumulator =x_1 + x_2 + ... +x_n

Real-world use

Where it is used

Every metric in statistics and ML: mean (xˉ=1n∑xi\bar{x} = \frac{1}{n}\sum x_i), variance (σ2=1n∑(xi−xˉ)2\sigma^2 = \frac{1}{n}\sum(x_i - \bar{x})^2), MSE (1n∑(yi−y^i)2\frac{1}{n}\sum(y_i - \hat{y}_i)^2), MAE (1n∑∣yi−y^i∣\frac{1}{n}\sum|y_i - \hat{y}_i|), cross-entropy loss (−∑yiln⁡y^i-\sum y_i \ln \hat{y}_i), and dot products (u⋅v=∑iuivi\mathbf{u} \cdot \mathbf{v} = \sum_i u_i v_i).

Problem it solves

When you have nn numbers and want to add them all, writing x1+x2+x3+⋯+xnx_1 + x_2 + x_3 + \cdots + x_n for n=10,000n = 10{,}000 is impractical. ∑i=1nxi\sum_{i=1}^{n} x_i encodes the entire addition in one compact expression that works for any nn.

How it solves the problem

The sigma notation specifies the start index, end index, and the formula to evaluate at each step. It maps directly to a for loop in code: initialize an accumulator to 0, add each term, return the final total.

Example in a business

The mean absolute error (MAE) is: MAE=1n∑i=1n∣yi−y^i∣\text{MAE} = \frac{1}{n} \sum_{i=1}^{n} |y_i - \hat{y}_i|. In a report for a 10,000-row test set, this notation tells a reader: "sum the absolute errors for all 10,000 observations, then divide by 10,000." The ∑\sum compresses 10,000 explicit additions into one symbol.

The formula, piece by piece

Breaking the notation:

  • ∑\sum: uppercase Greek letter Sigma. Stands for "Sum" (S in Greek). The "adding" counterpart of ∏\prod (product).
  • i=1i = 1: the index ii starts at 1 (lower limit, written below ∑\sum). The index variable is a dummy: you could use jj, kk, or any letter.
  • nn: the index ii runs up to and including nn (upper limit, written above ∑\sum).
  • xix_i: the expression evaluated at each value of ii (the "summand"). Full expansion: ∑i=1nxi=x1+x2+x3+⋯+xn\sum_{i=1}^{n} x_i = x_1 + x_2 + x_3 + \cdots + x_n Special cases:
  • ∑i=10\sum_{i=1}^{0} (empty sum) =0= 0 by convention (additive identity).
  • ∑i=1nc=c⋅n\sum_{i=1}^{n} c = c \cdot n (a constant summed nn times equals n×cn \times c).
  • ∑i=1n(axi+byi)=a∑i=1nxi+b∑i=1nyi\sum_{i=1}^{n} (ax_i + by_i) = a\sum_{i=1}^{n} x_i + b\sum_{i=1}^{n} y_i (linearity of summation).

The formula in words

"∑i=1nxi\sum_{i=1}^{n} x_i means: let ii take values 1, 2, 3, ..., up to nn. For each value of ii, compute xix_i. Then add all those computed values together." Spoken: "sum of xix_i for ii from 1 to nn", or "sum over all ii of xix_i." The formula inside can be anything: ∑i=1ni=1+2+⋯+n=n(n+1)2\sum_{i=1}^{n} i = 1 + 2 + \cdots + n = \frac{n(n+1)}{2} (Gauss's formula). ∑i=1ni2=n(n+1)(2n+1)6\sum_{i=1}^{n} i^2 = \frac{n(n+1)(2n+1)}{6}.

Critical Concepts

  1. Index is a dummy variable: ∑i=1nxi=∑j=1nxj=∑k=1nxk\sum_{i=1}^{n} x_i = \sum_{j=1}^{n} x_j = \sum_{k=1}^{n} x_k. The letter used does not matter; only the range and formula matter.
  2. Linearity: ∑(axi+b)=a∑xi+nb\sum(a x_i + b) = a \sum x_i + nb. You can pull constants out. This is constantly used to simplify formulas.
  3. Double summation: ∑i=1m∑j=1naij\sum_{i=1}^{m} \sum_{j=1}^{n} a_{ij} iterates over all pairs (i,j)(i, j). This is what happens in matrix operations.
  4. Mean formula: xˉ=1n∑i=1nxi\bar{x} = \frac{1}{n}\sum_{i=1}^{n} x_i. Every use of mean in statistics is this formula.
  5. Vectorized code: np.sum(x) or sum(x) in Python, sum(x) in R, implement ∑\sum directly.

For large arrays, vectorized operations are orders of magnitude faster than Python loops.

Step-by-step calculation (tiny example)

Input: {xi}={3,7,2,8,5}\{x_i\} = \{3, 7, 2, 8, 5\}. Compute ∑i=15xi\sum_{i=1}^{5} x_i and xˉ\bar{x}.

Step 1: List the terms and add them sequentially x1=3x_1 = 3: running total = 3 x2=7x_2 = 7: running total = 3 + 7 = 10 x3=2x_3 = 2: running total = 10 + 2 = 12 x4=8x_4 = 8: running total = 12 + 8 = 20 x5=5x_5 = 5: running total = 20 + 5 = 25

Step 2: Record the sum ∑i=15xi=25\sum_{i=1}^{5} x_i = 25

Step 3: Compute the mean xˉ=∑xin=255=5\bar{x} = \frac{\sum x_i}{n} = \frac{25}{5} = 5

Code examples

Beginner example (Python)

python
# Summation using Python
x = [3, 7, 2, 8, 5]

# Method 1: built-in sum()
total = sum(x)
print(f"Sum: {total}")   # 25

# Method 2: explicit loop (shows the sigma logic)
total_loop = 0   # initialize accumulator to 0 (additive identity)
for xi in x:
    total_loop += xi
print(f"Sum (loop): {total_loop}")   # 25

# Mean
n = len(x)
mean = sum(x) / n
print(f"Mean: {mean}")   # 5.0

# Variance: sum((x_i - mean)^2) / n
variance = sum((xi - mean)**2 for xi in x) / n
print(f"Variance: {variance}")   # 5.2

Beginner example (R)

r
x <- c(3, 7, 2, 8, 5)  # sum() is base R
total <- sum(x)
print(total)  # 25

# Mean
mean_val <- sum(x) / length(x)
print(mean_val)  # 5 (same as mean(x))

# Variance using summation
n <- length(x)
variance <- sum((x - mean_val)^2) / n  # vectorized: R subtracts mean from all elements
print(variance)  # 5.2 (population variance)

Professional example (Python)

python
import numpy as np

# Scenario: compute multiple regression metrics from scratch using summation notation
# Demonstrates how every metric is a specific use of sum
y_true = np.array([120.0, 90.0, 75.0, 200.0, 55.0, 140.0, 95.0, 180.0])
y_pred = np.array([110.0, 95.0, 70.0, 190.0, 60.0, 135.0, 100.0, 185.0])
n = len(y_true)

# Mean: (1/n) * sum(y_i)
mean_true = (1/n) * np.sum(y_true)

# MAE: (1/n) * sum(|y_i - y_hat_i|)
mae = (1/n) * np.sum(np.abs(y_true - y_pred))

# MSE: (1/n) * sum((y_i - y_hat_i)^2)
mse = (1/n) * np.sum((y_true - y_pred)**2)

# RMSE: sqrt(MSE)
rmse = np.sqrt(mse)

# R-squared: 1 - sum((y_i - y_hat_i)^2) / sum((y_i - mean_true)^2)
ss_residual = np.sum((y_true - y_pred)**2)
ss_total = np.sum((y_true - mean_true)**2)
r_squared = 1 - (ss_residual / ss_total)
print(f"MAE: {mae:.4f}")
print(f"MSE: {mse:.4f}")
print(f"RMSE: {rmse:.4f}")
print(f"R-squared: {r_squared:.4f}")
print("\nEvery metric above is a specific form of summation (sigma notation).")

Professional example (R)

r
# Regression metrics from scratch using summation (sigma)
y_true <- c(120, 90, 75, 200, 55, 140, 95, 180)
y_pred <- c(110, 95, 70, 190, 60, 135, 100, 185)
n <- length(y_true)
mean_true <- (1/n) * sum(y_true)
mae <- (1/n) * sum(abs(y_true - y_pred))
mse <- (1/n) * sum((y_true - y_pred)^2)
rmse <- sqrt(mse)
ss_residual <- sum((y_true - y_pred)^2)
ss_total <- sum((y_true - mean_true)^2)
r_squared <- 1 - (ss_residual / ss_total)
cat(sprintf("MAE: %.4f\n", mae))
cat(sprintf("MSE: %.4f\n", mse))
cat(sprintf("RMSE: %.4f\n", rmse))
cat(sprintf("R-squared: %.4f\n", r_squared))
cat("\nEvery metric above is a specific form of summation (sigma notation).\n")

Source: AIO p. 44 of 286

#foundations#maths-symbols#algebra

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