I/M Machine

From Esolang
Jump to navigation Jump to search

I/M Machine is a strange esoteric programming language inspired by InterpretMe. The strangest thing is that infinite programs are completely normal and accepted.

I/M Machine
Paradigm(s) imperative, OISC
Designed by User:TenBillionPlusOne
Appeared in 2025
Memory system Accumulator-based
Computational class total/Unknown
Major implementations below
Influenced by InterpretMe
File extension(s) .imm, .fimm, .pimm, ...

Overview

The only memory I/M Machine uses is an accumulator, which is initially set to 1. The program consists of natural numbers of natural numbers separated by whitespace. All other instructions which include characters other than iImM are ignored.

The command described below is called until the program halts:

  • The first number of the program is removed;
  • [removed number - 1] is added to the accumulator;
  • If accumulator is equal to 0, the program halts.

It can be seen as one instruction, which takes one argument a and executes the following pseudocode:

x+=a; if(--x==0) halt;

So I/M Machine can be analyzed as OISC.

I/M Machine can also be analyzed as turing tarpit with two instructions:

  • I - Increment accumulator by 1.
  • M - Decrement accumulator. If it's equal to 0, halt.

Finiteness

Finite I/M Machine

Finite I/M Machine (FIMM) is limited version of I/M machine. All programs have finite size in it, and all instructions after the last are 0s. It's total and unusable for programming.

Periodic I/M Machine

Periodic I/M Machine (PIMM) is official version of I/M Machine, in which programs are split into two finite parts: initial, which is executed once, and looping, which is executed infinitely. Parts are split with instruction |.

Infinite I/M Machine

Infinite I/M Machine (IIMM) is full version of I/M Machine, which has infinite programs. IIMM program can be defined as computable function that maps each natural number to a natural number. It isn't official dialect of the esolang and it has no standard notation, but it can be implemented in the following ways:

  • Adding a mathematical function definition as comment. After the last instruction is executed, the program calculates next instructions using the function. Easy to read but hard to implement.
  • Instead of executing IMM file, a file written in the same language as an interpreter is executed. The interpreter calculates each instruction using the file and executes it.

Computational class

  • Finite I/M Machine is obviously total.
  • Periodic I/M Machine is proved sub-TC in talk. It's probably a Push-down automaton, but it isn't proved yet.
  • Computational class of Infinite I/M Machine is unknown.

(That's why the language is listed as both Unusable for programming and Usability unknown, and both Total and Unknown computational class.)

Relationship to InterpretMe

I/M Machine is shortcut of InterpretMe Machine. It's atemlanguage of InterpretMe, which means that IMM program is list of user inputs given to InterpretMe program *. Accumulator represents the minimal amount of empty user inputs required to terminate, counting from now.

(( Actually the true name of the language is Interpret/Me Machine. ))

Example programs

Truth machine

? | 1

Replace ? with a number. If it's 0, accumulator will be set to 0 and the program will halt. If not, it will run forever (word "loop" isn't appropriate here), with accumulator at a constant value ?. Note that 1 (IM) is a NOP.

Implementation

Periodic I/M Machine as OISC in Python:

# FIMM INTERPRETER
def interpret(program):
    'Interprets FIMM program'
    global acc
    for cmd in program:
        try: int(cmd); cmd < 0
        except: continue
        if cmd != int(cmd) or cmd < 0: continue
        acc += cmd - 1
        if acc == 0:
            exit(0)

# PROGRAM SPLITTING
program = input('Program: ').split(' ')
if '|' in program:
    ind = program.index('|')
    initial = program[:ind]
    looping = program[ind:]
    program.remove('|')
    if '|' in program:
        raise Exception('Incorrect number of separators')
else:
    initial = program
    looping = []

# BODY
acc = 1
interpret(initial)
while True:
    interpret(looping)