Giter Site home page Giter Site logo

linear-code's Introduction

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

> :m + Math.Code.Linear System.Random
> :set -XDataKinds
> c <- randomIO :: IO (LinearCode 7 4 F5)
> c
[7,4]_5-Code
> generatorMatrix c
( 1 0 1 0 0 2 0 )
( 0 2 0 0 1 2 0 )
( 0 1 0 1 0 1 0 )
( 1 0 0 0 0 1 1 )
> e1 :: Vector 4 F5
( 1 0 0 0 )
> v = encode c e1
> v
( 1 0 1 0 0 2 0 )
> 2 ^* e4 :: Vector 7 F3
( 0 0 0 2 0 0 0 )
> vWithError = v + 2 ^* e4
> vWithError
( 1 0 1 2 0 2 0 )
> isCodeword c v
True
> isCodeword c vWithError
False
> decode c vWithError
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

> c = hamming :: BinaryCode 7 4
> generatorMatrix c
( 1 1 0 1 0 0 0 )
( 1 0 1 0 1 0 0 )
( 0 1 1 0 0 1 0 )
( 1 1 1 0 0 0 1 )
> v = encode c e2
> vWithError = v + e3
> Just v' = decode c vWithError
> v' == v
True

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.