variety-0.1.0.2: integer arithmetic codes
Safe HaskellSafe-Inferred
LanguageHaskell2010

Codec.Arithmetic.Variety

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

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.

decode1 :: BitVec -> Integer Source #

Recover the value from a bit vector.

Value Type

newtype Value Source #

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.

Constructors

Value 

Fields

Instances

Instances details
Monoid Value Source # 
Instance details

Defined in Codec.Arithmetic.Variety

Methods

mempty :: Value #

mappend :: Value -> Value -> Value #

mconcat :: [Value] -> Value #

Semigroup Value Source # 
Instance details

Defined in Codec.Arithmetic.Variety

Methods

(<>) :: Value -> Value -> Value #

sconcat :: NonEmpty Value -> Value #

stimes :: Integral b => b -> Value -> Value #

Read Value Source # 
Instance details

Defined in Codec.Arithmetic.Variety

Show Value Source # 
Instance details

Defined in Codec.Arithmetic.Variety

Methods

showsPrec :: Int -> Value -> ShowS #

show :: Value -> String #

showList :: [Value] -> ShowS #

Eq Value Source # 
Instance details

Defined in Codec.Arithmetic.Variety

Methods

(==) :: Value -> Value -> Bool #

(/=) :: Value -> Value -> Bool #

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.

compose :: Value -> Value -> Value Source #

Compose two values into a value of a greater base. This is associative, but not commutative.

maxValue :: Value -> Integer Source #

Maximal possible value as an Integer in the given base.