Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #6191 > unrolled thread

How to evaluate parts of an expression, but not other parts?

Started byJulian Francis <julian.w.francis@gmail.com>
First post2011-11-05 09:46 +0000
Last post2011-11-08 12:14 +0000
Articles 4 — 4 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  How to evaluate parts of an expression, but not other parts? Julian Francis <julian.w.francis@gmail.com> - 2011-11-05 09:46 +0000
    Re: How to evaluate parts of an expression, but not other parts? Silvia <wyelen@gmail.com> - 2011-11-06 11:01 +0000
    Re: How to evaluate parts of an expression, but not other parts? Rui <rui.rojo@gmail.com> - 2011-11-07 10:52 +0000
    Re: How to evaluate parts of an expression, but not other parts? Alexey Popkov <lehin.p@gmail.com> - 2011-11-08 12:14 +0000

#6191 — How to evaluate parts of an expression, but not other parts?

FromJulian Francis <julian.w.francis@gmail.com>
Date2011-11-05 09:46 +0000
SubjectHow to evaluate parts of an expression, but not other parts?
Message-ID<j930l9$a3d$1@smc.vnet.net>
Dear all,

I'd like to use the TreePlot function to visualise the expression of a
dynamic programming problem I am working on.

If I have something like: ( (a+b) + (c+d )

Mathematica helpfully simplifies this to: a + b + c + d

But I'd prefer it to be in the original form.

I can't write Hold[ ( (a+b) + (c+d) )] because I do want a,b,c & d to
be evaluated.

I want to write something like:
Hold[ ( (Evaluate[a]+Evaluate[b]) + (Evaluate[c]+Evaluate[d]) ) ]

But this just leaves the Evaluate expressions unevaluated.

Any help greatly appreciated.

Thanks,
Julian.

[toc] | [next] | [standalone]


#6228

FromSilvia <wyelen@gmail.com>
Date2011-11-06 11:01 +0000
Message-ID<j95pe5$m7t$1@smc.vnet.net>
In reply to#6191
maybe you can use a Rule list to replace a, b, c, d outside the HoldForm. e.g.

HoldForm[(a + b) + (c + d)] /. {a -> Sin[Pi/4]}

[toc] | [prev] | [next] | [standalone]


#6245

FromRui <rui.rojo@gmail.com>
Date2011-11-07 10:52 +0000
Message-ID<j98d8t$3lo$1@smc.vnet.net>
In reply to#6191
What about

ReleaseHold[
 Hold[(a + b) + (c + d)] /. 
  i_Symbol /; Context[i] === "System`" :> Hold[i]]

or maybe

ReleaseHold[
 Hold[(a + b) + (c + d)] /. 
  i_Symbol /; Context[i] =!= "Global`" :> Hold[i]] 

[toc] | [prev] | [next] | [standalone]


#6259

FromAlexey Popkov <lehin.p@gmail.com>
Date2011-11-08 12:14 +0000
Message-ID<j9b6fj$4p5$1@smc.vnet.net>
In reply to#6191
Hi Julian,

Please see strongly related thread on Stack Overflow:

http://stackoverflow.com/questions/6633236/replace-inside-held-expression

Two techniques are presented and discussed there:

1) The Trott-Strzebonski in-place evaluation technique

http://library.wolfram.com/conferences/devconf99/villegas/UnevaluatedExpressions/Links/index_lnk_30.html

2) An undocumented, but very convenient, way to make replacements in
held expressions using RuleCondition:

In[3]:= Hold[{1, 2, 3, 4, 5}] /. n_Integer :> RuleCondition[n^2,
OddQ[n]]
Out[3]= Hold[{1, 2, 9, 4, 25}]

HTH,
Alexey



On 5 Nov, 13:46, Julian Francis <julian.w.francis@gmail.com> wrote:
> Dear all,
>
> I'd like to use the TreePlot function to visualise the expression of a
> dynamic programming problem I am working on.
>
> If I have something like: ( (a+b) + (c+d )
>
> Mathematica helpfully simplifies this to: a + b + c + d
>
> But I'd prefer it to be in the original form.
>
> I can't write Hold[ ( (a+b) + (c+d) )] because I do want a,b,c & d to
> be evaluated.
>
> I want to write something like:
> Hold[ ( (Evaluate[a]+Evaluate[b]) + (Evaluate[c]+Evaluate[d]) ) ]
>
> But this just leaves the Evaluate expressions unevaluated.
>
> Any help greatly appreciated.
>
> Thanks,
> Julian.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web