sequence - generates Morse-Thue, Rabbit, Leibnitz and Cycle sequences
> sequence -c -n 16 A B C # outputs 16 terms of a Cycle A B C A B C A B C A B C A B C A > sequence -l -n 16 A B C D E # 16 terms of a Leibnitz sequence A B B C B C C D B C C D C D D E > sequence -m -n 16 A B # 16 terms of a Morse-Thue-2 sequence A B B A B A A B B A A B A B B A > sequence -m -n 27 A B C # 27 terms of a Morse-Thue-3 sequence A B C B C A C A B B C A C A B A B C C A B A B C B C A > sequence -r A B # outputs 21 terms of a Rabbit sequence A B A A B A B A A B A A B A B A A B A B A > sox `sequence -n 8 snippet1.wav snippet2.wav` longer.wav > play longer.wav # much more interesting than a loop :-) > midisox `sequence -n 8 snippet1.mid snippet2.mid` longer.mid > aplaymidi longer.mid # much more interesting than a loop :-)
This script outputs its arguments in one of a number of particular sequences: Cycle, Leibnitz, Morse-Thue or Rabbit. Apart from the Cycle, the other three sequences are fractal and scale-free.
The Morse-Thue sequence, according to Schroeder, is named in honour of the Norwegian mathematician Axel Thue (1863-1922), who introduced it in 1906 as an aperiodic, recursively computable sequence, and after Marston Morse of Princeton (1892-1977) who discovered its significance in the symbolic dynamics of certain nonlinear systems. The sequence for K=2 can be generated by taking the modulo 2 of the number of one-bits in the binary nonnegative integers; or, starting with a 0, by repeatedly applying the mapping 0 -> 0 1 and 1 -> 1 0; or by repeatedly appending the complement. The first five stages are 0, then 0 1, then 0 1 1 0, then 0 1 1 0 1 0 0 1, then 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0.
With K=3 it can be generated by taking the modulo 3 of the number of one-bits in the binary nonnegative integers; or recursively by adding 1 and then 2, modulo 3. The first three stages are 0, then 0 1 2, then 0 1 2 1 2 0 2 0 1.
The Leibnitz sequence can be generated by counting the one-bits in the binary nonnegative integers; or by repeatedly appending the current sequence with one added to it. The first five stages are 0, then 0 1, then 0 1 1 2, then 0 1 1 2 1 2 2 3, then 0 1 1 2 1 2 2 3 1 2 2 3 2 3 3 4.
The Rabbit sequence (named by Schroeder) arises from Fibonacci's rabbit-problem in the Liber Abaci (1202). The sequence can be generated by starting with 1 and repeatedly applying the mapping 0 -> 1 and 1 -> 1 0; or by starting with the first two stages 1, then 1 0, and then appending to each stage the previous stage, so the next four stages are 1 0 1, then 1 0 1 1 0, then 1 0 1 1 0 1 0 1, then 1 0 1 1 0 1 0 1 1 0 1 1 0.
This is sequence version 1.1
Outputs its arguments in a Cycle (or loop).
Outputs its arguments in a Leibnitz sequence. If N terms are to be output, there must be at least enough arguments (K) so that: 2**K > N
Outputs its arguments in a Morse-Thue sequence. This is the default.
Outputs just a certain Number (42 in this example) of terms in the sequence. The default is 16, except for the Rabbit sequence where the default is 21.
Outputs its arguments in a Rabbit sequence. There must be two arguments (if there are more, the others are ignored).
Prints the Version number.
The current version of sequence is available by http at
www.pjb.com.au/midi/free/sequence
To install sequence, save it to disc,
move it into your $PATH, make it executable, and if necessary
edit the first line to reflect where perl is installed on your system.
1.1, 20091107, mode options don't override -n if they follow it
1.0, 20091005, first working version
Peter J Billam www.pjb.com.au/comp/contact.html
On output, sequence doesn't quote arguments containing spaces;
this is actually a Feature, to allow patterns like:
sequence -c -n 8 "A A A" B # works :-)
But it does make a mess of filenames with spaces, like:
sequence -n 8 "a midi file.mid" another.mid # misfires :-(
"Fractals, Chaos, Power Laws", Manfred Schroeder, Freeman, 1991
www.pjb.com.au/midi/midisox.html
www.pjb.com.au/midi