Foundations to Frontier
Tests
A. Mathematical Foundations › A2 Linear Algebra › Vectors and spaces

Vectors and Vector Operations

Arrows you can add and stretch, and lists of numbers that describe anything. Robot positions, forces, data points, word embeddings and gradients are all vectors.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

An arrow that says “go this way, this far”

A treasure map says: “walk 3 steps east, then 2 steps north”. That instruction is a vector. You can draw it as an arrow, or write it as two numbers: (3, 2).

Adding arrows = doing one move, then the other

First walk (3, 2), then walk (1, 4). Where do you end up? 3 + 1 = 4 steps east and 2 + 4 = 6 steps north: (4, 6). Adding vectors just means doing one move after the other.

Stretching arrows

“Walk twice as far in the same direction” turns (3, 2) into (6, 4). Multiplying a vector by a number stretches it. A negative number turns it around.

Play with it. Move the sliders and watch the orange arrow, u + v:

Adding and scaling vectors
1.50uuvu+v
u + v = (4, 4) · 1.50u = (4.50, 1.50) · ‖u‖ = 3.16

Vectors that aren’t arrows

A list of numbers can describe anything. A fruit could be (weight 150 g, sweetness 7, redness 9). A robot arm could be (joint 1 angle, joint 2 angle, joint 3 angle). Mathematicians call these vectors too, even when there’s no arrow to draw.

In robotics

A Mars rover keeps track of its position as a vector (x, y, z). Every time it drives, it adds the small move vector to its position.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Walk (2, 1), then walk (3, 3). Where are you?
  2. 2. What is 3 × (1, 2)?
  3. 3. A list (age, height, weight) describing a person is…

Level 1: Beginner

★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.

Notation

We write vectors in bold or with an arrow: v\mathbf v or v⃗\vec v. They’re usually written as a column:

v=(32)∈R2,w=(1−42)∈R3\mathbf v = \begin{pmatrix} 3 \\ 2 \end{pmatrix} \in \mathbb{R}^2, \qquad \mathbf w = \begin{pmatrix} 1 \\ -4 \\ 2 \end{pmatrix} \in \mathbb{R}^3

The numbers are the components. R2\mathbb{R}^2 is the flat plane, and R3\mathbb{R}^3 is 3D space.

The operations

Operation Rule Example
Addition add matching components (3,2)+(1,4)=(4,6)(3,2) + (1,4) = (4,6)
Scalar multiplication multiply every component 2(3,2)=(6,4)2(3,2) = (6,4)
Negative flip every sign −(3,2)=(−3,−2)-(3,2) = (-3,-2)
Subtraction add the negative (3,2)−(1,4)=(2,−2)(3,2) - (1,4) = (2,-2)
Zero vector all zeros 0=(0,0)\mathbf 0 = (0,0)

From one point to another

The vector that takes you from point AA to point BB is AB→=B−A\overrightarrow{AB} = B - A. From A=(1,2)A = (1,2) to B=(4,6)B = (4,6): (3,4)(3,4).

Length

By Pythagoras, the length (or norm) of (x,y)(x, y) is x2+y2\sqrt{x^2 + y^2}. So ∥(3,4)∥=5\lVert(3,4)\rVert = 5. Dividing a vector by its length gives a unit vector, which has length 1 and the same direction: (3,4)/5=(0.6,0.8)(3,4)/5 = (0.6, 0.8).

📝 Quick check (Level 1)
0/3 answered
  1. 1. (5, −1) − (2, 3) = ?
  2. 2. Length of (6, 8)?
  3. 3. The vector from A = (2, 2) to B = (5, 6) is…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 30 minUndergraduate students and practising engineers.

Vectors in n dimensions

Rn\mathbb{R}^n is the set of all lists x=(x1,…,xn)\mathbf x = (x_1, \dots, x_n) of real numbers. Operations work component by component:

(x+y)i=xi+yi,(c x)i=c xi(\mathbf x + \mathbf y)_i = x_i + y_i, \qquad (c\,\mathbf x)_i = c\,x_i

They obey familiar rules: x+y=y+x\mathbf x + \mathbf y = \mathbf y + \mathbf x, (x+y)+z=x+(y+z)(\mathbf x + \mathbf y) + \mathbf z = \mathbf x + (\mathbf y + \mathbf z), c(x+y)=cx+cyc(\mathbf x + \mathbf y) = c\mathbf x + c\mathbf y, (a+b)x=ax+bx(a+b)\mathbf x = a\mathbf x + b\mathbf x, x+0=x\mathbf x + \mathbf 0 = \mathbf x. These rules are exactly what defines a “vector space” (A2.1-3).

Linear and convex combinations

A linear combination of vectors v1,…,vk\mathbf v_1, \dots, \mathbf v_k is c1v1+⋯+ckvkc_1\mathbf v_1 + \dots + c_k\mathbf v_k. When the weights are non-negative and sum to 1, it’s a convex combination: a weighted average.

  • Linear interpolation (lerp): (1−t)a+t b(1-t)\mathbf a + t\,\mathbf b moves along the segment from a\mathbf a (at t=0t = 0) to b\mathbf b (at t=1t = 1). Robots use it to plan straight-line motions, and animators use it for in-between frames.
  • Centroid (mean): xˉ=1n∑ixi\bar{\mathbf x} = \frac1n\sum_i \mathbf x_i, the centre of a cloud of points. It’s what k-means clustering computes for each cluster.
🐍 Exercise 1: vector operations from scratch
Write vadd, vscale, lerp and centroid using plain Python lists.

Vectors in NumPy

In practice we use NumPy arrays, where u + v and 3 * u work component by component and run very fast. A whole dataset is a matrix with one vector per row.

Where vectors show up

Field Vector
Data science Each row of a table: a data point with nn features
ML Model parameters θ∈Rd\theta \in \mathbb{R}^d. The gradient ∇L\nabla L is a vector pointing uphill
NLP Word and sentence embeddings in R768\mathbb{R}^{768} and up
Robotics Position, velocity, acceleration, force, torque. Joint configuration q∈Rn\mathbf q \in \mathbb{R}^n
Physics The resultant force is the vector sum of all forces. Zero resultant means equilibrium
📝 Quick check (Level 2)
0/3 answered
  1. 1. lerp(a, b, 0.25) is…
  2. 2. The centroid of (0,0), (6,0), (0,6) is…
  3. 3. Which is a convex combination?

Level 3: Advanced

★★★★☆ Advanced⏱ 35 minGraduate level, with full derivations and proofs.

Points versus vectors

A point is a location, and a vector is a displacement. They behave differently:

  • point − point = vector (B−AB - A)
  • point + vector = point
  • point + point has no meaning: the answer depends on where you put the origin.

But affine combinations, ∑iwiPi\sum_i w_i P_i with ∑wi=1\sum w_i = 1, are meaningful for points.

Theorem

An affine combination of points doesn’t depend on the choice of origin.

Proof. Shift the origin by o\mathbf o, so each point becomes Pi−oP_i - \mathbf o. Then ∑wi(Pi−o)=∑wiPi−(∑wi)o=∑wiPi−o\sum w_i(P_i - \mathbf o) = \sum w_i P_i - (\sum w_i)\mathbf o = \sum w_i P_i - \mathbf o. That’s the same point, written in the new coordinates. ∎ If the weights summed to anything other than 1, the result would move with the origin.

Robotics encodes this difference with homogeneous coordinates: a point (x,y,z,1)(x, y, z, 1) versus a direction (x,y,z,0)(x, y, z, 0). A rigid transform moves points but only rotates directions (R2).

Barycentric coordinates

Every point PP in the plane can be written as P=αA+βB+γCP = \alpha A + \beta B + \gamma C with α+β+γ=1\alpha + \beta + \gamma = 1 for a triangle ABCABC. PP is inside the triangle exactly when all three weights are ≥0\ge 0. This is how graphics cards decide which pixels a triangle covers, and how meshes interpolate values in simulations.

The centroid minimizes squared distance

Theorem

For points x1,…,xn\mathbf x_1, \dots, \mathbf x_n, the point c\mathbf c minimizing ∑i∥xi−c∥2\sum_i \lVert \mathbf x_i - \mathbf c\rVert^2 is the centroid xˉ\bar{\mathbf x}.

Proof. Write xi−c=(xi−xˉ)+(xˉ−c)\mathbf x_i - \mathbf c = (\mathbf x_i - \bar{\mathbf x}) + (\bar{\mathbf x} - \mathbf c) and expand:

∑i∥xi−c∥2=∑i∥xi−xˉ∥2+2(xˉ−c)⋅∑i(xi−xˉ)+n∥xˉ−c∥2.\sum_i\lVert\mathbf x_i - \mathbf c\rVert^2 = \sum_i\lVert\mathbf x_i - \bar{\mathbf x}\rVert^2 + 2(\bar{\mathbf x}-\mathbf c)\cdot\sum_i(\mathbf x_i - \bar{\mathbf x}) + n\lVert\bar{\mathbf x}-\mathbf c\rVert^2.

The middle sum is 0\mathbf 0 by the definition of the mean. The last term is ≥0\ge 0 and is zero only when c=xˉ\mathbf c = \bar{\mathbf x}. ∎ This is exactly why each k-means update moves a centre to the mean of its cluster (D8).

Exercise 3.1: Show that the midpoint of A and B is an affine combination, and find its weights

M=12A+12BM = \tfrac12 A + \tfrac12 B. The weights sum to 1, so MM doesn’t depend on the origin.

Exercise 3.2: Is (1, 1) inside the triangle (0,0), (4,0), (0,4)?

Write (1,1)=α(0,0)+β(4,0)+γ(0,4)(1,1) = \alpha(0,0) + \beta(4,0) + \gamma(0,4) with α+β+γ=1\alpha+\beta+\gamma = 1. This gives β=0.25,γ=0.25,α=0.5\beta = 0.25, \gamma = 0.25, \alpha = 0.5. All are ≥0\ge 0, so yes, it’s inside.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Which expression is meaningful for points A, B?
  2. 2. In homogeneous coordinates, a direction vector has last component…
  3. 3. Barycentric weights (0.5, 0.6, −0.1) mean the point is…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Meaning as direction: embeddings

Word2vec (Mikolov et al., 2013) found that relations between words appear as consistent vector offsets. For example, vking−vman+vwoman\mathbf v_{\text{king}} - \mathbf v_{\text{man}} + \mathbf v_{\text{woman}} is closest to vqueen\mathbf v_{\text{queen}}. Recent research on the linear representation hypothesis (Park, Choe and Veitch, 2024) asks when and why high-level concepts in large language models are encoded as directions. That question is central to interpretability and model steering (F15). You’ll test the idea in Practice Code 5.

High-dimensional vectors behave strangely

In Rd\mathbb{R}^d with large dd, two random directions are almost perpendicular. The cosine of the angle between them is roughly normal with standard deviation 1/d1/\sqrt d. So for large dd, the typical ∣cos⁡θ∣\lvert\cos\theta\rvert is about 2/(πd)\sqrt{2/(\pi d)}. This is why huge numbers of nearly independent features can be packed into an embedding space (“superposition”, F15), and why similarity search needs care (A2.1-2).

🐍 Exercise 2 (research): random vectors are nearly orthogonal
Estimate the average |cos θ| between random vectors as the dimension grows, and compare with √(2/(πd)).

Six-dimensional vectors in robotics

Rigid-body robotics packs angular and linear quantities into 6-vectors: a twist (ω,v)(\boldsymbol\omega, \mathbf v) for velocity, and a wrench (τ,f)(\boldsymbol\tau, \mathbf f) for force and torque. Featherstone’s spatial vector algebra (2008) uses them to compute the dynamics of a robot with nn joints in O(n)O(n) time. That’s what real-time controllers for humanoids and quadrupeds run (R4).

References

  1. H. Grassmann (1844). Die lineale Ausdehnungslehre. (The first general theory of vector spaces.)
  2. J. W. Gibbs and E. B. Wilson (1901). Vector Analysis. Yale University Press.
  3. T. Mikolov, W. Yih, G. Zweig (2013). “Linguistic regularities in continuous space word representations.” NAACL-HLT.
  4. R. Featherstone (2008). Rigid Body Dynamics Algorithms. Springer.
  5. K. Park, Y. J. Choe, V. Veitch (2024). “The linear representation hypothesis and the geometry of large language models.” ICML.
  6. G. Strang (2016). Introduction to Linear Algebra, 5th ed. Wellesley-Cambridge Press. Chapter 1.
  7. S. Axler (2024). Linear Algebra Done Right, 4th ed. Springer (open access). Chapter 1.