6namespace quids::rules::quantum_computer {
7 using namespace std::complex_literals;
11 for (
auto oid = 0; oid < iter.num_object; ++oid) {
15 iter.get_object(oid, begin, size, mag);
17 std::cout <<
"\t" << mag.real() << (mag.imag() < 0 ?
" - " :
" + ") << std::abs(mag.imag()) <<
"i ";
18 for (
auto it = begin; it != begin + size; ++it)
19 std::cout << (*it ?
'1' :
'0');
25 modifier_t inline cnot(uint32_t control_bit, uint32_t bit) {
26 return [=](
char* begin,
char* end,
mag_t &mag) {
27 begin[bit] ^= begin[control_bit];
35 hadamard(
size_t bit_) : bit(bit_) {}
36 inline void get_num_child(
char const *parent_begin,
char const *parent_end, uint &num_child, uint &max_child_size)
const override {
38 max_child_size = std::distance(parent_begin, parent_end);
40 inline void populate_child(
char const *parent_begin,
char const *parent_end,
char*
const child_begin, uint
const child_id, uint &size,
mag_t &mag)
const override {
41 static const PROBA_TYPE sqrt2 = 1/std::sqrt(2);
42 mag *= parent_begin[bit] && child_id ? -sqrt2 : sqrt2;
44 size = std::distance(parent_begin, parent_end);
45 for (
auto i = 0; i < size; ++i)
46 child_begin[i] = parent_begin[i];
48 child_begin[bit] ^= !child_id;
53 return [=](
char* begin,
char* end,
mag_t &mag) {
54 begin[bit] = !begin[bit];
59 return [=](
char* begin,
char* end,
mag_t &mag) {
64 begin[bit] = !begin[bit];
69 return [=](
char* begin,
char* end,
mag_t &mag) {
73 begin[bit] = !begin[bit];
class represneting a dynamic (or rule).
Definition: quids.hpp:100
std::complex< PROBA_TYPE > mag_t
complex magnitude type
Definition: quids.hpp:73
class iteration it_t
iteration class type
Definition: quids.hpp:75
std::function< void(char *parent_begin, char *parent_end, mag_t &mag)> modifier_t
simple "modifier" type (single input, single output of same size dynamic)
Definition: quids.hpp:81