Blues machine/Portable Minsky Machine Notation conversion

From Esolang
Jump to navigation Jump to search

Back to blues machine

Overview:

  • 0 will contain the constant 0.
  • 1 will be a junk variable that absorbs any operations we don’t want.
  • 2 will contain the constant 2.
  • The Minsky machine must only use counter indices greater than or equal to 3. Equivalently, you can increase all counter indices by 3 before applying this conversion.
  • A counter value of x is encoded as 2x.

Initialization

blues 2, 1, 1, 1, 1, 0, 1, 1
blues 2, 1, 1, 1, 1, 0, 1, 1
blues 3, 1, 1, 1, 1, 0, 1, 1
 ⋮
blues N, 1, 1, 1, 1, 0, 1, 1

Incrementing

PMMN:

inc(n)

Pseudo-C:

*n *= 2;

Blues machine:

blues 1, n, 2, 1, 1, 0, 1, 1

Decrementing

PMMN:

dec(n)

Pseudo-C:

line m:   *n /= 2; if(*n) goto m+2;
line m+1: ++*n;

Blues machine:

line m:   blues 1, 1, 1, n, 2, n, 1, m+2
line m+1: blues n, 1, 1, 1, 1, 0, 1, 1

If-Else

PMMN:

if(dec(n)) {...} else {...}

Pseudo-C:

line m:   *n /= 2; if(*n) goto j;
line m+1: ++*n;
           ⋮     else block
line j-1: goto k;
line j:    ⋮     if block
line k

Blues machine:

line m:   blues 1, 1, 1, n, 2, n, 1, j
line m+1: blues n, 1, 1, 1, 1, 0, 1, 1
           ⋮                            else block
line j-1: blues 1, 1, 1, 1, 1, 2, 1, k
           ⋮                            if block
line k

While

PMMN:

while(dec(n)) {...}

Pseudo-C:

line m:   *n /= 2; if(*n) goto m+3;
line m+1: ++*n;
line m+2: goto j;
           ⋮     while block
line j-1: goto m;

Blues machine:

line m:   blues 1, 1, 1, n, 2, n, 1, m+3
line m+1: blues n, 1, 1, 1, 1, 0, 1, 1
line m+2: blues 1, 1, 1, 1, 1, 2, 1, j
           ⋮                              while block
line j-1: blues 1, 1, 1, 1, 1, 2, 1, m