SlideShare a Scribd company logo
@copyright Russell John Childs, PhD, 11th March 2017
========================================================================================
Simple demo of C++ framework allowing quantum mechanics to be done with Matrix Mechanics using Dirac Bras,
Kets, inner, outer products, operators.
========================================================================================
Output of code (see later):
===========================================
Usage model:
===========================================
e^(i*theta): Polar notation cos theta + i sin theta
a + i*b: Cartesian notation a + i b
(e^(i*p/4))*Bra<3>{"010"}: Creates 3-qubit bra e^(i pi/4) <010|
Ket<3>{"010"}: Creates 3-qubit ket |010>
Bra<3>{"010"}*Ket<3>{"010"}: Inner product <010|010> = 1
Bra<3>{"010"}*Ket<3>{"110"}: Inner product <010|110> = 0
Bra<2>{"01"}*Ket<3>{"011"}: Inner product <01|011> = |1>
Bra<2>{"01"}*Bra<3>{"011"}: tensor prod <01|<011| = <01011|
Ket<2>{"01"}*Ket<3>{"011"}: tensor prod |01>|011> = |01011>
cos(theta)*Ket<1>{"0"}*Bra<1>{"0"} - sin(theta)*Ket<1>{"0"}*Bra<1>{"1"}+ sin(theta)*Ket<1>{"1"}*Bra<1>{"0"}+
cos(theta)*Ket<1>{"1"}*Bra<1>{"1"}:
Ry(2*theta) =
-- --
| cos theta |0><0| -sin theta |0><1| |
| sin theta |1><0| cos theta |1><1| |
-- --
Passive rotation operator. Applied to
alpha*Ket<1>{"0"} + beta*Ket<1>{"1"} = alpha |0> + beta |1> =
-- --
| alpha |
| beta |
-- --
Ket<1>{"0"}*Bra<1>{"0"} & Ket<1>{"1"}*Bra<1>{"1"} - operator tensor product |0><0| & |1><1| = |01><01|
(Ket<2>{"00"} >> Hadamard >> CNOT21) - the quantum circuit: |00> -- H -- CNOT21 = 1/sqrt_2(|00> + |11>), i.e. entangled
(psi >> M >> bob) - performs a measurement on psi using the operator 'bob'
===========================================
End of Usage model:
===========================================
gates.X -> (1+i*0)|0><1| + (1+i*0)|1><0|
gates.Y -> (0-i*1)|0><1| + (0+i*1)|1><0|
gates.Z -> (1+i*0)|0><0| + (-1+i*0)|1><1|
gates.H -> (4.32978e-17+i*0.707107)|0><0| + (4.32978e-17+i*0.707107)|0><1| + (-4.32978e-17+i*0.707107)|1><0| + (4.32978e-
17-i*0.707107)|1><1|
gates.S -> (1+i*0)|0><0| + (0+i*1)|1><1|
gates.T -> (1+i*0)|0><0| + (0.707107+i*0.707107)|1><1|
CNOT = ((Ket<1>{"0"}*Bra<1>{"0"}&gates.I) + (Ket<1>{"1"}*Bra<1>{"1"}&gates.X)) -> (1+i*0)|00><00| + (1+i*0)|01><01| +
(1+i*0)|10><11| + (1+i*0)|11><10|
gates.controlled(gates.X) -> (1+i*0)|00><00| + (1+i*0)|01><01| + (1+i*0)|10><11| + (1+i*0)|11><10|
~((e^(i*pi/4))*Ket<1>{"0"}*Bra<1>{"1"}) = ~(e^ip/4 |0><1|) -> (0.707107-i*0.707107)|1><0|
~gates.S = ~((1+i*0)|0><0| + (0+i*1)|1><1|) -> (1+i*0)|0><0| + (0-i*1)|1><1|
Psi<Dirac::K,1>({"0"}) = |0> -> (1+i*0)*|0>
(Psi<Dirac::K,1>({"0"})>>gates.H) - single qubit quantum circuit |0> -- H -> (-4.32978e-17+i*0.707107)*|1> + (4.32978e-
17+i*0.707107)*|0>
(Psi<Dirac::K,2>({"00"}) >> Hadamard) -> (4.32978e-17+i*0.707107)*|00> + (0+i*0)*|10> + (0+i*0)*|11> + (-4.32978e-
17+i*0.707107)*|01>
CNOT21 -> (1+i*0)|00><00| + (1+i*0)|01><11| + (1+i*0)|10><10| + (1+i*0)|11><01|
(Psi<Dirac::K,2>({"00"}) >> Hadamard >> CNOT21) -> (4.32978e-17+i*0.707107)*|00> + (0+i*0)*|10> + (0+i*0)*|01> + (-4.32978e-
17+i*0.707107)*|11>
Bob -> (1+i*0)|00><00| + (1+i*0)|01><01| + (1+i*0)|10><10| + (1+i*0)|11><11|
Alice -> (1+i*0)|00><00| + (1+i*0)|01><01| + (1+i*0)|10><10| + (1+i*0)|11><11|
Measurements:
psi = (4.32978e-17+i*0.707107)*|00> + (0+i*0)*|10> + (0+i*0)*|01> + (-4.32978e-17+i*0.707107)*|11>, Bob : (6.12323e-
17+i*1)*|00>, Alice : (6.12323e-17+i*1)*|00>}
psi = (4.32978e-17+i*0.707107)*|00> + (0+i*0)*|10> + (0+i*0)*|01> + (-4.32978e-17+i*0.707107)*|11>, Bob : (-6.12323e-
17+i*1)*|11>, Alice : (-6.12323e-17+i*1)*|11>}
psi = (4.32978e-17+i*0.707107)*|00> + (0+i*0)*|10> + (0+i*0)*|01> + (-4.32978e-17+i*0.707107)*|11>, Bob : (6.12323e-
17+i*1)*|00>, Alice : (6.12323e-17+i*1)*|00>}
psi = (4.32978e-17+i*0.707107)*|00> + (0+i*0)*|10> + (0+i*0)*|01> + (-4.32978e-17+i*0.707107)*|11>, Bob : (-6.12323e-
17+i*1)*|11>, Alice : (-6.12323e-17+i*1)*|11>}
psi = (4.32978e-17+i*0.707107)*|00> + (0+i*0)*|10> + (0+i*0)*|01> + (-4.32978e-17+i*0.707107)*|11>, Bob : (-6.12323e-
17+i*1)*|11>, Alice : (-6.12323e-17+i*1)*|11>}
psi = (4.32978e-17+i*0.707107)*|00> + (0+i*0)*|10> + (0+i*0)*|01> + (-4.32978e-17+i*0.707107)*|11>, Bob : (6.12323e-
17+i*1)*|00>, Alice : (6.12323e-17+i*1)*|00>}
psi = (4.32978e-17+i*0.707107)*|00> + (0+i*0)*|10> + (0+i*0)*|01> + (-4.32978e-17+i*0.707107)*|11>, Bob : (-6.12323e-
17+i*1)*|11>, Alice : (-6.12323e-17+i*1)*|11>}
psi = (4.32978e-17+i*0.707107)*|00> + (0+i*0)*|10> + (0+i*0)*|01> + (-4.32978e-17+i*0.707107)*|11>, Bob : (6.12323e-
17+i*1)*|00>, Alice : (6.12323e-17+i*1)*|00>}
psi = (4.32978e-17+i*0.707107)*|00> + (0+i*0)*|10> + (0+i*0)*|01> + (-4.32978e-17+i*0.707107)*|11>, Bob : (6.12323e-
17+i*1)*|00>, Alice : (6.12323e-17+i*1)*|00>}
psi = (4.32978e-17+i*0.707107)*|00> + (0+i*0)*|10> + (0+i*0)*|01> + (-4.32978e-17+i*0.707107)*|11>, Bob : (6.12323e-
17+i*1)*|00>, Alice : (6.12323e-17+i*1)*|00>}
(10+20*i)*K{"1010"} -> (10+i*20)*|1010>
(10+20*i)*B{"1010"} -> <1010|*(10+i*20)
(e^(i*pi/4))*B{"1010"}*K{"1010"}*~(e^(i*pi/4)) -> 1+i*0
(K{"1010"}*~(e^(i*pi/4))*((e^(i*pi/4))*B{"1010"})) -> (1+i*0)|1010><1010|
(K{"1010"}*~(e^(i*pi/4))*((e^(i*pi/4))*B{"1010"}))*(K{"1010"}*~(e^(i*pi/4))) -> (0.707107-i*0.707107)*|1010>
(B{"1010"}*~(e^(i*pi/4)))*(K{"1010"}*~(e^(i*pi/4))*((e^(i*pi/4))*B{"1010"})) -> <1010|*(0.707107-i*0.707107)
(K{"1010"}*~(e^(i*pi/4)))*(K{"1010"}*~(e^(i*pi/4))) -> (2.22045e-16-i*1)*|10101010>
(B{"1010"}*~(e^(i*pi/4)))*(B{"1010"}*~(e^(i*pi/4))) -> <10101010|*(2.22045e-16-i*1)
Bra<2>{"10"}*Ket<3>{"100"} -> (1+i*0)*|0>
Bra<2>{"11"}*Ket<3>{"100"} -> (0+i*0)*|0>
Bra<5>{"10011"}*Ket<3>{"100"} -> <11|*(1+i*0)
(Bra<1>{"1"}*Bra<1>{"0"})*(Ket<1>{"1"}*Ket<1>{"0"}*Ket<1>{"0"}) -> (1+i*0)*|0>
(Bra<1>{"1"}*Bra<1>{"1"})*(Ket<1>{"1"}*Ket<2>{"00"}) -> (0+i*0)*|0>
Bra<1>{"1"}*(Ket<3>{"100"}*Bra<5>{"10011"})*(Bra<2>{"10"}*Bra<1>{"0"}) -> (1+i*0)|00><10011100|
Ket<1>{"1"}*(Ket<3>{"100"}*Bra<5>{"10011"})*(Bra<2>{"10"}*Bra<1>{"0"}) -> (1+i*0)|1100><10011100|
std::cos(pi/4)*Ket<1>{"0"} + std::sin(pi/4)*(e^(i*pi/4))*Ket<1>{"1"} ->(0.5+i*0.5)*|1> + (0.707107+i*0)*|0>
((elem*Ket<1>{"0"}*Bra<1>{"0"} - elem*Ket<1>{"0"}*Bra<1>{"1"} + (elem*Ket<1>{"1"}*Bra<1>{"0"} +
elem*Ket<1>{"1"}*Bra<1>{"1"}))) -> (0.707107+i*0)|0><0| + (-0.707107+i*0)|0><1| + (0.707107+i*0)|1><0| + (0.707107+i*0)|1><1|
10*i -> +i*10, i*10 -> +i*10
(10*(-i))*(10*i) -> 100
abs(10*i) -> 10, abs(i*10) -> 10
10 +100*i -> 10+i*100, 2*(10 +100*i) -> 20+i*200, (10 +100*i)*3 -> 30+i*300, 4*C{10,100*i} -> 40+i*400, C{10,100*i}*5 -> 50+i*500
(2+3*i)*C{4,5*i}-> -7+i*22
~(2+3*i)*C{2,3*i} -> 13+i*0
abs(~(2+3*i)*C{2,3*i}) -> 13
(e^(i*pi/4)).m_real -> 0.707107, abs((e^(i*pi/4)).m_real) -> 0.707107
(1000.0*e^(-i*pi/4)) -> 707.107-i*707.107, 1000*~(e^(i*pi/4)) -> 707.107-i*707.107
(e^(i*pi/4))*(e^(i*pi/4)) -> 2.22045e-16+i*1
~(e^(i*pi/4))*(e^(i*pi/4)) -> 1+i*0
Code:
int main(void)
{
using namespace QuantumGates;
typedef QuantumGates::Ket<4> K;
typedef QuantumGates::Bra<4> B;
std::cout << "===========================================" << std::endl;
std::cout << "Usage model:" << std::endl;
std::cout << "===========================================" << std::endl;
std::cout << "e^(i*theta): Polar notation cos theta + i sin theta"
<< std::endl;
std::cout << "a + i*b: Cartesian notation a + i b" << std::endl;
std::cout << "(e^(i*p/4))*Bra<3>{"010"}: Creates 3-qubit bra e^(i pi/4) "
"<010|" << std::endl;
std::cout << "Ket<3>{"010"}: Creates 3-qubit ket |010>" << std::endl;
std::cout << "Bra<3>{"010"}*Ket<3>{"010"}: Inner product <010|010> = 1"
<< std::endl;
std::cout << "Bra<3>{"010"}*Ket<3>{"110"}: Inner product <010|110> = 0"
<< std::endl;
std::cout << "Bra<2>{"01"}*Ket<3>{"011"}: Inner product <01|011> = "
"|1>" << std::endl;
std::cout << "Bra<2>{"01"}*Bra<3>{"011"}: tensor prod <01|<011| "
"= <01011|" << std::endl;
std::cout << "Ket<2>{"01"}*Ket<3>{"011"}: tensor prod |01>|011> = "
"|01011>" << std::endl;
std::cout << "cos(theta)*Ket<1>{"0"}*Bra<1>{"0"} "
"- sin(theta)*Ket<1>{"0"}*Bra<1>{"1"}"
"+ sin(theta)*Ket<1>{"1"}*Bra<1>{"0"}"
"+ cos(theta)*Ket<1>{"1"}*Bra<1>{"1"}: "
<< std::endl << " Ry(2*theta) = " << std::endl <<
" -- --" << std::endl<<
" | cos theta |0><0| -sin theta |0><1| |"<< std::endl<<
" | sin theta |1><0| cos theta |1><1| |"<< std::endl<<
" -- --" << std::endl<<
" Passive rotation operator. Applied to"
<< std::endl <<
" alpha*Ket<1>{"0"} + beta*Ket<1>{"1"} "
" = alpha |0> + beta |1> ="
<< std::endl<<
" -- --" << std::endl<<
" | alpha |" << std::endl<<
" | beta |" << std::endl<<
" -- --" << std::endl;
std::cout << "Ket<1>{"0"}*Bra<1>{"0"} & Ket<1>{"1"}*Bra<1>{"1"} -"
" operator tensor product |0><0| & |1><1| = |01><01|"
<< std::endl;
std::cout << "(Ket<2>{"00"} >> Hadamard >> CNOT21) - the quantum circuit:"
" |00> -- H -- CNOT21 = 1/sqrt_2(|00> + |11>), i.e. entangled"
<< std::endl;
std::cout << "(psi >> M >> bob) - performs a measurement on psi "
"using the operator 'bob' " << std::endl;
std::cout << "===========================================" << std::endl;
std::cout << "End of Usage model:" << std::endl;
std::cout << "==========================================="
<< std::endl;
auto gates = Gate::instance();
std::cout << "gates.X -> " << gates.X << std::endl;
std::cout << "gates.Y -> " << gates.Y << std::endl;
std::cout << "gates.Z -> " << gates.Z << std::endl;
std::cout << "gates.H -> " << gates.H << std::endl;
std::cout << "gates.S -> " << gates.S << std::endl;
std::cout << "gates.T -> " << gates.T << std::endl;
auto CNOT = ((Ket<1>{"0"}*Bra<1>{"0"}&gates.I) +
(Ket<1>{"1"}*Bra<1>{"1"}&gates.X));
std::cout << "CNOT = ((Ket<1>{"0"}*Bra<1>{"0"}&gates.I) + "
"(Ket<1>{"1"}*Bra<1>{"1"}&gates.X)) -> "
<< CNOT << std::endl;
std::cout << "gates.controlled(gates.X) -> " << gates.controlled(gates.X)
<< std::endl;
std::cout << "~((e^(i*pi/4))*Ket<1>{"0"}*Bra<1>{"1"}) "
"= ~(e^ip/4 |0><1|) -> "
<< ~((e^(i*pi/4))*Ket<1>{"0"}*Bra<1>{1}) << std::endl;
std::cout << "~gates.S = ~(" << gates.S << ") -> " << ~gates.S
<< std::endl;
std::cout << "Psi<Dirac::K,1>({"0"}) = |0> -> " << Psi<Dirac::K,1>({"0"}) << std::endl;
std::cout << "(Psi<Dirac::K,1>({"0"})>>gates.H) - single qubit quantum circuit"
" |0> -- H -> " << (Psi<Dirac::K,1>({"0"})>>gates.H) << std::endl;
auto Hadamard = ((Ket<1>{"0"}*Bra<1>{"0"}&gates.H) +
(Ket<1>{"1"}*Bra<1>{"1"}&gates.I));
std::cout << "(Psi<Dirac::K,2>({"00"}) >> Hadamard) -> "
<< (Psi<Dirac::K,2>({"00"}) >> Hadamard) << std::endl;
auto CNOT21 = Ket<2>{"00"}*Bra<2>{"00"} + Ket<2>{"01"}*Bra<2>{"11"} +
Ket<2>{"10"}*Bra<2>{"10"} + Ket<2>{"11"}*Bra<2>{"01"};
std::cout << "CNOT21 -> "<< CNOT21 << std::endl;
std::cout << "(Psi<Dirac::K,2>({"00"}) >> Hadamard >> CNOT21) -> "
<< (Psi<Dirac::K,2>({"00"}) >> Hadamard >> CNOT21) << std::endl;
auto psi = (Psi<Dirac::K,2>({"00"}) >> Hadamard >> CNOT21);
auto bob = ((Ket<1>{"0"}*Bra<1>{"0"} + Ket<1>{"1"}*Bra<1>{"1"}) & gates.I);
auto alice = (gates.I &(Ket<1>{"0"}*Bra<1>{"0"} + Ket<1>{"1"}*Bra<1>{"1"}));
std::cout << "Bob -> " << bob << std::endl;
std::cout << "Alice -> " << alice << std::endl;
std::cout << "Measurements:" << std::endl;
for(unsigned i=0; i<10; ++i)
{
auto psi = (Psi<Dirac::K,2>({"00"}) >> Hadamard >> CNOT21);
std::cout << "psi = " << psi << ", ";
std::cout << "Bob : " << (psi >> M >> bob) << ", ";
std::cout << "Alice : " << (psi >> M >> alice) << "} ";
std::cout << std::endl;
}
std::cout << "(10+20*i)*K{"1010"} -> " << (10+20*i)*K{"1010"}<< std::endl;
std::cout << "(10+20*i)*B{"1010"} -> " << (10+20*i)*B{"1010"}<< std::endl;
std::cout << "(e^(i*pi/4))*B{"1010"}*K{"1010"}*~(e^(i*pi/4)) -> "
<< (e^(i*pi/4))*B{"1010"}*K{"1010"}*~(e^(i*pi/4)) << std::endl;
std::cout << "(K{"1010"}*~(e^(i*pi/4))*((e^(i*pi/4))*B{"1010"})) -> "
<<(K{"1010"}*~(e^(i*pi/4))*((e^(i*pi/4))*B{"1010"})) << std::endl;
std::cout << "(K{"1010"}*~(e^(i*pi/4))*((e^(i*pi/4))*B{"1010"}))*"
"(K{"1010"}*~(e^(i*pi/4)))"
" -> " << (K{"1010"}*~(e^(i*pi/4))*((e^(i*pi/4))*B{"1010"}))*
(K{"1010"}*~(e^(i*pi/4))) << std::endl;
std::cout << "(B{"1010"}*~(e^(i*pi/4)))*(K{"1010"}*~(e^(i*pi/4))*"
"((e^(i*pi/4))*B{"1010"})) -> "
<< (B{"1010"}*~(e^(i*pi/4)))*(K{"1010"}*~(e^(i*pi/4))*
((e^(i*pi/4))*B{"1010"})) << std::endl;
std::cout << "(K{"1010"}*~(e^(i*pi/4)))*(K{"1010"}*~(e^(i*pi/4))) -> "
<< (K{"1010"}*~(e^(i*pi/4)))*(K{"1010"}*~(e^(i*pi/4)))
<< std::endl;
std::cout << "(B{"1010"}*~(e^(i*pi/4)))*(B{"1010"}*~(e^(i*pi/4))) -> "
<< (B{"1010"}*~(e^(i*pi/4)))*(B{"1010"}*~(e^(i*pi/4)))
<< std::endl;
std::cout << "Bra<2>{"10"}*Ket<3>{"100"} -> "
<< Bra<2>{"10"}*Ket<3>{"100"} << std::endl;
std::cout << "Bra<2>{"11"}*Ket<3>{"100"} -> "
<< Bra<2>{"11"}*Ket<3>{"100"} << std::endl;
std::cout << "Bra<5>{"10011"}*Ket<3>{"100"} -> "
<< Bra<5>{"10011"}*Ket<3>{"100"} << std::endl;
std::cout <<
"(Bra<1>{"1"}*Bra<1>{"0"})*(Ket<1>{"1"}*Ket<1>{"0"}*Ket<1>{"0"})"
" -> " << (Bra<1>{"1"}*Bra<1>{"0"})*(Ket<1>{"1"}*Ket<1>{"0"}*Ket<1>{"0"})
<< std::endl;
std::cout << "(Bra<1>{"1"}*Bra<1>{"1"})*(Ket<1>{"1"}*Ket<2>{"00"}) "
"-> "
<< (Bra<1>{"1"}*Bra<1>{"1"})*(Ket<1>{"1"}*Ket<2>{"00"})
<< std::endl;
std::cout <<
"Bra<1>{"1"}*(Ket<3>{"100"}*Bra<5>{"10011"})*"
"(Bra<2>{"10"}*Bra<1>{"0"}) -> "
<< Bra<1>{"1"}*(Ket<3>{"100"}*Bra<5>{"10011"})*(Bra<2>{"10"}*Bra<1>{"0"})
<< std::endl;
std::cout << "Ket<1>{"1"}*(Ket<3>{"100"}*Bra<5>{"10011"})*"
"(Bra<2>{"10"}*Bra<1>{"0"}) -> "
<< Ket<1>{"1"}*(Ket<3>{"100"}*Bra<5>{"10011"})*
(Bra<2>{"10"}*Bra<1>{"0"})
<< std::endl;
std::cout << "std::cos(pi/4)*Ket<1>{"0"} + std::sin(pi/4)*(e^(i*pi/4))*"
"Ket<1>{"1"} ->"
<< std::cos(pi/4)*Ket<1>{"0"} +
std::sin(pi/4)*(e^(i*pi/4))*Ket<1>{"1"}
<< std::endl;
auto elem = 1/std::sqrt(2);
std::cout <<"((elem*Ket<1>{"0"}*Bra<1>{"0"} "
"- elem*Ket<1>{"0"}*Bra<1>{"1"} "
"+ (elem*Ket<1>{"1"}*Bra<1>{"0"} "
"+ elem*Ket<1>{"1"}*Bra<1>{"1"})))"
" -> "
<< ((elem*Ket<1>{"0"}*Bra<1>{"0"} - elem*Ket<1>{"0"}*Bra<1>{"1"}+
(elem*Ket<1>{"1"}*Bra<1>{"0"} + elem*Ket<1>{"1"}*Bra<1>{"1"})))
<< std::endl;
std::cout << "10*i -> " << 10*i << ", i*10 -> " << i*10 << std::endl;
std::cout << "(10*(-i))*(10*i) -> " << (10*(-i))*(10*i) << std::endl;
std::cout << "abs(10*i) -> " << abs(10*i)
<< ", abs(i*10) -> " << abs(i*10)<< std::endl;
std::cout << "10 +100*i -> " << 10 +100*i
<< ", 2*(10 +100*i) -> "<< 2*(10 +100*i)
<< ", (10 +100*i)*3 -> " << (10 +100*i)*3
<< ", 4*C{10,100*i} -> " << 4*C{10,100*i}
<< ", C{10,100*i}*5 -> " << C{10,100*i}*5 << std::endl;
std::cout << "(2+3*i)*C{4,5*i}-> " << (2+3*i)*C{4,5*i} << std::endl;
std::cout << "~(2+3*i)*C{2,3*i} -> " << ~(2+3*i)*C{2,3*i} << std::endl;
std::cout << "abs(~(2+3*i)*C{2,3*i}) -> "
<< abs(~(2+3*i)*C{2,3*i}) << std::endl;
auto x = e^(i*pi/4);
std::cout << "(e^(i*pi/4)).m_real -> " << x.m_real
<< ", abs((e^(i*pi/4)).m_real) -> " << abs(x.m_imag)<<std::endl;
std::cout << "(1000.0*e^(-i*pi/4)) -> " << (1000.0*e^(-i*pi/4))
<< ", 1000*~(e^(i*pi/4)) -> " << 1000*~(e^(i*pi/4))
<< std::endl;
std::cout << "(e^(i*pi/4))*(e^(i*pi/4)) -> " << x*x << std::endl;
std::cout << "~(e^(i*pi/4))*(e^(i*pi/4)) -> "<< ~x*x << std::endl;
return 0;
}

More Related Content

PPT
Python tutorial
PDF
What Have The Properties Ever Done For Us
PDF
[D15] 最強にスケーラブルなカラムナーDBよ、Hadoopとのタッグでビッグデータの地平を目指せ!by Daisuke Hirama
PDF
Parse Everything With Elixir
PPTX
Ruby's Arrays and Hashes with examples
PDF
Functional Gradient Boosting based on Residual Network Perception
PDF
Explain this!
PDF
The Ring programming language version 1.5.3 book - Part 69 of 184
Python tutorial
What Have The Properties Ever Done For Us
[D15] 最強にスケーラブルなカラムナーDBよ、Hadoopとのタッグでビッグデータの地平を目指せ!by Daisuke Hirama
Parse Everything With Elixir
Ruby's Arrays and Hashes with examples
Functional Gradient Boosting based on Residual Network Perception
Explain this!
The Ring programming language version 1.5.3 book - Part 69 of 184

What's hot (15)

PDF
2017 reviews for laowai career center china job scam
PDF
Recentrer l'intelligence artificielle sur les connaissances
PPTX
Ruby Language: Array, Hash and Iterators
PDF
C4 4.5
PDF
The Ring programming language version 1.9 book - Part 69 of 210
DOC
Qhttnew
PDF
Percona Live 4/15/15: Transparent sharding database virtualization engine (DVE)
PDF
Intro to OTP in Elixir
PDF
Oceans 2019 tutorial-geophysical-nav_7-updated
PDF
FINAL Composite
PDF
The ABCs of OTP
PDF
機械学習モデルの判断根拠の説明
PDF
Poodr ch8-composition
PDF
POTENCIAS Y RADICALES
PDF
Lenses and Prisms in Swift - Elviro Rocca - Codemotion Rome 2018
2017 reviews for laowai career center china job scam
Recentrer l'intelligence artificielle sur les connaissances
Ruby Language: Array, Hash and Iterators
C4 4.5
The Ring programming language version 1.9 book - Part 69 of 210
Qhttnew
Percona Live 4/15/15: Transparent sharding database virtualization engine (DVE)
Intro to OTP in Elixir
Oceans 2019 tutorial-geophysical-nav_7-updated
FINAL Composite
The ABCs of OTP
機械学習モデルの判断根拠の説明
Poodr ch8-composition
POTENCIAS Y RADICALES
Lenses and Prisms in Swift - Elviro Rocca - Codemotion Rome 2018
Ad

Viewers also liked (20)

PDF
Simple shared mutex UML
PDF
Brochure Sistema de Información para administración de establecimientos comer...
PPTX
NoSQL - Hands on
PDF
Interview uml design
PDF
Multithreaded sockets c++11
PDF
Recursion to iteration automation.
PDF
Design pattern to avoid downcasting
PDF
IBM Kinexa Prove It! C programming test results.
PDF
Full_resume_Dr_Russell_John_Childs
PDF
Shared_memory_hash_table
PPTX
3Com 7030-10136
PPTX
What have you learned from your audience feedback?
PDF
Content Strategy Report: LPCS
PPTX
雷諾數測試與計算
PDF
Cuidados de enfermería ante el accidente ofídico
PPTX
プロジェクト
PDF
Políticos [Maçonaria]
PPTX
Perfect places
PDF
Рекламный буклет налоговой системы "Свободная экономика"
Simple shared mutex UML
Brochure Sistema de Información para administración de establecimientos comer...
NoSQL - Hands on
Interview uml design
Multithreaded sockets c++11
Recursion to iteration automation.
Design pattern to avoid downcasting
IBM Kinexa Prove It! C programming test results.
Full_resume_Dr_Russell_John_Childs
Shared_memory_hash_table
3Com 7030-10136
What have you learned from your audience feedback?
Content Strategy Report: LPCS
雷諾數測試與計算
Cuidados de enfermería ante el accidente ofídico
プロジェクト
Políticos [Maçonaria]
Perfect places
Рекламный буклет налоговой системы "Свободная экономика"
Ad

Similar to Dirac demo (quantum mechanics with C++). Please note: There is a problem with SlideShare updating documents, so there may be divergence between the code and the copied & pasted output. (20)

PDF
Prelude to halide_public
DOCX
Tugas praktikukm pemrograman c++
KEY
Haskellで学ぶ関数型言語
PDF
PDF
Dipôles linéaires, régime transitoire
PDF
第6回 関数とフロー制御
PDF
C Code and the Art of Obfuscation
PDF
DOCX
C programs
PDF
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
PDF
Declare Your Language: Transformation by Strategic Term Rewriting
PDF
PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~
DOCX
C programs
PDF
Modern C++ Explained: Move Semantics (Feb 2018)
DOCX
cosc 281 hw3
PDF
MongoDB for Analytics
PDF
Compilation of COSMO for GPU using LLVM
PDF
User Defined Aggregation in Apache Spark: A Love Story
PDF
User Defined Aggregation in Apache Spark: A Love Story
PDF
Hitchhiker's Guide to Functional Programming
Prelude to halide_public
Tugas praktikukm pemrograman c++
Haskellで学ぶ関数型言語
Dipôles linéaires, régime transitoire
第6回 関数とフロー制御
C Code and the Art of Obfuscation
C programs
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
Declare Your Language: Transformation by Strategic Term Rewriting
PostgreSQL10の新機能 ~ロジカルレプリケーションを中心に~
C programs
Modern C++ Explained: Move Semantics (Feb 2018)
cosc 281 hw3
MongoDB for Analytics
Compilation of COSMO for GPU using LLVM
User Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love Story
Hitchhiker's Guide to Functional Programming

More from Russell Childs (20)

PDF
spinor_quantum_simulator_user_guide_.pdf
PDF
String searching o_n
PDF
String searching o_n
PDF
String searching o_n
PDF
String searching
PDF
Feature extraction using adiabatic theorem
PDF
Feature extraction using adiabatic theorem
PDF
Wavelets_and_multiresolution_in_two_pages
PDF
Relativity 2
PDF
Full resume dr_russell_john_childs_2016
PDF
Interview C++11 code
PDF
Dynamic programming burglar_problem
PDF
K d tree_cpp
PDF
Algorithms devised for a google interview
PDF
IBM Kinexa Prove It! C++ programming test results.
PDF
2 mathematical challenge_analysis_design_and_results
PDF
1 mathematical challenge_problem
PDF
3 mathematical challenge_code
PDF
Cpp11 multithreading and_simd_linux_code
PDF
Cpp11 sample linux
spinor_quantum_simulator_user_guide_.pdf
String searching o_n
String searching o_n
String searching o_n
String searching
Feature extraction using adiabatic theorem
Feature extraction using adiabatic theorem
Wavelets_and_multiresolution_in_two_pages
Relativity 2
Full resume dr_russell_john_childs_2016
Interview C++11 code
Dynamic programming burglar_problem
K d tree_cpp
Algorithms devised for a google interview
IBM Kinexa Prove It! C++ programming test results.
2 mathematical challenge_analysis_design_and_results
1 mathematical challenge_problem
3 mathematical challenge_code
Cpp11 multithreading and_simd_linux_code
Cpp11 sample linux

Recently uploaded (20)

PPTX
BIOMOLECULES PPT........................
PPTX
famous lake in india and its disturibution and importance
PPTX
Pharmacology of Autonomic nervous system
PDF
Sciences of Europe No 170 (2025)
PPT
POSITIONING IN OPERATION THEATRE ROOM.ppt
PDF
Unveiling a 36 billion solar mass black hole at the centre of the Cosmic Hors...
PDF
CHAPTER 3 Cell Structures and Their Functions Lecture Outline.pdf
PDF
lecture 2026 of Sjogren's syndrome l .pdf
PPTX
2. Earth - The Living Planet earth and life
PPTX
Application of enzymes in medicine (2).pptx
PPTX
Protein & Amino Acid Structures Levels of protein structure (primary, seconda...
PPTX
C1 cut-Methane and it's Derivatives.pptx
PPTX
ognitive-behavioral therapy, mindfulness-based approaches, coping skills trai...
PPTX
neck nodes and dissection types and lymph nodes levels
PPTX
Vitamins & Minerals: Complete Guide to Functions, Food Sources, Deficiency Si...
PPTX
Introduction to Fisheries Biotechnology_Lesson 1.pptx
PDF
ELS_Q1_Module-11_Formation-of-Rock-Layers_v2.pdf
PDF
Biophysics 2.pdffffffffffffffffffffffffff
PPTX
cpcsea ppt.pptxssssssssssssssjjdjdndndddd
PPTX
2. Earth - The Living Planet Module 2ELS
BIOMOLECULES PPT........................
famous lake in india and its disturibution and importance
Pharmacology of Autonomic nervous system
Sciences of Europe No 170 (2025)
POSITIONING IN OPERATION THEATRE ROOM.ppt
Unveiling a 36 billion solar mass black hole at the centre of the Cosmic Hors...
CHAPTER 3 Cell Structures and Their Functions Lecture Outline.pdf
lecture 2026 of Sjogren's syndrome l .pdf
2. Earth - The Living Planet earth and life
Application of enzymes in medicine (2).pptx
Protein & Amino Acid Structures Levels of protein structure (primary, seconda...
C1 cut-Methane and it's Derivatives.pptx
ognitive-behavioral therapy, mindfulness-based approaches, coping skills trai...
neck nodes and dissection types and lymph nodes levels
Vitamins & Minerals: Complete Guide to Functions, Food Sources, Deficiency Si...
Introduction to Fisheries Biotechnology_Lesson 1.pptx
ELS_Q1_Module-11_Formation-of-Rock-Layers_v2.pdf
Biophysics 2.pdffffffffffffffffffffffffff
cpcsea ppt.pptxssssssssssssssjjdjdndndddd
2. Earth - The Living Planet Module 2ELS

Dirac demo (quantum mechanics with C++). Please note: There is a problem with SlideShare updating documents, so there may be divergence between the code and the copied & pasted output.

  • 1. @copyright Russell John Childs, PhD, 11th March 2017 ======================================================================================== Simple demo of C++ framework allowing quantum mechanics to be done with Matrix Mechanics using Dirac Bras, Kets, inner, outer products, operators. ======================================================================================== Output of code (see later): =========================================== Usage model: =========================================== e^(i*theta): Polar notation cos theta + i sin theta a + i*b: Cartesian notation a + i b (e^(i*p/4))*Bra<3>{"010"}: Creates 3-qubit bra e^(i pi/4) <010| Ket<3>{"010"}: Creates 3-qubit ket |010> Bra<3>{"010"}*Ket<3>{"010"}: Inner product <010|010> = 1 Bra<3>{"010"}*Ket<3>{"110"}: Inner product <010|110> = 0 Bra<2>{"01"}*Ket<3>{"011"}: Inner product <01|011> = |1> Bra<2>{"01"}*Bra<3>{"011"}: tensor prod <01|<011| = <01011| Ket<2>{"01"}*Ket<3>{"011"}: tensor prod |01>|011> = |01011> cos(theta)*Ket<1>{"0"}*Bra<1>{"0"} - sin(theta)*Ket<1>{"0"}*Bra<1>{"1"}+ sin(theta)*Ket<1>{"1"}*Bra<1>{"0"}+ cos(theta)*Ket<1>{"1"}*Bra<1>{"1"}: Ry(2*theta) = -- -- | cos theta |0><0| -sin theta |0><1| | | sin theta |1><0| cos theta |1><1| | -- -- Passive rotation operator. Applied to alpha*Ket<1>{"0"} + beta*Ket<1>{"1"} = alpha |0> + beta |1> = -- -- | alpha | | beta | -- -- Ket<1>{"0"}*Bra<1>{"0"} & Ket<1>{"1"}*Bra<1>{"1"} - operator tensor product |0><0| & |1><1| = |01><01| (Ket<2>{"00"} >> Hadamard >> CNOT21) - the quantum circuit: |00> -- H -- CNOT21 = 1/sqrt_2(|00> + |11>), i.e. entangled (psi >> M >> bob) - performs a measurement on psi using the operator 'bob' =========================================== End of Usage model: =========================================== gates.X -> (1+i*0)|0><1| + (1+i*0)|1><0| gates.Y -> (0-i*1)|0><1| + (0+i*1)|1><0| gates.Z -> (1+i*0)|0><0| + (-1+i*0)|1><1| gates.H -> (4.32978e-17+i*0.707107)|0><0| + (4.32978e-17+i*0.707107)|0><1| + (-4.32978e-17+i*0.707107)|1><0| + (4.32978e- 17-i*0.707107)|1><1| gates.S -> (1+i*0)|0><0| + (0+i*1)|1><1| gates.T -> (1+i*0)|0><0| + (0.707107+i*0.707107)|1><1| CNOT = ((Ket<1>{"0"}*Bra<1>{"0"}&gates.I) + (Ket<1>{"1"}*Bra<1>{"1"}&gates.X)) -> (1+i*0)|00><00| + (1+i*0)|01><01| + (1+i*0)|10><11| + (1+i*0)|11><10| gates.controlled(gates.X) -> (1+i*0)|00><00| + (1+i*0)|01><01| + (1+i*0)|10><11| + (1+i*0)|11><10| ~((e^(i*pi/4))*Ket<1>{"0"}*Bra<1>{"1"}) = ~(e^ip/4 |0><1|) -> (0.707107-i*0.707107)|1><0| ~gates.S = ~((1+i*0)|0><0| + (0+i*1)|1><1|) -> (1+i*0)|0><0| + (0-i*1)|1><1| Psi<Dirac::K,1>({"0"}) = |0> -> (1+i*0)*|0> (Psi<Dirac::K,1>({"0"})>>gates.H) - single qubit quantum circuit |0> -- H -> (-4.32978e-17+i*0.707107)*|1> + (4.32978e- 17+i*0.707107)*|0> (Psi<Dirac::K,2>({"00"}) >> Hadamard) -> (4.32978e-17+i*0.707107)*|00> + (0+i*0)*|10> + (0+i*0)*|11> + (-4.32978e- 17+i*0.707107)*|01> CNOT21 -> (1+i*0)|00><00| + (1+i*0)|01><11| + (1+i*0)|10><10| + (1+i*0)|11><01| (Psi<Dirac::K,2>({"00"}) >> Hadamard >> CNOT21) -> (4.32978e-17+i*0.707107)*|00> + (0+i*0)*|10> + (0+i*0)*|01> + (-4.32978e- 17+i*0.707107)*|11> Bob -> (1+i*0)|00><00| + (1+i*0)|01><01| + (1+i*0)|10><10| + (1+i*0)|11><11| Alice -> (1+i*0)|00><00| + (1+i*0)|01><01| + (1+i*0)|10><10| + (1+i*0)|11><11| Measurements: psi = (4.32978e-17+i*0.707107)*|00> + (0+i*0)*|10> + (0+i*0)*|01> + (-4.32978e-17+i*0.707107)*|11>, Bob : (6.12323e- 17+i*1)*|00>, Alice : (6.12323e-17+i*1)*|00>} psi = (4.32978e-17+i*0.707107)*|00> + (0+i*0)*|10> + (0+i*0)*|01> + (-4.32978e-17+i*0.707107)*|11>, Bob : (-6.12323e- 17+i*1)*|11>, Alice : (-6.12323e-17+i*1)*|11>} psi = (4.32978e-17+i*0.707107)*|00> + (0+i*0)*|10> + (0+i*0)*|01> + (-4.32978e-17+i*0.707107)*|11>, Bob : (6.12323e- 17+i*1)*|00>, Alice : (6.12323e-17+i*1)*|00>} psi = (4.32978e-17+i*0.707107)*|00> + (0+i*0)*|10> + (0+i*0)*|01> + (-4.32978e-17+i*0.707107)*|11>, Bob : (-6.12323e- 17+i*1)*|11>, Alice : (-6.12323e-17+i*1)*|11>} psi = (4.32978e-17+i*0.707107)*|00> + (0+i*0)*|10> + (0+i*0)*|01> + (-4.32978e-17+i*0.707107)*|11>, Bob : (-6.12323e- 17+i*1)*|11>, Alice : (-6.12323e-17+i*1)*|11>} psi = (4.32978e-17+i*0.707107)*|00> + (0+i*0)*|10> + (0+i*0)*|01> + (-4.32978e-17+i*0.707107)*|11>, Bob : (6.12323e- 17+i*1)*|00>, Alice : (6.12323e-17+i*1)*|00>}
  • 2. psi = (4.32978e-17+i*0.707107)*|00> + (0+i*0)*|10> + (0+i*0)*|01> + (-4.32978e-17+i*0.707107)*|11>, Bob : (-6.12323e- 17+i*1)*|11>, Alice : (-6.12323e-17+i*1)*|11>} psi = (4.32978e-17+i*0.707107)*|00> + (0+i*0)*|10> + (0+i*0)*|01> + (-4.32978e-17+i*0.707107)*|11>, Bob : (6.12323e- 17+i*1)*|00>, Alice : (6.12323e-17+i*1)*|00>} psi = (4.32978e-17+i*0.707107)*|00> + (0+i*0)*|10> + (0+i*0)*|01> + (-4.32978e-17+i*0.707107)*|11>, Bob : (6.12323e- 17+i*1)*|00>, Alice : (6.12323e-17+i*1)*|00>} psi = (4.32978e-17+i*0.707107)*|00> + (0+i*0)*|10> + (0+i*0)*|01> + (-4.32978e-17+i*0.707107)*|11>, Bob : (6.12323e- 17+i*1)*|00>, Alice : (6.12323e-17+i*1)*|00>} (10+20*i)*K{"1010"} -> (10+i*20)*|1010> (10+20*i)*B{"1010"} -> <1010|*(10+i*20) (e^(i*pi/4))*B{"1010"}*K{"1010"}*~(e^(i*pi/4)) -> 1+i*0 (K{"1010"}*~(e^(i*pi/4))*((e^(i*pi/4))*B{"1010"})) -> (1+i*0)|1010><1010| (K{"1010"}*~(e^(i*pi/4))*((e^(i*pi/4))*B{"1010"}))*(K{"1010"}*~(e^(i*pi/4))) -> (0.707107-i*0.707107)*|1010> (B{"1010"}*~(e^(i*pi/4)))*(K{"1010"}*~(e^(i*pi/4))*((e^(i*pi/4))*B{"1010"})) -> <1010|*(0.707107-i*0.707107) (K{"1010"}*~(e^(i*pi/4)))*(K{"1010"}*~(e^(i*pi/4))) -> (2.22045e-16-i*1)*|10101010> (B{"1010"}*~(e^(i*pi/4)))*(B{"1010"}*~(e^(i*pi/4))) -> <10101010|*(2.22045e-16-i*1) Bra<2>{"10"}*Ket<3>{"100"} -> (1+i*0)*|0> Bra<2>{"11"}*Ket<3>{"100"} -> (0+i*0)*|0> Bra<5>{"10011"}*Ket<3>{"100"} -> <11|*(1+i*0) (Bra<1>{"1"}*Bra<1>{"0"})*(Ket<1>{"1"}*Ket<1>{"0"}*Ket<1>{"0"}) -> (1+i*0)*|0> (Bra<1>{"1"}*Bra<1>{"1"})*(Ket<1>{"1"}*Ket<2>{"00"}) -> (0+i*0)*|0> Bra<1>{"1"}*(Ket<3>{"100"}*Bra<5>{"10011"})*(Bra<2>{"10"}*Bra<1>{"0"}) -> (1+i*0)|00><10011100| Ket<1>{"1"}*(Ket<3>{"100"}*Bra<5>{"10011"})*(Bra<2>{"10"}*Bra<1>{"0"}) -> (1+i*0)|1100><10011100| std::cos(pi/4)*Ket<1>{"0"} + std::sin(pi/4)*(e^(i*pi/4))*Ket<1>{"1"} ->(0.5+i*0.5)*|1> + (0.707107+i*0)*|0> ((elem*Ket<1>{"0"}*Bra<1>{"0"} - elem*Ket<1>{"0"}*Bra<1>{"1"} + (elem*Ket<1>{"1"}*Bra<1>{"0"} + elem*Ket<1>{"1"}*Bra<1>{"1"}))) -> (0.707107+i*0)|0><0| + (-0.707107+i*0)|0><1| + (0.707107+i*0)|1><0| + (0.707107+i*0)|1><1| 10*i -> +i*10, i*10 -> +i*10 (10*(-i))*(10*i) -> 100 abs(10*i) -> 10, abs(i*10) -> 10 10 +100*i -> 10+i*100, 2*(10 +100*i) -> 20+i*200, (10 +100*i)*3 -> 30+i*300, 4*C{10,100*i} -> 40+i*400, C{10,100*i}*5 -> 50+i*500 (2+3*i)*C{4,5*i}-> -7+i*22 ~(2+3*i)*C{2,3*i} -> 13+i*0 abs(~(2+3*i)*C{2,3*i}) -> 13 (e^(i*pi/4)).m_real -> 0.707107, abs((e^(i*pi/4)).m_real) -> 0.707107 (1000.0*e^(-i*pi/4)) -> 707.107-i*707.107, 1000*~(e^(i*pi/4)) -> 707.107-i*707.107 (e^(i*pi/4))*(e^(i*pi/4)) -> 2.22045e-16+i*1 ~(e^(i*pi/4))*(e^(i*pi/4)) -> 1+i*0 Code: int main(void) { using namespace QuantumGates; typedef QuantumGates::Ket<4> K; typedef QuantumGates::Bra<4> B; std::cout << "===========================================" << std::endl; std::cout << "Usage model:" << std::endl; std::cout << "===========================================" << std::endl; std::cout << "e^(i*theta): Polar notation cos theta + i sin theta" << std::endl; std::cout << "a + i*b: Cartesian notation a + i b" << std::endl; std::cout << "(e^(i*p/4))*Bra<3>{"010"}: Creates 3-qubit bra e^(i pi/4) " "<010|" << std::endl; std::cout << "Ket<3>{"010"}: Creates 3-qubit ket |010>" << std::endl; std::cout << "Bra<3>{"010"}*Ket<3>{"010"}: Inner product <010|010> = 1" << std::endl; std::cout << "Bra<3>{"010"}*Ket<3>{"110"}: Inner product <010|110> = 0" << std::endl; std::cout << "Bra<2>{"01"}*Ket<3>{"011"}: Inner product <01|011> = " "|1>" << std::endl; std::cout << "Bra<2>{"01"}*Bra<3>{"011"}: tensor prod <01|<011| " "= <01011|" << std::endl; std::cout << "Ket<2>{"01"}*Ket<3>{"011"}: tensor prod |01>|011> = " "|01011>" << std::endl; std::cout << "cos(theta)*Ket<1>{"0"}*Bra<1>{"0"} " "- sin(theta)*Ket<1>{"0"}*Bra<1>{"1"}" "+ sin(theta)*Ket<1>{"1"}*Bra<1>{"0"}" "+ cos(theta)*Ket<1>{"1"}*Bra<1>{"1"}: " << std::endl << " Ry(2*theta) = " << std::endl << " -- --" << std::endl<< " | cos theta |0><0| -sin theta |0><1| |"<< std::endl<< " | sin theta |1><0| cos theta |1><1| |"<< std::endl<< " -- --" << std::endl<<
  • 3. " Passive rotation operator. Applied to" << std::endl << " alpha*Ket<1>{"0"} + beta*Ket<1>{"1"} " " = alpha |0> + beta |1> =" << std::endl<< " -- --" << std::endl<< " | alpha |" << std::endl<< " | beta |" << std::endl<< " -- --" << std::endl; std::cout << "Ket<1>{"0"}*Bra<1>{"0"} & Ket<1>{"1"}*Bra<1>{"1"} -" " operator tensor product |0><0| & |1><1| = |01><01|" << std::endl; std::cout << "(Ket<2>{"00"} >> Hadamard >> CNOT21) - the quantum circuit:" " |00> -- H -- CNOT21 = 1/sqrt_2(|00> + |11>), i.e. entangled" << std::endl; std::cout << "(psi >> M >> bob) - performs a measurement on psi " "using the operator 'bob' " << std::endl; std::cout << "===========================================" << std::endl; std::cout << "End of Usage model:" << std::endl; std::cout << "===========================================" << std::endl; auto gates = Gate::instance(); std::cout << "gates.X -> " << gates.X << std::endl; std::cout << "gates.Y -> " << gates.Y << std::endl; std::cout << "gates.Z -> " << gates.Z << std::endl; std::cout << "gates.H -> " << gates.H << std::endl; std::cout << "gates.S -> " << gates.S << std::endl; std::cout << "gates.T -> " << gates.T << std::endl; auto CNOT = ((Ket<1>{"0"}*Bra<1>{"0"}&gates.I) + (Ket<1>{"1"}*Bra<1>{"1"}&gates.X)); std::cout << "CNOT = ((Ket<1>{"0"}*Bra<1>{"0"}&gates.I) + " "(Ket<1>{"1"}*Bra<1>{"1"}&gates.X)) -> " << CNOT << std::endl; std::cout << "gates.controlled(gates.X) -> " << gates.controlled(gates.X) << std::endl; std::cout << "~((e^(i*pi/4))*Ket<1>{"0"}*Bra<1>{"1"}) " "= ~(e^ip/4 |0><1|) -> " << ~((e^(i*pi/4))*Ket<1>{"0"}*Bra<1>{1}) << std::endl; std::cout << "~gates.S = ~(" << gates.S << ") -> " << ~gates.S << std::endl; std::cout << "Psi<Dirac::K,1>({"0"}) = |0> -> " << Psi<Dirac::K,1>({"0"}) << std::endl; std::cout << "(Psi<Dirac::K,1>({"0"})>>gates.H) - single qubit quantum circuit" " |0> -- H -> " << (Psi<Dirac::K,1>({"0"})>>gates.H) << std::endl; auto Hadamard = ((Ket<1>{"0"}*Bra<1>{"0"}&gates.H) + (Ket<1>{"1"}*Bra<1>{"1"}&gates.I)); std::cout << "(Psi<Dirac::K,2>({"00"}) >> Hadamard) -> " << (Psi<Dirac::K,2>({"00"}) >> Hadamard) << std::endl; auto CNOT21 = Ket<2>{"00"}*Bra<2>{"00"} + Ket<2>{"01"}*Bra<2>{"11"} + Ket<2>{"10"}*Bra<2>{"10"} + Ket<2>{"11"}*Bra<2>{"01"}; std::cout << "CNOT21 -> "<< CNOT21 << std::endl; std::cout << "(Psi<Dirac::K,2>({"00"}) >> Hadamard >> CNOT21) -> " << (Psi<Dirac::K,2>({"00"}) >> Hadamard >> CNOT21) << std::endl; auto psi = (Psi<Dirac::K,2>({"00"}) >> Hadamard >> CNOT21); auto bob = ((Ket<1>{"0"}*Bra<1>{"0"} + Ket<1>{"1"}*Bra<1>{"1"}) & gates.I); auto alice = (gates.I &(Ket<1>{"0"}*Bra<1>{"0"} + Ket<1>{"1"}*Bra<1>{"1"})); std::cout << "Bob -> " << bob << std::endl; std::cout << "Alice -> " << alice << std::endl; std::cout << "Measurements:" << std::endl; for(unsigned i=0; i<10; ++i) { auto psi = (Psi<Dirac::K,2>({"00"}) >> Hadamard >> CNOT21); std::cout << "psi = " << psi << ", "; std::cout << "Bob : " << (psi >> M >> bob) << ", "; std::cout << "Alice : " << (psi >> M >> alice) << "} "; std::cout << std::endl; } std::cout << "(10+20*i)*K{"1010"} -> " << (10+20*i)*K{"1010"}<< std::endl; std::cout << "(10+20*i)*B{"1010"} -> " << (10+20*i)*B{"1010"}<< std::endl; std::cout << "(e^(i*pi/4))*B{"1010"}*K{"1010"}*~(e^(i*pi/4)) -> " << (e^(i*pi/4))*B{"1010"}*K{"1010"}*~(e^(i*pi/4)) << std::endl; std::cout << "(K{"1010"}*~(e^(i*pi/4))*((e^(i*pi/4))*B{"1010"})) -> " <<(K{"1010"}*~(e^(i*pi/4))*((e^(i*pi/4))*B{"1010"})) << std::endl; std::cout << "(K{"1010"}*~(e^(i*pi/4))*((e^(i*pi/4))*B{"1010"}))*"
  • 4. "(K{"1010"}*~(e^(i*pi/4)))" " -> " << (K{"1010"}*~(e^(i*pi/4))*((e^(i*pi/4))*B{"1010"}))* (K{"1010"}*~(e^(i*pi/4))) << std::endl; std::cout << "(B{"1010"}*~(e^(i*pi/4)))*(K{"1010"}*~(e^(i*pi/4))*" "((e^(i*pi/4))*B{"1010"})) -> " << (B{"1010"}*~(e^(i*pi/4)))*(K{"1010"}*~(e^(i*pi/4))* ((e^(i*pi/4))*B{"1010"})) << std::endl; std::cout << "(K{"1010"}*~(e^(i*pi/4)))*(K{"1010"}*~(e^(i*pi/4))) -> " << (K{"1010"}*~(e^(i*pi/4)))*(K{"1010"}*~(e^(i*pi/4))) << std::endl; std::cout << "(B{"1010"}*~(e^(i*pi/4)))*(B{"1010"}*~(e^(i*pi/4))) -> " << (B{"1010"}*~(e^(i*pi/4)))*(B{"1010"}*~(e^(i*pi/4))) << std::endl; std::cout << "Bra<2>{"10"}*Ket<3>{"100"} -> " << Bra<2>{"10"}*Ket<3>{"100"} << std::endl; std::cout << "Bra<2>{"11"}*Ket<3>{"100"} -> " << Bra<2>{"11"}*Ket<3>{"100"} << std::endl; std::cout << "Bra<5>{"10011"}*Ket<3>{"100"} -> " << Bra<5>{"10011"}*Ket<3>{"100"} << std::endl; std::cout << "(Bra<1>{"1"}*Bra<1>{"0"})*(Ket<1>{"1"}*Ket<1>{"0"}*Ket<1>{"0"})" " -> " << (Bra<1>{"1"}*Bra<1>{"0"})*(Ket<1>{"1"}*Ket<1>{"0"}*Ket<1>{"0"}) << std::endl; std::cout << "(Bra<1>{"1"}*Bra<1>{"1"})*(Ket<1>{"1"}*Ket<2>{"00"}) " "-> " << (Bra<1>{"1"}*Bra<1>{"1"})*(Ket<1>{"1"}*Ket<2>{"00"}) << std::endl; std::cout << "Bra<1>{"1"}*(Ket<3>{"100"}*Bra<5>{"10011"})*" "(Bra<2>{"10"}*Bra<1>{"0"}) -> " << Bra<1>{"1"}*(Ket<3>{"100"}*Bra<5>{"10011"})*(Bra<2>{"10"}*Bra<1>{"0"}) << std::endl; std::cout << "Ket<1>{"1"}*(Ket<3>{"100"}*Bra<5>{"10011"})*" "(Bra<2>{"10"}*Bra<1>{"0"}) -> " << Ket<1>{"1"}*(Ket<3>{"100"}*Bra<5>{"10011"})* (Bra<2>{"10"}*Bra<1>{"0"}) << std::endl; std::cout << "std::cos(pi/4)*Ket<1>{"0"} + std::sin(pi/4)*(e^(i*pi/4))*" "Ket<1>{"1"} ->" << std::cos(pi/4)*Ket<1>{"0"} + std::sin(pi/4)*(e^(i*pi/4))*Ket<1>{"1"} << std::endl; auto elem = 1/std::sqrt(2); std::cout <<"((elem*Ket<1>{"0"}*Bra<1>{"0"} " "- elem*Ket<1>{"0"}*Bra<1>{"1"} " "+ (elem*Ket<1>{"1"}*Bra<1>{"0"} " "+ elem*Ket<1>{"1"}*Bra<1>{"1"})))" " -> " << ((elem*Ket<1>{"0"}*Bra<1>{"0"} - elem*Ket<1>{"0"}*Bra<1>{"1"}+ (elem*Ket<1>{"1"}*Bra<1>{"0"} + elem*Ket<1>{"1"}*Bra<1>{"1"}))) << std::endl; std::cout << "10*i -> " << 10*i << ", i*10 -> " << i*10 << std::endl; std::cout << "(10*(-i))*(10*i) -> " << (10*(-i))*(10*i) << std::endl; std::cout << "abs(10*i) -> " << abs(10*i) << ", abs(i*10) -> " << abs(i*10)<< std::endl; std::cout << "10 +100*i -> " << 10 +100*i << ", 2*(10 +100*i) -> "<< 2*(10 +100*i) << ", (10 +100*i)*3 -> " << (10 +100*i)*3 << ", 4*C{10,100*i} -> " << 4*C{10,100*i} << ", C{10,100*i}*5 -> " << C{10,100*i}*5 << std::endl; std::cout << "(2+3*i)*C{4,5*i}-> " << (2+3*i)*C{4,5*i} << std::endl; std::cout << "~(2+3*i)*C{2,3*i} -> " << ~(2+3*i)*C{2,3*i} << std::endl; std::cout << "abs(~(2+3*i)*C{2,3*i}) -> " << abs(~(2+3*i)*C{2,3*i}) << std::endl; auto x = e^(i*pi/4); std::cout << "(e^(i*pi/4)).m_real -> " << x.m_real << ", abs((e^(i*pi/4)).m_real) -> " << abs(x.m_imag)<<std::endl; std::cout << "(1000.0*e^(-i*pi/4)) -> " << (1000.0*e^(-i*pi/4)) << ", 1000*~(e^(i*pi/4)) -> " << 1000*~(e^(i*pi/4)) << std::endl; std::cout << "(e^(i*pi/4))*(e^(i*pi/4)) -> " << x*x << std::endl; std::cout << "~(e^(i*pi/4))*(e^(i*pi/4)) -> "<< ~x*x << std::endl;