Taylor Series (First-Order Approximation) TODO
Concept
The Taylor series approximates a sufficiently smooth function near a point a using a polynomial built from the function's derivatives at that point. The first-order approximation is f(x) ≈ f(a) + f'(a)(x−a) — replacing the curve with its tangent line — and since the error is dominated by the quadratic term, it shrinks proportionally to (x−a)² as x approaches a. In the multivariable case this becomes f(x) ≈ f(a) + ∇f(a)ᵀ(x−a), so the gradient vector becomes the local linear model — the foundation that optimization and numerical methods like gradient descent and Newton's method stand on. Common approximations such as (1+x)^n ≈ 1 + nx, e^x ≈ 1 + x, and ln(1+x) ≈ x are all first-order Taylor expansions around a=0, and all come with the same caveat: they only hold for small |x|. Whenever you use an approximation, you must always state which point it's centered near and how much error is tolerable — otherwise a linearization taken far from that point silently gives you a wrong answer.
Linearization is the default tool for quickly estimating a price curve's local sensitivity (slippage, delta) or the impact of a fee change, and knowing the valid range is what makes that estimate safe to rely on.
Code & Formula
# Day 33 — 테일러 급수(1차 근사)
# f(x) ≈ f(a) + f'(a)(x-a) 로 exp(x)를 a=0에서 선형근사하고, x가 a에서 멀어질수록 오차가 커짐을 본다.
import math
def f(x):
return math.exp(x)
def f_prime(x):
return math.exp(x) # exp의 도함수는 자기 자신
def taylor_1st_order(x, a):
return f(a) + f_prime(a) * (x - a)
a = 0.0
print(f"e^x 를 a={a} 에서 1차 테일러 근사:\n")
print(f"{'x':>6} {'실제값':>12} {'근사값':>12} {'오차':>12}")
for x in [0.01, 0.1, 0.3, 0.5, 1.0, 2.0]:
exact = f(x)
approx = taylor_1st_order(x, a)
err = abs(exact - approx)
print(f"{x:6.2f} {exact:12.6f} {approx:12.6f} {err:12.6f}")
print("\n오차는 대략 (x-a)^2 에 비례해서 커진다 (2차 항이 지배).")
for x in [0.1, 0.2, 0.4]:
err = abs(f(x) - taylor_1st_order(x, a))
print(f" x={x}: 오차={err:.6f}, (x-a)^2={x**2:.6f}, 비율={err / x**2:.4f}")
Exercise
Compute ln(1+x) using both its first-order approximation at x=0 and its true value at x=0.01, 0.1, and 0.5, and tabulate how the relative error grows.
Practical Connection
Expanding LMSR's price function to first order around the current inventory gives a closed-form, fast estimate of expected fill price and slippage for a small order — and that same expansion explains why the estimate breaks down as order size grows.
If you study this on a given day, add a note link and a ✅ to this line in the source curriculum (docs/knowledge/math-50-curriculum.md) and this spot will lead straight to the note body. You can also write directly on this page — but regenerating overwrites it, so it's safer to keep anything you want to save as markdown under docs/algorithms/.