BRAGA

02 Writing02-02 Notes02-02-050

Multiplicative Inverse

Published 16 Apr 20268 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
a⋅1a=1a \cdot \frac{1}{a} = 1
(1)

(for a≠0a \neq 0)

Deep Breakdown

What it tells me (Situation Awareness): The multiplicative inverse (or reciprocal) of aa is 1a\frac{1}{a}: the unique number that, when multiplied by aa, produces 1 (the multiplicative identity). Every non-zero real number has exactly one multiplicative inverse. In DA/DS, this property is the foundation of: division (dividing by aa = multiplying by 1a\frac{1}{a}), matrix inversion (A⋅A−1=IA \cdot A^{-1} = I, the matrix analog), normalization (multiplying by 1n\frac{1}{n} to compute means), and deriving the OLS normal equations via (XTX)−1(X^T X)^{-1}.

Flowchart

Yes: 1/a is the correctinverseNo: wrong inverseYes: no inverse existsGiven a ≠ 0Findmultiplicativeinverse: 1/aCompute a ×(1/a)Result = 1?a · (1/a) = 1confirmedError: recheckDivision: b/a = b× (1/a)Matrixextension: A ·A⁻¹ = Ia = 0?1/0 is undefined→ZeroDivisionError

Real-world use

Where it is used

Normalization by sample size (1n∑xi=xˉ\frac{1}{n} \sum x_i = \bar{x}), computing proportions and rates (CTR = clicks × 1impressions\frac{1}{\text{impressions}}), matrix inversion for solving linear systems (A−1bA^{-1}\mathbf{b}), probability distributions (normalization constants ensure probabilities sum to 1), and feature standardization (x−μσ=(x−μ)⋅σ−1\frac{x - \mu}{\sigma} = (x - \mu) \cdot \sigma^{-1}).

Problem it solves

The mean is defined as xˉ=1n∑xi\bar{x} = \frac{1}{n}\sum x_i. Dividing by nn is multiplying by 1n\frac{1}{n}, the multiplicative inverse of nn. Without the multiplicative inverse, division would have no algebraic meaning. In matrix algebra, solving Ax=bA\mathbf{x} = \mathbf{b} requires x=A−1b\mathbf{x} = A^{-1}\mathbf{b} — the matrix inverse, which is the matrix-analog of 1a\frac{1}{a}.

How it solves the problem

a⋅1a=1a \cdot \frac{1}{a} = 1 means 1a\frac{1}{a} "undoes" aa. In a linear system: multiplying both sides of a⋅x=ba \cdot x = b by 1a\frac{1}{a} gives x=bax = \frac{b}{a}. For matrices: Ax=b⇒A−1Ax=A−1b⇒Ix=A−1b⇒x=A−1bA\mathbf{x} = \mathbf{b} \Rightarrow A^{-1}A\mathbf{x} = A^{-1}\mathbf{b} \Rightarrow I\mathbf{x} = A^{-1}\mathbf{b} \Rightarrow \mathbf{x} = A^{-1}\mathbf{b}.

Example in a business

Click-through rate (CTR): CTR=clicksimpressions=clicks×1impressions\text{CTR} = \frac{\text{clicks}}{\text{impressions}} = \text{clicks} \times \frac{1}{\text{impressions}}. Division is multiplication by the inverse. In SQL: clicks / impressions AS ctr. If impressions = 0, the division is undefined (no inverse exists for 0), so you need NULLIF(impressions, 0) to guard against division by zero.

The formula, piece by piece

Breaking the notation:

  • aa: any non-zero real number.
  • 1a\frac{1}{a}: the reciprocal (multiplicative inverse) of aa.
  • a⋅1aa \cdot \frac{1}{a}: multiplying aa by its reciprocal.
  • =1= 1: the result is the multiplicative identity.
  • "for a≠0a \neq 0": the inverse does not exist when a=0a = 0 (division by zero is undefined).

Formal statement: ∀a∈R∖{0}, a⋅a−1=a−1⋅a=1\forall a \in \mathbb{R} \setminus \{0\},\ a \cdot a^{-1} = a^{-1} \cdot a = 1. Matrix extension: for an invertible (non-singular) square matrix AA: A⋅A−1=A−1⋅A=IA \cdot A^{-1} = A^{-1} \cdot A = I.

Conditions for matrix invertibility:

  • Square matrix (n×nn \times n).
  • Non-singular: det⁡(A)≠0\det(A) \neq 0.
  • Full rank: rank(A)=n\text{rank}(A) = n.
  • No zero eigenvalues.

The formula in words

"Every number (except zero) has a reciprocal: the number you multiply it by to get 1. Division is just multiplying by the reciprocal. In matrices, the inverse matrix plays the same role: multiply a matrix by its inverse to get the identity (the matrix version of 1). Watch out — just as you cannot divide by zero, you cannot invert a singular matrix."

Critical Concepts

  1. Division by zero guard: a / 0 raises ZeroDivisionError in Python. In SQL, 1 / 0 raises a division error unless guarded with NULLIF. In pandas, 0 / 0 = NaN for floats (IEEE 754). Always guard denominators: denominator = max(count, 1) or df['rate'] = df['clicks'] / df['impressions'].replace(0, np.nan).
  2. Matrix inverse is expensive: A−1A^{-1} for an n×nn \times n matrix is O(n3)O(n^3). Never compute np.linalg.inv(A) @ b — use np.linalg.solve(A, b) instead, which is faster and numerically stable (it uses LU decomposition).
  3. OLS normal equations: β^=(XTX)−1XTy\hat{\boldsymbol{\beta}} = (X^T X)^{-1} X^T \mathbf{y}. The (XTX)−1(X^T X)^{-1} is the matrix inverse of XTXX^T X. If XX has multicollinear columns, XTXX^T X is singular (no inverse). Ridge regression adds λI\lambda I to ensure invertibility: (XTX+λI)−1(X^T X + \lambda I)^{-1} always exists for λ>0\lambda > 0.
  4. Normalization constant: in probability, the PDF normalization condition ∫f(x) dx=1\int f(x)\, dx = 1 is enforced by multiplying by 1Z\frac{1}{Z} where Z=∫g(x) dxZ = \int g(x)\, dx is the partition function. 1Z\frac{1}{Z} is the multiplicative inverse of ZZ.

Step-by-step calculation (tiny example)

Task: verify multiplicative inverse for scalars, then solve a simple linear system.

Step 1: Scalar reciprocal check a=4a = 4: 14=0.25\frac{1}{4} = 0.25. 4×0.25=14 \times 0.25 = 1. Confirmed. a=−2a = -2: 1−2=−0.5\frac{1}{-2} = -0.5. (−2)×(−0.5)=1(-2) \times (-0.5) = 1. Confirmed.

Step 2: Solve 3x=123x = 12 using multiplicative inverse Multiply both sides by 13\frac{1}{3}: x=12×13=4x = 12 \times \frac{1}{3} = 4. Check: 3×4=123 \times 4 = 12. Correct.

Step 3: 2×2 matrix inverse A=[2153]A = \begin{bmatrix}2 & 1 \\ 5 & 3\end{bmatrix}. det⁡(A)=2⋅3−1⋅5=1\det(A) = 2\cdot3 - 1\cdot5 = 1. A−1=11[3−1−52]=[3−1−52]A^{-1} = \frac{1}{1}\begin{bmatrix}3 & -1 \\ -5 & 2\end{bmatrix} = \begin{bmatrix}3 & -1 \\ -5 & 2\end{bmatrix}. Check: A⋅A−1=[2⋅3+1⋅(−5)2⋅(−1)+1⋅25⋅3+3⋅(−5)5⋅(−1)+3⋅2]=[1001]=IA \cdot A^{-1} = \begin{bmatrix}2\cdot3+1\cdot(-5) & 2\cdot(-1)+1\cdot2 \\ 5\cdot3+3\cdot(-5) & 5\cdot(-1)+3\cdot2\end{bmatrix} = \begin{bmatrix}1 & 0 \\ 0 & 1\end{bmatrix} = I. Confirmed.

Code examples

Beginner example (Python)

python
# Multiplicative inverse: a * (1/a) = 1
values = [4, -2, 0.5, 100, -0.25]
print("Verifying a × (1/a) == 1 (for a ≠ 0):")
for a in values:
    inv_a = 1 / a
    result = a * inv_a
    print(f" {a} × (1/{a}) = {a} × {inv_a:.4f} = {result:.6f} | ≈ 1: {abs(result - 1) < 1e-10}")

# Division by zero guard
denominators = [10, 5, 0, 3, 0, 8]
numerators = [100, 50, 999, 30, 1, 80]
print("\nSafe division with zero guard:")
for num, den in zip(numerators, denominators):
    safe_den = den if den != 0 else None
    rate = num / safe_den if safe_den is not None else float('nan')
    print(f" {num} / {den} → {rate}")

# Matrix inverse via np.linalg.solve (preferred over inv)
import numpy as np
A = np.array([[2.0, 1.0], [5.0, 3.0]])
b = np.array([8.0, 19.0])
# Preferred: solve(A, b) — do NOT use inv(A) @ b
x = np.linalg.solve(A, b)
print(f"\nSolving Ax=b: A={A.tolist()}, b={b.tolist()}")
print(f"Solution x = {x}")
print(f"Verification A@x = {A @ x} (should be {b})")

Beginner example (R)

r
# Multiplicative inverse: a * (1/a) = 1
values <- c(4, -2, 0.5, 100, -0.25)
cat("Verifying a × (1/a) == 1:\n")
for (a in values) {
  result <- a * (1/a)
  cat(sprintf(" %.3f × (1/%.3f) = %.6f | ≈ 1: %s\n", a, a, result, abs(result - 1) < 1e-10))
}

# Matrix inverse
A <- matrix(c(2, 5, 1, 3), nrow=2)
b <- c(8, 19)
# solve(A, b) is preferred over solve(A) %*% b
x <- solve(A, b)
cat(sprintf("\nSolution x = (%.1f, %.1f)\n", x[1], x[2]))
cat("Verification A %*% x =", as.vector(A %*% x), "\n")
cat("Should equal b =", b, "\n")

# Safe rate calculation
safe_rate <- function(num, den) ifelse(den == 0, NA_real_, num / den)
cat("\nSafe CTR:", safe_rate(c(100, 50, 0, 30), c(10, 0, 5, 0)), "\n")

Professional example (Python)

python
import numpy as np
import pandas as pd

# Scenario: OLS normal equations with invertibility check
# + practical rate computation with zero-denomination guard
np.random.seed(42)
n, p = 300, 3

# Design matrix with intercept
X = np.column_stack([np.ones(n), np.random.randn(n, p - 1)])
true_beta = np.array([5.0, 2.0, -1.5])
y = X @ true_beta + np.random.normal(0, 1.0, n)

# OLS: beta_hat = (X'X)^{-1} X'y
XtX = X.T @ X
det_XtX = np.linalg.det(XtX)
print("OLS Normal Equations: beta_hat = (X'X)^{-1} X'y")
print("=" * 48)
print(f" det(X'X) = {det_XtX:.2f} ({'invertible' if abs(det_XtX) > 1e-10 else 'SINGULAR — no inverse'})")

# Solve (never use inv(XtX) @ XtX @ b directly)
beta_hat = np.linalg.solve(XtX, X.T @ y)
print(f" True beta: {true_beta}")
print(f" Estimated beta: {beta_hat.round(4)}")
print()

# Ridge: add λI to guarantee invertibility
lambda_vals = [0.0, 0.01, 0.1, 1.0]
print("Ridge (X'X + λI)^{-1} X'y — λI ensures invertibility:")
for lam in lambda_vals:
    reg_matrix = XtX + lam * np.eye(p)
    det_reg = np.linalg.det(reg_matrix)
    beta_ridge = np.linalg.solve(reg_matrix, X.T @ y)
    mse = np.mean((y - X @ beta_ridge) ** 2)
    print(f" λ={lam:.2f}: det={det_reg:.1f}, beta={beta_ridge.round(3)}, MSE={mse:.4f}")
print()

# Practical: campaign rate metrics with zero-guard
campaigns = pd.DataFrame({
    "campaign": ["A", "B", "C", "D", "E"],
    "impressions": [10_000, 5_000, 0, 8_500, 0],
    "clicks": [320, 150, 50, 0, 0],
    "conversions": [45, 20, 3, 0, 0],
})

# Safe division: 1/impressions guarded against 0
campaigns["ctr"] = (
    campaigns["clicks"] / campaigns["impressions"].replace(0, np.nan)
).round(4)
campaigns["cvr"] = (
    campaigns["conversions"] / campaigns["clicks"].replace(0, np.nan)
).round(4)
print("Campaign Rates (safe inverse: guard against 0 denominator):")
print(campaigns[["campaign", "impressions", "clicks", "ctr", "cvr"]].to_string(index=False))

Professional example (R)

r
# Campaign rates: CTR = clicks/impressions, CVR = conversions/clicks (guard 0)
campaigns <- data.frame(
  campaign = c("A", "B", "C"),
  impressions = c(1000, 0, 500),
  clicks = c(50, 10, 25),
  conversions = c(5, 1, 3)
)
campaigns$ctr <- round(campaigns$clicks / replace(campaigns$impressions, campaigns$impressions == 0, NA), 4)
campaigns$cvr <- round(campaigns$conversions / replace(campaigns$clicks, campaigns$clicks == 0, NA), 4)
cat("Campaign Rates (safe inverse: guard against 0 denominator):\n")
print(campaigns[, c("campaign", "impressions", "clicks", "ctr", "cvr")])

Source: 1300 p. 16

#foundations#number-sets-and-logic#basic-identities

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