“Smart” substitution of subexpressions












3














I have the following question.



An expression, which I want to simplify contains several subexpressions which appear quite frequently all over the place. To optimize simplification I would like to use abbreviations for some of them. Is there any way to do it in a "smart" way, i.e. to account for subexpressions which differ only by sign/multiplication by a number or a variable? Here is an example to illustrate what I mean.



For example, the adverted subexpression is:



-a^2 + b^2/(c^2 - d^2)


and I want to use variable A1 everywhere instead it:



-a^2 + b^2/(c^2 - d^2) -> A1


Now, I want Mathematica to substitute the expressions which are essentially equal to this one, but are simply written in another form like:



-a^2 - b^2/(d^2 - c^2)
-a^2 + (-b^2/(d^2 - c^2))


Also it would be great to use this rule for expressions like



-2*a^2 + 2*b^2/(c^2 - d^2) (*2*A1*)


or



a^2 - b^2/(c^2 - d^2) (*-A1*)


or even



-x*a^2 + x*b^2/(c^2 - d^2) (*x*A1*)


Is there a way to do it?










share|improve this question





























    3














    I have the following question.



    An expression, which I want to simplify contains several subexpressions which appear quite frequently all over the place. To optimize simplification I would like to use abbreviations for some of them. Is there any way to do it in a "smart" way, i.e. to account for subexpressions which differ only by sign/multiplication by a number or a variable? Here is an example to illustrate what I mean.



    For example, the adverted subexpression is:



    -a^2 + b^2/(c^2 - d^2)


    and I want to use variable A1 everywhere instead it:



    -a^2 + b^2/(c^2 - d^2) -> A1


    Now, I want Mathematica to substitute the expressions which are essentially equal to this one, but are simply written in another form like:



    -a^2 - b^2/(d^2 - c^2)
    -a^2 + (-b^2/(d^2 - c^2))


    Also it would be great to use this rule for expressions like



    -2*a^2 + 2*b^2/(c^2 - d^2) (*2*A1*)


    or



    a^2 - b^2/(c^2 - d^2) (*-A1*)


    or even



    -x*a^2 + x*b^2/(c^2 - d^2) (*x*A1*)


    Is there a way to do it?










    share|improve this question



























      3












      3








      3







      I have the following question.



      An expression, which I want to simplify contains several subexpressions which appear quite frequently all over the place. To optimize simplification I would like to use abbreviations for some of them. Is there any way to do it in a "smart" way, i.e. to account for subexpressions which differ only by sign/multiplication by a number or a variable? Here is an example to illustrate what I mean.



      For example, the adverted subexpression is:



      -a^2 + b^2/(c^2 - d^2)


      and I want to use variable A1 everywhere instead it:



      -a^2 + b^2/(c^2 - d^2) -> A1


      Now, I want Mathematica to substitute the expressions which are essentially equal to this one, but are simply written in another form like:



      -a^2 - b^2/(d^2 - c^2)
      -a^2 + (-b^2/(d^2 - c^2))


      Also it would be great to use this rule for expressions like



      -2*a^2 + 2*b^2/(c^2 - d^2) (*2*A1*)


      or



      a^2 - b^2/(c^2 - d^2) (*-A1*)


      or even



      -x*a^2 + x*b^2/(c^2 - d^2) (*x*A1*)


      Is there a way to do it?










      share|improve this question















      I have the following question.



      An expression, which I want to simplify contains several subexpressions which appear quite frequently all over the place. To optimize simplification I would like to use abbreviations for some of them. Is there any way to do it in a "smart" way, i.e. to account for subexpressions which differ only by sign/multiplication by a number or a variable? Here is an example to illustrate what I mean.



      For example, the adverted subexpression is:



      -a^2 + b^2/(c^2 - d^2)


      and I want to use variable A1 everywhere instead it:



      -a^2 + b^2/(c^2 - d^2) -> A1


      Now, I want Mathematica to substitute the expressions which are essentially equal to this one, but are simply written in another form like:



      -a^2 - b^2/(d^2 - c^2)
      -a^2 + (-b^2/(d^2 - c^2))


      Also it would be great to use this rule for expressions like



      -2*a^2 + 2*b^2/(c^2 - d^2) (*2*A1*)


      or



      a^2 - b^2/(c^2 - d^2) (*-A1*)


      or even



      -x*a^2 + x*b^2/(c^2 - d^2) (*x*A1*)


      Is there a way to do it?







      simplifying-expressions replacement semantic-matching






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 hours ago









      xzczd

      25.9k469246




      25.9k469246










      asked 3 hours ago









      user43283

      1533




      1533






















          1 Answer
          1






          active

          oldest

          votes


















          4














          Short version :



          When one wants to do f[a+b] /. a+b->c, it is often more efficient to write f[a+b] /. a-> c-b and simplify the result ( with Simplify, Expand...).



          Long version :



          You can apply the rule b -> -Sqrt[a^2 + A1] Sqrt[c^2 - d^2] (equivalent to -a^2 + b^2/(c^2 - d^2) -> A1) and afterward try to simplify.



          In fact, your example is a little bit more complex because there are to possible rules b-> Sqrt[...] and b-> -Sqrt[...], but it works fine :



          rule = Solve[-a^2 + b^2/(c^2 - d^2) == A1, b]

          transfomation[x_] := x /. rule // ExpandAll // Together

          -a^2 - b^2/(d^2 - c^2) // transfomation
          -a^2 + (-b^2/(d^2 - c^2)) // transfomation
          -2*a^2 + 2*b^2/(c^2 - d^2) (*2*A1*) // transfomation
          a^2 - b^2/(c^2 - d^2) (*-A1*)// transfomation
          -x*a^2 + x*b^2/(c^2 - d^2) (*x*A1*) // transfomation



          {{b -> -Sqrt[a^2 + A1] Sqrt[c^2 - d^2]}, {b -> Sqrt[a^2 + A1]
          Sqrt[c^2 - d^2]}}



          {A1, A1}



          {A1, A1}



          {2 A1, 2 A1}



          {-A1, -A1}



          {A1 x, A1 x}







          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',
            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%2f188876%2fsmart-substitution-of-subexpressions%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            4














            Short version :



            When one wants to do f[a+b] /. a+b->c, it is often more efficient to write f[a+b] /. a-> c-b and simplify the result ( with Simplify, Expand...).



            Long version :



            You can apply the rule b -> -Sqrt[a^2 + A1] Sqrt[c^2 - d^2] (equivalent to -a^2 + b^2/(c^2 - d^2) -> A1) and afterward try to simplify.



            In fact, your example is a little bit more complex because there are to possible rules b-> Sqrt[...] and b-> -Sqrt[...], but it works fine :



            rule = Solve[-a^2 + b^2/(c^2 - d^2) == A1, b]

            transfomation[x_] := x /. rule // ExpandAll // Together

            -a^2 - b^2/(d^2 - c^2) // transfomation
            -a^2 + (-b^2/(d^2 - c^2)) // transfomation
            -2*a^2 + 2*b^2/(c^2 - d^2) (*2*A1*) // transfomation
            a^2 - b^2/(c^2 - d^2) (*-A1*)// transfomation
            -x*a^2 + x*b^2/(c^2 - d^2) (*x*A1*) // transfomation



            {{b -> -Sqrt[a^2 + A1] Sqrt[c^2 - d^2]}, {b -> Sqrt[a^2 + A1]
            Sqrt[c^2 - d^2]}}



            {A1, A1}



            {A1, A1}



            {2 A1, 2 A1}



            {-A1, -A1}



            {A1 x, A1 x}







            share|improve this answer




























              4














              Short version :



              When one wants to do f[a+b] /. a+b->c, it is often more efficient to write f[a+b] /. a-> c-b and simplify the result ( with Simplify, Expand...).



              Long version :



              You can apply the rule b -> -Sqrt[a^2 + A1] Sqrt[c^2 - d^2] (equivalent to -a^2 + b^2/(c^2 - d^2) -> A1) and afterward try to simplify.



              In fact, your example is a little bit more complex because there are to possible rules b-> Sqrt[...] and b-> -Sqrt[...], but it works fine :



              rule = Solve[-a^2 + b^2/(c^2 - d^2) == A1, b]

              transfomation[x_] := x /. rule // ExpandAll // Together

              -a^2 - b^2/(d^2 - c^2) // transfomation
              -a^2 + (-b^2/(d^2 - c^2)) // transfomation
              -2*a^2 + 2*b^2/(c^2 - d^2) (*2*A1*) // transfomation
              a^2 - b^2/(c^2 - d^2) (*-A1*)// transfomation
              -x*a^2 + x*b^2/(c^2 - d^2) (*x*A1*) // transfomation



              {{b -> -Sqrt[a^2 + A1] Sqrt[c^2 - d^2]}, {b -> Sqrt[a^2 + A1]
              Sqrt[c^2 - d^2]}}



              {A1, A1}



              {A1, A1}



              {2 A1, 2 A1}



              {-A1, -A1}



              {A1 x, A1 x}







              share|improve this answer


























                4












                4








                4






                Short version :



                When one wants to do f[a+b] /. a+b->c, it is often more efficient to write f[a+b] /. a-> c-b and simplify the result ( with Simplify, Expand...).



                Long version :



                You can apply the rule b -> -Sqrt[a^2 + A1] Sqrt[c^2 - d^2] (equivalent to -a^2 + b^2/(c^2 - d^2) -> A1) and afterward try to simplify.



                In fact, your example is a little bit more complex because there are to possible rules b-> Sqrt[...] and b-> -Sqrt[...], but it works fine :



                rule = Solve[-a^2 + b^2/(c^2 - d^2) == A1, b]

                transfomation[x_] := x /. rule // ExpandAll // Together

                -a^2 - b^2/(d^2 - c^2) // transfomation
                -a^2 + (-b^2/(d^2 - c^2)) // transfomation
                -2*a^2 + 2*b^2/(c^2 - d^2) (*2*A1*) // transfomation
                a^2 - b^2/(c^2 - d^2) (*-A1*)// transfomation
                -x*a^2 + x*b^2/(c^2 - d^2) (*x*A1*) // transfomation



                {{b -> -Sqrt[a^2 + A1] Sqrt[c^2 - d^2]}, {b -> Sqrt[a^2 + A1]
                Sqrt[c^2 - d^2]}}



                {A1, A1}



                {A1, A1}



                {2 A1, 2 A1}



                {-A1, -A1}



                {A1 x, A1 x}







                share|improve this answer














                Short version :



                When one wants to do f[a+b] /. a+b->c, it is often more efficient to write f[a+b] /. a-> c-b and simplify the result ( with Simplify, Expand...).



                Long version :



                You can apply the rule b -> -Sqrt[a^2 + A1] Sqrt[c^2 - d^2] (equivalent to -a^2 + b^2/(c^2 - d^2) -> A1) and afterward try to simplify.



                In fact, your example is a little bit more complex because there are to possible rules b-> Sqrt[...] and b-> -Sqrt[...], but it works fine :



                rule = Solve[-a^2 + b^2/(c^2 - d^2) == A1, b]

                transfomation[x_] := x /. rule // ExpandAll // Together

                -a^2 - b^2/(d^2 - c^2) // transfomation
                -a^2 + (-b^2/(d^2 - c^2)) // transfomation
                -2*a^2 + 2*b^2/(c^2 - d^2) (*2*A1*) // transfomation
                a^2 - b^2/(c^2 - d^2) (*-A1*)// transfomation
                -x*a^2 + x*b^2/(c^2 - d^2) (*x*A1*) // transfomation



                {{b -> -Sqrt[a^2 + A1] Sqrt[c^2 - d^2]}, {b -> Sqrt[a^2 + A1]
                Sqrt[c^2 - d^2]}}



                {A1, A1}



                {A1, A1}



                {2 A1, 2 A1}



                {-A1, -A1}



                {A1 x, A1 x}








                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 2 hours ago

























                answered 2 hours ago









                andre314

                11.8k12249




                11.8k12249






























                    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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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.


                    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%2f188876%2fsmart-substitution-of-subexpressions%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

                    CARDNET

                    Boot-repair Failure: Unable to locate package grub-common:i386

                    濃尾地震