Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #10031 > unrolled thread
| Started by | Brentt <brenttnewman@gmail.com> |
|---|---|
| First post | 2012-05-11 04:15 +0000 |
| Last post | 2012-05-12 08:51 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Fine control of evaluation Brentt <brenttnewman@gmail.com> - 2012-05-11 04:15 +0000
Re: Fine control of evaluation A Retey <awnl@gmx-topmail.de> - 2012-05-12 08:51 +0000
| From | Brentt <brenttnewman@gmail.com> |
|---|---|
| Date | 2012-05-11 04:15 +0000 |
| Subject | Fine control of evaluation |
| Message-ID | <joi3pj$n55$1@smc.vnet.net> |
Hello, I am struggling with evaluation control and was hoping someone might
point me in the right direction. I vaguely remember seeing something in the
manual or the tutorials addressing this issue, but I can't find the section
I saw it in.
How does one get fine control over things wrapped in Hold and HoldForm. Say
I have some functions
func1[x_]:= f[x];
func2[x_] := g[x];
step1 = HoldForm[ func1[x]+ func2[x] ];
Now say I want the statements wrapped in HoldForm, func1[x]+ func2[x] to
evaluate to f[x]+ func2[x]
I thought naturally it would be something like
step2 = HoldForm[ Evaluate[func1[x]]+ func2[x] ] ;
But then HoldForm seems a bit overzealous about it's task, and outputs
Evaluate[func1[x]]+ func2[x]---it leaves Evaluate unevaluated. (I tried
wrapping it func1[x] in ReleaseHold to no avail.)
The above is just pseudocode, Maybe there is some specifics about what I
was actually doing that was causing the unintuitive behavior (i.e. HoldForm
holding Evaluate, instead of, well, evaluating.) What I was doing was more
along these lines:
----------------
ubounds= {u,0, pi};
vbounds={v,0,2pi};
t[dir_]:= D[s[u,v],dir_]; (*where dir_ is going to be either u or v*)
(*here is the difficult part:*)
formattedOutput= Integrate[HoldForm[t[u]] , ubounds, vbounds ]
//TraditionalForm;
----------------
The issue is that I want the t[u] wrapped in the HoldForm to evaluate to
D[s[u,v],dir_], and hold that. If I wrap it in Evaluate, HoldForm holds
Evaluate (puzzling), and tries to integrate Evaluate as if it is the
integrand. I've tried all kinds of permutations of HoldForm, Defer,
ReleaseHold, Evaluate, and I haven't had anything to work.
Thank you for any help or pointing me in the right direction
[toc] | [next] | [standalone]
| From | A Retey <awnl@gmx-topmail.de> |
|---|---|
| Date | 2012-05-12 08:51 +0000 |
| Message-ID | <jol8b4$43t$1@smc.vnet.net> |
| In reply to | #10031 |
Hi,
> Hello, I am struggling with evaluation control and was hoping someone might
> point me in the right direction. I vaguely remember seeing something in the
> manual or the tutorials addressing this issue, but I can't find the section
> I saw it in.
the general documentation is this (which I consider a must-read):
tutorial/Evaluation
your particular problem is documented here:
ref/Evaluate (possible issues section)
> How does one get fine control over things wrapped in Hold and HoldForm. Say
> I have some functions
>
> func1[x_]:= f[x];
> func2[x_] := g[x];
> step1 = HoldForm[ func1[x]+ func2[x] ];
>
> Now say I want the statements wrapped in HoldForm, func1[x]+ func2[x] to
> evaluate to f[x]+ func2[x]
>
> I thought naturally it would be something like
>
> step2 = HoldForm[ Evaluate[func1[x]]+ func2[x] ] ;
>
> But then HoldForm seems a bit overzealous about it's task, and outputs
> Evaluate[func1[x]]+ func2[x]---it leaves Evaluate unevaluated. (I tried
> wrapping it func1[x] in ReleaseHold to no avail.)
from the documentation of Evaluate: "Evaluate works only on the first
level, directly inside a held function:"
> The above is just pseudocode, Maybe there is some specifics about what I
> was actually doing that was causing the unintuitive behavior (i.e. HoldForm
> holding Evaluate, instead of, well, evaluating.) What I was doing was more
> along these lines:
> ----------------
> ubounds= {u,0, pi};
> vbounds={v,0,2pi};
> t[dir_]:= D[s[u,v],dir_]; (*where dir_ is going to be either u or v*)
>
> (*here is the difficult part:*)
> formattedOutput= Integrate[HoldForm[t[u]] , ubounds, vbounds ]
> //TraditionalForm;
> ----------------
> The issue is that I want the t[u] wrapped in the HoldForm to evaluate to
> D[s[u,v],dir_], and hold that. If I wrap it in Evaluate, HoldForm holds
> Evaluate (puzzling), and tries to integrate Evaluate as if it is the
> integrand. I've tried all kinds of permutations of HoldForm, Defer,
> ReleaseHold, Evaluate, and I haven't had anything to work.
What you want to do is to insert evaluated subexpression into a held
expressions. There are many ways to achieve this, but the most common is
to use With:
With[{ubounds = ubounds, vbounds = vbounds, expr = t[u]},
HoldForm[Integrate[expr, ubounds, vbounds]]
]
(note that I've wrapped everythin with HoldForm and also inserted
ubounds and vbounds. Without that Integrate would try to integrate
HoldForm, which it can't do and I assume you don't even actually want it
to try...)
hth,
albert
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web