quantum_register
このオブジェクトは量子ビットのセットを表します。量子ゲートオブジェクトと共に使用して、量子アルゴリズムをシミュレートすることができます。
C ++サンプルプログラム:quantum_computing_ex.cpp
#include <dlib / quantum_computing.h>
class quantum_register { /*! INITIAL VALUE - num_bits() == 1 - state_vector().nr() == 2 - state_vector().nc() == 1 - state_vector()(0) == 1 - state_vector()(1) == 0 - probability_of_bit(0) == 0 - i.e. This register represents a single quantum bit and it is completely in the 0 state. WHAT THIS OBJECT REPRESENTS This object represents a set of quantum bits. !*/ public: quantum_register( ); /*! ensures - this object is properly initialized !*/ int num_bits ( ) const; /*! ensures - returns the number of quantum bits in this register !*/ void set_num_bits ( int new_num_bits ); /*! requires - 1 <= new_num_bits <= 30 ensures - #num_bits() == new_num_bits - #state_vector().nr() == 2^new_num_bits (i.e. the size of the state_vector is exponential in the number of bits in a register) - for all valid i: - probability_of_bit(i) == 0 !*/ void zero_all_bits( ); /*! ensures - for all valid i: - probability_of_bit(i) == 0 !*/ void append ( const quantum_register& reg ); /*! ensures - #num_bits() == num_bits() + reg.num_bits() - #this->state_vector() == tensor_product(this->state_vector(), reg.state_vector()) - The original bits in *this become the high order bits of the resulting register and all the bits in reg end up as the low order bits in the resulting register. !*/ double probability_of_bit ( int bit ) const; /*! requires - 0 <= bit < num_bits() ensures - returns the probability of measuring the given bit and it being in the 1 state. - The returned value is also equal to the sum of norm(state_vector()(i)) for all i where the bit'th bit in i is set to 1. (note that the lowest order bit is bit 0) !*/ template <typename rand_type> bool measure_bit ( int bit, rand_type& rnd ); /*! requires - 0 <= bit < num_bits() - rand_type == an implementation of dlib/rand/rand_float_abstract.h ensures - measures the given bit in this register. Let R denote the boolean result of the measurement, where true means the bit was measured to have value 1 and false means it had a value of 0. - if (R == true) then - returns true - #probability_of_bit(bit) == 1 - else - returns false - #probability_of_bit(bit) == 0 !*/ template <typename rand_type> bool measure_and_remove_bit ( int bit, rand_type& rnd ); /*! requires - num_bits() > 1 - 0 <= bit < num_bits() - rand_type == an implementation of dlib/rand/rand_float_abstract.h ensures - measures the given bit in this register. Let R denote the boolean result of the measurement, where true means the bit was measured to have value 1 and false means it had a value of 0. - #num_bits() == num_bits() - 1 - removes the bit that was measured from this register. - if (R == true) then - returns true - else - returns false !*/ const matrix<qc_scalar_type,0,1>& state_vector( ) const; /*! ensures - returns a const reference to the state vector that describes the state of the quantum bits in this register. !*/ matrix<qc_scalar_type,0,1>& state_vector( ); /*! ensures - returns a non-const reference to the state vector that describes the state of the quantum bits in this register. !*/ void swap ( quantum_register& item ); /*! ensures - swaps *this and item !*/ }; inline void swap ( quantum_register& a, quantum_register& b ) { a.swap(b); } /*! provides a global swap function !*/