如何在MATLAB中计算GF(2)上矩阵的左零空间?
Great question! Calculating the left null space of a binary matrix over GF(2) comes up a lot in areas like coding theory, cryptography, and finite field linear algebra. Let’s break this down into manual calculation steps and how to leverage MATLAB’s built-in tools to do it efficiently.
手动计算GF(2)上的左零空间
First, remember the definition: the left null space of matrix ( A ) (over GF(2)) is all row vectors ( \mathbf{y} ) where ( \mathbf{y}A = \mathbf{0} ). A key insight here is that this is exactly the right null space of ( A^T ) (the transpose of ( A )) over GF(2) — because ( \mathbf{y}A = \mathbf{0} ) is equivalent to ( A^T \mathbf{y}^T = \mathbf{0} ).
Here’s a step-by-step manual method:
- Start with your binary matrix ( A ), compute its transpose ( A^T ).
- Perform row reduction modulo 2 on ( A^T ): all addition/subtraction follows GF(2) rules (1+1=0, 0+1=1, no negative numbers).
- Identify the free variables in the reduced row echelon form (RREF) of ( A^T ).
- For each free variable, set it to 1 and the rest to 0, then solve for the pivot variables to get a solution vector ( \mathbf{x} ) to ( A^T \mathbf{x} = \mathbf{0} ).
- Transpose each solution ( \mathbf{x} ) to get ( \mathbf{y} = \mathbf{x}^T ); these ( \mathbf{y} ) vectors form a basis for ( A )’s left null space.
Let’s use an example to make this concrete:
Take ( A = \begin{bmatrix} 1 & 0 & 1 \ 0 & 1 & 1 \end{bmatrix} ) (binary entries):
- ( A^T = \begin{bmatrix} 1 & 0 \ 0 & 1 \ 1 & 1 \end{bmatrix} )
- Row reduce ( A^T ) over GF(2): add row 1 and row 2 to row 3 (since 1+1=0 in GF(2)), resulting in ( \begin{bmatrix} 1 & 0 \ 0 & 1 \ 0 & 0 \end{bmatrix} )
- The third variable is free — set it to 1, then solve: ( x_1 = x_3 = 1 ), ( x_2 = x_3 = 1 ), so ( \mathbf{x} = \begin{bmatrix} 1 \ 1 \ 1 \end{bmatrix} )
- The left null space basis is ( \mathbf{y} = \mathbf{x}^T = \begin{bmatrix} 1 & 1 & 1 \end{bmatrix} ), and you can verify ( \mathbf{y}A = \mathbf{0} ) (all entries are 0 when computed modulo 2).
MATLAB内置函数实现
Yes, MATLAB has built-in support for this via its Galois Field Toolbox (included in most standard MATLAB distributions). Here’s the workflow:
- Convert your binary matrix to a GF(2) object:
Wrap your standard binary matrix into a finite field structure using thegf()function. For example:A = [1 0 1; 0 1 1]; % Your binary matrix A_gf = gf(A, 2); % 2 specifies we're working in GF(2) - Compute the left null space:
As we established earlier, we need the right null space of ( A^T ). Use thenull()function on the transpose of your GF(2) matrix:
The outputright_null_AT = null(A_gf');right_null_ATis a GF(2) matrix where each column is a basis vector for ( A^T )’s right null space. To get the left null space basis vectors (row vectors), just transpose this result:left_null_basis = right_null_AT'; - Verify the result:
You can double-check that every row inleft_null_basissatisfies ( \mathbf{y}A = \mathbf{0} ) over GF(2):
This should return a zero matrix in GF(2).left_null_basis * A_gf
If you don’t have access to the GF Toolbox, you could implement GF(2) row reduction manually, but the built-in functions are way more efficient and less error-prone for larger matrices.
内容的提问来源于stack exchange,提问作者Rahul Sankar

