Copyright | (c) Eric Bailey 2024-2025 |
---|---|
License | MIT |
Maintainer | eric@ericb.me |
Stability | experimental |
Portability | POSIX |
Safe Haskell | Safe-Inferred |
Language | GHC2021 |
Data.Rhythm.Binary
Description
De Bruijn sequences, and conversion between binary strings and lists of intervals.
Synopsis
- binaryToIntervals :: String -> [Int]
- deBruijnSequence :: Int -> [Int]
- intervalsToBinary :: [Int] -> String
- necklaces :: Int -> [[Int]]
- necklaces' :: (Integral a, Bits a) => Int -> Tree a
- necklacesAllowed :: [Int] -> Int -> [[Int]]
- necklacesPopCount :: Int -> Int -> [[Int]]
Documentation
binaryToIntervals :: String -> [Int] Source #
Convert a binary string to a list of intervals.
>>>
binaryToIntervals "1010010001001000"
[2,3,4,3,4]
deBruijnSequence :: Int -> [Int] Source #
Generate the largest de Bruijn sequence of a given order.
Based on http://debruijnsequence.org/db/greedy.
>>>
deBruijnSequence 4
[1,1,1,1,0,1,1,0,0,1,0,1,0,0,0,0]
intervalsToBinary :: [Int] -> String Source #
Convert a list of intervals to a binary string.
>>>
intervalsToBinary [2,3,4,3,4]
"1010010001001000"
necklaces :: Int -> [[Int]] Source #
All binary necklaces of a given length.
>>>
necklaces 4
[[1,1,1,1],[1,1,1,0],[1,1,0,0],[1,0,1,0],[1,0,0,0],[0,0,0,0]]
necklaces' :: (Integral a, Bits a) => Int -> Tree a Source #
All binary necklaces of a given length, encoded as numbers.
\[ \begin{align*} \sigma(x_1 ... x_n) &= x_2 ... x_n x_1 \\ \tau(x_1 ... x_{n-1}) &= x_1 ... x_{n-1}\overline{x_n} \end{align*} \]
Generate the tree of binary necklaces of length \(n\), starting with \(x = 0^n\) as root, where children of \(x\) are the necklaces of the form \(\tau\sigma^j(x)\) for \(1 \le j \le n -1\).
>>>
flatten (necklaces' 4)
[0,1,3,7,15,5]