00001 #ifndef _INC_NET_H
00002 #define _INC_NET_H
00003
00004 #include <fstream>
00005 #include <map>
00006 #include <list>
00007 #include <string>
00008 #include <complex>
00009 #include <iostream>
00010
00011 #include "matrix.h"
00012 #include "su2_cmp.h"
00013 #include "su2.h"
00014
00015 #include "Exception.h"
00016
00018
00036 class Net
00037 {
00038 public:
00040 struct icoord
00041 {
00042 short x : 16;
00043 short t : 16;
00044 short z : 16;
00045 short y : 16;
00046 };
00047
00049
00050 struct icoord_cmp
00051 {
00052 bool operator()(const icoord& A, const icoord& B) const
00053 {
00054 int* pA = (int *) &A;
00055 int* pB = (int *) &B;
00056
00057 if (*pA < *pB)
00058 return true;
00059 else if (*pA++ > *pB++)
00060 return false;
00061 else if (*pA < *pB)
00062 return true;
00063 else
00064 return false;
00065
00066
00067
00068
00069
00070
00071 }
00072 };
00073
00074
00075
00077 struct knot
00078 {
00079 int l;
00080 std::string word;
00081
00082 Matrix<cdouble> M;
00083 };
00084
00085
00087 std::list<knot*> knots;
00088 typedef std::complex<double> cdouble;
00089
00091 double tilewidth;
00092
00094 int G;
00095
00096 Matrix<cdouble>* gate_set;
00097 int N;
00098 char* gate_labels;
00099 int* gate_orders;
00100 int* gate_inverses;
00101
00103 int search_count;
00104
00106 char label_indices[512];
00107
00109 void generate_net(int max_length);
00110
00112 void add(Matrix<cdouble>& U, char* word, int l);
00113
00114
00115
00117
00120 icoord coordinate(const Matrix<cdouble>& U, int rounding=-1);
00121
00123 typedef std::map<icoord, std::list<knot*> , icoord_cmp> nettype;
00124 nettype su2net;
00125
00127 Net(double tw);
00128
00130 Net(const char* file);
00131
00133 ~Net(void);
00134
00136
00142 void generate(char* labels, cdouble** basis, int n, int max_length);
00143
00145 void generate(char labels[], cdouble basis[][4], int n, int max_length)
00146 {
00147 cdouble** b = new cdouble*[n];
00148 for (int i=0;i<n;i++)
00149 {
00150 b[i] = new cdouble[4];
00151 memcpy(b[i],basis[i],4*sizeof(cdouble));
00152 }
00153
00154 generate((char*)labels, b, n, max_length);
00155
00156 for (int i=0;i<n;i++)
00157 delete[] b[i];
00158 delete[] b;
00159 }
00160
00162 int load(const char* file);
00163
00165 void save(const char* file);
00166
00168 knot* nearest(const Matrix<cdouble>& U);
00169
00171 std::string nearest_string(const Matrix<cdouble>& U)
00172 {
00173 return nearest(U)->word;
00174 }
00175
00177 Matrix<cdouble> evaluate(const std::string& s);
00178
00180 std::string invert(const std::string& s);
00181
00183 int searched(void) { return search_count; }
00184
00186 int size(void) { return knots.size(); }
00187
00189 knot solovay_kitaev(const Matrix<cdouble>& U, int depth);
00190
00192
00193 friend std::ostream& operator<<(std::ostream& out, const Net& N);
00194 };
00195 #endif