Discussion:
TraditionalForm ordering
(too old to reply)
Chris Chiasson
2007-08-15 08:16:42 UTC
Permalink
Is there some way to retain TraditionalForm, but have held expressions
maintain their original order? For instance, it would be useful if I
could make the expression below print as b+a instead of a+b. Are there
any secret options to TraditionalForm that do that?

***@HoldForm[b+a]

Bonus points:
Explain the output of this command in terms of the pattern matching of
FormatValues, Attributes, and DefaultValues of Times.

Grid[Outer[***@Times[1,##,1]&,{2,a,1},{2,a,1}],Dividers->All]
--
http://chris.chiasson.name/
Carl Woll
2007-08-16 09:02:29 UTC
Permalink
Post by Chris Chiasson
Is there some way to retain TraditionalForm, but have held expressions
maintain their original order? For instance, it would be useful if I
could make the expression below print as b+a instead of a+b. Are there
any secret options to TraditionalForm that do that?
Use the undocumented function PolynomialForm:

TraditionalForm @ PolynomialForm[HoldForm[b + a], TraditionalOrder -> False]

Carl Woll
Wolfram Research
Post by Chris Chiasson
Explain the output of this command in terms of the pattern matching of
FormatValues, Attributes, and DefaultValues of Times.
Chris Chiasson
2007-08-16 09:04:31 UTC
Permalink
Thank you Dr. Woll.
Post by Carl Woll
Post by Chris Chiasson
Is there some way to retain TraditionalForm, but have held expressions
maintain their original order? For instance, it would be useful if I
could make the expression below print as b+a instead of a+b. Are there
any secret options to TraditionalForm that do that?
Carl Woll
Wolfram Research
Post by Chris Chiasson
Explain the output of this command in terms of the pattern matching of
FormatValues, Attributes, and DefaultValues of Times.
--
http://chris.chiasson.name/
Mitch Murphy
2007-09-10 22:54:21 UTC
Permalink
Carl,

wow! i've been banging my head against turning off automated
canonical ordering for hours. basically i want to keep order of
equation "as entered" ...

In[44]:= c - b + a

Out[44]= a - b + c

In[45]:= PolynomialForm[HoldForm[c - b + a], TraditionalOrder -> False]

Out[45]= c - b + a


... but how do i get rid of a leading one coeff (which is now inside
HoldForm)

In[46]:= c - 1 b + a

Out[46]= a - b + c

In[47]:= PolynomialForm[HoldForm[c - 1 b + a], TraditionalOrder ->
False]

Out[47]= c - 1 b + a


thanks,
Mitch
Post by Carl Woll
Post by Carl Woll
False]
Carl Woll
Wolfram Research
Post by Carl Woll
Explain the output of this command in terms of the pattern
matching of
FormatValues, Attributes, and DefaultValues of Times.
Chris Chiasson
2007-09-11 09:23:21 UTC
Permalink
Post by Mitch Murphy
Carl,
wow! i've been banging my head against turning off automated
canonical ordering for hours. basically i want to keep order of
equation "as entered" ...
In[44]:= c - b + a
Out[44]= a - b + c
In[45]:= PolynomialForm[HoldForm[c - b + a], TraditionalOrder -> False]
Out[45]= c - b + a
... but how do i get rid of a leading one coeff (which is now inside
HoldForm)
In[46]:= c - 1 b + a
Out[46]= a - b + c
In[47]:= PolynomialForm[HoldForm[c - 1 b + a], TraditionalOrder ->
False]
Out[47]= c - 1 b + a
thanks,
Mitch
Post by Carl Woll
Post by Carl Woll
False]
Carl Woll
Wolfram Research
Post by Carl Woll
Explain the output of this command in terms of the pattern
matching of
FormatValues, Attributes, and DefaultValues of Times.
The problem (IMHO) is that you were (unknowingly?) relying on a bad
feature of Times where it didn't show the 1 due to (pattern matching
during conversion to boxes that amounts to) evaluation while printing.
You can check that using HoldForm[1 a b] and FullForm[HoldForm[1 a
b]], which will still show the 1 when using HoldForm. It appears that,
in this case (but not the one I presented as a bonus question),
PolynomialForm prevents the evaluation during printing. So, you will
have to feed Times the exact arguments you want it to print.

This can be very tricky if the arguments to Times need to remain
unevaluated. I effectively needed to step outside of the HoldForm
expression to evaluate some things using RuleCondition (undocumented),
and then step back inside the HoldForm with the exact expression you
want using $ConditionHold (undocumented). Things are further
complicated by the fact that Times[a] prints as Times[a] instead of a,
creating a motivation to use the (undocumented) Null calling structure
for Function. So, here is the code:

ur := Print@"ur fired";
{HoldForm[ur 1 2], HoldForm[ur 1]} /.
HoldPattern[Times][args__] :>
RuleCondition[
Function[Null,
If[***@Unevaluated@{##} ===
1, $ConditionHold@##, $***@Times@##],
HoldAllComplete] @@
DeleteCases[HoldComplete[args], ***@Times], True]

--
http://chris.chiasson.name/

Loading...