       Re: Mantaining the same form

• To: mathgroup at smc.vnet.net
• Subject: [mg124136] Re: Mantaining the same form
• From: Peter Breitfeld <phbrf at t-online.de>
• Date: Tue, 10 Jan 2012 06:01:43 -0500 (EST)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• References: <je9624\$iqs\$1@smc.vnet.net> <jee830\$cvo\$1@smc.vnet.net>

```Before applying a function to it's parameters, the parameters are
Simplified to Mathematica's canonical form. To avoid this you have to
set a Hold... Attribute:

ClearAll[MyFunction]
SetAttributes[MyFunction, HoldAll]
MyFunction[expr_]:=Hold[expr]

In:= MyFunction[(Sin[2 x] Tan[y])/(x Sec[y]^2)]

Out= Hold[(Sin[2 x] Tan[y])/(x Sec[y]^2)]

Chris Young 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:= exprHeld[e_] := Hold[e]
>
> In:= exprHeld[(Sin[2 x] * Tan[y])/(x * Sec[y]^2)]
> Out= Hold[(Cos[y] Sin[2 x] Sin[y])/x]
>
> In:= holdAll[e_] := HoldAll[e]
>
> holdAll[(Sin[2 x] * Tan[y])/(x * Sec[y]^2)]
> Out= HoldAll[(Cos[y] Sin[2 x] Sin[y])/x]
>
> In:= holdComplete[e_] := HoldComplete[e]
>
> In:= holdComplete[(Sin[2 x] * Tan[y])/(x * Sec[y]^2)]
> Out= HoldComplete[(Cos[y] Sin[2 x] Sin[y])/x]
>
>
> In:= uneval[e_] := Unevaluated[e];
>
> In:= uneval[(Sin[2 x] * Tan[y])/(x * Sec[y]^2)]
> Out= (Cos[y] Sin[2 x] Sin[y])/x
>
> In:= Hold[Unevaluated[(Sin[2 x] * Tan[y])/(x * Sec[y]^2)]]
> Out= Hold[Unevaluated[(Sin[2 x] Tan[y])/(x Sec[y]^2)]]
>
> In:= holdUneval[e_] := Hold[Unevaluated[e]]
>
> In:= holdUneval[(Sin[2 x] * Tan[y])/(x * Sec[y]^2)]
>
> Out= Hold[Unevaluated[(Cos[y] Sin[2 x] Sin[y])/x]]
>
> In:= ToString[HoldComplete @ ((Sin[2 x] * Tan[y])/(x * Sec[y]^2)),
> InputForm]
> Out= "HoldComplete[(Sin[2*x]*Tan[y])/(x*Sec[y]^2)]"
>
> In:= heldString[e_] := ToExpression[
>    ToString[HoldComplete @ e, InputForm],
>    InputForm];
>
> In:= heldString[(Sin[2 x] * Tan[y])/(x * Sec[y]^2)]
>
> Out= HoldComplete[(Cos[y] Sin[2 x] Sin[y])/x]
>
>

--
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de

```

• Prev by Date: Re: Mantaining the same form
• Next by Date: Re: Extension to BinLists Function
• Previous by thread: Re: Mantaining the same form
• Next by thread: data proccess