00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _QGTYPES_H_
00026 #define _QGTYPES_H_
00027
00028 #include <iostream>
00029 #include <vector>
00030 #include <string>
00031
00032 #include "qgerror.h"
00033
00034
00035
00036
00037
00038 namespace qgame {
00039
00048 class Complex {
00049 double re,im;
00050 friend double sqabs(const Complex&);
00051 friend std::ostream& operator<<(std::ostream &, const Complex &);
00052
00053 public:
00054 Complex(double re = 0, double im = 0);
00056 double Re();
00057 double Im();
00058 double sqabs();
00060 Complex operator+(const Complex&);
00061 Complex operator-(const Complex&);
00062 Complex operator*(const Complex&);
00063 Complex operator+=(const Complex&);
00064 Complex operator*=(const Complex&);
00065 };
00066 std::ostream& operator<<(std::ostream &, const Complex &);
00067 double sqabs(const Complex&);
00075 class QubitList {
00076 std::vector<int> qbl;
00077 friend std::ostream & operator<<(std::ostream &, const QubitList &);
00078
00079 public:
00080 unsigned int size() const;
00081 void append(int qbnum);
00082 int operator[](const unsigned int) const throw(Error);
00084 };
00085 std::ostream & operator<<(std::ostream &, const QubitList &);
00086
00096 class QuSubReg {
00097 int num;
00098 std::vector<Complex*> sub;
00099 friend class Qureg;
00100
00101 public:
00102 QuSubReg(int numQb);
00103 ~QuSubReg();
00104
00105 unsigned int numQb() const;
00106 unsigned int numAmps() const;
00107 Complex& operator[](const unsigned int) throw(Error);
00108 };
00109
00115 class Qureg {
00116 int num;
00117 std::vector<Complex> amp;
00118
00119 friend class QuSubReg;
00120 friend std::ostream& operator<<(std::ostream &, Qureg);
00121 public:
00122 Qureg(int size = 0);
00124 unsigned int size() const;
00125 std::vector<QuSubReg> getSubRegs(const QubitList &qubits);
00138 std::vector<double> getProbabilities(const QubitList &qubits);
00141 void collapse(const QubitList &qubits, int value);
00147 void normalize();
00148 Complex & operator[](const unsigned int) throw(Error);
00149 };
00150 std::ostream& operator<<(std::ostream &, Qureg);
00151
00162 struct TestCase {
00163 std::string oracleTT;
00164 int desiredRes;
00165 TestCase(const std::string &tt, int res) { oracleTT = tt; desiredRes = res; }
00167 TestCase(const std::string &casestr);
00171 };
00172 };
00173
00174 #endif