CSS product code  0.1
C++ library to estimate distance of CSS codes. Some particular construction of CSS codes are implemented.
concatenation.c
Go to the documentation of this file.
1 //Nov 21, 2018 Weilei Zeng, copied from hypergraph.c
2 //construct quantum concatenated code from two quantum codes. Check their parameters
3 //there are several ways for concatenation, see hypergraph_product_code.pdf
4 
5 //July 22, 2018 Weilei Zeng
6 //An integrated program to check all parameter in Table 1 in Leonid's construction of Hypergraph product codes.
7 
8 
9 //Weilei Zeng, July 19, 2018
10 //According to Leonid's note on construction of high dimension hypergraph product code, using small random Matrix P_j, j={1,2,3,4} to generate code in 2D, 3D, and 4D. Then get parameters of [n,k,d] for those codes.
11 //This program is modified from the hypercubic code project (dated Jul 19, 2018)
12 
13 //if G_x.row_rank()+G_z.row_rank()=full rank, then it is not a quantum code.
14 //construct G_x and G_z for toric code, cubic code, and hypercubic code. Following the structure and notation in model.pdf
15 #include "weilei_lib/my_lib.h"
16 #include <itpp/itbase.h>
17 using namespace itpp;
18 using namespace std;
19 
20 /*//moved to lib.h
21 bool is_quantum_code(GF2mat G_x, GF2mat G_z){
22  //check if the code is quantum or not
23  //not used here. originally designed for generator like [7,3,4] code at random size, which has been confirmed to be valid only for size L = 7n
24  if (G_x.row_rank()+G_z.row_rank() == G_x.cols()){
25  return false;
26  }else{
27  return true;
28  }
29  }*/
30 
31 /*//moved to lib.h
32 GF2mat make_it_full_rank(GF2mat fat){
33  //Can not use the functoin here. I can not remove the degeneracy in the check matrix, which is actually the syndrome code. By removing it, I am removing the syndrome code.
34  //reduce a fat matrix with degenerate rows to a thin matrix with full rank; remove the dependent rows
35  GF2mat thin, T,U;
36  ivec P;
37  int rank = fat.T_fact(T,U,P);
38  thin = U.get_submatrix(0,0,rank-1,U.cols()-1);
39  thin.permute_cols(P,true);
40  return thin;
41  }*/
42 
43 GF2mat get_check_code734(int L){//L=7n
44  //return check matrix code code [7,3,4], find definition in research note.pdf
45  GF2mat G(L,L);
46  for ( int i=0;i<L;i++){
47  G.set(i,i,1);
48  if (i+2>L-1) {
49  G.set(i,i+2-L,1);
50  } else {
51  G.set(i,i+2,1);
52  }
53  if (i+3>L-1) {
54  G.set(i,i+3-L,1);
55  }else{
56  G.set(i,i+3,1);
57  }
58  }
59  return G;
60 }
61 GF2mat get_check_code743(int L){//L=7n
62  //return check matrix code code [7,4,3], find definition in research note.pdf
63  GF2mat G(L,L);
64  for ( int i=0;i<L;i++){
65  G.set(i,i,1);
66  if (i+2>L-1) {
67  G.set(i,i+2-L,1);
68  } else {
69  G.set(i,i+2,1);
70  }
71  if (i+3>L-1) {
72  G.set(i,i+3-L,1);
73  }else{
74  G.set(i,i+3,1);
75  }
76  if (i+4>L-1) {
77  G.set(i,i+4-L,1);
78  }else{
79  G.set(i,i+4,1);
80  }
81  }
82  return G;
83 }
84 
85 GF2mat get_check_rept(int L){//return circulant check matrix for repetition code of length L
86  GF2mat a(L,L);
87  for (int i=0;i<L-1;i++){//construct a : circulant check matrix for repetition code
88  a.set(i,i,1);
89  a.set(i,i+1,1);
90  }
91  a.set(L-1,L-1,1);
92  a.set(L-1,0,1);
93  //cout<<"circulant check matrix for repetition code : a = "<<a<<endl;
94  return a;
95 }
96 GF2mat get_check(int generator_flag, int L){
97  //return check matric a for generating toric code, cubic code and hypercubic code.
98  switch(generator_flag){
99  case 1: return get_check_rept(L);break;
100  case 2: return get_check_code734(L);break;
101  case 3: return get_check_code743(L);break;
102  }
103  // return get_check_734(L);//code [7,3,4]
104  // return get_check_743(L);//code [7,4,3]
105  // return get_check_rept(L); //circulant check matrix for repetition code.
106 }
107 
108 GF2mat extensionBj(GF2mat Aj,GF2mat Ajless, GF2mat P){
109  // GF2mat Aj=*Aj_p,Ajless=*Ajless_p,P=*P_p;
110  //cout<<"extensionBj"<<endl;
111  GF2mat Bj=kron(Aj,gf2dense_eye(P.rows()))
112  .concatenate_horizontal(kron(gf2dense_eye(Aj.rows()),P))
113  .concatenate_vertical(
114  GF2mat(Ajless.rows()*P.cols(),Aj.cols()*P.rows()).concatenate_horizontal(
115  kron(Ajless,gf2dense_eye(P.cols()))
116  ));
117  return Bj;
118 }
119 
120 GF2mat * extension(GF2mat *A1_p,GF2mat P,int m){
121  //from an (m-1) chain complex A = {A1,A2,A3,...A_(m-1)}, and an r x c binary matrix P, construct an extended m chain complex B={B1,B2,...,Bm}.
122  GF2mat A[m-1]; //construct A from pointer A1_p
123  for (int i=0;i<m-1;i++){
124  A[i]=*(A1_p+i);
125  }
126  const int MAX_m=6;//maximum length of chain complex
127  // cout<<"extension: m = "<<m<<endl;
128  //GF2mat B[MAX_m];
129  static GF2mat B[MAX_m];//have to be static to be used outside this function. It is better to use vector<> here
130  GF2mat A1=A[0],B1;
131  B1=kron(A1,gf2dense_eye(P.rows()))
132  .concatenate_horizontal(kron(gf2dense_eye(A1.rows()),P));
133  B[0]=B1;
134  if (m==2){
135  GF2mat B2=kron(gf2dense_eye( A1.cols() ),P)
136  .concatenate_vertical(kron(A1,gf2dense_eye(P.cols())));
137  B[1]=B2;
138  return B;
139  }
140  //if m>2
141  for (int j=2;j<m;j++){//run m-1 loop
142  GF2mat Bj = extensionBj(A[j-1],A[j-2],P);
143  B[j-1]=Bj;
144  }
145  GF2mat Amless = A[m-2];
146  GF2mat Bm=kron(gf2dense_eye( Amless.cols() ),P)
147  .concatenate_vertical(kron(Amless,gf2dense_eye(P.cols())));
148  B[m-1] = Bm;
149  return B;
150 }
151 
152 int printNKD(int nkd[][MAX_M], int m){//print n k d in table format
153  //5 is the maximum I will try, but just put 10 here since it is small
154  for ( int i=1;i<m+1;i++){
155  for ( int j=0;j<i+1;j++){
156  cout<<nkd[i][j]<<"\t";
157  }
158  cout<<endl;
159  }
160 }
161 vector<int> parameterP(GF2mat P[], int m){//m is the size of P
162  //print parameters of matrix P, and derived parameter of Cm including
163  //P: r,c,kappa,\tilde\kappa,\delta,\tilde\kappa,rank
164  //C:n,k,d_left,d_right
165  cout<<"#Expected value calculated from Table 1:"<<endl;
166  int n[m+1][MAX_M];
167  n[1][0]=P[0].rows();
168  n[1][1]=P[0].cols();
169  for ( int i=2;i<m+1;i++){
170  n[i][0]=n[i-1][0]*P[i-1].rows();
171  n[i][i]=n[i-1][i-1]*P[i-1].cols();
172  for ( int j=1;j<i;j++){
173  n[i][j]=n[i-1][j]*P[i-1].rows()+n[i-1][j-1]*P[i-1].cols();
174  }
175  }
176  cout<<"n0\tn1\tn2\tn3\tn4"<<endl;
177  printNKD(n,m);
178 
179  int k[m],kt[m],r;//\kappa, \tilde\kappa, rank
180  cout<<"-----------------------------------"<<endl;
181  for ( int i=0;i<m;i++){
182  r=P[i].row_rank();
183  //cout<<r<<"\t";
184  k[i]=P[i].cols()-r;
185  kt[i]=P[i].rows()-r;
186  }
187  int kC[m+1][MAX_M];//kC[m][j];k value of (Aj,Ajplus^T)
188  kC[1][0]=kt[0];
189  kC[1][1]=k[0];
190  for ( int i=2;i<m+1;i++){
191  kC[i][0]=kC[i-1][0]*kt[i-1];
192  kC[i][i]=kC[i-1][i-1]*k[i-1];
193  for ( int j=1;j<i;j++){
194  kC[i][j] = kC[i-1][j-1]*k[i-1]+kC[i-1][j]*kt[i-1];
195  }
196  }
197  cout<<"k0\tk1\tk2\tk3\tk4"<<endl;
198  printNKD(kC,m);
199  //distance
200  int delta[m],delta_tilde[m];//distance of P and P^T
201  int dl1,dl2; //temperary distance of P and P^T
202 
203  cout<<"-----------------------------------parameters of P:"<<endl;
204  cout<<"row\tcol\trank\tkappa,delta,kappa_tilde,delta_tilde"<<endl;
205  for ( int i=0;i<m;i++){
206  dl1 = classical_dist(P[i]);
207  dl2 = classical_dist(P[i].transpose());
208  // cout<<"dist(P["<<i<<"]) = "
209  cout<<P[i].rows()<<"\t"<<P[i].cols()<<"\t"<<P[i].row_rank()<<"\t";
210  cout<<k[i]<<"\t"<<dl1<<"\t"<<kt[i]<<"\t"<<dl2<<"\t"<<endl;
211  delta[i]=dl1;
212  delta_tilde[i]=dl2;
213  }
214  cout<<"-----------------------------------"<<endl;
215  // const int INF = 999;
216  int dl[m+1][MAX_M];
217  dl[1][1]=delta[0];
218  dl[1][0]= (kt[0]>0)? 1:INF;//delta_tilde[0];
219  for ( int i=2;i<m+1;i++){
220  dl[i][i]=dl[i-1][i-1]*delta[i-1];//not sure what to put here
221  dl[i][0]=(kt[i-1]>0)? dl[i-1][0]:INF;//delta_tilde[i-1];//last element
222  for ( int j=1;j<i;j++){//elements in between
223  dl[i][j]= (kt[i-1]>0)? min(dl[i-1][j-1]*delta[i-1],dl[i-1][j]) : dl[i-1][j-1]*delta[i-1];
224  }
225  }
226 
227  // cout<<"d0\td1\td2\td3\td4\td(left)"<<endl;
228  for (int i=1;i<m+1;i++){
229  for (int j=0;j<i+1;j++){
230  if (dl[i][j]>999){//normalize infinity
231  dl[i][j]=999;
232  }
233  }
234  }
235  // printNKD(dl,m);
236  vector<int> dist(m*(m+1)*2);
237  int index=0;
238  for (int i=1;i<m+1;i++){
239  for (int j=0;j<i+1;j++){
240  dist[index]=dl[i][j];
241  index++;
242  }
243  }
244 
245  //right distance
246  int dr[m+1][MAX_M];
247  dr[1][0]=delta_tilde[0];
248  dr[1][1]= (k[0]>0)? 1:INF;//delta_tilde[0];
249  for ( int i=2;i<m+1;i++){
250  dr[i][0]=dr[i-1][0]*delta_tilde[i-1];//not sure what to put here
251  dr[i][i]=(k[i-1]>0)? dr[i-1][i-1]:INF;//delta_tilde[i-1];//last element
252  for ( int j=1;j<i;j++){//elements in between
253  dr[i][j]= (k[i-1]>0)? min(dr[i-1][j]*delta_tilde[i-1],dr[i-1][j-1]) : dr[i-1][j]*delta_tilde[i-1];
254  }
255  }
256  // cout<<"d0\td1\td2\td3\td4\td(right)"<<endl;
257  for (int i=1;i<m+1;i++){
258  for (int j=0;j<i+1;j++){
259  if (dr[i][j]>999){//normalize infinity for output
260  dr[i][j]=999;
261  }
262  }
263  }
264  // printNKD(dr,m);
265 
266  //add to vector dist
267  index=m*(m+1);
268  for (int i=1;i<m+1;i++){
269  for (int j=0;j<i+1;j++){
270  dist[index]=dr[i][j];
271  index++;
272  }
273  }
274 
275  //print distance
276 
277  int d_min[m+1][MAX_M];
278  for (int i=1;i<m+1;i++){
279  for (int j=0;j<i+1;j++){
280  d_min[i][j]=min(dl[i][j],dr[i][j]);
281  }
282  }
283  cout<<"d0\td1\td2\td3\td4\td_min=min(d_left,d_right)"<<endl;
284  printNKD(d_min,m);
285  cout<<"d0\td1\td2\td3\td4\td_left"<<endl;
286  printNKD(dl,m);
287  cout<<"d0\td1\td2\td3\td4\td_right"<<endl;
288  printNKD(dr,m);
289 
290 
291  // cout<<"\# Numerical results on [n,k,d] value of code Q (Aj,A(j+1)^T)"<<endl;
292  return dist;
293 }
294 
295 int parameterC(GF2mat *B1, int m, int m_max, vector<int> dist){//*B1=Cm[0]
296  //input: pointer of first matrix, length of the chain, max chain length, expected distance
297  //print rank and size of Cm
298 
299  int r[m];//rank
300  cout<<" n= ";
301  for (int i=0;i<m;i++){
302  r[i]=(B1+i)->row_rank();
303  cout<<(B1+i)->rows()<<"\t";
304  // cout<<"m="<<m<<",i="<<i<<", rank="<<r[i]<<", size("<<(B1+i)->rows()<<","<<(B1+i)->cols()<<")"<<endl;
305  }
306  cout<<(B1+m-1)->cols()<<endl;
307  cout<<" k= ";
308  for (int i=0;i<m-1;i++){
309  int k = (B1+i)->cols() - r[i] -r[i+1];
310  cout<<k<<"\t";
311  }
312  cout<<endl;
313  //check distance
314 
315 
316  /* for (int i=0;i<30;i++){//14 for m_max=4
317  cout<<"["<<""<<dist[i]<<"]";
318  }*/
319  //left distance
320  cout<<"d_left=\t";
321  for (int i=0;i<m-1;i++){
322  int index = m*(m+1)/2+i;
323  int d_left = hypergraph_dist(*(B1+i),*(B1+i+1),dist[index] );
324  cout<<d_left<<"\t";
325  }
326  cout<<endl;
327 
328  cout<<" d_right=";
329  // int m_max=5;
330  for (int i=0;i<m-1;i++){
331  int index = m_max*(m_max+1)+m*(m+1)/2+i;
332  int d_right = hypergraph_dist(*(B1+i),*(B1+i+1),dist[index] ,1);//1 for flipping to right distance
333  cout<<d_right<<"\t";
334  }
335  cout<<endl;
336  return 0;
337 }
338 
339 int saveC(GF2mat *B1,int m, char * folder_Cm){//*B1=C[0]
340  //save or print the result
341  for (int i=0;i<m;i++){
342  char filename[256];
343  // char folder[]="data/random/C";
344  sprintf(filename,"%s/C%d_%d.mm",folder_Cm,m,i);
345  GF2mat_to_MM(*(B1+i),filename);
346 
347  /* char matrixname[256];
348  sprintf(matrixname,"m=%d C[%d]",m,i);
349  GF2matPrint(*(B1+i),matrixname);*/
350  }
351  return 0;
352 }
353 
354 GF2mat generate_random_P(double p, int x,int y,char * filename){
355  //probability p to get 1 for each element
356  //return P with density p
357  GF2mat P(x,y);
358  for (int i=0;i<x;i++){
359  for ( int j=0;j<y;j++){
360  if (randu()<p) P.set(i,j,1);
361  }
362  }
363  // cout<<"Pj"<<P<<endl;
364  // GF2mat_to_MM(P,filename);
365  return P;
366 }
367 
368 //int check(GF2mat Aj,GF2mat Ajplus, GF2mat Bj,GF2mat Bjplus){
369 int check(){
370  GF2mat Aj=MM_to_GF2mat("data/random/temp/C2_0.mm");
371  GF2mat Ajplus=MM_to_GF2mat("data/random/temp/C2_1.mm");
372  GF2mat Bj=MM_to_GF2mat("data/random/temp/C3_0.mm");
373  GF2mat Bjplus=MM_to_GF2mat("data/random/temp/C3_1.mm");
374 
375  cout<<Aj.rows()<<"x"<<Aj.cols()<<endl;
376  cout<<Ajplus.rows()<<"x"<<Ajplus.cols()<<endl;
377  cout<<Bj.rows()<<"x"<<Bj.cols()<<endl;
378  cout<<Bjplus.rows()<<"x"<<Bjplus.cols()<<endl;
379  cout<<"check"<<endl;
380 
381  GF2mat T,U;
382  ivec P;
383  int rank_of_Aj =Aj.transpose().T_fact(T,U,P);
384  GF2mat C = T.get_submatrix(rank_of_Aj,0,Aj.cols()-1,Aj.cols()-1);//rank_of_T = Aj.cols()-rank_of_Aj
385  int dAj=2;
386  bvec codeword=zeros_b(Aj.cols());
387  bvec zero=zeros_b(Aj.cols());
388  for ( int i=0;i<C.rows();i++){
389  codeword = C.get_row(i);
390  int wt = BERC::count_errors(zero,codeword);
391  if (wt==dAj){
392  cout<<"codeword : "<<codeword<<endl;
393  break;
394  }
395  }
396  cout<<Aj*codeword<<endl;
397  bvec codewordB;
398  int r=4;
399  GF2mat y(1,r);
400  GF2mat x(1,Aj.cols());
401  x.set_row(0,codeword);
402  y.set(0,1,1);
403  GF2mat z=kron(x,y);
404  z.set_size(1,Bj.cols(),true);
405  //bvec e=z.get_row(0);
406  if ( (Bj*z.transpose()).is_zero() ){
407  cout<<"Bj*z=0"<<endl;
408  }
409  GF2mat BjplusT=Bjplus.transpose();
410  GF2mat Bz=BjplusT.concatenate_vertical(z);
411  cout<<Bjplus.row_rank()<<"<>"<<Bz.rows()<<"<>"<<Bz.row_rank()<<endl;
412  return 0;
413 }
414 
415 int check2(){//check if the codeword with smaller distance is inside Bjplus
416  GF2mat Aj=MM_to_GF2mat("data/random/temp/C3_1.mm");
417  GF2mat Ajplus=MM_to_GF2mat("data/random/temp/C3_2.mm");
418  GF2mat Bj=MM_to_GF2mat("data/random/temp/C4_2.mm");
419  GF2mat Bjplus=MM_to_GF2mat("data/random/temp/C4_3.mm");
420 
421  cout<<Aj.rows()<<"x"<<Aj.cols()<<endl;
422  cout<<Ajplus.rows()<<"x"<<Ajplus.cols()<<endl;
423  cout<<Bj.rows()<<"x"<<Bj.cols()<<endl;
424  cout<<Bjplus.rows()<<"x"<<Bjplus.cols()<<endl;
425  cout<<"check2"<<endl;
426 
427  GF2mat T,U;
428  ivec P;
429  int rank_of_Aj =Aj.transpose().T_fact(T,U,P);
430  GF2mat C = T.get_submatrix(rank_of_Aj,0,Aj.cols()-1,Aj.cols()-1);//rank_of_T = Aj.cols()-rank_of_Aj
431  int dAj=4;
432  bvec codeword=zeros_b(Aj.cols());
433  bvec zero=zeros_b(Aj.cols());
434  for ( int i=0;i<C.rows();i++){
435  codeword = C.get_row(i);
436  int wt = BERC::count_errors(zero,codeword);
437  if (wt==dAj){
438  cout<<"codeword : "<<codeword<<endl;
439  break;
440  }
441  }
442  cout<<Aj*codeword<<endl;
443 
444  GF2mat AjplusT=Ajplus.transpose();
445  GF2mat z(1,AjplusT.cols());
446  z.set_row(0,codeword);
447  GF2mat Az=AjplusT.concatenate_vertical(z);
448  cout<<Ajplus.row_rank()<<"<>"<<Az.rows()<<"<>"<<Az.row_rank()<<endl;
449  if ( (Aj*Az.transpose()).is_zero() ){
450  cout<<"Aj*AzT=0"<<endl;
451  }
452  /*
453  GF2mat BjplusT=Bjplus.transpose();
454  GF2mat Bz=BjplusT.concatenate_vertical(z);
455  cout<<Bjplus.row_rank()<<"<>"<<Bz.rows()<<"<>"<<Bz.row_rank()<<endl;
456  */
457  return 0;
458 }
459 
460 int generate_concatenation(GF2mat P[],int max_m,vector<int> dist, char * folder_Cm){//folder_Cm: the folder to save all C matrix
461  GF2mat *Cm1,*Cm2;
462  Cm1=&P[0];Cm2=&P[2];
463  Cm1=extension(Cm1,P[1],2);
464  GF2mat Gax=*Cm1,Gaz=*(Cm1+1);
465  Cm2=extension(Cm2,P[3],2);
466  GF2mat Gbx=*Cm2,Gbz=*(Cm2+1);
467  Gaz=Gaz.transpose(); Gbz=Gbz.transpose();
468  //quantum_dist(Gax,Gaz,5,1);
469  //following is an upper bound of distance, need to be checked
470  int daz=min(classical_dist(P[0]),classical_dist(P[1]) );
471  int dax=min(classical_dist(P[0].transpose()),classical_dist(P[1].transpose()));
472  int dbz=min(classical_dist(P[2]),classical_dist(P[3]));
473  int dbx=min(classical_dist(P[2].transpose()),classical_dist(P[3].transpose()));
474  // concatenate(Gax,Gaz,Gbx,Gbz,dax,daz,dbx,dbz);
475  reduce(Gax,Gaz,Gbx,Gbz,dax,daz,dbx,dbz);
476  cout<<"finish generate_concatenation"<<endl;
477  return 0;
478 }
479 
480 int generate(GF2mat P[],int max_m,vector<int> dist, char * folder_Cm){//folder_Cm: the folder to save all C matrix
481  //from P[] create m chain complex for m=2,3,4, and save it in folder_Cm
482  // int L=6;//15 min for size 6
483  // GF2mat P=get_check_rept(L);
484  // check(); check2();return 0;
485  // const int max_m=4;
486 
487  GF2mat *Cm1;//the first matrix in m-chain complex C
488  Cm1=&P[0];//initialize
489 
490 
491  GF2mat Cms[max_m*(max_m)];//save all Cm matrices for test
492  Cms[0]=P[0];
493  for ( int i=2;i<max_m+1;i++){
494  Cm1 = extension(Cm1,P[i-1],i);
495  // GF2mat *temp= & Cm1;
496  for ( int j=0;j<i;j++){
497  Cms[(i-1)*max_m+j] = *(Cm1+j);
498  }
499  //saveC(Cm1,i,folder_Cm);
500  parameterC(Cm1,i,max_m,dist);
501  }
502  // check(Cms[4],Cms[5],Cms[8],Cms[9] );
503  return 0;
504 }
505 
506 int main(int args, char ** argv){
507 
508 
509  RNG_randomize();
510  Real_Timer timer;
511  timer.tic();
512  int max_m=4;
513  GF2mat P[max_m];
514  char * folder_Cm = "null";//argv[5];
515 
516  if (args == 2) {//generate random P, and save with title
517  char * title = argv[1];
518  int px,py; //size of P[i]
519  double density = 0.5; //density of P[i]
520  for ( int i =0;i<max_m;i++){
521  // P[i] = MM_to_GF2mat(argv[i+1]);
522  char pname[256];
523  sprintf(pname,"%s-P%d.mm",title,i+1);//different input title to save the matrix in file
524  px=randi(4,7); py=randi(4,7);
525  //px=5;py=px;
526  density=0.75;//3.5/py;
527  P[i]=generate_random_P(density,px,py,pname);//p,x,y,filename
528  //check some condition to be satisfied. maximum number should be controled
529  int condition_trials=500;
530  for (int j=0;j<condition_trials;j++){
531  // * check full rank, typical max run 2 to remain some full rank matrix
532  //if (P[i].row_rank()==P[i].rows()){//reduce prob of full rank
533  if ( P[i].row_rank() == min(P[i].rows(),P[i].cols()) ){ //no full rank
534  P[i]=generate_random_P(density,px,py,pname);//p,x,y,filename
535  }else{
536  GF2mat_to_MM(P[i],pname);//save file disabled in generate_random_P()
537  break;
538  } // * //
539  /* //check condition for TZ's code, Alexey 2018
540  int kappa=P[i].cols()-P[i].row_rank();
541  int delta=classical_dist(P[i]);
542  int delta_tilde=classical_dist(P[i].transpose());
543  int delta_min = min(delta,delta_tilde);
544  // if (delta<INF &&delta_tilde<INF && kappa*delta_min >P[i].cols()){
545  if (delta<INF &&delta_tilde<INF){//this condition is the same as P[i].row_rank()<min(P[i].rows(),P[i].cols())
546  cout<<"condition satidfied when j = "<<j<<endl;
547  GF2mat_to_MM(P[i],pname);//save file disabled in generate_random_P()
548  break;
549  }else{
550  P[i]=generate_random_P(density,px,py,pname);//p,x,y,filename
551  }*/
552  }
553  // P[i] = get_check_rept(4);
554  //P[i]=get_check_code743(7);
555  // cout<<"P["<<i+1<<"] "<<P[i]<<endl;
556  }
557  }else{//from given P
558  cout<<"Check result for given P. "<<argv[1]<<endl;
559  for ( int i =0;i<max_m;i++){
560  char * filename_Pi = argv[i+1];
561  P[i]=MM_to_GF2mat(filename_Pi);
562  cout<<"P["<<i+1<<"] "<<P[i]<<endl;
563  }
564  /* char * filename_P1 = argv[1];
565  char * filename_P2 = argv[2];
566  char * filename_P3 = argv[3];
567  char * filename_P4 = argv[4];*/
568  folder_Cm = argv[5]; //not in use
569 
570  }
571  vector<int> dist;
572  dist = parameterP(P,max_m);//not necessary for concatenation right now
573 
574  generate_concatenation(P,max_m,dist,folder_Cm);
575  // generate(P,max_m,dist,folder_Cm);
576  cout<<"Finish "<<argv[1]<<". Time needed is ";
577  timer.toc_print();
578  return 0;
579 }
get_check_code734
GF2mat get_check_code734(int L)
Definition: concatenation.c:43
common::classical_dist
int classical_dist(itpp::GF2mat G)
Definition: dist.cpp:114
generate
int generate(GF2mat P[], int max_m, vector< int > dist, char *folder_Cm)
Definition: concatenation.c:480
check2
int check2()
Definition: concatenation.c:415
parameterP
vector< int > parameterP(GF2mat P[], int m)
Definition: concatenation.c:161
MAX_M
const int MAX_M
Definition: product_lib.h:13
MM_to_GF2mat
itpp::GF2mat MM_to_GF2mat(std::string file_name)
Definition: mm_read.cpp:36
get_check_code743
GF2mat get_check_code743(int L)
Definition: concatenation.c:61
parameterC
int parameterC(GF2mat *B1, int m, int m_max, vector< int > dist)
Definition: concatenation.c:295
GF2mat_to_MM
int GF2mat_to_MM(itpp::GF2mat G, char *file_name, int debug)
Definition: mm_write.cpp:18
common::INF
const int INF
Definition: dist.h:19
extension
GF2mat * extension(GF2mat *A1_p, GF2mat P, int m)
Definition: concatenation.c:120
saveC
int saveC(GF2mat *B1, int m, char *folder_Cm)
Definition: concatenation.c:339
common::kron
itpp::GF2mat kron(itpp::GF2mat A, itpp::GF2mat B)
Definition: lib.cpp:162
extensionBj
GF2mat extensionBj(GF2mat Aj, GF2mat Ajless, GF2mat P)
Definition: concatenation.c:108
printNKD
int printNKD(int nkd[][MAX_M], int m)
Definition: concatenation.c:152
get_check_rept
GF2mat get_check_rept(int L)
Definition: concatenation.c:85
check
int check()
Definition: concatenation.c:369
common::hypergraph_dist
int hypergraph_dist(itpp::GF2mat Aj, itpp::GF2mat Ajplus, int dist_expected, int flip=0)
Definition: dist.cpp:292
generate_concatenation
int generate_concatenation(GF2mat P[], int max_m, vector< int > dist, char *folder_Cm)
Definition: concatenation.c:460
generate_random_P
GF2mat generate_random_P(double p, int x, int y, char *filename)
Definition: concatenation.c:354
main
int main(int args, char **argv)
Definition: concatenation.c:506
get_check
GF2mat get_check(int generator_flag, int L)
Definition: concatenation.c:96