BRAGA

02 Writing02-02 Notes02-02-265

Standard Limit (Exponential)

Published 16 Apr 202610 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
lim⁡x→0ex−1x=1\lim_{x \to 0} \frac{e^x - 1}{x} = 1
(1)

Deep Breakdown

What it tells me (Situation Awareness): This limit is the derivative of exe^x at x=0x = 0: d/dx[ex]∣x=0=lim⁡h→0(eh−1)/h=1d/dx[e^x]|_{x=0} = \lim_{h\to 0}(e^h - 1)/h = 1. It says that ex−1≈xe^x - 1 \approx x for small xx — the exponential grows at rate 1 near 0. This is why ee is the "natural" base: it is the unique base where this derivative equals exactly 1. Equivalently: lim⁡x→0(ex−1)/x=1\lim_{x\to 0}(e^x - 1)/x = 1 confirms that d/dx[ex]=exd/dx[e^x] = e^x, since at x=0x=0 the slope is e0=1e^0 = 1. In DS/DA: the numerically stable computation of ex−1e^x - 1 for small xx (use np.expm1(x) to avoid catastrophic cancellation); log-return approximation in finance (ln⁡(1+r)≈r\ln(1+r) \approx r for small rr, derived from the companion limit lim⁡x→0ln⁡(1+x)/x=1\lim_{x\to 0}\ln(1+x)/x = 1); Taylor expansion of the exponential used in gradient approximations.

Flowchart

lim_{x- 0}(e^x -1)/x: 0/0 formMethod 1: Taylorseriese^x = 1 + x +x^2/2! + ...e^x - 1 = x +x^2/2! + ...(e^x-1)/x = 1 +x/2! + x^2/3! + ...As x- 0: allhigher termsvanish - limit = 1Method 2:L'Hopital (0/0form)Numerator deriv:d/dx[e^x - 1] =e^xDenominatorderiv: d/dx[x] = 1lim e^x / 1 = e^0= 1Consequence:d/dx[e^x] at x=0equals 1

Real-world use

Where it is used

Proving d/dx[ex]=exd/dx[e^x] = e^x from first principles; numerical stability: np.expm1(x) computes ex−1e^x - 1 accurately for small xx (avoids catastrophic cancellation in ex−1e^x - 1 when ex≈1e^x \approx 1); log-return approximation: for small return rr, ln⁡(1+r)≈r\ln(1+r) \approx r (companion limit lim⁡x→0ln⁡(1+x)/x=1\lim_{x\to 0}\ln(1+x)/x = 1); soft-plus gradient: d/dx[ln⁡(1+ex)]=ex/(1+ex)=σ(x)d/dx[\ln(1+e^x)] = e^x/(1+e^x) = \sigma(x) — uses the fact that (ex−1)/x→1(e^x-1)/x \to 1 for the slope analysis; small-perturbation analysis of any system that uses exe^x as an activation or link function.

Problem it solves

(e0−1)/0=0/0(e^0 - 1)/0 = 0/0 is undefined, yet the slope of exe^x at 0 is clearly well-defined. This limit provides that slope, confirming exe^x has slope 1 at x=0x=0. It also drives numerically stable computation: for small xx, ex≈1+xe^x \approx 1 + x, so ex−1≈xe^x - 1 \approx x but the naive subtraction ex−1e^x - 1 loses precision due to floating-point cancellation.

How it solves the problem

Taylor expansion: ex−1=x+x2/2!+…e^x - 1 = x + x^2/2! + \ldots. Divide by xx: (ex−1)/x=1+x/2!+…→1(e^x-1)/x = 1 + x/2! + \ldots \to 1 as x→0x\to 0. Alternatively, L'Hôpital: lim⁡(ex−1)/x=lim⁡ex/1=1\lim (e^x-1)/x = \lim e^x/1 = 1.

Example in a business

A DS computes log-returns for a financial time series. For a price relative R=Pt/Pt−1=1+rR = P_t/P_{t-1} = 1 + r where rr is the simple return, the log-return is ln⁡R=ln⁡(1+r)\ln R = \ln(1+r). For small rr (e.g., daily returns <1%< 1\%): ln⁡(1+r)≈r−r2/2+…≈r\ln(1+r) \approx r - r^2/2 + \ldots \approx r. The approximation error is O(r2)O(r^2): at r=0.01r=0.01 (1%), error ≈0.005%\approx 0.005\%. This approximation is valid because lim⁡r→0ln⁡(1+r)/r=1\lim_{r\to 0}\ln(1+r)/r = 1 (the companion limit to the exponential standard limit).

The formula, piece by piece

  • exe^x: exponential function base ee
  • ex−1e^x - 1: the exponential minus its value at x=0x=0 (which is 1)
  • xx: the increment from 0
  • (ex−1)/x(e^x - 1)/x: "how much does exe^x increase per unit of xx near 0?" — the slope at 0
  • =1= 1: the slope of exe^x at x=0x = 0 is 1, consistent with d/dx[ex]∣x=0=e0=1d/dx[e^x]|_{x=0} = e^0 = 1
  • Generalization: lim⁡x→0(eax−1)/x=a\lim_{x\to 0}(e^{ax} - 1)/x = a; lim⁡x→0(eax−1)/(ax)=1\lim_{x\to 0}(e^{ax} - 1)/(ax) = 1
  • Companion: lim⁡x→0ln⁡(1+x)/x=1\lim_{x\to 0}\ln(1+x)/x = 1 (inverse relationship: ln⁡\ln and exp⁡\exp cancel near 0)
  • Numerical note: np.expm1(x) is the numerically stable version of ex−1e^x - 1 for small xx

The formula in words

"For small xx, exe^x is approximately 1+x1 + x. So ex−1≈xe^x - 1 \approx x, and the ratio (ex−1)/x(e^x - 1)/x approaches 1. This says the exponential function has slope 1 at the origin." Tiny trace: x=0.1x = 0.1: (e0.1−1)/0.1=(1.10517−1)/0.1=1.0517(e^{0.1}-1)/0.1 = (1.10517-1)/0.1 = 1.0517. x=0.01x = 0.01: (1.01005−1)/0.01=1.005(1.01005-1)/0.01 = 1.005. x→0x \to 0: →1\to 1. ✓\checkmark

Critical Concepts

  • This is d/dx[ex]d/dx[e^x] at x=0x=0: the derivative definition gives d/dx[ex]∣x=0=lim⁡h→0(e0+h−e0)/h=lim⁡h→0(eh−1)/h=1=e0d/dx[e^x]|_{x=0} = \lim_{h\to 0}(e^{0+h}-e^0)/h = \lim_{h\to 0}(e^h-1)/h = 1 = e^0. Combined with the general formula d/dx[ex]=ex⋅d/dx[x]=exd/dx[e^x] = e^x \cdot d/dx[x] = e^x (chain rule with f=exf=e^x), this limit confirms the entire derivative. It is the anchor point.
  • np.expm1(x) for numerical stability: for small xx, np.exp(x) - 1 suffers catastrophic cancellation: e10−10≈1+10−10e^{10^{-10}} \approx 1 + 10^{-10}, and subtracting 1 in float64 loses all significant digits. np.expm1(x) computes ex−1e^x - 1 via a Taylor series for small xx, returning approximately xx with full precision. Always use expm1 when computing ex−1e^x - 1 for potentially small xx (e.g., Poisson log-likelihood, option pricing, softplus gradient).
  • Log-return and log-sum-exp: the companion limit lim⁡x→0ln⁡(1+x)/x=1\lim_{x\to 0}\ln(1+x)/x = 1 (proved by L'Hôpital: lim⁡(1/(1+x))/1=1\lim(1/(1+x))/1 = 1) means log-returns ≈\approx simple returns for small returns. This is used in finance, information theory (relative entropy: DKL(p∥q)≈∑i(pi−qi)2/(2qi)D_{KL}(p\|q) \approx \sum_i (p_i-q_i)^2/(2q_i) for small differences), and in log-sum-exp numerics.
  • Taylor expansion and ML activations: ex≈1+x+x2/2e^x \approx 1 + x + x^2/2 for small xx. The softplus function f(x)=ln⁡(1+ex)f(x) = \ln(1 + e^x): for x≈0x \approx 0, f(x)≈ln⁡(2)+x/2+x2/8−…f(x) \approx \ln(2) + x/2 + x^2/8 - \ldots. Its derivative σ(x)=ex/(1+ex)\sigma(x) = e^x/(1+e^x): at x=0x=0, σ(0)=1/2=f′(0)\sigma(0) = 1/2 = f'(0). Both rely on the slope-1 property at 0.
  • Relationship to interest rate formulas: for a fractional return rr per period, after nn periods the total is (1+r)n(1+r)^n.

For small rr: (1+r)n≈ern(1+r)^n \approx e^{rn} using (ex−1)/x→1(e^x-1)/x \to 1. This is why the rule of 72 works: at annual rate rr, doubling time ≈72/r%\approx 72/r\% uses er⋅t=2⇒t=ln⁡2/r≈0.693/re^{r\cdot t} = 2 \Rightarrow t = \ln 2/r \approx 0.693/r; in percentage terms, ≈69.3/r≈72/r\approx 69.3/r \approx 72/r (rounded for convenience).

Step-by-step calculation (tiny example)

Evaluate lim⁡x→0(e3x−1)/x\lim_{x\to 0}(e^{3x} - 1)/x.

Step 1: Introduce a factor of 3. (e3x−1)/x=3⋅(e3x−1)/(3x)(e^{3x}-1)/x = 3 \cdot (e^{3x}-1)/(3x).

Step 2: Let u=3xu = 3x; as x→0x\to 0, u→0u\to 0. =3⋅(eu−1)/u= 3 \cdot (e^u-1)/u.

Step 3: Apply the standard limit. =3⋅1=3= 3 \cdot 1 = 3. Verify: x=0.001x = 0.001: (e0.003−1)/0.001=0.003004.../0.001≈3.004≈3(e^{0.003}-1)/0.001 = 0.003004.../0.001 \approx 3.004 \approx 3. ✓\checkmark

Code examples

Beginner example (Python)

python
import numpy as np
print("Standard Limit: lim_{x->0} (e^x - 1)/x = 1")
print(f"\n{'x':>12} {'(e^x-1)/x':>14} {'Error from 1':>14}")
for x in [0.5, 0.1, 0.01, 0.001, 0.0001, 1e-8]:
    ratio = np.expm1(x) / x   # numerically stable
error = abs(ratio - 1.0)
print(f"{x:>12.6e} {ratio:>14.9f} {error:>14.2e}")   # Generalization: lim(e^(ax) - 1)/x = a
print(f"\n--- Generalization: lim_{{x->0}} (e^(ax)-1)/x = a ---")
print(f"{'a':>6} {'Numerical (x=1e-8)':>20} {'Analytic (=a)':>14}")
for a in [0.5, 2.0, -1.0, np.pi]:
    x = 1e-8
numerical = np.expm1(a * x) / x
print(f"{a:>6.3f} {numerical:>20.8f} {a:>14.6f}")   # Numerical stability: expm1 vs naive subtraction
print(f"\n--- Numerical stability: expm1 vs exp(x)-1 for tiny x ---")
print(f"{'x':>12} {'exp(x)-1 (naive)':>20} {'expm1(x) (stable)':>20} {'True (approx x)':>18}")
for x in [1e-6, 1e-10, 1e-14, 1e-16]:
    naive = np.exp(x) - 1   # suffers cancellation for very small x
stable = np.expm1(x)   # uses Taylor series near 0
print(f"{x:>12.2e} {naive:>20.15e} {stable:>20.15e} {x:>18.15e}")

Beginner example (R)

r
# Standard limit: lim_{x->0} (e^x - 1)/x = 1
cat("Standard Limit: lim_{x->0} (e^x - 1)/x = 1\n\n")
cat(sprintf("%-12s %-14s %-14s\n", "x", "(e^x-1)/x", "Error from 1"))
for (x in c(0.5, 0.1, 0.01, 0.001, 1e-8)) {
  ratio <- expm1(x) / x  # expm1 is available in base R
  error <- abs(ratio - 1.0)
  cat(sprintf("%-12.2e %-14.9f %-14.2e\n", x, ratio, error))
}

# Log-return approximation: log(1+r) ≈ r for small r
cat("\n--- Log-return approximation: log(1+r) ≈ r for small r ---\n")
cat(sprintf("%-8s %-12s %-12s %-12s\n", "r (%)", "log(1+r)", "r (approx)", "Error"))
for (r_pct in c(10, 5, 1, 0.1, 0.01)) {
  r <- r_pct / 100
  lr <- log(1 + r)  # log1p is also available
  err <- abs(lr - r)
  cat(sprintf("%-8.2f %-12.6f %-12.6f %-12.4e\n", r_pct, lr, r, err))
}

Professional example (Python)

python
import numpy as np
from sklearn.datasets import make_classification
from sklearn.preprocessing import StandardScaler
np.random.seed(42)

# -- Standard Limit (exp): numerically stable Poisson log-likelihood --
# Use case: A DS fits a Poisson regression model manually and encounters
# the numerical stability issue with computing log(lambda) when lambda is
# very small. The expm1 function (based on the standard exponential limit)
# ensures stable computation of e^x - 1 for small x.
#
# Poisson log-likelihood: ell(w) = sum_i [y_i * (w^T x_i) - exp(w^T x_i)]
# For link: lambda_i = exp(w^T x_i)
# Gradient: d(ell)/dw = X^T (y - lambda)
# Key issue: when w^T x is large and negative, lambda ≈ 0, and computations
# like y*log(lambda) need care.
N = 200
DIM = 3
LR = 0.01
N_ITER = 300

def poisson_log_lambda(w: np.ndarray, X: np.ndarray) -> np.ndarray:
    """Log of Poisson rate: z = X @ w. lambda = exp(z)."""
    return X @ w   # log(lambda) directly

def stable_poisson_ll(w: np.ndarray, X: np.ndarray, y: np.ndarray) -> float:
    """
    Numerically stable Poisson log-likelihood.

    ell = sum[y * log_lambda - exp(log_lambda)] = sum[y * z - exp(z)]
    Uses np.exp with clipping to avoid overflow.
    """
    z = poisson_log_lambda(w, X)
    lam = np.exp(np.clip(z, -30, 20))
    return float(np.sum(y * z - lam))

def poisson_gradient(w: np.ndarray, X: np.ndarray, y: np.ndarray) -> np.ndarray:
    """Gradient: d(ell)/dw = X^T(y - lambda)."""
    z = poisson_log_lambda(w, X)
    lam = np.exp(np.clip(z, -30, 20))
    return X.T @ (y - lam)


# Demonstrate expm1 precision for small-lambda regime
print("Standard Limit (exp): expm1 Precision for Small Lambda")
print(f"\nlim_{{x->0}} (e^x - 1)/x = 1 -> e^x - 1 ≈ x for small x")
print(f"\nNumerical stability of e^x - 1 in Poisson computations:")
print(f"{'z (log lambda)':>18} {'lambda':>12} {'naive exp(z)-1':>18} {'expm1(z)':>12} {'True ~ z':>10}")
for z in [-10, -5, -1, -0.1, -0.01, -0.001, -1e-6, -1e-10]:
    lam = np.exp(z)
    naive = np.exp(z) - 1
    stable = np.expm1(z)
    print(f"{z:>18.4e} {lam:>12.6e} {naive:>18.10e} {stable:>12.10e} {z:>10.6e}")

# Fit Poisson regression via gradient ascent on log-likelihood
X_raw = np.random.randn(N, DIM)
scaler = StandardScaler()
X = scaler.fit_transform(X_raw)
true_w = np.array([0.5, -0.3, 0.2])
log_lam_true = X @ true_w
y = np.random.poisson(np.exp(np.clip(log_lam_true, -5, 5))).astype(float)
w = np.zeros(DIM)
ll_history = []
for step in range(N_ITER):
    ll = stable_poisson_ll(w, X, y)
    ll_history.append(ll)
    grad = poisson_gradient(w, X, y)
    w = w + LR * grad / N

print(f"\nPoisson Regression via Gradient Ascent (max-likelihood)")
print(f"N={N}, DIM={DIM}, true_w={true_w}")
print(f"\nLog-likelihood: step 1={ll_history[0]:.2f}, step 100={ll_history[99]:.2f}, "
      f"final={ll_history[-1]:.2f}")
print(f"Fitted w: {np.round(w, 4)}")
print(f"True w: {true_w}")
print(f"\nKey: d/dw[exp(w^Tx)] = exp(w^Tx)*x -- uses d/dx[e^x] = e^x, anchored by lim(e^x-1)/x = 1")

#calculus#differential-calculus#limits-of-functions

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