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.
Where it lands in Jayverse
- Verex: state the valid range of the LMSR linear estimate. When implementing the first-order price expansion for slippage/delta, document explicitly the order-size range where the linear estimate stays close to the true LMSR price.
- Verex: add a test comparing the linear estimate against the true price as order size grows. Catch the point where the approximation silently becomes wrong, instead of trusting the linearization past its valid range.
- Auditor: require a centering point and error bound for every linearized formula. Any place a nonlinear formula (fee curves, funding estimates) is swapped for a linear one needs both documented, not just the approximation itself.
Key expressions
| Expression | 뜻 · 쓰이는 자리 |
|---|---|
| shrink proportionally to | ~에 비례해서 줄어들다 · 오차가 어떻게 작아지는지 설명할 때. "the error... shrinks proportionally to (x−a)²" |
| silently (give a wrong answer) | 티 안 나게, 모르는 새 · 경고 없이 오답이 나올 때. "silently gives you a wrong answer" |
| closed-form | 닫힌 형태의(수식으로 바로 풀리는) · 근사식이 빠르게 계산됨을 말할 때. "a closed-form, fast estimate" |
| come with the same caveat | 같은 단서(주의사항)가 따라붙다 · 여러 근사식이 공통 한계를 가질 때. "all come with the same caveat" |
| centered near | ~을 중심으로 한 · 근사가 기준점 근처에서만 유효할 때. "which point it's centered near" |
| stand on | ~위에 기반을 두다 · 다른 방법론의 토대가 될 때. "the foundation that optimization... stand on" |
| tolerable | 감내할 수 있는, 허용 가능한 · 오차의 허용 범위를 말할 때. "how much error is tolerable" |
| LMSR | 로그마켓스코어링룰(Logarithmic Market Scoring Rule) · 예측시장 AMM의 가격함수, 1차 테일러 전개로 슬리피지를 근사할 때 대상이 됨. "Expanding LMSR's price function to first order" |
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/.