A #fractran model in #rakulang

my $c=True;
while $c {
for @p ->(\t,\n) {
$c=True;
for n.keys ->\v {
if a{v}:exists and a{v}>=n{v}
or t{v}:exists and t{v}>=n{v}
{
$c=True
} else {
$c=False;last
}
}
if $c {
for a.keys ->\v {
if t{v}:exists {a{v}+=t{v}}
if n{v}:exists {a{v}-=n{v}}
}
for t.keys ->\v {
if not a{v}:exists {a{v}=t{v}}
}
last
}
}
}

Inspired by @neauoire's explorations of #fractran. The above code is very condensed to fit in a post. To run it you have something like

my Map \a = {r2 => 6, r3 => 7};
my @p =
( {r5=>1,r7=>1,r13=>1}, {r3=>1,r11=>1} ),
( {r11=>1}, {r13=>1} ),
( {}, {r11=>1} ),
( {r3=>1}, {r7=>1} ),
( {r11=>1}, {r2=>1} ),
( {}, {r3=>1} );

I have kept the primes so it is easy to see the link with the original #fractran program:

acc = (2^6)*(3^7)
program =
(5*7*13/3*11,11/13,1/11,3/7,11/2,1/3)

The model shows that the primes and fractions are an obfuscation of a machine with single composite instruction and an infinite number of registers.

The similarity with the rewrite system used by @neauoire in https://wiki.xxiivv.com/site/fractran.html is obvious:

:: left side > right side

AC 6 left side
00 6 × 15/6 = 15, side right

is equivalent with

my @p = ( {left=>1,side=>1},{right=>1,side=>1} ), ;

my %a = {right=>1, side=>1};

fractran

By Devine Lu Linvega

XXIIVV

@wim_v12e I'm so excited to see you mess with this!! If you find smaller implementations of the programs on xxiivv(div, mod, etc) please let me know.

Have you tried making a program like: x is-prime?

@neauoire I wrote this because I was curious about the machine behind the language. In particular, your remark about the reduced fractions. In the code I posted I left out the condition that generalised it to non-reduced fractions (just so it would fit in a post).

I have not written any program in it, I've only used existing ones to test the machine. I'll test it some more and then I can think about how to write programs in it.

@wim_v12e So what do you think about the machine? Elegant isn't?
@neauoire Yes, it's really cool how such a simple machine is Turing complete.