Beispiel #1
0
void quantum_print_qureg( quantum_reg reg )
{
  int i = 0, j;
  for ( ; i < reg.size; i++ )
  {
    printf( "% f %+fi|%lli&gt; (%e) (|", quantum_real( reg.node[ i ].amplitude ), quantum_imag( reg.node[ i ].amplitude ), reg.node[ i ].state, quantum_prob_inline( reg.node[ i ].amplitude ) );
    j = reg.width - 1;
    for ( ; j >= 0; j-- )
    {
      if ( ( j % 4 ) == 3 )
        putchar( 32 );
      printf( "%i", (int)( reg.node[ i ].state >> (unsigned char)( j ) ) & 1 );
      //j--;
    }
    puts( "&gt;)" );
    //i++;
  }
  putchar( 10 );
  return;
}
Beispiel #2
0
float quantum_purity( quantum_density_op *rho )
{
  int i, j, k, l;
  float f = 0.0;
  float _Complex g, dp;
  i = 0;
  for ( ; i < rho->num; i++ )
  {
    f += rho->prob[ i ] * rho->prob[ i ];
    //i++;
  }
  i = 0;
  for ( ; i < rho->num; i++ )
  {
    j = 0;
    for ( ; j < i; j++ )
    {
      dp = quantum_dot_product( &rho->reg[ i ], &rho->reg[ j ] );
      k = 0;
      for ( ; k < rho->reg[ i ].size; k++ )
      {
        l = quantum_get_state( rho->reg[ i ].node[ k ].state, rho->reg[ j ] );
        if ( l >= 0 )
        {
          g = rho->reg[ i ].node[ k ].amplitude * dp * rho->prob[ i ] * rho->prob[ j ] * quantum_conj( rho->reg[ j ].node[ l ].amplitude );
        }
        else
          g = 0.0;
        f += quantum_real( g ) * (double)( 2 );
        //k++;
      }
      //j++;
    }
    //i++;
  }
  return f;
}
Beispiel #3
0
void quantum_print_matrix( quantum_matrix m )
{
  int i, j, z = 0;
  do
  {
    z++;
  }
  while ( ( ( ( 1 << z ) < m.rows ) & 255 ) != 0 );
  z--;
  i = 0;
  for ( ; i < m.rows; i++ )
  {
    j = 0;
    for ( ; j < m.cols; j++ )
    {
      printf( "%g %+gi ", quantum_real( m.t[ j + ( m.cols * i ) ] ), quantum_imag( m.t[ j + ( m.cols * i ) ] ) );
      //j++;
    }
    putchar( 10 );
    //i++;
  }
  putchar( 10 );
  return;
}