qgtypes.h

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 _QGTYPES_H_
00026 #define _QGTYPES_H_
00027 
00028 #include <iostream>
00029 #include <vector>
00030 #include <string>
00031 
00032 #include "qgerror.h"
00033 
00034 /***************************************************************************
00035  * Basic types for QGame++.
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

Generated on Sat Apr 3 18:42:28 2004 for QGame++ by doxygen 1.3.5