ln(x) and Limits — Math Foundations for AI
Natural Logarithm: ln(x)
What ln means, its derivative, and why it's used in AI loss functions.
What is ln?
ln(x) = natural logarithm = log base e
ln answers: "e to what power gives x?"
ln(1) = 0 because e⁰ = 1
ln(e) = 1 because e¹ = e
ln(7.39) = 2 because e² ≈ 7.389
ln(0.5) = -0.69 because e^(-0.69) ≈ 0.5Derivative of ln
f(x) = ln(x)
f'(x) = 1/x
At x=1: f'(1) = 1/1 = 1
At x=2: f'(2) = 1/2 = 0.5
At x=5: f'(5) = 1/5 = 0.2
At x=0.1: f'(0.1) = 1/0.1 = 10 ← steep near zero!Why ln Appears in AI Loss Functions
Cross-Entropy Loss = -y·ln(ŷ)
If target y=1:
ŷ=0.9 (good): Loss = -ln(0.9) = 0.105 (small ✓)
ŷ=0.5 (okay): Loss = -ln(0.5) = 0.693 (medium)
ŷ=0.1 (bad): Loss = -ln(0.1) = 2.303 (big! ✗)
ŷ=0.001 (terrible): Loss = -ln(0.001) = 6.908 (huge!! ✗✗)
ln punishes bad predictions HARD.
Gentle for good predictions.Why ln Instead of Squared Error?
Loss graph (-ln(ŷ) when target=1):
Loss ▲
7 │· ← terrible prediction: huge penalty
5 │ ·
3 │ ··
2 │ ···
1 │ ····
0 │ ········· ← good prediction: almost no penalty
└──────────────────────► ŷ
0 0.2 0.4 0.6 0.8 1.0
Gradient = -1/ŷ:
ŷ=0.9: gradient = -1.11 (small push)
ŷ=0.1: gradient = -10 (big push!)
ŷ=0.01: gradient = -100 (huge push!!)
→ Worse prediction = stronger correction
→ Model fixes big mistakes FASTLimits: lim(x)
"What value does the function approach?"
What lim Means
lim f(x) = L
x→a
"As x approaches a, f(x) approaches L"
It's the DESTINATION, even if you never arrive.Simple Example
lim (x + 1) = ?
x→3
x=2.9: 3.9
x=2.99: 3.99
x=2.999: 3.999
x→3: → 4
Answer: 4 (just plug in)When You CAN'T Plug In (0/0)
lim (x² - 1)/(x - 1) = ?
x→1
Plug in: (1-1)/(1-1) = 0/0 ← undefined!
But approach from both sides:
x=0.99: → 1.99
x=0.999: → 1.999
x=1.001: → 2.001
x=1.01: → 2.01
Approaches 2!
Why: (x²-1)/(x-1) = (x+1)(x-1)/(x-1) = x+1
At x→1: x+1 → 2 ✓Limit with Infinity
lim 1/x = ?
x→∞
x=10: 0.1
x=100: 0.01
x=1000: 0.001
x=1000000: 0.000001
Approaches 0. Never reaches it.
lim 1/x = 0
x→∞Euler's Number AS a Limit
e = lim (1 + 1/n)ⁿ
n→∞
n=1: 2.000
n=10: 2.594
n=100: 2.705
n=1000: 2.717
n=10000: 2.7181
n→∞: → 2.71828... = e
Approaches e but never passes it.
▲ value
e │─ ─ ─ ─ ─ ─ ─ ─ ─ ← limit line
│ ········
│ ··
│ ·
│ ·
│ ·
2 │·
└──────────────────► n
1 10 100 1000 ∞Limits in AI
LimitValueMeaning in AIlim(x→∞) sigmoid(x)1Output saturates at 1 (confident positive)lim(x→-∞) sigmoid(x)0Output saturates at 0 (confident negative)lim(x→0) ln(x)-∞Loss explodes for wrong predictionslim(n→∞) (1+1/n)ⁿeFoundation of all exponentialslim(lr→0) gradient stepexact derivativeSmaller learning rate = more preciseKey Takeaway
lim tells you where a function is HEADING,
even if it never actually arrives there.
In AI:
- Sigmoid APPROACHES 0 and 1 but never reaches them
- Loss APPROACHES infinity as prediction → 0
- e IS the limit of (1+1/n)ⁿ as n → ∞
- Derivative IS the limit of (f(x+h)-f(x))/h as h → 0