Algorithm for searching based on diagonal entries

V0  V1  V2  V3  V4  V5  V6  V7  V8  V9 

V0 1 1 1 0 0 0 0 0 0 0 V1 0 55 0 -1 -1 0 0 0 0 0 V2 0 0 5 0 0 1 1 0 0 0 V3 0 0 0 5 0 0 0 -1 0 0 V4 0 0 0 0 5 0 0 -1 0 0 V5 0 0 0 0 0 5 0 -1 1 0 V6 0 0 0 0 0 0 5 0 1 0 V7 0 0 0 0 0 0 0 5 0 -1 V8 0 0 0 0 0 0 0 0 55 -1 V9 0 0 0 0 0 0 0 0 0 5

I need an algorithm to display result like this: Subgraph1: V0,V1 Subgraph2: V2,V5,V6,V8 SubGraph3: V3,V4, V7, V9.

Multiplying N x N matrices using Diagonal storage

This question is a part of my research. I am trying to multiply two N X N matrices which are stored diagonally. I implemented the following algorithm for this purpose which is working correctly but the problem is it is taking way too much time. For example, To multiply 1000 x 1000 matrices, it is taking almost 26 minutes. I am giving an small example for better understanding of what I am trying to accomplish.

Matrix A = [ 1 2 3 4 ], Matrix B =[ 5 6 7 8], diagArrayA= [1 4 2 3] (Elements stored diagonally in the order main diagonal – super diagonal -sub diagonal), diagArrayB = [5 8 6 7] (Same as above),

Result = A X B = [ 19 50 22 43] (Correct output) The code for multiply function is followed: (The problem seems to be in this function). I will appreciate any comment on the problem/code.

void multiplyDiag(vector <float> diagArrayA, vector <float> diagArrayB){                cout << "function called " << endl;            //please declare as array             // float *a=cutDiagElement(getArray(diagArrayA,-1),0,0);          //   cout << "Value : " << a[0];         vector <float> result;         result.resize(n*n);       float total_time=0.0;       // const int sum=n*(n+1)/2; 

for(int k=0; k<=n-1;k++) { //1

             int start_index=k*n-k*(k-1)/2;               //cout << start_index;             //  int stop_index=start_index+n-k-1;            for(int i=k+1; i<=n-1; i++){ //2                  vector <float> diag_a1=cutDiagElement(getArray(diagArrayA,k-i),0,k);                 // cout << diag_a1[0] <<endl;                   vector <float> diag_b1=cutDiagElement(getArray(diagArrayB,i),0,0);                     int length1=diag_b1.size();                   //  int length1=n-i;                     // length1=length1-0-0;                   //cout << length1;                    float start1=clock();                   for(int j=0; j<=length1-1;j++)                       { //3                               //cout << "OK";                       result[start_index+i-k+j]+=diag_a1[j]*diag_b1[j];                          } //3                   float end1=clock();                   total_time=total_time+(end1-start1);                      vector <float> diag_a2=cutDiagElement(getArray(diagArrayA, i), 0, 0);                    vector <float> diag_b2= cutDiagElement(getArray(diagArrayB,k-i), k, 0);                    //  cout << diag_b2[0];                 //  int length2=diag_a2.size();                     float start2=clock();                    for(int j=0; j<=length1-1;j++)                        { //4                                 result[start_index+j]+=diag_a2[j]*diag_b2[j];                                //  cout<< multiply_result[start_index+j] << endl;                          }    //4                    float end2=clock();                  total_time=total_time+(end2-start2);          } //2     for(int i=0; i<=k; i++)      { //5              vector <float> diag_a3=cutDiagElement(getArray(diagArrayA, i), 0, k-i);                vector <float> diag_b3 = cutDiagElement(getArray(diagArrayB, k-i), i, 0);                int length3=diag_a3.size();              //   int length3=n-i;                //  length3=length3-(k-i);                float start3=clock();                  for(int j=0; j<=length3-1;j++){ //6                                             result[start_index+j]+=diag_a3[j]*diag_b3[j];                                               //cout<< multiply_result[start_index+j] << endl;                                }  //6             float end3=clock();           total_time=total_time+(end3-start3);       } //5 

}//1

// computing sub diagonal

for(int k=1; k<=n-1; k++) { //7

    int start_index=n*(n+1)/2+(k-1)*n-k*(k-1)/2;       // int stop_index=start_index+n-k-1;     for(int i=k+1; i<=n-1; i++)      { //8               vector <float> diag_a1=cutDiagElement(getArray(diagArrayA, -i), 0, 0);                vector <float> diag_b1= cutDiagElement(getArray(diagArrayB, i-k), 0, k);                int length1=diag_b1.size();               // int length1=n-(i-k);                 //   length1=length1-k;                float start4=clock();                for(int j=0; j<=length1-1;j++){ //9                            result[start_index+i+j-k]+=diag_a1[j]*diag_b1[j];                       } //9                  float end4=clock();                   total_time=total_time+(end4-start4);                   vector <float> diag_a2=cutDiagElement(getArray(diagArrayA, i-k), k, 0);                   vector <float> diag_b2= cutDiagElement(getArray(diagArrayB,-i), 0, 0);                 // int length2=diag_a2.size();                  float start5=clock();                   for(int j=0; j<=length1-1;j++)                            { //10                               result[start_index+j]+=diag_a2[j]*diag_b2[j];                            }//10                       float end5=clock();                 total_time=total_time+(end5-start5);        } //8     for(int i=0; i<=k; i++)                { //11                     vector <float> diag_a3=cutDiagElement(getArray(diagArrayA, -i), k-i, 0);                       vector <float> diag_b3 = cutDiagElement(getArray(diagArrayB, i-k), 0, i);                        int length3=diag_a3.size();                      //     int length3=n-i;                        //     length3=length3-(k-i);                      float start6=clock();                      for(int j=0; j<=length3-1;j++){ //12                                             result[start_index+j]+=diag_a3[j]*diag_b3[j];                                }  //12                    float end6=clock();                   total_time=total_time+(end6-start6);                   } //11 

} //7

cout << “time :” << (total_time) / CLOCKS_PER_SEC*1000 <

           cout << result[x] << endl;             } 

}

Multiplying N x N matrices using Diagonal storage

This question is a part of my research. I am trying to multiply two N X N matrices which are stored diagonally. I implemented the following algorithm for this purpose which is working correctly but the problem is it is taking way too much time. For example, To multiply 1000 x 1000 matrices, it is taking almost 26 minutes. I am giving an small example for better understanding of what I am trying to accomplish.

Matrix A = [ 1 2 3 4 ], Matrix B =[ 5 6 7 8], diagArrayA= [1 4 2 3] (Elements stored diagonally in the order main diagonal – super diagonal -sub diagonal), diagArrayB = [5 8 6 7] (Same as above),

Result = A X B = [ 19 50 22 43] (Correct output) The code for multiply function is followed: (The problem seems to be in this function). I will appreciate any comment on the problem/code.

void multiplyDiag(vector <float> diagArrayA, vector <float> diagArrayB){                cout << "function called " << endl;            //please declare as array             // float *a=cutDiagElement(getArray(diagArrayA,-1),0,0);          //   cout << "Value : " << a[0];         vector <float> result;         result.resize(n*n);       float total_time=0.0;       // const int sum=n*(n+1)/2; 

for(int k=0; k<=n-1;k++) { //1

             int start_index=k*n-k*(k-1)/2;               //cout << start_index;             //  int stop_index=start_index+n-k-1;            for(int i=k+1; i<=n-1; i++){ //2                  vector <float> diag_a1=cutDiagElement(getArray(diagArrayA,k-i),0,k);                 // cout << diag_a1[0] <<endl;                   vector <float> diag_b1=cutDiagElement(getArray(diagArrayB,i),0,0);                     int length1=diag_b1.size();                   //  int length1=n-i;                     // length1=length1-0-0;                   //cout << length1;                    float start1=clock();                   for(int j=0; j<=length1-1;j++)                       { //3                               //cout << "OK";                       result[start_index+i-k+j]+=diag_a1[j]*diag_b1[j];                          } //3                   float end1=clock();                   total_time=total_time+(end1-start1);                      vector <float> diag_a2=cutDiagElement(getArray(diagArrayA, i), 0, 0);                    vector <float> diag_b2= cutDiagElement(getArray(diagArrayB,k-i), k, 0);                    //  cout << diag_b2[0];                 //  int length2=diag_a2.size();                     float start2=clock();                    for(int j=0; j<=length1-1;j++)                        { //4                                 result[start_index+j]+=diag_a2[j]*diag_b2[j];                                //  cout<< multiply_result[start_index+j] << endl;                          }    //4                    float end2=clock();                  total_time=total_time+(end2-start2);          } //2     for(int i=0; i<=k; i++)      { //5              vector <float> diag_a3=cutDiagElement(getArray(diagArrayA, i), 0, k-i);                vector <float> diag_b3 = cutDiagElement(getArray(diagArrayB, k-i), i, 0);                int length3=diag_a3.size();              //   int length3=n-i;                //  length3=length3-(k-i);                float start3=clock();                  for(int j=0; j<=length3-1;j++){ //6                                             result[start_index+j]+=diag_a3[j]*diag_b3[j];                                               //cout<< multiply_result[start_index+j] << endl;                                }  //6             float end3=clock();           total_time=total_time+(end3-start3);       } //5 

}//1

// computing sub diagonal

for(int k=1; k<=n-1; k++) { //7

    int start_index=n*(n+1)/2+(k-1)*n-k*(k-1)/2;       // int stop_index=start_index+n-k-1;     for(int i=k+1; i<=n-1; i++)      { //8               vector <float> diag_a1=cutDiagElement(getArray(diagArrayA, -i), 0, 0);                vector <float> diag_b1= cutDiagElement(getArray(diagArrayB, i-k), 0, k);                int length1=diag_b1.size();               // int length1=n-(i-k);                 //   length1=length1-k;                float start4=clock();                for(int j=0; j<=length1-1;j++){ //9                            result[start_index+i+j-k]+=diag_a1[j]*diag_b1[j];                       } //9                  float end4=clock();                   total_time=total_time+(end4-start4);                   vector <float> diag_a2=cutDiagElement(getArray(diagArrayA, i-k), k, 0);                   vector <float> diag_b2= cutDiagElement(getArray(diagArrayB,-i), 0, 0);                 // int length2=diag_a2.size();                  float start5=clock();                   for(int j=0; j<=length1-1;j++)                            { //10                               result[start_index+j]+=diag_a2[j]*diag_b2[j];                            }//10                       float end5=clock();                 total_time=total_time+(end5-start5);        } //8     for(int i=0; i<=k; i++)                { //11                     vector <float> diag_a3=cutDiagElement(getArray(diagArrayA, -i), k-i, 0);                       vector <float> diag_b3 = cutDiagElement(getArray(diagArrayB, i-k), 0, i);                        int length3=diag_a3.size();                      //     int length3=n-i;                        //     length3=length3-(k-i);                      float start6=clock();                      for(int j=0; j<=length3-1;j++){ //12                                             result[start_index+j]+=diag_a3[j]*diag_b3[j];                                }  //12                    float end6=clock();                   total_time=total_time+(end6-start6);                   } //11 

} //7

cout << “time :” << (total_time) / CLOCKS_PER_SEC*1000 <

           cout << result[x] << endl;             } 

}

Multiplying N x N matrices using Diagonal storage

This question is a part of my research. I am trying to multiply two N X N matrices which are stored diagonally. I implemented the following algorithm for this purpose which is working correctly but the problem is it is taking way too much time. For example, To multiply 1000 x 1000 matrices, it is taking almost 26 minutes. I am giving an small example for better understanding of what I am trying to accomplish.

Matrix A = [ 1 2 3 4 ], Matrix B =[ 5 6 7 8], diagArrayA= [1 4 2 3] (Elements stored diagonally in the order main diagonal – super diagonal -sub diagonal), diagArrayB = [5 8 6 7] (Same as above),

Result = A X B = [ 19 50 22 43] (Correct output) The code for multiply function is followed: (The problem seems to be in this function). I will appreciate any comment on the problem/code.

void multiplyDiag(vector <float> diagArrayA, vector <float> diagArrayB){                cout << "function called " << endl;            //please declare as array             // float *a=cutDiagElement(getArray(diagArrayA,-1),0,0);          //   cout << "Value : " << a[0];         vector <float> result;         result.resize(n*n);       float total_time=0.0;       // const int sum=n*(n+1)/2; 

for(int k=0; k<=n-1;k++) { //1

             int start_index=k*n-k*(k-1)/2;               //cout << start_index;             //  int stop_index=start_index+n-k-1;            for(int i=k+1; i<=n-1; i++){ //2                  vector <float> diag_a1=cutDiagElement(getArray(diagArrayA,k-i),0,k);                 // cout << diag_a1[0] <<endl;                   vector <float> diag_b1=cutDiagElement(getArray(diagArrayB,i),0,0);                     int length1=diag_b1.size();                   //  int length1=n-i;                     // length1=length1-0-0;                   //cout << length1;                    float start1=clock();                   for(int j=0; j<=length1-1;j++)                       { //3                               //cout << "OK";                       result[start_index+i-k+j]+=diag_a1[j]*diag_b1[j];                          } //3                   float end1=clock();                   total_time=total_time+(end1-start1);                      vector <float> diag_a2=cutDiagElement(getArray(diagArrayA, i), 0, 0);                    vector <float> diag_b2= cutDiagElement(getArray(diagArrayB,k-i), k, 0);                    //  cout << diag_b2[0];                 //  int length2=diag_a2.size();                     float start2=clock();                    for(int j=0; j<=length1-1;j++)                        { //4                                 result[start_index+j]+=diag_a2[j]*diag_b2[j];                                //  cout<< multiply_result[start_index+j] << endl;                          }    //4                    float end2=clock();                  total_time=total_time+(end2-start2);          } //2     for(int i=0; i<=k; i++)      { //5              vector <float> diag_a3=cutDiagElement(getArray(diagArrayA, i), 0, k-i);                vector <float> diag_b3 = cutDiagElement(getArray(diagArrayB, k-i), i, 0);                int length3=diag_a3.size();              //   int length3=n-i;                //  length3=length3-(k-i);                float start3=clock();                  for(int j=0; j<=length3-1;j++){ //6                                             result[start_index+j]+=diag_a3[j]*diag_b3[j];                                               //cout<< multiply_result[start_index+j] << endl;                                }  //6             float end3=clock();           total_time=total_time+(end3-start3);       } //5 

}//1

// computing sub diagonal

for(int k=1; k<=n-1; k++) { //7

    int start_index=n*(n+1)/2+(k-1)*n-k*(k-1)/2;       // int stop_index=start_index+n-k-1;     for(int i=k+1; i<=n-1; i++)      { //8               vector <float> diag_a1=cutDiagElement(getArray(diagArrayA, -i), 0, 0);                vector <float> diag_b1= cutDiagElement(getArray(diagArrayB, i-k), 0, k);                int length1=diag_b1.size();               // int length1=n-(i-k);                 //   length1=length1-k;                float start4=clock();                for(int j=0; j<=length1-1;j++){ //9                            result[start_index+i+j-k]+=diag_a1[j]*diag_b1[j];                       } //9                  float end4=clock();                   total_time=total_time+(end4-start4);                   vector <float> diag_a2=cutDiagElement(getArray(diagArrayA, i-k), k, 0);                   vector <float> diag_b2= cutDiagElement(getArray(diagArrayB,-i), 0, 0);                 // int length2=diag_a2.size();                  float start5=clock();                   for(int j=0; j<=length1-1;j++)                            { //10                               result[start_index+j]+=diag_a2[j]*diag_b2[j];                            }//10                       float end5=clock();                 total_time=total_time+(end5-start5);        } //8     for(int i=0; i<=k; i++)                { //11                     vector <float> diag_a3=cutDiagElement(getArray(diagArrayA, -i), k-i, 0);                       vector <float> diag_b3 = cutDiagElement(getArray(diagArrayB, i-k), 0, i);                        int length3=diag_a3.size();                      //     int length3=n-i;                        //     length3=length3-(k-i);                      float start6=clock();                      for(int j=0; j<=length3-1;j++){ //12                                             result[start_index+j]+=diag_a3[j]*diag_b3[j];                                }  //12                    float end6=clock();                   total_time=total_time+(end6-start6);                   } //11 

} //7

cout << “time :” << (total_time) / CLOCKS_PER_SEC*1000 <

           cout << result[x] << endl;             } 

}

spectral sequence example diagonal map confusion

I’m attempting to wrap my head around spectral sequences, so constructed a really basic example to apply the definitions and go through the motions. My filtered chain complexes are:

$ F_2C_*: 0 \rightarrow \mathbb{Z} \xrightarrow{i_1} \mathbb{Z_1}\oplus \mathbb{Z_2} \xrightarrow{p_2} \mathbb{Z} \rightarrow 0 $

$ F_1C_*: 0 \rightarrow 0 \rightarrow \mathbb{Z}_2 \xrightarrow{p_2} \mathbb{Z} \rightarrow 0 $

$ F_0C_*:$ The zero complex.

Here $ i_1$ and $ p_2$ are the inclusion and projection maps, and the sub-indices on the $ \mathbb{Z}s$ are just for labeling purposes.

With $ Z^r_{p,q}$ defined as $ \{x \in F_pC_q : \partial x \in F_{p-r}C_{q-1}\}/F_{p-1}C_q$ , the differential is meant to restrict to well-defined maps $ d^r:Z^r_{p,q} \rightarrow Z^r_{p-r,q-1}$ .

But in my example the map $ Z^1_{2,2} \rightarrow Z^1_{1,1}$ does not appear to be well-defined:

$ Z^1_{2,2} := \{x \in \mathbb{Z}\oplus \mathbb{Z} : p_2 x \in \mathbb{Z} \}/\mathbb{Z}_2 \cong \mathbb{Z}_1$ ,

$ Z^1_{1,1} := \mathbb{Z}$ .

However $ [(a,b)]$ and $ [(a,b’)]$ in $ Z^1_{2,2}$ get sent to $ b$ and $ b’$ in $ \mathbb{Z}$ respectively, even though $ [(a,b)] = [(a,b’)]$ .

I cannot see where I’ve made a mistake, but I’m pretty sure something’s not right. Where have I gone wrong?

About a “modification” of the diagonal language $\{w_i \mid \text{Every turing machine } M_1 \ldots M_i \text{ reject } w_i\}$

I have given the seeming modification of the diagonal language $ \{w_i \mid \text{Every turing machine } M_1 \ldots M_i \text{ rejects } w_i\}$ , yet I can’t prove that it is undecidable.

My thoughts so far:

  • This language is intuitively undecidable, but it might trick you into thinking that it is, and it is in fact decidable: At last there exists an $ i$ from which $ M_i = M^*$ where $ M^*$ rejects every word $ w$

  • I can’t directly reduce this to the diagonal language

  • I can’t build a halting problem solving machine on this if I can’t define my enumeration of $ w_i$ and $ M_i$ freely, which I can’t (and is that even right?).

A nice tip would be helpful. Thanks 🙂

Block Diagonal Matrix

I have a problem in transforming a matrix to block diagonal matrix. My matrix is like:

\begin{array}{cccc} a & b & c & 0 \ b & 0 & 0 & c \ c & 0 & 0 & b \ 0 & c & b & a \ \end{array}

I want to make a block diagonal matrix by using Kronecker product and the other process related matrices.

\begin{array}{cc} A & 0 \ 0 & B \ \end{array}

where A and B are the 2*2 matrices.

Thanks