Re: HoldForm Question
- To: mathgroup at smc.vnet.net
- Subject: [mg41404] Re: HoldForm Question
- From: "Dana DeLouis" <delouis at bellsouth.net>
- Date: Sun, 18 May 2003 05:02:33 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Thank you everyone for your help! :>)
I never thought of Replacement rules as the solution. :>(
Ted has a great idea, but I was hoping not to have to break an equation into
elements.
However, the material is great, and the link will keep me studying for a
long time.
I really liked Torben's idea of using HoldPattern in the replacement rules.
This allows me to not introduce extra variables.
I noticed that HoldForm does not like to Hold the value of "1" in an
equation where it considers it useless
HoldForm[2*Pi*1*1]
Returns...
HoldForm[2*Pi]
Here, it gets rid of the 1's. (Copied from InputForm)
In Torben's list, the 1's were dropped from the output. Well, I can live
with that, but it does not look symmetrical for "display" purposes.
Here is my solution "so far"
I made my own little function to generate the list of replacement rules. I
first tried it as a function, but then realized the function would be called
at each element in a table.
I decided to have the function assign a list of replacement rules to a
variable. Then, use this variable when generating the table.
Here is Torben's excellent idea, but the 1's are not kept.
v = Table[HoldForm[(2*Pi*r*c)/8] /. {HoldPattern[r] -> r,
HoldPattern[c] -> c}, {r, 0, 3}, {c, 0, 4}];
MatrixForm[v]
Here is my Function call holdem. It assigns a list of rules to the variable
"held", and prints a message.
holdem[v_List] := Module[{s, t},
(* s holds a string, t (temp) holds unique values of list v *)
(* 'held' is a Global variable for storage of HoldPattern Rules *)
t = Union[v] (* No duplicates *);
Global`held = Map[Rule[HoldPattern[#], If[# == 1, HoldForm[1], #]] &,
t];
s = "Note: 'held' holds a list of HoldPattern Rules for\n ";
s = StringJoin[s , ToString[t]];
Print[StyleForm[s, FontWeight -> "Bold", FontSlant -> "Italic"]];
Print[Global`held // TableForm];]
Before the table, I do this...
holdem[{r, c}]
Note: 'held' holds a list of HoldPattern Rules for
{r,c}
HoldPattern[c] -> If[c == 1, HoldForm[1], c]
HoldPattern[r] -> If[r == 1, HoldForm[1], r]
Now, I can use Torben's idea, and the 1's stay as 1's.
v = Table[HoldForm[(2*Pi*r*c)/8] /. held, {r, 0, 3},
{c, 0, 4}]; MatrixForm[v]
To remove the HoldForm at each element, I had to make another small program
Eval[x_] := MapAll[ReleaseHold, x]
v//Eval
Anyway, thank you for your help. This will work. :>)
--
Dana DeLouis
Windows XP
Mathematica $VersionNumber -> 4.2
delouis at bellsouth.net
= = = = = = = = = = = = = = = = =