Quantum Computing Simulation and Visualization  
010000101110011010100111101101101110100110111111000010101000100110101001101110101101100010100111100000111111010010100001101000101011111111100010101100111111100000101011011110011010101101111111

Measuring Entanglement - Code

Real tangle( unsigned int k) const {

  Complex prod = 0; Real A = 0, B = 0, r = 0;

  unsigned long i = 0, j, k1 = 1LU << k; // k1 = 0...010...0, k'th bit = 1

  while( i < N) { // i will have k'th bit = 0, j will have k'th bit = 1

    j = i | k1; prod += Conj(a[i])*a[j];

    A += abs2(a[i]); B += abs2(a[j]);

    ++i; i += (i & k1); // skip i values with k'th bit = 1
  }

  Real t = 2*eps*eps*N; // threshold for zero norm squared: 2*sum{|e+i*e|**2} = 2*(2*e*e*(N/2))

  if( A > t && B > t) r = 1 - abs2(prod)/(A*B);

  return r;
}

qce++