Substitution rule for sums of similar objects?

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











up vote
3
down vote

favorite












Consider objects like



obj= (Sum[Subscript[A, i], i, 1, 5] Sum[Subscript[A, i], i, 3, 6] Sum[Subscript[A, i], i, 2, 3])/(
Sum[Subscript[A, i], i, 3, 8] Sum[Subscript[A, i], i, 1, 2] Sum[Subscript[A, i], i, 4, 6])



enter image description here




I would like to have a substitution rule myRule that would perform the following replacement



obj /. myRule



enter image description here




for sequences of sums of $A_i$ of any lengths, and with indices not necessarily consecutive and not necessarily integer. How can this be done?










share|improve this question



























    up vote
    3
    down vote

    favorite












    Consider objects like



    obj= (Sum[Subscript[A, i], i, 1, 5] Sum[Subscript[A, i], i, 3, 6] Sum[Subscript[A, i], i, 2, 3])/(
    Sum[Subscript[A, i], i, 3, 8] Sum[Subscript[A, i], i, 1, 2] Sum[Subscript[A, i], i, 4, 6])



    enter image description here




    I would like to have a substitution rule myRule that would perform the following replacement



    obj /. myRule



    enter image description here




    for sequences of sums of $A_i$ of any lengths, and with indices not necessarily consecutive and not necessarily integer. How can this be done?










    share|improve this question

























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      Consider objects like



      obj= (Sum[Subscript[A, i], i, 1, 5] Sum[Subscript[A, i], i, 3, 6] Sum[Subscript[A, i], i, 2, 3])/(
      Sum[Subscript[A, i], i, 3, 8] Sum[Subscript[A, i], i, 1, 2] Sum[Subscript[A, i], i, 4, 6])



      enter image description here




      I would like to have a substitution rule myRule that would perform the following replacement



      obj /. myRule



      enter image description here




      for sequences of sums of $A_i$ of any lengths, and with indices not necessarily consecutive and not necessarily integer. How can this be done?










      share|improve this question















      Consider objects like



      obj= (Sum[Subscript[A, i], i, 1, 5] Sum[Subscript[A, i], i, 3, 6] Sum[Subscript[A, i], i, 2, 3])/(
      Sum[Subscript[A, i], i, 3, 8] Sum[Subscript[A, i], i, 1, 2] Sum[Subscript[A, i], i, 4, 6])



      enter image description here




      I would like to have a substitution rule myRule that would perform the following replacement



      obj /. myRule



      enter image description here




      for sequences of sums of $A_i$ of any lengths, and with indices not necessarily consecutive and not necessarily integer. How can this be done?







      function-construction pattern-matching replacement






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 hours ago









      xzczd

      24.9k466235




      24.9k466235










      asked 3 hours ago









      Kagaratsch

      4,42431246




      4,42431246




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          Try the following:



          obj /. HoldPattern@Plus@a : (h : Subscript)[A, _] .. :> h[A, ## & @@ Last /@ a]


          It can be even shorter:



          obj /. HoldPattern@+a : (h : Subscript)[A, _] .. :> h[A, ## & @@ Last /@ a]





          share|improve this answer





























            up vote
            1
            down vote













            Here's an alternative that will work with subscripted As that have more than one subscript, which may (or may not) be what you want:



            obj /. HoldPattern[Plus[seq : Subscript[A, __] ..]] :>
            Subscript[A, Sequence @@ Cases[seq, Subscript[A, inds__] :> inds]]





            share|improve this answer



























              up vote
              0
              down vote













              Block[Plus = (Subscript[#[[1]], ## & @@ ##[[All, -1]]] &), obj] // TeXForm



              $largefracA_2,3 A_3,4,5,6 A_1,2,3,4,5A_1,2 A_4,5,6 A_3,4,5,6,7,8$




              Alternatively,



              obj /. Plus -> (Subscript[#[[1]], ## & @@ ##[[All, -1]]] &) // TeXForm



              $largefracA_2,3 A_3,4,5,6 A_1,2,3,4,5A_1,2 A_4,5,6 A_3,4,5,6,7,8$







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



                );













                 

                draft saved


                draft discarded


















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184396%2fsubstitution-rule-for-sums-of-similar-objects%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
                3
                down vote



                accepted










                Try the following:



                obj /. HoldPattern@Plus@a : (h : Subscript)[A, _] .. :> h[A, ## & @@ Last /@ a]


                It can be even shorter:



                obj /. HoldPattern@+a : (h : Subscript)[A, _] .. :> h[A, ## & @@ Last /@ a]





                share|improve this answer


























                  up vote
                  3
                  down vote



                  accepted










                  Try the following:



                  obj /. HoldPattern@Plus@a : (h : Subscript)[A, _] .. :> h[A, ## & @@ Last /@ a]


                  It can be even shorter:



                  obj /. HoldPattern@+a : (h : Subscript)[A, _] .. :> h[A, ## & @@ Last /@ a]





                  share|improve this answer
























                    up vote
                    3
                    down vote



                    accepted







                    up vote
                    3
                    down vote



                    accepted






                    Try the following:



                    obj /. HoldPattern@Plus@a : (h : Subscript)[A, _] .. :> h[A, ## & @@ Last /@ a]


                    It can be even shorter:



                    obj /. HoldPattern@+a : (h : Subscript)[A, _] .. :> h[A, ## & @@ Last /@ a]





                    share|improve this answer














                    Try the following:



                    obj /. HoldPattern@Plus@a : (h : Subscript)[A, _] .. :> h[A, ## & @@ Last /@ a]


                    It can be even shorter:



                    obj /. HoldPattern@+a : (h : Subscript)[A, _] .. :> h[A, ## & @@ Last /@ a]






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 2 hours ago

























                    answered 3 hours ago









                    xzczd

                    24.9k466235




                    24.9k466235




















                        up vote
                        1
                        down vote













                        Here's an alternative that will work with subscripted As that have more than one subscript, which may (or may not) be what you want:



                        obj /. HoldPattern[Plus[seq : Subscript[A, __] ..]] :>
                        Subscript[A, Sequence @@ Cases[seq, Subscript[A, inds__] :> inds]]





                        share|improve this answer
























                          up vote
                          1
                          down vote













                          Here's an alternative that will work with subscripted As that have more than one subscript, which may (or may not) be what you want:



                          obj /. HoldPattern[Plus[seq : Subscript[A, __] ..]] :>
                          Subscript[A, Sequence @@ Cases[seq, Subscript[A, inds__] :> inds]]





                          share|improve this answer






















                            up vote
                            1
                            down vote










                            up vote
                            1
                            down vote









                            Here's an alternative that will work with subscripted As that have more than one subscript, which may (or may not) be what you want:



                            obj /. HoldPattern[Plus[seq : Subscript[A, __] ..]] :>
                            Subscript[A, Sequence @@ Cases[seq, Subscript[A, inds__] :> inds]]





                            share|improve this answer












                            Here's an alternative that will work with subscripted As that have more than one subscript, which may (or may not) be what you want:



                            obj /. HoldPattern[Plus[seq : Subscript[A, __] ..]] :>
                            Subscript[A, Sequence @@ Cases[seq, Subscript[A, inds__] :> inds]]






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 57 mins ago









                            Pillsy

                            12.5k13179




                            12.5k13179




















                                up vote
                                0
                                down vote













                                Block[Plus = (Subscript[#[[1]], ## & @@ ##[[All, -1]]] &), obj] // TeXForm



                                $largefracA_2,3 A_3,4,5,6 A_1,2,3,4,5A_1,2 A_4,5,6 A_3,4,5,6,7,8$




                                Alternatively,



                                obj /. Plus -> (Subscript[#[[1]], ## & @@ ##[[All, -1]]] &) // TeXForm



                                $largefracA_2,3 A_3,4,5,6 A_1,2,3,4,5A_1,2 A_4,5,6 A_3,4,5,6,7,8$







                                share|improve this answer
























                                  up vote
                                  0
                                  down vote













                                  Block[Plus = (Subscript[#[[1]], ## & @@ ##[[All, -1]]] &), obj] // TeXForm



                                  $largefracA_2,3 A_3,4,5,6 A_1,2,3,4,5A_1,2 A_4,5,6 A_3,4,5,6,7,8$




                                  Alternatively,



                                  obj /. Plus -> (Subscript[#[[1]], ## & @@ ##[[All, -1]]] &) // TeXForm



                                  $largefracA_2,3 A_3,4,5,6 A_1,2,3,4,5A_1,2 A_4,5,6 A_3,4,5,6,7,8$







                                  share|improve this answer






















                                    up vote
                                    0
                                    down vote










                                    up vote
                                    0
                                    down vote









                                    Block[Plus = (Subscript[#[[1]], ## & @@ ##[[All, -1]]] &), obj] // TeXForm



                                    $largefracA_2,3 A_3,4,5,6 A_1,2,3,4,5A_1,2 A_4,5,6 A_3,4,5,6,7,8$




                                    Alternatively,



                                    obj /. Plus -> (Subscript[#[[1]], ## & @@ ##[[All, -1]]] &) // TeXForm



                                    $largefracA_2,3 A_3,4,5,6 A_1,2,3,4,5A_1,2 A_4,5,6 A_3,4,5,6,7,8$







                                    share|improve this answer












                                    Block[Plus = (Subscript[#[[1]], ## & @@ ##[[All, -1]]] &), obj] // TeXForm



                                    $largefracA_2,3 A_3,4,5,6 A_1,2,3,4,5A_1,2 A_4,5,6 A_3,4,5,6,7,8$




                                    Alternatively,



                                    obj /. Plus -> (Subscript[#[[1]], ## & @@ ##[[All, -1]]] &) // TeXForm



                                    $largefracA_2,3 A_3,4,5,6 A_1,2,3,4,5A_1,2 A_4,5,6 A_3,4,5,6,7,8$








                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered 13 mins ago









                                    kglr

                                    167k8188390




                                    167k8188390



























                                         

                                        draft saved


                                        draft discarded















































                                         


                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184396%2fsubstitution-rule-for-sums-of-similar-objects%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