Workspace IndexMath › Day 33

Taylor Series (First-Order Approximation) TODO

Math · Day 33 / 52 · October — Calculus & Optimization (Day 27-34)

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/.


한국어

테일러 급수(1차 근사) TODO

Math · Day 33 / 52 · 10월 — 미적분·최적화 (Day 27–34)

개념

테일러 급수는 충분히 매끄러운 함수를 한 점 a 근방에서 그 점에서의 도함수 값들로 만든 다항식으로 근사하는 도구다. 1차 근사는 f(x) ≈ f(a) + f'(a)(x-a)로, 곡선을 접선으로 바꾸는 것이며 오차는 2차 항이 지배하므로 x가 a에 가까울수록 (x-a)²에 비례해 줄어든다. 다변수에서는 f(x) ≈ f(a) + ∇f(a)ᵀ(x-a)가 되어 기울기 벡터가 국소 선형 모델이 되고, 이것이 경사하강법과 뉴턴법 같은 최적화·수치해석 기법이 서 있는 토대다. 자주 쓰는 근사인 (1+x)^n ≈ 1 + nx, e^x ≈ 1 + x, ln(1+x) ≈ x도 모두 a=0에서의 1차 테일러 전개이며, |x|가 작을 때만 유효하다는 조건이 함께 따라온다. 근사를 쓸 때는 항상 '어느 점 근방인가'와 '오차가 어느 정도까지 허용되는가'를 명시해야 하며, 그렇지 않으면 멀리서 쓴 선형화가 조용히 틀린 답을 준다.

가격 곡선의 국소 민감도(슬리피지, 델타)나 수수료 변화의 영향을 빠르게 추정할 때 선형화가 기본 도구이고, 어디까지가 유효 범위인지 아는 것이 그 추정을 안전하게 만든다.

코드 · 수식

# 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}")

연습

ln(1+x)를 x=0 근방 1차 근사와 실제 값으로 x=0.01, 0.1, 0.5에서 각각 계산해 상대 오차가 어떻게 커지는지 표로 적어 보라.

실무 · Verex 연결

LMSR의 가격 함수를 현재 재고 근방에서 1차 전개하면 소량 주문의 예상 체결가와 슬리피지를 닫힌 형태로 빠르게 추정할 수 있고, 주문이 커질수록 그 추정이 왜 빗나가는지도 같은 식에서 설명된다.

공부한 날 원본 커리큘럼(docs/knowledge/math-50-curriculum.md)의 이 줄에 노트 링크와 ✅ 를 붙이면, 이 자리는 노트 본문으로 바로 이어집니다. 노트 없이 이 페이지에 바로 적어도 됩니다 — 다만 다시 생성하면 덮어쓰이므로, 남길 글은 docs/algorithms/ 의 마크다운으로 쓰는 편이 안전합니다.

← 32. 고정소수점 산술(Q64.96)34. 볼록집합/볼록함수 판별 →