Need to find matrix formulation

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I have a $B$ matrix: $B = B_ij$



I need to find closed matrix formulation of:



$$sum_i sum_j sum_m sum_n B_ij B_jm B_mn B_ni$$



But I am so confused!



Edit by Henrik:



Originally, it was asked to express



$$sum_i sum_j sum_m sum_n B_mi B_mj B_ni B_nj$$



in terms of matrices.










share|improve this question









New contributor




farhadpti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • I formatted the math using Mathjax. Please check if I introduced any errors.
    – Johu
    7 hours ago










  • This site is about Mathematica, the software. Should we move your question over to Mathematics?
    – Johu
    7 hours ago











  • Could you also check, if you have not made any mistakes with the indexes.
    – Johu
    7 hours ago










  • @DavidG.Stork I am not sure whether your edit was meaningfull. By swapping some of the indices, you actually changed the question dramatically. For example, Louis' (imho correct) answer became invalid under this modification.
    – Henrik Schumacher
    31 mins ago











  • @LouisB I'd suggest to undelete your post. Imho, it is a perfect answer to the original question.
    – Henrik Schumacher
    19 mins ago














up vote
1
down vote

favorite












I have a $B$ matrix: $B = B_ij$



I need to find closed matrix formulation of:



$$sum_i sum_j sum_m sum_n B_ij B_jm B_mn B_ni$$



But I am so confused!



Edit by Henrik:



Originally, it was asked to express



$$sum_i sum_j sum_m sum_n B_mi B_mj B_ni B_nj$$



in terms of matrices.










share|improve this question









New contributor




farhadpti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • I formatted the math using Mathjax. Please check if I introduced any errors.
    – Johu
    7 hours ago










  • This site is about Mathematica, the software. Should we move your question over to Mathematics?
    – Johu
    7 hours ago











  • Could you also check, if you have not made any mistakes with the indexes.
    – Johu
    7 hours ago










  • @DavidG.Stork I am not sure whether your edit was meaningfull. By swapping some of the indices, you actually changed the question dramatically. For example, Louis' (imho correct) answer became invalid under this modification.
    – Henrik Schumacher
    31 mins ago











  • @LouisB I'd suggest to undelete your post. Imho, it is a perfect answer to the original question.
    – Henrik Schumacher
    19 mins ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have a $B$ matrix: $B = B_ij$



I need to find closed matrix formulation of:



$$sum_i sum_j sum_m sum_n B_ij B_jm B_mn B_ni$$



But I am so confused!



Edit by Henrik:



Originally, it was asked to express



$$sum_i sum_j sum_m sum_n B_mi B_mj B_ni B_nj$$



in terms of matrices.










share|improve this question









New contributor




farhadpti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I have a $B$ matrix: $B = B_ij$



I need to find closed matrix formulation of:



$$sum_i sum_j sum_m sum_n B_ij B_jm B_mn B_ni$$



But I am so confused!



Edit by Henrik:



Originally, it was asked to express



$$sum_i sum_j sum_m sum_n B_mi B_mj B_ni B_nj$$



in terms of matrices.







matrix algebra






share|improve this question









New contributor




farhadpti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




farhadpti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 25 mins ago









Henrik Schumacher

38.8k254114




38.8k254114






New contributor




farhadpti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 7 hours ago









farhadpti

61




61




New contributor




farhadpti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





farhadpti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






farhadpti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • I formatted the math using Mathjax. Please check if I introduced any errors.
    – Johu
    7 hours ago










  • This site is about Mathematica, the software. Should we move your question over to Mathematics?
    – Johu
    7 hours ago











  • Could you also check, if you have not made any mistakes with the indexes.
    – Johu
    7 hours ago










  • @DavidG.Stork I am not sure whether your edit was meaningfull. By swapping some of the indices, you actually changed the question dramatically. For example, Louis' (imho correct) answer became invalid under this modification.
    – Henrik Schumacher
    31 mins ago











  • @LouisB I'd suggest to undelete your post. Imho, it is a perfect answer to the original question.
    – Henrik Schumacher
    19 mins ago
















  • I formatted the math using Mathjax. Please check if I introduced any errors.
    – Johu
    7 hours ago










  • This site is about Mathematica, the software. Should we move your question over to Mathematics?
    – Johu
    7 hours ago











  • Could you also check, if you have not made any mistakes with the indexes.
    – Johu
    7 hours ago










  • @DavidG.Stork I am not sure whether your edit was meaningfull. By swapping some of the indices, you actually changed the question dramatically. For example, Louis' (imho correct) answer became invalid under this modification.
    – Henrik Schumacher
    31 mins ago











  • @LouisB I'd suggest to undelete your post. Imho, it is a perfect answer to the original question.
    – Henrik Schumacher
    19 mins ago















I formatted the math using Mathjax. Please check if I introduced any errors.
– Johu
7 hours ago




I formatted the math using Mathjax. Please check if I introduced any errors.
– Johu
7 hours ago












This site is about Mathematica, the software. Should we move your question over to Mathematics?
– Johu
7 hours ago





This site is about Mathematica, the software. Should we move your question over to Mathematics?
– Johu
7 hours ago













Could you also check, if you have not made any mistakes with the indexes.
– Johu
7 hours ago




Could you also check, if you have not made any mistakes with the indexes.
– Johu
7 hours ago












@DavidG.Stork I am not sure whether your edit was meaningfull. By swapping some of the indices, you actually changed the question dramatically. For example, Louis' (imho correct) answer became invalid under this modification.
– Henrik Schumacher
31 mins ago





@DavidG.Stork I am not sure whether your edit was meaningfull. By swapping some of the indices, you actually changed the question dramatically. For example, Louis' (imho correct) answer became invalid under this modification.
– Henrik Schumacher
31 mins ago













@LouisB I'd suggest to undelete your post. Imho, it is a perfect answer to the original question.
– Henrik Schumacher
19 mins ago




@LouisB I'd suggest to undelete your post. Imho, it is a perfect answer to the original question.
– Henrik Schumacher
19 mins ago










3 Answers
3






active

oldest

votes

















up vote
4
down vote













If this is indeed a Mathematica question, then first note that:



$$sum _j B_i,j B_j,kequiv (B.B)_i,j$$



and



$$sum _i B_i,iequiv operatornameTr[B]$$



So, the Mathematica equivalent of:



$$sum _i sum _j sum _m sum _n B_i,j B_j,m B_m,n B_n,i $$



is:



Tr[B . B . B . B]


or:



Tr[MatrixPower[B, 4]]


For the original form of the question, note that:



$$ B_i,jequiv B^T_j,i $$



So, the Mathematica equivalent of:



$$sum _i sum _j sum _k sum _l B_m,i B_m,j B_n,i B_n,j$$



is:



Tr[B.Transpose[B].B.Transpose[B]]





share|improve this answer



























    up vote
    1
    down vote













    This is a closed matrix formulation of $B^4$.






    share|improve this answer
















    • 2




      It's the trace of $B^4$, no?
      – LouisB
      6 hours ago

















    up vote
    0
    down vote













    Carl's answer is perfect as it is. His use of MatrixPower inspired me to think a little about computational complexity: Matrix-matrix multiplication has complexity $O(n^3)$ (in the straight-forward implementations, not these theoretically fancy but practically irrelevant algorithms). If we can get rid of one or two of them, we can even afford a transposition to speed up the computation:



    n = 5000;
    B = RandomReal[-1, 1, n, n];
    a = Tr[B.B.B.B]; // RepeatedTiming // First
    b = Tr[MatrixPower[B, 4]]; // RepeatedTiming // First
    c = With[A = B.B, Total[A Transpose[A], 2]]; // RepeatedTiming // First
    a == b == c



    5.7



    4.207



    2.5



    True




    For the original question, LouisB's answer (c below) seems to be both correct and efficient:



    n = 5000;
    B = RandomReal[-1, 1, n, n];
    a = Tr[B.Transpose[B].B.Transpose[B]]; // RepeatedTiming // First
    b = With[u = Flatten[B.Transpose[B]], u.u]; // RepeatedTiming // First
    c = Total[(Transpose[B].B)^2, 2]; // RepeatedTiming // First
    a == b == c



    5.8



    2.4



    2.40



    True







    share|improve this answer






















      Your Answer




      StackExchange.ifUsing("editor", function ()
      return StackExchange.using("mathjaxEditing", function ()
      StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
      StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
      );
      );
      , "mathjax-editing");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "387"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );






      farhadpti is a new contributor. Be nice, and check out our Code of Conduct.









       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f182391%2fneed-to-find-matrix-formulation%23new-answer', 'question_page');

      );

      Post as a guest






























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      4
      down vote













      If this is indeed a Mathematica question, then first note that:



      $$sum _j B_i,j B_j,kequiv (B.B)_i,j$$



      and



      $$sum _i B_i,iequiv operatornameTr[B]$$



      So, the Mathematica equivalent of:



      $$sum _i sum _j sum _m sum _n B_i,j B_j,m B_m,n B_n,i $$



      is:



      Tr[B . B . B . B]


      or:



      Tr[MatrixPower[B, 4]]


      For the original form of the question, note that:



      $$ B_i,jequiv B^T_j,i $$



      So, the Mathematica equivalent of:



      $$sum _i sum _j sum _k sum _l B_m,i B_m,j B_n,i B_n,j$$



      is:



      Tr[B.Transpose[B].B.Transpose[B]]





      share|improve this answer
























        up vote
        4
        down vote













        If this is indeed a Mathematica question, then first note that:



        $$sum _j B_i,j B_j,kequiv (B.B)_i,j$$



        and



        $$sum _i B_i,iequiv operatornameTr[B]$$



        So, the Mathematica equivalent of:



        $$sum _i sum _j sum _m sum _n B_i,j B_j,m B_m,n B_n,i $$



        is:



        Tr[B . B . B . B]


        or:



        Tr[MatrixPower[B, 4]]


        For the original form of the question, note that:



        $$ B_i,jequiv B^T_j,i $$



        So, the Mathematica equivalent of:



        $$sum _i sum _j sum _k sum _l B_m,i B_m,j B_n,i B_n,j$$



        is:



        Tr[B.Transpose[B].B.Transpose[B]]





        share|improve this answer






















          up vote
          4
          down vote










          up vote
          4
          down vote









          If this is indeed a Mathematica question, then first note that:



          $$sum _j B_i,j B_j,kequiv (B.B)_i,j$$



          and



          $$sum _i B_i,iequiv operatornameTr[B]$$



          So, the Mathematica equivalent of:



          $$sum _i sum _j sum _m sum _n B_i,j B_j,m B_m,n B_n,i $$



          is:



          Tr[B . B . B . B]


          or:



          Tr[MatrixPower[B, 4]]


          For the original form of the question, note that:



          $$ B_i,jequiv B^T_j,i $$



          So, the Mathematica equivalent of:



          $$sum _i sum _j sum _k sum _l B_m,i B_m,j B_n,i B_n,j$$



          is:



          Tr[B.Transpose[B].B.Transpose[B]]





          share|improve this answer












          If this is indeed a Mathematica question, then first note that:



          $$sum _j B_i,j B_j,kequiv (B.B)_i,j$$



          and



          $$sum _i B_i,iequiv operatornameTr[B]$$



          So, the Mathematica equivalent of:



          $$sum _i sum _j sum _m sum _n B_i,j B_j,m B_m,n B_n,i $$



          is:



          Tr[B . B . B . B]


          or:



          Tr[MatrixPower[B, 4]]


          For the original form of the question, note that:



          $$ B_i,jequiv B^T_j,i $$



          So, the Mathematica equivalent of:



          $$sum _i sum _j sum _k sum _l B_m,i B_m,j B_n,i B_n,j$$



          is:



          Tr[B.Transpose[B].B.Transpose[B]]






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 5 hours ago









          Carl Woll

          58.1k274150




          58.1k274150




















              up vote
              1
              down vote













              This is a closed matrix formulation of $B^4$.






              share|improve this answer
















              • 2




                It's the trace of $B^4$, no?
                – LouisB
                6 hours ago














              up vote
              1
              down vote













              This is a closed matrix formulation of $B^4$.






              share|improve this answer
















              • 2




                It's the trace of $B^4$, no?
                – LouisB
                6 hours ago












              up vote
              1
              down vote










              up vote
              1
              down vote









              This is a closed matrix formulation of $B^4$.






              share|improve this answer












              This is a closed matrix formulation of $B^4$.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered 7 hours ago









              David G. Stork

              21.5k11646




              21.5k11646







              • 2




                It's the trace of $B^4$, no?
                – LouisB
                6 hours ago












              • 2




                It's the trace of $B^4$, no?
                – LouisB
                6 hours ago







              2




              2




              It's the trace of $B^4$, no?
              – LouisB
              6 hours ago




              It's the trace of $B^4$, no?
              – LouisB
              6 hours ago










              up vote
              0
              down vote













              Carl's answer is perfect as it is. His use of MatrixPower inspired me to think a little about computational complexity: Matrix-matrix multiplication has complexity $O(n^3)$ (in the straight-forward implementations, not these theoretically fancy but practically irrelevant algorithms). If we can get rid of one or two of them, we can even afford a transposition to speed up the computation:



              n = 5000;
              B = RandomReal[-1, 1, n, n];
              a = Tr[B.B.B.B]; // RepeatedTiming // First
              b = Tr[MatrixPower[B, 4]]; // RepeatedTiming // First
              c = With[A = B.B, Total[A Transpose[A], 2]]; // RepeatedTiming // First
              a == b == c



              5.7



              4.207



              2.5



              True




              For the original question, LouisB's answer (c below) seems to be both correct and efficient:



              n = 5000;
              B = RandomReal[-1, 1, n, n];
              a = Tr[B.Transpose[B].B.Transpose[B]]; // RepeatedTiming // First
              b = With[u = Flatten[B.Transpose[B]], u.u]; // RepeatedTiming // First
              c = Total[(Transpose[B].B)^2, 2]; // RepeatedTiming // First
              a == b == c



              5.8



              2.4



              2.40



              True







              share|improve this answer


























                up vote
                0
                down vote













                Carl's answer is perfect as it is. His use of MatrixPower inspired me to think a little about computational complexity: Matrix-matrix multiplication has complexity $O(n^3)$ (in the straight-forward implementations, not these theoretically fancy but practically irrelevant algorithms). If we can get rid of one or two of them, we can even afford a transposition to speed up the computation:



                n = 5000;
                B = RandomReal[-1, 1, n, n];
                a = Tr[B.B.B.B]; // RepeatedTiming // First
                b = Tr[MatrixPower[B, 4]]; // RepeatedTiming // First
                c = With[A = B.B, Total[A Transpose[A], 2]]; // RepeatedTiming // First
                a == b == c



                5.7



                4.207



                2.5



                True




                For the original question, LouisB's answer (c below) seems to be both correct and efficient:



                n = 5000;
                B = RandomReal[-1, 1, n, n];
                a = Tr[B.Transpose[B].B.Transpose[B]]; // RepeatedTiming // First
                b = With[u = Flatten[B.Transpose[B]], u.u]; // RepeatedTiming // First
                c = Total[(Transpose[B].B)^2, 2]; // RepeatedTiming // First
                a == b == c



                5.8



                2.4



                2.40



                True







                share|improve this answer
























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Carl's answer is perfect as it is. His use of MatrixPower inspired me to think a little about computational complexity: Matrix-matrix multiplication has complexity $O(n^3)$ (in the straight-forward implementations, not these theoretically fancy but practically irrelevant algorithms). If we can get rid of one or two of them, we can even afford a transposition to speed up the computation:



                  n = 5000;
                  B = RandomReal[-1, 1, n, n];
                  a = Tr[B.B.B.B]; // RepeatedTiming // First
                  b = Tr[MatrixPower[B, 4]]; // RepeatedTiming // First
                  c = With[A = B.B, Total[A Transpose[A], 2]]; // RepeatedTiming // First
                  a == b == c



                  5.7



                  4.207



                  2.5



                  True




                  For the original question, LouisB's answer (c below) seems to be both correct and efficient:



                  n = 5000;
                  B = RandomReal[-1, 1, n, n];
                  a = Tr[B.Transpose[B].B.Transpose[B]]; // RepeatedTiming // First
                  b = With[u = Flatten[B.Transpose[B]], u.u]; // RepeatedTiming // First
                  c = Total[(Transpose[B].B)^2, 2]; // RepeatedTiming // First
                  a == b == c



                  5.8



                  2.4



                  2.40



                  True







                  share|improve this answer














                  Carl's answer is perfect as it is. His use of MatrixPower inspired me to think a little about computational complexity: Matrix-matrix multiplication has complexity $O(n^3)$ (in the straight-forward implementations, not these theoretically fancy but practically irrelevant algorithms). If we can get rid of one or two of them, we can even afford a transposition to speed up the computation:



                  n = 5000;
                  B = RandomReal[-1, 1, n, n];
                  a = Tr[B.B.B.B]; // RepeatedTiming // First
                  b = Tr[MatrixPower[B, 4]]; // RepeatedTiming // First
                  c = With[A = B.B, Total[A Transpose[A], 2]]; // RepeatedTiming // First
                  a == b == c



                  5.7



                  4.207



                  2.5



                  True




                  For the original question, LouisB's answer (c below) seems to be both correct and efficient:



                  n = 5000;
                  B = RandomReal[-1, 1, n, n];
                  a = Tr[B.Transpose[B].B.Transpose[B]]; // RepeatedTiming // First
                  b = With[u = Flatten[B.Transpose[B]], u.u]; // RepeatedTiming // First
                  c = Total[(Transpose[B].B)^2, 2]; // RepeatedTiming // First
                  a == b == c



                  5.8



                  2.4



                  2.40



                  True








                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 21 mins ago

























                  answered 34 mins ago









                  Henrik Schumacher

                  38.8k254114




                  38.8k254114




















                      farhadpti is a new contributor. Be nice, and check out our Code of Conduct.









                       

                      draft saved


                      draft discarded


















                      farhadpti is a new contributor. Be nice, and check out our Code of Conduct.












                      farhadpti is a new contributor. Be nice, and check out our Code of Conduct.











                      farhadpti is a new contributor. Be nice, and check out our Code of Conduct.













                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f182391%2fneed-to-find-matrix-formulation%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Comments

                      Popular posts from this blog

                      What does second last employer means? [closed]

                      List of Gilmore Girls characters

                      Confectionery