Re: Mantaining the same form
- To: mathgroup at smc.vnet.net
- Subject: [mg124137] Re: Mantaining the same form
- From: Bob Hanlon <hanlonr357 at gmail.com>
- Date: Tue, 10 Jan 2012 06:02:04 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <je9624$iqs$1@smc.vnet.net>
Include in attributes of functions either HoldAll or HoldFirst or HoldRest as appropriate SetAttributes[{exprHeld, exprForm}, HoldAll]; exprHeld[e_]:=Hold[e] exprForm[e_]:=HoldForm[e] exprHeld[(Sin[2 x]*Tan[y])/(x*Sec[y]^2)] Hold[(Sin[2 x] Tan[y])/(x Sec[y]^2)] exprForm[(Sin[2 x]*Tan[y])/(x*Sec[y]^2)] (Sin[2 x] Tan[y])/(x Sec[y]^2) {%,%%}//ReleaseHold {(Cos[y] Sin[2 x] Sin[y])/x,(Cos[y] Sin[2 x] Sin[y])/x} Bob Hanlon On Mon, Jan 9, 2012 at 3:17 AM, Chris Young <cy56 at comcast.net> wrote: > On 2012-01-07 10:16:36 +0000, Miguel Gil said: > >> At a function in which one parameter is an expression "expr", >> Mathematica 8.0 evaluates or simplifies the value of "expr" when it is >> introduced. >> How is that Mathematica keep the same form of the "expr" introduced?. >> >> Example: >> >> In []: MyFunction [expr_]: = expr; >> MyFunction [(Sin [2x], Tan [y]) / (x * Sec [y]^2)] >> >> Out []: (Cos [y]^2 (Sin [2x], Tan [y]) / x >> >> I want to get the same expression (Sin [2x], Tan [y]) / (x * Sec [y]^2) >> >> Clearly, the input expression and modified expression are equivalent, >> but are not equal. >> For example, if we were to apply the rule of L'Hopital or the theorem >> Schwarz the results would be erroneous. > > I tried everything I could think of, but couldn't write any function > that would just pass on the expression unchanged: > > In[264]:= exprHeld[e_] := Hold[e] > > In[265]:= exprHeld[(Sin[2 x] * Tan[y])/(x * Sec[y]^2)] > Out[265]= Hold[(Cos[y] Sin[2 x] Sin[y])/x] > > In[266]:= holdAll[e_] := HoldAll[e] > > holdAll[(Sin[2 x] * Tan[y])/(x * Sec[y]^2)] > Out[267]= HoldAll[(Cos[y] Sin[2 x] Sin[y])/x] > > In[268]:= holdComplete[e_] := HoldComplete[e] > > In[269]:= holdComplete[(Sin[2 x] * Tan[y])/(x * Sec[y]^2)] > Out[269]= HoldComplete[(Cos[y] Sin[2 x] Sin[y])/x] > > > In[270]:= uneval[e_] := Unevaluated[e]; > > In[271]:= uneval[(Sin[2 x] * Tan[y])/(x * Sec[y]^2)] > Out[271]= (Cos[y] Sin[2 x] Sin[y])/x > > In[272]:= Hold[Unevaluated[(Sin[2 x] * Tan[y])/(x * Sec[y]^2)]] > Out[272]= Hold[Unevaluated[(Sin[2 x] Tan[y])/(x Sec[y]^2)]] > > In[273]:= holdUneval[e_] := Hold[Unevaluated[e]] > > In[274]:= holdUneval[(Sin[2 x] * Tan[y])/(x * Sec[y]^2)] > > Out[274]= Hold[Unevaluated[(Cos[y] Sin[2 x] Sin[y])/x]] > > In[278]:= ToString[HoldComplete @ ((Sin[2 x] * Tan[y])/(x * Sec[y]^2)), > InputForm] > Out[278]= "HoldComplete[(Sin[2*x]*Tan[y])/(x*Sec[y]^2)]" > > In[279]:= heldString[e_] := ToExpression[ > ToString[HoldComplete @ e, InputForm], > InputForm]; > > In[280]:= heldString[(Sin[2 x] * Tan[y])/(x * Sec[y]^2)] > > Out[280]= HoldComplete[(Cos[y] Sin[2 x] Sin[y])/x] >