Common Differentiation Rules — Power, Exponential, and Logarithmic Functions
Common Differentiation Rules — Power, Exponential, and Logarithmic Functions
In the previous chapter, we understood the meaning of the derivative; this chapter covers practical calculation. Mastering the differentiation rules for the three most commonly used function types in AI will allow you to handle most scenarios.
Quick Reference Table of Basic Function Derivatives
| Function f(x) | Derivative f'(x) | Scenarios in AI |
|---|---|---|
| ( c ) (Constant) | ( 0 ) | Constant disappears when differentiating the bias term |
| ( x^n ) | ( nx^{n-1} ) | ( x^2 ) in MSE loss |
| ( e^x ) | ( e^x ) | Sigmoid, Softmax |
| ( \ln x ) | ( \frac{1}{x} ) | Cross-entropy loss |
Rules for differentiation of arithmetic operations
| Rules | Formulas |
|---|---|
| Sum and difference | ( (f \pm g)' = f' \pm g' ) |
| Product | ( (fg)' = f'g + fg' ) |
| Constant multiple | ( (cf)' = cf' ) |
The most important derivative:\( (e^x)' = e^x \)——The derivative of the exponential function equals itself.
This makes the exponential function ubiquitous in differential equations and deep learning.
Real-life examples
Learning differentiation rules is like learning knife skills in cooking—each rule is a fundamental skill, and combining them allows you to handle any recipe.
( (e^x)' = e^x ) is like an unchanging ingredient: no matter how it is processed, it remains the same.
Mathematical definition
Derivative of a power function: decrease the power by one, multiply by the original exponent
[ \frac{d}{dx} x^n = n x^{n-1} ]
This is the most basic differentiation formula. For example, ( (x^2)' = 2x ) and ( (x^3)' = 3x^2 ).
In the MSE loss, ( (y - \hat{y})^2 ) is a power function, and its derivative is ( 2(y - \hat{y}) ).
Derivative of the exponential function: the derivative is itself
[ \frac{d}{dx} e^x = e^x ]
This is one of the most unique functions in mathematics. The derivative of e^x is still e^x—no matter how many times you differentiate it, it remains the same.
This property causes e^x to appear repeatedly in the Sigmoid function ( \sigma(x) = 1/(1+e^{-x}) ) and Softmax.
Derivative of the logarithmic function
[ \frac{d}{dx} \ln x = \frac{1}{x} ]
It is used when differentiating the log term in cross-entropy loss. The derivatives of the logarithm and the exponential are reciprocals of each other—they are inverse functions.
Product and difference rule
[ (f \pm g)' = f' \pm g' ]
The derivative of a sum is the sum of the derivatives. The differentiation operation can "pass through" addition and subtraction, differentiating each term separately.
Product Rule
[ (f \cdot g)' = f' \cdot g + f \cdot g' ]
The derivative of a product is not the product of the derivatives. Instead, it is "the derivative of the first times the second + the first times the derivative of the second".
This rule frequently appears in backpropagation—when calculating the partial derivative of ( w \cdot x ) with respect to w, the product rule is used.
By combining these three types of functions and three rules, you can find the derivatives of the vast majority of functions in AI.
For example, the derivative of Sigmoid, \( \sigma'(x) = \sigma(x)(1-\sigma(x)) \), is a combination of the quotient rule, the derivative of the exponential function, and the chain rule.
Python Hands-on Practice
Example
import
sympy
as
sp
x
=
sp.
Symbol
(
'x'
)
funcs
=
{
'x^3'
: x**
3
,
'e^x'
: sp.
exp
(
x
)
,
'ln(x)'
: sp.
log
(
x
)
,
'x^2 + 3x + 5'
: x**
2
3
*x +
5
}
(
"=== Symbol Differentiation Verification ==="
)
for
name
,
f
in
funcs.
items
(
)
:
(
f
"f(x)={name:15s} → f'(x)={sp.diff(f, x)}"
)
Product rule
f
=
x**
2
- sp.
exp
(
x
)
(
f
"\n(x^2 · e^x)' = {sp.diff(f, x)}"
)
Chain rule: derivative of (2x+1)^3
g
=
(
2
*x +
1
)
**
3
(
f
"((2x+1)^3)' = {sp.diff(g, x)}"
)
Application scenarios in AI
Gradient calculation in backpropagation
Every layer of a neural network involves these basic differentiation rules. For the linear layer y = Wx + b, differentiation with respect to parameter W uses the product rule, and differentiation with respect to b uses the derivative of a constant being 0.
Derivation of the derivative of the Sigmoid activation function
( \sigma(x) = 1/(1+e^{-x}) ) can be differentiated using the quotient rule to get ( \sigma'(x) = \sigma(x)(1-\sigma(x)) ). This concise form is extremely fast to compute during backpropagation—it only requires the \sigma(x) value already calculated during the forward pass, without needing to recalculate the exponential.
Softmax + Cross-Entropy Combination Gradient
Softmax involves exponentiation, summation, and division, making its derivative complex on its own. However, when combined with the cross-entropy loss, the gradient miraculously simplifies to ( \hat{y} - y ) (prediction - true label)—this is one of the most elegant derivative simplifications in deep learning and the fundamental reason for the standard Softmax+CE in classification tasks.