BRAGA

02 Writing02-02 Notes02-02-289

Constant Multiple

Published 16 Apr 202612 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
∫c⋅f(x) dx=c∫f(x) dx\int c \cdot f(x)\,dx = c \int f(x)\,dx
(1)

Deep Breakdown

What it tells me (Situation Awareness): The constant multiple rule for integrals says a constant scalar factor can be pulled outside the integral. This is a direct consequence of integration's linearity — specifically, the linearity of the limit of Riemann sums. Scaling every function value by cc scales the area by cc. In DA/DS: this is used constantly and almost invisibly. Normalizing a probability density f(x)f(x) to integrate to 1 means choosing c=1/∫fc = 1/\int f so that c∫f(x) dx=1c\int f(x)\,dx = 1. Expected value computation E[cX]=cE[X]\mathbb{E}[cX] = c\mathbb{E}[X] is the continuous-domain constant multiple rule. In numeric integration (quadrature): c * np.trapz(f_vals, x) — the constant can be factored before or after the trapezoid sum. In ML: the regularization term λ∥w∥2\lambda\|w\|^2 scaled by λ\lambda obeys this rule; the learning rate α\alpha in gradient descent is a constant factor on the gradient integral (in continuous-time gradient flow).

Flowchart

Integral: integralof c*f(x) dxc is a constant(does notdepend on x)Pull c outside: c* integral of f(x)dxEvaluate integralof f(x) dxseparatelyMultiply result bycWhy it works:Riemann sumscalingsumc*f(x_i)*delta_x= c * sumf(x_i)*delta_xTaking limit:same rule holdsfor the integralIn probability:E[cX] = c*E[X]In normalization:choose c =1/integral_f tomake densityintegrate to 1In ML: lambda *integral =integral oflambda*f(regularizationscaling)

Real-world use

Where it is used

Expected value linearity: E[cX]=cE[X]=c∫xf(x)dx\mathbb{E}[cX] = c\mathbb{E}[X] = c\int xf(x)dx; normalizing constant in probability: p(x)=f(x)/Zp(x) = f(x)/Z where Z=∫f(x)dxZ = \int f(x)dx — computing ZZ once and applying the constant; scaling loss functions (L2L_2 regularization: ∫λw2dw=λ∫w2dw\int \lambda w^2 dw = \lambda\int w^2 dw); continuous-time gradient flow: dw/dt=−α∇L(w)dw/dt = -\alpha\nabla L(w), integrating: Δw=−α∫0T∇L(w)dt\Delta w = -\alpha\int_0^T \nabla L(w)dt; scaling in Fourier transforms: F{cf}=cF{f}\mathcal{F}\{cf\} = c\mathcal{F}\{f\}; computing cumulative distributions F(x)=∫0xp(t)dtF(x) = \int_0^x p(t)dt when pp includes a normalizing constant.

Problem it solves

Without this rule, you would need to integrate c⋅f(x)c \cdot f(x) from scratch each time you encounter a scaled function — recomputing the antiderivative entirely. The constant multiple rule lets you separate the "shape" (integral of ff) from the "scale" (cc), solving them independently and multiplying at the end.

How it solves the problem

For any constant cc (not depending on xx): ∫c⋅f(x)dx=c∫f(x)dx\int c\cdot f(x)dx = c\int f(x)dx. Find the antiderivative F(x)F(x) of f(x)f(x), then the antiderivative of cf(x)cf(x) is cF(x)+CcF(x) + C. Proof via differentiation: d/dx[cF(x)]=c⋅F′(x)=c⋅f(x)d/dx[cF(x)] = c\cdot F'(x) = c\cdot f(x). ✓\checkmark

Example in a business

A DS computes the expected revenue per session from a fitted exponential distribution: f(x)=λe−λxf(x) = \lambda e^{-\lambda x} for x≥0x \geq 0. Mean: E[X]=∫0∞xλe−λxdx=λ∫0∞xe−λxdx\mathbb{E}[X] = \int_0^\infty x \lambda e^{-\lambda x}dx = \lambda\int_0^\infty xe^{-\lambda x}dx — the constant λ\lambda is factored out, then the integral ∫0∞xe−λxdx=1/λ2\int_0^\infty xe^{-\lambda x}dx = 1/\lambda^2 (by integration by parts). So E[X]=λ⋅1/λ2=1/λ\mathbb{E}[X] = \lambda \cdot 1/\lambda^2 = 1/\lambda. Without the constant multiple rule, the λ\lambda stays inside and complicates the integration. With it: factor λ\lambda, integrate the simpler xe−λxxe^{-\lambda x}, multiply.

The formula, piece by piece

  • cc: a constant — any real number that does NOT depend on the variable of integration xx
  • f(x)f(x): an integrable function of xx
  • ∫c⋅f(x)dx\int c\cdot f(x)dx: the integral of the product
  • =c∫f(x)dx= c\int f(x)dx: the constant factors out; compute ∫f(x)dx\int f(x)dx then multiply by cc
  • Definite form: ∫abc⋅f(x)dx=c∫abf(x)dx\int_a^b c\cdot f(x)dx = c\int_a^b f(x)dx
  • Proof: d/dx[cF(x)+C′]=c⋅f(x)d/dx[cF(x)+C'] = c\cdot f(x) for any antiderivative FF of ff
  • Caveat: cc must be truly constant with respect to xx; if c=c(x)c = c(x), this rule does NOT apply (need product rule / integration by parts)
  • Combination with addition: ∫[cf(x)+dg(x)]dx=c∫f(x)dx+d∫g(x)dx\int[cf(x) + dg(x)]dx = c\int f(x)dx + d\int g(x)dx (full linearity of integration)

The formula in words

"Scaling a function by a constant scales its area by the same constant. You can factor the constant out of the integral, compute the integral of the unscaled function, and then multiply the result by the constant." Tiny trace: ∫3x2dx=3∫x2dx=3⋅x3/3+C=x3+C\int 3x^2 dx = 3\int x^2 dx = 3 \cdot x^3/3 + C = x^3 + C. Verify: d/dx[x3]=3x2d/dx[x^3] = 3x^2. ✓\checkmark

Critical Concepts

  • Linearity of integration: the constant multiple rule is one half of the linearity of the integral (the other half is the sum rule ∫[f+g]=∫f+∫g\int[f+g] = \int f + \int g). Together they give: ∫[af+bg]dx=a∫fdx+b∫gdx\int[af+bg]dx = a\int f dx + b\int g dx — integration is a linear operator, just like matrix-vector multiplication. This linearity is why expected value is linear: E[aX+bY]=aE[X]+bE[Y]\mathbb{E}[aX+bY] = a\mathbb{E}[X] + b\mathbb{E}[Y] for independent or jointly distributed X,YX, Y.
  • Normalizing constants in probability: a PDF must satisfy ∫p(x)dx=1\int p(x)dx = 1. Often we can compute an unnormalized density p~(x)∝p(x)\tilde{p}(x) \propto p(x) and find the normalizing constant Z=∫p~(x)dxZ = \int \tilde{p}(x)dx. Then p(x)=p~(x)/Zp(x) = \tilde{p}(x)/Z. The constant multiple rule ensures ∫p(x)dx=(1/Z)∫p~(x)dx=(1/Z)⋅Z=1\int p(x)dx = (1/Z)\int\tilde{p}(x)dx = (1/Z)\cdot Z = 1. In Bayesian inference, computing Z=∫p(X∣θ)p(θ)dθZ = \int p(X|\theta)p(\theta)d\theta (the evidence) is often intractable — this is why MCMC and variational inference work with unnormalized densities.
  • Variance formula uses the rule: Var[cX]=c2Var[X]\text{Var}[cX] = c^2\text{Var}[X], derived from ∫(cx−cμ)2f(x)dx=c2∫(x−μ)2f(x)dx=c2Var[X]\int (cx-c\mu)^2 f(x)dx = c^2\int(x-\mu)^2 f(x)dx = c^2\text{Var}[X]. The square makes it c2c^2, not cc. In feature scaling: if you multiply a feature by cc, the variance scales by c2c^2 and the standard deviation by ∣c∣|c|.
  • Numerical integration preserves the rule: c * scipy.integrate.quad(f, a, b) gives the same result as scipy.integrate.quad(lambda x: c * f(x), a, b). This matters for performance when cc is large: avoid scaling inside the integrand if possible (reduces floating-point issues and can be factored post-integration).
  • Gradient flow as integral of gradient: continuous gradient descent solves dw/dt=−∇L(w)dw/dt = -\nabla L(w).

The weight update over a time period [0,T][0,T] is w(T)−w(0)=−∫0T∇L(w(t))dtw(T) - w(0) = -\int_0^T \nabla L(w(t))dt. Learning rate α\alpha corresponds to time T=αT = \alpha (step size), and the constant multiple rule applies: α∫01∇Ldt=∫01α∇Ldt\alpha \int_0^1 \nabla L dt = \int_0^1 \alpha\nabla L dt — scaling the learning rate is exactly scaling the gradient integral.

Step-by-step calculation (tiny example)

Evaluate ∫5e3xdx\int 5e^{3x}dx.

Step 1: Identify the constant. The constant is c=5c = 5 (does not depend on xx). Factor it out: 5∫e3xdx5\int e^{3x}dx.

Step 2: Integrate e3xe^{3x}. ∫e3xdx=e3x/3+C\int e^{3x}dx = e^{3x}/3 + C (chain rule in reverse: d/dx[e3x/3]=3e3x/3=e3xd/dx[e^{3x}/3] = 3e^{3x}/3 = e^{3x}).

Step 3: Multiply by the constant. 5∫e3xdx=5⋅(e3x/3)+C=(5/3)e3x+C5\int e^{3x}dx = 5\cdot(e^{3x}/3) + C = (5/3)e^{3x} + C. Verify: d/dx[(5/3)e3x]=(5/3)⋅3e3x=5e3xd/dx[(5/3)e^{3x}] = (5/3)\cdot 3e^{3x} = 5e^{3x}. ✓\checkmark

Code examples

Beginner example (Python)

python
import numpy as np
from scipy import integrate

def verify_constant_multiple_rule(f, c: float, a: float, b: float) -> None:
    """Numerically verify: integral(c*f) = c * integral(f) on [a, b].

    Uses scipy.integrate.quad for accurate numerical integration.
    """
    integral_cf, err_cf = integrate.quad(lambda x: c * f(x), a, b)
    integral_f, err_f = integrate.quad(f, a, b)
    c_times_integral = c * integral_f
    match = abs(integral_cf - c_times_integral) < 1e-8
    print(f" integral(c*f): {integral_cf:.8f}")
    print(f" c * integral(f): {c_times_integral:.8f}")
    print(f" Difference: {abs(integral_cf - c_times_integral):.2e} Match: {match}")


print("Constant Multiple Rule: integral(c*f) = c * integral(f)")

# Example 1: 5*e^(3x) from 0 to 1
print("\nf(x) = e^(3x), c = 5, [0, 1]")
print(f"Analytic: 5 * (e^3 - 1)/3 = {5 * (np.exp(3) - 1) / 3:.8f}")
verify_constant_multiple_rule(lambda x: np.exp(3 * x), c=5.0, a=0.0, b=1.0)

# Example 2: probability density normalization
print("\n--- Normalization: p(x) = (1/Z) * unnormalized density ---")
lam = 2.0  # exponential distribution rate
# Unnormalized density: f(x) = e^(-lam*x) on [0, inf)
z, _ = integrate.quad(lambda x: np.exp(-lam * x), 0, np.inf)
print(f"Unnormalized: f(x) = exp(-{lam}x)")
print(f"Normalizing constant Z = {z:.6f} (should be 1/lambda = {1/lam:.6f})")
integral_normalized, _ = integrate.quad(lambda x: (1/z) * np.exp(-lam * x), 0, np.inf)
print(f"integral(p(x)) = (1/Z)*Z = {integral_normalized:.8f} (should be 1.0)")

# Example 3: E[cX] = c*E[X] via numerical integration
print("\n--- E[cX] = c*E[X] ---")
MEAN_TRUE = 1 / lam  # exponential mean = 1/lambda
for c_scale in [0.5, 2.0, 10.0]:
    ex, _ = integrate.quad(lambda x: x * lam * np.exp(-lam * x), 0, 20)
    ecx, _ = integrate.quad(lambda x: c_scale * x * lam * np.exp(-lam * x), 0, 20)
    print(f" c = {c_scale}: E[X] = {ex:.5f}, E[{c_scale}X] = {ecx:.5f} "
          f"(c*E[X] = {c_scale * ex:.5f}) Match: {abs(ecx - c_scale * ex) < 1e-6}")

Beginner example (R)

r
# Constant Multiple Rule: integral(c*f) = c * integral(f)
verify_constant_multiple <- function(f, c, a, b) {
  int_cf <- integrate(function(x) c * f(x), lower = a, upper = b)$value
  int_f <- integrate(f, lower = a, upper = b)$value
  cat(sprintf(" integral(c*f) = %.8f\n", int_cf))
  cat(sprintf(" c*integral(f) = %.8f\n", c * int_f))
  cat(sprintf(" Difference = %.2e\n\n", abs(int_cf - c * int_f)))
}
cat("Constant Multiple Rule\n\n")

# f(x) = exp(3x), c = 5
cat("f(x) = exp(3x), c=5, [0,1]\n")
analytic <- 5 * (exp(3) - 1) / 3
cat(sprintf("Analytic: %.8f\n", analytic))
verify_constant_multiple(function(x) exp(3 * x), c = 5, a = 0, b = 1)

# Normalization
lam <- 2.0
Z <- integrate(function(x) exp(-lam * x), lower = 0, upper = Inf)$value
cat(sprintf("Normalization: Z = %.6f = 1/lambda = %.6f\n", Z, 1/lam))
int_norm <- integrate(function(x) (1/Z) * exp(-lam * x), lower = 0, upper = Inf)$value
cat(sprintf("integral(p(x)) = %.8f (should be 1)\n\n", int_norm))

# E[cX] = c*E[X]
cat("E[cX] = c*E[X]:\n")
for (c_val in c(0.5, 2, 10)) {
  ex <- integrate(function(x) x * lam * exp(-lam * x), lower = 0, upper = 20)$value
  ecx <- integrate(function(x) c_val * x * lam * exp(-lam * x), lower = 0, upper = 20)$value
  cat(sprintf(" c=%.1f: E[X]=%.5f, E[cX]=%.5f, c*E[X]=%.5f\n", c_val, ex, ecx, c_val * ex))
}

Professional example (Python)

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

# -- Constant Multiple Rule: gradient flow scaling and variance of scaled features --
# Two connected applications:
# (A) Feature scaling: Var[c*X] = c^2 * Var[X], integral form via constant multiple rule
# Scaling features by c scales variance by c^2 (not c) -- critical for LR selection
# (B) Continuous gradient flow: Delta_w = -alpha * integral(grad L dt)
# The learning rate alpha is a constant factor on the integrated gradient
# Analytic form: for quadratic loss L(w) = (1/2)||Xw-y||^2, gradient = X^T(Xw-y)
# Integral of gradient from 0 to alpha = alpha * grad(w_0) (first-order approx)
N = 200
DIM = 4
X_raw, y = make_regression(n_samples=N, n_features=DIM, noise=0.5, random_state=42)
y = y / y.std()
print("Constant Multiple Rule: Feature Scaling and Gradient Flow")

# Part A: Var[c*X] = c^2 * Var[X]
print("\n--- Part A: Var[c*X] = c^2 * Var[X] (constant multiple rule in variance) ---")
print(f"{'Feature':>10} {'Std(X)':>10} {'c':>6} {'Std(cX)':>10} {'c*Std(X)':>12} {'Match':>8}")
for i in range(DIM):
    feature = X_raw[:, i]
    std_x = feature.std()
    for c in [0.1, 2.0, 10.0]:
        std_cx = (c * feature).std()
        c_std_x = abs(c) * std_x
        match = abs(std_cx - c_std_x) < 1e-8
        print(f" feat[{i}] {std_x:>10.4f} {c:>6.1f} {std_cx:>10.4f} {c_std_x:>12.4f} {str(match):>8}")
    break  # just show first feature

# Part B: Gradient flow integral: Delta_w = -alpha * grad(w_0) + O(alpha^2)
print("\n--- Part B: Learning rate as constant in gradient flow integral ---")
scaler = StandardScaler()
X = scaler.fit_transform(X_raw)
w0 = np.zeros(DIM)
grad0 = X.T @ (X @ w0 - y) / N  # initial gradient
# For quadratic loss: w(T) = exp(-T * X^TX/N) * w0 + (I - exp(-T * X^TX/N)) * w*
# First-order: w(alpha) ≈ w0 - alpha * grad0 (constant multiple rule on gradient integral)
# Verify: numerical vs. analytic first-order approximation
print(f"Initial gradient norm: {np.linalg.norm(grad0):.6f}")
print(f"\n{'alpha':>8} {'|Delta_w| analytic':>20} {'|Delta_w| exact (GD1)':>22} {'Match':>8}")
for alpha in [0.001, 0.01, 0.05, 0.1, 0.5]:
    # First-order (constant multiple rule): Delta_w ≈ -alpha * grad0
    dw_analytic = alpha * np.linalg.norm(grad0)
    # Exact one-step gradient descent
    w1 = w0 - alpha * grad0
    dw_exact = np.linalg.norm(w1 - w0)
    # They should match (they are identical: dw_exact = alpha * ||grad0||)
    match = abs(dw_analytic - dw_exact) < 1e-10
    print(f"{alpha:>8.3f} {dw_analytic:>20.8f} {dw_exact:>22.8f} {str(match):>8}")
print(f"\nConclusion: gradient descent step = alpha * gradient is the constant multiple")
print(f"rule: scaling the gradient by alpha is equivalent to factoring alpha outside")
print(f"the integral of the gradient flow over step size alpha.")

Source: 1300 p. 235

#calculus#integral-calculus#rules-of-integration

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