LODA: Lexicographical Order Descent Assembly
LODA is an assembly language, computational model and a tool for mining integer sequences. You can use it to search programs that calculate sequences from the On-Line Encyclopedia of Integer Sequences® (OEIS®).
The LODA command-line tool is written in C++ and is published under the terms of the Apache License 2.0. To build it, run
make in the
src folder. The
loda command-line tool provides the following commands and options:
Usage: loda <command> <options> Core commands: evaluate <file> Evaluate a program to a sequence optimize <file> Optimize a program and print it minimize <file> Minimize a program and print it (use -t to set the number of terms) optmin <file> Optimize and minimize a program and print it (use -t to set the number of terms) generate Generate a random program and print it test Run test suite OEIS commands: mine Mine programs for OEIS sequences synthesize Synthesize programs for OEIS sequences maintain Maintain programs for OEIS sequences update Update OEIS index General options: -l <string> Log level (values:debug,info,warn,error,alert) -t <number> Number of sequence terms (default:20) -s <number> Maximum physical memory (default:1024) Interpreter options: -c <number> Maximum number of interpreter cycles (default:10000000) -m <number> Maximum number of used memory cells (default:100000) Generator options: -g <number> Generator version (default:1) -p <number> Maximum number of operations (default:20) -n <number> Maximum constant (default:4) -i <number> Maximum index (default:4) -o <string> Operation types (default:^;m:mov,a:add,s:sub,t:trn,u:mul,d:div,o:mod,p:pow,k:log,f:fac,g:gcd,b:bin,c:cmp,l:lpb,r:clr;^:negate pattern) -a <string> Operand types (default:cd;c:constant,d:direct mem,i:indirect mem) -e <file> Program template -r Search for programs of linear sequences (slow) -x Optimize and overwrite existing programs
For example, run
./loda eval programs/oeis/000/A000045.asm to generate the first terms of the Fibonacci sequence.
The LODA language is an assembly language with instructions for common integer operations. It supports an unbounded set of memory cells storing integer, arithmetic operations and a loop based on a lexicographical order descent on memory regions.
Programs operate on memory consisting of an unbounded sequence of memory cells
$2,... each storing an integer. There are three types of operands supported:
- Constants, for example 5.
- Direct memory access, for example
$5. Reads or writes the value of the fifth memory cell.
- Indirect memory access, for example
$$7. Reads the value at memory cell #7 and interpretes it as an address. For instance, if the value of
$7is 13, then
$$7accesses the memory cell #13.
These are the following instructions supported by LODA. In the following, let
a be a direct or an indirect memory access, and let
b be a constant, a direct or an indirect memory access.
||Assignment||Assign the value of the source to the target operand:
||Addition||Add the source to the target operand:
||Subtraction||Subtract the source from the target operand:
||Truncation||Subtract and truncate if result is negative:
||Multiplication||Multiply the target with the source value:
||Division||Divide the target by the source value:
||Modulus||Remainder of division of target by source:
||Power||Raise source to the power of target:
||Logarithm||Logarithm of target with source as base:
||Factorial||Apply factorial function to target:
||Greatest Common Divisor||Greatest common divisor or target and source:
||Binomial Coefficient||Target over source:
||Comparison||Compare target with source value:
lpb x,y ...
lpe define the beginning and the end of an lexicographical order descent loop. The part between these two instructions is executed in a loop as long as a defined, finite memory region strictly decreases in every iteration of the loop.
x marks the start of that memory region, whereas
y is interpreted as a number and defines the length of this region. For example,
lpb $4,3 ...
lpe is executed as long as the vector (or polynom)
$6 is strictly decreasing in every iteration according to the lexicographical ordering. If
y is not a constant and evaluates to different values in subsequent iterations, the minimum length is used to compare the memory regions.
Termination: all LODA programs are guaranteed to halt on every input. An infinite loop cannot occur, because the values of the memory region strictly decrease in every iteration and can at most reach the region consisting only of zeros. Hence, all loops therefore also all LODA programs eventually terminate.
Programs can be used to generate integer sequences. A program generates a sequence
a(n) by taking
$0=n as input and producing the output
The following programs include some classical examples of sequences and functions on the natural numbers.
- Fibonacci numbers (A000045)
- Number of divisors (A000005)
- Characteristic function of primes (A010051): Uses
- Ackermann function: The Ackermann function is a non-primitive recursive function can be expressed in LODA. It is based on an algorithm by Grossman and Zeitman.
Mining Programs for Integer Sequences
The programs/oeis folder contains programs that generate integer sequences from the On-Line Encyclopedia of Integer Sequences® (OEIS®).
All programs in the oeis folder have been automatically generated using the
loda mine command. Warning: these programs have been validated only for the first terms of the sequences as found in the downloaded version of the OEIS database. There is no guarantee that any particular program is correct, i.e., generates the correct (infinite) sequence.
Before mining programs for integer sequences, you need to download files from the OEIS website. Use
loda update to download the required files. After that, you may run
loda mine to search for programs for integer sequences from OEIS. Found programs are written to
programs/oeis. When using the command-line flag
-x, existing programs are overriden if the new program is simpler or faster than the existing one.
If you would like to get updates on new programs, you can check out the @lodaminer Twitter account.
Currently, there are about 19k programs available.