MIDA
Version 1.0.2.This manual describes MIDA language and its realization (version 1.0.2, 10 September 2016).
Copyright © 2014–2016 Mark Karpov
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled “GNU Free Documentation License”.
[ < ] | [ > ] | [Contents] | [Index] | [ ? ] |
This document describes MIDA language and its primary realization. This program is distributed under GNU General Public License, version 3.
1 What is MIDA? | General description of MIDA language. | |
2 Installation | Instructions to build and install MIDA on Posix-compatible systems. | |
3 Invocation | Command line interface of the program. | |
4 Configuration File | How to change behavior of MIDA via configuration file. | |
5 Interactive REPL | How to use MIDA interpreter in interactive mode. | |
6 MIDA Tutorial | This tutorial teaches concepts of MIDA language. | |
Appendix A GNU Free Documentation License | License for copying this manual. | |
Concept Index | Index of concepts described in this manual. |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
MIDA is a minimalistic declarative language for algorithmic generation of MIDI files. MIDA is not interactive in sense that you cannot control result of its activity in real time, it is intended for producers and should be used with a DAW. MIDA can help you create variative elements in your music in a very simple way. Since MIDI can control a lot of different instruments, power of MIDA is truly great.
Main reason for MIDA development is to create software tool that can be used in such a way that does not change established workflow, so people could use familiar plugins and software instruments.
Currently MIDA can be used to translate source files into ‘.mid’ files, and also in interactive mode that will help you to understand how MIDA language works.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
PATH
, like this:
# in .bashrc or similar export PATH=$HOME/.local/bin:$PATH
cd
into it, and let stack
do its thing:
$ git clone https://github.com/mrkkrp/mida.git $ cd mida $ stack build --copy-bins
$ mida --version MIDA 1.0.2
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
MIDA can work as translator from source code to MIDI files, or as interactive environment (interpreter) that functions much like REPL. If no input file is supplied, MIDA starts in interactive mode by default. Otherwise, one should use command line options to start MIDA in interactive mode.
mida [-i|--interactive] [-s|--seed SEED] [-q|--quarter TICKS] [-b|--beats BEATS] [-o|--output OUT] [--license] [--version] [FILES]
Here’s the complete list of command line options:
-h
, --help
Shows information regarding invocation parameters.
-i
, --interactive
Starts MIDA in interactive mode. This option effectively disables all other supplied options, because they only make sense in non-interactive (batch) mode.
-s
seed, --seed
seedSets seed for MIDI generation. You can generate identical MIDI
files if you use the same seed. Default value is 0
.
-q
ticks, --quarter
ticksSets number of ticks for quarter note, default value is
24
.
-b
beats, --beats
beatsSets total time of result MIDI file as number of beats (quarter
notes), default value is 16
.
-o
output, --output
outputSpecifies output file. Default value is built from base name of supplied file and extension ‘.mid’.
--license
Show license of the program.
--version
Show version of the program.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
MIDA can be customized to some extent with help of configuration file. One should create the file in his/her home directory. This directory will be different on different operating systems. On GNU/Linux machines it would be something like ‘/home/username/.mida.yaml’, while Windows users should create the file ‘C:\Users\username\.mida.yaml’.
The configuration file is a plain YAML file.
The following table describes all variables that can be assigned in the configuration file.
prog
Index of program that will be used in preview. Default value is
0
. You can change this variable from within the MIDA REPL with
‘:prog’ command (see section Interactive REPL).
progop
Command line option of external program that will be used for
preview. By default, MIDA uses timidity
, so value of this
variable is ‘--force-program’.
prompt
Prompt that will be used in MIDA REPL. Default value is ‘> ’.
prvcmd
Command that will be used to invoke external program for preview. You can use this variable to supply some options as well. Default value is ‘timidity’.
prvlen
How many elements are displayed after evaluation of given principle. Default value is ‘18’. You can also interactively change the value form interactive REPL (see section Interactive REPL).
src
Default name of currently active file. If you load some file, this value is automatically set to its file name. It’s used to generate some file names when you decide to save your session. Default value is ‘foo.da’.
tempo
Tempo that’s used in preview. Default value is ‘120’, but you can easily change it with ‘:tempo’ command (see section Interactive REPL).
tempop
Command line option of external program that will be used for
preview. Default value is ‘--adjust-tempo’, because default program
for preview is timidity
.
verbose
This indicates whether or not display simplified principle before printing the final result of evaluation. Default value is ‘true’.
Here is complete example of ‘.mida.yaml’ file:
# # MIDA Configuration File # prompt: "mida> " prvlen: 20 verbose: false
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In interactive mode you can enter principles for evaluation and special
commands to control MIDA environment. MIDA has useful editing
capabilities, similar to those of some shells (bash
for
example). It also has “smart” tab-completion, that is, completion’s
logic depends on contents of the input line.
It’s allowed to put comments in MIDA source files or in interactive environment. MIDA uses Unix shell comment style: line comments starts with ‘#’.
Interpreter supports multiline input. It automatically detects unbalanced parenthesis, braces, brackets. If you want to continue writing a principle on the next line, end current line with a comma ‘,’. Since comma is allowed only between elements of a principle, MIDA knows that current principle is not completed.
Evaluation of principles will be described later in this document (see section MIDA Tutorial). Now, let’s examine all the special commands that are available in MIDA interactive sessions. All the commands begin with colon ‘:’ and are case-sensitive.
Change working directory. Since MIDA allows to load, save, and generate various files, it’s sometimes convenient to be able to change directories.
Restore default state of environment removing all (non-standard) definitions from the memory.
Print definition of specified symbol. This command can take several arguments (names of definitions to print). For example:
> :def dur0 vel0 dur0 = {5 6 $ 17} vel0 = {50..70}
Show help text. For example:
> :help Available commands: :cd Change working directory :clear Restore default state of environment :def Print definition of given symbol :help Show this help text :license Show license :load Load definitions from given file :make Generate and save MIDI file :prog Set program for preview :prv Play the score with external program :prvlen Set length of displayed results :purge Remove redundant definitions :pwd Print working directory :quit Quit the interactive environment :save Save current environment in file :tempo Set tempo for preview :udef Remove definition of given symbol
Load definition from specified source files. When something is defined, you usually get some helpful feedback:
> :load projects/music/tst1.da • «pch0» • «dur0» • «vel0» • «pch1» • «dur1» • «vel1» • «pch2» • «dur2» • «vel2» "/home/mark/projects/music/tst1.da" loaded successfully.
Note that you can specify as many source files as you wish, they will be loaded successively and all definitions from those files will be available in the interactive environment. Nevertheless, remember that definitions from one file may be silently redefined by definitions from another file if they have the same names.
One of the most common commands is ‘:make’. It produces MIDI file based on current state of MIDA environment. This command takes up to four arguments. If you don’t supply any of them, corresponding default value will be used.
First argument is seed for generator of pseudo-random numbers. We
work with seeds because they allow to generate identical scores given
the same seeds (it’s useful sometimes). Default value of this argument
is 0
.
Second argument is number of ticks per quarter note. This value
allows to convert abstract numbers that represent duration into
conventional notes. Default value is 24
, and usually you don’t
want to change it unless you’re working with extremely complex rhythms.
Third argument is total length of composition as number of quarter
notes. This parameter is also known as “beats” (although in reality, a
beat is not always equal to quarter note). Default value is 16
.
The last parameter is file name of MIDI file. If it’s not supplied, system will try to guess the name. Guessing algorithm is the same as for ‘:save’ command but extension will be replaced with ‘.mid’.
See the stuff in action:
> :make 1 24 128 MIDI file saved as "/home/mark/projects/music/tst1.mid".
Set program for preview. MIDA uses external programs to play generated
MIDI files. This command temporarily changes program (timbre). Default
value is 0
, but you can choose different default value via
configuration file (see section Configuration File).
Play current score with help of external program. To use this command
you need to install program that can generate sound from MIDI files and
has command line interface. Default choice is timidity
. MIDA is
already configured to work with timidity
. This is a useful
program for this sort of job because it provides some console output and
playing can be ceased with Ctrl-C command (on
Posix-systems). Also, you can use ‘:prog’ and ‘:tempo’
commands to set program (timbre) and tempo respectively.
The ‘:prv’ command itself takes up to three arguments, similar to those of ‘:make’ command: seed, ticks per quarter note, and total length.
This command allows to specify how many elements of evaluated principle
will be displayed. Default value is 16
, but you can choose
different default value via configuration file (see section Configuration File).
> 1 ≡ 1 ⇒ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1… > :prvlen 20 > 1 ≡ 1 ⇒ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1…
You can “purge” all useless definitions from memory using ‘:purge’ command. A definition is considered useless if it’s not used as a part of a top-level definition. Here’s an example:
> α = β β = 12 Y = 13 dur0 = α • «α» • «β» • «Y» • «dur0» > :def Y Y = 13 > :purge Environment purged. > :def Y Y = > :def β β = 12
What happened here? Well, we see that dur0
is a top level
definition (see section Definitions). α
is used in dur0
’s
principle and β
is used in α
’s principle. So, α
and
β
are necessary definitions. What’s about Y
? It does not
participate in principle building of any top-level definition. System
considers it redundant, so it purges it.
Quite obviously, it prints current working directory.
Quit the interactive environment.
Save the current environment in MIDA source file. As you compose music with MIDA, you will need to save all existing definitions to hard disk. You can then edit them or load them into MIDA to continue your work. It’s quite easy to accomplish with ‘:save’ command. This command takes an optional argument — file name. If you don’t supply the file name, the system will try to guess it. It will be file name of loaded source file, last used file name, or default value (it can be specified in configuration file (see section Configuration File). I recommend ‘.da’ as file name extension for MIDA source files.
Set tempo for preview. Default value is 120
, but you can choose
different default value via configuration file (see section Configuration File).
Remove definition of given symbol. Although standard way to remove definition is ‘definition_name =’, i.e. assigning empty principle to it, you may find ‘:udef’ command more convenient, because it takes arbitrary number of arguments and it also frees memory that was allocated for specified definitions.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Now that you know all the basic information about the interpreter, we can start our journey into the magic world of MIDA.
MIDA is minimalistic, declarative language. In fact, it is so simple that any statement that has valid syntax will produce valid result. MIDA statement only has to pass parser, that’s all. Declarative nature of MIDA means that you describe relations between principles that will be turned into actual MIDI data without describing control flow.
6.1 Literal Values | Most basic elements in MIDA. | |
6.2 Principles | Some theoretic notions. | |
6.3 Definitions | How to create re-usable pieces of code. | |
6.4 Ranges | How to write long series of numbers concisely. | |
6.5 Multivalues | Elements that have multiple values at the same time. | |
6.6 Sections | Elements that are containers for other elements. | |
6.7 Conditional Multivalues | Workhorses of algorithmic composition. | |
6.8 Polymorphic Operators | How to combine elements? |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Start the interactive environment. Now you should be looking at something like this:
[mark@arch ~]$ mida MIDA Copyright © 2014–2016 Mark Karpov This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions; see GNU General Public License for details. MIDA Interactive Environment 1.0.2 >
You can try your powers right away. Remember, MIDA is all about sequences of numbers. Numbers can represent different things:
Let’s start from how you can enter the numbers at the prompt and what you get as a result.
6.1.1 Duration | How duration is represented in MIDA. | |
6.1.2 Velocity | How velocity is represented in MIDA. | |
6.1.3 Pitch | Note alias and other. | |
6.1.4 Additional Parameters | Other parameters. |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Duration in MIDI is relative to ticks per quarter note (TPQ). TPQ
is set before translation either via command line options or as a
parameter of ‘:make’ and ‘:prv’ commands. As I said, default
value is 24
, so try to work with this in mind.
So, if quarter note is 24
ticks, whole note will be 96
ticks, while eight note will be 12
ticks, etc. You can also use
any number in between creating rather strange rhythms. Remember that you
can use numbers greater than 127
for duration, so there is no
limits.
Let’s enter a number:
> 24 ≡ 24 ⇒ 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24…
So, we see that we can enter literal values! However, the result may look a bit strange, but ignore this repetitiveness for now.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Since MIDI format is piano-oriented, velocity in our case means
loudness. Again, to write down velocities we use plain numbers. Valid
values are form 0
to 127
, where 0
means silence,
while 127
signifies loudest note.
Although you can enter literals greater than 127
, they are not
guaranteed to be processed correctly.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Sure, you can use the same plain numbers from 0
to 127
for
pitch, but it’s a bit inconvenient. MIDA has predefined “alias” for that
case. Since MIDA doesn’t work with negative numbers, we use alias where
octaves start from 0
. So c0
corresponds to 0
,
cs0
to 1
, and so on: one semitone per number.
Please note that there is no standard way to number octaves in MIDI. The
MIDI standard only says that note with index 60
must be
Middle C. We’ve chosen zero-based system for reasons that I have
described earlier, some software starts numeration from -2
.
Enter any alias into MIDA and see for yourself that it’s just like entering corresponding MIDI code (note that all alias are case-sensitive):
> c5 ≡ 60 ⇒ 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60…
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Parameters like modulation, breath, aftertouch, and pitch bend are called additional parameters. In section Definitions we will explain why they are called so, but for now it’s important to understand how you can use literal values to represent these parameters and their change in time.
Additional parameters are written either as plain numbers from 0
to 127
or as sum of predefined constant called modifier and
plain number.
Numbers from 0
to 127
without modifier represent value
that doesn’t change during length of note. Modifiers tells MIDA to use
special forms of modulation, while number that’s added to modifier
signifies intensity of such a modulation.
This table describes forms of modulation that exist in MIDA:
Ascending change for whole duration of note.
Condescending change for whole duration of note.
Ascending change for first half of note’s duration and condescending change for the second half.
Condescending change for first half of note’s duration and ascending change for the second half.
So, for example, the command ‘_ud + 127’ represents ascending
change of some parameter for half duration of given note and
condescending change back to initial value for another half. 127
signifies maximal possible intensity of this modulation.
Symbols ‘_u’, ‘_d’, ‘_du’, and ‘_ud’ represent plain numbers, you can check it in your REPL, but don’t use “magic numbers”, because they may be changed in future versions of MIDA.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Smallest piece of composition in MIDA is called element. Now we know at least one kind of element: literal values. Realization of literal value is just its value. Bear with me and all the stuff will be clear to you.
The thing we enter in interactive sessions is called principle. A principle can consist of zero or more elements. These elements may be separated by commas ‘,’. Let’s try some principles:
> 1, 2, 3 ≡ 1 2 3 ⇒ 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3… > c5 d5 e5 f5 g5 a5 b5 c6 ≡ 60 62 64 65 67 69 71 72 ⇒ 60 62 64 65 67 69 71 72 60 62 64 65 67 69 71 72 60 62…
So, we enter a principle and MIDA prints its realization. Realization of principle is built this way:
Realization can be either infinite sequence of non-negative numbers or bottom ‘⊥’. Bottom is realization of empty principle and it is said to be less defined than any other result.
> ≡ ⇒ ⊥
In the next section we will see other rôle of bottom.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
I’ve said that it’s quite hard to write an incorrect statement in MIDA. Let’s prove it. Here’s my attempt:
> foo ≡ ⇒ ⊥ > asdfasdflk ≡ ⇒ ⊥ > 1 2 rere 5 ≡ 1 2 5 ⇒ 1 2 5 1 2 5 1 2 5 1 2 5 1 2 5 1 2 5…
So, MIDA thinks that these things are realized to ⊥
, they can be
even put inside a principle without any obvious harm.
The thing is that MIDA considers any alpha-numeric sequence of characters that does not begin with a number identifier (from MIDA 0.4.1 identifiers can contain underscore ‘_’). Identifier has associated definition. Definition can hold a principle and default value of any definition is empty principle. You can combine definitions to build really complex principles. Keep in mind that names of the definitions are case-sensitive.
Definitions are created by putting definition name on the left side of equation sign ‘=’ and a principle on the right of the sign. Let’s give it a go:
> α = 1 2 3 • «α» > α ≡ 1 2 3 ⇒ 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3… > α 5 ≡ 1 2 3 5 ⇒ 1 2 3 5 1 2 3 5 1 2 3 5 1 2 3 5 1 2…
Remember that definitions are like recipes how to create a principle and they live in interactive environment. So we can change a definition and all other definitions which use it will change accordingly:
> α = 5 β = 6 Y = α β • «α» • «β» • «Y» > Y ≡ 5 6 ⇒ 5 6 5 6 5 6 5 6 5 6 5 6 5 6 5 6 5 6… > β = 10 • «β» > Y ≡ 5 10 ⇒ 5 10 5 10 5 10 5 10 5 10 5 10 5 10 5 10 5 10…
And since all possible definitions are bound to empty principles, we can even design our principles in top-down manner, using definitions that we haven’t defined yet.
Now you’re ready to create your first piece of music, but before you do
it I should explain something about top-level definitions. These
are special names that represent duration, velocity, pitch, and other
parameters of voices. There may be up to 16
different voices in a
MIDA score.
The names are as following:
dur_
— duration;
vel_
— velocity;
pch_
— pitch;
mod_
— modulation;
bth_
— breath;
aft_
— aftertouch;
bnd_
— pitch bend.
Replace ‘_’ with index of desired voice, valid values are from
0
to 15
.
Let’s create some music (or “music”, creation of real music is left as an exercise for the reader):
> dur0 = 24 vel0 = 70 pch0 = c5 d5 e5 f5 g5 a5 b5 • «dur0» • «vel0» • «pch0»
It’s as simple as that! Other top-level definitions hold empty
principles, so their realization is bottom ⊥
, thus they will be
ignored. Additional parameters like modulation, breath, aftertouch, and
pitch bend may be omitted (that’s why they are called “additional”) — in
this case there will be no corresponding events in result MIDI file. Use
‘:make’ command to create a MIDI file:
> :make 0 24 14 MIDI file saved as "/home/mark/foo.mid".
We can play the music from MIDA interactive environment right now! Here
is how (make sure that you have installed timidity
, and
configured it correctly):
> :prv 0 24 14 MIDI file saved as "/tmp/foo.mid". Requested buffer size 32768, fragment size 8192 ALSA pcm 'default' set buffer size 33868, period size 3760 bytes Playing /tmp/foo.mid MIDI file: /tmp/foo.mid Format: 1 Tracks: 1 Divisions: 24 Playing time: ~9 seconds Notes cut: 0 Notes lost totally: 0
Play with this example a little more. Try changing the definitions. Try
to set different tempo and different timbre using ‘:tempo’ and
‘:prog’ commands (see section Interactive REPL). Try to define several
voices that sound simultaneously (define dur1
, vel1
, and
pch1
).
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Now that you know all the basics, we can talk about advanced methods of element manipulation. Simplest such a method is range. Range in MIDA is written as two numbers separated by two commas ‘..’ (without space between them). Range notation represents collection of successive natural numbers from left-side number to right-side number inclusively.
> 1..3 ≡ 1 2 3 ⇒ 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3… > 5..2 ≡ 5 4 3 2 ⇒ 5 4 3 2 5 4 3 2 5 4 3 2 5 4 3 2 5 4…
Although you cannot specify step between resulting elements, you can add a number to all elements of a principle or multiply all the elements by given number. How? Keep reading!
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
So far, we’ve worked only with literal values. But MIDA knows one more kind of element: multivalue. Multivalue is such an element that has many values at the same time. You know, just like electron exists in different positions around atomic nucleus. Realization of multivalue is a pseudo-random value chosen from all possible variants.
Multivalue is written as collection of possible values inside of braces:
> {1..3} ≡ {1 2 3} ⇒ 1 2 2 2 3 1 2 1 1 1 2 2 3 1 3 1 2 1…
As you can see, the same element is replicated, but its realized value is different for every instance. Here we have uniform distribution, but you can change it with help of repetition:
> {1 1 2 3} # 1 → 50%, 2 → 25%, 3 → 25% ≡ {1 1 2 3} ⇒ 1 1 1 1 2 1 3 3 1 3 3 3 1 2 1 3 3 1… > {1 $ 8, 2 3} # 1 → 80%, 2 → 10%, 3 → 10% ≡ {1 1 1 1 1 1 1 1 2 3} ⇒ 1 1 2 1 3 1 1 3 1 1 3 3 1 1 1 1 1 1…
Basic operators work together! (‘$’ operator will be considered later, see section Repetition.) You can put a multivalue into another multivalue too:
> {1 {2 3}} # 1 → 50%, 2 → 25%, 3 → 25% ≡ {1 {2 3}} ⇒ 3 1 1 1 1 2 1 1 1 2 1 2 1 1 3 1 3 2…
1
has probability 50%, and {2 3}
has probability
50%. Inside {2 3}
every element has equal probability 50%, so
result probabilities look like: 1
— 50%, 2
— 25%, 3
— 25%.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Section is another kind of element. Section is collection of elements that can be manipulated as one element.
Sections are written as a principle inside of square brackets (‘[’ and ‘]’):
> [1..3] ≡ 1 2 3 ⇒ 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3…
Typical example of their use is in juxtaposition with multivalues. With help of sections you can easily use sequence of elements as part of multivalue:
> {1 2 [3..5]} ≡ {1 2 [3 4 5]} ⇒ 3 4 5 3 4 5 1 2 1 2 3 4 5 2 3 4 5 1…
So here we have 1
with probability 1/3
, 2
with
probability 1/3
and 3 4 5
with the same probability. We
could use multivalues in the section too to get arbitrary complex
structures.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
One step forward is conditional multivalues. These are just like multivalues, but they depend on realized value of previous element. For every value of previous element conditional multivalue provides collection of possible results. If there is no such a collection, random collection will be selected from all existing collections. If first element of a sequence is conditional multivalue, actual multivalue (collection) will be chosen randomly for the first iteration.
This example demonstrates syntax of conditional multivalue and its logic:
> {<1> 2 3 <2> 3 <3> 1} ≡ {<1> 2 3 <2> 3 <3> 1} ⇒ 1 3 1 3 1 2 3 1 2 3 1 2 3 1 3 1 2 3…
If the last element has value 1
, conditional multivalue will have
value 2
or 3
. If the last element has value 2
,
conditional multivalue will have value 3
for sure, and so on.
Conditions are checked from left to right, first matched condition selects realization of one of corresponding elements.
It’s also possible to use multiple conditional elements:
> {<1 2> 3 <3> 1 2} ≡ {<1 2> 3 <3> 1 2} ⇒ 3 1 3 2 3 2 3 2 3 2 3 2 3 1 3 2 3 2…
You can use sections to match not only on the last element, but on sequence of elements:
> {<[1..3]> 4 <1..4> 1..3} ≡ {<[1 2 3]> 4 <1 2 3 4> 1 2 3} ⇒ 4 3 1 2 1 2 2 2 3 2 3 3 1 1 2 3 4 1…
Here, 1 2 3
triggers 4
while any other single element
triggers 1
, 2
, or 3
.
You can use multivalues in conditional clauses as a sort of “or” operator, consider the following example:
> {<[1 {2 3}]> 7 <1..7> 1..6} ≡ {<[1 {2 3}]> 7 <1 2 3 4 5 6 7> 1 2 3 4 5 6} ⇒ 7 1 1 6 1 1 2 7 1 1 4 1 3 7 3 4 5 5 1 3 7 6 5 1 4 2 5 1 1 2 7 1 4 6 2 1…
Here our first condition says “if last but one realized element is
1
and after it goes 2
or 3
, result will be
7
”.
As always, you can use conditional multivalues inside of any part of other conditional multivalues, but sometimes such complex structures are difficult to understand for human living being.
Be careful when using empty principles in conditional multivalues! Once conditional multivalue happens to choose empty principle, it may hang, because this principle won’t add any elements and last element will remain the same. This may be a desirable situation only when you have other elements in your principle, not single repeating conditional multivalue.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Now you know about all basic elements in MIDA. There are a number of operations that can be performed on these elements. You can combine all kinds of elements and the operators will behave differently according to types of their operands. Thus, we call the operators polymorphic.
All operators in MIDA are infix (or prefix, if unary) and left associative. All operators have the same precedence, so they are always applied from left to right. However, you can use parenthesis ‘(’ and ‘)’ to change order of evaluation.
6.8.1 Basic Arithmetic | How to add, subtract, multiply, and divide elements. | |
6.8.2 Repetition | How to repeat elements. | |
6.8.3 Rotation | How to rotate sections. | |
6.8.4 Reverse | How to reverse elements. |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
To perform arithmetic operation, put ‘+’, ‘-’, ‘*’, or ‘/’ between two elements.
> 1 + 3 ≡ 4 ⇒ 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4… > 7 + (2 * 2) ≡ 11 ⇒ 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11… > 7 / 2 ≡ 3 ⇒ 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3… > (4 - 1) / 0 ≡ 3 ⇒ 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3… > 7 - 100 ≡ 0 ⇒ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0…
Note that we don’t work with negative numbers in MIDA, so subtraction
and division work a bit differently than you might expect: if difference
between two values is negative, it will be substituted with
0
. This is example of “saturation”. If you divide something by
zero, you will get dividend unchanged.
You can put any element into arithmetic expressions. Different types of elements will produce different effects:
> [1..3] + 10 ≡ 11 12 13 ⇒ 11 12 13 11 12 13 11 12 13 11 12 13 11 12 13 11 12 13… > [1..3] + [0 10] ≡ 1 11 2 12 3 13 ⇒ 1 11 2 12 3 13 1 11 2 12 3 13 1 11 2 12 3 13… > [1..3] + {0 10} ≡ {1 11} {2 12} {3 13} ⇒ 1 12 13 1 12 13 11 2 3 11 12 3 1 2 13 1 2 13… > {1..3} + [0 10] ≡ {[1 11] [2 12] [3 13]} ⇒ 1 11 1 11 1 11 1 11 2 12 2 12 1 11 1 11 1 11… > {<1> 2 <2> 1} + 5 ≡ {<6> 7 <7> 6} ⇒ 6 7 6 7 6 7 6 7 6 7 6 7 6 7 6 7 6 7… > {_u _d _ud _du} + 127 ≡ {511 639 255 383} ⇒ 511 255 383 639 383 639 383 639 255 639 383 383 511 511 639 639 511 255…
General rule for type of result element:
In general, we can say that every value of left hand operand is “processed” by right hand operand (according to operator), and results are collected together to make up result of the same type as left hand operand.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Operator for repetition is ‘$’. Principles of evaluation are a bit different from arithmetic operators:
> 1 $ 3, 10 ≡ 1 1 1 10 ⇒ 1 1 1 10 1 1 1 10 1 1 1 10 1 1 1 10 1 1… > {1 2} $ 3, 10 ≡ {1 2} {1 2} {1 2} 10 ⇒ 1 1 1 10 2 1 2 10 1 2 1 10 2 1 1 10 1 1… > [1..3] $ 3, 10 ≡ 1 2 3 1 2 3 1 2 3 10 ⇒ 1 2 3 1 2 3 1 2 3 10 1 2 3 1 2 3 1 2… > 1 $ {2 3}, 10 ≡ {[1 1] [1 1 1]} 10 ⇒ 1 1 10 1 1 1 10 1 1 10 1 1 1 10 1 1 10 1… > [1..3] $ [2 3 1], 10 ≡ 1 1 2 2 2 3 10 ⇒ 1 1 2 2 2 3 10 1 1 2 2 2 3 10 1 1 2 2… > {1..3} $ [2 3 1] ≡ {1 1 2 2 2 3} ⇒ 2 2 2 2 3 2 2 3 2 1 3 1 2 1 3 3 2 2… > {1..3} $ [{2}] ≡ {[1 1] [2 2] [3 3]} ⇒ 3 3 3 3 1 1 2 2 1 1 2 2 3 3 2 2 3 3…
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
You also can “rotate” a principle with caret ‘^’ operator, removing its former elements that will appear at the end of the principle:
> [1..3] ^ 1 ≡ 2 3 1 ⇒ 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1… > [1..3] ^ {1 2} ≡ {[2 3 1] [3 1 2]} ⇒ 3 1 2 2 3 1 3 1 2 2 3 1 2 3 1 3 1 2… > [[1..3] $ 3] ^ [0 2 1] ≡ 1 2 3 3 1 2 2 3 1 ⇒ 1 2 3 3 1 2 2 3 1 1 2 3 3 1 2 2 3 1…
This is so-called left rotation, but you can emulate right-rotation too knowing length of given principle. Note that rotation only makes sense applied to sections.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Reverse is the single unary operator in MIDA. It has the highest precedence, this means that it is evaluated before all other operators:
> @[1..3] ≡ 3 2 1 ⇒ 3 2 1 3 2 1 3 2 1 3 2 1 3 2 1 3 2 1… > @{[1 2] [3 4]} ≡ {[2 1] [4 3]} ⇒ 4 3 2 1 4 3 4 3 2 1 4 3 4 3 2 1 4 3…
As always, arbitrary complex elements can be reversed.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Version 1.3, 3 November 2008
Copyright © 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc. http://fsf.org/ Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
The purpose of this License is to make a manual, textbook, or other functional and useful document free in the sense of freedom: to assure everyone the effective freedom to copy and redistribute it, with or without modifying it, either commercially or noncommercially. Secondarily, this License preserves for the author and publisher a way to get credit for their work, while not being considered responsible for modifications made by others.
This License is a kind of “copyleft”, which means that derivative works of the document must themselves be free in the same sense. It complements the GNU General Public License, which is a copyleft license designed for free software.
We have designed this License in order to use it for manuals for free software, because free software needs free documentation: a free program should come with manuals providing the same freedoms that the software does. But this License is not limited to software manuals; it can be used for any textual work, regardless of subject matter or whether it is published as a printed book. We recommend this License principally for works whose purpose is instruction or reference.
This License applies to any manual or other work, in any medium, that contains a notice placed by the copyright holder saying it can be distributed under the terms of this License. Such a notice grants a world-wide, royalty-free license, unlimited in duration, to use that work under the conditions stated herein. The “Document”, below, refers to any such manual or work. Any member of the public is a licensee, and is addressed as “you”. You accept the license if you copy, modify or distribute the work in a way requiring permission under copyright law.
A “Modified Version” of the Document means any work containing the Document or a portion of it, either copied verbatim, or with modifications and/or translated into another language.
A “Secondary Section” is a named appendix or a front-matter section of the Document that deals exclusively with the relationship of the publishers or authors of the Document to the Document’s overall subject (or to related matters) and contains nothing that could fall directly within that overall subject. (Thus, if the Document is in part a textbook of mathematics, a Secondary Section may not explain any mathematics.) The relationship could be a matter of historical connection with the subject or with related matters, or of legal, commercial, philosophical, ethical or political position regarding them.
The “Invariant Sections” are certain Secondary Sections whose titles are designated, as being those of Invariant Sections, in the notice that says that the Document is released under this License. If a section does not fit the above definition of Secondary then it is not allowed to be designated as Invariant. The Document may contain zero Invariant Sections. If the Document does not identify any Invariant Sections then there are none.
The “Cover Texts” are certain short passages of text that are listed, as Front-Cover Texts or Back-Cover Texts, in the notice that says that the Document is released under this License. A Front-Cover Text may be at most 5 words, and a Back-Cover Text may be at most 25 words.
A “Transparent” copy of the Document means a machine-readable copy, represented in a format whose specification is available to the general public, that is suitable for revising the document straightforwardly with generic text editors or (for images composed of pixels) generic paint programs or (for drawings) some widely available drawing editor, and that is suitable for input to text formatters or for automatic translation to a variety of formats suitable for input to text formatters. A copy made in an otherwise Transparent file format whose markup, or absence of markup, has been arranged to thwart or discourage subsequent modification by readers is not Transparent. An image format is not Transparent if used for any substantial amount of text. A copy that is not “Transparent” is called “Opaque”.
Examples of suitable formats for Transparent copies include plain ASCII without markup, Texinfo input format, LaTeX input format, SGML or XML using a publicly available DTD, and standard-conforming simple HTML, PostScript or PDF designed for human modification. Examples of transparent image formats include PNG, XCF and JPG. Opaque formats include proprietary formats that can be read and edited only by proprietary word processors, SGML or XML for which the DTD and/or processing tools are not generally available, and the machine-generated HTML, PostScript or PDF produced by some word processors for output purposes only.
The “Title Page” means, for a printed book, the title page itself, plus such following pages as are needed to hold, legibly, the material this License requires to appear in the title page. For works in formats which do not have any title page as such, “Title Page” means the text near the most prominent appearance of the work’s title, preceding the beginning of the body of the text.
The “publisher” means any person or entity that distributes copies of the Document to the public.
A section “Entitled XYZ” means a named subunit of the Document whose title either is precisely XYZ or contains XYZ in parentheses following text that translates XYZ in another language. (Here XYZ stands for a specific section name mentioned below, such as “Acknowledgements”, “Dedications”, “Endorsements”, or “History”.) To “Preserve the Title” of such a section when you modify the Document means that it remains a section “Entitled XYZ” according to this definition.
The Document may include Warranty Disclaimers next to the notice which states that this License applies to the Document. These Warranty Disclaimers are considered to be included by reference in this License, but only as regards disclaiming warranties: any other implication that these Warranty Disclaimers may have is void and has no effect on the meaning of this License.
You may copy and distribute the Document in any medium, either commercially or noncommercially, provided that this License, the copyright notices, and the license notice saying this License applies to the Document are reproduced in all copies, and that you add no other conditions whatsoever to those of this License. You may not use technical measures to obstruct or control the reading or further copying of the copies you make or distribute. However, you may accept compensation in exchange for copies. If you distribute a large enough number of copies you must also follow the conditions in section 3.
You may also lend copies, under the same conditions stated above, and you may publicly display copies.
If you publish printed copies (or copies in media that commonly have printed covers) of the Document, numbering more than 100, and the Document’s license notice requires Cover Texts, you must enclose the copies in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on the back cover. Both covers must also clearly and legibly identify you as the publisher of these copies. The front cover must present the full title with all words of the title equally prominent and visible. You may add other material on the covers in addition. Copying with changes limited to the covers, as long as they preserve the title of the Document and satisfy these conditions, can be treated as verbatim copying in other respects.
If the required texts for either cover are too voluminous to fit legibly, you should put the first ones listed (as many as fit reasonably) on the actual cover, and continue the rest onto adjacent pages.
If you publish or distribute Opaque copies of the Document numbering more than 100, you must either include a machine-readable Transparent copy along with each Opaque copy, or state in or with each Opaque copy a computer-network location from which the general network-using public has access to download using public-standard network protocols a complete Transparent copy of the Document, free of added material. If you use the latter option, you must take reasonably prudent steps, when you begin distribution of Opaque copies in quantity, to ensure that this Transparent copy will remain thus accessible at the stated location until at least one year after the last time you distribute an Opaque copy (directly or through your agents or retailers) of that edition to the public.
It is requested, but not required, that you contact the authors of the Document well before redistributing any large number of copies, to give them a chance to provide you with an updated version of the Document.
You may copy and distribute a Modified Version of the Document under the conditions of sections 2 and 3 above, provided that you release the Modified Version under precisely this License, with the Modified Version filling the role of the Document, thus licensing distribution and modification of the Modified Version to whoever possesses a copy of it. In addition, you must do these things in the Modified Version:
If the Modified Version includes new front-matter sections or appendices that qualify as Secondary Sections and contain no material copied from the Document, you may at your option designate some or all of these sections as invariant. To do this, add their titles to the list of Invariant Sections in the Modified Version’s license notice. These titles must be distinct from any other section titles.
You may add a section Entitled “Endorsements”, provided it contains nothing but endorsements of your Modified Version by various parties—for example, statements of peer review or that the text has been approved by an organization as the authoritative definition of a standard.
You may add a passage of up to five words as a Front-Cover Text, and a passage of up to 25 words as a Back-Cover Text, to the end of the list of Cover Texts in the Modified Version. Only one passage of Front-Cover Text and one of Back-Cover Text may be added by (or through arrangements made by) any one entity. If the Document already includes a cover text for the same cover, previously added by you or by arrangement made by the same entity you are acting on behalf of, you may not add another; but you may replace the old one, on explicit permission from the previous publisher that added the old one.
The author(s) and publisher(s) of the Document do not by this License give permission to use their names for publicity for or to assert or imply endorsement of any Modified Version.
You may combine the Document with other documents released under this License, under the terms defined in section 4 above for modified versions, provided that you include in the combination all of the Invariant Sections of all of the original documents, unmodified, and list them all as Invariant Sections of your combined work in its license notice, and that you preserve all their Warranty Disclaimers.
The combined work need only contain one copy of this License, and multiple identical Invariant Sections may be replaced with a single copy. If there are multiple Invariant Sections with the same name but different contents, make the title of each such section unique by adding at the end of it, in parentheses, the name of the original author or publisher of that section if known, or else a unique number. Make the same adjustment to the section titles in the list of Invariant Sections in the license notice of the combined work.
In the combination, you must combine any sections Entitled “History” in the various original documents, forming one section Entitled “History”; likewise combine any sections Entitled “Acknowledgements”, and any sections Entitled “Dedications”. You must delete all sections Entitled “Endorsements.”
You may make a collection consisting of the Document and other documents released under this License, and replace the individual copies of this License in the various documents with a single copy that is included in the collection, provided that you follow the rules of this License for verbatim copying of each of the documents in all other respects.
You may extract a single document from such a collection, and distribute it individually under this License, provided you insert a copy of this License into the extracted document, and follow this License in all other respects regarding verbatim copying of that document.
A compilation of the Document or its derivatives with other separate and independent documents or works, in or on a volume of a storage or distribution medium, is called an “aggregate” if the copyright resulting from the compilation is not used to limit the legal rights of the compilation’s users beyond what the individual works permit. When the Document is included in an aggregate, this License does not apply to the other works in the aggregate which are not themselves derivative works of the Document.
If the Cover Text requirement of section 3 is applicable to these copies of the Document, then if the Document is less than one half of the entire aggregate, the Document’s Cover Texts may be placed on covers that bracket the Document within the aggregate, or the electronic equivalent of covers if the Document is in electronic form. Otherwise they must appear on printed covers that bracket the whole aggregate.
Translation is considered a kind of modification, so you may distribute translations of the Document under the terms of section 4. Replacing Invariant Sections with translations requires special permission from their copyright holders, but you may include translations of some or all Invariant Sections in addition to the original versions of these Invariant Sections. You may include a translation of this License, and all the license notices in the Document, and any Warranty Disclaimers, provided that you also include the original English version of this License and the original versions of those notices and disclaimers. In case of a disagreement between the translation and the original version of this License or a notice or disclaimer, the original version will prevail.
If a section in the Document is Entitled “Acknowledgements”, “Dedications”, or “History”, the requirement (section 4) to Preserve its Title (section 1) will typically require changing the actual title.
You may not copy, modify, sublicense, or distribute the Document except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, or distribute it is void, and will automatically terminate your rights under this License.
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, receipt of a copy of some or all of the same material does not give you any rights to use it.
The Free Software Foundation may publish new, revised versions of the GNU Free Documentation License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. See http://www.gnu.org/copyleft/.
Each version of the License is given a distinguishing version number. If the Document specifies that a particular numbered version of this License “or any later version” applies to it, you have the option of following the terms and conditions either of that specified version or of any later version that has been published (not as a draft) by the Free Software Foundation. If the Document does not specify a version number of this License, you may choose any version ever published (not as a draft) by the Free Software Foundation. If the Document specifies that a proxy can decide which future versions of this License can be used, that proxy’s public statement of acceptance of a version permanently authorizes you to choose that version for the Document.
“Massive Multiauthor Collaboration Site” (or “MMC Site”) means any World Wide Web server that publishes copyrightable works and also provides prominent facilities for anybody to edit those works. A public wiki that anybody can edit is an example of such a server. A “Massive Multiauthor Collaboration” (or “MMC”) contained in the site means any set of copyrightable works thus published on the MMC site.
“CC-BY-SA” means the Creative Commons Attribution-Share Alike 3.0 license published by Creative Commons Corporation, a not-for-profit corporation with a principal place of business in San Francisco, California, as well as future copyleft versions of that license published by that same organization.
“Incorporate” means to publish or republish a Document, in whole or in part, as part of another Document.
An MMC is “eligible for relicensing” if it is licensed under this License, and if all works that were first published under this License somewhere other than this MMC, and subsequently incorporated in whole or in part into the MMC, (1) had no cover texts or invariant sections, and (2) were thus incorporated prior to November 1, 2008.
The operator of an MMC Site may republish an MMC contained in the site under CC-BY-SA on the same site at any time before August 1, 2009, provided the MMC is eligible for relicensing.
To use this License in a document you have written, include a copy of the License in the document and put the following copyright and license notices just after the title page:
Copyright (C) year your name. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled ``GNU Free Documentation License''.
If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, replace the “with…Texts.” line with this:
with the Invariant Sections being list their titles, with the Front-Cover Texts being list, and with the Back-Cover Texts being list.
If you have Invariant Sections without Cover Texts, or some other combination of the three, merge those two alternatives to suit the situation.
If your document contains nontrivial examples of program code, we recommend releasing these examples in parallel under your choice of free software license, such as the GNU General Public License, to permit their use in free software.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Jump to: | A B C D I M P R S T V |
---|
Jump to: | A B C D I M P R S T V |
---|
[Top] | [Contents] | [Index] | [ ? ] |
[Top] | [Contents] | [Index] | [ ? ] |
This document was generated on September 10, 2016 using texi2html 5.0.
The buttons in the navigation panels have the following meaning:
Button | Name | Go to | From 1.2.3 go to |
---|---|---|---|
[ << ] | FastBack | Beginning of this chapter or previous chapter | 1 |
[ < ] | Back | Previous section in reading order | 1.2.2 |
[ Up ] | Up | Up section | 1.2 |
[ > ] | Forward | Next section in reading order | 1.2.4 |
[ >> ] | FastForward | Next chapter | 2 |
[Top] | Top | Cover (top) of document | |
[Contents] | Contents | Table of contents | |
[Index] | Index | Index | |
[ ? ] | About | About (help) |
where the Example assumes that the current position is at Subsubsection One-Two-Three of a document of the following structure:
This document was generated on September 10, 2016 using texi2html 5.0.