17 itpp::bvec alpha(C.rows());
18 itpp::GF2mat alphaM(1,C.rows());
19 int max = pow(2,C.rows());
20 itpp::bvec codeword(C.cols());
21 int wt, min_wt=C.cols();
22 itpp::bvec zero = itpp::zeros_b(C.cols());
26 for (
int i =1;i<max;i++){
28 alpha = itpp::dec2bin(C.rows(),i);
29 alphaM.set_row(0,alpha);
32 codeword=(alphaM*C).get_row(0);
33 wt = itpp::BERC::count_errors(zero,codeword);
35 min_wt = (wt<min_wt)? wt : min_wt;
36 if ( min_wt == 1)
return 1;
47 int C_rows=C.rows(), G_rows=G.rows();
48 int dec_C=(int) pow(2, C_rows);
49 int dec_G=(int) pow(2, G_rows);
52 itpp::bvec bvec_zero=itpp::zeros_b(N);
53 itpp::GF2mat alpha_C(1,C_rows), alpha_G(1,G_rows);
56 for (
int i = 1; i < dec_C ; i++){
57 alpha_C.set_row(0,itpp::dec2bin(C_rows,i));
58 for (
int j = 0; j < dec_G; j++){
59 alpha_G.set_row(0,itpp::dec2bin(G_rows,j));
60 bvec_C = (alpha_C * C + alpha_G * G).get_row(0);
62 wt = itpp::BERC::count_errors(bvec_zero,bvec_C);
64 min_wt = (wt<min_wt)? wt : min_wt;
65 if ( min_wt == 1 )
return 1;
89 itpp::bvec row_vec,zero=itpp::zeros_b(C.cols());
90 int wt,min_wt=C.cols();
94 for (
int j=0;j<perm_try;j++){
95 perm = sort_index( itpp::randu(C.cols()) );
96 C.permute_cols(perm,
false);
99 perm = sort_index( itpp::randu(C.rows()) );
100 C.permute_rows(perm,
false);
102 for (
int i = 0;i<C.rows();i++){
103 row_vec = C.get_row(i);
104 wt = itpp::BERC::count_errors(zero,row_vec);
119 int rank_of_G = G.transpose().T_fact(T,U,P);
120 if ( rank_of_G == G.cols() ){
123 itpp::GF2mat H = T.get_submatrix(rank_of_G,0,G.cols()-1,G.cols()-1);
134 itpp::GF2mat T,U; itpp::ivec P;
136 int rank_of_G = G.transpose().T_fact(T,U,P);
138 itpp::GF2mat Q=T.get_submatrix(rank_of_G,0,n-1,n-1);
147 itpp::GF2mat temp=G_x;
153 int rank_of_G_z = G_z.transpose().T_fact(T,U,P);
154 itpp::GF2mat Q=T.get_submatrix(rank_of_G_z,0,G_z.cols()-1,G_z.cols()-1);
155 itpp::GF2mat GQ=G_x.concatenate_vertical(Q);
158 int rank_of_G_x = G_x.row_rank();
159 int rank_of_Q = Q.rows();
160 if (rank_of_G_x == rank_of_Q){
161 std::cout<<
"getC(): It is not a quantum code:zero rank for codeword space"<<std::endl;
164 if ( G_x.cols()-rank_of_G_z-rank_of_G_x < 1){
165 std::cout<<
"empty code space"<<std::endl;
166 throw "empty code space";
170 itpp::GF2mat C = U.get_submatrix(rank_of_G_x,0,rank_of_Q-1,G_x.cols()-1 );
172 C.permute_cols(P,
true);
186 itpp::GF2mat temp=G_x; G_x=G_z; G_z=temp;
191 itpp::GF2mat T,U; itpp::ivec P;
192 int rank_of_G_z = G_z.transpose().T_fact(T,U,P);
195 if (G_z.cols() - rank_of_G_z < 11){
200 itpp::GF2mat Q=T.get_submatrix(rank_of_G_z,0,G_z.cols()-1,G_z.cols()-1);
201 itpp::GF2mat GQ=G_x.concatenate_vertical(Q);
202 int min_wt=GQ.cols(),wt;
204 for (
int iq=0;iq<trialQ;iq++){
205 itpp::ivec perm = sort_index( itpp::randu( GQ.cols() ));
206 GQ.permute_cols(perm,
false);
208 int rank_of_G_x = G_x.row_rank();
209 int rank_of_Q = Q.rows();
211 if (rank_of_G_x == rank_of_Q){
214 itpp::GF2mat C = U.get_submatrix(rank_of_G_x,0,rank_of_Q-1,G_x.cols()-1 );
215 C.permute_cols(P,
true);
218 trialQ=(wt<min_wt)? ( (10*iq > trialQ)? 10*iq : trialQ ):trialQ;
219 min_wt=(wt<min_wt)? wt:min_wt;
220 if (min_wt ==1)
return 1;
232 if ( dist_expected > 10 ) trialQ = trialQ*2;
236 itpp::GF2mat temp=G_x; G_x=G_z; G_z=temp;
239 itpp::GF2mat T,U; itpp::ivec P;
240 int rank_of_G_z = G_z.transpose().T_fact(T,U,P);
241 itpp::GF2mat Q=T.get_submatrix(rank_of_G_z,0,G_z.cols()-1,G_z.cols()-1);
245 itpp::GF2mat GQ=G_x.concatenate_vertical(Q);
246 int min_wt=GQ.cols(),wt;
248 for (
int iq=0;iq<trialQ;iq++){
249 itpp::ivec perm = sort_index( itpp::randu( GQ.cols() ));
250 GQ.permute_cols(perm,
false);
252 int rank_of_G_x = G_x.row_rank();
253 int rank_of_Q = Q.rows();
255 if (rank_of_G_x == rank_of_Q){
258 itpp::GF2mat C = U.get_submatrix(rank_of_G_x,0,rank_of_Q-1,G_x.cols()-1 );
259 C.permute_cols(P,
true);
263 min_wt=(wt<min_wt)? wt:min_wt;
268 for (
int i =0;i<max_trial;i++){
270 min_wt=(wt<min_wt)? wt:min_wt;
273 if (min_wt <= dist_expected){
277 trialQ=(trialQ<1000)? 1000:trialQ;
278 if (debug) std::cout<<
"quantum_dist: reach min distance when iq = "<<iq<<
", continue to run with trialQ = "<<trialQ<<std::endl;
294 itpp::GF2mat G_z = Aj;
295 itpp::GF2mat G_x = Ajplus.transpose();
304 itpp::GF2mat temp=G_x;
317 int rank_of_G_z = G_z.transpose().T_fact(T,U,P);
318 itpp::GF2mat Q=T.get_submatrix(rank_of_G_z,0,G_z.cols()-1,G_z.cols()-1);
323 itpp::GF2mat GQ=G_x.concatenate_vertical(Q);
324 int min_wt=GQ.cols(),wt;
326 for (
int iq=0;iq<trialQ;iq++){
327 itpp::ivec perm = sort_index( itpp::randu( GQ.cols() ));
328 GQ.permute_cols(perm,
false);
330 int rank_of_G_x = G_x.row_rank();
331 int rank_of_Q = Q.rows();
333 if (rank_of_G_x == rank_of_Q){
335 if (dist_expected != 999){
336 std::cout<<std::endl<<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!NOTICE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!NOTICE!!!!!!!!!!!!!"<<std::endl;
337 std::cout<<
"("<<dist_expected<<
")";
341 itpp::GF2mat C = U.get_submatrix(rank_of_G_x,0,rank_of_Q-1,G_x.cols()-1 );
342 C.permute_cols(P,
true);
348 min_wt=(wt<min_wt)? wt:min_wt;
353 for (
int i =0;i<max_trial;i++){
354 if (min_wt == dist_expected){
357 }
else if (min_wt < dist_expected){
365 min_wt=(wt<min_wt)? wt:min_wt;
370 if (min_wt == dist_expected){
376 if (min_wt != dist_expected){
377 std::cout<<std::endl<<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!NOTICE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!NOTICE!!!!!!!!!!!!!"<<std::endl;
378 std::cout<<
"("<<dist_expected<<
")";
397 int N=error_bits.length();
398 int n=(int) sqrt(N/2);
402 for (
int j=0; j<n; j++){
403 if (error_bits.get(n*0+j)){
409 std::cout<<std::endl;
410 for (
int i=1;i<n;i++){
411 for (
int j=0; j<n; j++){
412 if (error_bits.get(n*(i-1)+n*n+j)){
417 if (error_bits.get(n*i+j)){
424 std::cout<<std::endl;
427 for (
int j=0; j<n; j++){
428 if (error_bits.get(n*(n-1)+n*n+j)){
435 std::cout<<std::endl;
440 std::cout<<header.c_str()<<std::endl;
455 itpp::bvec e_t = e_in;
458 H.set_size(H.rows(),H.cols()+1,
true);
459 H.set_col(H.cols()-1,s);
463 H.transpose().T_fact(T,U,P);
464 itpp::GF2mat Q=T.get_submatrix(H.rows(),0,H.cols()-1,H.cols()-1);
465 itpp::bvec X_t=Q.get_row(Q.rows()-1);
466 X_t.set_size(X_t.size()-1,
true);
474 for (
int i=0;i<L;i++){
493 for (
int i=0;i<L;i++){
515 for (
int i=0;i<L-1;i++){
526 switch(generator_flag){
551 itpp::GF2mat_sparse Gs=G.sparsify();
552 itpp::GF2mat_sparse_alist Gsa;
554 itpp::LDPC_Parity H(Gsa);
555 itpp::LDPC_Code C(&H);