Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

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 $0,$1,$2,... each storing an integer. There are three types of operands supported:

  1. Constants, for example 5.
  2. Direct memory access, for example $5. Reads or writes the value of the fifth memory cell.
  3. 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 $7 is 13, then $$7 accesses the memory cell #13.

Arithmetic Operations

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.

Operation Name Description
mov a,b Assignment Assign the value of the source to the target operand: a:=b
add a,b Addition Add the source to the target operand: a:=a+b
sub a,b Subtraction Subtract the source from the target operand: a:=a-b
trn a,b Truncation Subtract and truncate if result is negative: a:=(a>=b)?(a-b):0
mul a,b Multiplication Multiply the target with the source value: a:=a*b
div a,b Division Divide the target by the source value: a:=floor(a/b)
mod a,b Modulus Remainder of division of target by source: a:=a%b
pow a,b Power Raise source to the power of target: a:=a^b
log a,b Logarithm Logarithm of target with source as base: a:=floor(log_b(a))
fac a Factorial Apply factorial function to target: a:=a!
gcd a,b Greatest Common Divisor Greatest common divisor or target and source: a:=gcd(a,b). Undefinied for 0,0. Otherwise always positive.
bin a,b Binomial Coefficient Target over source: a:=a!/(b!(a-b)!)
cmp a,b Comparison Compare target with source value: a:=(a=b)?1:0


The instructions 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) $4,$5,$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.

Integer Sequences

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 a(n)=$1.

Example Programs

The following programs include some classical examples of sequences and functions on the natural numbers.

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.

Available Programs

Currently, there are about 19k programs available.


LODA is an assembly language, a computational model and a tool for mining integer sequence programs.





No releases published


No packages published


You can’t perform that action at this time.