Пример #1
0
quantum_matrix quantum_density_matrix( quantum_density_op *rho )
{
  int i, j, k, l1, l2, dim = 1 << rho->reg->width;
  quantum_matrix m;
  if ( dim < 0 )
    quantum_error( 3 );
  m = quantum_new_matrix( dim, dim );
  k = 0;
  for ( ; k < rho->num; k++ )
  {
    quantum_reconstruct_hash( &rho->reg[ k ] );
    i = 0;
    for ( ; i < dim; i++ )
    {
      j = 0;
      for ( ; j < dim; j++ )
      {
        l1 = quantum_get_state( i, rho->reg[ k ] );
        l2 = quantum_get_state( j, rho->reg[ k ] );
        if ( l1 >= 0 && l2 >= 0 )
        {
          m.t[ i + ( m.cols * j ) ] += rho->reg[ k ].node[ l2 ].amplitude * rho->prob[ k ] * quantum_conj( rho->reg[ k ].node[ l1 ].amplitude );
        }
        //j++;
      }
      //i++;
    }
    //k++;
  }
  return m;
}
Пример #2
0
quantum_matrix quantum_mmult( quantum_matrix A, quantum_matrix B )
{
  int i, j, k;
  quantum_matrix C;
  if ( A.cols != B.rows )
    quantum_error( 4 );
  C = quantum_new_matrix( B.cols, A.rows );
  i = 0;
  for ( ; i < B.cols; i++ )
  {
    j = 0;
    for ( ; j < A.rows; j++ )
    {
      k = 0;
      for ( ; k < B.rows; k++ )
      {
        C.t[ i + ( C.cols * j ) ] += B.t[ i + ( B.cols * k ) ] * A.t[ k + ( A.cols * j ) ];
        //k++;
      }
      //j++;
    }
    //i++;
  }
  return C;
}
Пример #3
0
quantum_matrix quantum_qureg2matrix( quantum_reg reg )
{
  quantum_matrix m = quantum_new_matrix( 1, 1 << reg.width );
  int i = 0;
  for ( ; i < reg.size; i++ )
  {
    m.t[ (reg.node[ i ].state & 0xFFFFFFFF) ] = reg.node[ i ].amplitude;
    //i++;
  }
  return m;
}