initial commit with license
[weak_simulation_stab_extent.git] / supplement.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <math.h>
4
5
6 void printBinary(unsigned long number, int T) {
7
8   int i;
9   
10   for(i=0; i<T; i++)
11     printf("%d", (int)(number/pow(2,i))%2);
12   printf("\n");
13   
14 }
15
16 void supplement(long stabStateIndices[], int T)
17 {
18
19   int K = round(log(T)/log(2)); // T = 2^K
20
21   //printf("K=%d\n", K);
22
23   int treeDepth, levelMaskDepth, maskIndex;
24
25   unsigned long levelMask;
26
27   unsigned long long maskList[K];
28
29   unsigned long given = (unsigned long)stabStateIndices[0]; // the given bitstring
30
31   unsigned long bitstring;
32
33   int bitstringCounter = 1;  // bitstringCounter starts at 1 since 0 is the given bitstring
34
35   int i;
36
37   // first added bitstring is alpha ... alpha for alpha = 01
38   bitstring = 1;
39   for(i=1; i<T/2; i++) {
40     bitstring *= 4;
41     bitstring += 1;
42   }
43   //printf("%lu\n", bitstring);
44   stabStateIndices[bitstringCounter] = given^(bitstring);
45   bitstringCounter++;
46
47   // second added bitstring is beta ... beta for beta = 10
48   bitstring = 2;
49   for(i=1; i<T/2; i++) {
50     bitstring *= 4;
51     bitstring += 2;
52   }
53   //printf("%lu\n", bitstring);
54   stabStateIndices[bitstringCounter] = given^bitstring;
55   bitstringCounter++;
56
57   maskList[0] = round(pow(2,pow(2,K)))-1;
58
59   for(treeDepth=1; treeDepth<=K-1; treeDepth++) {
60
61     levelMask = round(pow(2,pow(2,K-treeDepth))-1);
62     // repeat this unit-cell mask to the other bits on levelMask
63     for(levelMaskDepth=2; levelMaskDepth<=round(pow(2,treeDepth-1)); levelMaskDepth++) {
64       levelMask += round(pow(2,pow(2,K-treeDepth+1)))*levelMask;
65     }
66
67     //printf("levelMask=");
68     //printBinary(levelMask, T);
69
70     bitstring = stabStateIndices[1] ^ levelMask;
71
72     for(maskIndex=0; maskIndex < (int)(pow(2,treeDepth)); maskIndex++) {
73       stabStateIndices[bitstringCounter] = bitstring;
74       for(i=0; i<treeDepth; i++){
75         // if ith binary digit of maskIndex is 1 then XOR with ith string in maskList
76         stabStateIndices[bitstringCounter] ^= ((int)(maskIndex/(pow(2,i)))%2)*maskList[i];
77       }
78       //printf("new bitstring=");
79       //printBinary(stabStateIndices[bitstringCounter], T);
80       bitstringCounter++;
81     }
82
83     maskList[treeDepth] = levelMask;
84     
85   }
86     
87 }
88
89
90 int main(int argc, char *argv[])
91 {
92
93   int T = (int)pow(2,4);
94   long* stabStateIndices;
95   
96   stabStateIndices = calloc(T+1,sizeof(long));
97
98   stabStateIndices[0] = (int)(pow(2,T))-1;
99
100   supplement(&stabStateIndices[0], T);
101
102   int i;
103   for(i=0; i<T+1; i++)
104     printBinary(stabStateIndices[i], T);
105   printf("\n");
106   
107   return 0;
108   
109 }