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, but I don't know of a way to implement this series of commands as a function:
ClearAttributes[Plus, Orderless]
ClearAttributes[Times, Orderless]
e1=c (b-a)
SetAttributes[Plus, Orderless]
SetAttributes[Times, Orderless]
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
Question
How do I define a function such that:
e1=func[c (b-a)]
e2=c (b-a) (
e1==e2
c (b – a)
(–a + b) c
True
Notes: (1) 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.
(2) This is not quite a duplicate of Changing the display ordering of orderless functions? because there the OP was looking for a function that would dictate the display order, while I was looking for a simpler approach that merely displayed the output in the same order that I typed it. [So the function would just act to protect the display order, rather than specify it.]
(3)This was originally a question that ended up having two separate parts. To make the information in this more readily searchable, I've divided this question into two (this being the first part). See: Dividing one thread into two
e1 = orderlessForm[a + b];e2 = orderlessForm[b + a];e1 == e2givesa + b == b + ainstead ofTrue. I've added an edit at the end of my question to make this requirement explicit. – theorist Dec 30 '18 at 04:20FullFormfor what you see there and then see you can add anUpValuetoorderedFormto make it disappear when used in any computation like this. But in general why do you need that requirement? Why can’t you just useFirstfirst? – b3m2a1 Dec 30 '18 at 15:35UpValue: Sorry, I don't understand where you wish to add that or what you mean by makingorderedFormdisappear. (2) Need for requirement: I thought I explained that at the end of my OP—I need expressions I define when usingorderlessFormwill behave normally. (3) UseFirstfirst: Sorry, don't know what you mean here. – theorist Dec 30 '18 at 21:38UpValuethat handles working withPlusor you useorderlessFormonly as a display form—e.g. useFirstto strip it before doing any operations. – b3m2a1 Dec 30 '18 at 21:45orderlessForm[a8 + a9 + a10]gives me a8 + a9 + a10. – theorist Dec 31 '18 at 08:58$Post=orderlessFormdo? – Andrew Dec 31 '18 at 09:34