Wrestling with substitution rules











up vote
2
down vote

favorite












Summary



I am struggling with substitution rules.



Example



Here are several cases which are problematic:



Clear[a,α];
{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2} /. {a + b -> α}


Actual result:



{1 + a + 2 b, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}


Desired result:



{1 + α +  b, -α, 2 α, α^2}


Question



Currently, the rule is permuted for every case, e.g.



2 a + 2 b -> 2α


Can the alpha substitution rule be generalized That, is there a single rule to handle all cases?










share|improve this question




















  • 2




    You mean: "One to rule them all"? ;)
    – Henrik Schumacher
    Nov 4 at 18:38








  • 1




    Use PolynomialReduce to obtain algebraic "substitutions". In[208]:= PolynomialReduce[{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}, a + b - alpha, {a, b}][[All, 2]] Out[208]= {1 + alpha + b, -alpha, 2 alpha, alpha^2}
    – Daniel Lichtblau
    Nov 4 at 19:14






  • 1




    Generally, to apply a relationship broadly, write the corresponding rule such that the LHS of the rule is as simple as possible, e.g., solution posted by @HenrikSchumacher. Since rules are applied to the structure of the internal (FullForm) representation, this will result in the highest number of matches with the LHS.
    – Bob Hanlon
    Nov 4 at 19:38















up vote
2
down vote

favorite












Summary



I am struggling with substitution rules.



Example



Here are several cases which are problematic:



Clear[a,α];
{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2} /. {a + b -> α}


Actual result:



{1 + a + 2 b, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}


Desired result:



{1 + α +  b, -α, 2 α, α^2}


Question



Currently, the rule is permuted for every case, e.g.



2 a + 2 b -> 2α


Can the alpha substitution rule be generalized That, is there a single rule to handle all cases?










share|improve this question




















  • 2




    You mean: "One to rule them all"? ;)
    – Henrik Schumacher
    Nov 4 at 18:38








  • 1




    Use PolynomialReduce to obtain algebraic "substitutions". In[208]:= PolynomialReduce[{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}, a + b - alpha, {a, b}][[All, 2]] Out[208]= {1 + alpha + b, -alpha, 2 alpha, alpha^2}
    – Daniel Lichtblau
    Nov 4 at 19:14






  • 1




    Generally, to apply a relationship broadly, write the corresponding rule such that the LHS of the rule is as simple as possible, e.g., solution posted by @HenrikSchumacher. Since rules are applied to the structure of the internal (FullForm) representation, this will result in the highest number of matches with the LHS.
    – Bob Hanlon
    Nov 4 at 19:38













up vote
2
down vote

favorite









up vote
2
down vote

favorite











Summary



I am struggling with substitution rules.



Example



Here are several cases which are problematic:



Clear[a,α];
{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2} /. {a + b -> α}


Actual result:



{1 + a + 2 b, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}


Desired result:



{1 + α +  b, -α, 2 α, α^2}


Question



Currently, the rule is permuted for every case, e.g.



2 a + 2 b -> 2α


Can the alpha substitution rule be generalized That, is there a single rule to handle all cases?










share|improve this question















Summary



I am struggling with substitution rules.



Example



Here are several cases which are problematic:



Clear[a,α];
{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2} /. {a + b -> α}


Actual result:



{1 + a + 2 b, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}


Desired result:



{1 + α +  b, -α, 2 α, α^2}


Question



Currently, the rule is permuted for every case, e.g.



2 a + 2 b -> 2α


Can the alpha substitution rule be generalized That, is there a single rule to handle all cases?







replacement rule






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 4 at 18:35









Henrik Schumacher

44.1k263129




44.1k263129










asked Nov 4 at 18:34









dantopa

47428




47428








  • 2




    You mean: "One to rule them all"? ;)
    – Henrik Schumacher
    Nov 4 at 18:38








  • 1




    Use PolynomialReduce to obtain algebraic "substitutions". In[208]:= PolynomialReduce[{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}, a + b - alpha, {a, b}][[All, 2]] Out[208]= {1 + alpha + b, -alpha, 2 alpha, alpha^2}
    – Daniel Lichtblau
    Nov 4 at 19:14






  • 1




    Generally, to apply a relationship broadly, write the corresponding rule such that the LHS of the rule is as simple as possible, e.g., solution posted by @HenrikSchumacher. Since rules are applied to the structure of the internal (FullForm) representation, this will result in the highest number of matches with the LHS.
    – Bob Hanlon
    Nov 4 at 19:38














  • 2




    You mean: "One to rule them all"? ;)
    – Henrik Schumacher
    Nov 4 at 18:38








  • 1




    Use PolynomialReduce to obtain algebraic "substitutions". In[208]:= PolynomialReduce[{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}, a + b - alpha, {a, b}][[All, 2]] Out[208]= {1 + alpha + b, -alpha, 2 alpha, alpha^2}
    – Daniel Lichtblau
    Nov 4 at 19:14






  • 1




    Generally, to apply a relationship broadly, write the corresponding rule such that the LHS of the rule is as simple as possible, e.g., solution posted by @HenrikSchumacher. Since rules are applied to the structure of the internal (FullForm) representation, this will result in the highest number of matches with the LHS.
    – Bob Hanlon
    Nov 4 at 19:38








2




2




You mean: "One to rule them all"? ;)
– Henrik Schumacher
Nov 4 at 18:38






You mean: "One to rule them all"? ;)
– Henrik Schumacher
Nov 4 at 18:38






1




1




Use PolynomialReduce to obtain algebraic "substitutions". In[208]:= PolynomialReduce[{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}, a + b - alpha, {a, b}][[All, 2]] Out[208]= {1 + alpha + b, -alpha, 2 alpha, alpha^2}
– Daniel Lichtblau
Nov 4 at 19:14




Use PolynomialReduce to obtain algebraic "substitutions". In[208]:= PolynomialReduce[{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2}, a + b - alpha, {a, b}][[All, 2]] Out[208]= {1 + alpha + b, -alpha, 2 alpha, alpha^2}
– Daniel Lichtblau
Nov 4 at 19:14




1




1




Generally, to apply a relationship broadly, write the corresponding rule such that the LHS of the rule is as simple as possible, e.g., solution posted by @HenrikSchumacher. Since rules are applied to the structure of the internal (FullForm) representation, this will result in the highest number of matches with the LHS.
– Bob Hanlon
Nov 4 at 19:38




Generally, to apply a relationship broadly, write the corresponding rule such that the LHS of the rule is as simple as possible, e.g., solution posted by @HenrikSchumacher. Since rules are applied to the structure of the internal (FullForm) representation, this will result in the highest number of matches with the LHS.
– Bob Hanlon
Nov 4 at 19:38










2 Answers
2






active

oldest

votes

















up vote
6
down vote













{a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2} /. {a -> α - b} // Simplify



{1 + b + α, -α, 2 α, α^2}







share|improve this answer




























    up vote
    5
    down vote













    Also



    Simplify[{a + 2 b + 1, -a - b, 2 a + 2 b,  a^2 + 2 a b + b^2}, {a + b == α}]



    {1 + b + α, -α, 2 α, α^2}







    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: 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%2f185287%2fwrestling-with-substitution-rules%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
      6
      down vote













      {a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2} /. {a -> α - b} // Simplify



      {1 + b + α, -α, 2 α, α^2}







      share|improve this answer

























        up vote
        6
        down vote













        {a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2} /. {a -> α - b} // Simplify



        {1 + b + α, -α, 2 α, α^2}







        share|improve this answer























          up vote
          6
          down vote










          up vote
          6
          down vote









          {a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2} /. {a -> α - b} // Simplify



          {1 + b + α, -α, 2 α, α^2}







          share|improve this answer












          {a + 2 b + 1, -a - b, 2 a + 2 b, a^2 + 2 a b + b^2} /. {a -> α - b} // Simplify



          {1 + b + α, -α, 2 α, α^2}








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 4 at 18:37









          Henrik Schumacher

          44.1k263129




          44.1k263129






















              up vote
              5
              down vote













              Also



              Simplify[{a + 2 b + 1, -a - b, 2 a + 2 b,  a^2 + 2 a b + b^2}, {a + b == α}]



              {1 + b + α, -α, 2 α, α^2}







              share|improve this answer

























                up vote
                5
                down vote













                Also



                Simplify[{a + 2 b + 1, -a - b, 2 a + 2 b,  a^2 + 2 a b + b^2}, {a + b == α}]



                {1 + b + α, -α, 2 α, α^2}







                share|improve this answer























                  up vote
                  5
                  down vote










                  up vote
                  5
                  down vote









                  Also



                  Simplify[{a + 2 b + 1, -a - b, 2 a + 2 b,  a^2 + 2 a b + b^2}, {a + b == α}]



                  {1 + b + α, -α, 2 α, α^2}







                  share|improve this answer












                  Also



                  Simplify[{a + 2 b + 1, -a - b, 2 a + 2 b,  a^2 + 2 a b + b^2}, {a + b == α}]



                  {1 + b + α, -α, 2 α, α^2}








                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 4 at 19:18









                  kglr

                  170k8193396




                  170k8193396






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f185287%2fwrestling-with-substitution-rules%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest




















































































                      這個網誌中的熱門文章

                      Xamarin.form Move up view when keyboard appear

                      Post-Redirect-Get with Spring WebFlux and Thymeleaf

                      Anylogic : not able to use stopDelay()