🤖 AI Math Unit 1 — Vectors & Geometric EmbeddingsApplied STEM · Vector spaces & column vectors · L1 (Manhattan) and L2 (Euclidean) norms · Dot products & vector projections · Cosine similarity in NLP & vector search · Word and token embeddings (Word2Vec / Transformer)
In Artificial Intelligence and Natural Language Processing, text, images, and audio are mapped to high-dimensional numerical vectors called embeddings. We explore vector geometry, norms, and distance metrics used in modern vector databases.
📊 Math for AI & Data Science — Exam Blueprint & Domain Weighting
Vectors & Embeddings
~25%MATHAI
Matrices & Neural Layers
~25%MATHAI
Gradient Descent & Loss
~25%MATHAI
Probability, Bayes & PCA
~25%MATHAI
Official curriculum weighting and examination domain distribution for Math for AI & Data Science.
● Definition 1.1 — Vector Norms & Distances
For a vector x = [x_1, x_2, \dots, x_n]^T \in \mathbb{R}^nx=[x1,x2,…,xn]T∈Rn: 1. Euclidean ( L_2 L2) Norm: \( \|\mathbf{x}\|_2 = \sqrt{\sum_{i=1}^n x_i^2} = \sqrt{\mathbf{x}^T\mathbf{x}} \). Measures straight-line geometric distance. 2. Manhattan (\( L_1 \)) Norm: \( \|\mathbf{x}\|_1 = \sum_{i=1}^n |x_i| \). Used in Lasso regularization (L1 sparsity). 3. Max (\( L_\infty \)) Norm: \( \|\mathbf{x}\|_\infty = \max_i |x_i| \). Used in adversarial robustness attacks (FGSM).
● Deep Conceptual Intuition — Vectors, Norms & High-Dimensional Embeddings
Linear Structure, Inner Products & Geometric Transformations: In \(\mathbb{R}^n\), the dot product \(\mathbf{u}\cdot\mathbf{v} = \|\mathbf{u}\|\|\mathbf{v}\|\cos\theta = \sum_{i=1}^n u_i v_i\) encodes orthogonality (\(\mathbf{u}\perp\mathbf{v} \iff \mathbf{u}\cdot\mathbf{v} = 0\)) and orthogonal projection \(\operatorname{proj}_{\mathbf{v}}\mathbf{u} = \dfrac{\mathbf{u}\cdot\mathbf{v}}{\|\mathbf{v}\|^2}\mathbf{v}\). For a matrix transformation \(A \in \mathbb{R}^{n\times n}\), \(|\det(A)|\) measures the local volume scaling factor, and \(A\) is invertible if and only if \(\det(A) \ne 0\) (equivalently, all eigenvalues \(\lambda_i \ne 0\)).
Document and query embedding vectors \(\mathbf{q} = [4, 2]^T\) and \(\mathbf{d} = [2, 4]^T\) with cosine similarity \(\cos\theta = \frac{16}{20} = 0.80\).
⊙ Explorer · Embedding Space: Cosine Similarity \(\cos \theta\) & \(L_{1}\) vs. \(L_{2}\) Norm Balls
interactive
Live numerical table for Embedding Space: Cosine Similarity \(\cos \theta\) & \(L_{1}\) vs. \(L_{2}\) Norm Balls
Parameter / Metric
Value
Drag to rotate, scroll to zoom · loads a small 3D library on first use
Compare two embedding vectors \(u\) and \(v\) on the unit \(L_{2}\) circle (indigo) and unit \(L_{1}\) diamond (dashed gray), tracking their dot-product cosine similarity \(\cos(\theta_u - \theta_v)\).
For eigenvalues, \(A\mathbf{v} = \lambda\mathbf{v}\) with \(\mathbf{v} \ne \mathbf{0}\) is equivalent to \((A - \lambda I)\mathbf{v} = \mathbf{0}\). A homogeneous linear system has a non-trivial nullspace vector \(\mathbf{v} \ne \mathbf{0}\) if and only if the matrix \(A - \lambda I\) is singular, yielding the characteristic polynomial \(\det(A - \lambda I) = 0\).
Worked Example 1.A — Cosine Similarity Between Word Embeddings
Problem. In an NLP embedding model, the word vectors for 'king' and 'queen' in a 3-dimensional subspace are \( \mathbf{u} = [0.8, 0.6, 0.0]^T \) and \( \mathbf{v} = [0.6, 0.8, 0.0]^T \). An unrelated word 'apple' has vector \( \mathbf{w} = [0.0, 0.1, 0.99]^T \). Calculate the cosine similarity between 'king' and 'queen', and between 'king' and 'apple'.
Worked Example \(B\) — Vectors, Norms & High-Dimensional Embeddings (Easy Application)
Problem. Consider a simple logistic regression model where the decision boundary is defined by the equation \( 3x + 4y - 12 = 0 \). This equation represents a linear boundary in a 2D feature space. What is the y-intercept of this decision boundary?
▸ Show step-by-step solution
The equation of the decision boundary is given by \( 3x + 4y - 12 = 0 \). To find the y-intercept, we set \( x = 0 \) and solve for \( y \). \nSubstituting \( x = 0 \) into the equation: \n\( 3(0) + 4y - 12 = 0 \)
\( 4y - 12 = 0 \)
\( 4y = 12 \)
\( y = \frac{12}{4} \)
\( y = 3 \)
Therefore, the y-intercept of the decision boundary is 3.
Worked Example \(C\) — Vectors, Norms & High-Dimensional Embeddings (Medium Application)
Problem. A linear transformation is defined by the matrix \(M = \begin{pmatrix} 2 & 1 \\ 3 & 4 \end{pmatrix}\). If an input vector is \(v = \begin{pmatrix} x \\ 1 \end{pmatrix}\), and the output vector after the transformation is \(w = \begin{pmatrix} 5 \\ 7 \end{pmatrix}\), what is the value of \(x\)?
▸ Show step-by-step solution
The linear transformation is given by \(w = Mv\). Substituting the given matrices and vectors, we have:
\[ \begin{pmatrix} 3 \\ 7 \end{pmatrix} = \begin{pmatrix} 2 & 1 \\ 3 & 4 \end{pmatrix} \begin{pmatrix} x \\ 1 \end{pmatrix} \]
Performing the matrix multiplication on the right side gives:
\[ \begin{pmatrix} 3 \\ 7 \end{pmatrix} = \begin{pmatrix} 2x + 1(1) \\ 3x + 4(1) \end{pmatrix} = \begin{pmatrix} 2x + 1 \\ 3x + 4 \end{pmatrix} \]
Equating the corresponding components of the vectors, we get two equations:
1. \(3 = 2x + 1\)
2. \(7 = 3x + 4\)
Solving the first equation for \(x\):
\(3 - 1 = 2x\)
\(2 = 2x\)
\(x = \frac{2}{2}\)
\(x = 1\)
Solving the second equation for \(x\):
\(7 - 4 = 3x\)
\(3 = 3x\)
\(x = \frac{3}{3}\)
\(x = 1\)
Both equations yield \(x=1\). Therefore, the value of \(x\) is 1.
Worked Example \(D\) — Vectors, Norms & High-Dimensional Embeddings (Hard Application)
Problem. Consider two vectors, \( \mathbf{u} = \begin{bmatrix} 3 \\ 4 \end{bmatrix} \) and \( \mathbf{v} = \begin{bmatrix} 1 \\ -2 \end{bmatrix} \). What is the vector representing \( 2\mathbf{u} - \mathbf{v} \)?
▸ Show step-by-step solution
To find the vector \( 2\mathbf{u} - \mathbf{v} \), we first compute \( 2\mathbf{u} \) and then subtract \( \mathbf{v} \) from the result.
\( 2\mathbf{u} = 2 \times \begin{bmatrix} 3 \\ 4 \end{bmatrix} = \begin{bmatrix} 2 \times 3 \\ 2 \times 4 \end{bmatrix} = \begin{bmatrix} 6 \\ 8 \end{bmatrix} \).
Now, we subtract \( \mathbf{v} \) from \( 2\mathbf{u} \):
\( 2\mathbf{u} - \mathbf{v} = \begin{bmatrix} 6 \\ 8 \end{bmatrix} - \begin{bmatrix} 1 \\ -2 \end{bmatrix} = \begin{bmatrix} 6 - 1 \\ 8 - (-2) \end{bmatrix} = \begin{bmatrix} 5 \\ 8 + 2 \end{bmatrix} = \begin{bmatrix} 5 \\ 10 \end{bmatrix} \).
Therefore, the resulting vector is \( \begin{bmatrix} 5 \\ 10 \end{bmatrix} \).
⚠️ Common Exam Traps — Vectors, Norms & High-Dimensional Embeddings
1. Non-Commutativity of Matrix Multiplication & Cross Products: On Mathematics for Artificial Intelligence & Machine Learning, assuming \(AB = BA\) (so expanding \((A+B)^2\) as \(A^2 + 2AB + B^2\) instead of \(A^2 + AB + BA + B^2\)) or forgetting \(\mathbf{u}\times\mathbf{v} = -(\mathbf{v}\times\mathbf{u})\) invalidates matrix proofs.
2. Using Position Vectors Instead of Direction Vectors for Angles: To find the angle at vertex \(B\) of triangle \(ABC\), you must use tail-to-tail vectors \(\overrightarrow{BA}\) and \(\overrightarrow{BC}\), never \(\overrightarrow{AB}\cdot\overrightarrow{BC}\) (which finds the exterior supplementary angle \(180^\circ - B\)).
Error Diagnosis — Common Student Traps vs. Exam-Board Method (Vectors, Norms & High-Dimensional Embeddings)
Common Student Trap
Why It Fails Mathematically
Correct Exam-Board Method
Computing angle at \(B\) using \(\overrightarrow{AB}\cdot\overrightarrow{BC}\)
Vectors are head-to-tail instead of tail-to-tail, giving \(180^\circ - \theta\).
Reverse \(\overrightarrow{AB}\) so both emanate from \(B\): use \(\overrightarrow{BA}\cdot\overrightarrow{BC}\).
Using the same parameter \(t\) for two intersecting 3D lines \(\mathbf{r}_1(t) = \mathbf{r}_2(t)\)
Tests for a simultaneous collision at time \(t\) rather than geometric intersection of paths.
Assign distinct parameters \(\lambda\) and \(\mu\) to the two lines before equating components.
Assuming \((AB)^{-1} = A^{-1}B^{-1}\)
Multiplying \((AB)(A^{-1}B^{-1})\) does not cancel inner factors when \(AB \ne BA\).
Use the shoe-sock reversal law: \((AB)^{-1} = B^{-1}A^{-1}\).
Fast Matrix & Vector Verification (Mathematics for Artificial Intelligence & Machine Learning): Check every \(2\times 2\) or \(3\times 3\) eigenvalue computation using the trace and determinant invariants: \(\sum \lambda_i = \operatorname{tr}(A)\) (sum of diagonal entries) and \(\prod \lambda_i = \det(A)\).
[Practice 1 · Easy] Consider two vectors, \( \mathbf{u} = \begin{bmatrix} 3 \\ 4 \end{bmatrix} \) and \( \mathbf{v} = \begin{bmatrix} 1 \\ -2 \end{bmatrix} \). What is the vector representing \( 2\mathbf{u} - \mathbf{v} \)?
💡 Hint 1 of 3
To find the vector \( 2\mathbf{u} - \mathbf{v} \), we first compute \( 2\mathbf{u} \) and then subtract \( \mathbf{v} \) from the result.