The danish composer Per Nørgaard (1932-2025) invented a serial composition method based on a sequence of integers called the “Infinity Series”. The series is most famously used in the symphony “Voyage into the Golden Screen”.
Mathematically speaking, the series is actually a sequence, and is simple to define, e.g. by
a_0 = 0 \\
a_{2n} = -a_n \\
a_{2n + 1} = a_n + 1There are many nice articles online explaining the properties of the sequence and many ways to derive it, so we won’t go into that here. Instead we will present a way to compute the sequence iteratively based on the following equivalent formula:
a_0 = 0 \\
a_{k+1} = (-1)^{\nu_2(k)} (\nu_2(k) + 1 - a_k)Here, \nu_2(k) is the 2-adic valuation of k which can be computed efficiently using a count trailing zeros (CTZ) function (e.g. trailing_zeros in Rust). This gives a way to compute the sequence as an iterator. In Rust, and implementation would look something like this:
pub struct NørgårdsInfinitySequence {
previous: i64,
index: u64,
}
impl NørgårdsInfinitySequence {
pub fn new() -> Self {
NørgårdsInfinitySequence {
previous: 0,
index: 0,
}
}
}
impl Iterator for NørgårdsInfinitySequence {
type Item = i64;
fn next(&mut self) -> Option<Self::Item> {
if self.index > 0 {
let v = self.index.trailing_zeros() as i64;
self.previous = v + 1 - self.previous;
if v.is_odd() {
self.previous = -self.previous;
}
}
self.index += 1;
Some(self.previous)
}
}