Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #7615 > unrolled thread
| Started by | Miguel Gil <misvrne@gmail.com> |
|---|---|
| First post | 2012-01-07 10:16 +0000 |
| Last post | 2012-01-11 09:23 +0000 |
| Articles | 6 — 6 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Mantaining the same form Miguel Gil <misvrne@gmail.com> - 2012-01-07 10:16 +0000
Re: Mantaining the same form Chris Young <cy56@comcast.net> - 2012-01-09 08:21 +0000
Re: Mantaining the same form "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2012-01-10 11:04 +0000
Re: Mantaining the same form Peter Breitfeld <phbrf@t-online.de> - 2012-01-10 11:05 +0000
Re: Mantaining the same form Bob Hanlon <hanlonr357@gmail.com> - 2012-01-10 11:05 +0000
Re: Mantaining the same form Christopher Young <cy56@comcast.net> - 2012-01-11 09:23 +0000
| From | Miguel Gil <misvrne@gmail.com> |
|---|---|
| Date | 2012-01-07 10:16 +0000 |
| Subject | Mantaining the same form |
| Message-ID | <je9624$iqs$1@smc.vnet.net> |
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. Thanks
[toc] | [next] | [standalone]
| From | Chris Young <cy56@comcast.net> |
|---|---|
| Date | 2012-01-09 08:21 +0000 |
| Message-ID | <jee830$cvo$1@smc.vnet.net> |
| In reply to | #7615 |
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]
[toc] | [prev] | [next] | [standalone]
| From | "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> |
|---|---|
| Date | 2012-01-10 11:04 +0000 |
| Message-ID | <jeh5vf$r8c$1@smc.vnet.net> |
| In reply to | #7684 |
On Mon, 09 Jan 2012 08:21:52 -0000, Chris Young <cy56@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] > You forgot your Attributes: In[1] := exprHeld[e_] := Hold[e]; SetAttributes[exprHeld, HoldAll]; In[3]:= exprHeld[(Sin[2 x]*Tan[y])/(x*Sec[y]^2)] Out[3]= Hold[(Sin[2 x] Tan[y])/(x Sec[y]^2)] (Note that HoldAll is an Attribute, not a function.)
[toc] | [prev] | [next] | [standalone]
| From | Peter Breitfeld <phbrf@t-online.de> |
|---|---|
| Date | 2012-01-10 11:05 +0000 |
| Message-ID | <jeh61c$r95$1@smc.vnet.net> |
| In reply to | #7684 |
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[14]:= MyFunction[(Sin[2 x] Tan[y])/(x Sec[y]^2)] Out[14]= 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[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] > > -- _________________________________________________________________ Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de
[toc] | [prev] | [next] | [standalone]
| From | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| Date | 2012-01-10 11:05 +0000 |
| Message-ID | <jeh62b$r98$1@smc.vnet.net> |
| In reply to | #7615 |
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@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]
>
[toc] | [prev] | [next] | [standalone]
| From | Christopher Young <cy56@comcast.net> |
|---|---|
| Date | 2012-01-11 09:23 +0000 |
| Message-ID | <jejke5$b53$1@smc.vnet.net> |
| In reply to | #7615 |
Thanks a lot, this is a big help. It's going to take me a while to
understand why the Hold functions don't actually do anything, or give
any warning, if the attributes don't include a Hold.
On Jan 9, 2012, at 8:57 AM, Bob Hanlon wrote:
> 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@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]
>>
Chris Young
cy56@comcast.net
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web