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

Data.Rhythm.Binary.Necklaces

Description

Binary necklaces, internally encoded as numbers.

References

Synopsis

Ergonomic

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]]

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

All binary necklaces of a given length with allowed parts.

>>> necklacesAllowed [1,2,3] 5
[[1,1,1,1,1],[1,1,1,1,0],[1,1,1,0,0],[1,1,0,1,0],[1,0,1,0,0]]

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]]

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

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

>>> necklacesPopCountAllowed 3 [1,2,3] 5
[[1,1,1,0,0],[1,1,0,1,0]]

Efficient

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]