BRAGA

02 Writing02-02 Notes02-02-315

Implicit Differentiation (If F(x,y) = 0)

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
dydx=−FxFy\frac{dy}{dx} = -\frac{F_x}{F_y}
(1)

Deep Breakdown

What it tells me (Situation Awareness): Implicit differentiation handles the case where a curve or surface is defined by an equation F(x,y)=0F(x, y) = 0 (or F(x,y)=cF(x, y) = c) rather than as an explicit function y=f(x)y = f(x). When you cannot (or do not want to) solve for yy explicitly, you can still find dy/dxdy/dx by differentiating both sides of F(x,y)=0F(x,y) = 0 with respect to xx — treating yy as a function of xx and applying the chain rule. The result is the compact formula dydx=−FxFy\frac{dy}{dx} = -\frac{F_x}{F_y} where Fx=∂F∂xF_x = \frac{\partial F}{\partial x} and Fy=∂F∂yF_y = \frac{\partial F}{\partial y}. In DA/DS, this formula appears in: deriving optimality conditions for constrained optimization (the slope of the constraint curve at the optimum), sensitivity analysis of equilibrium conditions (how does the equilibrium point shift when a parameter changes?), understanding the geometry of level sets (the gradient ∇F\nabla F is perpendicular to the level curve F=0F = 0), and computing the Jacobian of implicitly defined transformations.

Flowchart

YesNoImplicitequation: F(x, y)= 0Differentiateboth sides withrespect to xApply chain rule:dF/dx = partial_xF + partial_y F *(dy/dx) = 0Solve for dy/dx:dy/dx = -F_x /F_yEvaluate at aspecific point(x0, y0)?Compute F_xand F_y at (x0,y0), then ratioLeave as afunction of x andy (valid on thecurve)F_y = 0 at apoint? Tangentis vertical, dy/dxundefined there

Real-world use

Where it is used

Constrained optimization: the constraint g(x,y)=0g(x,y) = 0 defines an implicit curve; the slope of this curve is needed for the KKT conditions. Equilibrium analysis: in game theory or market models, the equilibrium is defined implicitly; sensitivity of equilibrium to parameter changes requires implicit differentiation. Level set geometry: the normal to a level curve F(x,y)=cF(x,y) = c is ∇F=(Fx,Fy)\nabla F = (F_x, F_y), and the tangent slope is −Fx/Fy-F_x/F_y. Reparametrization in probability: if a distribution is parameterized implicitly (e.g., via a score equation), implicit differentiation gives parameter sensitivity.

Problem it solves

Many relationships are naturally expressed as F(x,y)=0F(x,y) = 0 (a unit circle: x2+y2−1=0x^2 + y^2 - 1 = 0; the logistic boundary: wTx=0w^T x = 0; budget constraints; isoquants in economics). Solving for yy explicitly is often impossible (transcendental equations like ey+xy=0e^y + xy = 0) or produces messy expressions. Implicit differentiation gives dy/dxdy/dx directly without needing the explicit form.

How it solves the problem

Differentiating F(x,y)=0F(x, y) = 0 with respect to xx (using the chain rule on the yy dependence):

∂F∂x+∂F∂ydydx=0  ⟹  dydx=−FxFy\frac{\partial F}{\partial x} + \frac{\partial F}{\partial y}\frac{dy}{dx} = 0 \implies \frac{dy}{dx} = -\frac{F_x}{F_y}
(2)

This works as long as Fy≠0F_y \neq 0 at the point of interest (by the Implicit Function Theorem: the curve can be locally expressed as y=f(x)y = f(x) if Fy≠0F_y \neq 0).

Example in a business

In a two-class SVM, the decision boundary satisfies wTx+b=0w^T x + b = 0, an implicit linear equation. For a feature vector (x1,x2)(x_1, x_2), the slope of the boundary is dx2dx1=−Fx1Fx2=−w1w2\frac{dx_2}{dx_1} = -\frac{F_{x_1}}{F_{x_2}} = -\frac{w_1}{w_2}. This tells the analyst exactly how the decision boundary trades off the two features — without solving for x2x_2 explicitly.

The formula, piece by piece

dydx=−FxFy\frac{dy}{dx} = -\frac{F_x}{F_y}
(3)

Each symbol:

  • F(x,y)=0F(x, y) = 0: the implicit equation defining the curve; FF is a differentiable function of both xx and yy
  • Fx=∂F∂xF_x = \frac{\partial F}{\partial x}: partial derivative of FF with respect to xx (treat yy as constant)
  • Fy=∂F∂yF_y = \frac{\partial F}{\partial y}: partial derivative of FF with respect to yy (treat xx as constant)
  • dydx\frac{dy}{dx}: the slope of the curve F(x,y)=0F(x,y) = 0 at a point (x0,y0)(x_0, y_0)
  • The negative sign: comes from rearranging Fx+Fy⋅dydx=0F_x + F_y \cdot \frac{dy}{dx} = 0
  • Condition: Fy≠0F_y \neq 0 at the point (otherwise the tangent is vertical or the curve has a singularity) For a surface in 3D (F(x,y,z)=0F(x,y,z) = 0, implicit surface):
∂z∂x=−FxFz,∂z∂y=−FyFz\frac{\partial z}{\partial x} = -\frac{F_x}{F_z}, \quad \frac{\partial z}{\partial y} = -\frac{F_y}{F_z}
(4)

The formula in words

"The curve is defined by F(x,y)=0F(x,y) = 0, not by an explicit rule y=f(x)y = f(x). To find the slope, differentiate FF with respect to xx: the xx changes FF directly (at rate FxF_x) and also through yy (at rate Fy⋅dy/dxF_y \cdot dy/dx by chain rule). Since FF is always 0 on the curve, the total change is 0. Set Fx+Fy⋅dy/dx=0F_x + F_y \cdot dy/dx = 0 and solve: dy/dx=−Fx/Fydy/dx = -F_x/F_y."

Critical Concepts

  • Implicit Function Theorem (IFT): if F(x0,y0)=0F(x_0, y_0) = 0 and Fy(x0,y0)≠0F_y(x_0, y_0) \neq 0, then there exists a neighborhood of x0x_0 where the curve F(x,y)=0F(x,y)=0 is the graph of a differentiable function y=f(x)y = f(x). The derivative is −Fx/Fy-F_x/F_y.
  • Gradient perpendicularity: the gradient ∇F=(Fx,Fy)\nabla F = (F_x, F_y) is always perpendicular to the level curve F=cF = c. The tangent vector to the curve is (−Fy,Fx)(-F_y, F_x) (rotated 90°), giving slope dy/dx=−Fx/Fydy/dx = -F_x/F_y
  • Vertical tangent: when Fy=0F_y = 0 at a point, the tangent is vertical (dy/dxdy/dx is undefined, but dx/dy=−Fy/Fx=0dx/dy = -F_y/F_x = 0). Classic example: top and bottom of a circle.
  • Extension to Jacobians: for a system Fi(x1,…,xn,y1,…,ym)=0F_i(x_1, \ldots, x_n, y_1, \ldots, y_m) = 0, the Jacobian of y\mathbf{y} with respect to x\mathbf{x} is −Jy−1Jx-J_y^{-1} J_x, a direct matrix analogue.
  • SVM connection: the SVM decision boundary wTx=0w^T x = 0 is an implicit linear equation. Implicit differentiation gives the feature trade-off rate directly from the weight vector components.
  • Lagrange multiplier geometry: at the optimum of a constrained problem, the gradient of the objective is proportional to the gradient of the constraint (∇f=λ∇g\nabla f = \lambda \nabla g), which is a statement about the alignment of level sets — an implicit differentiation result.

Step-by-step calculation (tiny example)

Find dy/dxdy/dx for the unit circle F(x,y)=x2+y2−1=0F(x,y) = x^2 + y^2 - 1 = 0.

Step 1: Compute partial derivatives Fx=∂∂x(x2+y2−1)=2xF_x = \frac{\partial}{\partial x}(x^2 + y^2 - 1) = 2x Fy=∂∂y(x2+y2−1)=2yF_y = \frac{\partial}{\partial y}(x^2 + y^2 - 1) = 2y

Step 2: Apply the formula

dydx=−FxFy=−2x2y=−xy\frac{dy}{dx} = -\frac{F_x}{F_y} = -\frac{2x}{2y} = -\frac{x}{y}
(5)

Step 3: Evaluate at the point (x0,y0)=(1/2, 1/2)(x_0, y_0) = (1/\sqrt{2},\, 1/\sqrt{2}) (45° on the circle)

dydx∣(12,12)=−1/21/2=−1\frac{dy}{dx}\bigg|_{(\frac{1}{\sqrt{2}}, \frac{1}{\sqrt{2}})} = -\frac{1/\sqrt{2}}{1/\sqrt{2}} = -1
(6)

The tangent to the circle at 45° has slope −1-1. Verification: from explicit form y=1−x2y = \sqrt{1 - x^2}, dydx=−x1−x2=−xy\frac{dy}{dx} = \frac{-x}{\sqrt{1-x^2}} = -\frac{x}{y}

Code examples

Beginner example (Python)

python
import numpy as np

def big_f(x: float, y: float) -> float:
    """Implicit curve: x^2 + y^2 - 1 = 0 (unit circle)."""
    return x**2 + y**2 - 1.0

def f_x(x: float, y: float) -> float:
    """F_x = partial F / partial x = 2x."""
    return 2.0 * x

def f_y(x: float, y: float) -> float:
    """F_y = partial F / partial y = 2y."""
    return 2.0 * y

def implicit_slope(x: float, y: float) -> float:
    """dy/dx = -F_x / F_y (valid when F_y != 0)."""
    fy = f_y(x, y)
    if abs(fy) < 1e-10:
        raise ValueError(f"F_y ≈ 0 at ({x},{y}): vertical tangent, dy/dx undefined")
    return -f_x(x, y) / fy


# Test points on the unit circle
test_points = [
    (1.0 / np.sqrt(2), 1.0 / np.sqrt(2)),   # 45 degrees
    (0.5, np.sqrt(0.75)),                   # 60 degrees
    (0.0, 1.0),                             # 90 degrees: F_y = 2, F_x = 0 -> slope = 0
]
print("Implicit differentiation on unit circle (x^2 + y^2 = 1):")
print(f" {'(x, y)':>26} | {'On curve?':>10} | {'dy/dx':>10}")
for x0, y0 in test_points:
    on_curve = abs(big_f(x0, y0)) < 1e-8
    slope = implicit_slope(x0, y0)
    print(f" ({x0:>8.5f}, {y0:>8.5f}) | {str(on_curve):>10} | {slope:>10.5f}")

# Numerical check: perturb along the curve, measure slope
x0, y0 = test_points[0]
dx = 1e-6
y1 = np.sqrt(max(0, 1.0 - (x0 + dx)**2))   # stay on circle
numerical_slope = (y1 - y0) / dx
print(f"\nNumerical check at ({x0:.4f},{y0:.4f}):")
print(f" Implicit formula: {implicit_slope(x0, y0):.6f}")
print(f" Numerical slope: {numerical_slope:.6f}")

Beginner example (R)

r
big_f <- function(x, y) x^2 + y^2 - 1  # unit circle
f_x_fn <- function(x, y) 2 * x
f_y_fn <- function(x, y) 2 * y
implicit_slope <- function(x, y) -f_x_fn(x, y) / f_y_fn(x, y)

# Test points on the unit circle
test_points <- list(
  c(1/sqrt(2), 1/sqrt(2)),  # 45 degrees
  c(0.5, sqrt(0.75)),       # 60 degrees
  c(0, 1)                   # 90 degrees
)
cat("Implicit differentiation on unit circle:\n")
for (pt in test_points) {
  x0 <- pt[1]; y0 <- pt[2]
  on_curve <- abs(big_f(x0, y0)) < 1e-8
  slope <- implicit_slope(x0, y0)
  cat(sprintf(" (%.5f, %.5f): on curve=%s, dy/dx = %.5f\n", x0, y0, on_curve, slope))
}

Professional example (Python)

python
"""
Implicit differentiation
for SVM decision boundary analysis. For a linear SVM
with weight vector
w = [w1, w2] and bias b: Decision boundary: F(x1, x2) = w1*x1 + w2*x2 + b = 0 The slope of the boundary (how much x2 changes per unit x1 change): dx2/dx1 = -F_{x1} / F_{x2} = -w1 / w2 Business insight: if w1 > w2, x1 (e.g., spend) matters more per unit
than x2 (e.g., frequency). The slope of the decision line quantifies
the feature trade-off at the classification boundary.
"""
import numpy as np
import matplotlib.pyplot as plt
from sklearn.svm import SVC
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
RANDOM_SEED = 42
rng = np.random.default_rng(RANDOM_SEED)   # 2-feature binary classification
x_data, y_data = make_classification( n_samples=300, n_features=2, n_redundant=0, n_informative=2, random_state=RANDOM_SEED, class_sep=1.5 )
x_train, x_test, y_train, y_test = train_test_split( x_data, y_data, test_size=0.3, random_state=RANDOM_SEED )
scaler = StandardScaler()
x_train_s = scaler.fit_transform(x_train)
x_test_s = scaler.transform(x_test)   # Fit linear SVM
svm = SVC(kernel="linear", C=1.0)
svm.fit(x_train_s, y_train)   # Decision boundary: w1*x1 + w2*x2 +
b = 0
w = svm.coef_[0]
b_svm = svm.intercept_[0]   # Implicit differentiation: dx2/dx1 = -F_{x1}/F_{x2} = -w[0]/w[1]
slope_boundary = -w[0] / w[1]
intercept_boundary = -b_svm / w[1]
print("=== SVM Decision Boundary via Implicit Differentiation ===")
print(f" Weight vector w = [{w[0]:.4f}, {w[1]:.4f}]")
print(f" Bias b = {b_svm:.4f}")
print(f"\n Decision boundary: {w[0]:.4f}*x1 + {w[1]:.4f}*x2 + {b_svm:.4f} = 0")
print(f" Implicit slope dx2/dx1 = -w[0]/w[1] = {slope_boundary:.4f}")
print(f" Interpretation: for each unit increase in x1 (holding on the boundary),")
print(f" x2 must change by {slope_boundary:.4f} to stay on the decision boundary.")
print()
print(f" |w1/w2| = {abs(w[0]/w[1]):.4f}: " f"{'x1 matters more' if abs(w[0]) > abs(w[1]) else 'x2 matters more'} " f"per unit change at the boundary")   # Verify by checking two boundary points
x1_a = 0.0
x2_a = (-w[0] * x1_a - b_svm) / w[1]
x1_b = 1.0
x2_b = (-w[0] * x1_b - b_svm) / w[1]
numerical_slope = (x2_b - x2_a) / (x1_b - x1_a)
print(f"\n Numerical verification: dx2/dx1 from two boundary points = {numerical_slope:.4f}")
print(f" Match: {abs(slope_boundary - numerical_slope) < 1e-8}")

Source: 1300 p. 231

#calculus#multivariable-calculus-and-matrix-calculus#partial-differentiation-and-total-differentials

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