MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: TraditionalForm ordering

  • To: mathgroup at smc.vnet.net
  • Subject: [mg81083] Re: TraditionalForm ordering
  • From: Chris Chiasson <chris.chiasson at gmail.com>
  • Date: Tue, 11 Sep 2007 05:22:50 -0400 (EDT)
  • References: <200708150812.EAA09733@smc.vnet.net>

On Sep 10, 5:54 pm, Mitch Murphy <mi... at lemma.ca> wrote:
> 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
>
> On Aug 16, 2007, at 04:51, Carl Woll wrote:
>
> > Use the undocumented function PolynomialForm:
>
> > TraditionalForm @ PolynomialForm[HoldForm[b + a], TraditionalOrder -
> > > False]
>
> > Carl Woll
> > Wolfram Research
>
> >> Bonus points:
> >> Explain the output of this command in terms of the pattern
> >> matching of
> >> FormatValues, Attributes, and DefaultValues of Times.
>
> >> Grid[Outer[HoldForm@Times[1,##,1]&,{2,a,1},{2,a,1}],Dividers->All]

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[Length@Unevaluated@{##} ===
       1, $ConditionHold@##, $ConditionHold@Times@##],
     HoldAllComplete] @@
    DeleteCases[HoldComplete[args], Default@Times], True]

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



  • Prev by Date: Re: Dt "gradient" (dumb title, sorry)
  • Next by Date: design question, how to have a set of manipulate controls, but have separate expression associated with each control?
  • Previous by thread: Re: Re: TraditionalForm ordering
  • Next by thread: design question, how to have a set of manipulate controls, but have separate expression associated with each control?