nested commutators

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 defined the commutator between two matrices as



comm[A_,B_]:=A.B-B.A


I have defined the nested commutator as



nestcomm[A_,B_,n_]:= ToExpression[ 
StringRepeat["comm[a,", n] <> "b" <> StringRepeat["]", n]
]


where $n$ indicates how many time the commutator must be nested.



Does exists a more simple way to define an $n$-time nested operation between two elements $A$ and $B$? I tried to use the Nest function but without success.










share|improve this question

























    up vote
    1
    down vote

    favorite












    I have defined the commutator between two matrices as



    comm[A_,B_]:=A.B-B.A


    I have defined the nested commutator as



    nestcomm[A_,B_,n_]:= ToExpression[ 
    StringRepeat["comm[a,", n] <> "b" <> StringRepeat["]", n]
    ]


    where $n$ indicates how many time the commutator must be nested.



    Does exists a more simple way to define an $n$-time nested operation between two elements $A$ and $B$? I tried to use the Nest function but without success.










    share|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have defined the commutator between two matrices as



      comm[A_,B_]:=A.B-B.A


      I have defined the nested commutator as



      nestcomm[A_,B_,n_]:= ToExpression[ 
      StringRepeat["comm[a,", n] <> "b" <> StringRepeat["]", n]
      ]


      where $n$ indicates how many time the commutator must be nested.



      Does exists a more simple way to define an $n$-time nested operation between two elements $A$ and $B$? I tried to use the Nest function but without success.










      share|improve this question













      I have defined the commutator between two matrices as



      comm[A_,B_]:=A.B-B.A


      I have defined the nested commutator as



      nestcomm[A_,B_,n_]:= ToExpression[ 
      StringRepeat["comm[a,", n] <> "b" <> StringRepeat["]", n]
      ]


      where $n$ indicates how many time the commutator must be nested.



      Does exists a more simple way to define an $n$-time nested operation between two elements $A$ and $B$? I tried to use the Nest function but without success.







      nest






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 5 hours ago









      Galuoises

      1887




      1887




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          Redefine your comm function to take in and put out a pair of matrices, then Nest can be called easily:



          comm[A_, B_] := A, A.B - B.A


          Then just invoke Nest with the number of terms in the final position. For n=2:



          Rest[Nest[comm, a, b, 2]]
          a.(a.b - b.a) - (a.b - b.a).a





          share|improve this answer




















          • Thank you for your help!
            – Galuoises
            6 mins ago

















          up vote
          2
          down vote













          Would something like the following work?



          comm[A_,B_,1] := A.B-B.A
          comm[A_, B_, n_Integer?Positive] := comm[comm[A, B, n-1], B, 1]


          For example:



          comm[A, B, 2] //TensorExpand
          comm[A, B, 3] //TensorExpand



          A.B.B - 2 B.A.B + B.B.A



          A.B.B.B - 3 B.A.B.B + 3 B.B.A.B - B.B.B.A




          Use:



          comm[A_, B_, n_Integer?Positive] := comm[A, comm[A, B, n-1], 1]


          to obtain the same definition as in @bill's answer.






          share|improve this answer




















          • Thank you! I appreciate your answer
            – Galuoises
            7 mins ago










          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
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184631%2fnested-commutators%23new-answer', 'question_page');

          );

          Post as a guest






























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          4
          down vote



          accepted










          Redefine your comm function to take in and put out a pair of matrices, then Nest can be called easily:



          comm[A_, B_] := A, A.B - B.A


          Then just invoke Nest with the number of terms in the final position. For n=2:



          Rest[Nest[comm, a, b, 2]]
          a.(a.b - b.a) - (a.b - b.a).a





          share|improve this answer




















          • Thank you for your help!
            – Galuoises
            6 mins ago














          up vote
          4
          down vote



          accepted










          Redefine your comm function to take in and put out a pair of matrices, then Nest can be called easily:



          comm[A_, B_] := A, A.B - B.A


          Then just invoke Nest with the number of terms in the final position. For n=2:



          Rest[Nest[comm, a, b, 2]]
          a.(a.b - b.a) - (a.b - b.a).a





          share|improve this answer




















          • Thank you for your help!
            – Galuoises
            6 mins ago












          up vote
          4
          down vote



          accepted







          up vote
          4
          down vote



          accepted






          Redefine your comm function to take in and put out a pair of matrices, then Nest can be called easily:



          comm[A_, B_] := A, A.B - B.A


          Then just invoke Nest with the number of terms in the final position. For n=2:



          Rest[Nest[comm, a, b, 2]]
          a.(a.b - b.a) - (a.b - b.a).a





          share|improve this answer












          Redefine your comm function to take in and put out a pair of matrices, then Nest can be called easily:



          comm[A_, B_] := A, A.B - B.A


          Then just invoke Nest with the number of terms in the final position. For n=2:



          Rest[Nest[comm, a, b, 2]]
          a.(a.b - b.a) - (a.b - b.a).a






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 5 hours ago









          bill s

          51.8k375146




          51.8k375146











          • Thank you for your help!
            – Galuoises
            6 mins ago
















          • Thank you for your help!
            – Galuoises
            6 mins ago















          Thank you for your help!
          – Galuoises
          6 mins ago




          Thank you for your help!
          – Galuoises
          6 mins ago










          up vote
          2
          down vote













          Would something like the following work?



          comm[A_,B_,1] := A.B-B.A
          comm[A_, B_, n_Integer?Positive] := comm[comm[A, B, n-1], B, 1]


          For example:



          comm[A, B, 2] //TensorExpand
          comm[A, B, 3] //TensorExpand



          A.B.B - 2 B.A.B + B.B.A



          A.B.B.B - 3 B.A.B.B + 3 B.B.A.B - B.B.B.A




          Use:



          comm[A_, B_, n_Integer?Positive] := comm[A, comm[A, B, n-1], 1]


          to obtain the same definition as in @bill's answer.






          share|improve this answer




















          • Thank you! I appreciate your answer
            – Galuoises
            7 mins ago














          up vote
          2
          down vote













          Would something like the following work?



          comm[A_,B_,1] := A.B-B.A
          comm[A_, B_, n_Integer?Positive] := comm[comm[A, B, n-1], B, 1]


          For example:



          comm[A, B, 2] //TensorExpand
          comm[A, B, 3] //TensorExpand



          A.B.B - 2 B.A.B + B.B.A



          A.B.B.B - 3 B.A.B.B + 3 B.B.A.B - B.B.B.A




          Use:



          comm[A_, B_, n_Integer?Positive] := comm[A, comm[A, B, n-1], 1]


          to obtain the same definition as in @bill's answer.






          share|improve this answer




















          • Thank you! I appreciate your answer
            – Galuoises
            7 mins ago












          up vote
          2
          down vote










          up vote
          2
          down vote









          Would something like the following work?



          comm[A_,B_,1] := A.B-B.A
          comm[A_, B_, n_Integer?Positive] := comm[comm[A, B, n-1], B, 1]


          For example:



          comm[A, B, 2] //TensorExpand
          comm[A, B, 3] //TensorExpand



          A.B.B - 2 B.A.B + B.B.A



          A.B.B.B - 3 B.A.B.B + 3 B.B.A.B - B.B.B.A




          Use:



          comm[A_, B_, n_Integer?Positive] := comm[A, comm[A, B, n-1], 1]


          to obtain the same definition as in @bill's answer.






          share|improve this answer












          Would something like the following work?



          comm[A_,B_,1] := A.B-B.A
          comm[A_, B_, n_Integer?Positive] := comm[comm[A, B, n-1], B, 1]


          For example:



          comm[A, B, 2] //TensorExpand
          comm[A, B, 3] //TensorExpand



          A.B.B - 2 B.A.B + B.B.A



          A.B.B.B - 3 B.A.B.B + 3 B.B.A.B - B.B.B.A




          Use:



          comm[A_, B_, n_Integer?Positive] := comm[A, comm[A, B, n-1], 1]


          to obtain the same definition as in @bill's answer.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 5 hours ago









          Carl Woll

          62.4k281158




          62.4k281158











          • Thank you! I appreciate your answer
            – Galuoises
            7 mins ago
















          • Thank you! I appreciate your answer
            – Galuoises
            7 mins ago















          Thank you! I appreciate your answer
          – Galuoises
          7 mins ago




          Thank you! I appreciate your answer
          – Galuoises
          7 mins ago

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184631%2fnested-commutators%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          What does second last employer means? [closed]

          Installing NextGIS Connect into QGIS 3?

          One-line joke