Cleanest way to take a[b[c]] to a[b][c]












2












$begingroup$


As indicated in the title I'm looking for the fastest way to transform a[b[c]] into a[b][c], and the natural generalization to an arbitrary chaining of arguments. I'm sure there's got to be a convenient way that I've overlooked.



In my cases a, b, and c can be any expression with any complicated internal structure they like.










share|improve this question











$endgroup$








  • 1




    $begingroup$
    The solution likely would use Operate.
    $endgroup$
    – QuantumDot
    48 mins ago










  • $begingroup$
    f = Curry[Replace][a_[b_[c_]] :> a[b][c]] also works, so that a[b[c]] // f gives the desired result.
    $endgroup$
    – Shredderroy
    39 mins ago










  • $begingroup$
    How about generalizing the question to taking a[b[c[d[...]]]] to a[b][c][d]...?
    $endgroup$
    – David G. Stork
    27 mins ago












  • $begingroup$
    @DavidG.Stork sorry I thought that was implicit
    $endgroup$
    – b3m2a1
    22 mins ago










  • $begingroup$
    @b3m2a1: Oh.... well I recommend you alter the question... and seem my new solution.
    $endgroup$
    – David G. Stork
    19 mins ago
















2












$begingroup$


As indicated in the title I'm looking for the fastest way to transform a[b[c]] into a[b][c], and the natural generalization to an arbitrary chaining of arguments. I'm sure there's got to be a convenient way that I've overlooked.



In my cases a, b, and c can be any expression with any complicated internal structure they like.










share|improve this question











$endgroup$








  • 1




    $begingroup$
    The solution likely would use Operate.
    $endgroup$
    – QuantumDot
    48 mins ago










  • $begingroup$
    f = Curry[Replace][a_[b_[c_]] :> a[b][c]] also works, so that a[b[c]] // f gives the desired result.
    $endgroup$
    – Shredderroy
    39 mins ago










  • $begingroup$
    How about generalizing the question to taking a[b[c[d[...]]]] to a[b][c][d]...?
    $endgroup$
    – David G. Stork
    27 mins ago












  • $begingroup$
    @DavidG.Stork sorry I thought that was implicit
    $endgroup$
    – b3m2a1
    22 mins ago










  • $begingroup$
    @b3m2a1: Oh.... well I recommend you alter the question... and seem my new solution.
    $endgroup$
    – David G. Stork
    19 mins ago














2












2








2





$begingroup$


As indicated in the title I'm looking for the fastest way to transform a[b[c]] into a[b][c], and the natural generalization to an arbitrary chaining of arguments. I'm sure there's got to be a convenient way that I've overlooked.



In my cases a, b, and c can be any expression with any complicated internal structure they like.










share|improve this question











$endgroup$




As indicated in the title I'm looking for the fastest way to transform a[b[c]] into a[b][c], and the natural generalization to an arbitrary chaining of arguments. I'm sure there's got to be a convenient way that I've overlooked.



In my cases a, b, and c can be any expression with any complicated internal structure they like.







function-construction






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 14 mins ago









David G. Stork

24.1k22153




24.1k22153










asked 1 hour ago









b3m2a1b3m2a1

27.2k257156




27.2k257156








  • 1




    $begingroup$
    The solution likely would use Operate.
    $endgroup$
    – QuantumDot
    48 mins ago










  • $begingroup$
    f = Curry[Replace][a_[b_[c_]] :> a[b][c]] also works, so that a[b[c]] // f gives the desired result.
    $endgroup$
    – Shredderroy
    39 mins ago










  • $begingroup$
    How about generalizing the question to taking a[b[c[d[...]]]] to a[b][c][d]...?
    $endgroup$
    – David G. Stork
    27 mins ago












  • $begingroup$
    @DavidG.Stork sorry I thought that was implicit
    $endgroup$
    – b3m2a1
    22 mins ago










  • $begingroup$
    @b3m2a1: Oh.... well I recommend you alter the question... and seem my new solution.
    $endgroup$
    – David G. Stork
    19 mins ago














  • 1




    $begingroup$
    The solution likely would use Operate.
    $endgroup$
    – QuantumDot
    48 mins ago










  • $begingroup$
    f = Curry[Replace][a_[b_[c_]] :> a[b][c]] also works, so that a[b[c]] // f gives the desired result.
    $endgroup$
    – Shredderroy
    39 mins ago










  • $begingroup$
    How about generalizing the question to taking a[b[c[d[...]]]] to a[b][c][d]...?
    $endgroup$
    – David G. Stork
    27 mins ago












  • $begingroup$
    @DavidG.Stork sorry I thought that was implicit
    $endgroup$
    – b3m2a1
    22 mins ago










  • $begingroup$
    @b3m2a1: Oh.... well I recommend you alter the question... and seem my new solution.
    $endgroup$
    – David G. Stork
    19 mins ago








1




1




$begingroup$
The solution likely would use Operate.
$endgroup$
– QuantumDot
48 mins ago




$begingroup$
The solution likely would use Operate.
$endgroup$
– QuantumDot
48 mins ago












$begingroup$
f = Curry[Replace][a_[b_[c_]] :> a[b][c]] also works, so that a[b[c]] // f gives the desired result.
$endgroup$
– Shredderroy
39 mins ago




$begingroup$
f = Curry[Replace][a_[b_[c_]] :> a[b][c]] also works, so that a[b[c]] // f gives the desired result.
$endgroup$
– Shredderroy
39 mins ago












$begingroup$
How about generalizing the question to taking a[b[c[d[...]]]] to a[b][c][d]...?
$endgroup$
– David G. Stork
27 mins ago






$begingroup$
How about generalizing the question to taking a[b[c[d[...]]]] to a[b][c][d]...?
$endgroup$
– David G. Stork
27 mins ago














$begingroup$
@DavidG.Stork sorry I thought that was implicit
$endgroup$
– b3m2a1
22 mins ago




$begingroup$
@DavidG.Stork sorry I thought that was implicit
$endgroup$
– b3m2a1
22 mins ago












$begingroup$
@b3m2a1: Oh.... well I recommend you alter the question... and seem my new solution.
$endgroup$
– David G. Stork
19 mins ago




$begingroup$
@b3m2a1: Oh.... well I recommend you alter the question... and seem my new solution.
$endgroup$
– David G. Stork
19 mins ago










2 Answers
2






active

oldest

votes


















2












$begingroup$

Operate[#[[0]], First@#] &[a[b[c]]]



a[b][c]




ClearAll[deCompose]
deCompose = Nest[Operate[#[[0]], First@#] &, #, Depth[#] - 2] &;

deCompose@a[b[c]]



a[b][c]




exp = Compose[a, b, c, d, e, f, g]



a[b[c[d[e[f[g]]]]]]




deCompose @ exp



a[b][c][d][e][f][g]







share|improve this answer











$endgroup$





















    2












    $begingroup$

    Not particularly "clean," but it works:



    Operate[Head[#], Level[#, 2][[2]]] & @ a[b[c]]


    For the full generalization:



    Nest[Operate[Head[#], Level[#, 2][[2]]] & , #, Depth[#] -2] & @
    a[b[c[d[e]]]]





    share|improve this answer











    $endgroup$













      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',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      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%2f190047%2fcleanest-way-to-take-abc-to-abc%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2












      $begingroup$

      Operate[#[[0]], First@#] &[a[b[c]]]



      a[b][c]




      ClearAll[deCompose]
      deCompose = Nest[Operate[#[[0]], First@#] &, #, Depth[#] - 2] &;

      deCompose@a[b[c]]



      a[b][c]




      exp = Compose[a, b, c, d, e, f, g]



      a[b[c[d[e[f[g]]]]]]




      deCompose @ exp



      a[b][c][d][e][f][g]







      share|improve this answer











      $endgroup$


















        2












        $begingroup$

        Operate[#[[0]], First@#] &[a[b[c]]]



        a[b][c]




        ClearAll[deCompose]
        deCompose = Nest[Operate[#[[0]], First@#] &, #, Depth[#] - 2] &;

        deCompose@a[b[c]]



        a[b][c]




        exp = Compose[a, b, c, d, e, f, g]



        a[b[c[d[e[f[g]]]]]]




        deCompose @ exp



        a[b][c][d][e][f][g]







        share|improve this answer











        $endgroup$
















          2












          2








          2





          $begingroup$

          Operate[#[[0]], First@#] &[a[b[c]]]



          a[b][c]




          ClearAll[deCompose]
          deCompose = Nest[Operate[#[[0]], First@#] &, #, Depth[#] - 2] &;

          deCompose@a[b[c]]



          a[b][c]




          exp = Compose[a, b, c, d, e, f, g]



          a[b[c[d[e[f[g]]]]]]




          deCompose @ exp



          a[b][c][d][e][f][g]







          share|improve this answer











          $endgroup$



          Operate[#[[0]], First@#] &[a[b[c]]]



          a[b][c]




          ClearAll[deCompose]
          deCompose = Nest[Operate[#[[0]], First@#] &, #, Depth[#] - 2] &;

          deCompose@a[b[c]]



          a[b][c]




          exp = Compose[a, b, c, d, e, f, g]



          a[b[c[d[e[f[g]]]]]]




          deCompose @ exp



          a[b][c][d][e][f][g]








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 15 mins ago

























          answered 23 mins ago









          kglrkglr

          180k9200413




          180k9200413























              2












              $begingroup$

              Not particularly "clean," but it works:



              Operate[Head[#], Level[#, 2][[2]]] & @ a[b[c]]


              For the full generalization:



              Nest[Operate[Head[#], Level[#, 2][[2]]] & , #, Depth[#] -2] & @
              a[b[c[d[e]]]]





              share|improve this answer











              $endgroup$


















                2












                $begingroup$

                Not particularly "clean," but it works:



                Operate[Head[#], Level[#, 2][[2]]] & @ a[b[c]]


                For the full generalization:



                Nest[Operate[Head[#], Level[#, 2][[2]]] & , #, Depth[#] -2] & @
                a[b[c[d[e]]]]





                share|improve this answer











                $endgroup$
















                  2












                  2








                  2





                  $begingroup$

                  Not particularly "clean," but it works:



                  Operate[Head[#], Level[#, 2][[2]]] & @ a[b[c]]


                  For the full generalization:



                  Nest[Operate[Head[#], Level[#, 2][[2]]] & , #, Depth[#] -2] & @
                  a[b[c[d[e]]]]





                  share|improve this answer











                  $endgroup$



                  Not particularly "clean," but it works:



                  Operate[Head[#], Level[#, 2][[2]]] & @ a[b[c]]


                  For the full generalization:



                  Nest[Operate[Head[#], Level[#, 2][[2]]] & , #, Depth[#] -2] & @
                  a[b[c[d[e]]]]






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 14 mins ago

























                  answered 39 mins ago









                  David G. StorkDavid G. Stork

                  24.1k22153




                  24.1k22153






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Mathematica Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      Use MathJax to format equations. MathJax reference.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f190047%2fcleanest-way-to-take-abc-to-abc%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Ponta tanko

                      Tantalo (mitologio)

                      Erzsébet Schaár