# How to simplify expression and use HoldForm at the same time?

Hopefully a simple problem for the experts here.

I have a need many times to build a symbolic expression for an equation (say a PDE) to use for plot labels in a low level function inside Manipulate, and so I make a function that I call to build the pde in symbolic form, so I can use it for a plot label. I pass the PDE parameters to this function, and the function uses HoldForm to build it.

But when one of the parameters is 1 (or even zero), and because of HoldForm, these remain stuck there and do not simplify away, and I'd like to remove them.

Currently I use If statement to check for these cases. But I have a feeling there is a better way.

Here is the function (example)

f[c_] := Module[{},
HoldForm[c* D["u"["x", "t"], {"x", 2}] == "f"["x", "t"]]
]


now, when I call it like this

f[1]


it returns

So now I do

f[c_] := Module[{},
If[c == 1,
HoldForm[ D["u"["x", "t"], {"x", 2}] == "f"["x", "t"] ],
HoldForm[c* D["u"["x", "t"], {"x", 2}] == "f"["x", "t"] ],
]
]


and now f[1] returns

I tried many things, (Defer, Simplify, Evaluate, etc...) and nothing works, other than by doing this manual check before using HoldForm.

And about the use of strings there, I had to do it this way :). Too many problems if I use actual symbols. Long story. May be for another topic I can explain why, but for the above works ok for me now other than those extra checks I have to do manually.

question is: is there a trick to do what I am doing about without the If check (I have few parameters to check, and have to do many checks for 1's and 0's as well). Not a big problem for me to do the checks, just wondering if there is a trick I am overlooking.

thanks

• Nasser, in passing, why do you keep using Module[{}, ...]? Commented Jan 19, 2012 at 16:13
• Nasser, I fear I have received that answer before; my apologies for not remembering. In a compiled language I believe the empty module would not affect speed, but in Mathematica it does. The hit is small, but in cases of fast and simple functions it is significant. I would personally prefer that you leave the extraneous Module out of your questions as IMHO it obscures the function, and also results in propagation of the empty Module to answers. Commented Jan 20, 2012 at 4:11

Why don't you use HoldForm only on the part that actually needs to be held? For example:
f[c_] := Module[{},