00001 /*************************************************************************** 00002 * QGame++ * 00003 * ======= * 00004 * A Quantum Gate And Measurement Emulator. * 00005 * * 00006 * Copyright (C) 2003/04 by Manuel Nickschas * 00007 * <qgame-devel@nickschas.de> * 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; either version 2 of the License, or * 00012 * (at your option) any later version. * 00013 * * 00014 * This program is distributed in the hope that it will be useful, * 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00017 * GNU General Public License for more details. * 00018 * * 00019 * You should have received a copy of the GNU General Public License * 00020 * along with this program; if not, write to the * 00021 * Free Software Foundation, Inc., * 00022 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00023 ***************************************************************************/ 00024 00025 #ifndef _QGGATES_H_ 00026 #define _QGGATES_H_ 00027 00028 #include "qgtypes.h" 00029 #include "qgerror.h" 00030 00031 #include <vector> 00032 #include <string> 00033 #include <iostream> 00034 #include <cmath> 00035 00036 namespace qgame { 00037 00042 class QGate { 00043 00044 public: 00045 virtual std::string dump() const; 00046 virtual unsigned int numQb() = 0; 00047 virtual void apply(QuSubReg &) = 0; 00048 }; 00049 00055 class QMatrixGate : public QGate { 00056 protected: 00057 int numQubits; 00058 int numAmps; 00059 std::vector<std::vector<Complex> > matrix; 00060 QMatrixGate() {} ; 00061 public: 00062 virtual unsigned int numQb(); 00063 virtual void apply(QuSubReg &) throw(Error); 00064 00065 std::string dump() const; 00066 QMatrixGate(std::vector<std::vector<Complex> >); 00067 }; 00068 00069 std::ostream & operator<<(std::ostream &o, const QGate &); 00070 00071 /**************************************************************************** 00072 * Standard quantum gates 00073 ****************************************************************************/ 00074 00079 class QGateQNOT : public QMatrixGate { 00080 public: 00081 QGateQNOT(); 00082 std::string dump() const; 00083 }; 00084 00086 class QGateCNOT : public QMatrixGate { 00087 public: 00088 QGateCNOT(); 00089 std::string dump() const; 00090 }; 00091 00093 class QGateNAND : public QMatrixGate { 00094 public: 00095 QGateNAND(); 00096 std::string dump() const; 00097 }; 00098 00100 class QGateSRN : public QMatrixGate { 00101 public: 00102 QGateSRN(); 00103 std::string dump() const; 00104 }; 00105 00107 class QGateH2 : public QMatrixGate { 00108 public: 00109 QGateH2(); 00110 std::string dump() const; 00111 }; 00112 00114 class QGateUTHETA : public QMatrixGate { 00115 double theta; 00116 public: 00117 QGateUTHETA(double theta); 00118 std::string dump() const; 00119 }; 00120 00122 class QGateCPHASEOLD : public QMatrixGate { 00123 double alpha; 00124 public: 00125 QGateCPHASEOLD(double alpha); 00126 std::string dump() const; 00127 }; 00128 00131 class QGateCPHASE : public QMatrixGate { 00132 double alpha; 00133 public: 00134 QGateCPHASE(double alpha); 00135 std::string dump() const; 00136 }; 00137 00141 class QGateU2 : public QMatrixGate { 00142 double phi,theta,psi,alpha; 00143 public: 00144 QGateU2(double phi, double theta, double psi, double alpha); 00145 std::string dump() const; 00146 }; 00147 00149 class QGateSWAP : public QMatrixGate { 00150 public: 00151 QGateSWAP(); 00152 std::string dump() const; 00153 }; 00154 00156 class QOracle : public QMatrixGate { 00157 std::string truthtable; 00158 public: 00159 QOracle(const std::string &truthtable); 00161 std::string dump() const; 00162 }; 00163 00165 }; 00166 00167 #endif