ALGA
Version 0.2.2.This manual describes ALGA language and its realization (version 0.2.2, 10 September 2016).
Copyright © 2015–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 ALGA language and its primary realization. This program is distributed under GNU General Public License, version 3.
1 What is ALGA? | General description of ALGA language. | |
2 Installation | Instructions to build and install ALGA on Posix-compatible systems. | |
3 Invocation | Command line interface of the program. | |
4 Configuration File | How to change behavior of ALGA via configuration file. | |
5 Interactive REPL | How to use ALGA interpreter in interactive mode. | |
6 ALGA Tutorial | This tutorial teaches concepts of ALGA 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] | [ ? ] |
ALGA is a MIDA-like declarative language for algorithmic automation in popular digital audio workstations (DAWs). ALGA is a good and robust choice for several reasons:
Currently ALGA can be used to patch projects (or “exported tracks”), and also in interactive mode that will help you to understand how ALGA 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/alga.git $ cd mida $ stack build --copy-bins
$ alga --version ALGA 0.2.2
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
ALGA performs patching of XML files that represent tracks in some DAW. The program can be used in batch mode as well as in REPL mode. If no input file is supplied, ALGA starts in interactive mode by default. Otherwise, one should use command line options to start ALGA in interactive mode.
alga [-i|--interactive] [-B|--backend DAW] [-s|--seed SEED] [-b|--beats BEATS] [-t|--target TARGET] [--license] [--version] [FILES]
Here’s the complete list of command line options:
-h
, --help
Shows information regarding invocation parameters.
-i
, --interactive
Run the program in interactive mode. This option effectively disables
all other supplied options (except for --backend
), because they
only make sense in non-interactive (batch) mode.
-B
daw, --backend
dawSpecify which backend to use, daw should be name of some supported DAW, for example ‘ardour’ or ‘cubase’.
-s
seed, --seed
seedSet seed for generation. It’s possible to generate identical output
files if the same seed is used. Default value is 0
.
-b
beats, --beats
beatsSet total length of automation track as number of whole notes
beats (name of the variable is such for historical
reasons). Default value is 4.0
.
-t
target, --target
targetSpecify target XML file for patching. If the option is not supplied, file name is generated by replacing extension of source file with ‘.xml’.
--license
Show license of the program.
--version
Show version of the program.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
ALGA 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/.alga.yaml’, while Windows users should create the file ‘C:\Users\username\.alga.yaml’.
The configuration file a plain YAML file.
The following table describes all variables that can be assigned in the configuration file.
backend
Currently only two values are acceptable: ‘ardour’ and ‘cubase’. ‘ardour’ is the default value.
precision
This is floating point value that represents precision that’s expected from various helper commands available in REPL (see section Interactive REPL). Default value is ‘0.01’.
prompt
Prompt that will be used in ALGA REPL. Default value is ‘> ’.
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’.
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 ‘.alga.yaml’ file:
# # ALGA Configuration File # prompt: "alga> " prvlen: 20 verbose: false
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In interactive mode you can enter principles for evaluation and special
commands to control ALGA environment. ALGA 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 ALGA source files or in interactive environment. ALGA 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, ALGA knows that current principle is not completed.
Evaluation of principles will be described later in this document (see section ALGA Tutorial). Now, let’s examine all the special commands that are available in ALGA interactive sessions. All the commands begin with colon ‘:’ and are case-sensitive.
Set backend (name of DAW). Currently two values are acceptable: ‘ardour’ and ‘cubase’ with ‘ardour’ being the default.
Change working directory. Since ALGA 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 α β α = {5 6 $ 17} β = {50..70}
Show help text. For example:
> :help Available commands: :backend Set backend (name of DAW) :cd Change working directory :clear Restore default state of environment :def Print definition of given symbol :help Show this help text :lin Linear scale conversion to ratio :load Load definitions from given file :log Logarithmic scale conversion to ratio :make Patch an XML file :prvlen Set length of displayed results :purge Remove redundant definitions :pwd Print working directory :quit Quit the interactive environment :ratio Real number to ratio converter :save Save current environment in file :udef Remove definition of given symbol :vol Convert decibels to ratio
Linear scale conversion to ratio. There are quite a few built-in helper
functions in ALGA that should simplify working with ratios (since ALGA
uses ratios as its main numeric data type). This is one of
them. :lin
command takes three arguments (in this order): minimum
value of argument, maximum value of argument, and actual value of
argument. The command prints a ratio from 0
(corresponds to
minimum value) to 1
(maximum value) that can be used to specify
value of automation parameter using linear scale.
Load definition from specified source files. When something is defined, you usually get some helpful feedback:
> :load tracks.ga • «synth0.pan» • «synth0.pand» • «synth1.pan» • «synth1.pand» • «synth2.pan» • «synth2.pand» "/home/mark/projects/music/tracks.ga" 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.
The same as :lin
, but uses logarithmic scale for conversion.
One of the most common commands is ‘:make’. It patches XML file using current state of ALGA environment. This command takes up to three 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 total length of composition as number of whole
notes. This parameter is also known as “beats” (this name is for
historical reasons). Default value is 4.0
.
The last parameter is name of file to patch. 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 ‘.xml’.
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:
> α = β β = 1/2 Y = 1/3 synth_group.volume = α • «α» • «β» • «Y» • «dur0» > :def Y Y = 1/3 > :purge Environment purged. > :def Y Y = > :def β β = 1/2
What happened here? Well, we see that synth_group.volume
is a top
level definition (see section Definitions). α
is used in
synth_group.volume
’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.
This utility converts floating point numbers to ratios:
> :ratio 0.897 ≈ 8/9
Save the current environment in ALGA source file. As you work with ALGA, you will need to save all existing definitions to hard disk. You can then edit them or load them into ALGA 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 ‘.ga’ as file name extension for ALGA source files.
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.
Convert decibels to ratio:
> :vol -3.0 ≈ 1/2
[ << ] | [ < ] | [ 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 ALGA.
ALGA is minimalistic, declarative language. In fact, it is so simple that any statement that has valid syntax will produce valid result. ALGA statement only has to pass parser, that’s all. Declarative nature of ALGA means that you describe relations between principles that will be turned into automation data without describing control flow.
6.1 Literal Values | Most basic elements in ALGA. | |
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 ~]$ alga ALGA Copyright © 2015 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. ALGA Interactive Environment 0.2.2 >
You can try your powers right away. Remember, ALGA 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 ALGA. | |
6.1.2 Volume and Gain | How volume and gain represented in ALGA. | |
6.1.3 Stereo Panorama | How position on stereo panorama is represented in ALGA. | |
6.1.4 Other Parameters | Other parameters. |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
ALGA uses non-negative rational numbers in form of ratios to represent everything. This allows to preserve higher quality of calculations until values are converted into floating point representation (in result XML document). For example, you can try the following:
> 1/3 * 3 # ignore repetitiveness for now ≡ 1 ⇒ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1…
Given this system of number representation you have natural means to represent duration of musical sounds. We work with abstract duration closely related to classical music notation techniques where ‘1/8’ represents eighth note, while ‘1’ signifies the whole note. To represent more «unusual» duration, use ratios like ‘3/2’ or ‘11/8’; ‘1 1/2’ is not a single number, it’s two different numbers.
In ALGA we don’t care about tempo, because this is something DAW handles for us, so this is all we need to know about duration of things.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Usually volume and gain are represented in decibels. For example it’s
normal for volume to be represented from 0
(full volume) to
-∞
. However, for consistency, we use ratios to represent volume
too. The conversion is rather trivial and ALGA has built-in
functionality to assist you:
> :vol 0 ≈ 1 > :vol -6 ≈ 1/4 > :vol -100 ≈ 0
For information about :vol
command see section Interactive REPL.
For your convenience there are predefined values on
and
off
that you can use instead of 1
and 0
respectively:
> on ≡ 1 ⇒ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1… > off ≡ 0 ⇒ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0…
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Just like duration and volume, position on stereo panorama is easy to
represent with ratios. In ALGA there is a convention that 0
signifies extreme left position, 1
— extreme right position, and
1/2
is center.
So, suppose you want your sound to change from left to right again and again, this is easy to represent:
> 0 1/2 1 1/2 ≡ 0 1/2 1 1/2 ⇒ 0 1/2 1 1/2 0 1/2 1 1/2 0 1/2 1 1/2 0 1/2 1 1/2 0 1/2…
There are predefined values specially for panorama too. The previous principle can be written this way:
> L C R C ≡ 0 1/2 1 1/2 ⇒ 0 1/2 1 1/2 0 1/2 1 1/2 0 1/2 1 1/2 0 1/2 1 1/2 0 1/2…
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
All other parameters are represented in similar way. Usually your tool
of interest have finite range of values that some parameter can
have. When represented in ALGA, minimum value of parameter is written as
0
and maximum value is written as 1
, of course you also
have everything in between with endless precision.
After a coupe of tries you will find correct ratios to represent desired values in ALGA.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Smallest piece of composition in ALGA is called element. Now we know at least one kind of element: literal values (ratios). 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… > 1/3, 1/2, 90 ≡ 1/3 1/2 90 ⇒ 1/3 1/2 90 1/3 1/2 90 1/3 1/2 90 1/3 1/2 90 1/3 1/2 90 1/3 1/2 90…
So, we enter a principle and ALGA 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 ALGA. 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, ALGA thinks that these things are realized to ⊥
, they can be
even put inside a principle without any obvious harm.
The thing is that ALGA considers any alpha-numeric sequence of characters (underscores are allowed too) that does not begin with a number identifier. 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 actual automation data. The system evaluates them to get values that are then written into XML document in acceptable for given DAW format.
You need to know about naming scheme to be able to program automation in ALGA:
volume
— controls volume of track
track_name;
mute
— controls mute of track track_name;
igain
— controls input gain of track
track_name;
pan
— controls position on stereo panorama of
track track_name;
i
slotindex_
paramindex —
controls value of “insert slot” slotindex parameter
paramindex for track track_name;
s
slotindex_
paramindex —
controls value of “send slot” slotindex parameter paramindex
for track track_name;
p
paramindex — controls value of synth
parameter paramindex for track track_name.
To control duration of every step of one of the parameters listed above, add ‘d’ to the end of definition’s name (‘d’ stands for delta or duration).
For example, suppose we have a Cubase or Ardour project that has track called ‘synth0’. We want to control its position on stereo panorama so that every eighth note it changes cyclically from left to center, from center to right, from right to left again. Let’s start our ALGA interpreter and create the necessary definitions:
> synth0.pan = L L C C R R • «synth0.pan» > synth0.pan ≡ 0 0 1/2 1/2 1 1 ⇒ 0 0 1/2 1/2 1 1 0 0 1/2 1/2 1 1 0 0 1/2 1/2 1 1… > synth0.pand = 1/8, 0 • «synth0.pand» > synth0.pand ≡ 1/8 0 ⇒ 1/8 0 1/8 0 1/8 0 1/8 0 1/8 0 1/8 0 1/8 0 1/8 0 1/8 0…
Now it’s pretty easy to “patch” our project file or “exported
definitions”, just use :make
command:
> :make 0 32 my_tracks.xml File patched sucessfully "my_tracks.xml".
For information about :make
command see section Interactive REPL.
So, that’s basically all you need to know, experiment on your own, try to program very simplistic behaviors and you will see that this is pretty easy.
[ << ] | [ < ] | [ 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 ALGA 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 ALGA 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 ALGA. 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 ALGA 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 + 3 ≡ 10/3 ⇒ 10/3 10/3 10/3 10/3 10/3 10/3 10/3 10/3 10/3 10/3 10/3 10/3 10/3 10/3 10/3 10/3 10/3 10/3… > 7 + (2 * 2) ≡ 11 ⇒ 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11… > 7 / 2 ≡ 7/2 ⇒ 7/2 7/2 7/2 7/2 7/2 7/2 7/2 7/2 7/2 7/2 7/2 7/2 7/2 7/2 7/2 7/2 7/2 7/2… > (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 ALGA, so subtraction
and division work a bit different 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…
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 ALGA. 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 G I M P R S V |
---|
Jump to: | A B C D G I M P R S 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.