Re: HoldForm Question
- To: mathgroup at smc.vnet.net
- Subject: [mg41380] Re: HoldForm Question
- From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
- Date: Sat, 17 May 2003 05:47:55 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Dana wanted to do the following:
Table[2*Pi*r*c/8, {r,0,7}, {c,0,7}]
where the multiplication would be held (not computed) and
the values in (2*Pi*r*c) would have thier original order.
I give a solution that defines formatting of a new function (HeldTimes)
below.
This requires use of some obscure features.
---------------------------
SetAttributes[ HeldTimes, {Flat,OneIdentity} ];
MakeBoxes[ HeldTimes[x_,y_^-1], form:(StandardForm|TraditionalForm) ]:=
TagBox[ FractionBox[ MakeBoxes[x,form], MakeBoxes[y,form] ], HeldTimes];
MakeBoxes[ HeldTimes[ x_, Rational[1,y_] ],
form:(StandardForm|TraditionalForm) ]:=
TagBox[ FractionBox[ MakeBoxes[x,form], MakeBoxes[y,form] ], HeldTimes];
MakeBoxes[ HeldTimes[x_,y_], form:(StandardForm|TraditionalForm) ]:=
TagBox[ RowBox[ { MakeBoxes[x,form], " ", MakeBoxes[y,form] } ],
HeldTimes];
Table[ HeldTimes[2, Pi, r, c, 1/8], {r,0,7}, {c,0,7} ]
(**** Output Not Shown *****)
--------------------------
To understand how this works read about
Flat, OneIdentity, MakeBoxes, and TagBox in the notebook I have posted at
http://library.wolfram.com/infocenter/MathSource/4557/
You will find a large collection of Mathematica tutorials there!
-------
Regards,
Ted Ersek