/* When the user clicks on the button, toggle between hiding and showing the dropdown content */



added code, README and Makefile
[strong_simulation_gauss_sum_rank.git] / gausssums_multipleof6.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <complex.h>
4 #include <math.h>
5
6 int readPaulicoeffs(int* alpha, int* beta, int* gamma, int* delta, int numqubits);
7 complex double Gausssum1d(int quadraticcoeff, int linearcoeff);
8 complex double Kroneck(int arg);
9   
10 // order of matrix elements is [row][column]!!!
11
12 int main()
13 {
14
15   int i;
16   int x, y, xp, yp;
17   
18   int N;              // number of qubits
19   scanf("%d", &N);
20   if(N%6!=0) {
21     printf("Error: N must be a multiple of 6!\n");
22     return 1;
23   }
24
25   int alpha[N], beta[N], gamma[N], delta[N];
26
27   double complex summand, sum;
28
29   while(readPaulicoeffs(alpha, beta, gamma, delta, N)) {
30
31     /* for(i=0; i<N; i++) */
32     /*   printf("%d %d %d %d\n", alpha[i], beta[i], gamma[i], delta[i]); */
33
34     sum = 1.0+0.0*I;
35     for(i=0; i<N; i+=6) {
36       summand = 0.0*I;
37       for(y=0; y<=1; y++) {
38         //for(x=0;x<=(y*(gamma[i]+gamma[i+1])+(y+1)*(gamma[i]+delta[i+1]))%2; x++) {
39         for(x=y*(beta[i]+alpha[i+1]+beta[i+1])%2;x<=(y*(beta[i]+alpha[i+1]+beta[i+1])+y*(gamma[i]+gamma[i+1])+(y+1)*(gamma[i]+delta[i+1]))%2; x++) {
40           for(yp=((gamma[i+3]+delta[i+4])*x)%2; yp<=(1+(gamma[i+3]+gamma[i+4])*x)%2; yp++) {
41             //strange that I don't need the following modification to x
42           //****for(yp=((gamma[i+3]+delta[i+4])*x*(1+alpha[i]+beta[i]))%2; yp<=(1+(gamma[i+3]+gamma[i+4])*x*(1+alpha[i]+beta[i]))%2; yp++) {
43             for(xp=yp*(beta[i+3]+alpha[i+4]+beta[i+4])%2;xp<=(yp*(beta[i+3]+alpha[i+4]+beta[i+4])+yp*(gamma[i+3]+gamma[i+4])+(yp+1)*(gamma[i+3]+delta[i+4]))%2; xp++) {
44           //for(xp=0;xp<=(yp*(gamma[i+3]+gamma[i+4])+(yp+1)*(gamma[i+3]+delta[i+4]))%2; xp++) {
45               summand += 2.0*(0.125*pow(2.0,(1-y*pow(gamma[i]-gamma[i+1],2)-pow(y-1,2)*pow(gamma[i]-delta[i+1],2))*(1-yp*pow(gamma[i+3]-gamma[i+4],2)-pow(yp-1,2)*pow(gamma[i+3]-delta[i+4],2)))*cexp(M_PI*I/2.0*((delta[i+1]-gamma[i])*pow(y+1,2)+2.0*(beta[i]+beta[i+1]+gamma[i]+delta[i+1])*x*pow(y+1,2)+2.0*(delta[i]+delta[i+1]+beta[i]+beta[i+1])*x*y+(2.0*beta[i]+3.0*delta[i]+delta[i+1])*y))*Gausssum1d(0.0,beta[i+2])*Kroneck(gamma[i]+delta[i]-gamma[i+1]-delta[i+1])*Kroneck(gamma[i+2]+delta[i+2]) 
46                               + 0.125*pow(2.0,(1-y*pow(gamma[i]-gamma[i+1],2)-pow(y-1,2)*pow(gamma[i]-delta[i+1],2))*(1-yp*pow(gamma[i+3]-gamma[i+4],2)-pow(yp-1,2)*pow(gamma[i+3]-delta[i+4],2)))*cexp(M_PI*I/2.0*((delta[i+1]-gamma[i])*pow(y+1,2)+2.0*(beta[i]+beta[i+1]+gamma[i]+delta[i+1])*x*pow(y+1,2)+2.0*(delta[i]+delta[i+1]+beta[i]+beta[i+1])*x*y+(2.0*beta[i]+3.0*delta[i]+delta[i+1])*y))*csqrt(-I)*Gausssum1d(gamma[i+2]+delta[i+2],0)*Kroneck(gamma[i]+delta[i]-gamma[i+1]-delta[i+1])*Kroneck(alpha[i+2]+beta[i+2]))
47                 *(0.125*cexp(M_PI*I/2.0*((delta[i+4]-gamma[i+3])*pow(yp+1,2)+2.0*(beta[i+3]+beta[i+4]+gamma[i+3]+delta[i+4])*xp*pow(yp+1,2)+2.0*(delta[i+3]+delta[i+4]+beta[i+3]+beta[i+4])*xp*yp+(2.0*beta[i+3]+3.0*delta[i+3]+delta[i+4])*yp))*Gausssum1d(0.0,beta[i+5])*Kroneck(gamma[i+3]+delta[i+3]-gamma[i+4]-delta[i+4])*Kroneck(gamma[i+5]+delta[i+5]) 
48                   + 0.125*cexp(M_PI*I/2.0*((delta[i+4]-gamma[i+3])*pow(yp+1,2)+2.0*(beta[i+3]+beta[i+4]+gamma[i+3]+delta[i+4])*xp*pow(yp+1,2)+2.0*(delta[i+3]+delta[i+4]+beta[i+3]+beta[i+4])*xp*yp+(2.0*beta[i+3]+3.0*delta[i+3]+delta[i+4])*yp))*csqrt(-I)*Gausssum1d(gamma[i+5]+delta[i+5],0)*Kroneck(gamma[i+3]+delta[i+3]-gamma[i+4]-delta[i+4])*Kroneck(alpha[i+5]+beta[i+5]));
49             }
50           }
51           for(yp=0; yp<=(1+alpha[i+5])%2; yp++) {
52             for(xp=0;xp<=(1+beta[i+5])%2; xp++) {
53               summand += (0.125*pow(2.0,1-y*pow(gamma[i]-gamma[i+1],2)-pow(y-1,2)*pow(gamma[i]-delta[i+1],2))*cexp(M_PI*I/2.0*((delta[i+1]-gamma[i])*pow(y+1,2)+2.0*(beta[i]+beta[i+1]+gamma[i]+delta[i+1])*x*pow(y+1,2)+2.0*(delta[i]+delta[i+1]+beta[i]+beta[i+1])*x*y+(2.0*beta[i]+3.0*delta[i]+delta[i+1])*y))*Gausssum1d(0.0,beta[i+2])*Kroneck(gamma[i]+delta[i]-gamma[i+1]-delta[i+1])*Kroneck(gamma[i+2]+delta[i+2]) 
54                           + 0.125*pow(2.0,1-y*pow(gamma[i]-gamma[i+1],2)-pow(y-1,2)*pow(gamma[i]-delta[i+1],2))*cexp(M_PI*I/2.0*((delta[i+1]-gamma[i])*pow(y+1,2)+2.0*(beta[i]+beta[i+1]+gamma[i]+delta[i+1])*x*pow(y+1,2)+2.0*(delta[i]+delta[i+1]+beta[i]+beta[i+1])*x*y+(2.0*beta[i]+3.0*delta[i]+delta[i+1])*y))*csqrt(-I)*Gausssum1d(gamma[i+2]+delta[i+2],0)*Kroneck(gamma[i]+delta[i]-gamma[i+1]-delta[i+1])*Kroneck(alpha[i+2]+beta[i+2]))
55                 *(0.125*2.0*csqrt(-I)*cexp(M_PI*I/2.0*(2.0*beta[i+5]*yp+pow(xp+1,2)*(delta[i+3]+gamma[i+4]+2.0*beta[i+4])+xp*(delta[i+3]+delta[i+4])))*Gausssum1d(1,beta[i+3]+beta[i+4]+delta[i+3]+(xp+1)*gamma[i+4]+xp*delta[i+4])*Kroneck(gamma[i+3]+delta[i+3]-gamma[i+4]-delta[i+4]+1)*Kroneck(gamma[i+5]+delta[i+5]));
56             }
57           }
58           //for(yp=x; yp<=1; yp++) {
59           for(yp=x*(1+alpha[i]+beta[i])%2; yp<=1; yp++) {
60             //for(xp=(yp*(delta[i+3]+delta[i+4])+x)%2;xp<=(1+yp*(gamma[i+3]+gamma[i+4])+x)%2; xp++) {
61             for(xp=(yp*(delta[i+3]+delta[i+4])+x*(1+alpha[i]+beta[i]))%2;xp<=(1+yp*(gamma[i+3]+gamma[i+4])+x*(1+alpha[i]+beta[i]))%2; xp++) {
62               summand += 2.0*(0.125*pow(2.0,(1-y*pow(gamma[i]-gamma[i+1],2)-pow(y-1,2)*pow(gamma[i]-delta[i+1],2))*(pow(yp-1,2)*(pow(xp,2)*(gamma[i+3]+delta[i+4])+pow(xp-1,2)*(gamma[i+4]+delta[i+3]))))*cexp(M_PI*I/2.0*((delta[i+1]-gamma[i])*pow(y+1,2)+2.0*(beta[i]+beta[i+1]+gamma[i]+delta[i+1])*x*pow(y+1,2)+2.0*(delta[i]+delta[i+1]+beta[i]+beta[i+1])*x*y+(2.0*beta[i]+3.0*delta[i]+delta[i+1])*y))*Gausssum1d(0.0,beta[i+2])*Kroneck(gamma[i]+delta[i]-gamma[i+1]-delta[i+1])*Kroneck(gamma[i+2]+delta[i+2]) 
63                           + 0.125*pow(2.0,(1-y*pow(gamma[i]-gamma[i+1],2)-pow(y-1,2)*pow(gamma[i]-delta[i+1],2))*(pow(yp-1,2)*(pow(xp,2)*(gamma[i+3]+delta[i+4])+pow(xp-1,2)*(gamma[i+4]+delta[i+3]))))*cexp(M_PI*I/2.0*((delta[i+1]-gamma[i])*pow(y+1,2)+2.0*(beta[i]+beta[i+1]+gamma[i]+delta[i+1])*x*pow(y+1,2)+2.0*(delta[i]+delta[i+1]+beta[i]+beta[i+1])*x*y+(2.0*beta[i]+3.0*delta[i]+delta[i+1])*y))*csqrt(-I)*Gausssum1d(gamma[i+2]+delta[i+2],0)*Kroneck(gamma[i]+delta[i]-gamma[i+1]-delta[i+1])*Kroneck(alpha[i+2]+beta[i+2]))
64                 *(0.125*(-I)*cexp(M_PI*I/2.0*(yp*(delta[i+3]+delta[i+4])+pow(yp+1,2)*(delta[i+3]+gamma[i+4]+2*beta[i+4])+pow(xp,2)+2*(beta[i+3]+beta[i+4]+delta[i+3]+gamma[i+4]*(yp+1)+delta[i+4]*yp)*xp))*Gausssum1d(0,xp+beta[i+3]+beta[i+4]+delta[i+3]+gamma[i+4]*(yp+1)+delta[i+4]*yp+gamma[i+5]+delta[i+5])*Kroneck(gamma[i+3]+delta[i+3]-gamma[i+4]-delta[i+4]+1)*Kroneck(alpha[i+5]+beta[i+5]));
65             }
66           }
67         }
68       }
69
70       for(y=0; y<=(1+alpha[i+2])%2; y++) {
71         for(x=0; x<=(1+beta[i+2])%2; x++) {
72           for(yp=0; yp<=1; yp++) {
73             for(xp=yp*(beta[i+3]+alpha[i+4]+beta[i+4])%2;xp<=(yp*(beta[i+3]+alpha[i+4]+beta[i+4])+yp*(gamma[i+3]+gamma[i+4])+(yp+1)*(gamma[i+3]+delta[i+4]))%2; xp++) {
74               //for(xp=0;xp<=(yp*(gamma[i+3]+gamma[i+4])+(yp+1)*(gamma[i+3]+delta[i+4]))%2; xp++) {
75               summand += (0.125*2.0*csqrt(-I)*cexp(M_PI*I/2.0*(2.0*beta[i+2]*y+pow(x+1,2)*(delta[i]+gamma[i+1]+2.0*beta[i+1])+x*(delta[i]+delta[i+1])))*Gausssum1d(1,beta[i]+beta[i+1]+delta[i]+(x+1)*gamma[i+1]+x*delta[i+1])*Kroneck(gamma[i]+delta[i]-gamma[i+1]-delta[i+1]+1)*Kroneck(gamma[i+2]+delta[i+2]))
76                 *(0.125*pow(2.0,1-yp*pow(gamma[i+3]-gamma[i+4],2)-pow(yp-1,2)*pow(gamma[i+3]-delta[i+4],2))*cexp(M_PI*I/2.0*((delta[i+4]-gamma[i+3])*pow(yp+1,2)+2.0*(beta[i+3]+beta[i+4]+gamma[i+3]+delta[i+4])*xp*pow(yp+1,2)+2.0*(delta[i+3]+delta[i+4]+beta[i+3]+beta[i+4])*xp*yp+(2.0*beta[i+3]+3.0*delta[i+3]+delta[i+4])*yp))*Gausssum1d(0.0,beta[i+5])*Kroneck(gamma[i+3]+delta[i+3]-gamma[i+4]-delta[i+4])*Kroneck(gamma[i+5]+delta[i+5]) 
77                   + 0.125*pow(2.0,1-yp*pow(gamma[i+3]-gamma[i+4],2)-pow(yp-1,2)*pow(gamma[i+3]-delta[i+4],2))*cexp(M_PI*I/2.0*((delta[i+4]-gamma[i+3])*pow(yp+1,2)+2.0*(beta[i+3]+beta[i+4]+gamma[i+3]+delta[i+4])*xp*pow(yp+1,2)+2.0*(delta[i+3]+delta[i+4]+beta[i+3]+beta[i+4])*xp*yp+(2.0*beta[i+3]+3.0*delta[i+3]+delta[i+4])*yp))*csqrt(-I)*Gausssum1d(gamma[i+5]+delta[i+5],0)*Kroneck(gamma[i+3]+delta[i+3]-gamma[i+4]-delta[i+4])*Kroneck(alpha[i+5]+beta[i+5]));
78             }
79           }
80           for(yp=0; yp<=(1+alpha[i+5])%2; yp++) {
81             for(xp=0;xp<=(1+beta[i+5])%2; xp++) {
82               summand += (0.125*2.0*csqrt(-I)*cexp(M_PI*I/2.0*(2.0*beta[i+2]*y+pow(x+1,2)*(delta[i]+gamma[i+1]+2.0*beta[i+1])+x*(delta[i]+delta[i+1])))*Gausssum1d(1,beta[i]+beta[i+1]+delta[i]+(x+1)*gamma[i+1]+x*delta[i+1])*Kroneck(gamma[i]+delta[i]-gamma[i+1]-delta[i+1]+1)*Kroneck(gamma[i+2]+delta[i+2]))
83                 *(0.125*2.0*csqrt(-I)*cexp(M_PI*I/2.0*(2.0*beta[i+5]*yp+pow(xp+1,2)*(delta[i+3]+gamma[i+4]+2.0*beta[i+4])+xp*(delta[i+3]+delta[i+4])))*Gausssum1d(1,beta[i+3]+beta[i+4]+delta[i+3]+(xp+1)*gamma[i+4]+xp*delta[i+4])*Kroneck(gamma[i+3]+delta[i+3]-gamma[i+4]-delta[i+4]+1)*Kroneck(gamma[i+5]+delta[i+5]));
84             }
85           }
86           for(yp=0; yp<=1; yp++) {
87             for(xp=(yp*(delta[i+3]+delta[i+4]))%2;xp<=(1+yp*(gamma[i+3]+gamma[i+4]))%2; xp++) {
88               summand += (0.125*2.0*csqrt(-I)*cexp(M_PI*I/2.0*(2.0*beta[i+2]*y+pow(x+1,2)*(delta[i]+gamma[i+1]+2.0*beta[i+1])+x*(delta[i]+delta[i+1])))*Gausssum1d(1,beta[i]+beta[i+1]+delta[i]+(x+1)*gamma[i+1]+x*delta[i+1])*Kroneck(gamma[i]+delta[i]-gamma[i+1]-delta[i+1]+1)*Kroneck(gamma[i+2]+delta[i+2]))
89                 *(0.125*(-I)*pow(2.0,(pow(yp-1,2)*(pow(xp,2)*(gamma[i+3]+delta[i+4])+pow(xp-1,2)*(gamma[i+4]+delta[i+3]))))*cexp(M_PI*I/2.0*(yp*(delta[i+3]+delta[i+4])+pow(yp+1,2)*(delta[i+3]+gamma[i+4]+2*beta[i+4])+pow(xp,2)+2*(beta[i+3]+beta[i+4]+delta[i+3]+gamma[i+4]*(yp+1)+delta[i+4]*yp)*xp))*Gausssum1d(0,xp+beta[i+3]+beta[i+4]+delta[i+3]+gamma[i+4]*(yp+1)+delta[i+4]*yp+gamma[i+5]+delta[i+5])*Kroneck(gamma[i+3]+delta[i+3]-gamma[i+4]-delta[i+4]+1)*Kroneck(alpha[i+5]+beta[i+5]));
90             }
91           }
92         }
93       }
94
95       for(y=0; y<=1; y++) {
96         for(x=(y*(delta[i]+delta[i+1]))%2; x<=(1+y*(gamma[i]+gamma[i+1]))%2; x++) {
97           for(yp=((gamma[i+3]+delta[i+4])*y)%2; yp<=(1+(gamma[i+3]+gamma[i+4])*y)%2; yp++) {
98             for(xp=yp*(beta[i+3]+alpha[i+4]+beta[i+4])%2;xp<=(yp*(beta[i+3]+alpha[i+4]+beta[i+4])+yp*(gamma[i+3]+gamma[i+4])+(yp+1)*(gamma[i+3]+delta[i+4]))%2; xp++) {
99               //for(xp=0;xp<=(yp*(gamma[i+3]+gamma[i+4])+(yp+1)*(gamma[i+3]+delta[i+4]))%2; xp++) {
100               summand += 2.0*(0.125*pow(2.0,(pow(y-1,2)*(pow(x,2)*(gamma[i]+delta[i+1])+pow(x-1,2)*(gamma[i+1]+delta[i])))*(1-yp*pow(gamma[i+3]-gamma[i+4],2)-pow(yp-1,2)*pow(gamma[i+3]-delta[i+4],2)))*(-I)*cexp(M_PI*I/2.0*(y*(delta[i]+delta[i+1])+pow(y+1,2)*(delta[i]+gamma[i+1]+2*beta[i+1])+pow(x,2)+2*(beta[i]+beta[i+1]+delta[i]+gamma[i+1]*(y+1)+delta[i+1]*y)*x))*Gausssum1d(0,x+beta[i]+beta[i+1]+delta[i]+gamma[i+1]*(y+1)+delta[i+1]*y+gamma[i+2]+delta[i+2])*Kroneck(gamma[i]+delta[i]-gamma[i+1]-delta[i+1]+1)*Kroneck(alpha[i+2]+beta[i+2]))
101                 *(0.125*cexp(M_PI*I/2.0*((delta[i+4]-gamma[i+3])*pow(yp+1,2)+2.0*(beta[i+3]+beta[i+4]+gamma[i+3]+delta[i+4])*xp*pow(yp+1,2)+2.0*(delta[i+3]+delta[i+4]+beta[i+3]+beta[i+4])*xp*yp+(2.0*beta[i+3]+3.0*delta[i+3]+delta[i+4])*yp))*Gausssum1d(0.0,beta[i+5])*Kroneck(gamma[i+3]+delta[i+3]-gamma[i+4]-delta[i+4])*Kroneck(gamma[i+5]+delta[i+5]) 
102                   + 0.125*cexp(M_PI*I/2.0*((delta[i+4]-gamma[i+3])*pow(yp+1,2)+2.0*(beta[i+3]+beta[i+4]+gamma[i+3]+delta[i+4])*xp*pow(yp+1,2)+2.0*(delta[i+3]+delta[i+4]+beta[i+3]+beta[i+4])*xp*yp+(2.0*beta[i+3]+3.0*delta[i+3]+delta[i+4])*yp))*csqrt(-I)*Gausssum1d(gamma[i+5]+delta[i+5],0)*Kroneck(gamma[i+3]+delta[i+3]-gamma[i+4]-delta[i+4])*Kroneck(alpha[i+5]+beta[i+5]));
103             }
104           }
105           for(yp=0; yp<=(1+alpha[i+5])%2; yp++) {
106             for(xp=0;xp<=(1+beta[i+5])%2; xp++) {
107               summand += (0.125*pow(2.0,pow(y-1,2)*(pow(x,2)*(gamma[i]+delta[i+1])+pow(x-1,2)*(gamma[i+1]+delta[i])))*(-I)*cexp(M_PI*I/2.0*(y*(delta[i]+delta[i+1])+pow(y+1,2)*(delta[i]+gamma[i+1]+2*beta[i+1])+pow(x,2)+2*(beta[i]+beta[i+1]+delta[i]+gamma[i+1]*(y+1)+delta[i+1]*y)*x))*Gausssum1d(0,x+beta[i]+beta[i+1]+delta[i]+gamma[i+1]*(y+1)+delta[i+1]*y+gamma[i+2]+delta[i+2])*Kroneck(gamma[i]+delta[i]-gamma[i+1]-delta[i+1]+1)*Kroneck(alpha[i+2]+beta[i+2]))
108                 *(0.125*2.0*csqrt(-I)*cexp(M_PI*I/2.0*(2.0*beta[i+5]*yp+pow(xp+1,2)*(delta[i+3]+gamma[i+4]+2.0*beta[i+4])+xp*(delta[i+3]+delta[i+4])))*Gausssum1d(1,beta[i+3]+beta[i+4]+delta[i+3]+(xp+1)*gamma[i+4]+xp*delta[i+4])*Kroneck(gamma[i+3]+delta[i+3]-gamma[i+4]-delta[i+4]+1)*Kroneck(gamma[i+5]+delta[i+5]));
109             }
110           }
111           for(yp=y; yp<=1; yp++) {
112             for(xp=(yp*(delta[i+3]+delta[i+4])+y)%2;xp<=(1+yp*(gamma[i+3]+gamma[i+4])+y)%2; xp++) {
113               summand += 2.0*(0.125*pow(2.0,(pow(y-1,2)*(pow(x,2)*(gamma[i]+delta[i+1])+pow(x-1,2)*(gamma[i+1]+delta[i])))*(pow(yp-1,2)*(pow(xp,2)*(gamma[i+3]+delta[i+4])+pow(xp-1,2)*(gamma[i+4]+delta[i+3]))))*(-I)*cexp(M_PI*I/2.0*(y*(delta[i]+delta[i+1])+pow(y+1,2)*(delta[i]+gamma[i+1]+2*beta[i+1])+pow(x,2)+2*(beta[i]+beta[i+1]+delta[i]+gamma[i+1]*(y+1)+delta[i+1]*y)*x))*Gausssum1d(0,x+beta[i]+beta[i+1]+delta[i]+gamma[i+1]*(y+1)+delta[i+1]*y+gamma[i+2]+delta[i+2])*Kroneck(gamma[i]+delta[i]-gamma[i+1]-delta[i+1]+1)*Kroneck(alpha[i+2]+beta[i+2]))
114                 *(0.125*(-I)*cexp(M_PI*I/2.0*(yp*(delta[i+3]+delta[i+4])+pow(yp+1,2)*(delta[i+3]+gamma[i+4]+2*beta[i+4])+pow(xp,2)+2*(beta[i+3]+beta[i+4]+delta[i+3]+gamma[i+4]*(yp+1)+delta[i+4]*yp)*xp))*Gausssum1d(0,xp+beta[i+3]+beta[i+4]+delta[i+3]+gamma[i+4]*(yp+1)+delta[i+4]*yp+gamma[i+5]+delta[i+5])*Kroneck(gamma[i+3]+delta[i+3]-gamma[i+4]-delta[i+4]+1)*Kroneck(alpha[i+5]+beta[i+5]));
115             }
116           }
117         }
118       }
119
120       sum *= summand;
121     }
122     //printf("%lf+%lfI\n", creal(sum), cimag(sum));
123     printf("%lf\n", cabs(creal(sum))); 
124
125
126   }
127
128   return 0;
129 }
130
131 complex double Kroneck(int arg)
132 {
133   arg = (arg+1)%2; // output 1 if argument is 0 mod 2 and 0 otherwise
134   return ((complex double)arg);
135 }
136
137 complex double Gausssum1d(int quadraticcoeff, int linearcoeff)
138 {
139   /*****************************************
140   /* NOTE! we assume coeffs are either 0 or 1
141   /* (So you cannot pass off a linear coeff as a quadratic coeff by multiplying it by a factor of 2 (and considering it as mod 4)!)
142   *****************************************/
143   
144   quadraticcoeff %= 2;
145   linearcoeff %= 2;
146     
147   if(quadraticcoeff == 0)
148     if(linearcoeff == 0)
149       return 2.0+0.0*I;
150     else
151       return 0.0*I;
152   else
153     if(linearcoeff == 0)
154       return 1.0+1.0*I;
155     else
156       return 1.0-1.0*I;
157
158 }
159
160 int readPaulicoeffs(int *alpha, int *beta, int *gamma, int *delta, int numqubits)
161 {
162
163   int i;
164
165   if(scanf("%d %d %d %d", &alpha[0], &beta[0], &gamma[0], &delta[0]) != EOF) {
166     for(i=1; i<numqubits; i++) {
167       scanf("%d %d %d %d", &alpha[i], &beta[i], &gamma[i], &delta[i]);
168     }
169     return 1;
170   } else
171     return 0;
172
173 }
174
175
176