Skip to content

Enumerables

amiika edited this page Dec 4, 2019 · 14 revisions

Enumerables

Enumberables are something that can be calculated and played on the fly (which is more fun). Ziffers has some built in methods for calculating sequences such as continued fractions of Pi or triangular sums.

You can also create your own number sequences, so if you happen to know a mathematic formula for creating the perfect melody it is relatively easy to try it out :)

Playing number sequences

Number sequences are any number of numbers that creates a finite or infinite sequence.

Consider a number 369420. This number can be played sequantially as a melody or concurrently as a chord. It can also be played in any key or scale and added some rhythmic variation based on taste or some mathematical relations between the numbers.

Then consider a sequence of numbers 6 18 54 162 486 1458 4374. These numbers again could be played in different ways. These sets of numbers can also be transformed, added, divided, etc. and the base of the numbers can be changed for example from 10 to 6. Number sequences can also be considered as a string that can be modified with rules.

Examples of combining rhythm with the number sequences:

zplay pi, rhythm: "|: eeqq :| h q q |: q e e q q:|"

zplay reverse_sum(589865754), groups: false, lengths: {0=>"q", 1=>"e",2=>"e",3=>"q",4=>"e",5=>"q",6=>"q", 7=>"q",8=>"e",9=>"q"}

Creating new enumerables

Custom enumerables can be created using Ruby's enumerations.

There couple of ways of creating enumerations. Using ranges and lazy enumerations:

# To infinity and beyond!
sums = (1..Float::INFINITY).lazy.collect {|x| (x*x)}
zplay sums, groups: false, sleep: 0.125

Or by creating enumerations using Enumeration class:

def awesomeness(n=6,variance=3)
  mem = [rrand_i(0,7)]
  Enumerator.new do |y|
    until mem.length>=n do
        mem = mem.zip(mem.map{|n| n+rrand_i(-variance, variance)}).flatten
        y << mem.join(" ")
      end
      print "Reached the end of enum!"
    end
  end

  # Loop cycles the finite enumerations
  z1 awesomeness, rhythm: "|: h q q :|: h h :|", synth: :dark_ambience

Integer sequences

There are many beautiful and intrigue integer sequences with musical properties out there. Best place to search for them is OEIS encyclopedia using hear keyword.

Here is a list of sequences as easy to use enumerations:

fibonacci: Fibonacci

Sequence in OEIS: A000045

# Play fibonacci numbers as chords
zplay fibonacci, sleep: 0.25

primes: Prime numbers

Sequence in OEIS: A000040

# Play primes as chords until 500
zplay primes(500), sleep: 0.25

# Play primes as chords until memory runs out
zplay primes, sleep: 0.25

recaman: Recaman

# Play recaman sequence as chords
zplay recaman, sleep: 0.25

hoffQ: Hofstadter Q-sequence

Sequence in OEIS: A005185

zplay hoffQ, sleep: 0.25, groups: false, scale: :minor, rhythm: "|: eeq :| q q |: q ee :|"

sterns: Sterns sequence

Sequence in OEIS: A002487

zplay sterns, sleep: 0.25, scale: :harmonic_minor

dress: Dress sequences

Sequence in OEIS: A001316

zplay dress, synth: :chipbass, key: :d3, scale: :minor_pentatonic, rhythm: "eeqh"

frac2: Remove all factors of 2 from n

Sequence in OEIS: A000265

zplay frac2, sleep: 0.25

binrev(base=2): Reverse binary digits

Sequence in OEIS: A030101

Optional parameter base, default=2.

zplay binrev, sleep: 0.25

reverse_sum(n,base=10): Reverse sum of n in base x

Reverse sum of some numbers creates symmetric patterns. Idea from MathPages.

Optional parameter base, default=10

zplay reverse_sum(313), synth: :fm, groups: false, rhythm: "q q h"

collatz(n): Collatz sequence

Collatz conjecture will create a number sequence that will eventually lead to 1.

zplay (collatz 987654321), groups: false, rhythm: "qqeeee"

triangular: Triangular numbers sequence

Sequence in OEIS: A000217

# Plays chords from triangular number sequence
zplay triangular, sleep: 0.25

quadratic: Quadratic function

# Play values of y as chords
z1 quadratic(1,100,1,-10,20), sleep: 0.2

aprog: Arithmetic progression

Create your own Arithemitc progression.

zplay aprog(1,4,5), sleep: 0.25
print "Done!"

# This one goes forever
zplay aprog(1,4), sleep: 0.25

gprog: Geometric progression

Create your own Geometric progression.

zplay gprog(3,4,5), sleep: 0.25
print "Done!"

# This one goes forever
zplay gprog(3,4), sleep: 0.25

Continued fractions

Infinite Continued fraction is a number sequence like pi or square root of 2. Continued fractions can be calculated using for example general infinite continued fraction algorithm, which was used for enumerables pi, phi and euler.

pi: Pi

Everybody loves π. Now you can listen to it forever (or until your computer crashes).

Sequence in OEIS: A000796

zplay pi, rhythm: [0.125,0.125,0.25]

phi: Phi (Golden ratio)

Sequence in OEIS: A001622

zplay phi, rhythm: "|: q q e e q :| h q q |: h q ee :|"

euler: Euler's number (e)

Sequence in OEIS: A001113

zplay euler, sleep: 0.25
Clone this wiki locally