Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gmcninch-tufts
GitHub Repository: gmcninch-tufts/2024-Sp-Math190
Path: blob/main/course-contents/notebooks/2024-02-14--ECC-01--ternary-code.ipynb
469 views
Kernel: Python 3 (ipykernel)

Let's create the field k having 3 elements, and the standard vector space V=k^9

K = GF(27); V = VectorSpace(K,9) print(K) print(V)
Finite Field in z3 of size 3^3 Vector space of dimension 9 over Finite Field in z3 of size 3^3

Now let's create a certain 3 dimensional subspace C of V -- a code -- essentially by giving its generator matrix.

C= V.subspace([V([1,0,0,1,1,0,1,1,2]), V([0,1,0,1,0,1,1,2,1]), V([0,0,1,0,1,1,2,1,1])]) C
Vector space of degree 9 and dimension 3 over Finite Field in z3 of size 3^3 Basis matrix: [1 0 0 1 1 0 1 1 2] [0 1 0 1 0 1 1 2 1] [0 0 1 0 1 1 2 1 1]

In order to manipulate the generator matrix as a matrix, we create the MatrixSpace of the right dimensions, and coerce the basis of C into a matrix:

MM = MatrixSpace(K,3,9) G = MM.matrix(C.basis()) G
[1 0 0 1 1 0 1 1 2] [0 1 0 1 0 1 1 2 1] [0 0 1 0 1 1 2 1 1]
def weight(v): r = [x for x in v if x != 0] return len(r) min([ weight(v) for v in C if v != 0])
6

Let's extract the matrix A which is the 3 x 6 matrix for which

G = [ I3 | A ]

A = MatrixSpace(K,3,6).matrix([b[3:9] for b in G]) A
[1 1 0 1 1 2] [1 0 1 1 2 1] [0 1 1 2 1 1]

And let's make the parity check matrix for C

i6=MatrixSpace(K,6,6).one() H=block_matrix([[-A.transpose(),i6]], subdivide=False) H
[2 2 0 1 0 0 0 0 0] [2 0 2 0 1 0 0 0 0] [0 2 2 0 0 1 0 0 0] [2 2 1 0 0 0 1 0 0] [2 1 2 0 0 0 0 1 0] [1 2 2 0 0 0 0 0 1]

And let's check that H * G.T == 0

H * G.T == 0
True
rank(H)
6

And indeed, if we use SAGE to check the right_kernel of the matrix H, we get exactly the subspace C.

H.right_kernel() == C