@@ -37,11 +37,11 @@ over arbitrary fields, including finite fields. Goes well with the
3737@HaskellForMath@ library and its finite field implementations in
3838@Math.Algebra.Field@. To use extension fields (fields of prime power, i.e.
3939@F_{p^k}@ with @k>1@), use one of the exported finite fields in
40- @ Math.Algebra.Field.Extension@ like 'F16' and its generator 'a16'.
40+ " Math.Algebra.Field.Extension" like 'F16' and its generator 'a16'.
4141
4242As theoretical basis, Introduction to Coding Theory by Yehuda Lindell is used.
4343It can be found at
44- http://u.cs.biu.ac.il/~lindell/89-662/coding_theory-lecture-notes.pdf
44+ < http://u.cs.biu.ac.il/~lindell/89-662/coding_theory-lecture-notes.pdf>
4545-}
4646module Math.Algebra.Code.Linear
4747 ( LinearCode (.. )
@@ -71,12 +71,12 @@ module Math.Algebra.Code.Linear
7171 , e , e1 , e2 , e3 , e4 , e5 , e6 , e7 , e8 , e9 , e10
7272 , char
7373
74- -- * Reexported matrix functions
74+ -- * Reexported matrix functions from "Math.Algebra.Matrix"
7575 , matrix , zero , transpose , fromList , fromLists
7676
77- -- * Reexported finite fields
78- , FiniteField , F2 , F3 , F5 , F7 , F11
79- , ExtensionField , F4 , F8 , F16 , F9
77+ -- * Reexported finite fields from @Math.Algebra.Field@
78+ , F2 , F3 , F5 , F7 , F11
79+ , F4 , F8 , F16 , F9
8080 ) where
8181
8282-- Linear codes from mathematical coding theory, including error correcting
@@ -117,32 +117,37 @@ import Math.Algebra.Matrix
117117 )
118118
119119
120- -- | A Generator is the generator matrix of a linear code, not necessarily
120+ -- | A ' Generator' is the generator matrix of a linear code, not necessarily
121121-- in standard form.
122122type Generator (n :: Nat ) (k :: Nat ) = Matrix k n
123+
124+ -- | A 'CheckMatrix' or parity matrix is the dual of a 'Generator'. It can
125+ -- be used to check if a word is a valid code word for the code. Also,
126+ -- > ∀v∈F^k: cG * H^T = 0
127+ -- i.e. the code is generated by the kernel of a check matrix.
123128type CheckMatrix (n :: Nat ) (k :: Nat ) = Matrix (n - k ) n
124129
125- -- | A [n,k]-Linear code over the field f . The code parameters f,n and k
126- -- are carried on the type level.
127- -- A linear code is a subspace C of f generated by the generator matrix.
130+ -- | A @ [n,k]@ -Linear code over the field @f@ . The code parameters @f@,@n@ and
131+ -- @k@ are carried on the type level.
132+ -- A linear code is a subspace @C@ of @f^n@ generated by the generator matrix.
128133data LinearCode (n :: Nat ) (k :: Nat ) (f :: * )
129134 = LinearCode { generatorMatrix :: Generator n k f
130135 -- ^ Generator matrix, used for most of the operations
131- -- , standardFormGenerator :: Maybe (Generator n k f)
132136 , checkMatrix :: CheckMatrix n k f
133137 -- ^ Check matrix which can be automatically calculated
134138 -- from the standard form generator.
135139 , distance :: Maybe Int
136140 -- ^ The minimal distance of the code. This is the parameter
137- -- d in [n,k,d]_q notation of code parameters. The problem
138- -- of finding the minimal distance is NP-Hard, thus might
139- -- not be available.
141+ -- @d@ in @ [n,k,d]_q@ notation of code parameters. The
142+ -- problem of finding the minimal distance is NP-Hard, thus
143+ -- might not be available.
140144 , syndromeTable :: SyndromeTable n k f
141145 -- ^ A map of all possible syndromes to their error vector.
142146 -- It is used to use syndrome decoding, a very slow decoding
143147 -- algorithm.
144148 }
145149
150+ -- | Extract an Int from a type level 'KnownNat'.
146151natToInt :: forall k . KnownNat k => Proxy k -> Int
147152natToInt = fromInteger . natVal
148153
@@ -154,11 +159,12 @@ instance forall n k f. (Eq f, Fractional f, KnownNat n, KnownNat k, k <= n)
154159instance forall n k f c .
155160 (KnownNat n , KnownNat k , KnownNat (Characteristic f ))
156161 => Show (LinearCode n k f ) where
157- show LinearCode {} =
158- ' [' : show n<> " ," <> show k<> " ]_" <> show c<> " -Code"
162+ show LinearCode {distance = md } =
163+ ' [' : show n<> " ," <> show k<> dist <> " ]_" <> show c<> " -Code"
159164 where c = char (Proxy :: Proxy f )
160165 n = natToInt @ n Proxy
161166 k = natToInt @ k Proxy
167+ dist = fromMaybe " " $ fmap (\ d -> ' ,' : show d) md
162168
163169instance forall n k f .
164170 (KnownNat n , KnownNat k , k <= n , Eq f , FinSet f , Num f , Ord f )
@@ -174,7 +180,9 @@ randomPermMatrix g =
174180 let n = natToInt @ n Proxy
175181 delta i j = if i == j then 1 else 0
176182 (perm,g') = _randomPermutation n g
177- in (fromLists [ [ delta i (perm !! (j- 1 )) | j <- [1 .. n] ] | i <- [1 .. n] ],g')
183+ in (fromLists [ [ delta i (perm !! (j- 1 ))
184+ | j <- [1 .. n] ]
185+ | i <- [1 .. n] ],g')
178186
179187-- | A random code with a generator in standard form. This does not generate
180188-- all possible codes but only one representant of the equivalence class
@@ -340,7 +348,9 @@ calcSyndromeTable c = M.fromListWith minWt allSyndromes
340348 allSyndromes :: [(Syndrome n k f , Vector n f )]
341349 allSyndromes = [(syndrome c e,e) | e <- lighterWords w]
342350
343-
351+ -- | Replace the 'syndromeTable' of a code with a newly calculated syndrome
352+ -- table for the (current) generator. Useful to get a syndrome table for
353+ -- transformed codes when the table cannot be transformed, too.
344354recalcSyndromeTable :: forall n k f .
345355 (KnownNat n , KnownNat k , k <= n , Eq f , FinSet f , Num f , Ord f )
346356 => LinearCode n k f -> LinearCode n k f
0 commit comments