Mathematical Foundations

Mathematics for Artificial Intelligence

Mathematics for AI & Machine Learning | Lesson 1 — Free Beginner Guide
Lesson 1 · AI Engineering Foundations

Mathematics for Artificial Intelligence

Every AI model is numbers moving through equations. This lesson builds that foundation from zero — so formulas in machine learning papers read like sentences, not walls of symbols.

13 topics
Beginner → Applied
Examples + diagrams
Tied to AI
01 Foundations

Why Mathematics Matters in AI

An AI system does not "understand" a cat photo, a sentence, or a song. It receives numbers, transforms those numbers using equations, and produces new numbers that we then interpret as a prediction. Mathematics is not a prerequisite you tolerate before "the real work" — it is the real work. The model architecture, the training process, and the evaluation of results are all mathematical operations wearing an engineering costume.

The four pillars an AI engineer leans on

BranchWhat it gives AI
Algebra & functionsThe language of models — every network is a function mapping input to output
Linear algebraVectors and matrices — how data, images, and words are actually stored and processed
CalculusDerivatives — how a model learns from its mistakes (gradient descent)
Probability & statisticsHow a model expresses uncertainty and makes decisions from patterns in data

This lesson builds the ground floor beneath all four: how numbers behave, how to read and write equations, and how to think in functions and graphs. Nothing here is "too basic" — these are the exact tools used, at full speed, inside every neural network.

Why this order

You cannot understand a loss function without logarithms, cannot understand a weight update without equations, and cannot understand a neuron's activation without functions and graphs. This lesson is sequenced so each topic unlocks the next.

02 Foundations

Types of Data

Before any math happens, raw information has to become numbers. In AI, we sort data into a few basic families, because each family gets processed differently.

Numerical — ages, prices, temperatures. Already numbers.
Categorical — colors, countries, "yes/no". Labels, not quantities.
Text — sentences, documents. Converted into number sequences.
Image / audio — grids of pixel brightness or sound wave values.

Turning categories into numbers

A model cannot multiply the word "red." So categorical data is converted — for example, with one-hot encoding: each category becomes a position in a list of 0s and a single 1.

Example

Colors = {Red, Green, Blue}

Red \(\rightarrow (1,0,0)\)   Green \(\rightarrow (0,1,0)\)   Blue \(\rightarrow (0,0,1)\)

Structured vs. unstructured

Structured data fits neatly into rows and columns, like a spreadsheet (a customer's age, income, purchase count). Unstructured data — images, audio, free text — has no fixed grid of columns, so it needs extra preprocessing before it becomes clean numeric input.

Raw Data "cat photo" Encoding pixels → numbers words → vectors Numeric Vector [0.12, 0.98, 0.44, ...] ready for the model
Every AI pipeline begins the same way: raw signal → encoding → numeric vector
AI connection

A neural network's very first job is always this conversion. An image becomes a grid of numbers between 0 and 1 (pixel brightness); a word becomes a vector of numbers called an embedding. From that point on, everything is arithmetic.

03 Numbers

Numbers

Numbers come in nested families — every family you learn contains the ones before it, plus something new.

SetSymbolContainsExample
Natural numbers\(\mathbb{N}\)Counting numbers1, 2, 3, 4...
Whole numbersNaturals + zero0, 1, 2, 3...
Integers\(\mathbb{Z}\)Whole numbers + negatives..., -2, -1, 0, 1, 2...
Rational numbers\(\mathbb{Q}\)Any fraction of integers\( \tfrac12, -\tfrac34, 5\)
Irrational numbersCannot be written as a fraction\(\pi,\ \sqrt2\)
Real numbers\(\mathbb{R}\)Rationals + irrationalseverything on the number line
-3 -2 -1 0 1 2 3 0.5 √2≈1.41
Every real number — fraction or irrational — has one exact spot on the number line
AI connection

The "weights" inside a neural network are real numbers, usually stored as decimals like 0.3821. Pixel values are integers from 0 to 255. Probabilities output by a model are real numbers restricted to the interval between 0 and 1. Knowing which "family" a number belongs to tells you what operations are even valid on it.

04 Numbers

Fractions

A fraction \(\dfrac{a}{b}\) means "split something into \(b\) equal pieces and take \(a\) of them." The top number is the numerator; the bottom is the denominator.

3⁄4 shaded 2⁄5 shaded
A fraction is a shaded portion of a whole, split into equal parts

The four operations

Multiply: \(\dfrac{a}{b}\times\dfrac{c}{d}=\dfrac{a\times c}{b\times d}\)

Divide: \(\dfrac{a}{b}\div\dfrac{c}{d}=\dfrac{a}{b}\times\dfrac{d}{c}\)

Add / subtract (common denominator first): \(\dfrac{a}{b}+\dfrac{c}{b}=\dfrac{a+c}{b}\)

As a decimal: \(\dfrac{3}{4}=0.75\)

Worked example

A dataset of 1,200 images is split so that \(\tfrac{3}{4}\) go to training and the rest to testing. Training size \(=1200\times\tfrac34=900\) images. Testing size \(=1200-900=300\) images.

AI connection

Fractions are everywhere in AI workflow decisions: an 80/20 train-test split, a dropout rate of \(\tfrac{1}{5}\) that randomly turns off neurons during training, or a model's output being a probability — which is really just a fraction between 0 and 1.

05 Numbers

Powers and Roots

A power (exponent) is repeated multiplication: \(a^n\) means multiply \(a\) by itself \(n\) times.

\(2^4 = 2\times2\times2\times2 = 16\)

\(a^0 = 1\)    \(a^{-n}=\dfrac{1}{a^n}\)    \(a^{m}\times a^{n}=a^{m+n}\)    \(\left(a^m\right)^n=a^{mn}\)

A root undoes a power. The square root asks "what number, multiplied by itself, gives this?"

\(\sqrt{16}=4\) because \(4\times4=16\)

General root: \(\sqrt[n]{a}=a^{1/n}\)

x y y = x² y = √x
Squaring grows fast; the square root grows — but slows down
Worked example

Distance between two points \((1,2)\) and \((4,6)\): \(d=\sqrt{(4-1)^2+(6-2)^2}=\sqrt{9+16}=\sqrt{25}=5\).

AI connection

Squaring is the heart of measuring error: Mean Squared Error squares every mistake before averaging, so bigger mistakes are punished disproportionately. Square roots appear in measuring the "length" (magnitude) of vectors, and in the standard deviation used to normalize data before feeding it to a model.

06 Numbers

Logarithms

A logarithm answers the reverse question of a power: "what exponent do I need to reach this number?"

\(\log_b(x) = y \iff b^y = x\)

\(\log_2(8) = 3\) because \(2^3=8\)

Natural log (base \(e\approx2.718\)): \(\ln(x)=\log_e(x)\)

Key properties

\(\log(ab)=\log a + \log b\)

\(\log\!\left(\dfrac{a}{b}\right)=\log a - \log b\)

\(\log(a^n)=n\log a\)

y = ln(x) x→0: y→ -∞
Logarithms rise quickly at first, then flatten — perfect for compressing huge number ranges
AI connection

Logarithms are essential to how models are trained. The most common training loss for classification, cross-entropy / log loss, is literally built from \(-\log(p)\), where \(p\) is the probability the model assigned to the correct answer. Because \(-\log(p)\) blows up as \(p\to0\), the model is punished heavily for being confidently wrong.

Worked example

If a model predicts probability \(p=0.9\) for the correct class, its loss is \(-\log(0.9)\approx0.105\) — small. If it predicts \(p=0.1\) for the correct class, its loss is \(-\log(0.1)\approx2.303\) — much larger. Confidence in the wrong direction is costly.

07 Relationships

Functions

A function is a rule: put a number in, get exactly one number out. Think of it as a machine.

x = 3 f(x) = x² + 1 the rule / the model f(3) = 10
Input → function → output. A trained AI model is exactly this, just with millions of internal steps

Domain and range

The domain is every valid input; the range is every possible output. For \(f(x)=\sqrt{x}\), the domain is \(x\geq0\) — you cannot feed it a negative number and get a real result.

Function families you'll meet constantly in AI

FunctionFormulaWhere it shows up
Linear\(f(x)=wx+b\)The basic building block of every neuron
Sigmoid\(f(x)=\dfrac{1}{1+e^{-x}}\)Squashes any number into a probability (0 to 1)
ReLU\(f(x)=\max(0,x)\)The most common activation function in deep networks
Softmaxturns a list of numbers into probabilities that sum to 1Final layer of a classifier
sigmoid ReLU
Two activation functions: sigmoid smoothly bends between 0 and 1; ReLU is flat, then a straight ramp
AI connection

A neural network is, mathematically, one giant function built by stacking small functions inside each other: \(f(x) = f_3(f_2(f_1(x)))\). Every "layer" you hear about is one of these functions.

08 Relationships

Graphs

A graph is a picture of a function or a relationship, drawn on a coordinate plane — two number lines crossing at a point called the origin \((0,0)\). The horizontal line is the \(x\)-axis; the vertical line is the \(y\)-axis. Every point is written as \((x,y)\).

x y (0,1) (2,2) y = 0.5x + 1
Plotting \(y = 0.5x + 1\): every point on the line satisfies the equation

Reading a graph

  • Slope — how steep the line is, i.e. how much \(y\) changes per unit of \(x\).
  • Intercept — where the line crosses the \(y\)-axis (the value of \(y\) when \(x=0\)).
  • Trend — is the relationship going up, down, curving, or flat?
AI connection

A training curve — loss going down over time — is a graph. A decision boundary that separates two classes on a scatter plot is a graph. Even a neural network's weights, when plotted, reveal patterns engineers use to debug and understand the model.

09 Algebra

Variables and Constants

A variable is a symbol standing in for a number that can change — usually letters like \(x\), \(y\), \(w\). A constant is a fixed value that never changes within the problem, like \(2\), \(\pi\), or a specific known number.

In \(f(x) = 3x + 5\):   \(x\) is the variable,   \(3\) and \(5\) are constants.

x₁ weight w (adjustable) Σ + b bias (constant) output
Inside a single artificial neuron: the input \(x\) and weight \(w\) are variables the model works with; the bias adjusts the result
AI connection

Training a neural network means searching for the best values of its variables — the weights and biases — so the model's predictions match reality as closely as possible. Everything the model "learns" lives inside these adjustable numbers.

10 Algebra

Equations

An equation is a statement that two expressions are equal. Solving it means finding the value of the variable that makes the statement true.

2x + 3 11 balanced when x = 4
An equation is a balance scale — whatever you do to one side, you must do to the other
Solving step by step

\(2x + 3 = 11\)

Subtract 3 from both sides: \(2x = 8\)

Divide both sides by 2: \(x = 4\)

Systems of equations

Sometimes multiple equations must be true at once — for example, finding the point where two lines cross. This is the base idea behind solving many small equations simultaneously, exactly what happens (at a massive scale) inside a trained network.

AI connection

Training an AI model literally means solving (approximately) a giant equation: adjust the weights \(w\) so that the model's output \(f(x)\) is as close as possible to the true answer \(y\). The rule used to nudge each weight closer, over and over, is called the weight update equation: \(w_{\text{new}} = w_{\text{old}} - \eta\dfrac{\partial L}{\partial w}\).

11 Algebra

Inequalities

An inequality compares two expressions without claiming they're equal — it says one is bigger, smaller, or at least/at most another.

\(x > 5\)  (strictly greater)    \(x \geq 5\)  (greater or equal)

\(x < 5\)  (strictly less)    \(x \leq 5\)  (less or equal)

5 x > 5
An open circle at 5 means 5 itself is not included; a filled circle would mean \(x \geq 5\)
Worked example

Solve \(3x - 4 \leq 11\): add 4 to both sides → \(3x \leq 15\); divide by 3 → \(x \leq 5\). Flip the inequality sign only when multiplying or dividing by a negative number.

AI connection

Inequalities define decision thresholds. A spam filter might classify an email as spam if the predicted probability satisfies \(p \geq 0.5\). Constraints in optimization ("keep this weight within a range") are also written as inequalities.

12 Application

Solving Practical Problems

Every real problem — including AI ones — follows the same four moves.

Understandwhat's being asked Translatewords → equation Solveapply the rules Checkdoes it make sense?
The same four-step process, whether you're solving a word problem or debugging a model
Worked example

Problem: A model correctly classifies 850 out of 1,000 test images. What is its accuracy as a percentage, and how many mistakes did it make?

Understand: we need a fraction turned into a percentage, plus a subtraction.

Translate: accuracy \(=\dfrac{850}{1000}\times100\); mistakes \(=1000-850\).

Solve: accuracy \(=85\%\); mistakes \(=150\).

Check: \(85\%\) of 1000 is 850 ✓, and \(850+150=1000\) ✓.

AI connection

This exact four-step habit is what an engineer runs, mentally, dozens of times a day: reading a metric, translating a business requirement into a loss function, running the numbers, and sanity-checking the result before trusting it.

13 Synthesis

Examples from Artificial Intelligence

Here is how every topic in this lesson combines inside a real, working piece of AI.

1 · A single neuron

\(z = w_1x_1 + w_2x_2 + b\)

\(\hat{y} = \sigma(z) = \dfrac{1}{1+e^{-z}}\)

This uses variables (\(x_1,x_2\)), constants that get learned (\(w_1,w_2,b\)), a function (\(\sigma\)), and the number \(e\) tied to logarithms.

2 · Measuring how wrong the model is

Mean Squared Error: \(L = \dfrac{1}{n}\sum_{i=1}^n (y_i - \hat{y}_i)^2\)

Cross-Entropy Loss: \(L = -\log(\hat{y}_{\text{correct class}})\)

This uses powers (squaring), fractions (the average), and logarithms.

3 · Improving the model — gradient descent

\(w_{\text{new}} = w_{\text{old}} - \eta \cdot \dfrac{\partial L}{\partial w}\)

This is literally an equation being solved again and again, where \(\eta\) (the learning rate) is a small constant that controls the size of each step — and the step size must satisfy an inequality \(0 < \eta < 1\) to avoid the model overshooting.

One full AI training loop, mathematically Input data(numbers) Function f(x)weights & bias Loss (log)how wrong? Update weightsequation + inequality repeat thousands of times
Every concept from this lesson — numbers, functions, equations, logs, inequalities — running together, on repeat
The takeaway

An AI model is not magic. It is numbers flowing through functions, measured by an equation involving logarithms, corrected by another equation bound by an inequality — repeated until the mistakes shrink. Every section in this lesson is a gear in that machine.