Tutorials › Linear Algebra › Counting Vectors and Subspaces Over F_p

Linear Algebra Beyond the Reals · Tutorial 969 of 1000

Counting Vectors and Subspaces Over F_p

Learn how basis coordinates count vectors in finite-field vector spaces and their subspaces, and why dimension and cardinality are different quantities.

Intermediate 10 min read

What You'll Learn

  • Count the vectors in \(\mathbb{F}_p^n\) from the independent choices for each coordinate.
  • Prove that an \(n\)-dimensional space over \(\mathbb{F}_p\) has \(p^n\) elements.
  • Extend a subspace basis to a basis of the full space.
  • Count the vectors in a \(k\)-dimensional subspace as \(p^k\).
  • Calculate how many vectors lie outside a subspace.
  • Distinguish dimension from the number of vectors in a space.

Counting by Coordinates

Over \(\mathbb{R}\), a line contains infinitely many vectors. Over a finite field, every coordinate has only finitely many possible values, so a finite-dimensional vector space has finitely many vectors. The basis gives a direct way to count them: each vector is specified by one scalar for each basis vector. The count depends both on the dimension and on the number of scalars in the field.

Throughout, \(p\) is prime and \(\mathbb{F}_p\) is the field of integers modulo \(p\), with elements represented by \(0,1,\dots,p-1\). Thus \(\mathbb{F}_p\) has exactly \(p\) elements. All vectors and subspaces in this tutorial are over \(\mathbb{F}_p\). A basis is an ordered list that is linearly independent and spans the space; its length is the dimension of the space. Each vector has a unique expression as a linear combination of the vectors in a basis.

Theorem: If \(V\) is an \(n\)-dimensional vector space over \(\mathbb{F}_p\), then \(V\) has exactly \(p^n\) vectors. This includes \(n=0\), for which \(V=\{\mathbf{0}\}\) and \(p^0=1\).

Proof. Fix a basis \((\mathbf{b}_1,\dots,\mathbf{b}_n)\) of \(V\). Every vector \(\mathbf{v}\in V\) has a unique coordinate expression \(\mathbf{v}=a_1\mathbf{b}_1+\cdots+a_n\mathbf{b}_n\), where each \(a_i\in\mathbb{F}_p\). There are \(p\) choices for each coefficient, so there are \(p^n\) coefficient lists. Uniqueness means that different lists give different vectors, and spanning means that every vector is obtained from a list. Therefore the number of vectors is \(p^n\). When \(n=0\), there is one empty coefficient list and its vector is \(\mathbf{0}\), so the same count gives \(p^0=1\). \(\square\)

The count is a consequence of a bijection: assigning a vector its basis coordinates pairs the vectors of \(V\) one-to-one with the \(n\)-tuples in \(\mathbb{F}_p^n\). There are \(p^n\) such tuples because each of the \(n\) positions can be chosen in \(p\) ways. This is a count of vectors, not a statement that the dimension itself is the number of vectors.

Worked Example: Listing Every Vector in \(\mathbb{F}_2^3\)

Each coordinate in \(\mathbb{F}_2^3\) is either \(0\) or \(1\). There are \(2\) choices in each of the \(3\) positions, so the space has \(2^3=8\) vectors. Listing the coordinate choices gives

$$ (0,0,0),\ (0,0,1),\ (0,1,0),\ (0,1,1),\ (1,0,0),\ (1,0,1),\ (1,1,0),\ (1,1,1). $$

There are eight entries in this list, and no other coordinate choices are possible. The dimension is \(3\); the cardinality, meaning the number of elements, is \(8\).

Why a Subspace Has \(p^k\) Vectors

Let \(U\) be a subspace of a finite-dimensional space \(V\). If \(U\) has dimension \(k\), a basis of \(U\) gives \(p^k\) combinations within \(U\). To compare those combinations with all the vectors in \(V\), it is useful to extend the basis of \(U\) to a basis of \(V\). The following argument justifies that extension in the finite-dimensional setting.

Result (Basis extension): Let \(U\) be a subspace of a finite-dimensional vector space \(V\). Any basis of \(U\) can be extended, by adding vectors from \(V\), to a basis of \(V\).

Proof. Write a basis of \(V\) as \((\mathbf{c}_1,\dots,\mathbf{c}_n)\), and start with a basis of \(U\). Process the vectors \(\mathbf{c}_1,\dots,\mathbf{c}_n\) in order. Whenever the current list does not span \(\mathbf{c}_i\), append \(\mathbf{c}_i\); otherwise leave the list unchanged. Each appended vector is outside the span of the list at that moment, so appending it preserves linear independence: a relation with a nonzero coefficient on the new vector would express that vector as a combination of the old list. At the end, every \(\mathbf{c}_i\) is in the span of the resulting list. Since the \(\mathbf{c}_i\) span \(V\), the resulting list spans \(V\) as well. It is both independent and spanning, so it is a basis of \(V\) containing the original basis of \(U\). \(\square\)

Theorem: If \(U\) is a \(k\)-dimensional subspace of an \(n\)-dimensional vector space \(V\) over \(\mathbb{F}_p\), then \(U\) has \(p^k\) vectors. Consequently, \(V\setminus U\) has \(p^n-p^k\) vectors.

Proof. Choose a basis \((\mathbf{u}_1,\dots,\mathbf{u}_k)\) of \(U\). By the basis extension result, add vectors \(\mathbf{w}_1,\dots,\mathbf{w}_{n-k}\) to obtain a basis of \(V\). Each vector of \(V\) has a unique expression \(\sum_{i=1}^{k}a_i\mathbf{u}_i+\sum_{j=1}^{n-k}b_j\mathbf{w}_j\). The vectors in \(U\) are exactly those whose coefficients \(b_1,\dots,b_{n-k}\) are all zero. Indeed, such an expression is a combination of the \(\mathbf{u}_i\), so it lies in \(U\). Conversely, a vector in \(U\) is a combination of the \(\mathbf{u}_i\); uniqueness of coordinates in the extended basis forces all its \(b_j\) to be zero. There are \(p^k\) choices for the \(a_i\), giving \(p^k\) vectors in \(U\). The whole space has \(p^n\) vectors, and \(U\) and \(V\setminus U\) are disjoint and together contain every vector of \(V\). Subtracting gives \(p^n-p^k\) vectors outside \(U\). If \(k=0\), this counts \(U=\{\mathbf{0}\}\); if \(k=n\), it gives zero vectors outside \(U=V\). \(\square\)

The added basis vectors provide the remaining \(n-k\) coordinates in \(V\). Setting all those coordinates to zero describes \(U\); allowing them to vary gives vectors outside \(U\) as well. This is why the subspace count depends on \(k\), even when the surrounding space has dimension \(n\).

Worked Example: A Two-Dimensional Subspace of \(\mathbb{F}_3^4\)

Let \(\mathbf{u}_1=(1,0,1,0)^\top\) and \(\mathbf{u}_2=(0,1,1,0)^\top\), and let \(U=\operatorname{span}\{\mathbf{u}_1,\mathbf{u}_2\}\) in \(\mathbb{F}_3^4\). A combination with coefficients \(a,b\in\mathbb{F}_3\) is

$$ a\mathbf{u}_1+b\mathbf{u}_2=(a,b,a+b,0)^\top. $$

The first two coordinates of this vector are \(a\) and \(b\), so only \(a=b=0\) gives the zero vector. Thus \(\mathbf{u}_1,\mathbf{u}_2\) are independent and form a basis of \(U\). The nine coefficient pairs give these nine vectors, with every coordinate calculated modulo \(3\):

$$ \begin{array}{lll} (0,0,0,0)^\top & (0,1,1,0)^\top & (0,2,2,0)^\top\\ (1,0,1,0)^\top & (1,1,2,0)^\top & (1,2,0,0)^\top\\ (2,0,2,0)^\top & (2,1,0,0)^\top & (2,2,1,0)^\top \end{array} $$

For example, the pair \((a,b)=(1,2)\) gives third coordinate \(1+2=0\) in \(\mathbb{F}_3\). To see how this basis sits inside the ambient space, append \(\mathbf{e}_3=(0,0,1,0)^\top\) and \(\mathbf{e}_4=(0,0,0,1)^\top\). A combination of the four vectors is \((a,b,a+b+c,d)^\top\). For any \((x_1,x_2,x_3,x_4)^\top\), choose \(a=x_1\), \(b=x_2\), \(c=x_3-x_1-x_2\), and \(d=x_4\), all in \(\mathbb{F}_3\). This represents every vector, and the coefficients are determined by these formulas, so the four vectors form a basis of \(\mathbb{F}_3^4\).

Check: for \(a=1,b=2\), the combination is \(\mathbf{u}_1+2\mathbf{u}_2=(1,2,1+2,0)^\top=(1,2,0,0)^\top\) in \(\mathbb{F}_3^4\), matching the list. The subspace has \(3^2=9\) vectors; the ambient space has \(3^4=81\). Therefore \(81-9=72\) vectors lie outside \(U\).

Dimension and Cardinality Are Different

Dimension counts basis vectors. Cardinality counts all vectors. Over a fixed field, the formula \(p^n\) connects the two, but the values need not be equal. Moreover, if the field changes, dimension alone does not determine which of two spaces has more vectors.

Worked Example: The Field Changes the Count

Compare \(\mathbb{F}_2^4\) and \(\mathbb{F}_3^3\). Their dimensions are \(4\) and \(3\), respectively. Their cardinalities are

$$ \left|\mathbb{F}_2^4\right|=2^4=16, \qquad \left|\mathbb{F}_3^3\right|=3^3=27. $$

Thus the space with smaller dimension has more vectors in this comparison. The field size matters: four coordinates with two choices each produce fewer vectors than three coordinates with three choices each. For a single field, however, increasing the dimension increases the count, since \(p^{n+1}=p\cdot p^n>p^n\) for every prime \(p\).

Check: \(16\) is the result of multiplying four factors of \(2\), and \(27\) is the result of multiplying three factors of \(3\). The calculation confirms that neither dimension number alone is the cardinality.

Common Counting Mistakes

Mistake: adding the number of coordinates to the number of field elements. A tempting but incorrect calculation is to say that \(\mathbb{F}_3^4\) has \(3+4=7\) vectors. This treats the four coordinates as if they contributed only four extra choices. In fact, each of the four coordinates can be chosen independently in three ways, so the count is \(3\cdot3\cdot3\cdot3=3^4=81\).

Mistake: confusing dimension with cardinality. A two-dimensional space over \(\mathbb{F}_5\) has \(5^2=25\) vectors, not two. A zero-dimensional space has one vector, not zero: its only vector is \(\mathbf{0}\). These checks are useful because the formula must count the zero vector as well as every nonzero vector.

Mistake: using the ambient dimension for a subspace count. In \(\mathbb{F}_3^4\), a two-dimensional subspace has \(3^2=9\) vectors, not \(3^4=81\). The latter counts the entire ambient space. The subspace uses two basis coordinates, and the other two coordinates in an extended basis must be zero for a vector to lie in that subspace.

These counts are useful whenever finite-field vectors are used as a finite set of possible states or configurations. They also provide a quick consistency check: an \(n\)-dimensional space over \(\mathbb{F}_p\) must have \(p^n\) vectors, and a \(k\)-dimensional subspace must have \(p^k\). The formulas count elements in a specified space or subspace; they do not count how many different subspaces of a given dimension exist.

Check Your Understanding

Use coordinate choices and basis expressions to justify each count.

  1. How many vectors are in \(\mathbb{F}_5^2\)? Explain why the two coordinate choices give that number.
  2. A subspace \(U\) has dimension \(3\) inside a \(5\)-dimensional space over \(\mathbb{F}_2\). How many vectors are in \(U\), and how many are outside it?
  3. Explain why a zero-dimensional vector space over \(\mathbb{F}_p\) has one vector.
  4. Can a three-dimensional space over \(\mathbb{F}_3\) have fewer vectors than a four-dimensional space over \(\mathbb{F}_2\)? Calculate both cardinalities.
  5. In extending a basis of a subspace to a basis of the full space, why must each added vector lie outside the span of the vectors already selected?

Test yourself: Linear Algebra final exam practice

Ready to check what you know? Work a full-length practice final, then open the complete worked solutions.

Want all 1,114 practice problems?

This tutorial covers one topic. Calc Pass covers the full Calculus AB & BC curriculum (the core of Calculus I and II): full review, every practice question, and step-by-step solutions to each one.

QR code to download the Calc Pass app

Get the Calc Pass App

Scan to download and practice on the go, with instant scoring.

Calc Pass Volume 1: 1,114 Practice Questions book cover

Vol. 1: 1,114 Questions

The complete practice question bank, organized by AB & BC topic.

View on Amazon
Calc Pass Volume 2: Solutions Manual book cover

Vol. 2: Solutions Manual

Fully worked solutions to every question in Volume 1.

View on Amazon