11 #include "weilei_lib/my_lib.h"
12 #include <itpp/itbase.h>
40 for (
int i=0;i<L;i++){
58 for (
int i=0;i<L;i++){
81 for (
int i=0;i<L-1;i++){
92 switch(generator_flag){
105 GF2mat Bj=
kron(Aj,gf2dense_eye(P.rows()))
106 .concatenate_horizontal(
kron(gf2dense_eye(Aj.rows()),P))
107 .concatenate_vertical(
108 GF2mat(Ajless.rows()*P.cols(),Aj.cols()*P.rows()).concatenate_horizontal(
109 kron(Ajless,gf2dense_eye(P.cols()))
117 for (
int i=0;i<m-1;i++){
122 static GF2mat B[MAX_m];
124 B1=
kron(A1,gf2dense_eye(P.rows()))
125 .concatenate_horizontal(
kron(gf2dense_eye(A1.rows()),P));
128 GF2mat B2=
kron(gf2dense_eye( A1.cols() ),P)
129 .concatenate_vertical(
kron(A1,gf2dense_eye(P.cols())));
134 for (
int j=2;j<m;j++){
138 GF2mat Amless = A[m-2];
139 GF2mat Bm=
kron(gf2dense_eye( Amless.cols() ),P)
140 .concatenate_vertical(
kron(Amless,gf2dense_eye(P.cols())));
147 for (
int i=1;i<m+1;i++){
148 for (
int j=0;j<i+1;j++){
149 cout<<nkd[i][j]<<
"\t";
158 cout<<
"#Expected value calculated from Table 1:"<<endl;
177 for (
int i=2;i<m+1;i++){
178 n[i][0]=n[i-1][0]*P[i-1].rows();
179 n[i][i]=n[i-1][i-1]*P[i-1].cols();
180 for (
int j=1;j<i;j++){
181 n[i][j]=n[i-1][j]*P[i-1].rows()+n[i-1][j-1]*P[i-1].cols();
184 cout<<
"n0\tn1\tn2\tn3\tn4"<<endl;
188 cout<<
"-----------------------------------"<<endl;
189 for (
int i=0;i<m;i++){
214 for (
int i=2;i<m+1;i++){
215 kC[i][0]=kC[i-1][0]*kt[i-1];
216 kC[i][i]=kC[i-1][i-1]*k[i-1];
217 for (
int j=1;j<i;j++){
218 kC[i][j] = kC[i-1][j-1]*k[i-1]+kC[i-1][j]*kt[i-1];
221 cout<<
"k0\tk1\tk2\tk3\tk4"<<endl;
230 int delta[m],delta_tilde[m];
233 cout<<
"-----------------------------------parameters of P:"<<endl;
234 cout<<
"row\tcol\trank\tkappa,delta,kappa_tilde,delta_tilde"<<endl;
235 for (
int i=0;i<m;i++){
239 cout<<P[i].rows()<<
"\t"<<P[i].cols()<<
"\t"<<P[i].row_rank()<<
"\t";
240 cout<<k[i]<<
"\t"<<dl1<<
"\t"<<kt[i]<<
"\t"<<dl2<<
"\t"<<endl;
244 cout<<
"-----------------------------------"<<endl;
267 dl[1][0]= (kt[0]>0)? 1:
INF;
268 for (
int i=2;i<m+1;i++){
269 dl[i][i]=dl[i-1][i-1]*delta[i-1];
270 dl[i][0]=(kt[i-1]>0)? dl[i-1][0]:
INF;
271 for (
int j=1;j<i;j++){
272 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];
277 for (
int i=1;i<m+1;i++){
278 for (
int j=0;j<i+1;j++){
285 vector<int> dist(m*(m+1)*2);
287 for (
int i=1;i<m+1;i++){
288 for (
int j=0;j<i+1;j++){
289 dist[index]=dl[i][j];
296 dr[1][0]=delta_tilde[0];
297 dr[1][1]= (k[0]>0)? 1:
INF;
298 for (
int i=2;i<m+1;i++){
299 dr[i][0]=dr[i-1][0]*delta_tilde[i-1];
300 dr[i][i]=(k[i-1]>0)? dr[i-1][i-1]:
INF;
301 for (
int j=1;j<i;j++){
302 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];
306 for (
int i=1;i<m+1;i++){
307 for (
int j=0;j<i+1;j++){
317 for (
int i=1;i<m+1;i++){
318 for (
int j=0;j<i+1;j++){
319 dist[index]=dr[i][j];
326 int d_min[m+1][
MAX_M];
327 for (
int i=1;i<m+1;i++){
328 for (
int j=0;j<i+1;j++){
329 d_min[i][j]=min(dl[i][j],dr[i][j]);
332 cout<<
"d0\td1\td2\td3\td4\td_min=min(d_left,d_right)"<<endl;
334 cout<<
"d0\td1\td2\td3\td4\td_left"<<endl;
336 cout<<
"d0\td1\td2\td3\td4\td_right"<<endl;
340 cout<<
"\# Numerical results on [n,k,d] value of code Q (Aj,A(j+1)^T)"<<endl;
344 int parameterC(GF2mat *B1,
int m,
int m_max, vector<int> dist){
349 for (
int i=0;i<m;i++){
350 r[i]=(B1+i)->row_rank();
351 cout<<(B1+i)->rows()<<
"\t";
354 cout<<(B1+m-1)->cols()<<endl;
356 for (
int i=0;i<m-1;i++){
357 int k = (B1+i)->cols() - r[i] -r[i+1];
369 for (
int i=0;i<m-1;i++){
370 int index = m*(m+1)/2+i;
378 for (
int i=0;i<m-1;i++){
379 int index = m_max*(m_max+1)+m*(m+1)/2+i;
387 int saveC(GF2mat *B1,
int m,
char * folder_Cm){
389 for (
int i=0;i<m;i++){
392 sprintf(filename,
"%s/C%d_%d.mm",folder_Cm,m,i);
406 for (
int i=0;i<x;i++){
407 for (
int j=0;j<y;j++){
408 if (randu()<p) P.set(i,j,1);
423 cout<<Aj.rows()<<
"x"<<Aj.cols()<<endl;
424 cout<<Ajplus.rows()<<
"x"<<Ajplus.cols()<<endl;
425 cout<<Bj.rows()<<
"x"<<Bj.cols()<<endl;
426 cout<<Bjplus.rows()<<
"x"<<Bjplus.cols()<<endl;
431 int rank_of_Aj =Aj.transpose().T_fact(T,U,P);
432 GF2mat C = T.get_submatrix(rank_of_Aj,0,Aj.cols()-1,Aj.cols()-1);
434 bvec codeword=zeros_b(Aj.cols());
435 bvec zero=zeros_b(Aj.cols());
436 for (
int i=0;i<C.rows();i++){
437 codeword = C.get_row(i);
438 int wt = BERC::count_errors(zero,codeword);
440 cout<<
"codeword : "<<codeword<<endl;
444 cout<<Aj*codeword<<endl;
448 GF2mat x(1,Aj.cols());
449 x.set_row(0,codeword);
452 z.set_size(1,Bj.cols(),
true);
454 if ( (Bj*z.transpose()).is_zero() ){
455 cout<<
"Bj*z=0"<<endl;
457 GF2mat BjplusT=Bjplus.transpose();
458 GF2mat Bz=BjplusT.concatenate_vertical(z);
459 cout<<Bjplus.row_rank()<<
"<>"<<Bz.rows()<<
"<>"<<Bz.row_rank()<<endl;
469 cout<<Aj.rows()<<
"x"<<Aj.cols()<<endl;
470 cout<<Ajplus.rows()<<
"x"<<Ajplus.cols()<<endl;
471 cout<<Bj.rows()<<
"x"<<Bj.cols()<<endl;
472 cout<<Bjplus.rows()<<
"x"<<Bjplus.cols()<<endl;
473 cout<<
"check2"<<endl;
477 int rank_of_Aj =Aj.transpose().T_fact(T,U,P);
478 GF2mat C = T.get_submatrix(rank_of_Aj,0,Aj.cols()-1,Aj.cols()-1);
480 bvec codeword=zeros_b(Aj.cols());
481 bvec zero=zeros_b(Aj.cols());
482 for (
int i=0;i<C.rows();i++){
483 codeword = C.get_row(i);
484 int wt = BERC::count_errors(zero,codeword);
486 cout<<
"codeword : "<<codeword<<endl;
490 cout<<Aj*codeword<<endl;
492 GF2mat AjplusT=Ajplus.transpose();
493 GF2mat z(1,AjplusT.cols());
494 z.set_row(0,codeword);
495 GF2mat Az=AjplusT.concatenate_vertical(z);
496 cout<<Ajplus.row_rank()<<
"<>"<<Az.rows()<<
"<>"<<Az.row_rank()<<endl;
497 if ( (Aj*Az.transpose()).is_zero() ){
498 cout<<
"Aj*AzT=0"<<endl;
509 int generate(GF2mat P[],
int max_m,vector<int> dist,
char * folder_Cm){
519 GF2mat Cms[max_m*(max_m)];
521 for (
int i=2;i<max_m+1;i++){
524 for (
int j=0;j<i;j++){
525 Cms[(i-1)*max_m+j] = *(Cm1+j);
534 int main(
int args,
char ** argv){
542 char * folder_Cm =
"null";
545 char * title = argv[1];
547 double density = 0.5;
548 for (
int i =0;i<max_m;i++){
551 sprintf(pname,
"%s-P%d.mm",title,i+1);
554 px=5;py=px;density=3.5/py;
557 int condition_trials=50000;
558 for (
int j=0;j<condition_trials;j++){
566 int kappa=P[i].cols()-P[i].row_rank();
569 int delta_min = min(delta,delta_tilde);
570 if (delta<
INF &&delta_tilde<INF && kappa*delta_min >P[i].cols()){
571 cout<<
"condition satidfied when j = "<<j<<endl;
583 for (
int i =0;i<max_m;i++){
584 char * filename_Pi = argv[i+1];
586 cout<<
"P["<<i+1<<
"] "<<P[i]<<endl;