Combining pure functions containing compound expressions












2














Background



For display purposes, I sometimes find it desirable to defeat Mathematica's canonical ordering of variables, and instead have it output terms in the order in which I type them. E.g., instead of this:



b-a
v=v0+a t
a8+a9+a10



–a + b



a t + v0



a10 + a8 + a9




...I'd prefer this:




b – a



v0 + a t



a8 + a9 + a10




This can be easily accomplished by removing the Orderless attributes from Plus and Times, entering the expression, and then immediately restoring those attributes (it is important to do the latter, since their absence alters basic functionality; e.g., without Orderless, Plus doesn't recognize that a + b is mathematically identical to b + a).



ClearAttributes[Plus, Orderless]
ClearAttributes[Times, Orderless]
e1=c (b-a)
SetAttributes[Plus, Orderless]
SetAttributes[Times, Orderless]



c (b – a)




Question



How do I implement the above as a function? I.e., I'd like to define a function such that:



e1=func[c (b-a)]
e2=c (b-a) (*confirm that Orderless is restored to both Plus and Times*)
e1==e2 (*check that functionality isn't affected by how function is displayed; want output to be "True"*)



c (b – a)



(–a + b) c



True




EDIT: Note that I want to alter only the display format, not any other functionality. E.g., MMA should still recognize that e1 and e2 are mathematically equivalent, even though e1 was defined while the Orderless Attribute was absent from both Plus and Times.



Thus far I've only managed the following, which achieves the desired output, but requires I enter a function, then the expression, then another function:



func1 := (ClearAttributes[Plus, Orderless]; ClearAttributes[Times, Orderless]) &;
func2 := (SetAttributes[Plus, Orderless]; SetAttributes[Times, Orderless]) &;
func1[_]
e1=c (b-a)
func2[_]
e2=c (b-a)
e1==e2



c (b – a)



(–a + b) c



True




So how do I combine the above into a single function that takes the expression as its argument? Or, to put it another way, how do I turn the following pseudocode into working MMA syntax?:



func := (ClearAttributes[Plus, Orderless]; 
ClearAttributes[Times, Orderless]; #;
SetAttributes[Plus, Orderless];
SetAttributes[Times, Orderless]) &;
func[c (b-a)]



(no output)




The above function gives no output because pure functions, by default, only return the result of the last statement. I could get output by moving # to the end, as follows, but that just causes it to return the argument with standard canonical ordering, since here # is evaluated after the Orderless Attributes are restored:



func := (ClearAttributes[Plus, Orderless]; 
ClearAttributes[Times, Orderless];
SetAttributes[Plus, Orderless];
SetAttributes[Times, Orderless];#) &;
func[c (b-a)]



(-a+b) c




Granted, one workaround might be to use a DownValues construction for the last statement, since that could step backwards and get # in its earlier (non-canonical) format, and output it. But it would be much more straightforward if I could just tell the function to output whatever intermediate result I wished.



Finally, if I abandon pure functions, I could do this, but it doesn't fully work because the output of Print is Null:



SetAttributes[f, HoldAll]
f[expr_] :=
Module[{}, ClearAttributes[Plus, Orderless];
ClearAttributes[Times, Orderless];
Print[expr];
SetAttributes[Plus, Orderless]; SetAttributes[Times, Orderless]]
e1 = f[c (b - a)]
e2 = c (b - a)
e1 == e2



c (b-a)



(-a + b) c



Null == (-a + b) c




So it would be nice if there were a simple way to get a function (both pure and otherwise) comprising a compound expression to return an assignable non-Null intermediate result (without exiting, which is what Return would do), which is something I could apply to other problems as well. I.e., I sometimes need MMA to 'do X, then do Y and return the result, then do Z', so seeing how it's done for this application would serve as a template that I could use elsewhere. I found this thread: Compound Statements and returning earlier results in () parentheses, but wasn't able to apply it to my problem.










share|improve this question





























    2














    Background



    For display purposes, I sometimes find it desirable to defeat Mathematica's canonical ordering of variables, and instead have it output terms in the order in which I type them. E.g., instead of this:



    b-a
    v=v0+a t
    a8+a9+a10



    –a + b



    a t + v0



    a10 + a8 + a9




    ...I'd prefer this:




    b – a



    v0 + a t



    a8 + a9 + a10




    This can be easily accomplished by removing the Orderless attributes from Plus and Times, entering the expression, and then immediately restoring those attributes (it is important to do the latter, since their absence alters basic functionality; e.g., without Orderless, Plus doesn't recognize that a + b is mathematically identical to b + a).



    ClearAttributes[Plus, Orderless]
    ClearAttributes[Times, Orderless]
    e1=c (b-a)
    SetAttributes[Plus, Orderless]
    SetAttributes[Times, Orderless]



    c (b – a)




    Question



    How do I implement the above as a function? I.e., I'd like to define a function such that:



    e1=func[c (b-a)]
    e2=c (b-a) (*confirm that Orderless is restored to both Plus and Times*)
    e1==e2 (*check that functionality isn't affected by how function is displayed; want output to be "True"*)



    c (b – a)



    (–a + b) c



    True




    EDIT: Note that I want to alter only the display format, not any other functionality. E.g., MMA should still recognize that e1 and e2 are mathematically equivalent, even though e1 was defined while the Orderless Attribute was absent from both Plus and Times.



    Thus far I've only managed the following, which achieves the desired output, but requires I enter a function, then the expression, then another function:



    func1 := (ClearAttributes[Plus, Orderless]; ClearAttributes[Times, Orderless]) &;
    func2 := (SetAttributes[Plus, Orderless]; SetAttributes[Times, Orderless]) &;
    func1[_]
    e1=c (b-a)
    func2[_]
    e2=c (b-a)
    e1==e2



    c (b – a)



    (–a + b) c



    True




    So how do I combine the above into a single function that takes the expression as its argument? Or, to put it another way, how do I turn the following pseudocode into working MMA syntax?:



    func := (ClearAttributes[Plus, Orderless]; 
    ClearAttributes[Times, Orderless]; #;
    SetAttributes[Plus, Orderless];
    SetAttributes[Times, Orderless]) &;
    func[c (b-a)]



    (no output)




    The above function gives no output because pure functions, by default, only return the result of the last statement. I could get output by moving # to the end, as follows, but that just causes it to return the argument with standard canonical ordering, since here # is evaluated after the Orderless Attributes are restored:



    func := (ClearAttributes[Plus, Orderless]; 
    ClearAttributes[Times, Orderless];
    SetAttributes[Plus, Orderless];
    SetAttributes[Times, Orderless];#) &;
    func[c (b-a)]



    (-a+b) c




    Granted, one workaround might be to use a DownValues construction for the last statement, since that could step backwards and get # in its earlier (non-canonical) format, and output it. But it would be much more straightforward if I could just tell the function to output whatever intermediate result I wished.



    Finally, if I abandon pure functions, I could do this, but it doesn't fully work because the output of Print is Null:



    SetAttributes[f, HoldAll]
    f[expr_] :=
    Module[{}, ClearAttributes[Plus, Orderless];
    ClearAttributes[Times, Orderless];
    Print[expr];
    SetAttributes[Plus, Orderless]; SetAttributes[Times, Orderless]]
    e1 = f[c (b - a)]
    e2 = c (b - a)
    e1 == e2



    c (b-a)



    (-a + b) c



    Null == (-a + b) c




    So it would be nice if there were a simple way to get a function (both pure and otherwise) comprising a compound expression to return an assignable non-Null intermediate result (without exiting, which is what Return would do), which is something I could apply to other problems as well. I.e., I sometimes need MMA to 'do X, then do Y and return the result, then do Z', so seeing how it's done for this application would serve as a template that I could use elsewhere. I found this thread: Compound Statements and returning earlier results in () parentheses, but wasn't able to apply it to my problem.










    share|improve this question



























      2












      2








      2







      Background



      For display purposes, I sometimes find it desirable to defeat Mathematica's canonical ordering of variables, and instead have it output terms in the order in which I type them. E.g., instead of this:



      b-a
      v=v0+a t
      a8+a9+a10



      –a + b



      a t + v0



      a10 + a8 + a9




      ...I'd prefer this:




      b – a



      v0 + a t



      a8 + a9 + a10




      This can be easily accomplished by removing the Orderless attributes from Plus and Times, entering the expression, and then immediately restoring those attributes (it is important to do the latter, since their absence alters basic functionality; e.g., without Orderless, Plus doesn't recognize that a + b is mathematically identical to b + a).



      ClearAttributes[Plus, Orderless]
      ClearAttributes[Times, Orderless]
      e1=c (b-a)
      SetAttributes[Plus, Orderless]
      SetAttributes[Times, Orderless]



      c (b – a)




      Question



      How do I implement the above as a function? I.e., I'd like to define a function such that:



      e1=func[c (b-a)]
      e2=c (b-a) (*confirm that Orderless is restored to both Plus and Times*)
      e1==e2 (*check that functionality isn't affected by how function is displayed; want output to be "True"*)



      c (b – a)



      (–a + b) c



      True




      EDIT: Note that I want to alter only the display format, not any other functionality. E.g., MMA should still recognize that e1 and e2 are mathematically equivalent, even though e1 was defined while the Orderless Attribute was absent from both Plus and Times.



      Thus far I've only managed the following, which achieves the desired output, but requires I enter a function, then the expression, then another function:



      func1 := (ClearAttributes[Plus, Orderless]; ClearAttributes[Times, Orderless]) &;
      func2 := (SetAttributes[Plus, Orderless]; SetAttributes[Times, Orderless]) &;
      func1[_]
      e1=c (b-a)
      func2[_]
      e2=c (b-a)
      e1==e2



      c (b – a)



      (–a + b) c



      True




      So how do I combine the above into a single function that takes the expression as its argument? Or, to put it another way, how do I turn the following pseudocode into working MMA syntax?:



      func := (ClearAttributes[Plus, Orderless]; 
      ClearAttributes[Times, Orderless]; #;
      SetAttributes[Plus, Orderless];
      SetAttributes[Times, Orderless]) &;
      func[c (b-a)]



      (no output)




      The above function gives no output because pure functions, by default, only return the result of the last statement. I could get output by moving # to the end, as follows, but that just causes it to return the argument with standard canonical ordering, since here # is evaluated after the Orderless Attributes are restored:



      func := (ClearAttributes[Plus, Orderless]; 
      ClearAttributes[Times, Orderless];
      SetAttributes[Plus, Orderless];
      SetAttributes[Times, Orderless];#) &;
      func[c (b-a)]



      (-a+b) c




      Granted, one workaround might be to use a DownValues construction for the last statement, since that could step backwards and get # in its earlier (non-canonical) format, and output it. But it would be much more straightforward if I could just tell the function to output whatever intermediate result I wished.



      Finally, if I abandon pure functions, I could do this, but it doesn't fully work because the output of Print is Null:



      SetAttributes[f, HoldAll]
      f[expr_] :=
      Module[{}, ClearAttributes[Plus, Orderless];
      ClearAttributes[Times, Orderless];
      Print[expr];
      SetAttributes[Plus, Orderless]; SetAttributes[Times, Orderless]]
      e1 = f[c (b - a)]
      e2 = c (b - a)
      e1 == e2



      c (b-a)



      (-a + b) c



      Null == (-a + b) c




      So it would be nice if there were a simple way to get a function (both pure and otherwise) comprising a compound expression to return an assignable non-Null intermediate result (without exiting, which is what Return would do), which is something I could apply to other problems as well. I.e., I sometimes need MMA to 'do X, then do Y and return the result, then do Z', so seeing how it's done for this application would serve as a template that I could use elsewhere. I found this thread: Compound Statements and returning earlier results in () parentheses, but wasn't able to apply it to my problem.










      share|improve this question















      Background



      For display purposes, I sometimes find it desirable to defeat Mathematica's canonical ordering of variables, and instead have it output terms in the order in which I type them. E.g., instead of this:



      b-a
      v=v0+a t
      a8+a9+a10



      –a + b



      a t + v0



      a10 + a8 + a9




      ...I'd prefer this:




      b – a



      v0 + a t



      a8 + a9 + a10




      This can be easily accomplished by removing the Orderless attributes from Plus and Times, entering the expression, and then immediately restoring those attributes (it is important to do the latter, since their absence alters basic functionality; e.g., without Orderless, Plus doesn't recognize that a + b is mathematically identical to b + a).



      ClearAttributes[Plus, Orderless]
      ClearAttributes[Times, Orderless]
      e1=c (b-a)
      SetAttributes[Plus, Orderless]
      SetAttributes[Times, Orderless]



      c (b – a)




      Question



      How do I implement the above as a function? I.e., I'd like to define a function such that:



      e1=func[c (b-a)]
      e2=c (b-a) (*confirm that Orderless is restored to both Plus and Times*)
      e1==e2 (*check that functionality isn't affected by how function is displayed; want output to be "True"*)



      c (b – a)



      (–a + b) c



      True




      EDIT: Note that I want to alter only the display format, not any other functionality. E.g., MMA should still recognize that e1 and e2 are mathematically equivalent, even though e1 was defined while the Orderless Attribute was absent from both Plus and Times.



      Thus far I've only managed the following, which achieves the desired output, but requires I enter a function, then the expression, then another function:



      func1 := (ClearAttributes[Plus, Orderless]; ClearAttributes[Times, Orderless]) &;
      func2 := (SetAttributes[Plus, Orderless]; SetAttributes[Times, Orderless]) &;
      func1[_]
      e1=c (b-a)
      func2[_]
      e2=c (b-a)
      e1==e2



      c (b – a)



      (–a + b) c



      True




      So how do I combine the above into a single function that takes the expression as its argument? Or, to put it another way, how do I turn the following pseudocode into working MMA syntax?:



      func := (ClearAttributes[Plus, Orderless]; 
      ClearAttributes[Times, Orderless]; #;
      SetAttributes[Plus, Orderless];
      SetAttributes[Times, Orderless]) &;
      func[c (b-a)]



      (no output)




      The above function gives no output because pure functions, by default, only return the result of the last statement. I could get output by moving # to the end, as follows, but that just causes it to return the argument with standard canonical ordering, since here # is evaluated after the Orderless Attributes are restored:



      func := (ClearAttributes[Plus, Orderless]; 
      ClearAttributes[Times, Orderless];
      SetAttributes[Plus, Orderless];
      SetAttributes[Times, Orderless];#) &;
      func[c (b-a)]



      (-a+b) c




      Granted, one workaround might be to use a DownValues construction for the last statement, since that could step backwards and get # in its earlier (non-canonical) format, and output it. But it would be much more straightforward if I could just tell the function to output whatever intermediate result I wished.



      Finally, if I abandon pure functions, I could do this, but it doesn't fully work because the output of Print is Null:



      SetAttributes[f, HoldAll]
      f[expr_] :=
      Module[{}, ClearAttributes[Plus, Orderless];
      ClearAttributes[Times, Orderless];
      Print[expr];
      SetAttributes[Plus, Orderless]; SetAttributes[Times, Orderless]]
      e1 = f[c (b - a)]
      e2 = c (b - a)
      e1 == e2



      c (b-a)



      (-a + b) c



      Null == (-a + b) c




      So it would be nice if there were a simple way to get a function (both pure and otherwise) comprising a compound expression to return an assignable non-Null intermediate result (without exiting, which is what Return would do), which is something I could apply to other problems as well. I.e., I sometimes need MMA to 'do X, then do Y and return the result, then do Z', so seeing how it's done for this application would serve as a template that I could use elsewhere. I found this thread: Compound Statements and returning earlier results in () parentheses, but wasn't able to apply it to my problem.







      function-construction output-formatting sorting output pure-function






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 9 hours ago

























      asked Dec 30 '18 at 1:55









      theorist

      1,082420




      1,082420






















          1 Answer
          1






          active

          oldest

          votes


















          7














          You could define a format that does this for you:



          SetAttributes[orderlessForm, HoldFirst]

          MakeBoxes[orderlessForm[expr_], form_] ^:= Internal`InheritedBlock[{Times, Plus},
          ClearAttributes[{Times, Plus}, Orderless];
          MakeBoxes[expr, form]
          ]


          Then:



          orderlessForm[c (b - a)]



          c (b - a)




          And, the usual output when not using the wrapper:



          c (b - a)



          (-a + b) c




          Note that the HoldFirst attribute does most of the work.






          share|improve this answer





















          • Thanks Carl. One problem I notice is that orderlessForm alters some functionality. E.g., e1 = orderlessForm[a + b]; e2 = orderlessForm[b + a]; e1 == e2 gives a + b == b + a instead of True. I've added an edit at the end of my question to make this requirement explicit.
            – theorist
            2 days ago










          • @theorist look at the FullForm for what you see there and then see you can add an UpValue to orderedForm to make it disappear when used in any computation like this. But in general why do you need that requirement? Why can’t you just use First first?
            – b3m2a1
            2 days ago










          • @b3m2a1 Let me address each of your points in turn. (1): add UpValue: Sorry, I don't understand where you wish to add that or what you mean by making orderedForm disappear. (2) Need for requirement: I thought I explained that at the end of my OP—I need expressions I define when using orderlessForm will behave normally. (3) Use First first: Sorry, don't know what you mean here.
            – theorist
            2 days ago










          • @theorist you define anUpValue that handles working with Plus or you use orderlessForm only as a display form—e.g. use First to strip it before doing any operations.
            – b3m2a1
            2 days ago










          • @b3m2a1 Sorry, still don't understand; I'd need to see the actual code.
            – theorist
            2 days 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',
          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%2f188576%2fcombining-pure-functions-containing-compound-expressions%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









          7














          You could define a format that does this for you:



          SetAttributes[orderlessForm, HoldFirst]

          MakeBoxes[orderlessForm[expr_], form_] ^:= Internal`InheritedBlock[{Times, Plus},
          ClearAttributes[{Times, Plus}, Orderless];
          MakeBoxes[expr, form]
          ]


          Then:



          orderlessForm[c (b - a)]



          c (b - a)




          And, the usual output when not using the wrapper:



          c (b - a)



          (-a + b) c




          Note that the HoldFirst attribute does most of the work.






          share|improve this answer





















          • Thanks Carl. One problem I notice is that orderlessForm alters some functionality. E.g., e1 = orderlessForm[a + b]; e2 = orderlessForm[b + a]; e1 == e2 gives a + b == b + a instead of True. I've added an edit at the end of my question to make this requirement explicit.
            – theorist
            2 days ago










          • @theorist look at the FullForm for what you see there and then see you can add an UpValue to orderedForm to make it disappear when used in any computation like this. But in general why do you need that requirement? Why can’t you just use First first?
            – b3m2a1
            2 days ago










          • @b3m2a1 Let me address each of your points in turn. (1): add UpValue: Sorry, I don't understand where you wish to add that or what you mean by making orderedForm disappear. (2) Need for requirement: I thought I explained that at the end of my OP—I need expressions I define when using orderlessForm will behave normally. (3) Use First first: Sorry, don't know what you mean here.
            – theorist
            2 days ago










          • @theorist you define anUpValue that handles working with Plus or you use orderlessForm only as a display form—e.g. use First to strip it before doing any operations.
            – b3m2a1
            2 days ago










          • @b3m2a1 Sorry, still don't understand; I'd need to see the actual code.
            – theorist
            2 days ago
















          7














          You could define a format that does this for you:



          SetAttributes[orderlessForm, HoldFirst]

          MakeBoxes[orderlessForm[expr_], form_] ^:= Internal`InheritedBlock[{Times, Plus},
          ClearAttributes[{Times, Plus}, Orderless];
          MakeBoxes[expr, form]
          ]


          Then:



          orderlessForm[c (b - a)]



          c (b - a)




          And, the usual output when not using the wrapper:



          c (b - a)



          (-a + b) c




          Note that the HoldFirst attribute does most of the work.






          share|improve this answer





















          • Thanks Carl. One problem I notice is that orderlessForm alters some functionality. E.g., e1 = orderlessForm[a + b]; e2 = orderlessForm[b + a]; e1 == e2 gives a + b == b + a instead of True. I've added an edit at the end of my question to make this requirement explicit.
            – theorist
            2 days ago










          • @theorist look at the FullForm for what you see there and then see you can add an UpValue to orderedForm to make it disappear when used in any computation like this. But in general why do you need that requirement? Why can’t you just use First first?
            – b3m2a1
            2 days ago










          • @b3m2a1 Let me address each of your points in turn. (1): add UpValue: Sorry, I don't understand where you wish to add that or what you mean by making orderedForm disappear. (2) Need for requirement: I thought I explained that at the end of my OP—I need expressions I define when using orderlessForm will behave normally. (3) Use First first: Sorry, don't know what you mean here.
            – theorist
            2 days ago










          • @theorist you define anUpValue that handles working with Plus or you use orderlessForm only as a display form—e.g. use First to strip it before doing any operations.
            – b3m2a1
            2 days ago










          • @b3m2a1 Sorry, still don't understand; I'd need to see the actual code.
            – theorist
            2 days ago














          7












          7








          7






          You could define a format that does this for you:



          SetAttributes[orderlessForm, HoldFirst]

          MakeBoxes[orderlessForm[expr_], form_] ^:= Internal`InheritedBlock[{Times, Plus},
          ClearAttributes[{Times, Plus}, Orderless];
          MakeBoxes[expr, form]
          ]


          Then:



          orderlessForm[c (b - a)]



          c (b - a)




          And, the usual output when not using the wrapper:



          c (b - a)



          (-a + b) c




          Note that the HoldFirst attribute does most of the work.






          share|improve this answer












          You could define a format that does this for you:



          SetAttributes[orderlessForm, HoldFirst]

          MakeBoxes[orderlessForm[expr_], form_] ^:= Internal`InheritedBlock[{Times, Plus},
          ClearAttributes[{Times, Plus}, Orderless];
          MakeBoxes[expr, form]
          ]


          Then:



          orderlessForm[c (b - a)]



          c (b - a)




          And, the usual output when not using the wrapper:



          c (b - a)



          (-a + b) c




          Note that the HoldFirst attribute does most of the work.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 30 '18 at 3:33









          Carl Woll

          67.1k388175




          67.1k388175












          • Thanks Carl. One problem I notice is that orderlessForm alters some functionality. E.g., e1 = orderlessForm[a + b]; e2 = orderlessForm[b + a]; e1 == e2 gives a + b == b + a instead of True. I've added an edit at the end of my question to make this requirement explicit.
            – theorist
            2 days ago










          • @theorist look at the FullForm for what you see there and then see you can add an UpValue to orderedForm to make it disappear when used in any computation like this. But in general why do you need that requirement? Why can’t you just use First first?
            – b3m2a1
            2 days ago










          • @b3m2a1 Let me address each of your points in turn. (1): add UpValue: Sorry, I don't understand where you wish to add that or what you mean by making orderedForm disappear. (2) Need for requirement: I thought I explained that at the end of my OP—I need expressions I define when using orderlessForm will behave normally. (3) Use First first: Sorry, don't know what you mean here.
            – theorist
            2 days ago










          • @theorist you define anUpValue that handles working with Plus or you use orderlessForm only as a display form—e.g. use First to strip it before doing any operations.
            – b3m2a1
            2 days ago










          • @b3m2a1 Sorry, still don't understand; I'd need to see the actual code.
            – theorist
            2 days ago


















          • Thanks Carl. One problem I notice is that orderlessForm alters some functionality. E.g., e1 = orderlessForm[a + b]; e2 = orderlessForm[b + a]; e1 == e2 gives a + b == b + a instead of True. I've added an edit at the end of my question to make this requirement explicit.
            – theorist
            2 days ago










          • @theorist look at the FullForm for what you see there and then see you can add an UpValue to orderedForm to make it disappear when used in any computation like this. But in general why do you need that requirement? Why can’t you just use First first?
            – b3m2a1
            2 days ago










          • @b3m2a1 Let me address each of your points in turn. (1): add UpValue: Sorry, I don't understand where you wish to add that or what you mean by making orderedForm disappear. (2) Need for requirement: I thought I explained that at the end of my OP—I need expressions I define when using orderlessForm will behave normally. (3) Use First first: Sorry, don't know what you mean here.
            – theorist
            2 days ago










          • @theorist you define anUpValue that handles working with Plus or you use orderlessForm only as a display form—e.g. use First to strip it before doing any operations.
            – b3m2a1
            2 days ago










          • @b3m2a1 Sorry, still don't understand; I'd need to see the actual code.
            – theorist
            2 days ago
















          Thanks Carl. One problem I notice is that orderlessForm alters some functionality. E.g., e1 = orderlessForm[a + b]; e2 = orderlessForm[b + a]; e1 == e2 gives a + b == b + a instead of True. I've added an edit at the end of my question to make this requirement explicit.
          – theorist
          2 days ago




          Thanks Carl. One problem I notice is that orderlessForm alters some functionality. E.g., e1 = orderlessForm[a + b]; e2 = orderlessForm[b + a]; e1 == e2 gives a + b == b + a instead of True. I've added an edit at the end of my question to make this requirement explicit.
          – theorist
          2 days ago












          @theorist look at the FullForm for what you see there and then see you can add an UpValue to orderedForm to make it disappear when used in any computation like this. But in general why do you need that requirement? Why can’t you just use First first?
          – b3m2a1
          2 days ago




          @theorist look at the FullForm for what you see there and then see you can add an UpValue to orderedForm to make it disappear when used in any computation like this. But in general why do you need that requirement? Why can’t you just use First first?
          – b3m2a1
          2 days ago












          @b3m2a1 Let me address each of your points in turn. (1): add UpValue: Sorry, I don't understand where you wish to add that or what you mean by making orderedForm disappear. (2) Need for requirement: I thought I explained that at the end of my OP—I need expressions I define when using orderlessForm will behave normally. (3) Use First first: Sorry, don't know what you mean here.
          – theorist
          2 days ago




          @b3m2a1 Let me address each of your points in turn. (1): add UpValue: Sorry, I don't understand where you wish to add that or what you mean by making orderedForm disappear. (2) Need for requirement: I thought I explained that at the end of my OP—I need expressions I define when using orderlessForm will behave normally. (3) Use First first: Sorry, don't know what you mean here.
          – theorist
          2 days ago












          @theorist you define anUpValue that handles working with Plus or you use orderlessForm only as a display form—e.g. use First to strip it before doing any operations.
          – b3m2a1
          2 days ago




          @theorist you define anUpValue that handles working with Plus or you use orderlessForm only as a display form—e.g. use First to strip it before doing any operations.
          – b3m2a1
          2 days ago












          @b3m2a1 Sorry, still don't understand; I'd need to see the actual code.
          – theorist
          2 days ago




          @b3m2a1 Sorry, still don't understand; I'd need to see the actual code.
          – theorist
          2 days ago


















          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%2f188576%2fcombining-pure-functions-containing-compound-expressions%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

          "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

          Alcedinidae

          Origin of the phrase “under your belt”?