Tutorials › Linear Algebra › p-Ary Hamming Codes from Projective Columns

Linear Algebra Beyond the Reals · Tutorial 978 of 1000

p-Ary Hamming Codes from Projective Columns

Learn how projective columns produce a p-ary Hamming code and why its length, dimension, and minimum distance follow from the construction.

Intermediate 10 min read

What You'll Learn

  • Normalize nonzero vectors to select one representative from each one-dimensional subspace over a prime field.
  • Count the projective columns used in the parity-check matrix.
  • Prove that the parity-check matrix has full row rank.
  • Derive the code dimension using rank-nullity.
  • Show that the resulting code has minimum distance three.
  • Construct and check examples over the fields with two and three elements.

From Projective Columns to a Code

A parity-check matrix defines a linear code as the set of vectors it sends to zero. The columns determine which coordinate combinations can cancel in that matrix product. For a p-ary Hamming code, the aim is to choose columns so that no one column is zero, no two columns are scalar multiples, and some three columns satisfy a nontrivial relation. These features rule out codewords of weights one and two while ensuring that a codeword of weight three exists.

Let \(p\) be a prime and let \(r\ge 2\). The field \(\mathbb{F}_p\) consists of the residues modulo \(p\), with addition and multiplication performed modulo \(p\). Work in the finite-dimensional vector space \(\mathbb{F}_p^r\). A one-dimensional subspace is a subspace of the form \(\operatorname{span}\{\mathbf{v}\}\) for some nonzero \(\mathbf{v}\in\mathbb{F}_p^r\). Its nonzero vectors are precisely the nonzero scalar multiples of \(\mathbf{v}\).

Definition: For each one-dimensional subspace of \(\mathbb{F}_p^r\), choose one nonzero vector as its representative, and use these representatives as the columns of a matrix \(\mathbf{H}\). The associated p-ary Hamming code is \(\mathbf{C}=\operatorname{Nul}\mathbf{H}=\{\mathbf{x}\in\mathbb{F}_p^n:\mathbf{H}\mathbf{x}=\mathbf{0}\}\), where \(n\) is the number of columns. A convenient representative convention is to scale each nonzero vector so that its first nonzero coordinate is \(1\).

The convention gives exactly one representative from each one-dimensional subspace. Indeed, multiplying a nonzero vector by the inverse of its first nonzero coordinate makes that coordinate \(1\). If two such normalized vectors are nonzero scalar multiples of one another, their first nonzero coordinates occur in the same position, and both equal \(1\); the scalar must therefore be \(1\). Thus the normalized vectors are equal.

The one-dimensional subspaces partition the nonzero vectors of \(\mathbb{F}_p^r\): every nonzero vector belongs to the subspace it spans, and two such subspaces either coincide or share no nonzero vector. Each one-dimensional subspace has \(p-1\) nonzero vectors, one for each nonzero scalar in \(\mathbb{F}_p\). Since \(\mathbb{F}_p^r\) has \(p^r-1\) nonzero vectors, the number of columns is

$$ n=\frac{p^r-1}{p-1}. $$

Parameters of the Construction

A vector \(\mathbf{x}\in\mathbb{F}_p^n\) is a codeword exactly when its coordinates give a linear combination of the columns of \(\mathbf{H}\) equal to \(\mathbf{0}\). The rank of \(\mathbf{H}\) is \(r\): every column is in \(\mathbb{F}_p^r\), and the columns include all standard basis vectors \(\mathbf{e}_1,\dots,\mathbf{e}_r\), which are normalized representatives of their own one-dimensional subspaces. Those vectors span \(\mathbb{F}_p^r\).

Theorem: For prime \(p\) and integer \(r\ge2\), the construction gives a linear code of length \(n=(p^r-1)/(p-1)\), dimension \(n-r\), and minimum distance \(3\). In the usual parameter notation, its parameters are \([n,n-r,3]\) over \(\mathbb{F}_p\).

Proof. The count of one-dimensional subspaces gives \(n=(p^r-1)/(p-1)\). Regard \(\mathbf{H}\) as the matrix of the linear map \(T:\mathbb{F}_p^n\to\mathbb{F}_p^r\) given by \(T(\mathbf{x})=\mathbf{H}\mathbf{x}\). Its image is all of \(\mathbb{F}_p^r\), since the columns include \(\mathbf{e}_1,\dots,\mathbf{e}_r\). Hence \(\operatorname{rank}\mathbf{H}=r\). By the Rank-Nullity Theorem, which states that the dimension of the domain of a linear map between finite-dimensional spaces equals the sum of its kernel dimension and image dimension, \(\dim\mathbf{C}=n-r\).

Define the Hamming weight \(\operatorname{wt}(\mathbf{x})\) to be the number of nonzero coordinates of \(\mathbf{x}\). The Hamming distance between two vectors is the number of coordinates in which they differ, so their distance is \(\operatorname{wt}(\mathbf{x}-\mathbf{y})\). In a linear code, the minimum distance between distinct codewords equals the least weight of a nonzero codeword: a difference of distinct codewords is a nonzero codeword, and each nonzero codeword is its difference from \(\mathbf{0}\).

No column of \(\mathbf{H}\) is zero, so a vector with just one nonzero coordinate cannot satisfy \(\mathbf{H}\mathbf{x}=\mathbf{0}\). Also, two distinct columns are not scalar multiples, because they represent different one-dimensional subspaces. A codeword with exactly two nonzero coordinates would give \(a\mathbf{h}_i+b\mathbf{h}_j=\mathbf{0}\) for distinct columns \(\mathbf{h}_i,\mathbf{h}_j\) and nonzero scalars \(a,b\). Rearranging gives \(\mathbf{h}_i=-b a^{-1}\mathbf{h}_j\), contradicting that the columns are not scalar multiples. Thus every nonzero codeword has weight at least three.

Finally, the columns include \(\mathbf{e}_1,\mathbf{e}_2,\mathbf{e}_1+\mathbf{e}_2\), each normalized as written. They are distinct representatives, and \(\mathbf{e}_1+\mathbf{e}_2-(\mathbf{e}_1+\mathbf{e}_2)=\mathbf{0}\) gives a codeword supported on those three columns, with coefficients \(1,1,-1\). All three coefficients are nonzero in \(\mathbb{F}_p\), including when \(p=2\), where \(-1=1\). Therefore a weight-three codeword exists, and the minimum distance is exactly \(3\). \(\square\)

Worked Constructions

Worked Example: The Projective Columns over \(\mathbb{F}_3^2\)

There are \(3^2-1=8\) nonzero vectors in \(\mathbb{F}_3^2\). Each one-dimensional subspace has \(3-1=2\) nonzero vectors, so there are \(8/2=4\) such subspaces. With the first-nonzero-coordinate convention, their representatives are \((1,0)^{\top}\), \((1,1)^{\top}\), \((1,2)^{\top}\), and \((0,1)^{\top}\). The last three entries \(1,2\) are residues modulo \(3\).

Use these vectors, in that order, as columns:

$$ \mathbf{H}= \begin{bmatrix} 1&1&1&0\\ 0&1&2&1 \end{bmatrix}. $$

The first and fourth columns are \(\mathbf{e}_1\) and \(\mathbf{e}_2\), so \(\operatorname{rank}\mathbf{H}=2\). The length is \(n=4\), and rank-nullity gives dimension \(4-2=2\). For a direct check of a weight-three codeword, take \(\mathbf{x}=(1,2,0,1)^{\top}\). Multiplication modulo \(3\) gives

$$ \mathbf{H}\mathbf{x} = \begin{bmatrix} 1+2\\ 2+1 \end{bmatrix} = \begin{bmatrix} 0\\ 0 \end{bmatrix} \quad\text{in }\mathbb{F}_3^2. $$

The vector has three nonzero entries. The theorem proves there is no nonzero codeword of smaller weight, so this code has parameters \([4,2,3]\) over \(\mathbb{F}_3\).

Worked Example: Binary Columns in Three Dimensions

In \(\mathbb{F}_2\), the only nonzero scalar is \(1\), so each one-dimensional subspace has only one nonzero vector. The seven nonzero vectors of \(\mathbb{F}_2^3\) are therefore the seven representatives. List them as \(\mathbf{e}_1,\mathbf{e}_2,\mathbf{e}_3,\mathbf{e}_1+\mathbf{e}_2,\mathbf{e}_1+\mathbf{e}_3,\mathbf{e}_2+\mathbf{e}_3,\mathbf{e}_1+\mathbf{e}_2+\mathbf{e}_3\). The parity-check matrix, displayed in two blocks to keep the columns readable, is

$$ \begin{bmatrix} 1&0&0&1\\ 0&1&0&1\\ 0&0&1&0 \end{bmatrix} \qquad \begin{bmatrix} 1&0&1\\ 0&1&1\\ 1&1&1 \end{bmatrix}. $$

The two displayed blocks are the first four and last three columns of the same \(3\times7\) matrix. Its first three columns are \(\mathbf{e}_1,\mathbf{e}_2,\mathbf{e}_3\), so its rank is \(3\). Thus the length is \(7\), and the dimension is \(7-3=4\). The first, second, and fourth columns satisfy \(\mathbf{e}_1+\mathbf{e}_2+(\mathbf{e}_1+\mathbf{e}_2)=\mathbf{0}\) over \(\mathbb{F}_2\). Accordingly, the vector with entries \(1\) in positions \(1,2,4\) and \(0\) elsewhere is a codeword: its parity-check product is \((1+0+1,\;0+1+1,\;0+0+0)^{\top}=\mathbf{0}\) modulo \(2\). Its weight is \(3\), verifying the minimum distance. The parameters are \([7,4,3]\).

Worked Example: Thirteen Columns over \(\mathbb{F}_3^3\)

For \(p=3\) and \(r=3\), the number of columns is

$$ n=\frac{3^3-1}{3-1}=\frac{26}{2}=13. $$

The normalized representatives can be listed compactly in three groups: all vectors \((1,a,b)^{\top}\) with \(a,b\in\{0,1,2\}\); the three vectors \((0,1,c)^{\top}\) with \(c\in\{0,1,2\}\); and \((0,0,1)^{\top}\). The first group has \(3\cdot3=9\) vectors, the second has \(3\), and the last has \(1\), giving \(9+3+1=13\). These groups cover all normalized vectors according to whether the first nonzero coordinate is in position one, two, or three.

Among the columns are \(\mathbf{e}_1=(1,0,0)^{\top}\), \(\mathbf{e}_2=(0,1,0)^{\top}\), and \(\mathbf{e}_1+\mathbf{e}_2=(1,1,0)^{\top}\). The standard basis columns \(\mathbf{e}_1,\mathbf{e}_2,\mathbf{e}_3\) show that the parity-check matrix has rank \(3\); hence the code dimension is \(13-3=10\). To check the weight-three relation, give coefficient \(1\) to the \(\mathbf{e}_1\) and \(\mathbf{e}_2\) columns, and coefficient \(-1=2\) to the \((1,1,0)^{\top}\) column. Their contribution to the matrix product is

$$ \begin{bmatrix}1\\0\\0\end{bmatrix} + \begin{bmatrix}0\\1\\0\end{bmatrix} + 2\begin{bmatrix}1\\1\\0\end{bmatrix} = \begin{bmatrix}1+2\\1+2\\0\end{bmatrix} = \begin{bmatrix}0\\0\\0\end{bmatrix} \quad\text{in }\mathbb{F}_3^3. $$

All three coefficients are nonzero, so this is a codeword of weight \(3\). The theorem gives minimum distance \(3\), and the parameters are \([13,10,3]\) over \(\mathbb{F}_3\).

Why One Representative Matters

The construction uses projective columns because scalar multiples point in the same one-dimensional direction. Including more than one vector from that direction would create proportional columns, and proportional columns yield a codeword of weight two. For example, over \(\mathbb{F}_3\), the columns \((1,0)^{\top}\) and \((2,0)^{\top}\) are proportional. The tempting two-coordinate vector \((1,1)^{\top}\) then gives

$$ \begin{bmatrix}1&2\\0&0\end{bmatrix} \begin{bmatrix}1\\1\end{bmatrix} = \begin{bmatrix}1+2\\0\end{bmatrix} = \begin{bmatrix}0\\0\end{bmatrix} \quad\text{in }\mathbb{F}_3^2. $$

This is a weight-two codeword, so that column choice cannot give the minimum distance claimed for a Hamming code. The correction is to keep exactly one representative from each one-dimensional subspace. In \(\mathbb{F}_3^2\), this means four representatives, not three: there are eight nonzero vectors, divided into groups of two nonzero scalar multiples.

The resulting structure explains each parameter. Counting projective directions determines the length; the presence of every standard basis column forces full row rank and therefore determines the dimension; and the absence of zero or proportional columns rules out weights one and two. The three-column relation guarantees that the lower bound is attained. These arguments apply for every prime \(p\) and every \(r\ge2\), without requiring the parity-check matrix to be written out in full.

Check Your Understanding

Use the representative convention and perform all arithmetic in the stated field.

  1. How many one-dimensional subspaces of \(\mathbb{F}_5^2\) are there, and what is the resulting code length?
  2. List the normalized representatives for the one-dimensional subspaces of \(\mathbb{F}_2^2\).
  3. Why do the standard basis columns guarantee that the parity-check matrix has rank \(r\)?
  4. For \(p=3\), verify directly that the columns \((1,0)^{\top}\), \((0,1)^{\top}\), and \((1,1)^{\top}\) give a weight-three codeword.
  5. Explain why two proportional columns would produce a codeword of weight two.

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