BRAGA

02 Writing02-02 Notes02-02-017

Product

Published 16 Apr 20266 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\prod_{i=1}^n x_i = x_1 \cdot x_2 \cdot \dots \cdot x_n
(1)

Deep Breakdown

What it tells me (Situation Awareness): ∏i=1nxi\prod_{i=1}^{n} x_i is the product notation (capital pi notation): a compact way to write "multiply all these terms together." It is the multiplicative counterpart of Σ\Sigma (summation). In DA/DS you encounter ∏\prod in the likelihood function for statistical models (the joint probability of all observations is the product of individual probabilities under the independence assumption), in the definition of factorial (n!=∏k=1nkn! = \prod_{k=1}^{n} k), and in generative probability models.

Flowchart

NoYesProductnotation: prodfrom i=1 to n ofx_iInitialize result =1 (multiplicativeidentity)Set i = 1Multiply result byx_ii == n?i = i + 1Return result =x_1 * x_2 * ... *x_n

Real-world use

Where it is used

Likelihood functions in statistical modeling (the probability of the entire dataset given model parameters), computing joint probabilities of independent events, Naive Bayes classifier (product of per-feature likelihoods), and in the chain rule of probability.

Problem it solves

A dataset with nn observations, each with probability pip_i under the model, has a joint probability P(data)=p1×p2×⋯×pnP(\text{data}) = p_1 \times p_2 \times \cdots \times p_n. Writing out all nn terms with explicit multiplication dots is impractical for n=10,000n = 10{,}000. ∏\prod compresses this to one symbol.

How it solves the problem

∏i=1npi\prod_{i=1}^{n} p_i says "multiply p1,p2,…,pnp_1, p_2, \ldots, p_n together." The start index, end index, and formula for each factor are all encoded in the notation. This is the exact structure of the likelihood function.

Example in a business

Maximum Likelihood Estimation (MLE) for a Bernoulli model (coin flips, binary outcomes).

The likelihood function is:

L(θ)=∏i=1nθyi(1−θ)1−yiL(\theta) = \prod_{i=1}^{n} \theta^{y_i} (1-\theta)^{1-y_i}
(2)

where yi∈{0,1}y_i \in \{0, 1\} are observations and θ\theta is the probability of success. You maximize L(θ)L(\theta) over θ\theta to find the best-fit parameter. In practice you maximize ln⁡L(θ)=∑i=1n[yiln⁡θ+(1−yi)ln⁡(1−θ)]\ln L(\theta) = \sum_{i=1}^{n} [y_i \ln\theta + (1-y_i)\ln(1-\theta)] instead (sum is easier than product).

The formula, piece by piece

Breaking the notation:

  • ∏\prod: uppercase Greek letter Pi. The "P" stands for "product" (just as Σ\Sigma stands for "sum").
  • i=1i = 1: start the index ii at 1 (lower bound, written below the ∏\prod).
  • nn: stop the index at nn (upper bound, written above the ∏\prod).
  • xix_i: the formula to evaluate at each value of ii (the factor).

Full expansion: ∏i=1nxi=x1×x2×x3×⋯×xn\prod_{i=1}^{n} x_i = x_1 \times x_2 \times x_3 \times \cdots \times x_n Related: ∏i=10\prod_{i=1}^{0} (empty product) =1= 1 by convention (the multiplicative identity, just as ∑i=10=0\sum_{i=1}^{0} = 0 is the additive identity). Log-product rule: ln⁡(∏i=1nxi)=∑i=1nln⁡(xi)\ln\left(\prod_{i=1}^{n} x_i\right) = \sum_{i=1}^{n} \ln(x_i). This is why likelihood is almost always maximized in log-space.

The formula in words

"∏i=1nxi\prod_{i=1}^{n} x_i means: start with 1, then multiply by x1x_1, then multiply by x2x_2, continuing until you multiply by xnx_n. The final result is the product of all nn terms." Step-by-step unrolled: ∏i=14xi=x1×x2×x3×x4\prod_{i=1}^{4} x_i = x_1 \times x_2 \times x_3 \times x_4.

Critical Concepts

  1. Starts with multiplicative identity 1: just as a running sum starts at 0, a running product starts at 1. Never start at 0 (you would get 0 for everything).
  2. Log trick: ∏xi\prod x_i can become extremely small (numerical underflow) when nn is large and xi<1x_i < 1. Take ln⁡\ln to convert to ∑ln⁡(xi)\sum \ln(x_i), which avoids underflow. This is why log-likelihood is standard in ML.
  3. Independent events: P(A∩B)=P(A)⋅P(B)P(A \cap B) = P(A) \cdot P(B) only if AA and BB are independent. The likelihood ∏pi\prod p_i assumes observations are independent and identically distributed (i.i.d.).
  4. Factorial as product: n!=∏k=1nkn! = \prod_{k=1}^{n} k.
  5. Any zero factor kills the product: if any xi=0x_i = 0, then ∏xi=0\prod x_i = 0.

In probability, a single impossible event makes the joint probability zero.

Step-by-step calculation (tiny example)

Input: compute ∏i=14xi\prod_{i=1}^{4} x_i where {xi}={2,3,5,4}\{x_i\} = \{2, 3, 5, 4\}.

Step 1: Initialize the running product result=1\text{result} = 1 (multiplicative identity).

Step 2: Multiply each term result=1×2=2\text{result} = 1 \times 2 = 2 result=2×3=6\text{result} = 2 \times 3 = 6 result=6×5=30\text{result} = 6 \times 5 = 30 result=30×4=120\text{result} = 30 \times 4 = 120

Step 3: Read the result ∏i=14xi=120\prod_{i=1}^{4} x_i = 120. Check: this is also 4!=244! = 24... wait: 2×3×5×4=1202 \times 3 \times 5 \times 4 = 120, which happens to equal 5!5! coincidentally. Read as: "the product of 2, 3, 5, and 4 is 120."

Code examples

Beginner example (Python)

python
import math
from functools import reduce   # Product notation using math.prod() (Python 3.8+)
values = [2, 3, 5, 4]   # Method 1: math.prod (cleanest)
result = math.prod(values)
print(result)   # 120 # Method 2: functools.reduce with multiplication
result2 = reduce(lambda acc, x: acc * x, values, 1)
print(result2)   # 120 # Method 3: loop (explicit, shows the logic)
result3 = 1   # start with multiplicative identity
for x in values:
    result3 *= x
print(result3)   # 120 # Factorial as a product
n = 5
n_factorial = math.prod(range(1, n + 1))
print(n_factorial)   # 120 = 5!

Beginner example (R)

r
values <- c(2, 3, 5, 4)  # prod() is base R
result <- prod(values)
print(result)  # 120 # Factorial as product
n <- 5
n_factorial <- prod(1:n)
print(n_factorial)  # 120 # Compare with R's factorial()
factorial(5)  # 120 (same)

Professional example (Python)

python
import numpy as np   # Scenario: computing log-likelihood for a Bernoulli model (coin flips / binary outcomes)
# Demonstrates why log of product = sum of logs is critical for numerical stability
# Observations: 1000 coin flips, with theta = 0.6 (true probability of heads)
np.random.seed(42)
theta_true = 0.6
y = np.random.binomial(1, theta_true, size=1000)   # 0s and 1s

def bernoulli_log_likelihood(y: np.ndarray, theta: float) -> float:
    """ Log-likelihood for Bernoulli model. L(theta) = prod(theta^y_i * (1-theta)^(1-y_i)) ln L(theta) = sum(y_i * ln(theta) + (1-y_i) * ln(1-theta)) Works in log-space to avoid underflow. """
    epsilon = 1e-12
    theta_safe = np.clip(theta, epsilon, 1 - epsilon)
    return np.sum(y * np.log(theta_safe) + (1 - y) * np.log(1 - theta_safe))   # Evaluate log-likelihood over a range of theta values
theta_values = np.linspace(0.01, 0.99, 100)
log_likelihoods = [bernoulli_log_likelihood(y, t) for t in theta_values]   # MLE: find the theta that maximizes log-likelihood
best_theta = theta_values[np.argmax(log_likelihoods)]
print(f"True theta: {theta_true}")
print(f"MLE theta: {best_theta:.3f}")
print(f"Mean of y (direct MLE): {y.mean():.3f}")   # Closed-form MLE = sample mean
# Log-likelihood is the sum (not product) version of the likelihood
# Product would underflow to 0.0 for n=1000 terms each < 1

Professional example (R)

r
# Bernoulli log-likelihood: log(prod(...)) = sum(log(...)) for numerical stability
set.seed(42)
theta_true <- 0.6
y <- rbinom(1000, 1, theta_true)
bernoulli_log_likelihood <- function(y, theta) { theta_safe <- pmin(pmax(theta, 1e-12), 1 - 1e-12) sum(y * log(theta_safe) + (1 - y) * log(1 - theta_safe))
}
theta_values <- seq(0.01, 0.99, length.out = 100)
log_likelihoods <- sapply(theta_values, function(t) bernoulli_log_likelihood(y, t))
best_theta <- theta_values[which.max(log_likelihoods)]
cat("True theta: ", theta_true, "\n")
cat(sprintf("MLE theta: %.3f\n", best_theta))
cat("Mean of y (direct MLE):", mean(y), "\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