Re: HoldForm Question
- To: mathgroup at smc.vnet.net
- Subject: [mg41381] Re: HoldForm Question
- From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
- Date: Sat, 17 May 2003 05:48:00 -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 sent in a solution earlier that solves the problem as stated. I give a similar solution below that works in a more general case. This solution also 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_,y_^n_Integer?Negative], form:(StandardForm|TraditionalForm) ]:= TagBox[ FractionBox[ MakeBoxes[x,form], MakeBoxes[y^#,form] &@@{-n} ], HeldTimes] MakeBoxes[ HeldTimes[ x_, Rational[p_, q_] ], form:(StandardForm|TraditionalForm) ]:= TagBox[ FractionBox[ MakeBoxes[ HeldTimes[x, p], form], MakeBoxes[q,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