Skip to content
Kittycat.tech logo

LaTeX for Calculus

✅ Copy-ready LaTeX (MathJax) code for Calculus, organised from beginner to advanced, with where each formula is used in maths and in Machine Learning, AI and Data Science. 😻

New to LaTeX? Start with the LaTeX (MathJax) Basics for Greek letters, dots and spaces.

Just click the "copy code" button below 'markdown'!

Summary Overview ​

1. Limits (Beginner) ​

1.1 Limit Notation ​

Limit: "\lim_{x \to a}"

Example:

limx→2(3x+1)=7

\to draws the arrow, and the condition goes under \lim using _.

Where it's used: describing the value a function gets close to. Limits are the foundation of derivatives and integrals.

markdown
$$
\lim_{x \to 2} (3x + 1) = 7
$$

1.2 One-Sided Limits ​

One-Sided Limits: "^{+}" and "^{-}"

Example:

limx→0−1x=−∞limx→0+1x=∞

0^{-} means approaching from the left, and 0^{+} means approaching from the right.

Where it's used: functions with jumps or vertical asymptotes, and piecewise functions.

markdown
$$
\lim_{x \to 0^{-}} \frac{1}{x} = -\infty \qquad \lim_{x \to 0^{+}} \frac{1}{x} = \infty
$$

1.3 Limits at Infinity ​

Limits at Infinity: "\infty"

Example:

limx→∞1x=0limn→∞(1+1n)n=e

Where it's used: long-run behaviour, horizontal asymptotes, and checking whether an algorithm converges.

markdown
$$
\lim_{x \to \infty} \frac{1}{x} = 0 \qquad \lim_{n \to \infty} \left( 1 + \frac{1}{n} \right)^{n} = e
$$

1.4 Continuity ​

Continuity

Example:

f is continuous at a⟺limx→af(x)=f(a)

Where it's used: checking that a function has no breaks before you differentiate it.

markdown
$$
f \text{ is continuous at } a \iff \lim_{x \to a} f(x) = f(a)
$$

2. Derivatives (Beginner) ​

2.1 Derivative Notations ​

Four Ways to Write a Derivative

Example:

f′(x)dydxddxf(x)x˙Dxf

Prime notation f'(x) is short, Leibniz notation \frac{dy}{dx} shows what changes with what, the dot \dot{x} is used for time in physics, and D_x f appears in some textbooks.

Where it's used: every topic in calculus. Different books prefer different notations.

markdown
$$
f'(x) \qquad \frac{dy}{dx} \qquad \frac{d}{dx} f(x) \qquad \dot{x} \qquad D_x f
$$

2.2 Definition of the Derivative ​

Derivative from First Principles

Example:

f′(x)=limh→0f(x+h)−f(x)h

Where it's used: proving differentiation rules from first principles, a common exam question.

markdown
$$
f'(x) = \lim_{h \to 0} \frac{f(x + h) - f(x)}{h}
$$

2.3 Differentiation Rules ​

Power, Product, Quotient and Chain Rules

Example:

ddxxn=nxn−1Power ruleddx[fg]=f′g+fg′Product ruleddx[fg]=f′g−fg′g2Quotient ruleddxf(g(x))=f′(g(x))⋅g′(x)Chain rule

&& adds a second column, so the rule names line up on the right.

Where it's used: almost every derivative you will calculate. The chain rule is the heart of backpropagation.

markdown
$$
\begin{aligned}
\frac{d}{dx} x^n &= n x^{n-1} && \text{Power rule} \\
\frac{d}{dx} [f g] &= f' g + f g' && \text{Product rule} \\
\frac{d}{dx} \left[ \frac{f}{g} \right] &= \frac{f' g - f g'}{g^2} && \text{Quotient rule} \\
\frac{d}{dx} f(g(x)) &= f'(g(x)) \cdot g'(x) && \text{Chain rule}
\end{aligned}
$$

2.4 Common Derivatives ​

Common Derivatives

Example:

ddxex=exddxln⁡x=1xddxsin⁡x=cos⁡xddxcos⁡x=−sin⁡xddxax=axln⁡addxtan⁡x=sec2⁡x

A single & between pairs makes two columns of equations.

Where it's used: the building blocks of harder derivatives. ex and ln⁡x appear in the sigmoid function and log-loss.

markdown
$$
\begin{aligned}
\frac{d}{dx} e^{x} &= e^{x} & \frac{d}{dx} \ln x &= \frac{1}{x} \\
\frac{d}{dx} \sin x &= \cos x & \frac{d}{dx} \cos x &= -\sin x \\
\frac{d}{dx} a^{x} &= a^{x} \ln a & \frac{d}{dx} \tan x &= \sec^2 x
\end{aligned}
$$

2.5 Higher-Order Derivatives ​

Second and Higher Derivatives

Example:

f″(x)d2ydx2f(n)(x)

In Leibniz notation, the 2 goes on the d at the top and on the x at the bottom. Use brackets in f^{(n)} so it is not read as a power.

Where it's used: concavity, acceleration and Taylor series.

markdown
$$
f''(x) \qquad \frac{d^2 y}{dx^2} \qquad f^{(n)}(x)
$$

2.6 Evaluating at a Point ​

Evaluation Bar: "\left. \right|"

Example:

ddxx2|x=2=2(2)=4

\left. is an invisible left bracket, so \right|_{x = 2} can draw the evaluation bar on its own.

Where it's used: finding the slope at a specific point, such as for a tangent line.

markdown
$$
\left. \frac{d}{dx} x^2 \right|_{x = 2} = 2(2) = 4
$$

2.7 Critical Points and the Second Derivative Test ​

Second Derivative Test

Example:

f′(c)=0andf″(c)>0⇒f has a local minimum at x=c

If f″(c)<0 instead, it is a local maximum.

Where it's used: optimisation problems, such as finding the lowest point of a cost function.

markdown
$$
f'(c) = 0 \quad \text{and} \quad f''(c) > 0 \;\Rightarrow\; f \text{ has a local minimum at } x = c
$$

2.8 Implicit Differentiation ​

Implicit Differentiation

Example:

x2+y2=12x+2ydydx=0dydx=−xy

Differentiate both sides with respect to x. Because y depends on x, the chain rule adds dydx to every y term.

Where it's used: curves that are hard to write as y=f(x), such as circles, and related rates problems.

markdown
$$
\begin{aligned}
x^2 + y^2 &= 1 \\
2x + 2y \frac{dy}{dx} &= 0 \\
\frac{dy}{dx} &= -\frac{x}{y}
\end{aligned}
$$

2.9 L'Hôpital's Rule ​

L'Hôpital's Rule

Example:

limx→af(x)g(x)=limx→af′(x)g′(x)limx→0sin⁡xx=limx→0cos⁡x1=1

Use it only when substituting directly gives 00 or ∞∞.

Where it's used: limits that look undefined at first, a very common exam question.

markdown
$$
\lim_{x \to a} \frac{f(x)}{g(x)} = \lim_{x \to a} \frac{f'(x)}{g'(x)}
$$

$$
\lim_{x \to 0} \frac{\sin x}{x} = \lim_{x \to 0} \frac{\cos x}{1} = 1
$$

3. Integrals (Intermediate) ​

3.1 Indefinite Integral ​

Indefinite Integral: "\int"

Example:

∫x2dx=x33+C

Do not forget + C. The thin space \, before dx is the usual style.

Where it's used: finding antiderivatives.

markdown
$$
\int x^2 \, dx = \frac{x^3}{3} + C
$$

3.2 Definite Integral and the Fundamental Theorem ​

Definite Integral: "\int_{a}^{b}"

Example:

∫abf(x)dx=[F(x)]ab=F(b)−F(a)∫02x2dx=[x33]02=83

\Big[ \Big] or \left[ \right] draws the square brackets used for evaluating between the limits.

Where it's used: areas under curves, total change and probabilities.

markdown
$$
\int_{a}^{b} f(x) \, dx = \Big[ F(x) \Big]_{a}^{b} = F(b) - F(a)
$$

$$
\int_{0}^{2} x^2 \, dx = \left[ \frac{x^3}{3} \right]_{0}^{2} = \frac{8}{3}
$$

3.3 Common Integrals ​

Common Integrals

Example:

∫xndx=xn+1n+1+C(n≠−1)∫1xdx=ln⁡|x|+C∫exdx=ex+C∫sin⁡xdx=−cos⁡x+C∫cos⁡xdx=sin⁡x+C

Where it's used: the building blocks of harder integrals.

markdown
$$
\begin{aligned}
\int x^n \, dx &= \frac{x^{n+1}}{n+1} + C \quad (n \neq -1) \\
\int \frac{1}{x} \, dx &= \ln \lvert x \rvert + C \\
\int e^{x} \, dx &= e^{x} + C \\
\int \sin x \, dx &= -\cos x + C \\
\int \cos x \, dx &= \sin x + C
\end{aligned}
$$

3.4 Substitution ​

Integration by Substitution

Example:

∫2xcos⁡(x2)dx=∫cos⁡udulet u=x2,du=2xdx=sin⁡u+C=sin⁡(x2)+C

Where it's used: integrals where one part is the derivative of another part.

markdown
$$
\begin{aligned}
\int 2x \cos(x^2) \, dx &= \int \cos u \, du && \text{let } u = x^2, \; du = 2x \, dx \\
&= \sin u + C \\
&= \sin(x^2) + C
\end{aligned}
$$

3.5 Integration by Parts ​

Integration by Parts

Example:

∫udv=uv−∫vdu∫xexdx=xex−ex+C

In the example, u=x and dv=exdx.

Where it's used: integrals of products, such as xex or xln⁡x.

markdown
$$
\int u \, dv = uv - \int v \, du
$$

$$
\int x e^{x} \, dx = x e^{x} - e^{x} + C
$$

3.6 Improper Integrals ​

Improper Integral

Example:

∫0∞e−xdx=limb→∞∫0be−xdx=1

Where it's used: probability distributions over infinite ranges, such as the exponential and normal distributions.

markdown
$$
\int_{0}^{\infty} e^{-x} \, dx = \lim_{b \to \infty} \int_{0}^{b} e^{-x} \, dx = 1
$$

3.7 Riemann Sums ​

Riemann Sum

Example:

∫abf(x)dx=limn→∞∑i=1nf(xi∗)Δx,Δx=b−an

Where it's used: understanding an integral as the area of many thin rectangles, and numerical integration in code.

markdown
$$
\int_{a}^{b} f(x) \, dx = \lim_{n \to \infty} \sum_{i=1}^{n} f(x_i^{*}) \, \Delta x, \qquad \Delta x = \frac{b - a}{n}
$$

3.8 Simple Differential Equations ​

Separable Differential Equation

Example:

dydt=ky∫1ydy=∫kdtln⁡|y|=kt+Cy(t)=y0ekt

Move each variable to its own side, then integrate both sides. y0 is the starting value at t=0.

Where it's used: exponential growth and decay, such as population growth, radioactive decay and continuous compound interest.

markdown
$$
\begin{aligned}
\frac{dy}{dt} &= k y \\
\int \frac{1}{y} \, dy &= \int k \, dt \\
\ln \lvert y \rvert &= k t + C \\
y(t) &= y_0 \, e^{k t}
\end{aligned}
$$

4. Sequences and Series (Intermediate) ​

4.1 Sequence and Series Notation ​

Sequences and Series

Example:

{an}n=1∞∑n=1∞an=a1+a2+a3+⋯

Use \{ \} for the curly brackets of a sequence.

Where it's used: describing lists of numbers and their sums.

markdown
$$
\{ a_n \}_{n=1}^{\infty} \qquad \sum_{n=1}^{\infty} a_n = a_1 + a_2 + a_3 + \cdots
$$

4.2 Geometric Series ​

Geometric Series

Example:

∑n=0∞arn=a1−r,|r|<1

Where it's used: compound interest, and discounted rewards in reinforcement learning, where r is the discount factor γ.

markdown
$$
\sum_{n=0}^{\infty} a r^{n} = \frac{a}{1 - r}, \qquad \lvert r \rvert < 1
$$

4.3 Taylor Series ​

Taylor Series

Example:

f(x)=∑n=0∞f(n)(a)n!(x−a)nex=1+x+x22!+x33!+⋯

Where it's used: approximating functions with polynomials, and optimisation methods such as Newton's method.

markdown
$$
f(x) = \sum_{n=0}^{\infty} \frac{f^{(n)}(a)}{n!} (x - a)^{n}
$$

$$
e^{x} = 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \cdots
$$

5. Multivariable Calculus (Advanced) ​

5.1 Partial Derivatives ​

Partial Derivative: "\partial"

Example:

f(x,y)=x2y⇒∂f∂x=2xy,∂f∂y=x2

Differentiate with respect to one variable and treat the others as constants.

Where it's used: functions with many inputs. Backpropagation computes ∂L∂w for every weight w.

markdown
$$
f(x, y) = x^2 y \quad \Rightarrow \quad \frac{\partial f}{\partial x} = 2xy, \quad \frac{\partial f}{\partial y} = x^2
$$

5.2 Gradient Vector ​

Gradient: "\nabla"

Example:

∇f(x,y)=[∂f∂x∂f∂y]=[2xyx2]

Where it's used: finding the direction of steepest increase. Gradient descent moves in the opposite direction.

markdown
$$
\nabla f(x, y) = \begin{bmatrix} \frac{\partial f}{\partial x} \\ \frac{\partial f}{\partial y} \end{bmatrix} = \begin{bmatrix} 2xy \\ x^2 \end{bmatrix}
$$

5.3 Multivariable Chain Rule ​

Multivariable Chain Rule

Example:

dzdt=∂z∂xdxdt+∂z∂ydydt

Here z depends on x and y, which both depend on t.

Where it's used: backpropagation when one value affects the loss through several paths.

markdown
$$
\frac{dz}{dt} = \frac{\partial z}{\partial x} \frac{dx}{dt} + \frac{\partial z}{\partial y} \frac{dy}{dt}
$$

5.4 Jacobian Matrix ​

Jacobian Matrix

Example:

J=[∂f1∂x1⋯∂f1∂xn⋮⋱⋮∂fm∂x1⋯∂fm∂xn]

Where it's used: derivatives of functions with several outputs, such as the layers of a neural network.

markdown
$$
J = \begin{bmatrix} \frac{\partial f_1}{\partial x_1} & \cdots & \frac{\partial f_1}{\partial x_n} \\ \vdots & \ddots & \vdots \\ \frac{\partial f_m}{\partial x_1} & \cdots & \frac{\partial f_m}{\partial x_n} \end{bmatrix}
$$

5.5 Hessian Matrix ​

Hessian Matrix

Example:

H=[∂2f∂x2∂2f∂x∂y∂2f∂y∂x∂2f∂y2]

Where it's used: the second derivative test with several variables, Newton's method, and the curvature of a loss function.

markdown
$$
H = \begin{bmatrix} \frac{\partial^2 f}{\partial x^2} & \frac{\partial^2 f}{\partial x \, \partial y} \\ \frac{\partial^2 f}{\partial y \, \partial x} & \frac{\partial^2 f}{\partial y^2} \end{bmatrix}
$$

5.6 Double Integrals ​

Double Integral: "\iint"

Example:

∬Df(x,y)dA=∫ab∫cdf(x,y)dydx

\iint and \iiint give double and triple integral signs.

Where it's used: volumes, and joint probability distributions of two variables.

markdown
$$
\iint_{D} f(x, y) \, dA = \int_{a}^{b} \int_{c}^{d} f(x, y) \, dy \, dx
$$

5.7 Lagrange Multipliers ​

Lagrange Multipliers

Example:

∇f(x,y)=λ∇g(x,y),g(x,y)=cL(x,y,λ)=f(x,y)−λ(g(x,y)−c)

λ is the Lagrange multiplier. To solve, set every partial derivative of the Lagrangian L to zero.

Where it's used: optimisation with a constraint, such as support vector machines in Machine Learning.

markdown
$$
\nabla f(x, y) = \lambda \, \nabla g(x, y), \qquad g(x, y) = c
$$

$$
\mathcal{L}(x, y, \lambda) = f(x, y) - \lambda \big( g(x, y) - c \big)
$$

6. Calculus for Machine Learning (Applied) ​

6.1 Gradient Descent ​

Gradient Descent Update

Example:

θ:=θ−α∇θJ(θ)

α is the learning rate and J(θ) is the cost function.

Where it's used: training almost every machine learning model.

markdown
$$
\theta := \theta - \alpha \, \nabla_{\theta} J(\theta)
$$

6.2 Chain Rule in Backpropagation ​

Backpropagation

Example:

∂L∂w=∂L∂y^⋅∂y^∂z⋅∂z∂w

Here z=wx+b and y^=σ(z). Each fraction is one step back through the network.

Where it's used: computing how each weight affects the loss in a neural network.

markdown
$$
\frac{\partial L}{\partial w} = \frac{\partial L}{\partial \hat{y}} \cdot \frac{\partial \hat{y}}{\partial z} \cdot \frac{\partial z}{\partial w}
$$

6.3 Derivative of the Sigmoid ​

Sigmoid Derivative

Example:

σ(z)=11+e−z⇒σ′(z)=σ(z)(1−σ(z))

Where it's used: logistic regression and neural networks that use the sigmoid activation.

markdown
$$
\sigma(z) = \frac{1}{1 + e^{-z}} \quad \Rightarrow \quad \sigma'(z) = \sigma(z) \big( 1 - \sigma(z) \big)
$$

6.4 Gradient of the Mean Squared Error ​

MSE Gradient

Example:

J(w)=1n∑i=1n(y^i−yi)2⇒∂J∂wj=2n∑i=1n(y^i−yi)xij

Here y^i=w⊤xi+b, and xij is feature j of example i.

Where it's used: training linear regression with gradient descent.

markdown
$$
J(\mathbf{w}) = \frac{1}{n} \sum_{i=1}^{n} (\hat{y}_i - y_i)^2 \;\Rightarrow\; \frac{\partial J}{\partial w_j} = \frac{2}{n} \sum_{i=1}^{n} (\hat{y}_i - y_i) \, x_{ij}
$$

✅Summarized reviews based on Kittycat's insights from the best online courses at top universities