Anastasios Kyrillidis · Rice University

Computational Optimization for AI

Written for Rice University's sophomore course COMP 282, this book connects vectors, matrices, and multivariable calculus to the algorithms that train modern AI models. Across six chapters, it pairs geometric intuition with exact floating-point operation counts and Big-O scaling: from inner products, norms, and least squares to gradient descent, automatic differentiation, eigendecomposition, the power method, Newton's method, and convexity.

Start reading Download the PDF PDF · 238 pages · 2.2 MB Report an error
CourseCOMP 282 (Rice University)
Scope6 chapters · 238 pages
NumberingExact PDF section & figure parity
LicenseCC BY-NC-SA 4.0 / MIT

What the web edition lets you do

01 · GEOMETRY & FLOP PLAYBACK

Drag vectors and step through the sum

Move x and y in the plane with mouse, touch, or arrow keys while formulas update live, or step term by term through p-dimensional inner products and count all 2p - 1 flops.

Example 1.7 · x = [1, -2, 5], y = [3, 1, -3]
i = 1 (1)(3) = 3 sum: 3
i = 2 (-2)(1) = -2 sum: 1
i = 3 (5)(-3) = -15 sum: -14
(1)(3) + (-2)(1) + (5)(-3) = -14
3 mults, 2 adds 5 flops (2p - 1)
Open in Chapter 1 workbench
02 · ZERO-BOILERPLATE CODE TRACE

Step through Python without boilerplate

Read only the core mathematical loop. Step through each line to watch i, result, and the flop count change, or expand show setup to inspect the inputs.

Python · the loop behind 2p - 1 flops
show setup
# Example 1.7
x = [1, -2, 5]
y = [3, 1, -3]
1def inner_product_loop(x, y):
2    result = x[0] * y[0]
3    for i in range(1, len(x)):
4        result += x[i] * y[i]
5    return result
6
7print(inner_product_loop(x, y))
line: - i: - result: - flops: 0
Output -14
Open the code stepper
03 · FULL-WIDTH CODE SESSIONS

Read longer code in full-width sessions

When code is too long for the margin, the reading pauses for a code session: the code, its recorded output and a chart, side by side.

Recorded run · Section 1.3.8
10⁻⁷ s 10⁻⁵ s 10⁻³ s 10⁻¹ s 1 s 10³ 10⁴ 10⁵ 10⁶ 10⁷ vector length p (log scale) 132x Python loop NumPy
p = 10⁷ loop 3.45e-01 s · NumPy 2.62e-03 s
Open the code session

Chapters

  1. CH 01 · p. 1

    Vectors, Norms, and the Cost of Doing AI

    This chapter builds upon our foundational understanding of vector spaces to introduce the tools necessary for measuring complexity, evaluating data and comparing algorithms operating on vectors.

  2. CH 02 · p. 34

    Optimization: from problems to gradient descent

    We introduce the paradigm of optimization by framing real-world tasks as problems of finding the "best" vector.

  3. CH 03 · p. 75

    Matrices: operations, norms, and geometry

    This chapter moves from one-dimensional vectors to two-dimensional matrices, the fundamental structures for representing datasets, transformations, and the very architecture of neural networks.

  4. CH 04 · p. 117

    Matrix inverse and eigendecomposition

    This chapter introduces two of the most powerful concepts in advanced linear algebra: the matrix inverse and the eigendecomposition.

  5. CH 05 · p. 150

    The power method

    This chapter extends the eigendecomposition story of Chapter 4 to arbitrary matrices via the Singular Value Decomposition, then explores the relationship between both decompositions and optimization.

  6. CH 06 · p. 192

    Curvature, Newton's method, and convexity

    We now reverse our perspective and employ eigendecomposition as a powerful analytical tool to dissect the geometry of optimization problems.

License

Text: CC BY-NC-SA 4.0. Code: MIT.

How to cite

Anastasios Kyrillidis, Computational Optimization for AI (COMP 282 Lecture Notes), Rice University, 2026.