CreatingRhythms-0.0.27.0
Copyright(c) Eric Bailey 2024-2025
LicenseMIT
Maintainereric@ericb.me
Stabilityexperimental
PortabilityPOSIX
Safe HaskellSafe-Inferred
LanguageGHC2021

Data.Rhythm.Binary

Description

De Bruijn sequences, and conversion between binary strings and lists of intervals.

Synopsis

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]

necklacesPopCount :: Int -> Int -> [[Int]] Source #

All binary necklaces with a given number of ones of a given length.

>>> necklacesPopCount 3 6
[[1,1,1,0,0,0],[1,1,0,1,0,0],[1,0,1,1,0,0],[1,0,1,0,1,0]]