meditationatae

Just another WordPress.com site

C source code to current TM #4 (chaotic) simulator

The code compiles and executes without problems using the GCC compiler on architecture x86_64 on Linux.

It only needs the standard C library. It’s an accelerated simulator that combines many repated operations into one big operation. It was checked against a conventional un-accelerated TM simulator, and the outputs matched.

(no name program, or sim12g84.c locally):

=========================================================

 

#include <stdio.h>
#define STACK_HEIGHT 100000000
#define TMAX 10

 

long lstack[STACK_HEIGHT]; // pile gauche; pas de malloc ou calloc
long rstack[STACK_HEIGHT]; // pile droite; “” “” “”

int main(void)
{

long ltop; // le sommet de la pile gauche; ltop est un indice
long rtop; // sommet de pile droite
int p1, p2, p3; // variables essentiellement booleennes
long time;
long time_billions;
long current_block; // nombre de 0 ou de 1 consecutifs dans le bloc sous la
long subindex; // tete de lecture; subindex indique ou la tete est
long loop_counter;
long loop_counter_b;
long delta_time;
long num1, num2, num9;
long count_ones;
long i;
int done;
int state; // 1->A, 2->B, 3->C
int the_rule; // meta-regle: de 1 a 10

 

ltop = 1;
rtop = 1;
lstack[1] = 3;
rstack[1] = 2;
current_block = 4; // au debut: 2000000000, 3, *4*, 2, 2000000000
subindex = 1; // nombre de 0 consecutifs, 1 consec., 0 consec., 1 consec., 0 consec.
time = 38; // on debute au temps 38
time_billions = 0;
state = 1; // on debute dans l’etat A
done = 0; // si 0: pas encore termine; si 1: on doit stopper le programme
loop_counter = 0;
loop_counter_b = 0;

 

while(done == 0)
{

 

if(1==0)
{
done = 1; // depasse le temps 10^10, on va stopper le programme
}

 

 

 

if( loop_counter>104)
{

if(the_rule == 10)
{
//printf(“a”);
}
else
{

if(the_rule == 1)
{
//printf(“\n”);
}

//printf(“%d”,the_rule);
}
} // le bloc de code C precedant concerne juste ce qui sera affiche

 

 

lstack[0] = 2000000000; // on pretend qu’il y a 2000000000 de zeros consec.
// a gauche, au debut de la pile; 2e+9 remplace l’infini

rstack[0] = 2000000000;

if(done == 1)
{
break; // porte de sortie de la boucle while(done == 0)
}

if(state == 1) // etat present = A
{
p1=0; // p1, p2, p3 sont des booleennes
p2=0; // avec des affectations qui varient selon l’etat
p3=0; // c’est pour economiser les noms de variable

if(subindex == 1)
{
p1 = 1;
}

if(lstack[ltop-1]==3 && lstack[ltop]==3)
{
p2 = 1;
}

if(lstack[ltop-1] > 7)
{
p3 = 1;
}

if(p1==1 && p2==0 && p3==1)
{
the_rule = 1; // the_rule := numero de la meta-regle a appliquer
}

if(p1==1 && p2==0 && p3==0)
{
the_rule = 5;
}

if(p1==1 && p2==1)
{
the_rule = 6;
}

if(p1 == 0)
{
the_rule = 8;
}
}

if(state == 2) // etat present = B
{
p1 = 0;
p2 = 0;

if(rstack[rtop-1] > 1)
{
p1 = 1;
}

if( (rstack[rtop]%2) == 0)
{
p2 = 1;
}

if(p1==0)
{
the_rule = 2;
}

if(p1==1 && p2==1)
{
the_rule = 3;
}

if(p1==1 && p2==0)
{
the_rule = 4;
}

}

if(state == 3) // etat present = C
{
p1 = 0;
p2 = 0;

if(subindex == 1)
{
p1 = 1;
}

if(current_block > 2)
{
p2 = 1;
}

if(p1 == 0)
{
the_rule = 7;
}

if(p1 == 1 && p2 == 1)
{
the_rule = 9;
}

if(p1==1 && p2==0)
{
the_rule = 10;
}

}

/*** le numero de la meta-regle est maintenant connu;
il s’agit ensuite de l’appliquer;
c’est le role du switch(the_rule) plus bas avec les “case” ***/

switch(the_rule)
{
case 1:
rstack[rtop] = 2+rstack[rtop];
lstack[ltop-1]=lstack[ltop-1]-8;
ltop=ltop+2;
lstack[ltop]=5;
lstack[ltop-1]=1;
subindex=4;
state=2;
delta_time=103;
break;

case 2:
num1=rstack[rtop];
num2=rstack[rtop-2];
current_block = current_block – 1;
rstack[rtop]=rstack[rtop]+1;
rstack[rtop-4]=rstack[rtop-4]+2;
ltop=ltop+2; // pile gauche “gagne 2 elements”
lstack[ltop]=rstack[rtop];
lstack[ltop-1]=current_block;
rtop=rtop-4; // la pile de droite “perd 4 elements”
current_block=num2;
subindex=num2;
state=2; // le prochain etat va etre B, apres application de Rule 2
delta_time=3*num1 + num2 + 4; // temps a ajouter au compteur de temps
break;

/*** dans la meta-regle 2, il y a une amalgation de blocs
suite a l’application de la meta-regle **/

case 3:
subindex=subindex-1;
current_block = current_block + 2;
rstack[rtop-1]=rstack[rtop-1]-2;
state=1;
delta_time = 7*rstack[rtop] – 1;
break;

case 4:
num1=rstack[rtop];
current_block=current_block+1;
rstack[rtop]=rstack[rtop]+1;
rstack[rtop-1]=rstack[rtop-1]-2;
subindex=subindex-1;
state=3;
delta_time = 7*num1 + 2;
break;

case 5:
current_block=current_block-1;
lstack[ltop]=lstack[ltop]-2;
rtop=rtop+2; // le sommet de pile droite croit de 2 blocs
rstack[rtop]=1;
rstack[rtop-1]=current_block;
current_block=2;
state=3;
delta_time=6;
break;

/*** case 5: ltop est inchange, rtop augmente de 2: cas de fission de blocs
apres application de la regle; inverse d’une amalgamation ***/

 

case 6:
subindex=2;
lstack[ltop-1]=lstack[ltop-1]-1;
current_block=current_block-1;
rtop=rtop+4;
rstack[rtop]=1;
rstack[rtop-1]=3;
rstack[rtop-2]=1;
rstack[rtop-3]=current_block;
current_block=lstack[ltop-1];
ltop=ltop-2;
state=2;
delta_time=5;
break;

case 7:
current_block=current_block-3;
subindex=subindex-1;
rtop=rtop+2;
rstack[rtop]=2;
rstack[rtop-1]=1;
state=2;
delta_time=3;
break;

case 8:
subindex=subindex-2;
current_block=current_block-3;
rtop=rtop+2;
rstack[rtop]=2;
rstack[rtop-1]=1;
state=3;
delta_time=10;
break;

case 9:
num9=lstack[ltop];
current_block=current_block-2;
lstack[ltop]=lstack[ltop]-1;
lstack[ltop-1]=lstack[ltop-1]+3;
subindex=lstack[ltop-1]-3;
rtop=rtop+2;
rstack[rtop-1]=current_block;
rstack[rtop]=lstack[ltop];
current_block=lstack[ltop-1];
ltop=ltop-2;
state=1;
delta_time= 4*num9 – 6;
break;

case 10:
num9=lstack[ltop];
current_block=current_block-2;
lstack[ltop]=lstack[ltop]-1;
lstack[ltop-1]=lstack[ltop-1]+3;
subindex=lstack[ltop-1]-3;
rstack[rtop]=rstack[rtop]+lstack[ltop];
current_block=lstack[ltop-1];
ltop=ltop-2;
state=1;
delta_time=4*num9 – 6;
break;

}

 

time = time + delta_time; // ajustement du nombre de steps ecoules
// un step est une transition selon la table

 

while(time >= 1000000000) // pour s’occuper de l’overflow de “time”
{
time = time – 1000000000;
time_billions++;
}

/****************

 

TIME IS: 8 billion + 914287753
USING RULE 1
ltop = 4611
rtop = 1673

1222

498722222
498722222
498722222
498722222
498722222
498722222
498722222
498722222
498722222
498722222

4987222
49896495a89
TIME IS: 8 billion + 914314687
USING RULE 1
ltop = 4691
rtop = 1533

 

*******************/

 

if(rtop == 1 && the_rule ==3 &&(3==(ltop%701)) )
{

/*** if rtop=1 and the_rule=3, then the head seems to
always be over square 0 July 18, 2006 ***/

 

count_ones=0;

i=1; // plus petit indice pointant a un bloc de 1 consecutifs

while(i<=ltop)
{
count_ones = count_ones + lstack[i];
i=i+2;
}

 

i=1;

if( time_billions > 455000)
{

while(i<=ltop)
{
printf(“%d “, lstack[i]);
i=i+1;
}

}

 

 

 

 

 

i=1;

while(i<=rtop)
{
count_ones = count_ones + rstack[i];
i=i+2;
}

 

printf(“\n”);

 

printf(“TIME IS: %ld billion + %ld\n”,time_billions, time);
printf(“COUNT OF ONES IS: %ld\n”, count_ones);

printf(“USING RULE %d\n”, the_rule);
printf(“ltop = %ld\n”, ltop);
printf(“rtop = %ld\n”, rtop);
printf(“counter= %ld billion + %ld\n”,loop_counter_b, loop_counter);

 

}

loop_counter++;
while(loop_counter>=1000000000)
{
loop_counter= loop_counter-1000000000;
loop_counter_b++;
}

 

} // ferme l’accoade de while(done == 0)

return 0;

} // ferme l’accoade de main()

Advertisements

Written by meditationatae

September 20, 2017 at 5:06 am

Posted in History

%d bloggers like this: