Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Codec.Arithmetic.Variety
Contents
Description
The optimal (shortest) binary code of a value in a domain of
uniform probability is simply the binary expansion of the index of
the value in that space. The optimal code of two such values is the
index of the pair in the cartesian product of both domains, and so on
for any number of values. This package defines a type Value
with a
Monoid
instance that performs this sort of composition. The only
difference with typical arithmetic
coding on a
rational number code is that for each operation, we operate on the
whole code with infinite precision. For an codec with finite
precision, see the
Variety.Bounded
module.
Synopsis
- encode :: [(Integer, Integer)] -> BitVec
- codeLen :: [Integer] -> Int
- decode :: [Integer] -> BitVec -> [Integer]
- encode1 :: Integer -> Integer -> BitVec
- codeLen1 :: Integer -> Int
- decode1 :: BitVec -> Integer
- newtype Value = Value {}
- mkValue :: Integer -> Integer -> Value
- toBitVec :: Value -> BitVec
- compose :: Value -> Value -> Value
- maxValue :: Value -> Integer
Value-base Interface
encode :: [(Integer, Integer)] -> BitVec Source #
Encode a series of value-base pairs into a single bit vector. A
base must be at least equal to 1
and the associated value must
exist in the range [0..base-1]
.
codeLen :: [Integer] -> Int Source #
Return the length of the code of a sequence of values in the given list of bases in bits.
decode :: [Integer] -> BitVec -> [Integer] Source #
Decode a bit vector given the same series of bases that was used to encode it. Throws an error if the given vector's size doesn't match the given bases.
encode1 :: Integer -> Integer -> BitVec Source #
Consider a positive integer as a bit vector, given its base. The base is only required to determine the number of leading 0s.
codeLen1 :: Integer -> Int Source #
Return the length of the code of a single value in the given base in bits.
Value Type
A value with its base, or the number of possible values that could be (i.e. radix, or variety). The value is like an index and ranges from [0..base-1] while the base is a cardinality is always positive and non-zero.
mkValue :: Integer -> Integer -> Value Source #
Construct from a value and a base. Throws an error if either is negative or if the value is not strictly less than the base.
toBitVec :: Value -> BitVec Source #
Drop the base and consider the value as a bit vector. The base conceptually rounds to the next power of 2.