Welcome


to Philip Perry's Perl-Music Page
link to scripts and manual (ZIP archive) at foot of page


This page and the perl scripts described below are a work in progress. The scripts have been written, for my own use but are also to some extent a development in support of, and a spin-off from, a research project looking at basic harmonic structures in music: 'Modulating Oscillatory Systems' and 'Reflection' described in other pages on this website.

The scripts are made available 'as is', without warranty or support (though with heavy commenting for programmers and this guide for the general user) and are of decidedly 'alpha' status and the work of an amateur. Though written for use with the MIDI output from the original Acorn/RISC OS version of the music editor Sibelius, the scripts should be usable with most standard MIDI files. There are also scripts dealing with numbers and sorting at the end of this page.

Basically, the approach is the same as that taken with the companion AWK scripts, (which are older) that is: to convert the music data into textual form and manipulate or examine the textual description of a composition with Perl scripts; but then, in contrast to the analytical AWK scripts, convert the altered text data back into MIDI format so as to be able to load it into a music editor or sequencer. While the AWK scripts focus on analysis, the Perl scripts as well as containing analytical features, also provide for a degree of synthesis.

Initially, the mid2txt perl script was written in 2003 to provide a platform independent method of producing a textual description of a piece of music - via the MIDI format (Musical Instrument Digital Interface). However, now (2005) version 0.02 of mid2txt also functions as the 'doorway' to a set of perl scripts which manipulate mid2txt's text-list output to achieve a number of further ends. Below is an inventory of the scripts and initial aims of this project.

The scripts depend on the powerful functions of the MIDI-perl modules (which require Perl 5.001 or above) written by Sean Burke - freely available from CPAN. Indeed, the above scripts do little more than press buttons (hopefully the right ones) in the right order; handing over the tricky work to the modules. I would like to record my thanks to Sean for making these modules available.

(For a powerful MIDI-to-chord-symbols perl script which also uses the MIDI-Perl modules, see midi2chord by Markus Kollmar.)



Perl Scripts

Introduction

Weaving a path through the scripts, with the different switches, inputs and outputs can be confusing at times, so there is a map below. Essentially, the scripts manipulate music data in textual form; but first the music data originating from a music editor or sequencer in MIDI format, must be converted to text; and perhaps at the end of a process re-converted back to MIDI data. The conversion from, and re-conversion to, MIDI file is handled by the scripts mid2txt and txt2mid - they are the gate-keepers. Between the entry from, and the exit to MIDI format, the remaining scripts offer a number of features for the manipulation of text files (lists) describing musical compositions.

Score-list or Event-list

It is probably helpful to keep in mind that there are two text list formats: Score-lists and Event-lists. Score lists contain information in the form of note-starttime (tick offset from beginning) plus note-duration (in ticks), which is somewhat more musician friendly than event list information in a time-chain of tick offsets from previous events -i.e. note_on and note_off events used by MIDI devices. Ticks or tick division is the basic MIDI unit of time for the user, most often set at 96 pulses (ticks) per quarternote - 96ppqn.

Map of Perl Scripts


                         input-MIDI-file
                                |
                             mid2txt
                      default   |   -e switch
           Score-list<------------------->Event-list
                |                              |
   -------------------    <--txt2txt-->    ----------
   |       |         |                     |        |
 canon  txt2inv   txt2ret  mos2txt<-----txt2mos  m2t2t_awk
           |         |        |                     |
           --------------------> <-----         AWKscripts-->
                      default   |   -e switch
                             txt2mid
                                |
                        output-MIDI-file

At present the principle functions offered by the scripts are:

mid2txt

Converts a MIDI file into textual description in either score list (default) or event list format.

Usage: [perl] mid2txt [-e -h] input-MIDI-file

Output is to STDOUT, which can be redirected to file, for example:
mid2txt -e input-MIDI-file > output-text-file
would send an event list to the output file specified. By default a score list is produced (note starttime + duration) this can be changed to an event list of note_on and note_off commands with the -e switch.

Note: mid2txt and the scripts generally, are quite sensitive to inconsistent input data like excess or missing note_on/note_offs - while there are no doubt weaknesses in the code of these perl scripts themselves, if difficulties arise, the first thing to check is the quality of the input data.

Here is an exerpt from a mid2txt output file: the first bar from J.S.Bach's setting of the chorale 'Ach Gott und Herr', in score list format.


MIDI file output in plain text:
MThd (6 bytes)
 Format 1 (2 tracks)
 Metrical time (TickDiv = 96 ppqn)

Track: 0 
@notes = (   # 2 notes...
 ['key_signature', 0, 0, 0],
 ['time_signature', 0, 4, 2, 24, 8],
 ['set_tempo', 72, 1000000],
);

Track: 1 
@notes = (   # 152 notes...
 ['control_change', 288, 0, 0, 0],
 ['control_change', 288, 0, 32, 0],
 ['patch_change', 288, 0, 0],
 ['control_change', 288, 0, 10, 64],
 ['control_change', 288, 0, 91, 61],
 ['note', 288, 96, 0, 67, 74],
 ['note', 288, 96, 0, 72, 78],
 ['note', 288, 96, 0, 48, 76],
 ['note', 288, 96, 0, 64, 78],
 ['note', 384, 96, 0, 67, 75],
 ['note', 384, 96, 0, 71, 75],
 ['note', 384, 96, 0, 55, 78],
 ['note', 384, 96, 0, 62, 78],
 ['note', 480, 96, 0, 66, 69],
 ['note', 480, 96, 0, 69, 67],
 ['note', 480, 48, 0, 50, 76],
 ['note', 480, 48, 0, 62, 78],
 ['note', 528, 48, 0, 50, 69],
 ['note', 528, 48, 0, 60, 72],
 ['note', 576, 96, 0, 62, 64],
 ['note', 576, 96, 0, 67, 68],
 ['note', 576, 96, 0, 43, 63],
 ['note', 576, 96, 0, 59, 70],
 ['note', 672, 48, 0, 64, 68],
 ['note', 672, 48, 0, 67, 75],
 ['note', 672, 48, 0, 48, 80],
 ['note', 672, 48, 0, 60, 78],
 ['note', 720, 48, 0, 62, 69],
 ['note', 720, 48, 0, 67, 73],
 ['note', 720, 48, 0, 48, 72],
 ['note', 720, 48, 0, 58, 68],
 ['note', 768, 96, 0, 60, 82],
 ['note', 768, 96, 0, 69, 87],
 ['note', 768, 48, 0, 53, 74],
 ['note', 768, 48, 0, 57, 74],
 etc...
);


txt2mos

Usage: txt2mos [-h -t<n,m>] inputfile

Output is to STDOUT, which can be redirected to (path and) file:
txt2mos -t288,288 input-text-list > output-text-file
would send the data to the output file specified.

A full notional 'bar zero' containing any pick-up note/chord precedes bar one; for pieces starting at the beginning of bar one this notional bar zero is empty, thus (m = n - 0). The default is 4/4 time, no pick-up note/chord, the -t switch is not required for these pieces.

At the standard rate of 96 pulses per quarternote (ppqn 96):
Quarternote = 96, Halfnote = 192, Wholenote = 384, Eighthnote = 48, Sixteenthnote = 24, Thirtysecondnote = 12. Thus:

Note1: Text input to txt2mos must be in event list format, so use mid2txt's -e switch when generating the text input file from a MIDI file.

Note2: The script preserves information from the input file's header for use by mos2txt, which can be deleted if not required.

Below is an example txt2mos output file: again J.S.Bach's setting of the chorale 'Ach Gott und Herr'; but now in MOS format. Reading from the left: bars with decimal fractions, accumulated ticks, highest fundamental of the harmonic series consistent with the harmony, the notes/chord of the chorale, followed by the backward '<' and forward leading '>' conjunctions of these harmonic series.


txt2mos  file:  frequencies in hertz : mid C=256Hz
bar      ticks  fundamental - notes - conjunctions
000.750: 0t      64f - 128C 320E 384G 512C - 576>
001.000: 96t     96f - 192G 288D 384G 480B - 576< 576>
001.250: 192t    16f - 144D 288D 352F# 416A - 576< 576>
001.375: 240t    16f - 144D 256C 352F# 416A - 576< 576>
001.500: 288t    48f - 96G 240B 288D 384G - 576< 576>
001.750: 384t    64f - 128C 256C 320E 384G - 576< 576>
001.875: 432t    32f - 128C 224A# 288D 384G - 576< 576>
002.000: 480t     8f - 168F 208A 256C 416A - 576< 576>
002.125: 528t    32f - 160E 192G 256C 416A - 576< 576>
002.250: 576t    24f - 144D 168F 288D 480B - 576< 576>
002.500: 672t    64f - 128C 192G 320E 512C - 576< 576D>
002.750: 768t    48f - 96G 240B 384G 576D - 576D< 576>
003.000: 864t     8f - 104A 256C 384G 512C - 576< 576>
003.125: 912t     8f - 104A 256C 352F# 512C - 576< 576>
003.250: 960t    24f - 120B 288D 384G 480B - 576< 576>
003.375: 1008t   32f - 128C 288D 384G 480B - 576< 576>
003.500: 1056t   16f - 144D 288D 352F# 416A - 576< 576>
003.750: 1152t   96f - 192G 288D 384G 480B - 576< 576>
003.875: 1200t   32f - 192G 288D 384G 512C - 576< 576>
004.000: 1248t   32f - 128C 320E 384G 416A - 576< 576>
004.250: 1344t   16f - 144D 288D 352F# 416A - 576< 576>
004.375: 1392t   16f - 144D 256C 352F# 416A - 576< 576c
004.500: 1440t   48f - 96G 240B 384G - 576< 576>
004.750: 1536t   32f - 160E 256C 384G 512C - 576< 576>
005.000: 1632t   48f - 144D 288D 336F 480B - 576< 576>
005.250: 1728t   64f - 128C 320E 384G 512C - 576< 576D>
005.500: 1824t   48f - 192G 240B 384G 576D - 576D< 768>
006.000: 2016t  128f - 256C 384G 640E - 768< 768>
006.125: 2064t   16f - 240B 256C 384G 640E - 768< 768>
006.250: 2112t   16f - 208A 256C 352F# 576D - 768< 768>
006.375: 2160t   16f - 208A 256C 352F# 512C - 768< 768>
006.500: 2208t   48f - 192G 240B 384G 576D - 768< 768>
006.750: 2304t   32f - 160E 256C 384G - 768< 768>
007.000: 2400t   16f - 176F# 256C 288D 416A - 768< 800>
007.250: 2496t   40f - 200G# 240B 320E 480B - 800< 800>
007.500: 2592t   16f - 208A 256C 320E 512C - 800< 800>
007.625: 2640t   16f - 208A 256C 336F 576D - 800< 832>
007.750: 2688t   64f - 192G 256C 384G 640E - 832< 832>
007.875: 2736t    8f - 168F 256C 416A 672F - 832< 832>
008.000: 2784t   64f - 192G 256C 384G 576D - 832< 960>
008.250: 2880t   48f - 96G 240B 384G 576D - 960< 960>
008.375: 2928t   48f - 96G 240B 336F 576D - 960< 960>
008.500: 2976t   64f - 128C 192G 320E 512C - 960<

Immediately one can see that the variety at the level of the chords/harmony is set within a broader unity revealed by the absence of harmonic series other than of the tonic (8f, 16f, 32f, 64f and 128f) and dominant (24f, 48f and 96f), linked by the conjuction 576 (note D) for the most part. There is one exception 40f - the series of E-major - which occurs in the vigorous harmony closing the piece, where also the conjunctions rise to a higher level and become more varied. The significance of the E-major chord in the key of C-major is discussed in 'Step toward a computational view of tonal music: Modulating Oscillatory Systems'.

mos2txt

Usage: mos2txt [-c<n> -h -t<n,m> -v<n>] inputfile

A full notional 'bar zero' containing any pick-up note/chord precedes bar one, for pieces starting at the beginning of bar one this notional bar zero is empty, thus m = n - 0 (default). The default is 4/4 time, no pick-up note/chord, the -t switch\n is not required for these pieces. Any piece can be input without the -t switch - it just imposes the defaults on the input.

Output is to STDOUT, which can be redirected to file, for example:
mos2txt input-MOS-text-file > output-score-text-file
would send the data to the output file specified.

This script relies on finding header data preserved in the input file, which it passes on to its output file. Essentially, mos2txt reconstructs the original input to txt2mos, adding further notes for the fundamentals and conjunctions. The output score list text file can be converted into a MIDI file by txt2mid and loaded into a music editor or sequencer.

txt2inv

Usage: mid2inv [-a<n> -h -k<n>] input-text-file

Output is to STDOUT, which can be redirected to file:
eg. midinvert -a55 -k input-text-list > output-text-file
would send an inverted score (note) list to the output file (or full path) specified - rotation axis G55, minor to major.

The input score list must be of a format produced by mid2txt -i.e. generated by the Perl-MIDI modules written by Sean Burke and freely available from CPAN - which require Perl 5.001 or above. By default middle C60 is the rotational axis, this can be changed using the -a switch to specify another MIDI note number eg. -a65 for F above middle C60. Any out of range rotations (beyond 0-127) are 8ve shifted into range. Also by default the key-shift is major to minor eg. from C-major to A-minor for the inverted piece, using the -k switch reverses this default shift for minor to major inversions. The inverted score list output by mid2inv can be turned back to MIDI format using txt2mid and then loaded into a music editor or sequencer.

Returning yet again to Bach's chorale setting, the first bar seen above as output from mid2txt is transformed into the score list below. Notice that the key_signature parameter three has been converted to '1' indicating A-minor and the first chord (which above was root position C-major, MIDI note-numbers: 48C, 64E, 67G and 72C) is below a second inversion A-minor chord: 52E, 57A, 60C and 76E. This transformation encapsulates the concept of 'reflecting' an harmonic series, by strict inversion, into an arithmetic series - an inverted or 'descending' harmonic series.


MIDI file output in plain text:
MThd (6 bytes)
 Format 1 (2 tracks)
 Metrical time (TickDiv = 96 ppqn)

Track: 0 
@notes = (   # 2 notes...
 ['key_signature', 0, 0, 1],
 ['time_signature', 0, 4, 2, 24, 8],
 ['set_tempo', 72, 1000000],
);

Track: 1 
@notes = (   # 152 notes...
 ['control_change', 288, 0, 0, 0],
 ['control_change', 288, 0, 32, 0],
 ['patch_change', 288, 0, 0],
 ['control_change', 288, 0, 10, 64],
 ['control_change', 288, 0, 91, 61],
 ['note', 288, 96, 0, 57, 74],
 ['note', 288, 96, 0, 52, 78],
 ['note', 288, 96, 0, 76, 76],
 ['note', 288, 96, 0, 60, 78],
 ['note', 384, 96, 0, 57, 75],
 ['note', 384, 96, 0, 53, 75],
 ['note', 384, 96, 0, 69, 78],
 ['note', 384, 96, 0, 62, 78],
 ['note', 480, 96, 0, 58, 69],
 ['note', 480, 96, 0, 55, 67],
 ['note', 480, 48, 0, 74, 76],
 ['note', 480, 48, 0, 62, 78],
 ['note', 528, 48, 0, 74, 69],
 ['note', 528, 48, 0, 64, 72],
 ['note', 576, 96, 0, 62, 64],
 ['note', 576, 96, 0, 57, 68],
 ['note', 576, 96, 0, 81, 63],
 ['note', 576, 96, 0, 65, 70],
 ['note', 672, 48, 0, 60, 68],
 ['note', 672, 48, 0, 57, 75],
 ['note', 672, 48, 0, 76, 88],
 ['note', 672, 48, 0, 64, 78],
 ['note', 720, 48, 0, 62, 69],
 ['note', 720, 48, 0, 57, 73],
 ['note', 720, 48, 0, 76, 72],
 ['note', 720, 48, 0, 66, 68],
 ['note', 768, 96, 0, 64, 82],
 ['note', 768, 96, 0, 55, 87],
 ['note', 768, 48, 0, 71, 74],
 ['note', 768, 48, 0, 67, 74],
 etc...
);

txt2ret

Usage: [perl] txt2ret [-h -t<n,m>] score-list-file

A full notional 'bar zero' containing any pick-up note/chord precedes bar one, for pieces starting at the beginning of bar one this notional bar zero is empty (thus: m = n - 0 or -t384,384) this is the default, no pick-up note/chord, the -t switch is not required for these pieces . In fact, only the 'm' value - the tick offset before first note/chord - is of significance to the output of the script: it provides a means of moving the retrograde form between varying beat positions, as a compostion might begin with a short note/chord and end with a long note/chord (see below).

Output is to STDOUT, which can be redirected to file:
eg. txt2ret score-list-file > retrograde-score-list-file
would send an retrograde score (note) list to the output file (or full path) specified.

The input score list (not event list) must be in the format produced by mid2txt -i.e. generated by the Perl-MIDI modules and contain multiple note data tracks. The retrograde score list output can be turned back to MIDI format using txt2mid and then loaded into a music editor or sequencer.

txt2ret returns a score list in retrograde order. Staying with the above example chorale, the end of the reversed track (below the cut-->), contains the original first five beats of the compostion, while also shown is the beginning of the track - now containing the last chord:


MIDI file output in plain text:
MThd (6 bytes)
 Format 1 (2 tracks)
 Metrical time (TickDiv = 96 ppqn)

Track: 0 
@notes = (   # 3 notes...
 ['key_signature', 0, 0, 0],
 ['time_signature', 0, 4, 2, 24, 8],
 ['set_tempo', 72, 1000000],
);

Track: 1 
@notes = (   # 152 notes...
 ['control_change', 288, 0, 0, 0],
 ['control_change', 288, 0, 32, 0],
 ['patch_change', 288, 0, 0],
 ['control_change', 288, 0, 10, 64],
 ['control_change', 288, 0, 91, 61],
 ['note', 288, 96, 0, 64, 80],
 ['note', 288, 96, 0, 72, 80],
 ['note', 288, 96, 0, 48, 71],
 ['note', 288, 96, 0, 55, 71],
cut-------------------------->
 ['note', 2832, 48, 0, 53, 74],
 ['note', 2832, 48, 0, 57, 74],
 ['note', 2880, 48, 0, 62, 69],
 ['note', 2880, 48, 0, 67, 73],
 ['note', 2880, 48, 0, 48, 72],
 ['note', 2880, 48, 0, 58, 68],
 ['note', 2928, 48, 0, 64, 68],
 ['note', 2928, 48, 0, 67, 75],
 ['note', 2928, 48, 0, 48, 80],
 ['note', 2928, 48, 0, 60, 78],
 ['note', 2976, 96, 0, 62, 64],
 ['note', 2976, 96, 0, 67, 68],
 ['note', 2976, 96, 0, 43, 63],
 ['note', 2976, 96, 0, 59, 70],
 ['note', 3072, 96, 0, 66, 69],
 ['note', 3072, 96, 0, 69, 67],
 ['note', 3072, 48, 0, 50, 69],
 ['note', 3072, 48, 0, 60, 72],
 ['note', 3120, 48, 0, 50, 76],
 ['note', 3120, 48, 0, 62, 78],
 ['note', 3168, 96, 0, 67, 75],
 ['note', 3168, 96, 0, 71, 75],
 ['note', 3168, 96, 0, 55, 78],
 ['note', 3168, 96, 0, 62, 78],
 ['note', 3264, 96, 0, 67, 74],
 ['note', 3264, 96, 0, 72, 78],
 ['note', 3264, 96, 0, 48, 76],
 ['note', 3264, 96, 0, 64, 78],
);

The above result was obtained using the switch -t384,288, the 288 empty ticks at the beginning were crucial in that without them the first few notes would occur before the control_change commands. However, if the switch -t384,384 was given, the whole piece would have been shifted by one quarternote so as to begin on the beat.

txt2txt

Usage: [perl] txt2txt [-c<s2e|e2s|s2z|s2c<opt>> -h] input-textfile

-c conversion switch, requires s2e, e2s or s2z as arguments: score-list to event-list, event-list to score-list or (type one - multi-track) score-list to (type zero - single track) score-list. The input data must be consistent with the argument given, for example s2z requires a score-list and not an event-list.

Output is to STDOUT, which can be redirected to file: eg. txt2txt -cs2e input-textfile > output-textfile would convert a score list to an event list, sending the output to the file specified. A type 0 event list needs two or three sequential runs: -ce2s -cs2z -cs2e

The s2c switch takes a scorelist file as input and reduces the data to a list of MIDI note numbers (i.e. s2chords) indexed by elapse times at a given granularity. The option is a number specifying the required granuality in ticks (default 48). Thus the command:


  txt2txt -cs2c96 input-textfile > out-putfile
would produce a text list of MIDI note numbers sounding at elapse times 0, 96, 192, 288, etc.., that is every quarternote given the usual tick division of 96ppqn - 96 pulses per quaternote. Another, less common tickdiv is 120ppqn. The script reads the tickdiv from the scorelist header.

By default -i.e. no -c switch given, the script scans the input file for errors and outputs a description of any found. At present only a scan for negative deltatimes is made - a feature sometimes produced by the original Acorn/RISC OS version of Sibelius. After which the user is presented with a Y/N choice to fix the data or exit:


  txt2txt myscore-list-file
  Track 2, negative number:  ['note', 384, -384, 0, 63, 95],
  Track 2, negative number:  ['note', 1536, -1536, 0, 65, 95],
  Track 2, negative number:  ['note', 2880, -2880, 0, 58, 94],
  Fix error(s), Y/N?
  Y /home/mydir/myfile
Anything after 'Y' or 'y' is taken to be the output file path. If no file name or path is specified the default is a file 'Sibfix' in the currently selected/working directory. The script cannot know the correct duration and so examines neighbouring notes beginning at the same moment and adopts the shortest duration found amongst them. It corrects both negative and zero durations which Sib7 (v3.5) produces in pairs.

The script uses the MIDI-perl modules written by Sean Burke (which require Perl 5.001 or above) - available from CPAN.


txt2mid

Usage: [perl] txt2mid [-e -f<filename> -h -p<ppqn> -t<n>] input-file

The default output filename (in cwd) is: txt2mid_MID, the -f switch can be used to change this to a different (path and) filename. (No space between -f and filename and/or "" around filename.)

By default txt2mid expects input in score list format, that is a note list of starttime + duration form. The -e switch changes this default to an event list of note_on and note_off events. By default the division is 96 (pulses per quarternote). The -p switch can be used to change this - as above no spaces or "". And the final default is MIDI type or format '1', which can be changed to type '0' (single track format) with the -t switch. This script reads a textual description of music in MIDI score list format (from mid2txt) or event list format (from mid2txt with -e switch) and converts the text list into a MIDI file via the services of the MIDI-perl modules.

Note: The input text data must be consistent with the switches used. For example, -t0 works only if the input data is all in one track and simply specify -p120 for a text list of division 96ppqn will create a MIDI file with internal inconsistencies.




canon

A script which searches through a piece of music, a sequence of of chords, for a canon at a given pitch and time interval.


 Usage: [perl] canon [-h -p<semitones> -t<ticks>] input-textfile

 -h help, -p pitch interval of canon, -t time interval of canon.
The input text file must be of the form generated by the script txt2txt with the -cs2c switch set, that is a text list of bar numbers, elapse times and MIDI note numbers. Eg:

        BarNum  PollTick NoteNumbers...
          1.50       192 50 66 69 74 78

The input data is scanned for a potential canon at the time interval in ticks and the pitch interval in semitones specified by the -p and -t switches. The defaults are time -t384 ticks (four quarternotes at the common tick division of 96ppqn and pitch -p0, a canon at a unison or octave interval. Pitch intervals of a fourth -p5 and fifth -p7 are common choices but any number 0-11 will work.

Output is to STDOUT, which can be redirected to file, eg:


 canon -t192 -p7 input-textfile > output-textfile
would look for canon at the fifth and separated by two quarternotes (assuming 96 pulses per quarternote) sending the output to the file specified. The canon script will only process one input file per run, multiple input files will overwrite each other.

In use the script will quickly run through a number of likely or desired pitch and time intervals applied to a single output file from txt2txt. On the basis of these result a judgement can be made as to which time and pitch intervals present the richest possibilities. For printing the output, the elapse times can all be sheared off in one operation by a text editor -- if not required; and the bar plus note information load into a multi-column template in a word processor.


baseN

Outputs digit sequences of fixed base number systems from base2 through base36, with decimal equivalent.


    Usage: [perl] baseN -n<number> -b<number>
    
    -i.e.   perl baseN -n256 -b2
will output 0 to 255 numbers in binary (base2) and decimal format.

    Usage: [perl] digseq -h

Numbers output are padded with leading zeros, with individual digits separated by spaces. Depending on the particular combination of (-n)number and (-b)base, a leading column of zeros may be appended to the output. In addition to the digits 0 through 9, the letters A through Z are used in numbers with bases above ten, as required. Redirection ( > myfile ) can be used to send output to file.

digseq

The script finds the number of possible and distinguishable digit sequences of the given mutable number, that is, all the nested configurations of a mutable base number (abr. MBN). For example, the mutable base number thirty (the harmonic series h1 through h30) can be accessed by six alternative three-column digit sequences: 5x3x2 (i.e. h1,2,3,4,5 nesting h10,h15 nesting h30 - ground state), 5x2x3, 3x5x2, 3x2x5, 2x5x3 and 2x3x5, as well as five alternative 'multiplied out' sequences: 15x2, 2x15, 6x5, 5x6 and 1x30 (h1 through h30 - prime state); each physically distinguishable.

First the script works out the divisors and prime factors of the mutable number (specified in the command as a decimal number). Next the script generates all the possible intermediate combinations which lie between the divisor pairs and the prime factors. Finally the script works out the total number of permutations of these combinations and more crucially the number of distinguishable arrangements -- that is valid mutable base digit sequences.

Output is to STDOUT, which can be redirected to file:

    eg. [perl] digseq -n10080 > myfile
would send the list of the number of distinguishable digit sequences to the output file or full path specified.

As a great variety of computational power abounds, it maybe a good idea to start with smaller numbers to gauge time scales vis-a-vis number. It is not so much the magnitude of the number itself but the number of factors and therefore columns, which multiply the range of potential digit sequences the script has to sift -i.e. 2592 (2x2x2x2x2x3x3x3x3) has up to nine columns, while 2951, a prime, has one column. The algorithm used to find the divisors and factors relies on the feature of 'bow waves' found in the Sieve of Eratosthenes and described in chapter seven of 'Journey to the Heart of Music'.

divisor

A script which find the divisors of positive odd and even whole numbers.

Usage: [perl] divisor -n<number> [-h]

Output is to STDOUT, which can be redirected to file:
eg. divisor -n10080 > myfile
eg. divisor -n12347 > home/mydivisors
would send the list of divisors to the output file or full path specified.

As a great variety of computational power abounds, it maybe a good idea to start with smaller numbers to gauge time scales vis-a-vis number size. The algorithm relies on the feature of 'bow waves' found in the Sieve of Eratosthenes and described in chapter seven of 'Journey to the Heart of Music'.




If you have any comments or suggestions my email address is: pjperry@freeuk.com.

Click here to download the scripts: awk and perl scripts plus manuals in a ZIP archive (50Kb).

Click here to download the awk HTML sorting script, entity mapping file and brief instructions.



back to Home Page


Created 28Sept2005
Updated 10Feb2008