项目作者: wchresta

项目描述 :
Haskell library for linear codes from coding theory
高级语言: Haskell
项目地址: git://github.com/wchresta/linear-code.git
创建时间: 2018-06-22T11:53:43Z
项目社区:https://github.com/wchresta/linear-code

开源协议:GNU General Public License v3.0

下载


Build Status
Hackage
Hackage Deps

linear-code

Library to handle linear codes from coding theory.

The library is designed to carry the most important bits of information in the
type system while still keeping the types sane.

This library is based roughly on Introduction to Coding Theory by Yehuda Lindell

Usage example

Working with random codes

  1. > :m + Math.Code.Linear System.Random
  2. > :set -XDataKinds
  3. > c <- randomIO :: IO (LinearCode 7 4 F5)
  4. > c
  5. [7,4]_5-Code
  6. > generatorMatrix c
  7. ( 1 0 1 0 0 2 0 )
  8. ( 0 2 0 0 1 2 0 )
  9. ( 0 1 0 1 0 1 0 )
  10. ( 1 0 0 0 0 1 1 )
  11. > e1 :: Vector 4 F5
  12. ( 1 0 0 0 )
  13. > v = encode c e1
  14. > v
  15. ( 1 0 1 0 0 2 0 )
  16. > 2 ^* e4 :: Vector 7 F3
  17. ( 0 0 0 2 0 0 0 )
  18. > vWithError = v + 2 ^* e4
  19. > vWithError
  20. ( 1 0 1 2 0 2 0 )
  21. > isCodeword c v
  22. True
  23. > isCodeword c vWithError
  24. False
  25. > decode c vWithError
  26. Just ( 1 0 2 2 2 2 0 )

Notice, the returned vector is NOT the one without error. The reason for this
is that a random code most likely does not have a distance >2 which would be
needed to correct one error. Let’s try with a hamming code

Correcting errors with hamming codes

  1. > c = hamming :: BinaryCode 7 4
  2. > generatorMatrix c
  3. ( 1 1 0 1 0 0 0 )
  4. ( 1 0 1 0 1 0 0 )
  5. ( 0 1 1 0 0 1 0 )
  6. ( 1 1 1 0 0 0 1 )
  7. > v = encode c e2
  8. > vWithError = v + e3
  9. > Just v' = decode c vWithError
  10. > v' == v
  11. True